Index: content/child/web_memory_dump_provider_adapter.cc |
diff --git a/content/child/web_memory_dump_provider_adapter.cc b/content/child/web_memory_dump_provider_adapter.cc |
index ef2cab810f0ab628f41333285b72440cd991f46b..b255ba2219940a29fb2417ec969dbbad29d8ef3a 100644 |
--- a/content/child/web_memory_dump_provider_adapter.cc |
+++ b/content/child/web_memory_dump_provider_adapter.cc |
@@ -4,9 +4,44 @@ |
#include "content/child/web_memory_dump_provider_adapter.h" |
+#include "base/lazy_instance.h" |
+#include "base/synchronization/lock.h" |
+#include "base/trace_event/memory_profiler_allocation_context.h" |
+#include "base/trace_event/memory_profiler_allocation_register.h" |
#include "content/child/web_process_memory_dump_impl.h" |
#include "third_party/WebKit/public/platform/WebMemoryDumpProvider.h" |
+using namespace base; |
+using namespace base::trace_event; |
+ |
+namespace { |
+ |
+AllocationRegister* g_allocation_register = nullptr; |
+LazyInstance<Lock>::Leaky g_allocation_register_lock = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+void ReportAllocation(void* address, size_t size) { |
+ // Calling |GetContextSnapshot| is only valid when |capture_enabled| is true. |
Primiano Tucci (use gerrit)
2015/10/19 21:32:03
maybe add a comment saying that you do the GetEmpt
|
+ AllocationContext context = |
+ AllocationContextTracker::capture_enabled() |
Primiano Tucci (use gerrit)
2015/10/19 21:32:03
We had a chat offline, I think that you can delete
|
+ ? AllocationContextTracker::GetContextSnapshot() |
+ : AllocationContext::GetEmpty(); |
+ |
+ AutoLock guard(g_allocation_register_lock.Get()); |
+ |
+ if (g_allocation_register) |
+ g_allocation_register->Insert(address, size, context); |
+} |
+ |
+void ReportFree(void* address) { |
+ AutoLock guard(g_allocation_register_lock.Get()); |
+ |
+ if (g_allocation_register) |
+ g_allocation_register->Remove(address); |
+} |
+ |
+} // namespace |
+ |
namespace content { |
WebMemoryDumpProviderAdapter::WebMemoryDumpProviderAdapter( |
@@ -35,7 +70,37 @@ bool WebMemoryDumpProviderAdapter::OnMemoryDump( |
} |
WebProcessMemoryDumpImpl web_pmd_impl(args.level_of_detail, pmd); |
+ if (web_memory_dump_provider_->supportsHeapProfiling()) { |
+ // TODO(ruuda): Dump |g_allocation_register| into the |ProcessMemoryDump|. |
+ } |
+ |
return web_memory_dump_provider_->onMemoryDump(level, &web_pmd_impl); |
} |
+void WebMemoryDumpProviderAdapter::OnHeapProfilingEnabled(bool enabled) { |
+ if (!web_memory_dump_provider_->supportsHeapProfiling()) |
+ return; |
+ |
+ if (enabled) { |
+ AutoLock guard(g_allocation_register_lock.Get()); |
Primiano Tucci (use gerrit)
2015/10/19 21:32:03
either put brances around here or move the lock up
|
+ |
+ if (!g_allocation_register) { |
+ g_allocation_register = new AllocationRegister(); |
+ } |
+ |
+ // Make this dump provider call the global hooks on every allocation / free. |
+ // TODO(ruuda): Because bookkeeping is done here in the adapter, and not in |
+ // the dump providers themselves, all dump providers in Blink share the |
+ // same global allocation register. At the moment this is not a problem, |
+ // because the only dump provider that supports heap profiling is the |
+ // PartitionAlloc dump provider. When Blink can depend on base and this |
+ // glue layer is removed, dump providers can have their own instance of the |
+ // allocation register. |
+ web_memory_dump_provider_->onHeapProfilingEnabled(ReportAllocation, |
+ ReportFree); |
+ } else { |
+ web_memory_dump_provider_->onHeapProfilingEnabled(nullptr, nullptr); |
+ } |
+} |
+ |
} // namespace content |