From 23a53301c545b45a6c809cc3f444c5f4e577f6c0 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Mon, 28 Sep 2020 15:38:26 +0200 Subject: [PATCH] [clangd] Introduce memory usage dumping to TUScheduler, for Preambles and ASTCache File-granular information is considered details. Depends on D88411 Differential Revision: https://reviews.llvm.org/D88415 --- clang-tools-extra/clangd/TUScheduler.cpp | 14 ++++++++++++-- clang-tools-extra/clangd/TUScheduler.h | 6 +++++- clang-tools-extra/clangd/unittests/ClangdTests.cpp | 4 +++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index c408c8c..baf3f91 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -56,6 +56,7 @@ #include "support/Cancellation.h" #include "support/Context.h" #include "support/Logger.h" +#include "support/MemoryTree.h" #include "support/Path.h" #include "support/Threading.h" #include "support/Trace.h" @@ -932,9 +933,9 @@ TUScheduler::FileStats ASTWorker::stats() const { // Note that we don't report the size of ASTs currently used for processing // the in-flight requests. We used this information for debugging purposes // only, so this should be fine. - Result.UsedBytes = IdleASTs.getUsedBytes(this); + Result.UsedBytesAST = IdleASTs.getUsedBytes(this); if (auto Preamble = getPossiblyStalePreamble()) - Result.UsedBytes += Preamble->Preamble.getSize(); + Result.UsedBytesPreamble = Preamble->Preamble.getSize(); return Result; } @@ -1429,5 +1430,14 @@ DebouncePolicy DebouncePolicy::fixed(clock::duration T) { return P; } +void TUScheduler::profile(MemoryTree &MT) const { + for (const auto &Elem : fileStats()) { + MT.detail(Elem.first()) + .child("preamble") + .addUsage(Opts.StorePreamblesInMemory ? Elem.second.UsedBytesPreamble + : 0); + MT.detail(Elem.first()).child("ast").addUsage(Elem.second.UsedBytesAST); + } +} } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h index 5d545b3..cc38db8 100644 --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -14,6 +14,7 @@ #include "GlobalCompilationDatabase.h" #include "index/CanonicalIncludes.h" #include "support/Function.h" +#include "support/MemoryTree.h" #include "support/Path.h" #include "support/Threading.h" #include "llvm/ADT/Optional.h" @@ -207,7 +208,8 @@ public: ~TUScheduler(); struct FileStats { - std::size_t UsedBytes = 0; + std::size_t UsedBytesAST = 0; + std::size_t UsedBytesPreamble = 0; unsigned PreambleBuilds = 0; unsigned ASTBuilds = 0; }; @@ -311,6 +313,8 @@ public: // FIXME: move to ClangdServer via createProcessingContext. static llvm::Optional getFileBeingProcessedInContext(); + void profile(MemoryTree &MT) const; + private: const GlobalCompilationDatabase &CDB; Options Opts; diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp index 813b95a..b047759 100644 --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -565,7 +565,9 @@ int hello; } MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") { - return arg.first() == Name && (arg.second.UsedBytes != 0) == UsesMemory && + return arg.first() == Name && + (arg.second.UsedBytesAST + arg.second.UsedBytesPreamble != 0) == + UsesMemory && std::tie(arg.second.PreambleBuilds, ASTBuilds) == std::tie(PreambleBuilds, ASTBuilds); } -- 2.7.4