| 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& edge : allocator_dumps_edges_) { |
| 330 value->BeginDictionary(); | 329 value->BeginDictionary(); |
| 331 value->SetString("source", edge.source.ToString()); | 330 value->SetString("source", edge.first.ToString()); |
| 332 value->SetString("target", edge.target.ToString()); | 331 value->SetString("target", edge.second.target.ToString()); |
| 333 value->SetInteger("importance", edge.importance); | 332 value->SetInteger("importance", edge.second.importance); |
| 334 value->SetString("type", edge.type); | 333 value->SetString("type", edge.second.type); |
| 335 value->EndDictionary(); | 334 value->EndDictionary(); |
| 336 } | 335 } |
| 337 value->EndArray(); | 336 value->EndArray(); |
| 338 } | 337 } |
| 339 | 338 |
| 340 void ProcessMemoryDump::AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 339 void ProcessMemoryDump::AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
| 341 const MemoryAllocatorDumpGuid& target, | 340 const MemoryAllocatorDumpGuid& target, |
| 342 int importance) { | 341 int importance) { |
| 343 allocator_dumps_edges_.push_back( | 342 DCHECK(allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end() || |
| 344 {source, target, importance, kEdgeTypeOwnership}); | 343 allocator_dumps_edges_[source].overridable) |
| 344 << "Cannot add multiple ownership edges between same allocator dumps"; |
| 345 allocator_dumps_edges_[source] = {target, importance, kEdgeTypeOwnership, |
| 346 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::CreateSharedMemoryOwnershipEdge( |
| 356 const MemoryAllocatorDumpGuid& client_dump_guid, |
| 357 const MemoryAllocatorDumpGuid& client_global_dump_guid, |
| 358 bool is_weak, |
| 359 int importance, |
| 360 uint64_t shm_unguessable_token) { |
| 361 if (UseNewOwnershipEdges() && shared_memory_handle) { |
| 362 base::SharedMemoryTracker::AddOwnershipEdge(pmd, dump->guid(), |
| 363 shared_memory_handle); |
| 364 AddOwnershipEdge( |
| 365 SharedMemoryTracker::GetLocallDumpGUIDFromToken(shm_unguessable_token), |
| 366 SharedMemoryTracker::GetGlobalDumpGUIDFromToken(shm_unguessable_token), |
| 367 importance); |
| 368 } else { |
| 369 // Existing logic for ownership |
| 370 if (is_weak) |
| 371 pmd->CreateWeakSharedGlobalAllocatorDump(client_global_dump_guid); |
| 372 else |
| 373 pmd->CreateSharedGlobalAllocatorDump(client_global_dump_guid); |
| 374 pmd->AddOwnershipEdge(client_dump_guid, client_global_dump_guid, |
| 375 importance); |
| 376 } |
| 377 } |
| 378 |
| 379 void ProcessMemoryDump::AddOverridableOwnershipEdge( |
| 380 const MemoryAllocatorDumpGuid& source, |
| 381 const MemoryAllocatorDumpGuid& target, |
| 382 int importance) { |
| 383 if (allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end() || |
| 384 allocator_dumps_edges_[source].overridable) { |
| 385 allocator_dumps_edges_[source] = {target, importance, kEdgeTypeOwnership, |
| 386 true /* overridable */}; |
| 387 } else { |
| 388 NOTREACHED(); |
| 389 } |
| 390 } |
| 391 |
| 353 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 392 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
| 354 const std::string& target_node_name) { | 393 const std::string& target_node_name) { |
| 355 // Do not create new dumps for suballocations in background mode. | 394 // Do not create new dumps for suballocations in background mode. |
| 356 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 395 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
| 357 return; | 396 return; |
| 358 | 397 |
| 359 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 398 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
| 360 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 399 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
| 361 AddOwnershipEdge(source, target_child_mad->guid()); | 400 AddOwnershipEdge(source, target_child_mad->guid()); |
| 362 } | 401 } |
| 363 | 402 |
| 364 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 403 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
| 365 DCHECK(is_black_hole_non_fatal_for_testing_); | 404 DCHECK(is_black_hole_non_fatal_for_testing_); |
| 366 if (!black_hole_mad_) | 405 if (!black_hole_mad_) |
| 367 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 406 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
| 368 return black_hole_mad_.get(); | 407 return black_hole_mad_.get(); |
| 369 } | 408 } |
| 370 | 409 |
| 371 } // namespace trace_event | 410 } // namespace trace_event |
| 372 } // namespace base | 411 } // namespace base |
| OLD | NEW |