Index: base/trace_event/malloc_dump_provider.cc |
diff --git a/base/trace_event/malloc_dump_provider.cc b/base/trace_event/malloc_dump_provider.cc |
index 28aa140d6702bb61c55dab49ae3be6c196078b94..acbe21130e66b9a6f778d09765010183822dc419 100644 |
--- a/base/trace_event/malloc_dump_provider.cc |
+++ b/base/trace_event/malloc_dump_provider.cc |
@@ -8,6 +8,10 @@ |
#include "base/trace_event/process_memory_dump.h" |
Primiano Tucci (use gerrit)
2015/10/26 14:25:35
please add an include "build/build_config.h", othe
ssid
2015/10/26 17:10:40
Done.
|
+#if defined(USE_TCMALLOC) |
+#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
+#endif |
+ |
namespace base { |
namespace trace_event { |
@@ -30,23 +34,50 @@ MallocDumpProvider::~MallocDumpProvider() { |
// the current process. |
bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, |
ProcessMemoryDump* pmd) { |
+ size_t total_virtual_size = 0; |
+ size_t resident_size = 0; |
+ size_t allocated_objects_size = 0; |
+ |
+#if defined(USE_TCMALLOC) |
+ size_t pageheap_unmapped_bytes = 0; |
+ bool res = MallocExtension::instance()->GetNumericProperty( |
+ "generic.heap_size", &total_virtual_size); |
+ DCHECK(res); |
+ res = MallocExtension::instance()->GetNumericProperty( |
+ "tcmalloc.pageheap_unmapped_bytes", &pageheap_unmapped_bytes); |
+ DCHECK(res); |
+ res = MallocExtension::instance()->GetNumericProperty( |
+ "generic.current_allocated_bytes", &allocated_objects_size); |
+ DCHECK(res); |
+ |
+ // TODO(ssid): Usage of metadata is not included in page heap bytes |
+ // (crbug.com/546491). MallocExtension::GetNumericProperty will be extended |
+ // to get this value. |
+ resident_size = total_virtual_size - pageheap_unmapped_bytes; |
Primiano Tucci (use gerrit)
2015/10/26 14:25:35
Maybe add a comment with a pointer to the tcmalloc
ssid
2015/10/26 17:10:40
Done.
|
+#else // defined(USE_TCMALLOC) |
+ |
struct mallinfo info = mallinfo(); |
DCHECK_GE(info.arena + info.hblkhd, info.uordblks); |
- // When the system allocator is implemented by tcmalloc, the total heap |
- // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc |
- // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of |
- // dlmalloc the total is given by |arena| + |hblkhd|. |
- // For more details see link: http://goo.gl/fMR8lF. |
+ // In case of Android's jemalloc |arena| is 0 and the outer pages size is |
+ // reported by |hblkhd|. In case of dlmalloc the total is given by |
+ // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF. |
+ total_virtual_size = info.arena + info.hblkhd; |
+ resident_size = info.uordblks; |
+ allocated_objects_size = info.uordblks; |
+#endif // defined(USE_TCMALLOC) |
+ |
MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); |
- outer_dump->AddScalar("virtual_size", |
- MemoryAllocatorDump::kUnitsBytes, |
- info.arena + info.hblkhd); |
+ outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes, |
+ total_virtual_size); |
+ outer_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
+ MemoryAllocatorDump::kUnitsBytes, resident_size); |
// Total allocated space is given by |uordblks|. |
MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); |
inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
- MemoryAllocatorDump::kUnitsBytes, info.uordblks); |
+ MemoryAllocatorDump::kUnitsBytes, |
+ allocated_objects_size); |
return true; |
} |