[cfe-commits] r130460 - in /cfe/trunk: include/clang-c/Index.h include/clang/AST/ExternalASTSource.h include/clang/Serialization/ASTReader.h include/clang/Serialization/ChainedIncludesSource.h lib/Serialization/ASTReader.cpp lib/Serialization/ChainedIncludesSource.cpp tools/libclang/CIndex.cpp
Ted Kremenek
kremenek at apple.com
Thu Apr 28 16:46:20 PDT 2011
Author: kremenek
Date: Thu Apr 28 18:46:20 2011
New Revision: 130460
URL: http://llvm.org/viewvc/llvm-project?rev=130460&view=rev
Log:
Enhance clang_getCXTUResourceUsage() to report the sizes of the memory buffers used by PCH.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/AST/ExternalASTSource.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ChainedIncludesSource.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=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Apr 28 18:46:20 2011
@@ -1024,14 +1024,15 @@
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
};
/**
Modified: cfe/trunk/include/clang/AST/ExternalASTSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTSource.h?rev=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Thu Apr 28 18:46:20 2011
@@ -190,6 +190,28 @@
///
/// 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
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Apr 28 18:46:20 2011
@@ -1066,6 +1066,10 @@
/// \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.
Modified: cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h?rev=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h (original)
+++ cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h Thu Apr 28 18:46:20 2011
@@ -57,6 +57,10 @@
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 @@
virtual void ForgetSema();
virtual std::pair<ObjCMethodList,ObjCMethodList> ReadMethodPool(Selector Sel);
virtual bool LookupUnqualified(LookupResult &R, Scope *S);
-
};
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Apr 28 18:46:20 2011
@@ -4053,6 +4053,23 @@
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;
Modified: cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp?rev=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp (original)
+++ cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp Thu Apr 28 18:46:20 2011
@@ -208,6 +208,16 @@
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);
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=130460&r1=130459&r2=130460&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Apr 28 18:46:20 2011
@@ -5232,6 +5232,12 @@
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 @@
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(),
More information about the cfe-commits
mailing list