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

Unified Diff: base/trace_event/malloc_dump_provider.cc

Issue 2890363003: Enable sharding of AllocationRegister on desktop. (Closed)
Patch Set: comment from primiano. Created 3 years, 7 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 7b3831c08d64a723d3773ba754708a3121c69e49..0e37293eac0894b84c59e8a0bba07ac487f6df89 100644
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -14,9 +14,9 @@
#include "base/debug/profiler.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"
#include "base/trace_event/heap_profiler_heap_dump_writer.h"
#include "base/trace_event/process_memory_dump.h"
+#include "base/trace_event/sharded_allocation_register.h"
#include "base/trace_event/trace_event_argument.h"
#include "build/build_config.h"
@@ -190,7 +190,8 @@ MallocDumpProvider* MallocDumpProvider::GetInstance() {
}
MallocDumpProvider::MallocDumpProvider()
- : heap_profiler_enabled_(false), tid_dumping_heap_(kInvalidThreadId) {}
+ : allocation_register_(new ShardedAllocationRegister),
+ tid_dumping_heap_(kInvalidThreadId) {}
MallocDumpProvider::~MallocDumpProvider() {}
@@ -286,7 +287,7 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
}
// Heap profiler dumps.
- if (!heap_profiler_enabled_)
+ if (!allocation_register_->IsEnabled())
return true;
// The dumps of the heap profiler should be created only when heap profiling
@@ -304,18 +305,14 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
TraceEventMemoryOverhead overhead;
std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context;
{
Primiano Tucci (use gerrit) 2017/05/22 16:37:50 at this point this {} scope delimiter is not neede
erikchen 2017/05/22 17:10:42 Done.
- AutoLock lock(allocation_register_lock_);
if (allocation_register_) {
Primiano Tucci (use gerrit) 2017/05/22 16:37:50 this condition is always going to evaluate to true
erikchen 2017/05/22 17:10:42 The condition ins already checked on line 290. Rem
if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) {
- for (const auto& alloc_size : *allocation_register_) {
- AllocationMetrics& metrics = metrics_by_context[alloc_size.context];
- metrics.size += alloc_size.size;
- metrics.count++;
-
- // Aggregate data for objects allocated through the shim.
- shim_allocated_objects_size += alloc_size.size;
- shim_allocated_objects_count++;
- }
+ ShardedAllocationRegister::OutputMetrics metrics =
+ allocation_register_->UpdateAndReturnsMetrics(metrics_by_context);
+
+ // Aggregate data for objects allocated through the shim.
+ shim_allocated_objects_size += metrics.size;
+ shim_allocated_objects_count += metrics.count;
}
allocation_register_->EstimateTraceMemoryOverhead(&overhead);
}
@@ -326,7 +323,7 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
inner_dump->AddScalar("shim_allocator_object_count",
MemoryAllocatorDump::kUnitsObjects,
shim_allocated_objects_count);
- } // lock(allocation_register_lock_)
+ }
pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc");
}
tid_dumping_heap_ = kInvalidThreadId;
@@ -337,20 +334,15 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) {
#if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
if (enabled) {
- {
- AutoLock lock(allocation_register_lock_);
- allocation_register_.reset(new AllocationRegister());
- }
+ if (!allocation_register_->IsInitialized())
Primiano Tucci (use gerrit) 2017/05/22 16:37:50 just call Initialize and early out in its implemen
erikchen 2017/05/22 17:10:42 Done.
+ allocation_register_->Initialize();
allocator::InsertAllocatorDispatch(&g_allocator_hooks);
} else {
- AutoLock lock(allocation_register_lock_);
- allocation_register_.reset();
- // Insert/RemoveAllocation below will no-op if the register is torn down.
- // Once disabled, heap profiling will not re-enabled anymore for the
- // lifetime of the process.
+ // Once we enable heap profiling, we never remove the structures from
+ // memory.
}
#endif
- heap_profiler_enabled_ = enabled;
+ allocation_register_->SetEnabled(enabled);
}
void MallocDumpProvider::InsertAllocation(void* address, size_t size) {
@@ -372,8 +364,7 @@ void MallocDumpProvider::InsertAllocation(void* address, size_t size) {
if (!tracker->GetContextSnapshot(&context))
return;
- AutoLock lock(allocation_register_lock_);
- if (!allocation_register_)
+ if (!allocation_register_->IsEnabled())
return;
allocation_register_->Insert(address, size, context);
@@ -385,8 +376,7 @@ void MallocDumpProvider::RemoveAllocation(void* address) {
if (tid_dumping_heap_ != kInvalidThreadId &&
tid_dumping_heap_ == PlatformThread::CurrentId())
return;
- AutoLock lock(allocation_register_lock_);
- if (!allocation_register_)
+ if (!allocation_register_->IsEnabled())
return;
allocation_register_->Remove(address);
}

Powered by Google App Engine
This is Rietveld 408576698