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 <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { | 279 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { |
280 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); | 280 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); |
281 | 281 |
282 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| | 282 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| |
283 // into this ProcessMemoryDump, checking for duplicates. | 283 // into this ProcessMemoryDump, checking for duplicates. |
284 for (auto& it : other->allocator_dumps_) | 284 for (auto& it : other->allocator_dumps_) |
285 AddAllocatorDumpInternal(std::move(it.second)); | 285 AddAllocatorDumpInternal(std::move(it.second)); |
286 other->allocator_dumps_.clear(); | 286 other->allocator_dumps_.clear(); |
287 | 287 |
288 // Move all the edges. | 288 // Move all the edges. |
289 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), | 289 allocator_dumps_edges_.insert(other->allocator_dumps_edges_.begin(), |
290 other->allocator_dumps_edges_.begin(), | |
291 other->allocator_dumps_edges_.end()); | 290 other->allocator_dumps_edges_.end()); |
292 other->allocator_dumps_edges_.clear(); | 291 other->allocator_dumps_edges_.clear(); |
293 | 292 |
294 for (auto& it : other->heap_dumps_) { | 293 for (auto& it : other->heap_dumps_) { |
295 DCHECK_EQ(0ul, heap_dumps_.count(it.first)); | 294 DCHECK_EQ(0ul, heap_dumps_.count(it.first)); |
296 heap_dumps_.insert(std::make_pair(it.first, std::move(it.second))); | 295 heap_dumps_.insert(std::make_pair(it.first, std::move(it.second))); |
297 } | 296 } |
298 other->heap_dumps_.clear(); | 297 other->heap_dumps_.clear(); |
299 } | 298 } |
300 | 299 |
(...skipping 18 matching lines...) Expand all Loading... | |
319 } | 318 } |
320 | 319 |
321 if (heap_dumps_.size() > 0) { | 320 if (heap_dumps_.size() > 0) { |
322 value->BeginDictionary("heaps"); | 321 value->BeginDictionary("heaps"); |
323 for (const auto& name_and_dump : heap_dumps_) | 322 for (const auto& name_and_dump : heap_dumps_) |
324 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); | 323 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); |
325 value->EndDictionary(); // "heaps" | 324 value->EndDictionary(); // "heaps" |
326 } | 325 } |
327 | 326 |
328 value->BeginArray("allocators_graph"); | 327 value->BeginArray("allocators_graph"); |
329 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { | 328 for (const auto& it : allocator_dumps_edges_) { |
329 const MemoryAllocatorDumpEdge& edge = it.second; | |
330 value->BeginDictionary(); | 330 value->BeginDictionary(); |
331 value->SetString("source", edge.source.ToString()); | 331 value->SetString("source", edge.source.ToString()); |
332 value->SetString("target", edge.target.ToString()); | 332 value->SetString("target", edge.target.ToString()); |
333 value->SetInteger("importance", edge.importance); | 333 value->SetInteger("importance", edge.importance); |
334 value->SetString("type", edge.type); | 334 value->SetString("type", edge.type); |
335 value->EndDictionary(); | 335 value->EndDictionary(); |
336 } | 336 } |
337 value->EndArray(); | 337 value->EndArray(); |
338 } | 338 } |
339 | 339 |
340 void ProcessMemoryDump::AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 340 void ProcessMemoryDump::AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
341 const MemoryAllocatorDumpGuid& target, | 341 const MemoryAllocatorDumpGuid& target, |
342 int importance) { | 342 int importance) { |
343 allocator_dumps_edges_.push_back( | 343 DCHECK(allocator_dumps_edges_.count(source) == 0 || |
344 {source, target, importance, kEdgeTypeOwnership}); | 344 allocator_dumps_edges_[source].overridable) |
345 << "Cannot add multiple ownership edges between same allocator dumps"; | |
Primiano Tucci (use gerrit)
2017/06/06 18:50:50
I think the dcheck itself is quite self-explicativ
ssid
2017/06/07 01:16:32
removed.
| |
346 allocator_dumps_edges_[source] = { | |
347 source, target, importance, kEdgeTypeOwnership, false /* overridable */}; | |
345 } | 348 } |
346 | 349 |
347 void ProcessMemoryDump::AddOwnershipEdge( | 350 void ProcessMemoryDump::AddOwnershipEdge( |
348 const MemoryAllocatorDumpGuid& source, | 351 const MemoryAllocatorDumpGuid& source, |
349 const MemoryAllocatorDumpGuid& target) { | 352 const MemoryAllocatorDumpGuid& target) { |
350 AddOwnershipEdge(source, target, 0 /* importance */); | 353 AddOwnershipEdge(source, target, 0 /* importance */); |
351 } | 354 } |
352 | 355 |
356 void ProcessMemoryDump::AddOverridableOwnershipEdge( | |
357 const MemoryAllocatorDumpGuid& source, | |
358 const MemoryAllocatorDumpGuid& target, | |
359 int importance) { | |
360 if (allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end()) { | |
Primiano Tucci (use gerrit)
2017/06/06 18:50:49
count()
ssid
2017/06/07 01:16:32
ouch, sorry.
| |
361 allocator_dumps_edges_[source] = { | |
362 source, target, importance, kEdgeTypeOwnership, true /* overridable */}; | |
363 } else { | |
364 // An edge between the source and target already exits. So, do nothing here | |
365 // since the new overridable edge is implicitly overridden by a strong edge | |
366 // which was created earlier. | |
367 DCHECK(!allocator_dumps_edges_[source].overridable); | |
368 } | |
369 } | |
370 | |
353 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 371 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
354 const std::string& target_node_name) { | 372 const std::string& target_node_name) { |
355 // Do not create new dumps for suballocations in background mode. | 373 // Do not create new dumps for suballocations in background mode. |
356 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 374 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
357 return; | 375 return; |
358 | 376 |
359 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 377 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
360 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 378 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
361 AddOwnershipEdge(source, target_child_mad->guid()); | 379 AddOwnershipEdge(source, target_child_mad->guid()); |
362 } | 380 } |
363 | 381 |
364 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 382 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
365 DCHECK(is_black_hole_non_fatal_for_testing_); | 383 DCHECK(is_black_hole_non_fatal_for_testing_); |
366 if (!black_hole_mad_) | 384 if (!black_hole_mad_) |
367 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 385 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
368 return black_hole_mad_.get(); | 386 return black_hole_mad_.get(); |
369 } | 387 } |
370 | 388 |
371 } // namespace trace_event | 389 } // namespace trace_event |
372 } // namespace base | 390 } // namespace base |
OLD | NEW |