[cfe-commits] r130383 - in /cfe/trunk: include/clang-c/Index.h include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Wed Apr 27 21:53:38 PDT 2011


Author: kremenek
Date: Wed Apr 27 23:53:38 2011
New Revision: 130383

URL: http://llvm.org/viewvc/llvm-project?rev=130383&view=rev
Log:
Enhance clang_getCXTUResourceUsage() to report the amount of memory used by ASTContext's side tables.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=130383&r1=130382&r2=130383&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Apr 27 23:53:38 2011
@@ -1022,13 +1022,14 @@
   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
 };
 
 /**

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=130383&r1=130382&r2=130383&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Apr 27 23:53:38 2011
@@ -344,9 +344,11 @@
   
   /// 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;

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=130383&r1=130382&r2=130383&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Apr 27 23:53:38 2011
@@ -6139,3 +6139,19 @@
 }
 
 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;
+}
+

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=130383&r1=130382&r2=130383&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Apr 27 23:53:38 2011
@@ -5198,7 +5198,7 @@
 
 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 @@
     case CXTUResourceUsage_SourceManagerContentCache:
       str = "SourceManager: content cache allocator";
       break;
+    case CXTUResourceUsage_AST_SideTables:
+      str = "ASTContext: side tables";
+      break;
   }
   return str;
 }
@@ -5239,7 +5242,7 @@
   
   // 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 @@
   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 =





More information about the cfe-commits mailing list