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

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: 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/synchronization/lock.h"
8 #include "base/trace_event/memory_profiler_allocation_context.h"
9 #include "base/trace_event/memory_profiler_allocation_register.h"
7 #include "content/child/web_process_memory_dump_impl.h" 10 #include "content/child/web_process_memory_dump_impl.h"
8 #include "third_party/WebKit/public/platform/WebMemoryDumpProvider.h" 11 #include "third_party/WebKit/public/platform/WebMemoryDumpProvider.h"
9 12
13 using namespace base;
14 using namespace base::trace_event;
15
16 namespace {
17 AllocationRegister* gAllocationRegister;
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 This is still chrome-land, this should be named g_
Ruud van Asseldonk 2015/10/13 10:42:18 Done.
18 Lock* gAllocationRegisterLock;
19
20 void reportAllocation(void* address, size_t size) {
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 I would probably rename these with a locked suffix
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 Also, IIRC this should start with a capital R
Ruud van Asseldonk 2015/10/13 10:42:18 No, the caller should not have to deal with lockin
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 Ah, you are definitely right. Ignore my comment ab
21 // Calling |GetContextSnapshot| is only valid when |capture_enabled| is true.
22 AllocationContext context =
23 AllocationContextTracker::capture_enabled()
24 ? AllocationContextTracker::GetContextSnapshot()
25 : AllocationContext::Empty();
26
27 AutoLock guard(*gAllocationRegisterLock);
28 gAllocationRegister->Insert(address, size, context);
29 }
30
31 void reportFree(void* address) {
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 ditto s/report/Report/
Ruud van Asseldonk 2015/10/13 10:42:18 Done.
32 AutoLock guard(*gAllocationRegisterLock);
33 gAllocationRegister->Remove(address);
34 }
35 }
36
10 namespace content { 37 namespace content {
11 38
12 WebMemoryDumpProviderAdapter::WebMemoryDumpProviderAdapter( 39 WebMemoryDumpProviderAdapter::WebMemoryDumpProviderAdapter(
13 blink::WebMemoryDumpProvider* wmdp) 40 blink::WebMemoryDumpProvider* wmdp)
14 : web_memory_dump_provider_(wmdp), is_registered_(false) { 41 : web_memory_dump_provider_(wmdp), is_registered_(false) {
15 } 42 }
16 43
17 WebMemoryDumpProviderAdapter::~WebMemoryDumpProviderAdapter() { 44 WebMemoryDumpProviderAdapter::~WebMemoryDumpProviderAdapter() {
18 DCHECK(!is_registered_); 45 DCHECK(!is_registered_);
19 } 46 }
20 47
21 bool WebMemoryDumpProviderAdapter::OnMemoryDump( 48 bool WebMemoryDumpProviderAdapter::OnMemoryDump(
22 const base::trace_event::MemoryDumpArgs& args, 49 const base::trace_event::MemoryDumpArgs& args,
23 base::trace_event::ProcessMemoryDump* pmd) { 50 base::trace_event::ProcessMemoryDump* pmd) {
24 blink::WebMemoryDumpLevelOfDetail level; 51 blink::WebMemoryDumpLevelOfDetail level;
25 switch (args.level_of_detail) { 52 switch (args.level_of_detail) {
26 case base::trace_event::MemoryDumpLevelOfDetail::LIGHT: 53 case base::trace_event::MemoryDumpLevelOfDetail::LIGHT:
27 level = blink::WebMemoryDumpLevelOfDetail::Light; 54 level = blink::WebMemoryDumpLevelOfDetail::Light;
28 break; 55 break;
29 case base::trace_event::MemoryDumpLevelOfDetail::DETAILED: 56 case base::trace_event::MemoryDumpLevelOfDetail::DETAILED:
30 level = blink::WebMemoryDumpLevelOfDetail::Detailed; 57 level = blink::WebMemoryDumpLevelOfDetail::Detailed;
31 break; 58 break;
32 default: 59 default:
33 NOTREACHED(); 60 NOTREACHED();
34 return false; 61 return false;
35 } 62 }
36 WebProcessMemoryDumpImpl web_pmd_impl(args.level_of_detail, pmd); 63 WebProcessMemoryDumpImpl web_pmd_impl(args.level_of_detail, pmd);
37 64
65 if (web_memory_dump_provider_->supportsHeapProfiling()) {
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 Just to avoid forgetting this in future, here you
66 // TODO(ruuda): Dump |gAllocationRegister| into the |ProcessMemoryDump|.
67 }
68
38 return web_memory_dump_provider_->onMemoryDump(level, &web_pmd_impl); 69 return web_memory_dump_provider_->onMemoryDump(level, &web_pmd_impl);
39 } 70 }
40 71
72 void WebMemoryDumpProviderAdapter::OnHeapProfilingEnabled(bool enabled) {
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 I'd probably move the supportsHeapProfiling() on t
Ruud van Asseldonk 2015/10/13 10:42:18 As you wish.
73 if (enabled) {
74 // Lazily initialize the global Blink allocation register.
75 if (gAllocationRegister == nullptr) {
76 gAllocationRegister = new AllocationRegister();
Primiano Tucci (use gerrit) 2015/10/12 16:36:45 these will make LeaskSanitizer barf. Either you ne
Ruud van Asseldonk 2015/10/13 10:42:18 The proper way of doing this is to delete when hea
77 gAllocationRegisterLock = new Lock();
78 }
79
80 // Make this dump provider call the global hooks on every allocation / free.
81 // TODO(ruuda): Because bookkeeping is done here in the adapter, and not in
82 // the dump providers themselves, all dump providers in Blink share the
83 // same global allocation register. At the moment this is not a problem,
84 // because the only dump provider that supports heap profiling is the
85 // PartitionAlloc dump provider. When Blink can depend on base and this
86 // glue layer is removed, dump providers can have their own instance of the
87 // allocation register.
88 if (web_memory_dump_provider_->supportsHeapProfiling())
89 web_memory_dump_provider_->onHeapProfilingEnabled(reportAllocation,
90 reportFree);
91 } else {
92 if (web_memory_dump_provider_->supportsHeapProfiling())
93 web_memory_dump_provider_->onHeapProfilingEnabled(nullptr, nullptr);
94 }
95 }
96
41 } // namespace content 97 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698