[PATCH] D92198: [clangd] Log remote index connectivity status
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 15 09:28:40 PST 2020
kbobyrev updated this revision to Diff 311943.
kbobyrev added a comment.
Actually clean up rebase artifacts.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92198/new/
https://reviews.llvm.org/D92198
Files:
clang-tools-extra/clangd/index/remote/Client.cpp
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===================================================================
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -19,14 +19,40 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
+#include <atomic>
#include <chrono>
+#include <memory>
namespace clang {
namespace clangd {
namespace remote {
namespace {
+llvm::StringRef toString(const grpc_connectivity_state &State) {
+ switch (State) {
+ case GRPC_CHANNEL_IDLE:
+ return "idle";
+ case GRPC_CHANNEL_CONNECTING:
+ return "connecting";
+ case GRPC_CHANNEL_READY:
+ return "ready";
+ case GRPC_CHANNEL_TRANSIENT_FAILURE:
+ return "transient failure";
+ case GRPC_CHANNEL_SHUTDOWN:
+ return "shutdown";
+ }
+ llvm_unreachable("Not a valid grpc_connectivity_state.");
+}
+
class IndexClient : public clangd::SymbolIndex {
+ void updateConnectionStatus() const {
+ auto NewStatus = Channel->GetState(/*try_to_connect=*/false);
+ auto OldStatus = ConnectionStatus.exchange(NewStatus);
+ if (OldStatus != NewStatus)
+ vlog("Remote index connection [{0}]: {1} => {2}", ServerAddress,
+ toString(OldStatus), toString(NewStatus));
+ }
+
template <typename RequestT, typename ReplyT>
using StreamingCall = std::unique_ptr<grpc::ClientReader<ReplyT>> (
remote::v1::SymbolIndex::Stub::*)(grpc::ClientContext *,
@@ -37,6 +63,7 @@
bool streamRPC(ClangdRequestT Request,
StreamingCall<RequestT, ReplyT> RPCCall,
CallbackT Callback) const {
+ updateConnectionStatus();
bool FinalResult = false;
trace::Span Tracer(RequestT::descriptor()->name());
const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request);
@@ -77,18 +104,21 @@
SPAN_ATTACH(Tracer, "Status", Reader->Finish().ok());
SPAN_ATTACH(Tracer, "Successful", Successful);
SPAN_ATTACH(Tracer, "Failed to parse", FailedToParse);
+ updateConnectionStatus();
return FinalResult;
}
public:
IndexClient(
- std::shared_ptr<grpc::Channel> Channel, llvm::StringRef ProjectRoot,
- llvm::StringRef Address,
+ std::shared_ptr<grpc::Channel> Channel, llvm::StringRef Address,
+ llvm::StringRef ProjectRoot,
std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000))
- : Stub(remote::v1::SymbolIndex::NewStub(Channel)),
+ : Stub(remote::v1::SymbolIndex::NewStub(Channel)), Channel(Channel),
+ ServerAddress(Address),
+ ConnectionStatus(Channel->GetState(/*try_to_connect=*/true)),
ProtobufMarshaller(new Marshaller(/*RemoteIndexRoot=*/"",
/*LocalIndexRoot=*/ProjectRoot)),
- ServerAddress(Address), DeadlineWaitingTime(DeadlineTime) {
+ DeadlineWaitingTime(DeadlineTime) {
assert(!ProjectRoot.empty());
}
@@ -128,6 +158,9 @@
private:
std::unique_ptr<remote::v1::SymbolIndex::Stub> Stub;
+ std::shared_ptr<grpc::Channel> Channel;
+ llvm::SmallString<256> ServerAddress;
+ mutable std::atomic<grpc_connectivity_state> ConnectionStatus;
std::unique_ptr<Marshaller> ProtobufMarshaller;
llvm::SmallString<256> ServerAddress;
// Each request will be terminated if it takes too long.
@@ -140,9 +173,8 @@
llvm::StringRef ProjectRoot) {
const auto Channel =
grpc::CreateChannel(Address.str(), grpc::InsecureChannelCredentials());
- Channel->GetState(true);
return std::unique_ptr<clangd::SymbolIndex>(
- new IndexClient(Channel, ProjectRoot, Address));
+ new IndexClient(Channel, Address, ProjectRoot));
}
} // namespace remote
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92198.311943.patch
Type: text/x-patch
Size: 3737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201215/bb9c493d/attachment-0001.bin>
More information about the cfe-commits
mailing list