Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: components/discardable_memory/common/discardable_shared_memory_heap.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: Implement buckets Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 pmd->GetSharedGlobalAllocatorDump(shared_segment_guid) 434 pmd->GetSharedGlobalAllocatorDump(shared_segment_guid)
434 ->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 435 ->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
435 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 436 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
436 allocated_objects_size_in_bytes); 437 allocated_objects_size_in_bytes);
437 438
438 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) 439 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps)
439 // the tracing UI will account the effective size of the segment to the 440 // the tracing UI will account the effective size of the segment to the
440 // client. 441 // client.
441 const int kImportance = 2; 442 const int kImportance = 2;
442 pmd->AddOwnershipEdge(segment_dump->guid(), shared_segment_guid, kImportance); 443 pmd->AddOwnershipEdge(segment_dump->guid(), shared_segment_guid, kImportance);
444 base::SharedMemoryTracker::AddOwnershipEdgeToSharedGlobalDump(
445 pmd, shared_segment_guid,
446 shared_memory->handle(), shared_memory->mapped_size());
443 } 447 }
444 448
445 // static 449 // static
446 base::trace_event::MemoryAllocatorDumpGuid 450 base::trace_event::MemoryAllocatorDumpGuid
447 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( 451 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(
448 uint64_t tracing_process_id, 452 uint64_t tracing_process_id,
449 int32_t segment_id) { 453 int32_t segment_id) {
450 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( 454 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf(
451 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); 455 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id));
452 } 456 }
(...skipping 14 matching lines...) Expand all
467 ScopedVector<ScopedMemorySegment>::const_iterator it = 471 ScopedVector<ScopedMemorySegment>::const_iterator it =
468 std::find_if(memory_segments_.begin(), memory_segments_.end(), 472 std::find_if(memory_segments_.begin(), memory_segments_.end(),
469 [span](const ScopedMemorySegment* segment) { 473 [span](const ScopedMemorySegment* segment) {
470 return segment->ContainsSpan(span); 474 return segment->ContainsSpan(span);
471 }); 475 });
472 DCHECK(it != memory_segments_.end()); 476 DCHECK(it != memory_segments_.end());
473 return (*it)->CreateMemoryAllocatorDump(span, block_size_, name, pmd); 477 return (*it)->CreateMemoryAllocatorDump(span, block_size_, name, pmd);
474 } 478 }
475 479
476 } // namespace discardable_memory 480 } // namespace discardable_memory
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698