Index: third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp |
diff --git a/third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp b/third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp |
index baefa38a3657d96e2ca457172b38070de389e552..d4077870cb4a24b2248731ff0b491e088bc20cd0 100644 |
--- a/third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp |
+++ b/third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp |
@@ -7,7 +7,6 @@ |
#include <unordered_map> |
#include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
-#include "base/trace_event/heap_profiler_allocation_register.h" |
#include "base/trace_event/memory_allocator_dump.h" |
#include "base/trace_event/process_memory_dump.h" |
#include "base/trace_event/trace_event_memory_overhead.h" |
@@ -66,24 +65,16 @@ bool BlinkGCMemoryDumpProvider::OnMemoryDump( |
BlinkGC::kForcedGC); |
DumpMemoryTotals(memory_dump); |
- if (is_heap_profiling_enabled_) { |
+ if (allocation_register_.is_enabled()) { |
// Overhead should always be reported, regardless of light vs. heavy. |
base::trace_event::TraceEventMemoryOverhead overhead; |
std::unordered_map<base::trace_event::AllocationContext, |
base::trace_event::AllocationMetrics> |
metrics_by_context; |
- { |
- MutexLocker locker(allocation_register_mutex_); |
- if (level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { |
- for (const auto& alloc_size : *allocation_register_) { |
- base::trace_event::AllocationMetrics& metrics = |
- metrics_by_context[alloc_size.context]; |
- metrics.size += alloc_size.size; |
- metrics.count++; |
- } |
- } |
- allocation_register_->EstimateTraceMemoryOverhead(&overhead); |
+ if (level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { |
+ allocation_register_.UpdateAndReturnsMetrics(metrics_by_context); |
} |
+ allocation_register_.EstimateTraceMemoryOverhead(&overhead); |
memory_dump->DumpHeapUsage(metrics_by_context, overhead, "blink_gc"); |
} |
@@ -95,18 +86,14 @@ bool BlinkGCMemoryDumpProvider::OnMemoryDump( |
void BlinkGCMemoryDumpProvider::OnHeapProfilingEnabled(bool enabled) { |
if (enabled) { |
- { |
- MutexLocker locker(allocation_register_mutex_); |
- if (!allocation_register_) |
- allocation_register_.reset(new base::trace_event::AllocationRegister()); |
- } |
+ allocation_register_.SetEnabled(); |
HeapAllocHooks::SetAllocationHook(ReportAllocation); |
HeapAllocHooks::SetFreeHook(ReportFree); |
} else { |
HeapAllocHooks::SetAllocationHook(nullptr); |
HeapAllocHooks::SetFreeHook(nullptr); |
+ allocation_register_.SetDisabled(); |
} |
- is_heap_profiling_enabled_ = enabled; |
} |
base::trace_event::MemoryAllocatorDump* |
@@ -124,8 +111,7 @@ void BlinkGCMemoryDumpProvider::ClearProcessDumpForCurrentGC() { |
BlinkGCMemoryDumpProvider::BlinkGCMemoryDumpProvider() |
: current_process_memory_dump_(new base::trace_event::ProcessMemoryDump( |
nullptr, |
- {base::trace_event::MemoryDumpLevelOfDetail::DETAILED})), |
- is_heap_profiling_enabled_(false) {} |
+ {base::trace_event::MemoryDumpLevelOfDetail::DETAILED})) {} |
void BlinkGCMemoryDumpProvider::insert(Address address, |
size_t size, |
@@ -136,15 +122,15 @@ void BlinkGCMemoryDumpProvider::insert(Address address, |
->GetContextSnapshot(&context)) |
return; |
context.type_name = type_name; |
- MutexLocker locker(allocation_register_mutex_); |
- if (allocation_register_) |
- allocation_register_->Insert(address, size, context); |
+ if (!allocation_register_.is_enabled()) |
+ return; |
+ allocation_register_.Insert(address, size, context); |
} |
void BlinkGCMemoryDumpProvider::Remove(Address address) { |
- MutexLocker locker(allocation_register_mutex_); |
- if (allocation_register_) |
- allocation_register_->Remove(address); |
+ if (!allocation_register_.is_enabled()) |
+ return; |
+ allocation_register_.Remove(address); |
} |
} // namespace blink |