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 36ee632255329506570831c90bc23287cad00580..62c54f85aa596db0ef69c9ea7afd44c22e895d90 100644 |
--- a/content/common/discardable_shared_memory_heap.cc |
+++ b/content/common/discardable_shared_memory_heap.cc |
@@ -31,6 +31,12 @@ DiscardableSharedMemoryHeap::Span::Span( |
DiscardableSharedMemoryHeap::Span::~Span() { |
} |
+DiscardableSharedMemoryHeap::MemoryStatistics::MemoryStatistics() { |
+} |
+ |
+DiscardableSharedMemoryHeap::MemoryStatistics::~MemoryStatistics() { |
+} |
+ |
DiscardableSharedMemoryHeap::ScopedMemorySegment::ScopedMemorySegment( |
DiscardableSharedMemoryHeap* heap, |
scoped_ptr<base::DiscardableSharedMemory> shared_memory, |
@@ -55,6 +61,24 @@ bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const { |
return heap_->IsMemoryResident(shared_memory_.get()); |
} |
+void DiscardableSharedMemoryHeap::ScopedMemorySegment::GetStatistics( |
+ MemoryStatistics::SegmentStatistics* segment_stats) { |
reveman
2015/04/23 17:32:30
I prefer if this was kept consistent with Discarda
ssid
2015/04/23 18:03:07
shared_memory is private field here, not shared wi
reveman
2015/04/23 18:11:53
I think Heap class is already a friend.
ssid
2015/04/24 11:23:04
Made it friend now.
|
+ segment_stats->size = size_; |
+ size_t offset = |
+ reinterpret_cast<size_t>(shared_memory_->memory()) / heap_->block_size_; |
+ segment_stats->num_of_objects = 0; |
+ segment_stats->used_size = 0; |
+ size_t end = offset + size_ / heap_->block_size_; |
+ while (offset < end) { |
+ Span* span = heap_->spans_[offset]; |
+ if (!IsInFreeList(span)) { |
+ segment_stats->num_of_objects++; |
+ segment_stats->used_size += span->length_; |
+ } |
+ offset += span->length_; |
+ } |
+} |
+ |
DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size) |
: block_size_(block_size), num_blocks_(0), num_free_blocks_(0) { |
DCHECK_NE(block_size_, 0u); |
@@ -212,6 +236,20 @@ size_t DiscardableSharedMemoryHeap::GetSizeOfFreeLists() const { |
return num_free_blocks_ * block_size_; |
} |
+void DiscardableSharedMemoryHeap::GetMemoryStatistics( |
+ DiscardableSharedMemoryHeap::MemoryStatistics* statistics) { |
+ statistics->block_size = block_size_; |
+ statistics->total_size = GetSize(); |
+ statistics->total_used_size = statistics->total_size - GetSizeOfFreeLists(); |
+ statistics->total_objects = 0; |
+ for (size_t i = 0; i < memory_segments_.size(); i++) { |
+ MemoryStatistics::SegmentStatistics segment_stats; |
+ memory_segments_[i]->GetStatistics(&segment_stats); |
+ statistics->segments_stats.push_back(segment_stats); |
+ statistics->total_objects += segment_stats.num_of_objects; |
+ } |
+} |
+ |
void DiscardableSharedMemoryHeap::InsertIntoFreeList( |
scoped_ptr<DiscardableSharedMemoryHeap::Span> span) { |
DCHECK(!IsInFreeList(span.get())); |