[cfe-commits] r130823 - in /cfe/trunk: include/clang-c/Index.h include/clang/Lex/PreprocessingRecord.h tools/libclang/CIndex.cpp
Ted Kremenek
kremenek at apple.com
Tue May 3 18:38:47 PDT 2011
Author: kremenek
Date: Tue May 3 20:38:46 2011
New Revision: 130823
URL: http://llvm.org/viewvc/llvm-project?rev=130823&view=rev
Log:
Enhance clang_getCXTUResourceUsage() to return the amount of memory used by the Preprocessor's bump allocator as well as those from the PreprocessingRecord.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
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=130823&r1=130822&r2=130823&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue May 3 20:38:46 2011
@@ -1035,12 +1035,14 @@
CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
+ CXTUResourceUsage_Preprocessor = 11,
+ CXTUResourceUsage_PreprocessingRecord = 12,
CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
CXTUResourceUsage_MEMORY_IN_BYTES_END =
- CXTUResourceUsage_ExternalASTSource_Membuffer_MMap,
+ CXTUResourceUsage_PreprocessingRecord,
CXTUResourceUsage_First = CXTUResourceUsage_AST,
- CXTUResourceUsage_Last = CXTUResourceUsage_ExternalASTSource_Membuffer_MMap
+ CXTUResourceUsage_Last = CXTUResourceUsage_PreprocessingRecord
};
/**
Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=130823&r1=130822&r2=130823&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Tue May 3 20:38:46 2011
@@ -291,6 +291,10 @@
/// \brief Deallocate memory in the preprocessing record.
void Deallocate(void *Ptr) { }
+ size_t getTotalMemory() const {
+ return BumpAlloc.getTotalMemory();
+ }
+
// Iteration over the preprocessed entities.
typedef std::vector<PreprocessedEntity *>::iterator iterator;
typedef std::vector<PreprocessedEntity *>::const_iterator const_iterator;
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=130823&r1=130822&r2=130823&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue May 3 20:38:46 2011
@@ -5246,6 +5246,12 @@
case CXTUResourceUsage_ExternalASTSource_Membuffer_MMap:
str = "ExternalASTSource: mmap'ed memory buffers";
break;
+ case CXTUResourceUsage_Preprocessor:
+ str = "Preprocessor: malloc'ed memory";
+ break;
+ case CXTUResourceUsage_PreprocessingRecord:
+ str = "Preprocessor: PreprocessingRecord";
+ break;
}
return str;
}
@@ -5280,7 +5286,7 @@
unsigned long completionBytes = 0;
if (GlobalCodeCompletionAllocator *completionAllocator =
astUnit->getCachedCompletionAllocator().getPtr()) {
- completionBytes = completionAllocator-> getTotalMemory();
+ completionBytes = completionAllocator->getTotalMemory();
}
createCXTUResourceUsageEntry(*entries,
CXTUResourceUsage_GlobalCompletionResults,
@@ -5314,7 +5320,21 @@
CXTUResourceUsage_ExternalASTSource_Membuffer_MMap,
(unsigned long) sizes.mmap_bytes);
}
-
+
+ // How much memory is being used by the Preprocessor?
+ Preprocessor &pp = astUnit->getPreprocessor();
+ const llvm::BumpPtrAllocator &ppAlloc = pp.getPreprocessorAllocator();
+ createCXTUResourceUsageEntry(*entries,
+ CXTUResourceUsage_Preprocessor,
+ ppAlloc.getTotalMemory());
+
+ if (PreprocessingRecord *pRec = pp.getPreprocessingRecord()) {
+ createCXTUResourceUsageEntry(*entries,
+ CXTUResourceUsage_PreprocessingRecord,
+ pRec->getTotalMemory());
+ }
+
+
CXTUResourceUsage usage = { (void*) entries.get(),
(unsigned) entries->size(),
entries->size() ? &(*entries)[0] : 0 };
More information about the cfe-commits
mailing list