| 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 26eb92319a23458cf2720248c5eafabb161bace5..b22c302b23f8957fcd2735fefb29ae42ed821a9d 100644
|
| --- a/base/trace_event/malloc_dump_provider.cc
|
| +++ b/base/trace_event/malloc_dump_provider.cc
|
| @@ -189,48 +189,43 @@ MallocDumpProvider::MallocDumpProvider()
|
|
|
| MallocDumpProvider::~MallocDumpProvider() {}
|
|
|
| -// Called at trace dump point time. Creates a snapshot the memory counters for
|
| -// 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;
|
| - size_t allocated_objects_count = 0;
|
| +MallocStatistics MallocDumpProvider::GetStatistics() {
|
| + MallocStatistics stats;
|
| +
|
| #if defined(USE_TCMALLOC)
|
| - bool res =
|
| - allocator::GetNumericProperty("generic.heap_size", &total_virtual_size);
|
| + bool res = allocator::GetNumericProperty("generic.heap_size",
|
| + &stats.total_virtual_size);
|
| DCHECK(res);
|
| res = allocator::GetNumericProperty("generic.total_physical_bytes",
|
| - &resident_size);
|
| + &stats.resident_size);
|
| DCHECK(res);
|
| res = allocator::GetNumericProperty("generic.current_allocated_bytes",
|
| - &allocated_objects_size);
|
| + &stats.allocated_objects_size);
|
| DCHECK(res);
|
| #elif defined(OS_MACOSX) || defined(OS_IOS)
|
| malloc_statistics_t stats = {0};
|
| malloc_zone_statistics(nullptr, &stats);
|
| - total_virtual_size = stats.size_allocated;
|
| - allocated_objects_size = stats.size_in_use;
|
| + stats.total_virtual_size = stats.size_allocated;
|
| + stats.allocated_objects_size = stats.size_in_use;
|
|
|
| // The resident size is approximated to the max size in use, which would count
|
| // the total size of all regions other than the free bytes at the end of each
|
| // region. In each allocation region the allocations are rounded off to a
|
| // fixed quantum, so the excess region will not be resident.
|
| // See crrev.com/1531463004 for detailed explanation.
|
| - resident_size = stats.max_size_in_use;
|
| + stats.resident_size = stats.max_size_in_use;
|
| #elif defined(OS_WIN)
|
| WinHeapInfo all_heap_info = {};
|
| WinHeapMemoryDumpImpl(&all_heap_info);
|
| - total_virtual_size =
|
| + stats.total_virtual_size =
|
| all_heap_info.committed_size + all_heap_info.uncommitted_size;
|
| // Resident size is approximated with committed heap size. Note that it is
|
| // possible to do this with better accuracy on windows by intersecting the
|
| // working set with the virtual memory ranges occuipied by the heap. It's not
|
| // clear that this is worth it, as it's fairly expensive to do.
|
| - resident_size = all_heap_info.committed_size;
|
| - allocated_objects_size = all_heap_info.allocated_size;
|
| - allocated_objects_count = all_heap_info.block_count;
|
| + stats.resident_size = all_heap_info.committed_size;
|
| + stats.allocated_objects_size = all_heap_info.allocated_size;
|
| + stats.allocated_objects_count = all_heap_info.block_count;
|
| #else
|
| struct mallinfo info = mallinfo();
|
| DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
|
| @@ -238,30 +233,45 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
|
| // 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;
|
| + stats.total_virtual_size = info.arena + info.hblkhd;
|
| + stats.resident_size = info.uordblks;
|
|
|
| // Total allocated space is given by |uordblks|.
|
| - allocated_objects_size = info.uordblks;
|
| + stats.allocated_objects_size = info.uordblks;
|
| #endif
|
| + if (stats.resident_size > stats.allocated_objects_size) {
|
| + // Explicitly specify why is extra memory resident. In tcmalloc it accounts
|
| + // for free lists and caches. In mac and ios it accounts for the
|
| + // fragmentation and metadata.
|
| + stats.allocated_objects_size =
|
| + stats.resident_size - stats.allocated_objects_size;
|
| + }
|
| + return stats;
|
| +}
|
| +
|
| +// Called at trace dump point time. Creates a snapshot the memory counters for
|
| +// the current process.
|
| +bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
|
| + ProcessMemoryDump* pmd) {
|
| + MallocStatistics stats = GetStatistics();
|
|
|
| MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
|
| outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes,
|
| - total_virtual_size);
|
| + stats.total_virtual_size);
|
| outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
|
| - MemoryAllocatorDump::kUnitsBytes, resident_size);
|
| + MemoryAllocatorDump::kUnitsBytes, stats.resident_size);
|
|
|
| MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects);
|
| inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
|
| MemoryAllocatorDump::kUnitsBytes,
|
| - allocated_objects_size);
|
| - if (allocated_objects_count != 0) {
|
| + stats.allocated_objects_size);
|
| + if (stats.allocated_objects_count != 0) {
|
| inner_dump->AddScalar(MemoryAllocatorDump::kNameObjectCount,
|
| MemoryAllocatorDump::kUnitsObjects,
|
| - allocated_objects_count);
|
| + stats.allocated_objects_count);
|
| }
|
|
|
| - if (resident_size > allocated_objects_size) {
|
| + if (stats.metadata_fragmentation_caches > 0) {
|
| // Explicitly specify why is extra memory resident. In tcmalloc it accounts
|
| // for free lists and caches. In mac and ios it accounts for the
|
| // fragmentation and metadata.
|
| @@ -269,7 +279,7 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
|
| pmd->CreateAllocatorDump("malloc/metadata_fragmentation_caches");
|
| other_dump->AddScalar(MemoryAllocatorDump::kNameSize,
|
| MemoryAllocatorDump::kUnitsBytes,
|
| - resident_size - allocated_objects_size);
|
| + stats.metadata_fragmentation_caches);
|
| }
|
|
|
| // Heap profiler dumps.
|
|
|