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 allocator_dumps_edges_[source] = { |
| 346 source, target, importance, kEdgeTypeOwnership, false /* overridable */}; |
345 } | 347 } |
346 | 348 |
347 void ProcessMemoryDump::AddOwnershipEdge( | 349 void ProcessMemoryDump::AddOwnershipEdge( |
348 const MemoryAllocatorDumpGuid& source, | 350 const MemoryAllocatorDumpGuid& source, |
349 const MemoryAllocatorDumpGuid& target) { | 351 const MemoryAllocatorDumpGuid& target) { |
350 AddOwnershipEdge(source, target, 0 /* importance */); | 352 AddOwnershipEdge(source, target, 0 /* importance */); |
351 } | 353 } |
352 | 354 |
| 355 void ProcessMemoryDump::AddOverridableOwnershipEdge( |
| 356 const MemoryAllocatorDumpGuid& source, |
| 357 const MemoryAllocatorDumpGuid& target, |
| 358 int importance) { |
| 359 if (allocator_dumps_edges_.count(source) == 0) { |
| 360 allocator_dumps_edges_[source] = { |
| 361 source, target, importance, kEdgeTypeOwnership, true /* overridable */}; |
| 362 } else { |
| 363 // An edge between the source and target already exits. So, do nothing here |
| 364 // since the new overridable edge is implicitly overridden by a strong edge |
| 365 // which was created earlier. |
| 366 DCHECK(!allocator_dumps_edges_[source].overridable); |
| 367 } |
| 368 } |
| 369 |
353 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 370 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
354 const std::string& target_node_name) { | 371 const std::string& target_node_name) { |
355 // Do not create new dumps for suballocations in background mode. | 372 // Do not create new dumps for suballocations in background mode. |
356 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 373 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
357 return; | 374 return; |
358 | 375 |
359 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 376 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
360 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 377 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
361 AddOwnershipEdge(source, target_child_mad->guid()); | 378 AddOwnershipEdge(source, target_child_mad->guid()); |
362 } | 379 } |
363 | 380 |
364 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 381 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
365 DCHECK(is_black_hole_non_fatal_for_testing_); | 382 DCHECK(is_black_hole_non_fatal_for_testing_); |
366 if (!black_hole_mad_) | 383 if (!black_hole_mad_) |
367 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 384 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
368 return black_hole_mad_.get(); | 385 return black_hole_mad_.get(); |
369 } | 386 } |
370 | 387 |
371 } // namespace trace_event | 388 } // namespace trace_event |
372 } // namespace base | 389 } // namespace base |
OLD | NEW |