aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-04-28 04:53:38 +0000
committerTed Kremenek <kremenek@apple.com>2011-04-28 04:53:38 +0000
commitba29bd25515fbd99e98ba0fedb9d93617b27609e (patch)
tree8cd565dfcb7ec193f26ce6294f3b2ed216d4a1e2
parenta97d24f2ca50f318f62a6cf2a621e7842dd63b4a (diff)
Enhance clang_getCXTUResourceUsage() to report the amount of memory used by ASTContext's side tables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130383 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang-c/Index.h5
-rw-r--r--include/clang/AST/ASTContext.h4
-rw-r--r--lib/AST/ASTContext.cpp16
-rw-r--r--tools/libclang/CIndex.cpp11
4 files changed, 31 insertions, 5 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 6b6e7bf242..14f4cc4819 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -1022,13 +1022,14 @@ enum CXTUResourceUsageKind {
CXTUResourceUsage_Selectors = 3,
CXTUResourceUsage_GlobalCompletionResults = 4,
CXTUResourceUsage_SourceManagerContentCache = 5,
+ CXTUResourceUsage_AST_SideTables = 6,
CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
CXTUResourceUsage_MEMORY_IN_BYTES_END =
- CXTUResourceUsage_SourceManagerContentCache,
+ CXTUResourceUsage_AST_SideTables,
CXTUResourceUsage_First = CXTUResourceUsage_AST,
- CXTUResourceUsage_Last = CXTUResourceUsage_SourceManagerContentCache
+ CXTUResourceUsage_Last = CXTUResourceUsage_AST_SideTables
};
/**
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 9c3cfe73b2..ad02aac360 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -344,9 +344,11 @@ public:
/// Return the total amount of physical memory allocated for representing
/// AST nodes and type information.
- size_t getTotalAllocatedMemory() const {
+ size_t getASTAllocatedMemory() const {
return BumpAlloc.getTotalMemory();
}
+ /// Return the total memory used for various side tables.
+ size_t getSideTableAllocatedMemory() const;
PartialDiagnostic::StorageAllocator &getDiagAllocator() {
return DiagAllocator;
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index c571c559bc..13c40f7ca1 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -6139,3 +6139,19 @@ MangleContext *ASTContext::createMangleContext() {
}
CXXABI::~CXXABI() {}
+
+size_t ASTContext::getSideTableAllocatedMemory() const {
+ size_t bytes = 0;
+ bytes += ASTRecordLayouts.getMemorySize();
+ bytes += ObjCLayouts.getMemorySize();
+ bytes += KeyFunctions.getMemorySize();
+ bytes += ObjCImpls.getMemorySize();
+ bytes += BlockVarCopyInits.getMemorySize();
+ bytes += DeclAttrs.getMemorySize();
+ bytes += InstantiatedFromStaticDataMember.getMemorySize();
+ bytes += InstantiatedFromUsingDecl.getMemorySize();
+ bytes += InstantiatedFromUsingShadowDecl.getMemorySize();
+ bytes += InstantiatedFromUnnamedFieldDecl.getMemorySize();
+ return bytes;
+}
+
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index c72d49634b..26e4af4049 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -5198,7 +5198,7 @@ typedef std::vector<CXTUResourceUsageEntry> MemUsageEntries;
static inline void createCXTUResourceUsageEntry(MemUsageEntries &entries,
enum CXTUResourceUsageKind k,
- double amount) {
+ unsigned long amount) {
CXTUResourceUsageEntry entry = { k, amount };
entries.push_back(entry);
}
@@ -5223,6 +5223,9 @@ const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) {
case CXTUResourceUsage_SourceManagerContentCache:
str = "SourceManager: content cache allocator";
break;
+ case CXTUResourceUsage_AST_SideTables:
+ str = "ASTContext: side tables";
+ break;
}
return str;
}
@@ -5239,7 +5242,7 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
// How much memory is used by AST nodes and types?
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST,
- (unsigned long) astContext.getTotalAllocatedMemory());
+ (unsigned long) astContext.getASTAllocatedMemory());
// How much memory is used by identifiers?
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Identifiers,
@@ -5249,6 +5252,10 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Selectors,
(unsigned long) astContext.Selectors.getTotalMemory());
+ // How much memory is used by ASTContext's side tables?
+ createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST_SideTables,
+ (unsigned long) astContext.getSideTableAllocatedMemory());
+
// How much memory is used for caching global code completion results?
unsigned long completionBytes = 0;
if (GlobalCodeCompletionAllocator *completionAllocator =