[clang-tools-extra] r333758 - [clangd] Compute better estimates for memory usage of the AST
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 1 07:44:57 PDT 2018
Author: ibiryukov
Date: Fri Jun 1 07:44:57 2018
New Revision: 333758
URL: http://llvm.org/viewvc/llvm-project?rev=333758&view=rev
Log:
[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*.
Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/TUScheduler.cpp
Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=333758&r1=333757&r2=333758&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Fri Jun 1 07:44:57 2018
@@ -220,8 +220,32 @@ std::size_t ParsedAST::getUsedBytes() co
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 {
Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=333758&r1=333757&r2=333758&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Fri Jun 1 07:44:57 2018
@@ -75,7 +75,7 @@ public:
/// Returns result of getUsedBytes() for the AST cached by \p K.
/// If no AST is cached, 0 is returned.
- bool getUsedBytes(Key K) {
+ std::size_t getUsedBytes(Key K) {
std::lock_guard<std::mutex> Lock(Mut);
auto It = findByKey(K);
if (It == LRU.end() || !It->second)
More information about the cfe-commits
mailing list