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

Unified Diff: base/trace_event/malloc_dump_provider.cc

Issue 2350423003: [Tentaive patch for discussion] Add Purge+Suspend metrics as UMA.
Patch Set: Add malloc_statistics Created 4 years, 3 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
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..807d36016647ea4d2b53b4296d9f15081ac21299 100644
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -10,6 +10,7 @@
#include "base/allocator/allocator_shim.h"
#include "base/allocator/features.h"
#include "base/debug/profiler.h"
+#include "base/memory/malloc_statistics.h"
#include "base/trace_event/heap_profiler_allocation_context.h"
#include "base/trace_event/heap_profiler_allocation_context_tracker.h"
#include "base/trace_event/heap_profiler_allocation_register.h"
@@ -193,75 +194,26 @@ 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;
- size_t allocated_objects_count = 0;
-#if defined(USE_TCMALLOC)
- bool res =
- allocator::GetNumericProperty("generic.heap_size", &total_virtual_size);
- DCHECK(res);
- res = allocator::GetNumericProperty("generic.total_physical_bytes",
- &resident_size);
- DCHECK(res);
- res = allocator::GetNumericProperty("generic.current_allocated_bytes",
- &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;
-
- // 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;
-#elif defined(OS_WIN)
- WinHeapInfo all_heap_info = {};
- WinHeapMemoryDumpImpl(&all_heap_info);
- 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;
-#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;
-
- // Total allocated space is given by |uordblks|.
- allocated_objects_size = info.uordblks;
-#endif
+ base::memory::MallocStatistics stats =
+ base::memory::MallocStatistics::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 +221,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.

Powered by Google App Engine
This is Rietveld 408576698