kadircet updated this revision to Diff 296684. kadircet marked 4 inline comments as done. kadircet added a comment.
- Rename attachMemoryUsage to profile - Split file symbols into symbols/refs/relations granularity - Rebase Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D88414/new/ 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); + void profile(MemoryTree &MT) const; + private: struct RefSlabAndCountReferences { std::shared_ptr<RefSlab> Slab; @@ -116,6 +119,8 @@ /// `indexMainDecls`. void updateMain(PathRef Path, ParsedAST &AST); + void profile(MemoryTree &MT) 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,25 @@ llvm_unreachable("Unknown clangd::IndexType"); } +void FileSymbols::profile(MemoryTree &MT) const { + std::lock_guard<std::mutex> Lock(Mutex); + for (const auto &SymSlab : SymbolsSnapshot) { + MT.detail(SymSlab.first()) + .child("symbols") + .addUsage(SymSlab.second->bytes()); + } + for (const auto &RefSlab : RefsSnapshot) { + MT.detail(RefSlab.first()) + .child("references") + .addUsage(RefSlab.second.Slab->bytes()); + } + for (const auto &RelSlab : SymbolsSnapshot) { + MT.detail(RelSlab.first()) + .child("relations") + .addUsage(RelSlab.second->bytes()); + } +} + FileIndex::FileIndex(bool UseDex, bool CollectMainFileRefs) : MergedIndex(&MainFileIndex, &PreambleIndex), UseDex(UseDex), CollectMainFileRefs(CollectMainFileRefs), @@ -442,5 +462,15 @@ } } +void FileIndex::profile(MemoryTree &MT) const { + PreambleSymbols.profile(MT.child("preamble").child("symbols")); + MT.child("preamble") + .child("index") + .addUsage(PreambleIndex.estimateMemoryUsage()); + MainFileSymbols.profile(MT.child("main_file").child("symbols")); + MT.child("main_file") + .child("index") + .addUsage(MainFileIndex.estimateMemoryUsage()); +} } // 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 @@ -16,9 +16,11 @@ #include "index/Index.h" #include "index/Serialization.h" #include "support/Context.h" +#include "support/MemoryTree.h" #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 +174,8 @@ return Queue.blockUntilIdleForTest(TimeoutSeconds); } + void profile(MemoryTree &MT) 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 @@ -16,6 +16,7 @@ #include "URI.h" #include "index/BackgroundIndexLoader.h" #include "index/FileIndex.h" +#include "index/Index.h" #include "index/IndexAction.h" #include "index/MemIndex.h" #include "index/Ref.h" @@ -414,5 +415,10 @@ return {TUsToIndex.begin(), TUsToIndex.end()}; } +void BackgroundIndex::profile(MemoryTree &MT) const { + IndexedSymbols.profile(MT.child("symbols")); + // We don't want to mix memory used by index and symbols, so call base class. + MT.child("index").addUsage(SwapIndex::estimateMemoryUsage()); +} } // namespace clangd } // namespace clang
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits