Chromium Code Reviews| Index: content/common/discardable_shared_memory_heap.cc |
| diff --git a/content/common/discardable_shared_memory_heap.cc b/content/common/discardable_shared_memory_heap.cc |
| index 958fa82554efecf5d9c4dee25bb6206cf7e891c9..604d6edaf78f8d08d042f7bcd8530ae58bf58d95 100644 |
| --- a/content/common/discardable_shared_memory_heap.cc |
| +++ b/content/common/discardable_shared_memory_heap.cc |
| @@ -60,6 +60,27 @@ bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const { |
| return heap_->IsMemoryResident(shared_memory_.get()); |
| } |
| +bool DiscardableSharedMemoryHeap::ScopedMemorySegment::ContainsSpan( |
| + Span* span) const { |
| + return shared_memory_ == span->shared_memory(); |
| +} |
| + |
| +base::trace_event::MemoryAllocatorDump* |
| +DiscardableSharedMemoryHeap::ScopedMemorySegment::CreateMemoryAllocatorDump( |
| + Span* span, |
| + const char* name, |
| + base::trace_event::ProcessMemoryDump* pmd) const { |
| + DCHECK_EQ(shared_memory_, span->shared_memory()); |
| + base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name); |
| + dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| + static_cast<uint64_t>(span->length())); |
| + |
| + pmd->AddSuballocation(dump->guid(), |
| + base::StringPrintf("discardable/segment_%d", id_)); |
| + return dump; |
| +} |
| + |
| void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump( |
| base::trace_event::ProcessMemoryDump* pmd) const { |
| heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd); |
| @@ -398,4 +419,30 @@ DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, |
| "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); |
| } |
| +base::trace_event::MemoryAllocatorDump* |
| +DiscardableSharedMemoryHeap::CreateMemoryAllocatorDump( |
| + Span* span, |
| + const char* name, |
| + base::trace_event::ProcessMemoryDump* pmd) const { |
| + if (!span->shared_memory()) { |
| + base::trace_event::MemoryAllocatorDump* dump = |
| + pmd->CreateAllocatorDump(name); |
| + dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes, 0u); |
| + return dump; |
| + } |
| + |
| + base::trace_event::MemoryAllocatorDump* allocator_dump; |
| + std::for_each( |
|
reveman
2015/08/24 16:50:06
can you use find_if instead? I think that represen
ssid
2015/08/24 17:21:13
Done.
|
| + memory_segments_.begin(), memory_segments_.end(), |
| + [span, name, pmd, &allocator_dump](const ScopedMemorySegment* segment) { |
| + if (segment->ContainsSpan(span)) |
| + allocator_dump = segment->CreateMemoryAllocatorDump(span, name, pmd); |
| + }); |
| + |
| + // Span with a shared memory should be found in some segment. |
| + DCHECK(allocator_dump != nullptr); |
|
reveman
2015/08/24 16:50:06
nit: DCHECK(!allocator_dump)
though this doesn't
ssid
2015/08/24 17:21:13
Done.
|
| + return allocator_dump; |
| +} |
| + |
| } // namespace content |