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

Side by Side Diff: third_party/WebKit/Source/platform/web_process_memory_dump.cc

Issue 2028483002: Remove abstract classes for memory dumper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 "platform/web_process_memory_dump_impl.h" 5 #include "platform/web_process_memory_dump.h"
6 6
7 #include "base/memory/discardable_memory.h" 7 #include "base/memory/discardable_memory.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/heap_profiler_heap_dump_writer.h" 10 #include "base/trace_event/heap_profiler_heap_dump_writer.h"
11 #include "base/trace_event/process_memory_dump.h" 11 #include "base/trace_event/process_memory_dump.h"
12 #include "base/trace_event/trace_event_argument.h" 12 #include "base/trace_event/trace_event_argument.h"
13 #include "base/trace_event/trace_event_memory_overhead.h" 13 #include "base/trace_event/trace_event_memory_overhead.h"
14 #include "platform/web_memory_allocator_dump_impl.h" 14 #include "platform/web_memory_allocator_dump.h"
15 #include "skia/ext/skia_trace_memory_dump_impl.h" 15 #include "skia/ext/skia_trace_memory_dump_impl.h"
16 #include "wtf/text/StringUTF8Adaptor.h"
16 17
17 #include <stddef.h> 18 #include <stddef.h>
18 19
19 namespace blink { 20 namespace blink {
20 21
21 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl() 22 WebProcessMemoryDump::WebProcessMemoryDump()
22 : owned_process_memory_dump_( 23 : owned_process_memory_dump_(
23 new base::trace_event::ProcessMemoryDump(nullptr)), 24 new base::trace_event::ProcessMemoryDump(nullptr)),
24 process_memory_dump_(owned_process_memory_dump_.get()), 25 process_memory_dump_(owned_process_memory_dump_.get()),
25 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {} 26 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {}
26 27
27 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl( 28 WebProcessMemoryDump::WebProcessMemoryDump(
28 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, 29 base::trace_event::MemoryDumpLevelOfDetail level_of_detail,
29 base::trace_event::ProcessMemoryDump* process_memory_dump) 30 base::trace_event::ProcessMemoryDump* process_memory_dump)
30 : process_memory_dump_(process_memory_dump), 31 : process_memory_dump_(process_memory_dump),
31 level_of_detail_(level_of_detail) {} 32 level_of_detail_(level_of_detail) {}
32 33
33 WebProcessMemoryDumpImpl::~WebProcessMemoryDumpImpl() { 34 WebProcessMemoryDump::~WebProcessMemoryDump() {
34 } 35 }
35 36
36 blink::WebMemoryAllocatorDump* 37 blink::WebMemoryAllocatorDump*
37 WebProcessMemoryDumpImpl::createMemoryAllocatorDump( 38 WebProcessMemoryDump::createMemoryAllocatorDump(
38 const blink::WebString& absolute_name) { 39 const String& absolute_name) {
40 StringUTF8Adaptor adapter(absolute_name);
41 std::string name(adapter.data(), adapter.length());
39 // Get a MemoryAllocatorDump from the base/ object. 42 // Get a MemoryAllocatorDump from the base/ object.
40 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = 43 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
41 process_memory_dump_->CreateAllocatorDump(absolute_name.utf8()); 44 process_memory_dump_->CreateAllocatorDump(name);
42 45
43 return createWebMemoryAllocatorDump(memory_allocator_dump); 46 return createWebMemoryAllocatorDump(memory_allocator_dump);
44 } 47 }
45 48
46 blink::WebMemoryAllocatorDump* 49 blink::WebMemoryAllocatorDump*
47 WebProcessMemoryDumpImpl::createMemoryAllocatorDump( 50 WebProcessMemoryDump::createMemoryAllocatorDump(
48 const blink::WebString& absolute_name, 51 const String& absolute_name,
49 blink::WebMemoryAllocatorDumpGuid guid) { 52 blink::WebMemoryAllocatorDumpGuid guid) {
53 StringUTF8Adaptor adapter(absolute_name);
54 std::string name(adapter.data(), adapter.length());
50 // Get a MemoryAllocatorDump from the base/ object with given guid. 55 // Get a MemoryAllocatorDump from the base/ object with given guid.
51 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = 56 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
52 process_memory_dump_->CreateAllocatorDump( 57 process_memory_dump_->CreateAllocatorDump(
53 absolute_name.utf8(), 58 name,
54 base::trace_event::MemoryAllocatorDumpGuid(guid)); 59 base::trace_event::MemoryAllocatorDumpGuid(guid));
55 return createWebMemoryAllocatorDump(memory_allocator_dump); 60 return createWebMemoryAllocatorDump(memory_allocator_dump);
56 } 61 }
57 62
58 blink::WebMemoryAllocatorDump* 63 blink::WebMemoryAllocatorDump*
59 WebProcessMemoryDumpImpl::createWebMemoryAllocatorDump( 64 WebProcessMemoryDump::createWebMemoryAllocatorDump(
60 base::trace_event::MemoryAllocatorDump* memory_allocator_dump) { 65 base::trace_event::MemoryAllocatorDump* memory_allocator_dump) {
61 if (!memory_allocator_dump) 66 if (!memory_allocator_dump)
62 return nullptr; 67 return nullptr;
63 68
64 // Wrap it and return to blink. 69 // Wrap it and return to blink.
65 WebMemoryAllocatorDumpImpl* web_memory_allocator_dump_impl = 70 WebMemoryAllocatorDump* web_memory_allocator_dump =
66 new WebMemoryAllocatorDumpImpl(memory_allocator_dump); 71 new WebMemoryAllocatorDump(memory_allocator_dump);
67 72
68 // memory_allocator_dumps_ will take ownership of 73 // memory_allocator_dumps_ will take ownership of
69 // |web_memory_allocator_dumpd_impl|. 74 // |web_memory_allocator_dump|.
70 memory_allocator_dumps_.set( 75 memory_allocator_dumps_.set(
71 memory_allocator_dump, adoptPtr(web_memory_allocator_dump_impl)); 76 memory_allocator_dump, adoptPtr(web_memory_allocator_dump));
72 return web_memory_allocator_dump_impl; 77 return web_memory_allocator_dump;
73 } 78 }
74 79
75 blink::WebMemoryAllocatorDump* WebProcessMemoryDumpImpl::getMemoryAllocatorDump( 80 blink::WebMemoryAllocatorDump* WebProcessMemoryDump::getMemoryAllocatorDump(
76 const blink::WebString& absolute_name) const { 81 const String& absolute_name) const {
82 StringUTF8Adaptor adapter(absolute_name);
83 std::string name(adapter.data(), adapter.length());
77 // Retrieve the base MemoryAllocatorDump object and then reverse lookup 84 // Retrieve the base MemoryAllocatorDump object and then reverse lookup
78 // its wrapper. 85 // its wrapper.
79 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = 86 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
80 process_memory_dump_->GetAllocatorDump(absolute_name.utf8()); 87 process_memory_dump_->GetAllocatorDump(name);
81 if (!memory_allocator_dump) 88 if (!memory_allocator_dump)
82 return nullptr; 89 return nullptr;
83 90
84 // The only case of (memory_allocator_dump && !web_memory_allocator_dump) 91 // The only case of (memory_allocator_dump && !web_memory_allocator_dump)
85 // is something from blink trying to get a MAD that was created from chromium, 92 // is something from blink trying to get a MAD that was created from chromium,
86 // which is an odd use case. 93 // which is an odd use case.
87 blink::WebMemoryAllocatorDump* web_memory_allocator_dump = 94 blink::WebMemoryAllocatorDump* web_memory_allocator_dump =
88 memory_allocator_dumps_.get(memory_allocator_dump); 95 memory_allocator_dumps_.get(memory_allocator_dump);
89 DCHECK(web_memory_allocator_dump); 96 DCHECK(web_memory_allocator_dump);
90 return web_memory_allocator_dump; 97 return web_memory_allocator_dump;
91 } 98 }
92 99
93 void WebProcessMemoryDumpImpl::clear() { 100 void WebProcessMemoryDump::clear() {
94 // Clear all the WebMemoryAllocatorDump wrappers. 101 // Clear all the WebMemoryAllocatorDump wrappers.
95 memory_allocator_dumps_.clear(); 102 memory_allocator_dumps_.clear();
96 103
97 // Clear the actual MemoryAllocatorDump objects from the underlying PMD. 104 // Clear the actual MemoryAllocatorDump objects from the underlying PMD.
98 process_memory_dump_->Clear(); 105 process_memory_dump_->Clear();
99 } 106 }
100 107
101 void WebProcessMemoryDumpImpl::takeAllDumpsFrom( 108 void WebProcessMemoryDump::takeAllDumpsFrom(
102 blink::WebProcessMemoryDump* other) { 109 blink::WebProcessMemoryDump* other) {
103 auto other_impl = static_cast<WebProcessMemoryDumpImpl*>(other); 110 // WebProcessMemoryDump is a container of WebMemoryAllocatorDump(s) which
104 // WebProcessMemoryDumpImpl is a container of WebMemoryAllocatorDump(s) which
105 // in turn are wrappers of base::trace_event::MemoryAllocatorDump(s). 111 // in turn are wrappers of base::trace_event::MemoryAllocatorDump(s).
106 // In order to expose the move and ownership transfer semantics of the 112 // In order to expose the move and ownership transfer semantics of the
107 // underlying ProcessMemoryDump, we need to: 113 // underlying ProcessMemoryDump, we need to:
108 114
109 // 1) Move and transfer the ownership of the wrapped 115 // 1) Move and transfer the ownership of the wrapped
110 // base::trace_event::MemoryAllocatorDump(s) instances. 116 // base::trace_event::MemoryAllocatorDump(s) instances.
111 process_memory_dump_->TakeAllDumpsFrom(other_impl->process_memory_dump_); 117 process_memory_dump_->TakeAllDumpsFrom(other->process_memory_dump_);
112 118
113 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers. 119 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers.
114 const size_t expected_final_size = memory_allocator_dumps_.size() + 120 const size_t expected_final_size = memory_allocator_dumps_.size() +
115 other_impl->memory_allocator_dumps_.size(); 121 other->memory_allocator_dumps_.size();
116 while (!other_impl->memory_allocator_dumps_.isEmpty()) { 122 while (!other->memory_allocator_dumps_.isEmpty()) {
117 auto first_entry = other_impl->memory_allocator_dumps_.begin(); 123 auto first_entry = other->memory_allocator_dumps_.begin();
118 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = 124 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
119 first_entry->key; 125 first_entry->key;
120 memory_allocator_dumps_.set(memory_allocator_dump, 126 memory_allocator_dumps_.set(memory_allocator_dump,
121 other_impl->memory_allocator_dumps_.take(memory_allocator_dump)); 127 other->memory_allocator_dumps_.take(memory_allocator_dump));
122 } 128 }
123 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size()); 129 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size());
124 DCHECK(other_impl->memory_allocator_dumps_.isEmpty()); 130 DCHECK(other->memory_allocator_dumps_.isEmpty());
125 } 131 }
126 132
127 void WebProcessMemoryDumpImpl::addOwnershipEdge( 133 void WebProcessMemoryDump::addOwnershipEdge(
128 blink::WebMemoryAllocatorDumpGuid source, 134 blink::WebMemoryAllocatorDumpGuid source,
129 blink::WebMemoryAllocatorDumpGuid target, 135 blink::WebMemoryAllocatorDumpGuid target,
130 int importance) { 136 int importance) {
131 process_memory_dump_->AddOwnershipEdge( 137 process_memory_dump_->AddOwnershipEdge(
132 base::trace_event::MemoryAllocatorDumpGuid(source), 138 base::trace_event::MemoryAllocatorDumpGuid(source),
133 base::trace_event::MemoryAllocatorDumpGuid(target), importance); 139 base::trace_event::MemoryAllocatorDumpGuid(target), importance);
134 } 140 }
135 141
136 void WebProcessMemoryDumpImpl::addOwnershipEdge( 142 void WebProcessMemoryDump::addOwnershipEdge(
137 blink::WebMemoryAllocatorDumpGuid source, 143 blink::WebMemoryAllocatorDumpGuid source,
138 blink::WebMemoryAllocatorDumpGuid target) { 144 blink::WebMemoryAllocatorDumpGuid target) {
139 process_memory_dump_->AddOwnershipEdge( 145 process_memory_dump_->AddOwnershipEdge(
140 base::trace_event::MemoryAllocatorDumpGuid(source), 146 base::trace_event::MemoryAllocatorDumpGuid(source),
141 base::trace_event::MemoryAllocatorDumpGuid(target)); 147 base::trace_event::MemoryAllocatorDumpGuid(target));
142 } 148 }
143 149
144 void WebProcessMemoryDumpImpl::addSuballocation( 150 void WebProcessMemoryDump::addSuballocation(
145 blink::WebMemoryAllocatorDumpGuid source, 151 blink::WebMemoryAllocatorDumpGuid source,
146 const blink::WebString& target_node_name) { 152 const String& target_node_name) {
153 StringUTF8Adaptor adapter(target_node_name);
154 std::string target_node(adapter.data(), adapter.length());
147 process_memory_dump_->AddSuballocation( 155 process_memory_dump_->AddSuballocation(
148 base::trace_event::MemoryAllocatorDumpGuid(source), 156 base::trace_event::MemoryAllocatorDumpGuid(source),
149 target_node_name.utf8()); 157 target_node);
150 } 158 }
151 159
152 SkTraceMemoryDump* WebProcessMemoryDumpImpl::createDumpAdapterForSkia( 160 SkTraceMemoryDump* WebProcessMemoryDump::createDumpAdapterForSkia(
153 const blink::WebString& dump_name_prefix) { 161 const String& dump_name_prefix) {
162 StringUTF8Adaptor adapter(dump_name_prefix);
163 std::string prefix(adapter.data(), adapter.length());
154 sk_trace_dump_list_.push_back(base::WrapUnique( 164 sk_trace_dump_list_.push_back(base::WrapUnique(
155 new skia::SkiaTraceMemoryDumpImpl( 165 new skia::SkiaTraceMemoryDumpImpl(
156 dump_name_prefix.utf8(), level_of_detail_, process_memory_dump_))); 166 prefix, level_of_detail_, process_memory_dump_)));
157 return sk_trace_dump_list_.back().get(); 167 return sk_trace_dump_list_.back().get();
158 } 168 }
159 169
160 blink::WebMemoryAllocatorDump* 170 blink::WebMemoryAllocatorDump*
161 WebProcessMemoryDumpImpl::createDiscardableMemoryAllocatorDump( 171 WebProcessMemoryDump::createDiscardableMemoryAllocatorDump(
162 const std::string& name, 172 const std::string& name,
163 base::DiscardableMemory* discardable) { 173 base::DiscardableMemory* discardable) {
164 base::trace_event::MemoryAllocatorDump* dump = 174 base::trace_event::MemoryAllocatorDump* dump =
165 discardable->CreateMemoryAllocatorDump(name.c_str(), 175 discardable->CreateMemoryAllocatorDump(name.c_str(),
166 process_memory_dump_); 176 process_memory_dump_);
167 return createWebMemoryAllocatorDump(dump); 177 return createWebMemoryAllocatorDump(dump);
168 } 178 }
169 179
170 void WebProcessMemoryDumpImpl::dumpHeapUsage( 180 void WebProcessMemoryDump::dumpHeapUsage(
171 const base::hash_map<base::trace_event::AllocationContext, 181 const base::hash_map<base::trace_event::AllocationContext,
172 base::trace_event::AllocationMetrics>& metrics_by_context, 182 base::trace_event::AllocationMetrics>& metrics_by_context,
173 base::trace_event::TraceEventMemoryOverhead& overhead, 183 base::trace_event::TraceEventMemoryOverhead& overhead,
174 const char* allocator_name) { 184 const char* allocator_name) {
175 process_memory_dump_->DumpHeapUsage(metrics_by_context, overhead, allocator_na me); 185 process_memory_dump_->DumpHeapUsage(metrics_by_context, overhead, allocator_na me);
176 } 186 }
177 187
178 } // namespace content 188 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698