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

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

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

Powered by Google App Engine
This is Rietveld 408576698