[PATCH] D83831: [clangd] Add more logs and attach tracers to remote index server routines

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 14 16:36:15 PDT 2020


kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83831

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -9,6 +9,8 @@
 #include "index/Index.h"
 #include "index/Serialization.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "support/Logger.h"
+#include "support/Trace.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
@@ -57,19 +59,26 @@
   grpc::Status Lookup(grpc::ServerContext *Context,
                       const LookupRequest *Request,
                       grpc::ServerWriter<LookupReply> *Reply) override {
+    trace::Span Tracer("Remote index server Lookup");
+    SPAN_ATTACH(Tracer, "LookupRequest", Request->ShortDebugString());
     clangd::LookupRequest Req;
     for (const auto &ID : Request->ids()) {
       auto SID = SymbolID::fromStr(StringRef(ID));
-      if (!SID)
+      if (!SID) {
+        elog("Lookup request cancelled: invalid SymbolID {1}", SID.takeError());
         return grpc::Status::CANCELLED;
+      }
       Req.IDs.insert(*SID);
     }
+    unsigned SentItems = 0;
     Index->lookup(Req, [&](const clangd::Symbol &Sym) {
       LookupReply NextMessage;
       *NextMessage.mutable_stream_result() =
           toProtobuf(Sym, IndexedProjectRoot);
       Reply->Write(NextMessage);
+      ++SentItems;
     });
+    SPAN_ATTACH(Tracer, "SentItems", SentItems);
     LookupReply LastMessage;
     LastMessage.set_final_result(true);
     Reply->Write(LastMessage);
@@ -79,13 +88,18 @@
   grpc::Status FuzzyFind(grpc::ServerContext *Context,
                          const FuzzyFindRequest *Request,
                          grpc::ServerWriter<FuzzyFindReply> *Reply) override {
+    trace::Span Tracer("Remote index server FuzzyFind");
+    SPAN_ATTACH(Tracer, "FuzzyFindRequest", Request->ShortDebugString());
     const auto Req = fromProtobuf(Request, IndexedProjectRoot);
+    unsigned SentItems = 0;
     bool HasMore = Index->fuzzyFind(Req, [&](const clangd::Symbol &Sym) {
       FuzzyFindReply NextMessage;
       *NextMessage.mutable_stream_result() =
           toProtobuf(Sym, IndexedProjectRoot);
       Reply->Write(NextMessage);
+      ++SentItems;
     });
+    SPAN_ATTACH(Tracer, "SentItems", SentItems);
     FuzzyFindReply LastMessage;
     LastMessage.set_final_result(HasMore);
     Reply->Write(LastMessage);
@@ -94,18 +108,25 @@
 
   grpc::Status Refs(grpc::ServerContext *Context, const RefsRequest *Request,
                     grpc::ServerWriter<RefsReply> *Reply) override {
+    trace::Span Tracer("Remote index server Refs");
+    SPAN_ATTACH(Tracer, "RefsRequest", Request->ShortDebugString());
     clangd::RefsRequest Req;
     for (const auto &ID : Request->ids()) {
       auto SID = SymbolID::fromStr(StringRef(ID));
-      if (!SID)
+      if (!SID) {
+        elog("Refs request cancelled: invalid SymbolID {1}", SID.takeError());
         return grpc::Status::CANCELLED;
+      }
       Req.IDs.insert(*SID);
     }
+    unsigned SentItems = 0;
     bool HasMore = Index->refs(Req, [&](const clangd::Ref &Reference) {
       RefsReply NextMessage;
       *NextMessage.mutable_stream_result() = toProtobuf(Reference, IndexRoot);
       Reply->Write(NextMessage);
+      ++SentItems;
     });
+    SPAN_ATTACH(Tracer, "SentItems", SentItems);
     RefsReply LastMessage;
     LastMessage.set_final_result(HasMore);
     Reply->Write(LastMessage);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83831.278018.patch
Type: text/x-patch
Size: 3548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200714/d3e9366a/attachment.bin>


More information about the cfe-commits mailing list