summaryrefslogtreecommitdiff
path: root/clang-tools-extra/clangd/ClangdUnit.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-06-01 14:44:57 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-06-01 14:44:57 +0000
commit0dc52ca2ede8f2644621c50e4e0c289ba0e6b4fc (patch)
tree8533e2f774feb7f8161ede7a9e575e1c9ccab402 /clang-tools-extra/clangd/ClangdUnit.cpp
parent29dab46c6fc35e02f0809f467756a7e134f7ccde (diff)
[clangd] Compute better estimates for memory usage of the AST
Also fix the return value of IdleASTs::getUsedBytes(). It was 'bool' instead of 'size_t' *facepalm*.
Diffstat (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp')
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp
index ba33f034c14..bf5de6ac34e 100644
--- a/clang-tools-extra/clangd/ClangdUnit.cpp
+++ b/clang-tools-extra/clangd/ClangdUnit.cpp
@@ -220,8 +220,32 @@ std::size_t ParsedAST::getUsedBytes() const {
auto &AST = getASTContext();
// FIXME(ibiryukov): we do not account for the dynamically allocated part of
// Message and Fixes inside each diagnostic.
- return AST.getASTAllocatedMemory() + AST.getSideTableAllocatedMemory() +
- ::getUsedBytes(LocalTopLevelDecls) + ::getUsedBytes(Diags);
+ std::size_t Total =
+ ::getUsedBytes(LocalTopLevelDecls) + ::getUsedBytes(Diags);
+
+ // FIXME: the rest of the function is almost a direct copy-paste from
+ // libclang's clang_getCXTUResourceUsage. We could share the implementation.
+
+ // Sum up variaous allocators inside the ast context and the preprocessor.
+ Total += AST.getASTAllocatedMemory();
+ Total += AST.getSideTableAllocatedMemory();
+ Total += AST.Idents.getAllocator().getTotalMemory();
+ Total += AST.Selectors.getTotalMemory();
+
+ Total += AST.getSourceManager().getContentCacheSize();
+ Total += AST.getSourceManager().getDataStructureSizes();
+ Total += AST.getSourceManager().getMemoryBufferSizes().malloc_bytes;
+
+ if (ExternalASTSource *Ext = AST.getExternalSource())
+ Total += Ext->getMemoryBufferSizes().malloc_bytes;
+
+ const Preprocessor &PP = getPreprocessor();
+ Total += PP.getTotalMemory();
+ if (PreprocessingRecord *PRec = PP.getPreprocessingRecord())
+ Total += PRec->getTotalMemory();
+ Total += PP.getHeaderSearchInfo().getTotalMemory();
+
+ return Total;
}
const std::vector<Inclusion> &ParsedAST::getInclusions() const {