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

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

Issue 1100073004: Adding discardable memory dump provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments. Created 5 years, 8 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/memory/discardable_shared_memory.h" 9 #include "base/memory/discardable_shared_memory.h"
10 #include "base/strings/stringprintf.h"
10 11
11 namespace content { 12 namespace content {
12 namespace { 13 namespace {
13 14
14 bool IsPowerOfTwo(size_t x) { 15 bool IsPowerOfTwo(size_t x) {
15 return (x & (x - 1)) == 0; 16 return (x & (x - 1)) == 0;
16 } 17 }
17 18
18 bool IsInFreeList(DiscardableSharedMemoryHeap::Span* span) { 19 bool IsInFreeList(DiscardableSharedMemoryHeap::Span* span) {
19 return span->previous() || span->next(); 20 return span->previous() || span->next();
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 206 }
206 207
207 size_t DiscardableSharedMemoryHeap::GetSize() const { 208 size_t DiscardableSharedMemoryHeap::GetSize() const {
208 return num_blocks_ * block_size_; 209 return num_blocks_ * block_size_;
209 } 210 }
210 211
211 size_t DiscardableSharedMemoryHeap::GetSizeOfFreeLists() const { 212 size_t DiscardableSharedMemoryHeap::GetSizeOfFreeLists() const {
212 return num_free_blocks_ * block_size_; 213 return num_free_blocks_ * block_size_;
213 } 214 }
214 215
216 bool DiscardableSharedMemoryHeap::DumpMemoryStatisticsInto(
217 base::trace_event::ProcessMemoryDump* pmd) {
218 for (size_t segment = 0; segment < memory_segments_.size(); segment++) {
reveman 2015/04/24 14:19:36 Would be nice to do something c++-ish like Release
ssid 2015/04/27 11:19:20 Thanks done.
219 std::string segment_id = base::StringPrintf("segment_%zu", segment);
reveman 2015/04/24 14:19:36 nit: maybe move "segment" string to a kMemoryAlloc
ssid 2015/04/27 11:19:20 Done.
220 base::trace_event::MemoryAllocatorDump* segment_dump =
221 pmd->CreateAllocatorDump("discardable", segment_id.c_str());
reveman 2015/04/24 14:19:36 nit: and maybe move this string to a kMemoryAlloca
ssid 2015/04/27 11:19:20 Done.
222
223 size_t num_of_objects = 0;
reveman 2015/04/24 14:19:36 nit: allocated_objects_count Might as well keep t
ssid 2015/04/27 11:19:20 Done.
224 size_t used_size = 0;
reveman 2015/04/24 14:19:36 nit: allocated_objects_size_in_bytes
ssid 2015/04/27 11:19:20 Done.
225 size_t offset = reinterpret_cast<size_t>(
226 memory_segments_[segment]->shared_memory_->memory()) /
227 block_size_;
228 size_t end = offset + memory_segments_[segment]->size_ / block_size_;
229 while (offset < end) {
230 Span* span = spans_[offset];
231 if (!IsInFreeList(span)) {
232 num_of_objects++;
233 used_size += span->length_;
234 }
235 offset += span->length_;
236 }
237
238 segment_dump->set_physical_size_in_bytes(
239 static_cast<int>(memory_segments_[segment]->size_));
240 segment_dump->set_allocated_objects_count(static_cast<int>(num_of_objects));
241 segment_dump->set_allocated_objects_size_in_bytes(
242 static_cast<int>(used_size));
243 }
244 return true;
245 }
246
215 void DiscardableSharedMemoryHeap::InsertIntoFreeList( 247 void DiscardableSharedMemoryHeap::InsertIntoFreeList(
216 scoped_ptr<DiscardableSharedMemoryHeap::Span> span) { 248 scoped_ptr<DiscardableSharedMemoryHeap::Span> span) {
217 DCHECK(!IsInFreeList(span.get())); 249 DCHECK(!IsInFreeList(span.get()));
218 size_t index = std::min(span->length_, arraysize(free_spans_)) - 1; 250 size_t index = std::min(span->length_, arraysize(free_spans_)) - 1;
219 free_spans_[index].Append(span.release()); 251 free_spans_[index].Append(span.release());
220 } 252 }
221 253
222 scoped_ptr<DiscardableSharedMemoryHeap::Span> 254 scoped_ptr<DiscardableSharedMemoryHeap::Span>
223 DiscardableSharedMemoryHeap::RemoveFromFreeList(Span* span) { 255 DiscardableSharedMemoryHeap::RemoveFromFreeList(Span* span) {
224 DCHECK(IsInFreeList(span)); 256 DCHECK(IsInFreeList(span));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // If |span| is in the free list, remove it and update |num_free_blocks_|. 342 // If |span| is in the free list, remove it and update |num_free_blocks_|.
311 if (IsInFreeList(span)) { 343 if (IsInFreeList(span)) {
312 DCHECK_GE(num_free_blocks_, span->length_); 344 DCHECK_GE(num_free_blocks_, span->length_);
313 num_free_blocks_ -= span->length_; 345 num_free_blocks_ -= span->length_;
314 RemoveFromFreeList(span); 346 RemoveFromFreeList(span);
315 } 347 }
316 } 348 }
317 } 349 }
318 350
319 } // namespace content 351 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698