diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index c408c8c0731de5..baf3f910b45ee8 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 5d545b366ec3e0..cc38db8071aba5 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 @@ class TUScheduler { ~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 @@ class TUScheduler { // 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 813b95aa3c824b..b047759faa47c5 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); }