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/memory_infra_background_whitelist.h" | 16 #include "base/trace_event/memory_infra_background_whitelist.h" |
16 #include "base/trace_event/process_memory_totals.h" | 17 #include "base/trace_event/process_memory_totals.h" |
17 #include "base/trace_event/trace_event_argument.h" | 18 #include "base/trace_event/trace_event_argument.h" |
19 #include "base/unguessable_token.h" | |
18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
19 | 21 |
20 #if defined(OS_IOS) | 22 #if defined(OS_IOS) |
21 #include <mach/vm_page_size.h> | 23 #include <mach/vm_page_size.h> |
22 #endif | 24 #endif |
23 | 25 |
24 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
25 #include <sys/mman.h> | 27 #include <sys/mman.h> |
26 #endif | 28 #endif |
27 | 29 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 allocator_dumps_edges_[source] = { | 348 allocator_dumps_edges_[source] = { |
347 source, target, importance, kEdgeTypeOwnership, false /* overridable */}; | 349 source, target, importance, kEdgeTypeOwnership, false /* overridable */}; |
348 } | 350 } |
349 | 351 |
350 void ProcessMemoryDump::AddOwnershipEdge( | 352 void ProcessMemoryDump::AddOwnershipEdge( |
351 const MemoryAllocatorDumpGuid& source, | 353 const MemoryAllocatorDumpGuid& source, |
352 const MemoryAllocatorDumpGuid& target) { | 354 const MemoryAllocatorDumpGuid& target) { |
353 AddOwnershipEdge(source, target, 0 /* importance */); | 355 AddOwnershipEdge(source, target, 0 /* importance */); |
354 } | 356 } |
355 | 357 |
358 void ProcessMemoryDump::CreateSharedMemoryOwnershipEdge( | |
359 const MemoryAllocatorDumpGuid& client_local_dump_guid, | |
360 const MemoryAllocatorDumpGuid& client_global_dump_guid, | |
361 const UnguessableToken& shared_memory_guid, | |
362 int importance) { | |
363 CreateWeakSharedMemoryOwnershipEdge( | |
364 client_local_dump_guid, client_global_dump_guid, shared_memory_guid, | |
365 importance, false /*is_weak*/); | |
366 } | |
367 | |
356 void ProcessMemoryDump::AddOverridableOwnershipEdge( | 368 void ProcessMemoryDump::AddOverridableOwnershipEdge( |
357 const MemoryAllocatorDumpGuid& source, | 369 const MemoryAllocatorDumpGuid& source, |
358 const MemoryAllocatorDumpGuid& target, | 370 const MemoryAllocatorDumpGuid& target, |
359 int importance) { | 371 int importance) { |
360 if (allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end()) { | 372 if (allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end()) { |
361 allocator_dumps_edges_[source] = { | 373 allocator_dumps_edges_[source] = { |
362 source, target, importance, kEdgeTypeOwnership, true /* overridable */}; | 374 source, target, importance, kEdgeTypeOwnership, true /* overridable */}; |
363 } else { | 375 } else { |
364 // An edge between the source and target already exits. So, do nothing here | 376 // 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 | 377 // since the new overridable edge is implicitly overridden by a strong edge |
366 // which was created earlier. | 378 // which was created earlier. |
367 DCHECK(!allocator_dumps_edges_[source].overridable); | 379 DCHECK(!allocator_dumps_edges_[source].overridable); |
368 } | 380 } |
369 } | 381 } |
370 | 382 |
383 void ProcessMemoryDump::CreateWeakSharedMemoryOwnershipEdge( | |
384 const MemoryAllocatorDumpGuid& client_local_dump_guid, | |
385 const MemoryAllocatorDumpGuid& client_global_dump_guid, | |
386 const UnguessableToken& shared_memory_guid, | |
387 int importance, | |
388 bool is_weak) { | |
389 if (MemoryAllocatorDumpGuid::UseSharedMemoryBasedGUIDs() && | |
390 !shared_memory_guid.is_empty()) { | |
391 // New model where the global dumps created by SharedMemoryTracker are used | |
392 // for the clients. | |
393 | |
hajimehoshi
2017/06/07 04:58:04
First I thought CreateSharedGlobalAllocatorDump sh
ssid
2017/06/08 00:05:58
Added extra comment.
That is exactly what the todo
| |
394 // The guid of the local dump cretaed by | |
395 // SharedMemoryTracker for the memory segment. | |
396 auto local_shm_guid = | |
397 SharedMemoryTracker::GetDumpGUIDForTracing(shared_memory_guid); | |
398 // The dump guid of the global dump cretaed by the tracker for the memory | |
399 // segment. | |
400 auto global_shm_guid = | |
401 SharedMemoryTracker::GetGlobalDumpGUIDForTracing(shared_memory_guid); | |
402 // Create an edge between local dump of the client and the local dump of the | |
403 // SharedMemoryTracker. | |
404 AddOwnershipEdge(client_local_dump_guid, local_shm_guid); | |
405 | |
406 // TODO(ssid): Handle the case of weak dumps here. This needs a new function | |
407 // GetOrCreaetGlobalDump() in PMD since we need to change the behavior of | |
408 // the created global dump. | |
409 // Create an edge that overrides the edge created | |
410 // by SharedMemoryTracker. | |
411 AddOwnershipEdge(local_shm_guid, global_shm_guid, importance); | |
412 } else { | |
413 // This is the old model where the clients create global dumps for | |
414 // themselves. | |
415 if (is_weak) | |
416 CreateWeakSharedGlobalAllocatorDump(client_global_dump_guid); | |
417 else | |
418 CreateSharedGlobalAllocatorDump(client_global_dump_guid); | |
419 AddOwnershipEdge(client_local_dump_guid, client_global_dump_guid, | |
420 importance); | |
421 } | |
422 } | |
423 | |
371 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 424 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
372 const std::string& target_node_name) { | 425 const std::string& target_node_name) { |
373 // Do not create new dumps for suballocations in background mode. | 426 // Do not create new dumps for suballocations in background mode. |
374 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 427 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
375 return; | 428 return; |
376 | 429 |
377 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 430 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
378 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 431 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
379 AddOwnershipEdge(source, target_child_mad->guid()); | 432 AddOwnershipEdge(source, target_child_mad->guid()); |
380 } | 433 } |
381 | 434 |
382 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 435 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
383 DCHECK(is_black_hole_non_fatal_for_testing_); | 436 DCHECK(is_black_hole_non_fatal_for_testing_); |
384 if (!black_hole_mad_) | 437 if (!black_hole_mad_) |
385 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 438 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
386 return black_hole_mad_.get(); | 439 return black_hole_mad_.get(); |
387 } | 440 } |
388 | 441 |
389 } // namespace trace_event | 442 } // namespace trace_event |
390 } // namespace base | 443 } // namespace base |
OLD | NEW |