diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 341e49a512..6b6e7bf242 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -1021,13 +1021,14 @@ enum CXTUResourceUsageKind { CXTUResourceUsage_Identifiers = 2, CXTUResourceUsage_Selectors = 3, CXTUResourceUsage_GlobalCompletionResults = 4, + CXTUResourceUsage_SourceManagerContentCache = 5, CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST, CXTUResourceUsage_MEMORY_IN_BYTES_END = - CXTUResourceUsage_GlobalCompletionResults, + CXTUResourceUsage_SourceManagerContentCache, CXTUResourceUsage_First = CXTUResourceUsage_AST, - CXTUResourceUsage_Last = CXTUResourceUsage_GlobalCompletionResults + CXTUResourceUsage_Last = CXTUResourceUsage_SourceManagerContentCache }; /** diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 653142dbee..1907ed5cc6 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -849,6 +849,16 @@ public: /// \brief Retrieve the stored line table. LineTableInfo &getLineTable(); + //===--------------------------------------------------------------------===// + // Queries for performance analysis. + //===--------------------------------------------------------------------===// + + /// Return the total amount of physical memory allocated by the + /// ContentCache allocator. + size_t getContentCacheSize() const { + return ContentCacheAlloc.getTotalMemory(); + } + //===--------------------------------------------------------------------===// // Other miscellaneous methods. //===--------------------------------------------------------------------===// diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 673f3eb509..c72d49634b 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -5220,6 +5220,9 @@ const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) { case CXTUResourceUsage_GlobalCompletionResults: str = "Code completion: cached global results"; break; + case CXTUResourceUsage_SourceManagerContentCache: + str = "SourceManager: content cache allocator"; + break; } return str; } @@ -5252,8 +5255,14 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) { astUnit->getCachedCompletionAllocator().getPtr()) { completionBytes = completionAllocator-> getTotalMemory(); } - createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_GlobalCompletionResults, - completionBytes); + createCXTUResourceUsageEntry(*entries, + CXTUResourceUsage_GlobalCompletionResults, + completionBytes); + + // How much memory is being used by SourceManager's content cache? + createCXTUResourceUsageEntry(*entries, + CXTUResourceUsage_SourceManagerContentCache, + (unsigned long) astContext.getSourceManager().getContentCacheSize()); CXTUResourceUsage usage = { (void*) entries.get(),