kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

File-granular information is considered details.

Depends on D88411 <https://reviews.llvm.org/D88411>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88414

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h

Index: clang-tools-extra/clangd/index/FileIndex.h
===================================================================
--- clang-tools-extra/clangd/index/FileIndex.h
+++ clang-tools-extra/clangd/index/FileIndex.h
@@ -24,6 +24,7 @@
 #include "index/Relation.h"
 #include "index/Serialization.h"
 #include "index/Symbol.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -87,6 +88,8 @@
              DuplicateHandling DuplicateHandle = DuplicateHandling::PickOne,
              size_t *Version = nullptr);
 
+  MemoryTree getMemoryUsage() const;
+
 private:
   struct RefSlabAndCountReferences {
     std::shared_ptr<RefSlab> Slab;
@@ -116,6 +119,8 @@
   /// `indexMainDecls`.
   void updateMain(PathRef Path, ParsedAST &AST);
 
+  MemoryTree getMemoryUsage() const;
+
 private:
   bool UseDex; // FIXME: this should be always on.
   bool CollectMainFileRefs;
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===================================================================
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -22,6 +22,7 @@
 #include "index/SymbolOrigin.h"
 #include "index/dex/Dex.h"
 #include "support/Logger.h"
+#include "support/MemoryTree.h"
 #include "support/Path.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Index/IndexingAction.h"
@@ -373,6 +374,18 @@
   llvm_unreachable("Unknown clangd::IndexType");
 }
 
+MemoryTree FileSymbols::getMemoryUsage() const {
+  MemoryTree MT;
+  std::lock_guard<std::mutex> Lock(Mutex);
+  for (const auto &SymSlab : SymbolsSnapshot)
+    MT.addChild(SymSlab.first(), SymSlab.second->bytes());
+  for (const auto &RefSlab : RefsSnapshot)
+    MT.addChild(RefSlab.first(), RefSlab.second.Slab->bytes());
+  for (const auto &RelSlab : SymbolsSnapshot)
+    MT.addChild(RelSlab.first(), RelSlab.second->bytes());
+  return MT;
+}
+
 FileIndex::FileIndex(bool UseDex, bool CollectMainFileRefs)
     : MergedIndex(&MainFileIndex, &PreambleIndex), UseDex(UseDex),
       CollectMainFileRefs(CollectMainFileRefs),
@@ -442,5 +455,13 @@
   }
 }
 
+MemoryTree FileIndex::getMemoryUsage() const {
+  MemoryTree MT;
+  MT.addChild("preamble_symbols", PreambleSymbols.getMemoryUsage(), true);
+  MT.addChild("preamble_index", PreambleIndex.estimateMemoryUsage());
+  MT.addChild("main_file_symbols", MainFileIndex.estimateMemoryUsage());
+  MT.addChild("main_file_index", MainFileSymbols.getMemoryUsage(), true);
+  return MT;
+}
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/Background.h
===================================================================
--- clang-tools-extra/clangd/index/Background.h
+++ clang-tools-extra/clangd/index/Background.h
@@ -19,6 +19,7 @@
 #include "support/Path.h"
 #include "support/Threading.h"
 #include "support/ThreadsafeFS.h"
+#include "support/Trace.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Threading.h"
@@ -172,6 +173,8 @@
     return Queue.blockUntilIdleForTest(TimeoutSeconds);
   }
 
+  MemoryTree getMemoryUsage() const;
+
 private:
   /// Represents the state of a single file when indexing was performed.
   struct ShardVersion {
Index: clang-tools-extra/clangd/index/Background.cpp
===================================================================
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -414,5 +414,11 @@
   return {TUsToIndex.begin(), TUsToIndex.end()};
 }
 
+MemoryTree BackgroundIndex::getMemoryUsage() const {
+  MemoryTree MT;
+  MT.addChild("symbols", IndexedSymbols.getMemoryUsage(), true);
+  MT.addChild("index", estimateMemoryUsage());
+  return MT;
+}
 } // namespace clangd
 } // namespace clang
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to