[clang-tools-extra] 23a5330 - [clangd] Introduce memory usage dumping to TUScheduler, for Preambles and ASTCache

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 12 06:27:25 PDT 2020


Author: Kadir Cetinkaya
Date: 2020-10-12T15:25:29+02:00
New Revision: 23a53301c545b45a6c809cc3f444c5f4e577f6c0

URL: https://github.com/llvm/llvm-project/commit/23a53301c545b45a6c809cc3f444c5f4e577f6c0
DIFF: https://github.com/llvm/llvm-project/commit/23a53301c545b45a6c809cc3f444c5f4e577f6c0.diff

LOG: [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

Added: 
    

Modified: 
    clang-tools-extra/clangd/TUScheduler.cpp
    clang-tools-extra/clangd/TUScheduler.h
    clang-tools-extra/clangd/unittests/ClangdTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index c408c8c0731d..baf3f910b45e 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 5d545b366ec3..cc38db8071ab 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<llvm::StringRef> 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 813b95aa3c82..b047759faa47 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);
 }


        


More information about the cfe-commits mailing list