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 "base/trace_event/process_memory_dump.h" | 5 #include "base/trace_event/process_memory_dump.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/trace_event/process_memory_totals.h" | 10 #include "base/trace_event/process_memory_totals.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 return allocator_dump ? allocator_dump | 137 return allocator_dump ? allocator_dump |
138 : CreateAllocatorDump( | 138 : CreateAllocatorDump( |
139 GetSharedGlobalAllocatorDumpName(guid), guid); | 139 GetSharedGlobalAllocatorDumpName(guid), guid); |
140 } | 140 } |
141 | 141 |
142 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( | 142 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( |
143 const MemoryAllocatorDumpGuid& guid) const { | 143 const MemoryAllocatorDumpGuid& guid) const { |
144 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); | 144 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); |
145 } | 145 } |
146 | 146 |
147 void ProcessMemoryDump::AddHeapDump(const std::string& absolute_name, | |
148 scoped_refptr<TracedValue> heap_dump) { | |
149 heap_dumps_[absolute_name] = heap_dump; | |
Primiano Tucci (use gerrit)
2015/10/26 11:52:07
add a DCHECK_EQ(0u, heap_dumps_.count(absolute_nam
Ruud van Asseldonk
2015/10/26 14:51:27
Done.
| |
150 } | |
151 | |
147 void ProcessMemoryDump::Clear() { | 152 void ProcessMemoryDump::Clear() { |
148 if (has_process_totals_) { | 153 if (has_process_totals_) { |
149 process_totals_.Clear(); | 154 process_totals_.Clear(); |
150 has_process_totals_ = false; | 155 has_process_totals_ = false; |
151 } | 156 } |
152 | 157 |
153 if (has_process_mmaps_) { | 158 if (has_process_mmaps_) { |
154 process_mmaps_.Clear(); | 159 process_mmaps_.Clear(); |
155 has_process_mmaps_ = false; | 160 has_process_mmaps_ = false; |
156 } | 161 } |
157 | 162 |
158 allocator_dumps_storage_.clear(); | 163 allocator_dumps_storage_.clear(); |
159 allocator_dumps_.clear(); | 164 allocator_dumps_.clear(); |
160 allocator_dumps_edges_.clear(); | 165 allocator_dumps_edges_.clear(); |
166 heap_dumps_.clear(); | |
161 } | 167 } |
162 | 168 |
163 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { | 169 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { |
164 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); | 170 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); |
165 | 171 |
166 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| | 172 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| |
167 // into this ProcessMemoryDump. | 173 // into this ProcessMemoryDump. |
168 for (MemoryAllocatorDump* mad : other->allocator_dumps_storage_) { | 174 for (MemoryAllocatorDump* mad : other->allocator_dumps_storage_) { |
169 // Check that we don't merge duplicates. | 175 // Check that we don't merge duplicates. |
170 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name())); | 176 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name())); |
171 allocator_dumps_storage_.push_back(mad); | 177 allocator_dumps_storage_.push_back(mad); |
172 allocator_dumps_[mad->absolute_name()] = mad; | 178 allocator_dumps_[mad->absolute_name()] = mad; |
173 } | 179 } |
174 other->allocator_dumps_storage_.weak_clear(); | 180 other->allocator_dumps_storage_.weak_clear(); |
175 other->allocator_dumps_.clear(); | 181 other->allocator_dumps_.clear(); |
176 | 182 |
177 // Move all the edges. | 183 // Move all the edges. |
178 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), | 184 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), |
179 other->allocator_dumps_edges_.begin(), | 185 other->allocator_dumps_edges_.begin(), |
180 other->allocator_dumps_edges_.end()); | 186 other->allocator_dumps_edges_.end()); |
181 other->allocator_dumps_edges_.clear(); | 187 other->allocator_dumps_edges_.clear(); |
188 | |
189 heap_dumps_.insert(other->heap_dumps_.begin(), other->heap_dumps_.end()); | |
190 other->heap_dumps_.clear(); | |
182 } | 191 } |
183 | 192 |
184 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { | 193 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { |
185 if (has_process_totals_) { | 194 if (has_process_totals_) { |
186 value->BeginDictionary("process_totals"); | 195 value->BeginDictionary("process_totals"); |
187 process_totals_.AsValueInto(value); | 196 process_totals_.AsValueInto(value); |
188 value->EndDictionary(); | 197 value->EndDictionary(); |
189 } | 198 } |
190 | 199 |
191 if (has_process_mmaps_) { | 200 if (has_process_mmaps_) { |
192 value->BeginDictionary("process_mmaps"); | 201 value->BeginDictionary("process_mmaps"); |
193 process_mmaps_.AsValueInto(value); | 202 process_mmaps_.AsValueInto(value); |
194 value->EndDictionary(); | 203 value->EndDictionary(); |
195 } | 204 } |
196 | 205 |
197 if (allocator_dumps_storage_.size() > 0) { | 206 if (allocator_dumps_storage_.size() > 0) { |
198 value->BeginDictionary("allocators"); | 207 value->BeginDictionary("allocators"); |
199 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_) | 208 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_) |
200 allocator_dump->AsValueInto(value); | 209 allocator_dump->AsValueInto(value); |
201 value->EndDictionary(); | 210 value->EndDictionary(); |
202 } | 211 } |
203 | 212 |
213 if (heap_dumps_.size() > 0) { | |
214 value->BeginDictionary("heap_dumps"); | |
215 for (auto name_and_dump : heap_dumps_) | |
Primiano Tucci (use gerrit)
2015/10/26 11:52:07
const auto& ?
Ruud van Asseldonk
2015/10/26 14:51:27
Done.
| |
216 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); | |
217 value->EndDictionary(); // heap_dumps | |
218 } | |
219 | |
204 value->BeginArray("allocators_graph"); | 220 value->BeginArray("allocators_graph"); |
205 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { | 221 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { |
206 value->BeginDictionary(); | 222 value->BeginDictionary(); |
207 value->SetString("source", edge.source.ToString()); | 223 value->SetString("source", edge.source.ToString()); |
208 value->SetString("target", edge.target.ToString()); | 224 value->SetString("target", edge.target.ToString()); |
209 value->SetInteger("importance", edge.importance); | 225 value->SetInteger("importance", edge.importance); |
210 value->SetString("type", edge.type); | 226 value->SetString("type", edge.type); |
211 value->EndDictionary(); | 227 value->EndDictionary(); |
212 } | 228 } |
213 value->EndArray(); | 229 value->EndArray(); |
(...skipping 14 matching lines...) Expand all Loading... | |
228 | 244 |
229 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 245 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
230 const std::string& target_node_name) { | 246 const std::string& target_node_name) { |
231 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 247 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
232 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 248 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
233 AddOwnershipEdge(source, target_child_mad->guid()); | 249 AddOwnershipEdge(source, target_child_mad->guid()); |
234 } | 250 } |
235 | 251 |
236 } // namespace trace_event | 252 } // namespace trace_event |
237 } // namespace base | 253 } // namespace base |
OLD | NEW |