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

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

Powered by Google App Engine
This is Rietveld 408576698