diff --git a/clang-tools-extra/clangd/index/remote/Service.proto b/clang-tools-extra/clangd/index/remote/Service.proto --- a/clang-tools-extra/clangd/index/remote/Service.proto +++ b/clang-tools-extra/clangd/index/remote/Service.proto @@ -10,8 +10,11 @@ package clang.clangd.remote.v1; +import "google/protobuf/empty.proto"; import "Index.proto"; +message MonitoringInfoReply { optional string info = 1; } + // Semantics of SymbolIndex match clangd::SymbolIndex with all required // structures corresponding to their clangd::* counterparts. service SymbolIndex { @@ -22,5 +25,7 @@ rpc Refs(RefsRequest) returns (stream RefsReply) {} rpc Relations(RelationsRequest) returns (stream RelationsReply) {} + + rpc MonitoringInfo(google.protobuf.Empty) returns (MonitoringInfoReply) {} } diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp --- a/clang-tools-extra/clangd/index/remote/server/Server.cpp +++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp @@ -91,7 +91,7 @@ class RemoteIndexServer final : public v1::SymbolIndex::Service { public: RemoteIndexServer(clangd::SymbolIndex &Index, llvm::StringRef IndexRoot) - : Index(Index) { + : Index(Index), ServiceStartTime(std::chrono::system_clock::now()) { llvm::SmallString<256> NativePath = IndexRoot; llvm::sys::path::native(NativePath); ProtobufMarshaller = std::unique_ptr(new Marshaller( @@ -280,8 +280,23 @@ Millis); } + grpc::Status MonitoringInfo(grpc::ServerContext *Context, + const google::protobuf::Empty *Request, + v1::MonitoringInfoReply *Reply) override { + auto Uptime = std::chrono::duration_cast( + std::chrono::system_clock::now() - ServiceStartTime) + .count(); + Reply->set_info(llvm::formatv( + "Service started at {0:%Y-%m-%d %H:%M:%S}. Uptime: {1} h {2} m.", + ServiceStartTime, Uptime / 60, Uptime % 60)); + logRequest(*Request); + logResponse(*Reply); + return grpc::Status::OK; + } + std::unique_ptr ProtobufMarshaller; clangd::SymbolIndex &Index; + llvm::sys::TimePoint<> ServiceStartTime; }; // Detect changes in \p IndexPath file and load new versions of the index