Chromium Code Reviews| 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 cretaed by SharedMemoryTracker for the memory | |
| 419 // segment. | |
| 420 auto local_shm_guid = | |
| 421 SharedMemoryTracker::GetDumpGUIDForTracing(shared_memory_guid); | |
| 422 // The dump guid of the global dump cretaed by the tracker for the memory | |
|
Primiano Tucci (use gerrit)
2017/06/08 15:09:33
nit: space comments from previous code with \n. di
ssid
2017/06/08 18:44:23
Done.
| |
| 423 // segment. | |
| 424 auto global_shm_guid = | |
| 425 SharedMemoryTracker::GetGlobalDumpGUIDForTracing(shared_memory_guid); | |
| 426 // Create an edge between local dump of the client and the local dump of the | |
| 427 // SharedMemoryTracker. Do not need to create the dumps here since the | |
| 428 // tracker would create them. | |
| 429 AddOwnershipEdge(client_local_dump_guid, local_shm_guid); | |
| 430 | |
| 431 // TODO(ssid): Handle the case of weak dumps here. This needs a new function | |
| 432 // GetOrCreaetGlobalDump() in PMD since we need to change the behavior of | |
| 433 // the created global dump. | |
| 434 // Create an edge that overrides the edge created | |
|
hajimehoshi
2017/06/08 05:10:05
nit: 'by' should be in this line?
ssid
2017/06/08 18:44:23
Yeah had a battle with git cl format and lost it :
| |
| 435 // by SharedMemoryTracker. | |
| 436 AddOwnershipEdge(local_shm_guid, global_shm_guid, importance); | |
| 437 } else { | |
| 438 // This is the old model where the clients create global dumps for | |
| 439 // themselves. | |
| 440 if (is_weak) | |
| 441 CreateWeakSharedGlobalAllocatorDump(client_global_dump_guid); | |
| 442 else | |
| 443 CreateSharedGlobalAllocatorDump(client_global_dump_guid); | |
| 444 AddOwnershipEdge(client_local_dump_guid, client_global_dump_guid, | |
| 445 importance); | |
| 446 } | |
| 447 } | |
| 448 | |
| 385 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 449 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
| 386 const std::string& target_node_name) { | 450 const std::string& target_node_name) { |
| 387 // Do not create new dumps for suballocations in background mode. | 451 // Do not create new dumps for suballocations in background mode. |
| 388 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 452 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
| 389 return; | 453 return; |
| 390 | 454 |
| 391 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 455 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
| 392 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 456 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
| 393 AddOwnershipEdge(source, target_child_mad->guid()); | 457 AddOwnershipEdge(source, target_child_mad->guid()); |
| 394 } | 458 } |
| 395 | 459 |
| 396 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 460 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
| 397 DCHECK(is_black_hole_non_fatal_for_testing_); | 461 DCHECK(is_black_hole_non_fatal_for_testing_); |
| 398 if (!black_hole_mad_) | 462 if (!black_hole_mad_) |
| 399 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 463 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
| 400 return black_hole_mad_.get(); | 464 return black_hole_mad_.get(); |
| 401 } | 465 } |
| 402 | 466 |
| 403 } // namespace trace_event | 467 } // namespace trace_event |
| 404 } // namespace base | 468 } // namespace base |
| OLD | NEW |