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

Side by Side Diff: content/child/web_process_memory_dump_impl.cc

Issue 1394183003: [tracing] Remove memory-infra plumbing classes for blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink_noglue
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
(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 "content/child/web_process_memory_dump_impl.h"
6
7 #include "base/trace_event/process_memory_dump.h"
8 #include "content/child/web_memory_allocator_dump_impl.h"
9 #include "skia/ext/skia_trace_memory_dump_impl.h"
10
11 namespace content {
12
13 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl()
14 : owned_process_memory_dump_(
15 new base::trace_event::ProcessMemoryDump(nullptr)),
16 process_memory_dump_(owned_process_memory_dump_.get()),
17 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {}
18
19 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl(
20 base::trace_event::MemoryDumpLevelOfDetail level_of_detail,
21 base::trace_event::ProcessMemoryDump* process_memory_dump)
22 : process_memory_dump_(process_memory_dump),
23 level_of_detail_(level_of_detail) {}
24
25 WebProcessMemoryDumpImpl::~WebProcessMemoryDumpImpl() {
26 }
27
28 blink::WebMemoryAllocatorDump*
29 WebProcessMemoryDumpImpl::createMemoryAllocatorDump(
30 const blink::WebString& absolute_name) {
31 // Get a MemoryAllocatorDump from the base/ object.
32 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
33 process_memory_dump_->CreateAllocatorDump(absolute_name.utf8());
34
35 return createWebMemoryAllocatorDump(memory_allocator_dump);
36 }
37
38 blink::WebMemoryAllocatorDump*
39 WebProcessMemoryDumpImpl::createMemoryAllocatorDump(
40 const blink::WebString& absolute_name,
41 blink::WebMemoryAllocatorDumpGuid guid) {
42 // Get a MemoryAllocatorDump from the base/ object with given guid.
43 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
44 process_memory_dump_->CreateAllocatorDump(
45 absolute_name.utf8(),
46 base::trace_event::MemoryAllocatorDumpGuid(guid));
47 return createWebMemoryAllocatorDump(memory_allocator_dump);
48 }
49
50 blink::WebMemoryAllocatorDump*
51 WebProcessMemoryDumpImpl::createWebMemoryAllocatorDump(
52 base::trace_event::MemoryAllocatorDump* memory_allocator_dump) {
53 if (!memory_allocator_dump)
54 return nullptr;
55
56 // Wrap it and return to blink.
57 WebMemoryAllocatorDumpImpl* web_memory_allocator_dump_impl =
58 new WebMemoryAllocatorDumpImpl(memory_allocator_dump);
59
60 // memory_allocator_dumps_ will take ownership of
61 // |web_memory_allocator_dumpd_impl|.
62 memory_allocator_dumps_.set(memory_allocator_dump,
63 make_scoped_ptr(web_memory_allocator_dump_impl));
64 return web_memory_allocator_dump_impl;
65 }
66
67 blink::WebMemoryAllocatorDump* WebProcessMemoryDumpImpl::getMemoryAllocatorDump(
68 const blink::WebString& absolute_name) const {
69 // Retrieve the base MemoryAllocatorDump object and then reverse lookup
70 // its wrapper.
71 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
72 process_memory_dump_->GetAllocatorDump(absolute_name.utf8());
73 if (!memory_allocator_dump)
74 return nullptr;
75
76 // The only case of (memory_allocator_dump && !web_memory_allocator_dump)
77 // is something from blink trying to get a MAD that was created from chromium,
78 // which is an odd use case.
79 blink::WebMemoryAllocatorDump* web_memory_allocator_dump =
80 memory_allocator_dumps_.get(memory_allocator_dump);
81 DCHECK(web_memory_allocator_dump);
82 return web_memory_allocator_dump;
83 }
84
85 void WebProcessMemoryDumpImpl::clear() {
86 // Clear all the WebMemoryAllocatorDump wrappers.
87 memory_allocator_dumps_.clear();
88
89 // Clear the actual MemoryAllocatorDump objects from the underlying PMD.
90 process_memory_dump_->Clear();
91 }
92
93 void WebProcessMemoryDumpImpl::takeAllDumpsFrom(
94 blink::WebProcessMemoryDump* other) {
95 auto other_impl = static_cast<WebProcessMemoryDumpImpl*>(other);
96 // WebProcessMemoryDumpImpl is a container of WebMemoryAllocatorDump(s) which
97 // in turn are wrappers of base::trace_event::MemoryAllocatorDump(s).
98 // In order to expose the move and ownership transfer semantics of the
99 // underlying ProcessMemoryDump, we need to:
100
101 // 1) Move and transfer the ownership of the wrapped
102 // base::trace_event::MemoryAllocatorDump(s) instances.
103 process_memory_dump_->TakeAllDumpsFrom(other_impl->process_memory_dump_);
104
105 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers.
106 const size_t expected_final_size = memory_allocator_dumps_.size() +
107 other_impl->memory_allocator_dumps_.size();
108 while (!other_impl->memory_allocator_dumps_.empty()) {
109 auto first_entry = other_impl->memory_allocator_dumps_.begin();
110 base::trace_event::MemoryAllocatorDump* memory_allocator_dump =
111 first_entry->first;
112 memory_allocator_dumps_.set(
113 memory_allocator_dump,
114 other_impl->memory_allocator_dumps_.take_and_erase(first_entry).Pass());
115 }
116 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size());
117 DCHECK(other_impl->memory_allocator_dumps_.empty());
118 }
119
120 void WebProcessMemoryDumpImpl::AddOwnershipEdge(
121 blink::WebMemoryAllocatorDumpGuid source,
122 blink::WebMemoryAllocatorDumpGuid target,
123 int importance) {
124 process_memory_dump_->AddOwnershipEdge(
125 base::trace_event::MemoryAllocatorDumpGuid(source),
126 base::trace_event::MemoryAllocatorDumpGuid(target), importance);
127 }
128
129 void WebProcessMemoryDumpImpl::AddOwnershipEdge(
130 blink::WebMemoryAllocatorDumpGuid source,
131 blink::WebMemoryAllocatorDumpGuid target) {
132 process_memory_dump_->AddOwnershipEdge(
133 base::trace_event::MemoryAllocatorDumpGuid(source),
134 base::trace_event::MemoryAllocatorDumpGuid(target));
135 }
136
137 void WebProcessMemoryDumpImpl::AddSuballocation(
138 blink::WebMemoryAllocatorDumpGuid source,
139 const blink::WebString& targetNodeName) {
140 process_memory_dump_->AddSuballocation(
141 base::trace_event::MemoryAllocatorDumpGuid(source),
142 targetNodeName.utf8());
143 }
144
145 SkTraceMemoryDump* WebProcessMemoryDumpImpl::CreateDumpAdapterForSkia(
146 const blink::WebString& dumpNamePrefix) {
147 sk_trace_dump_list_.push_back(new skia::SkiaTraceMemoryDumpImpl(
148 dumpNamePrefix.utf8(), level_of_detail_, process_memory_dump_));
149 return sk_trace_dump_list_.back();
150 }
151
152 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_process_memory_dump_impl.h ('k') | content/child/web_process_memory_dump_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698