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 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/shared_memory_tracker.h" |
12 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/trace_event/heap_profiler_heap_dump_writer.h" | 15 #include "base/trace_event/heap_profiler_heap_dump_writer.h" |
15 #include "base/trace_event/heap_profiler_serialization_state.h" | 16 #include "base/trace_event/heap_profiler_serialization_state.h" |
16 #include "base/trace_event/memory_infra_background_whitelist.h" | 17 #include "base/trace_event/memory_infra_background_whitelist.h" |
17 #include "base/trace_event/process_memory_totals.h" | 18 #include "base/trace_event/process_memory_totals.h" |
18 #include "base/trace_event/trace_event_argument.h" | 19 #include "base/trace_event/trace_event_argument.h" |
| 20 #include "base/unguessable_token.h" |
19 #include "build/build_config.h" | 21 #include "build/build_config.h" |
20 | 22 |
21 #if defined(OS_IOS) | 23 #if defined(OS_IOS) |
22 #include <mach/vm_page_size.h> | 24 #include <mach/vm_page_size.h> |
23 #endif | 25 #endif |
24 | 26 |
25 #if defined(OS_POSIX) | 27 #if defined(OS_POSIX) |
26 #include <sys/mman.h> | 28 #include <sys/mman.h> |
27 #endif | 29 #endif |
28 | 30 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 allocator_dumps_edges_[source] = { | 377 allocator_dumps_edges_[source] = { |
376 source, target, importance, kEdgeTypeOwnership, true /* overridable */}; | 378 source, target, importance, kEdgeTypeOwnership, true /* overridable */}; |
377 } else { | 379 } else { |
378 // An edge between the source and target already exits. So, do nothing here | 380 // An edge between the source and target already exits. So, do nothing here |
379 // since the new overridable edge is implicitly overridden by a strong edge | 381 // since the new overridable edge is implicitly overridden by a strong edge |
380 // which was created earlier. | 382 // which was created earlier. |
381 DCHECK(!allocator_dumps_edges_[source].overridable); | 383 DCHECK(!allocator_dumps_edges_[source].overridable); |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
| 387 void ProcessMemoryDump::CreateSharedMemoryOwnershipEdge( |
| 388 const MemoryAllocatorDumpGuid& client_local_dump_guid, |
| 389 const MemoryAllocatorDumpGuid& client_global_dump_guid, |
| 390 const UnguessableToken& shared_memory_guid, |
| 391 int importance) { |
| 392 CreateSharedMemoryOwnershipEdgeInternal( |
| 393 client_local_dump_guid, client_global_dump_guid, shared_memory_guid, |
| 394 importance, false /*is_weak*/); |
| 395 } |
| 396 |
| 397 void ProcessMemoryDump::CreateWeakSharedMemoryOwnershipEdge( |
| 398 const MemoryAllocatorDumpGuid& client_local_dump_guid, |
| 399 const MemoryAllocatorDumpGuid& client_global_dump_guid, |
| 400 const UnguessableToken& shared_memory_guid, |
| 401 int importance) { |
| 402 CreateSharedMemoryOwnershipEdgeInternal( |
| 403 client_local_dump_guid, client_global_dump_guid, shared_memory_guid, |
| 404 importance, true /*is_weak*/); |
| 405 } |
| 406 |
| 407 void ProcessMemoryDump::CreateSharedMemoryOwnershipEdgeInternal( |
| 408 const MemoryAllocatorDumpGuid& client_local_dump_guid, |
| 409 const MemoryAllocatorDumpGuid& client_global_dump_guid, |
| 410 const UnguessableToken& shared_memory_guid, |
| 411 int importance, |
| 412 bool is_weak) { |
| 413 if (MemoryAllocatorDumpGuid::UseSharedMemoryBasedGUIDs()) { |
| 414 DCHECK(!shared_memory_guid.is_empty()); |
| 415 // New model where the global dumps created by SharedMemoryTracker are used |
| 416 // for the clients. |
| 417 |
| 418 // The guid of the local dump created by SharedMemoryTracker for the memory |
| 419 // segment. |
| 420 auto local_shm_guid = |
| 421 SharedMemoryTracker::GetDumpGUIDForTracing(shared_memory_guid); |
| 422 |
| 423 // The dump guid of the global dump created by the tracker for the memory |
| 424 // segment. |
| 425 auto global_shm_guid = |
| 426 SharedMemoryTracker::GetGlobalDumpGUIDForTracing(shared_memory_guid); |
| 427 |
| 428 // Create an edge between local dump of the client and the local dump of the |
| 429 // SharedMemoryTracker. Do not need to create the dumps here since the |
| 430 // tracker would create them. |
| 431 AddOwnershipEdge(client_local_dump_guid, local_shm_guid); |
| 432 |
| 433 // TODO(ssid): Handle the case of weak dumps here. This needs a new function |
| 434 // GetOrCreaetGlobalDump() in PMD since we need to change the behavior of |
| 435 // the created global dump. |
| 436 // Create an edge that overrides the edge created by SharedMemoryTracker. |
| 437 AddOwnershipEdge(local_shm_guid, global_shm_guid, importance); |
| 438 } else { |
| 439 // This is the old model where the clients create global dumps for |
| 440 // themselves. |
| 441 if (is_weak) |
| 442 CreateWeakSharedGlobalAllocatorDump(client_global_dump_guid); |
| 443 else |
| 444 CreateSharedGlobalAllocatorDump(client_global_dump_guid); |
| 445 AddOwnershipEdge(client_local_dump_guid, client_global_dump_guid, |
| 446 importance); |
| 447 } |
| 448 } |
| 449 |
385 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 450 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
386 const std::string& target_node_name) { | 451 const std::string& target_node_name) { |
387 // Do not create new dumps for suballocations in background mode. | 452 // Do not create new dumps for suballocations in background mode. |
388 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 453 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
389 return; | 454 return; |
390 | 455 |
391 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 456 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
392 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 457 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
393 AddOwnershipEdge(source, target_child_mad->guid()); | 458 AddOwnershipEdge(source, target_child_mad->guid()); |
394 } | 459 } |
395 | 460 |
396 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 461 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
397 DCHECK(is_black_hole_non_fatal_for_testing_); | 462 DCHECK(is_black_hole_non_fatal_for_testing_); |
398 if (!black_hole_mad_) | 463 if (!black_hole_mad_) |
399 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 464 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
400 return black_hole_mad_.get(); | 465 return black_hole_mad_.get(); |
401 } | 466 } |
402 | 467 |
403 } // namespace trace_event | 468 } // namespace trace_event |
404 } // namespace base | 469 } // namespace base |
OLD | NEW |