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

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: Addressing comments. 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..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

Powered by Google App Engine
This is Rietveld 408576698