OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/discardable_memory/common/discardable_shared_memory_heap.h" | 5 #include "components/discardable_memory/common/discardable_shared_memory_heap.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/discardable_shared_memory.h" | 12 #include "base/memory/discardable_shared_memory.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/shared_memory_tracker.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/trace_event/memory_dump_manager.h" | 16 #include "base/trace_event/memory_dump_manager.h" |
16 | 17 |
17 namespace discardable_memory { | 18 namespace discardable_memory { |
18 namespace { | 19 namespace { |
19 | 20 |
20 bool IsPowerOfTwo(size_t x) { | 21 bool IsPowerOfTwo(size_t x) { |
21 return (x & (x - 1)) == 0; | 22 return (x & (x - 1)) == 0; |
22 } | 23 } |
23 | 24 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount, | 410 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount, |
410 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 411 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
411 allocated_objects_count); | 412 allocated_objects_count); |
412 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 413 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
413 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 414 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
414 allocated_objects_size_in_bytes); | 415 allocated_objects_size_in_bytes); |
415 obj_dump->AddScalar("locked_size", | 416 obj_dump->AddScalar("locked_size", |
416 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 417 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
417 locked_objects_size_in_bytes); | 418 locked_objects_size_in_bytes); |
418 | 419 |
419 // Emit an ownership edge towards a global allocator dump node. This allows | 420 base::SharedMemoryTracker::AddOwnershipEdges(pmd, obj_dump->guid(), |
420 // to avoid double-counting segments when both browser and client process emit | 421 shared_memory->shared_memory()); |
421 // them. In the special case of single-process-mode, this will be the only | |
422 // dumper active and the single ownership edge will become a no-op in the UI. | |
423 // The global dump is created as a weak dump so that the segment is removed if | |
424 // the browser does not dump it (segment was purged). | |
425 const uint64_t tracing_process_id = | |
426 base::trace_event::MemoryDumpManager::GetInstance() | |
427 ->GetTracingProcessId(); | |
428 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = | |
429 GetSegmentGUIDForTracing(tracing_process_id, segment_id); | |
430 // TODO(ssid): Make this weak once the GUID created is consistent | |
431 // crbug.com/661257. | |
432 pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid); | |
433 | |
434 // The size is added to the global dump so that it gets propagated to both the | |
435 // dumps associated. | |
436 pmd->GetSharedGlobalAllocatorDump(shared_segment_guid) | |
437 ->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
438 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
439 allocated_objects_size_in_bytes); | |
440 | |
441 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) | |
442 // the tracing UI will account the effective size of the segment to the | |
443 // client. | |
444 const int kImportance = 2; | |
445 pmd->AddOwnershipEdge(segment_dump->guid(), shared_segment_guid, kImportance); | |
446 } | 422 } |
447 | 423 |
448 // static | 424 // static |
449 base::trace_event::MemoryAllocatorDumpGuid | 425 base::trace_event::MemoryAllocatorDumpGuid |
450 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( | 426 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( |
451 uint64_t tracing_process_id, | 427 uint64_t tracing_process_id, |
452 int32_t segment_id) { | 428 int32_t segment_id) { |
453 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | 429 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( |
454 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); | 430 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); |
455 } | 431 } |
(...skipping 14 matching lines...) Expand all Loading... |
470 auto it = | 446 auto it = |
471 std::find_if(memory_segments_.begin(), memory_segments_.end(), | 447 std::find_if(memory_segments_.begin(), memory_segments_.end(), |
472 [span](const std::unique_ptr<ScopedMemorySegment>& segment) { | 448 [span](const std::unique_ptr<ScopedMemorySegment>& segment) { |
473 return segment->ContainsSpan(span); | 449 return segment->ContainsSpan(span); |
474 }); | 450 }); |
475 DCHECK(it != memory_segments_.end()); | 451 DCHECK(it != memory_segments_.end()); |
476 return (*it)->CreateMemoryAllocatorDump(span, block_size_, name, pmd); | 452 return (*it)->CreateMemoryAllocatorDump(span, block_size_, name, pmd); |
477 } | 453 } |
478 | 454 |
479 } // namespace discardable_memory | 455 } // namespace discardable_memory |
OLD | NEW |