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

Unified 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: Nits. 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 side-by-side diff with in-line comments
Download patch
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..fe3912cad2fc599afe9bfd468a63bad06e584e45 100644
--- a/content/common/discardable_shared_memory_heap.cc
+++ b/content/common/discardable_shared_memory_heap.cc
@@ -60,6 +60,24 @@ bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const {
return heap_->IsMemoryResident(shared_memory_.get());
}
+base::trace_event::MemoryAllocatorDump*
+DiscardableSharedMemoryHeap::ScopedMemorySegment::CreateMemoryAllocatorDump(
+ Span* span,
+ const char* name,
+ base::trace_event::ProcessMemoryDump* pmd) const {
+ if (shared_memory_ != span->shared_memory())
+ return nullptr;
+
+ 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 +416,27 @@ 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() == nullptr)
reveman 2015/08/21 18:05:24 nit: !span->shared_memory()
ssid 2015/08/24 14:52:10 Done.
+ return nullptr;
+
+ base::trace_event::MemoryAllocatorDump* allocator_dump;
+ std::for_each(
reveman 2015/08/21 18:05:24 can you instead do a std:::find_if for span->share
ssid 2015/08/21 19:02:30 I cannot do it because I have to match the span->s
reveman 2015/08/22 14:21:16 How about adding a "bool ScopedMemorySegment::Cont
ssid 2015/08/22 14:50:19 Yes I planned that at first, but I also need to ad
reveman 2015/08/22 15:04:07 I was thinking you could use the ScopedMemorySegme
ssid 2015/08/22 15:13:00 Ah sorry, I see what you meant now, sounds good, t
ssid 2015/08/24 14:52:10 Done.
+ memory_segments_.begin(), memory_segments_.end(),
+ [span, name, pmd, &allocator_dump](const ScopedMemorySegment* segment) {
+ base::trace_event::MemoryAllocatorDump* dump =
+ segment->CreateMemoryAllocatorDump(span, name, pmd);
+ if (dump != nullptr)
+ allocator_dump = dump;
+ });
+
+ // Span with a shared memory should be found in some segment.
+ DCHECK(allocator_dump != nullptr);
+ return allocator_dump;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698