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

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: 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 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* g_allocation_register;
18 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.
19
20 void ReportAllocation(void* address, size_t size) {
21 // Calling |GetContextSnapshot| is only valid when |capture_enabled| is true.
22 AllocationContext context =
23 AllocationContextTracker::capture_enabled()
24 ? AllocationContextTracker::GetContextSnapshot()
25 : AllocationContext::GetEmpty();
26
27 AutoLock guard(*g_allocation_register_lock);
28 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.
29 }
30
31 void ReportFree(void* address) {
32 AutoLock guard(*g_allocation_register_lock);
33 g_allocation_register->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()) {
66 // TODO(ruuda): Dump |g_allocation_register| 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) {
73 if (!web_memory_dump_provider_->supportsHeapProfiling())
74 return;
75
76 if (enabled) {
77 // Lazily initialize the global Blink allocation register.
78 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.
79 g_allocation_register = new AllocationRegister();
80 g_allocation_register_lock = new Lock();
81 }
82
83 // Make this dump provider call the global hooks on every allocation / free.
84 // TODO(ruuda): Because bookkeeping is done here in the adapter, and not in
85 // the dump providers themselves, all dump providers in Blink share the
86 // same global allocation register. At the moment this is not a problem,
87 // because the only dump provider that supports heap profiling is the
88 // PartitionAlloc dump provider. When Blink can depend on base and this
89 // glue layer is removed, dump providers can have their own instance of the
90 // allocation register.
91 web_memory_dump_provider_->onHeapProfilingEnabled(ReportAllocation,
92 ReportFree);
93 } else {
94 web_memory_dump_provider_->onHeapProfilingEnabled(nullptr, nullptr);
95 }
96 }
97
41 } // namespace content 98 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698