forked from OSchip/llvm-project
Enhance clang_getCXTUResourceUsage() to report the sizes of the memory buffers used by PCH.
llvm-svn: 130460
This commit is contained in:
parent
6d003c3041
commit
5e1ed7b8dd
|
@ -1024,14 +1024,15 @@ enum CXTUResourceUsageKind {
|
|||
CXTUResourceUsage_SourceManagerContentCache = 5,
|
||||
CXTUResourceUsage_AST_SideTables = 6,
|
||||
CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
|
||||
CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
|
||||
|
||||
CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
|
||||
CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
|
||||
CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
|
||||
CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
|
||||
CXTUResourceUsage_MEMORY_IN_BYTES_END =
|
||||
CXTUResourceUsage_SourceManager_Membuffer_MMap,
|
||||
CXTUResourceUsage_ExternalASTSource_Membuffer_MMap,
|
||||
|
||||
CXTUResourceUsage_First = CXTUResourceUsage_AST,
|
||||
CXTUResourceUsage_Last = CXTUResourceUsage_SourceManager_Membuffer_MMap
|
||||
CXTUResourceUsage_Last = CXTUResourceUsage_ExternalASTSource_Membuffer_MMap
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -190,6 +190,28 @@ public:
|
|||
///
|
||||
/// The default implementation of this method is a no-op.
|
||||
virtual void PrintStats();
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Queries for performance analysis.
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
struct MemoryBufferSizes {
|
||||
size_t malloc_bytes;
|
||||
size_t mmap_bytes;
|
||||
|
||||
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
|
||||
: malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
|
||||
};
|
||||
|
||||
/// Return the amount of memory used by memory buffers, breaking down
|
||||
/// by heap-backed versus mmap'ed memory.
|
||||
MemoryBufferSizes getMemoryBufferSizes() const {
|
||||
MemoryBufferSizes sizes(0, 0);
|
||||
getMemoryBufferSizes(sizes);
|
||||
return sizes;
|
||||
}
|
||||
|
||||
virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const = 0;
|
||||
|
||||
protected:
|
||||
static DeclContextLookupResult
|
||||
|
|
|
@ -1066,6 +1066,10 @@ public:
|
|||
/// \brief Print some statistics about AST usage.
|
||||
virtual void PrintStats();
|
||||
|
||||
/// Return the amount of memory used by memory buffers, breaking down
|
||||
/// by heap-backed versus mmap'ed memory.
|
||||
virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
|
||||
|
||||
/// \brief Initialize the semantic source with the Sema instance
|
||||
/// being used to perform semantic analysis on the abstract syntax
|
||||
/// tree.
|
||||
|
|
|
@ -57,6 +57,10 @@ protected:
|
|||
virtual void StartTranslationUnit(ASTConsumer *Consumer);
|
||||
virtual void PrintStats();
|
||||
|
||||
/// Return the amount of memory used by memory buffers, breaking down
|
||||
/// by heap-backed versus mmap'ed memory.
|
||||
virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ExternalSemaSource interface.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -65,7 +69,6 @@ protected:
|
|||
virtual void ForgetSema();
|
||||
virtual std::pair<ObjCMethodList,ObjCMethodList> ReadMethodPool(Selector Sel);
|
||||
virtual bool LookupUnqualified(LookupResult &R, Scope *S);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -4053,6 +4053,23 @@ void ASTReader::PrintStats() {
|
|||
std::fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
/// Return the amount of memory used by memory buffers, breaking down
|
||||
/// by heap-backed versus mmap'ed memory.
|
||||
void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {
|
||||
for (unsigned i = 0, e = Chain.size(); i != e; ++i)
|
||||
if (llvm::MemoryBuffer *buf = Chain[i]->Buffer.get()) {
|
||||
size_t bytes = buf->getBufferSize();
|
||||
switch (buf->getBufferKind()) {
|
||||
case llvm::MemoryBuffer::MemoryBuffer_Malloc:
|
||||
sizes.malloc_bytes += bytes;
|
||||
break;
|
||||
case llvm::MemoryBuffer::MemoryBuffer_MMap:
|
||||
sizes.mmap_bytes += bytes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASTReader::InitializeSema(Sema &S) {
|
||||
SemaObj = &S;
|
||||
S.ExternalSource = this;
|
||||
|
|
|
@ -208,6 +208,16 @@ void ChainedIncludesSource::StartTranslationUnit(ASTConsumer *Consumer) {
|
|||
void ChainedIncludesSource::PrintStats() {
|
||||
return getFinalReader().PrintStats();
|
||||
}
|
||||
void ChainedIncludesSource::getMemoryBufferSizes(MemoryBufferSizes &sizes)const{
|
||||
for (unsigned i = 0, e = CIs.size(); i != e; ++i) {
|
||||
if (const ExternalASTSource *eSrc =
|
||||
CIs[i]->getASTContext().getExternalSource()) {
|
||||
eSrc->getMemoryBufferSizes(sizes);
|
||||
}
|
||||
}
|
||||
|
||||
getFinalReader().getMemoryBufferSizes(sizes);
|
||||
}
|
||||
|
||||
void ChainedIncludesSource::InitializeSema(Sema &S) {
|
||||
return getFinalReader().InitializeSema(S);
|
||||
|
|
|
@ -5232,6 +5232,12 @@ const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) {
|
|||
case CXTUResourceUsage_SourceManager_Membuffer_MMap:
|
||||
str = "SourceManager: mmap'ed memory buffers";
|
||||
break;
|
||||
case CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc:
|
||||
str = "ExternalASTSource: malloc'ed memory buffers";
|
||||
break;
|
||||
case CXTUResourceUsage_ExternalASTSource_Membuffer_MMap:
|
||||
str = "ExternalASTSource: mmap'ed memory buffers";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
@ -5284,9 +5290,22 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
|
|||
createCXTUResourceUsageEntry(*entries,
|
||||
CXTUResourceUsage_SourceManager_Membuffer_Malloc,
|
||||
(unsigned long) srcBufs.malloc_bytes);
|
||||
createCXTUResourceUsageEntry(*entries,
|
||||
createCXTUResourceUsageEntry(*entries,
|
||||
CXTUResourceUsage_SourceManager_Membuffer_MMap,
|
||||
(unsigned long) srcBufs.mmap_bytes);
|
||||
|
||||
// How much memory is being used by the ExternalASTSource?
|
||||
if (ExternalASTSource *esrc = astContext.getExternalSource()) {
|
||||
const ExternalASTSource::MemoryBufferSizes &sizes =
|
||||
esrc->getMemoryBufferSizes();
|
||||
|
||||
createCXTUResourceUsageEntry(*entries,
|
||||
CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc,
|
||||
(unsigned long) sizes.malloc_bytes);
|
||||
createCXTUResourceUsageEntry(*entries,
|
||||
CXTUResourceUsage_ExternalASTSource_Membuffer_MMap,
|
||||
(unsigned long) sizes.mmap_bytes);
|
||||
}
|
||||
|
||||
CXTUResourceUsage usage = { (void*) entries.get(),
|
||||
(unsigned) entries->size(),
|
||||
|
|
Loading…
Reference in New Issue