[cfe-commits] r136190 - in /cfe/trunk: include/clang-c/Index.h include/clang/Lex/HeaderSearch.h lib/Lex/HeaderSearch.cpp tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Tue Jul 26 16:46:12 PDT 2011


Author: kremenek
Date: Tue Jul 26 18:46:11 2011
New Revision: 136190

URL: http://llvm.org/viewvc/llvm-project?rev=136190&view=rev
Log:
clang_getCXTUResourceUsage: report memory used by HeaderSearch.

This required converting the StringMaps to use a BumpPtrAllocator.  I measured the
compile time and saw no observable regression.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/lib/Lex/HeaderSearch.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=136190&r1=136189&r2=136190&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Jul 26 18:46:11 2011
@@ -1103,12 +1103,13 @@
   CXTUResourceUsage_Preprocessor = 11,
   CXTUResourceUsage_PreprocessingRecord = 12,
   CXTUResourceUsage_SourceManager_DataStructures = 13,
+  CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
   CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
   CXTUResourceUsage_MEMORY_IN_BYTES_END =
-    CXTUResourceUsage_SourceManager_DataStructures,
+    CXTUResourceUsage_Preprocessor_HeaderSearch,
 
   CXTUResourceUsage_First = CXTUResourceUsage_AST,
-  CXTUResourceUsage_Last = CXTUResourceUsage_SourceManager_DataStructures
+  CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
 };
 
 /**

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=136190&r1=136189&r2=136190&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Tue Jul 26 18:46:11 2011
@@ -16,6 +16,7 @@
 
 #include "clang/Lex/DirectoryLookup.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/Support/Allocator.h"
 #include <vector>
 
 namespace clang {
@@ -125,12 +126,14 @@
   /// and this value doesn't match the current query, the cache has to be
   /// ignored.  The second value is the entry in SearchDirs that satisfied the
   /// query.
-  llvm::StringMap<std::pair<unsigned, unsigned> > LookupFileCache;
+  llvm::StringMap<std::pair<unsigned, unsigned>, llvm::BumpPtrAllocator>
+    LookupFileCache;
 
 
   /// FrameworkMap - This is a collection mapping a framework or subframework
   /// name like "Carbon" to the Carbon.framework directory.
-  llvm::StringMap<const DirectoryEntry *> FrameworkMap;
+  llvm::StringMap<const DirectoryEntry *, llvm::BumpPtrAllocator>
+    FrameworkMap;
 
   /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
   /// headermaps.  This vector owns the headermap.
@@ -323,6 +326,9 @@
   search_dir_iterator system_dir_end() const { return SearchDirs.end(); }
 
   void PrintStats();
+  
+  size_t getTotalMemory() const;
+
 private:
 
   /// getFileInfo - Return the HeaderFileInfo structure for the specified

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=136190&r1=136189&r2=136190&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Tue Jul 26 18:46:11 2011
@@ -542,4 +542,10 @@
   return true;
 }
 
-
+size_t HeaderSearch::getTotalMemory() const {
+  return SearchDirs.capacity()
+    + FileInfo.capacity()
+    + HeaderMaps.capacity()
+    + LookupFileCache.getAllocator().getTotalMemory()
+    + FrameworkMap.getAllocator().getTotalMemory();
+}

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=136190&r1=136189&r2=136190&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 26 18:46:11 2011
@@ -5458,6 +5458,9 @@
     case CXTUResourceUsage_SourceManager_DataStructures:
       str = "SourceManager: data structures and tables";
       break;
+    case CXTUResourceUsage_Preprocessor_HeaderSearch:
+      str = "Preprocessor: header search tables";
+      break;
   }
   return str;
 }
@@ -5543,6 +5546,9 @@
                                  pRec->getTotalMemory());    
   }
   
+  createCXTUResourceUsageEntry(*entries,
+                               CXTUResourceUsage_Preprocessor_HeaderSearch,
+                               pp.getHeaderSearchInfo().getTotalMemory());
   
   CXTUResourceUsage usage = { (void*) entries.get(),
                             (unsigned) entries->size(),





More information about the cfe-commits mailing list