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

Side by Side 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: Preemptively address 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/web_memory_dump_provider_adapter.h" 5 #include "content/child/web_memory_dump_provider_adapter.h"
6 6
7 #include "base/lazy_instance.h"
8 #include "base/synchronization/lock.h"
9 #include "base/trace_event/memory_profiler_allocation_context.h"
10 #include "base/trace_event/memory_profiler_allocation_register.h"
7 #include "content/child/web_process_memory_dump_impl.h" 11 #include "content/child/web_process_memory_dump_impl.h"
8 #include "third_party/WebKit/public/platform/WebMemoryDumpProvider.h" 12 #include "third_party/WebKit/public/platform/WebMemoryDumpProvider.h"
9 13
14 using namespace base;
15 using namespace base::trace_event;
16
17 namespace {
18
19 AllocationRegister* g_allocation_register = nullptr;
20 LazyInstance<Lock>::Leaky g_allocation_register_lock =
21 LAZY_INSTANCE_INITIALIZER;
22
23 void ReportAllocation(void* address, size_t size) {
24 AllocationContext context = AllocationContextTracker::GetContextSnapshot();
25 AutoLock guard(g_allocation_register_lock.Get());
26
27 if (g_allocation_register)
28 g_allocation_register->Insert(address, size, context);
29 }
30
31 void ReportFree(void* address) {
32 AutoLock guard(g_allocation_register_lock.Get());
Primiano Tucci (use gerrit) 2015/10/19 21:32:03 nit: here and elsewhere s/guard/lock/ The name is
Ruud van Asseldonk 2015/10/20 11:43:57 Done.
33
34 if (g_allocation_register)
35 g_allocation_register->Remove(address);
36 }
37
38 } // namespace
39
10 namespace content { 40 namespace content {
11 41
12 WebMemoryDumpProviderAdapter::WebMemoryDumpProviderAdapter( 42 WebMemoryDumpProviderAdapter::WebMemoryDumpProviderAdapter(
13 blink::WebMemoryDumpProvider* wmdp) 43 blink::WebMemoryDumpProvider* wmdp)
14 : web_memory_dump_provider_(wmdp), is_registered_(false) { 44 : web_memory_dump_provider_(wmdp), is_registered_(false) {
15 } 45 }
16 46
17 WebMemoryDumpProviderAdapter::~WebMemoryDumpProviderAdapter() { 47 WebMemoryDumpProviderAdapter::~WebMemoryDumpProviderAdapter() {
18 DCHECK(!is_registered_); 48 DCHECK(!is_registered_);
19 } 49 }
20 50
21 bool WebMemoryDumpProviderAdapter::OnMemoryDump( 51 bool WebMemoryDumpProviderAdapter::OnMemoryDump(
22 const base::trace_event::MemoryDumpArgs& args, 52 const base::trace_event::MemoryDumpArgs& args,
23 base::trace_event::ProcessMemoryDump* pmd) { 53 base::trace_event::ProcessMemoryDump* pmd) {
24 blink::WebMemoryDumpLevelOfDetail level; 54 blink::WebMemoryDumpLevelOfDetail level;
25 switch (args.level_of_detail) { 55 switch (args.level_of_detail) {
26 case base::trace_event::MemoryDumpLevelOfDetail::LIGHT: 56 case base::trace_event::MemoryDumpLevelOfDetail::LIGHT:
27 level = blink::WebMemoryDumpLevelOfDetail::Light; 57 level = blink::WebMemoryDumpLevelOfDetail::Light;
28 break; 58 break;
29 case base::trace_event::MemoryDumpLevelOfDetail::DETAILED: 59 case base::trace_event::MemoryDumpLevelOfDetail::DETAILED:
30 level = blink::WebMemoryDumpLevelOfDetail::Detailed; 60 level = blink::WebMemoryDumpLevelOfDetail::Detailed;
31 break; 61 break;
32 default: 62 default:
33 NOTREACHED(); 63 NOTREACHED();
34 return false; 64 return false;
35 } 65 }
36 WebProcessMemoryDumpImpl web_pmd_impl(args.level_of_detail, pmd); 66 WebProcessMemoryDumpImpl web_pmd_impl(args.level_of_detail, pmd);
37 67
68 if (web_memory_dump_provider_->supportsHeapProfiling()) {
69 // TODO(ruuda): Dump |g_allocation_register| into the |ProcessMemoryDump|.
70 }
71
38 return web_memory_dump_provider_->onMemoryDump(level, &web_pmd_impl); 72 return web_memory_dump_provider_->onMemoryDump(level, &web_pmd_impl);
39 } 73 }
40 74
75 void WebMemoryDumpProviderAdapter::OnHeapProfilingEnabled(bool enabled) {
76 if (!web_memory_dump_provider_->supportsHeapProfiling())
77 return;
78
79 AutoLock guard(g_allocation_register_lock.Get());
Primiano Tucci (use gerrit) 2015/10/19 21:32:03 Can you restrict the scope of the guard only to t
Ruud van Asseldonk 2015/10/20 11:43:57 Done, changed to protect |g_allocation_register| a
80
81 if (enabled) {
82 if (!g_allocation_register)
83 g_allocation_register = new AllocationRegister();
84
85 // Make this dump provider call the global hooks on every allocation / free.
86 // TODO(ruuda): Because bookkeeping is done here in the adapter, and not in
87 // the dump providers themselves, all dump providers in Blink share the
88 // same global allocation register. At the moment this is not a problem,
89 // because the only dump provider that supports heap profiling is the
90 // PartitionAlloc dump provider. When Blink can depend on base and this
91 // glue layer is removed, dump providers can have their own instance of the
92 // allocation register.
93 web_memory_dump_provider_->onHeapProfilingEnabled(ReportAllocation,
94 ReportFree);
95 } else {
96 web_memory_dump_provider_->onHeapProfilingEnabled(nullptr, nullptr);
97 }
98 }
99
41 } // namespace content 100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698