summaryrefslogtreecommitdiffstats
path: root/base/trace_event/malloc_dump_provider.cc
diff options
context:
space:
mode:
authorssid <ssid@chromium.org>2015-10-26 16:05:04 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-26 23:05:55 +0000
commit0943409e7b60ead1aa0b4f4ef8b4de5617b81917 (patch)
treedd413f523b547fa2a6be621e3251ec81563e95a4 /base/trace_event/malloc_dump_provider.cc
parent60df207a0e5a2f690ac2eabcc3f7eb8e5ae3d47b (diff)
downloadchromium_src-0943409e7b60ead1aa0b4f4ef8b4de5617b81917.zip
chromium_src-0943409e7b60ead1aa0b4f4ef8b4de5617b81917.tar.gz
chromium_src-0943409e7b60ead1aa0b4f4ef8b4de5617b81917.tar.bz2
[tracing] Fix resident size of malloc dump provider when tcmalloc is used
When tcmalloc is used the dump provider only reports the total allocated objects size as the resident size. but in reality tcmalloc uses more resident memory than the allocated objects size since it has thread cache and free list memory that are resident. It also has malloc meta data that is resident. This CL changes the resident size of malloc to include tcmalloc's page heap free list sizes, and memory used by central, transfer and thread caches. To use GetNumericProperty function from base/trace_event, new api is added in allocator_extension. It still does not include the malloc metadata bytes since it is not returned by the tcmalloc api. So this should be added in tcmalloc. BUG=546491 Review URL: https://codereview.chromium.org/1408403004 Cr-Commit-Position: refs/heads/master@{#356162}
Diffstat (limited to 'base/trace_event/malloc_dump_provider.cc')
-rw-r--r--base/trace_event/malloc_dump_provider.cc57
1 files changed, 45 insertions, 12 deletions
diff --git a/base/trace_event/malloc_dump_provider.cc b/base/trace_event/malloc_dump_provider.cc
index 28aa140..6f15a04 100644
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -6,6 +6,7 @@
#include <malloc.h>
+#include "base/allocator/allocator_extension_thunks.h"
#include "base/trace_event/process_memory_dump.h"
namespace base {
@@ -30,23 +31,55 @@ MallocDumpProvider::~MallocDumpProvider() {
// the current process.
bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
ProcessMemoryDump* pmd) {
- 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.
+ size_t total_virtual_size = 0;
+ size_t resident_size = 0;
+ size_t allocated_objects_size = 0;
+
+ allocator::thunks::GetNumericPropertyFunction get_property_function =
+ allocator::thunks::GetGetNumericPropertyFunction();
+ if (get_property_function) {
+ // If the function is not null then tcmalloc is used. See
+ // MallocExtension::getNumericProperty.
+ size_t pageheap_unmapped_bytes = 0;
+ bool res = get_property_function("generic.heap_size", &total_virtual_size);
+ DCHECK(res);
+ res = get_property_function("tcmalloc.pageheap_unmapped_bytes",
+ &pageheap_unmapped_bytes);
+ DCHECK(res);
+ res = get_property_function("generic.current_allocated_bytes",
+ &allocated_objects_size);
+ DCHECK(res);
+
+ // Please see TCMallocImplementation::GetStats implementation for
+ // explanation
+ // about this math.
+ // 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;
+ } else {
+ struct mallinfo info = mallinfo();
+ DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
+
+ // 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;
+ }
+
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;
}