Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2019)

Unified Diff: base/trace_event/malloc_dump_provider.cc

Issue 1408403004: [tracing] Fix resident size of malloc dump provider when tcmalloc is used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6f15a04cfa4c14a6ef0e45de170dc8001d231188 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;
}
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698