diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-07-26 23:46:11 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-07-26 23:46:11 +0000 |
commit | fbcce6fba31fa8ae689e99358e25f6a736aee286 (patch) | |
tree | dd880cd6064f3d7916d11aad832dd6e5ca67d9c7 | |
parent | 120992ad81034687bc9fe76f6a76b60d6c4539b0 (diff) | |
download | bcm5719-llvm-fbcce6fba31fa8ae689e99358e25f6a736aee286.tar.gz bcm5719-llvm-fbcce6fba31fa8ae689e99358e25f6a736aee286.zip |
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.
llvm-svn: 136190
-rw-r--r-- | clang/include/clang-c/Index.h | 5 | ||||
-rw-r--r-- | clang/include/clang/Lex/HeaderSearch.h | 10 | ||||
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 8 | ||||
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 6 |
4 files changed, 24 insertions, 5 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index ddfaa97befb..e52ed461316 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -1103,12 +1103,13 @@ enum CXTUResourceUsageKind { 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 }; /** diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 4d2ed2eccc1..b61471d6088 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -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 @@ class HeaderSearch { /// 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 @@ public: 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 diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index e2fd02983c4..789c93f2318 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -542,4 +542,10 @@ bool HeaderSearch::ShouldEnterIncludeFile(const FileEntry *File, bool isImport){ return true; } - +size_t HeaderSearch::getTotalMemory() const { + return SearchDirs.capacity() + + FileInfo.capacity() + + HeaderMaps.capacity() + + LookupFileCache.getAllocator().getTotalMemory() + + FrameworkMap.getAllocator().getTotalMemory(); +} diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 6b073f56a95..829649a7795 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -5458,6 +5458,9 @@ const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) { 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 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) { pRec->getTotalMemory()); } + createCXTUResourceUsageEntry(*entries, + CXTUResourceUsage_Preprocessor_HeaderSearch, + pp.getHeaderSearchInfo().getTotalMemory()); CXTUResourceUsage usage = { (void*) entries.get(), (unsigned) entries->size(), |