OLD | NEW |
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_process_memory_dump_impl.h" | 5 #include "platform/WebProcessMemoryDumpImpl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/discardable_memory.h" | 9 #include "base/memory/discardable_memory.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/trace_event/heap_profiler_heap_dump_writer.h" | 11 #include "base/trace_event/heap_profiler_heap_dump_writer.h" |
12 #include "base/trace_event/process_memory_dump.h" | 12 #include "base/trace_event/process_memory_dump.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "base/trace_event/trace_event_memory_overhead.h" | 14 #include "base/trace_event/trace_event_memory_overhead.h" |
15 #include "content/child/web_memory_allocator_dump_impl.h" | 15 #include "platform/WebMemoryAllocatorDumpImpl.h" |
16 #include "skia/ext/skia_trace_memory_dump_impl.h" | 16 #include "skia/ext/skia_trace_memory_dump_impl.h" |
17 | 17 |
18 namespace content { | 18 namespace blink { |
19 | 19 |
20 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl() | 20 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl() |
21 : owned_process_memory_dump_( | 21 : owned_process_memory_dump_( |
22 new base::trace_event::ProcessMemoryDump(nullptr)), | 22 new base::trace_event::ProcessMemoryDump(nullptr)), |
23 process_memory_dump_(owned_process_memory_dump_.get()), | 23 process_memory_dump_(owned_process_memory_dump_.get()), |
24 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {} | 24 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {} |
25 | 25 |
26 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl( | 26 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl( |
27 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, | 27 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, |
28 base::trace_event::ProcessMemoryDump* process_memory_dump) | 28 base::trace_event::ProcessMemoryDump* process_memory_dump) |
(...skipping 30 matching lines...) Expand all Loading... |
59 base::trace_event::MemoryAllocatorDump* memory_allocator_dump) { | 59 base::trace_event::MemoryAllocatorDump* memory_allocator_dump) { |
60 if (!memory_allocator_dump) | 60 if (!memory_allocator_dump) |
61 return nullptr; | 61 return nullptr; |
62 | 62 |
63 // Wrap it and return to blink. | 63 // Wrap it and return to blink. |
64 WebMemoryAllocatorDumpImpl* web_memory_allocator_dump_impl = | 64 WebMemoryAllocatorDumpImpl* web_memory_allocator_dump_impl = |
65 new WebMemoryAllocatorDumpImpl(memory_allocator_dump); | 65 new WebMemoryAllocatorDumpImpl(memory_allocator_dump); |
66 | 66 |
67 // memory_allocator_dumps_ will take ownership of | 67 // memory_allocator_dumps_ will take ownership of |
68 // |web_memory_allocator_dumpd_impl|. | 68 // |web_memory_allocator_dumpd_impl|. |
69 memory_allocator_dumps_.set(memory_allocator_dump, | 69 memory_allocator_dumps_.insert(std::make_pair( |
70 make_scoped_ptr(web_memory_allocator_dump_impl)); | 70 memory_allocator_dump, make_scoped_ptr(web_memory_allocator_dump_impl))); |
71 return web_memory_allocator_dump_impl; | 71 return web_memory_allocator_dump_impl; |
72 } | 72 } |
73 | 73 |
74 blink::WebMemoryAllocatorDump* WebProcessMemoryDumpImpl::getMemoryAllocatorDump( | 74 blink::WebMemoryAllocatorDump* WebProcessMemoryDumpImpl::getMemoryAllocatorDump( |
75 const blink::WebString& absolute_name) const { | 75 const blink::WebString& absolute_name) const { |
76 // Retrieve the base MemoryAllocatorDump object and then reverse lookup | 76 // Retrieve the base MemoryAllocatorDump object and then reverse lookup |
77 // its wrapper. | 77 // its wrapper. |
78 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = | 78 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = |
79 process_memory_dump_->GetAllocatorDump(absolute_name.utf8()); | 79 process_memory_dump_->GetAllocatorDump(absolute_name.utf8()); |
80 if (!memory_allocator_dump) | 80 if (!memory_allocator_dump) |
81 return nullptr; | 81 return nullptr; |
82 | 82 |
83 // The only case of (memory_allocator_dump && !web_memory_allocator_dump) | 83 // The only case of (memory_allocator_dump && !web_memory_allocator_dump) |
84 // is something from blink trying to get a MAD that was created from chromium, | 84 // is something from blink trying to get a MAD that was created from chromium, |
85 // which is an odd use case. | 85 // which is an odd use case. |
86 blink::WebMemoryAllocatorDump* web_memory_allocator_dump = | 86 blink::WebMemoryAllocatorDump* web_memory_allocator_dump = |
87 memory_allocator_dumps_.get(memory_allocator_dump); | 87 memory_allocator_dumps_.at(memory_allocator_dump).get(); |
88 DCHECK(web_memory_allocator_dump); | 88 DCHECK(web_memory_allocator_dump); |
89 return web_memory_allocator_dump; | 89 return web_memory_allocator_dump; |
90 } | 90 } |
91 | 91 |
92 void WebProcessMemoryDumpImpl::clear() { | 92 void WebProcessMemoryDumpImpl::clear() { |
93 // Clear all the WebMemoryAllocatorDump wrappers. | 93 // Clear all the WebMemoryAllocatorDump wrappers. |
94 memory_allocator_dumps_.clear(); | 94 memory_allocator_dumps_.clear(); |
95 | 95 |
96 // Clear the actual MemoryAllocatorDump objects from the underlying PMD. | 96 // Clear the actual MemoryAllocatorDump objects from the underlying PMD. |
97 process_memory_dump_->Clear(); | 97 process_memory_dump_->Clear(); |
(...skipping 11 matching lines...) Expand all Loading... |
109 // base::trace_event::MemoryAllocatorDump(s) instances. | 109 // base::trace_event::MemoryAllocatorDump(s) instances. |
110 process_memory_dump_->TakeAllDumpsFrom(other_impl->process_memory_dump_); | 110 process_memory_dump_->TakeAllDumpsFrom(other_impl->process_memory_dump_); |
111 | 111 |
112 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers. | 112 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers. |
113 const size_t expected_final_size = memory_allocator_dumps_.size() + | 113 const size_t expected_final_size = memory_allocator_dumps_.size() + |
114 other_impl->memory_allocator_dumps_.size(); | 114 other_impl->memory_allocator_dumps_.size(); |
115 while (!other_impl->memory_allocator_dumps_.empty()) { | 115 while (!other_impl->memory_allocator_dumps_.empty()) { |
116 auto first_entry = other_impl->memory_allocator_dumps_.begin(); | 116 auto first_entry = other_impl->memory_allocator_dumps_.begin(); |
117 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = | 117 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = |
118 first_entry->first; | 118 first_entry->first; |
119 memory_allocator_dumps_.set( | 119 auto other_dump_impl = |
120 memory_allocator_dump, | 120 other_impl->memory_allocator_dumps_.at(first_entry->first).release(); |
121 other_impl->memory_allocator_dumps_.take_and_erase(first_entry)); | 121 memory_allocator_dumps_.insert(std::make_pair(memory_allocator_dump, |
| 122 make_scoped_ptr(other_dump_impl))); |
| 123 other_impl->memory_allocator_dumps_.erase(first_entry->first); |
122 } | 124 } |
123 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size()); | 125 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size()); |
124 DCHECK(other_impl->memory_allocator_dumps_.empty()); | 126 DCHECK(other_impl->memory_allocator_dumps_.empty()); |
125 } | 127 } |
126 | 128 |
127 void WebProcessMemoryDumpImpl::addOwnershipEdge( | 129 void WebProcessMemoryDumpImpl::addOwnershipEdge( |
128 blink::WebMemoryAllocatorDumpGuid source, | 130 blink::WebMemoryAllocatorDumpGuid source, |
129 blink::WebMemoryAllocatorDumpGuid target, | 131 blink::WebMemoryAllocatorDumpGuid target, |
130 int importance) { | 132 int importance) { |
131 process_memory_dump_->AddOwnershipEdge( | 133 process_memory_dump_->AddOwnershipEdge( |
(...skipping 12 matching lines...) Expand all Loading... |
144 void WebProcessMemoryDumpImpl::addSuballocation( | 146 void WebProcessMemoryDumpImpl::addSuballocation( |
145 blink::WebMemoryAllocatorDumpGuid source, | 147 blink::WebMemoryAllocatorDumpGuid source, |
146 const blink::WebString& target_node_name) { | 148 const blink::WebString& target_node_name) { |
147 process_memory_dump_->AddSuballocation( | 149 process_memory_dump_->AddSuballocation( |
148 base::trace_event::MemoryAllocatorDumpGuid(source), | 150 base::trace_event::MemoryAllocatorDumpGuid(source), |
149 target_node_name.utf8()); | 151 target_node_name.utf8()); |
150 } | 152 } |
151 | 153 |
152 SkTraceMemoryDump* WebProcessMemoryDumpImpl::createDumpAdapterForSkia( | 154 SkTraceMemoryDump* WebProcessMemoryDumpImpl::createDumpAdapterForSkia( |
153 const blink::WebString& dump_name_prefix) { | 155 const blink::WebString& dump_name_prefix) { |
154 sk_trace_dump_list_.push_back(new skia::SkiaTraceMemoryDumpImpl( | 156 sk_trace_dump_list_.push_back(make_scoped_ptr( |
155 dump_name_prefix.utf8(), level_of_detail_, process_memory_dump_)); | 157 new skia::SkiaTraceMemoryDumpImpl( |
156 return sk_trace_dump_list_.back(); | 158 dump_name_prefix.utf8(), level_of_detail_, process_memory_dump_))); |
| 159 return sk_trace_dump_list_.back().get(); |
157 } | 160 } |
158 | 161 |
159 blink::WebMemoryAllocatorDump* | 162 blink::WebMemoryAllocatorDump* |
160 WebProcessMemoryDumpImpl::CreateDiscardableMemoryAllocatorDump( | 163 WebProcessMemoryDumpImpl::CreateDiscardableMemoryAllocatorDump( |
161 const std::string& name, | 164 const std::string& name, |
162 base::DiscardableMemory* discardable) { | 165 base::DiscardableMemory* discardable) { |
163 base::trace_event::MemoryAllocatorDump* dump = | 166 base::trace_event::MemoryAllocatorDump* dump = |
164 discardable->CreateMemoryAllocatorDump(name.c_str(), | 167 discardable->CreateMemoryAllocatorDump(name.c_str(), |
165 process_memory_dump_); | 168 process_memory_dump_); |
166 return createWebMemoryAllocatorDump(dump); | 169 return createWebMemoryAllocatorDump(dump); |
(...skipping 10 matching lines...) Expand all Loading... |
177 bytes_by_context, | 180 bytes_by_context, |
178 session_state->stack_frame_deduplicator(), | 181 session_state->stack_frame_deduplicator(), |
179 session_state->type_name_deduplicator()); | 182 session_state->type_name_deduplicator()); |
180 process_memory_dump_->AddHeapDump(allocator_name, heap_dump); | 183 process_memory_dump_->AddHeapDump(allocator_name, heap_dump); |
181 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", | 184 std::string base_name = base::StringPrintf("tracing/heap_profiler_%s", |
182 allocator_name); | 185 allocator_name); |
183 overhead.DumpInto(base_name.c_str(), process_memory_dump_); | 186 overhead.DumpInto(base_name.c_str(), process_memory_dump_); |
184 } | 187 } |
185 | 188 |
186 } // namespace content | 189 } // namespace content |
OLD | NEW |