[PATCH] D101516: Introduce clangd-server-monitor tool

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 29 02:40:30 PDT 2021


kbobyrev created this revision.
kbobyrev added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, mgorny.
kbobyrev requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101516

Files:
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/monitor/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp


Index: clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -0,0 +1,60 @@
+//===--- Monitor.cpp - Request server monitoring information through CLI --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MonitoringService.grpc.pb.h"
+#include "MonitoringService.pb.h"
+
+#include "clang/Basic/Version.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Signals.h"
+
+#include <chrono>
+#include <grpc++/grpc++.h>
+
+namespace clang {
+namespace clangd {
+namespace remote {
+namespace {
+
+static constexpr char Overview[] = R"(
+This tool requests monitoring information (uptime, index freshness) from the
+server and prints it to stdout.
+)";
+
+llvm::cl::opt<std::string>
+    ServerAddress("server-address", llvm::cl::Positional,
+                  llvm::cl::desc("Address of the invoked server."),
+                  llvm::cl::Required);
+
+} // namespace
+} // namespace remote
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, char *argv[]) {
+  using namespace clang::clangd::remote;
+  llvm::cl::ParseCommandLineOptions(argc, argv, Overview);
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const auto Channel =
+      grpc::CreateChannel(ServerAddress, grpc::InsecureChannelCredentials());
+  const auto Stub = clang::clangd::remote::v1::Monitor::NewStub(Channel);
+  grpc::ClientContext Context;
+  Context.AddMetadata("version", clang::getClangToolFullVersion("clangd"));
+  const clang::clangd::remote::v1::MonitoringInfoRequest Request;
+  clang::clangd::remote::v1::MonitoringInfoReply Response;
+  const auto Status = Stub->MonitoringInfo(&Context, Request, &Response);
+  if (!Status.ok()) {
+    llvm::errs() << llvm::formatv(
+        "Can not request monitoring information ({0}): {1}\n",
+        Status.error_code(), Status.error_message());
+    return -1;
+  }
+  llvm::outs() << Response.DebugString();
+}
Index: clang-tools-extra/clangd/index/remote/monitor/CMakeLists.txt
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/monitor/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+add_clang_executable(clangd-server-monitor
+  Monitor.cpp
+
+  DEPENDS
+  RemoteIndexServiceProto
+  )
+
+target_link_libraries(clangd-server-monitor
+  PRIVATE
+  clangBasic
+
+  MonitoringServiceProto
+  RemoteIndexServiceProto
+  )
Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -38,6 +38,7 @@
 
   add_subdirectory(marshalling)
   add_subdirectory(server)
+  add_subdirectory(monitor)
 else()
   # Provides a no-op implementation of clangdRemoteIndex.
   add_subdirectory(unimplemented)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101516.341443.patch
Type: text/x-patch
Size: 3289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210429/2d862d58/attachment-0001.bin>


More information about the cfe-commits mailing list