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

Unified Diff: content/child/web_memory_dump_provider_adapter.cc

Issue 1391933004: [Tracing] Add hook to PartitionAlloc for heap profiling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address some primiano comments 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
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..00a52cbb64a482de230bbc2bc94c7dd3ebffeeac 100644
--- a/content/child/web_memory_dump_provider_adapter.cc
+++ b/content/child/web_memory_dump_provider_adapter.cc
@@ -4,9 +4,36 @@
#include "content/child/web_memory_dump_provider_adapter.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;
+Lock* g_allocation_register_lock;
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 After discussion offline, the lock should really b
Ruud van Asseldonk 2015/10/14 12:30:18 Done.
+
+void ReportAllocation(void* address, size_t size) {
+ // Calling |GetContextSnapshot| is only valid when |capture_enabled| is true.
+ AllocationContext context =
+ AllocationContextTracker::capture_enabled()
+ ? AllocationContextTracker::GetContextSnapshot()
+ : AllocationContext::GetEmpty();
+
+ AutoLock guard(*g_allocation_register_lock);
+ g_allocation_register->Insert(address, size, context);
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 null-check for the register before using it same b
Ruud van Asseldonk 2015/10/14 12:30:18 Done.
+}
+
+void ReportFree(void* address) {
+ AutoLock guard(*g_allocation_register_lock);
+ g_allocation_register->Remove(address);
+}
+}
+
namespace content {
WebMemoryDumpProviderAdapter::WebMemoryDumpProviderAdapter(
@@ -35,7 +62,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) {
+ // Lazily initialize the global Blink allocation register.
+ if (g_allocation_register == nullptr) {
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 take the lock here
Ruud van Asseldonk 2015/10/14 12:30:18 Done.
+ g_allocation_register = new AllocationRegister();
+ g_allocation_register_lock = new Lock();
+ }
+
+ // 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

Powered by Google App Engine
This is Rietveld 408576698