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

Side by Side Diff: content/common/discardable_shared_memory_heap.cc

Issue 1306243003: Add support to create memory allocator dump in base::DiscardableMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix html_viewer. Created 5 years, 4 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 "content/common/discardable_shared_memory_heap.h" 5 #include "content/common/discardable_shared_memory_heap.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/discardable_shared_memory.h" 10 #include "base/memory/discardable_shared_memory.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsUsed() const { 55 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsUsed() const {
56 return heap_->IsMemoryUsed(shared_memory_.get(), size_); 56 return heap_->IsMemoryUsed(shared_memory_.get(), size_);
57 } 57 }
58 58
59 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const { 59 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const {
60 return heap_->IsMemoryResident(shared_memory_.get()); 60 return heap_->IsMemoryResident(shared_memory_.get());
61 } 61 }
62 62
63 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::ContainsSpan(
64 Span* span) const {
65 return shared_memory_ == span->shared_memory();
66 }
67
68 base::trace_event::MemoryAllocatorDump*
69 DiscardableSharedMemoryHeap::ScopedMemorySegment::CreateMemoryAllocatorDump(
70 Span* span,
71 const char* name,
72 base::trace_event::ProcessMemoryDump* pmd) const {
73 DCHECK_EQ(shared_memory_, span->shared_memory());
74 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
75 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
76 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
77 static_cast<uint64_t>(span->length()));
78
79 pmd->AddSuballocation(dump->guid(),
80 base::StringPrintf("discardable/segment_%d", id_));
81 return dump;
82 }
83
63 void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump( 84 void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump(
64 base::trace_event::ProcessMemoryDump* pmd) const { 85 base::trace_event::ProcessMemoryDump* pmd) const {
65 heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd); 86 heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd);
66 } 87 }
67 88
68 DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size) 89 DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size)
69 : block_size_(block_size), num_blocks_(0), num_free_blocks_(0) { 90 : block_size_(block_size), num_blocks_(0), num_free_blocks_(0) {
70 DCHECK_NE(block_size_, 0u); 91 DCHECK_NE(block_size_, 0u);
71 DCHECK(IsPowerOfTwo(block_size_)); 92 DCHECK(IsPowerOfTwo(block_size_));
72 } 93 }
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 412 }
392 413
393 // static 414 // static
394 base::trace_event::MemoryAllocatorDumpGuid 415 base::trace_event::MemoryAllocatorDumpGuid
395 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, 416 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id,
396 int32 segment_id) { 417 int32 segment_id) {
397 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( 418 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf(
398 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); 419 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id));
399 } 420 }
400 421
422 base::trace_event::MemoryAllocatorDump*
423 DiscardableSharedMemoryHeap::CreateMemoryAllocatorDump(
424 Span* span,
425 const char* name,
426 base::trace_event::ProcessMemoryDump* pmd) const {
427 if (!span->shared_memory()) {
428 base::trace_event::MemoryAllocatorDump* dump =
429 pmd->CreateAllocatorDump(name);
430 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
431 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 0u);
432 return dump;
433 }
434
435 ScopedVector<ScopedMemorySegment>::const_iterator it =
436 std::find_if(memory_segments_.begin(), memory_segments_.end(),
437 [span](const ScopedMemorySegment* segment) {
438 return segment->ContainsSpan(span);
439 });
440 DCHECK(it != memory_segments_.end());
441 return (*it)->CreateMemoryAllocatorDump(span, name, pmd);
442 }
443
401 } // namespace content 444 } // namespace content
OLDNEW
« no previous file with comments | « content/common/discardable_shared_memory_heap.h ('k') | content/common/discardable_shared_memory_heap_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698