Enhance clang_getCXTUResourceUsage() to report the sizes of the memory buffers used by PCH.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130460 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 65ff731..b362aa4 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -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;