Enhance clang_getCXTUResourceUsage() to return the amount of memory used by the Preprocessor's bump allocator as well as those from the PreprocessingRecord.

llvm-svn: 130823
This commit is contained in:
Ted Kremenek 2011-05-04 01:38:46 +00:00
parent 37a477f7eb
commit 2160a0d3d7
3 changed files with 30 additions and 4 deletions

View File

@ -1035,12 +1035,14 @@ enum CXTUResourceUsageKind {
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
};
/**

View File

@ -291,6 +291,10 @@ namespace clang {
/// \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;

View File

@ -5246,6 +5246,12 @@ const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) {
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 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
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 clang_getCXTUResourceUsage(CXTranslationUnit TU) {
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 };