| 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/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 "content/child/web_memory_allocator_dump_impl.h" | 14 #include "platform/WebMemoryAllocatorDumpImpl.h" |
| 15 #include "skia/ext/skia_trace_memory_dump_impl.h" | 15 #include "skia/ext/skia_trace_memory_dump_impl.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace blink { |
| 18 | 18 |
| 19 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl() | 19 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl() |
| 20 : owned_process_memory_dump_( | 20 : owned_process_memory_dump_( |
| 21 new base::trace_event::ProcessMemoryDump(nullptr)), | 21 adoptPtr(new base::trace_event::ProcessMemoryDump(nullptr))), |
| 22 process_memory_dump_(owned_process_memory_dump_.get()), | 22 process_memory_dump_(owned_process_memory_dump_.get()), |
| 23 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {} | 23 level_of_detail_(base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {} |
| 24 | 24 |
| 25 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl( | 25 WebProcessMemoryDumpImpl::WebProcessMemoryDumpImpl( |
| 26 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, | 26 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, |
| 27 base::trace_event::ProcessMemoryDump* process_memory_dump) | 27 base::trace_event::ProcessMemoryDump* process_memory_dump) |
| 28 : process_memory_dump_(process_memory_dump), | 28 : process_memory_dump_(process_memory_dump), |
| 29 level_of_detail_(level_of_detail) {} | 29 level_of_detail_(level_of_detail) {} |
| 30 | 30 |
| 31 WebProcessMemoryDumpImpl::~WebProcessMemoryDumpImpl() { | 31 WebProcessMemoryDumpImpl::~WebProcessMemoryDumpImpl() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 59 if (!memory_allocator_dump) | 59 if (!memory_allocator_dump) |
| 60 return nullptr; | 60 return nullptr; |
| 61 | 61 |
| 62 // Wrap it and return to blink. | 62 // Wrap it and return to blink. |
| 63 WebMemoryAllocatorDumpImpl* web_memory_allocator_dump_impl = | 63 WebMemoryAllocatorDumpImpl* web_memory_allocator_dump_impl = |
| 64 new WebMemoryAllocatorDumpImpl(memory_allocator_dump); | 64 new WebMemoryAllocatorDumpImpl(memory_allocator_dump); |
| 65 | 65 |
| 66 // memory_allocator_dumps_ will take ownership of | 66 // memory_allocator_dumps_ will take ownership of |
| 67 // |web_memory_allocator_dumpd_impl|. | 67 // |web_memory_allocator_dumpd_impl|. |
| 68 memory_allocator_dumps_.set(memory_allocator_dump, | 68 memory_allocator_dumps_.set(memory_allocator_dump, |
| 69 make_scoped_ptr(web_memory_allocator_dump_impl)); | 69 adoptPtr(web_memory_allocator_dump_impl)); |
| 70 return web_memory_allocator_dump_impl; | 70 return web_memory_allocator_dump_impl; |
| 71 } | 71 } |
| 72 | 72 |
| 73 blink::WebMemoryAllocatorDump* WebProcessMemoryDumpImpl::getMemoryAllocatorDump( | 73 blink::WebMemoryAllocatorDump* WebProcessMemoryDumpImpl::getMemoryAllocatorDump( |
| 74 const blink::WebString& absolute_name) const { | 74 const blink::WebString& absolute_name) const { |
| 75 // Retrieve the base MemoryAllocatorDump object and then reverse lookup | 75 // Retrieve the base MemoryAllocatorDump object and then reverse lookup |
| 76 // its wrapper. | 76 // its wrapper. |
| 77 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = | 77 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = |
| 78 process_memory_dump_->GetAllocatorDump(absolute_name.utf8()); | 78 process_memory_dump_->GetAllocatorDump(absolute_name.utf8()); |
| 79 if (!memory_allocator_dump) | 79 if (!memory_allocator_dump) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 // In order to expose the move and ownership transfer semantics of the | 104 // In order to expose the move and ownership transfer semantics of the |
| 105 // underlying ProcessMemoryDump, we need to: | 105 // underlying ProcessMemoryDump, we need to: |
| 106 | 106 |
| 107 // 1) Move and transfer the ownership of the wrapped | 107 // 1) Move and transfer the ownership of the wrapped |
| 108 // base::trace_event::MemoryAllocatorDump(s) instances. | 108 // base::trace_event::MemoryAllocatorDump(s) instances. |
| 109 process_memory_dump_->TakeAllDumpsFrom(other_impl->process_memory_dump_); | 109 process_memory_dump_->TakeAllDumpsFrom(other_impl->process_memory_dump_); |
| 110 | 110 |
| 111 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers. | 111 // 2) Move and transfer the ownership of the WebMemoryAllocatorDump wrappers. |
| 112 const size_t expected_final_size = memory_allocator_dumps_.size() + | 112 const size_t expected_final_size = memory_allocator_dumps_.size() + |
| 113 other_impl->memory_allocator_dumps_.size(); | 113 other_impl->memory_allocator_dumps_.size(); |
| 114 while (!other_impl->memory_allocator_dumps_.empty()) { | 114 while (!other_impl->memory_allocator_dumps_.isEmpty()) { |
| 115 auto first_entry = other_impl->memory_allocator_dumps_.begin(); | 115 auto first_entry = other_impl->memory_allocator_dumps_.begin(); |
| 116 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = | 116 base::trace_event::MemoryAllocatorDump* memory_allocator_dump = |
| 117 first_entry->first; | 117 first_entry->key; |
| 118 memory_allocator_dumps_.set( | 118 memory_allocator_dumps_.set( |
| 119 memory_allocator_dump, | 119 memory_allocator_dump, |
| 120 other_impl->memory_allocator_dumps_.take_and_erase(first_entry)); | 120 other_impl->memory_allocator_dumps_.take(first_entry->key)); |
| 121 } | 121 } |
| 122 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size()); | 122 DCHECK_EQ(expected_final_size, memory_allocator_dumps_.size()); |
| 123 DCHECK(other_impl->memory_allocator_dumps_.empty()); | 123 DCHECK(other_impl->memory_allocator_dumps_.isEmpty()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void WebProcessMemoryDumpImpl::addOwnershipEdge( | 126 void WebProcessMemoryDumpImpl::addOwnershipEdge( |
| 127 blink::WebMemoryAllocatorDumpGuid source, | 127 blink::WebMemoryAllocatorDumpGuid source, |
| 128 blink::WebMemoryAllocatorDumpGuid target, | 128 blink::WebMemoryAllocatorDumpGuid target, |
| 129 int importance) { | 129 int importance) { |
| 130 process_memory_dump_->AddOwnershipEdge( | 130 process_memory_dump_->AddOwnershipEdge( |
| 131 base::trace_event::MemoryAllocatorDumpGuid(source), | 131 base::trace_event::MemoryAllocatorDumpGuid(source), |
| 132 base::trace_event::MemoryAllocatorDumpGuid(target), importance); | 132 base::trace_event::MemoryAllocatorDumpGuid(target), importance); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void WebProcessMemoryDumpImpl::addOwnershipEdge( | 135 void WebProcessMemoryDumpImpl::addOwnershipEdge( |
| 136 blink::WebMemoryAllocatorDumpGuid source, | 136 blink::WebMemoryAllocatorDumpGuid source, |
| 137 blink::WebMemoryAllocatorDumpGuid target) { | 137 blink::WebMemoryAllocatorDumpGuid target) { |
| 138 process_memory_dump_->AddOwnershipEdge( | 138 process_memory_dump_->AddOwnershipEdge( |
| 139 base::trace_event::MemoryAllocatorDumpGuid(source), | 139 base::trace_event::MemoryAllocatorDumpGuid(source), |
| 140 base::trace_event::MemoryAllocatorDumpGuid(target)); | 140 base::trace_event::MemoryAllocatorDumpGuid(target)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void WebProcessMemoryDumpImpl::addSuballocation( | 143 void WebProcessMemoryDumpImpl::addSuballocation( |
| 144 blink::WebMemoryAllocatorDumpGuid source, | 144 blink::WebMemoryAllocatorDumpGuid source, |
| 145 const blink::WebString& target_node_name) { | 145 const blink::WebString& target_node_name) { |
| 146 process_memory_dump_->AddSuballocation( | 146 process_memory_dump_->AddSuballocation( |
| 147 base::trace_event::MemoryAllocatorDumpGuid(source), | 147 base::trace_event::MemoryAllocatorDumpGuid(source), |
| 148 target_node_name.utf8()); | 148 target_node_name.utf8()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 SkTraceMemoryDump* WebProcessMemoryDumpImpl::createDumpAdapterForSkia( | 151 SkTraceMemoryDump* WebProcessMemoryDumpImpl::createDumpAdapterForSkia( |
| 152 const blink::WebString& dump_name_prefix) { | 152 const blink::WebString& dump_name_prefix) { |
| 153 sk_trace_dump_list_.push_back(new skia::SkiaTraceMemoryDumpImpl( | 153 sk_trace_dump_list_.append(adoptPtr(new skia::SkiaTraceMemoryDumpImpl( |
| 154 dump_name_prefix.utf8(), level_of_detail_, process_memory_dump_)); | 154 dump_name_prefix.utf8(), level_of_detail_, process_memory_dump_))); |
| 155 return sk_trace_dump_list_.back(); | 155 return sk_trace_dump_list_.last().get(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 blink::WebMemoryAllocatorDump* | 158 blink::WebMemoryAllocatorDump* |
| 159 WebProcessMemoryDumpImpl::CreateDiscardableMemoryAllocatorDump( | 159 WebProcessMemoryDumpImpl::CreateDiscardableMemoryAllocatorDump( |
| 160 const std::string& name, | 160 const std::string& name, |
| 161 base::DiscardableMemory* discardable) { | 161 base::DiscardableMemory* discardable) { |
| 162 base::trace_event::MemoryAllocatorDump* dump = | 162 base::trace_event::MemoryAllocatorDump* dump = |
| 163 discardable->CreateMemoryAllocatorDump(name.c_str(), | 163 discardable->CreateMemoryAllocatorDump(name.c_str(), |
| 164 process_memory_dump_); | 164 process_memory_dump_); |
| 165 return createWebMemoryAllocatorDump(dump); | 165 return createWebMemoryAllocatorDump(dump); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void WebProcessMemoryDumpImpl::dumpHeapUsage( | 168 void WebProcessMemoryDumpImpl::dumpHeapUsage( |
| 169 const base::hash_map<base::trace_event::AllocationContext, size_t>& | 169 const base::hash_map<base::trace_event::AllocationContext, size_t>& |
| 170 bytes_by_context, | 170 bytes_by_context, |
| 171 base::trace_event::TraceEventMemoryOverhead& overhead, | 171 base::trace_event::TraceEventMemoryOverhead& overhead, |
| 172 const char* allocator_name) { | 172 const char* allocator_name) { |
| 173 scoped_refptr<base::trace_event::MemoryDumpSessionState> session_state = | 173 scoped_refptr<base::trace_event::MemoryDumpSessionState> session_state = |
| 174 process_memory_dump_->session_state(); | 174 process_memory_dump_->session_state(); |
| 175 scoped_refptr<base::trace_event::TracedValue> heap_dump = ExportHeapDump( | 175 scoped_refptr<base::trace_event::TracedValue> heap_dump = ExportHeapDump( |
| 176 bytes_by_context, | 176 bytes_by_context, |
| 177 session_state->stack_frame_deduplicator(), | 177 session_state->stack_frame_deduplicator(), |
| 178 session_state->type_name_deduplicator()); | 178 session_state->type_name_deduplicator()); |
| 179 process_memory_dump_->AddHeapDump(allocator_name, heap_dump); | 179 process_memory_dump_->AddHeapDump(allocator_name, heap_dump); |
| 180 overhead.DumpInto("tracing/heap_profiler", process_memory_dump_); | 180 overhead.DumpInto("tracing/heap_profiler", process_memory_dump_); |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace content | 183 } // namespace content |
| OLD | NEW |