kbobyrev updated this revision to Diff 329865. kbobyrev marked 8 inline comments as done. kbobyrev added a comment.
Address review comments. The current format is "store seconds since X event". Should we store UNIX timestamps instead? This is probably not portable until C++20, so maybe it isn't a great idea. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D98246/new/ https://reviews.llvm.org/D98246 Files: clang-tools-extra/clangd/index/remote/Service.proto 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 @@ -8,6 +8,7 @@ #include "Index.pb.h" #include "Service.grpc.pb.h" +#include "Service.pb.h" #include "index/Index.h" #include "index/Serialization.h" #include "index/Symbol.h" @@ -283,11 +284,39 @@ clangd::SymbolIndex &Index; }; +class Monitor final : public v1::Monitor::Service { +public: + Monitor(llvm::sys::TimePoint<> StartTime) + : StartTime(StartTime), IndexLastReload(StartTime) {} + + void updateIndex(const llvm::sys::TimePoint<> UpdateTime) { + IndexLastReload = UpdateTime; + } + +private: + grpc::Status MonitoringInfo(grpc::ServerContext *Context, + const v1::MonitoringInfoRequest *Request, + v1::MonitoringInfoReply *Reply) override { + Reply->set_uptime(std::chrono::duration_cast<std::chrono::seconds>( + std::chrono::system_clock::now() - StartTime) + .count()); + Reply->set_time_since_reload( + std::chrono::duration_cast<std::chrono::seconds>( + std::chrono::system_clock::now() - IndexLastReload) + .count()); + return grpc::Status::OK; + } + + const llvm::sys::TimePoint<> StartTime; + llvm::sys::TimePoint<> IndexLastReload; +}; + // Detect changes in \p IndexPath file and load new versions of the index // whenever they become available. void hotReload(clangd::SwapIndex &Index, llvm::StringRef IndexPath, llvm::vfs::Status &LastStatus, - llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &FS) { + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &FS, + Monitor &Monitor) { auto Status = FS->status(IndexPath); // Requested file is same as loaded index: no reload is needed. if (!Status || (Status->getLastModificationTime() == @@ -306,6 +335,7 @@ Index.reset(std::move(NewIndex)); log("New index version loaded. Last modification time: {0}, size: {1} bytes.", Status->getLastModificationTime(), Status->getSize()); + Monitor.updateIndex(Status->getLastModificationTime()); } void runServerAndWait(clangd::SymbolIndex &Index, llvm::StringRef ServerAddress, @@ -417,11 +447,13 @@ } clang::clangd::SwapIndex Index(std::move(SymIndex)); - std::thread HotReloadThread([&Index, &Status, &FS]() { + Monitor Monitor(std::chrono::system_clock::now()); + + std::thread HotReloadThread([&Index, &Status, &FS, &Monitor]() { llvm::vfs::Status LastStatus = *Status; static constexpr auto RefreshFrequency = std::chrono::seconds(30); while (!clang::clangd::shutdownRequested()) { - hotReload(Index, llvm::StringRef(IndexPath), LastStatus, FS); + hotReload(Index, llvm::StringRef(IndexPath), LastStatus, FS, Monitor); std::this_thread::sleep_for(RefreshFrequency); } }); Index: clang-tools-extra/clangd/index/remote/Service.proto =================================================================== --- clang-tools-extra/clangd/index/remote/Service.proto +++ clang-tools-extra/clangd/index/remote/Service.proto @@ -24,3 +24,23 @@ rpc Relations(RelationsRequest) returns (stream RelationsReply) {} } +message MonitoringInfoRequest {} +message MonitoringInfoReply { + // Time since the server started (in seconds). + optional uint64 uptime = 1; + // Time since the last index reload (in seconds). + optional uint64 time_since_reload = 2; + // FIXME(kirillbobyrev): The following fields should be provided with the + // index (probably in adjacent metadata.txt file next to loaded .idx). + // Time since the index was built on the indexing machine. + optional uint64 freshness = 3; + // Time since the index was built on the indexing machine. + optional string index_commit_hash = 4; + // URL to the index file. + optional string index_link = 5; + optional string metadata = 9000; +} + +service Monitor { + rpc MonitoringInfo(MonitoringInfoRequest) returns (MonitoringInfoReply) {} +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits