OLD | NEW |
---|---|
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/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/discardable_shared_memory.h" | 10 #include "base/memory/discardable_shared_memory.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/trace_event/memory_dump_manager.h" | 12 #include "base/trace_event/memory_dump_manager.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 namespace { | 15 namespace { |
16 | 16 |
17 bool IsPowerOfTwo(size_t x) { | 17 bool IsPowerOfTwo(size_t x) { |
18 return (x & (x - 1)) == 0; | 18 return (x & (x - 1)) == 0; |
19 } | 19 } |
20 | 20 |
21 bool IsInFreeList(DiscardableSharedMemoryHeap::Span* span) { | 21 bool IsInFreeList(DiscardableSharedMemoryHeap::Span* span) { |
22 return span->previous() || span->next(); | 22 return span->previous() || span->next(); |
23 } | 23 } |
24 | 24 |
25 const char kDiscardableSegmentsDumpName[] = "discardable/segments"; | |
reveman
2015/07/30 16:00:59
We've been avoiding explicit constants for dump na
ssid
2015/07/30 20:05:15
Done.
| |
26 | |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 DiscardableSharedMemoryHeap::Span::Span( | 29 DiscardableSharedMemoryHeap::Span::Span( |
28 base::DiscardableSharedMemory* shared_memory, | 30 base::DiscardableSharedMemory* shared_memory, |
29 size_t start, | 31 size_t start, |
30 size_t length) | 32 size_t length) |
31 : shared_memory_(shared_memory), start_(start), length_(length) { | 33 : shared_memory_(shared_memory), start_(start), length_(length) { |
32 } | 34 } |
33 | 35 |
34 DiscardableSharedMemoryHeap::Span::~Span() { | 36 DiscardableSharedMemoryHeap::Span::~Span() { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 size_t DiscardableSharedMemoryHeap::GetSize() const { | 220 size_t DiscardableSharedMemoryHeap::GetSize() const { |
219 return num_blocks_ * block_size_; | 221 return num_blocks_ * block_size_; |
220 } | 222 } |
221 | 223 |
222 size_t DiscardableSharedMemoryHeap::GetSizeOfFreeLists() const { | 224 size_t DiscardableSharedMemoryHeap::GetSizeOfFreeLists() const { |
223 return num_free_blocks_ * block_size_; | 225 return num_free_blocks_ * block_size_; |
224 } | 226 } |
225 | 227 |
226 bool DiscardableSharedMemoryHeap::OnMemoryDump( | 228 bool DiscardableSharedMemoryHeap::OnMemoryDump( |
227 base::trace_event::ProcessMemoryDump* pmd) { | 229 base::trace_event::ProcessMemoryDump* pmd) { |
230 CreateAllocatedObjectsDump(pmd); | |
reveman
2015/07/30 16:00:59
I think it should be the responsibility of the Dis
ssid
2015/07/30 20:05:15
Yes, But then since i placed the method in this cl
| |
228 std::for_each( | 231 std::for_each( |
229 memory_segments_.begin(), memory_segments_.end(), | 232 memory_segments_.begin(), memory_segments_.end(), |
230 [pmd](const ScopedMemorySegment* segment) { | 233 [pmd](const ScopedMemorySegment* segment) { |
231 segment->OnMemoryDump(pmd); | 234 segment->OnMemoryDump(pmd); |
232 }); | 235 }); |
233 return true; | 236 return true; |
234 } | 237 } |
235 | 238 |
236 void DiscardableSharedMemoryHeap::InsertIntoFreeList( | 239 void DiscardableSharedMemoryHeap::InsertIntoFreeList( |
237 scoped_ptr<DiscardableSharedMemoryHeap::Span> span) { | 240 scoped_ptr<DiscardableSharedMemoryHeap::Span> span) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 size_t end = offset + size / block_size_; | 352 size_t end = offset + size / block_size_; |
350 while (offset < end) { | 353 while (offset < end) { |
351 Span* span = spans_[offset]; | 354 Span* span = spans_[offset]; |
352 if (!IsInFreeList(span)) { | 355 if (!IsInFreeList(span)) { |
353 allocated_objects_count++; | 356 allocated_objects_count++; |
354 allocated_objects_size_in_bytes += span->length_ * block_size_; | 357 allocated_objects_size_in_bytes += span->length_ * block_size_; |
355 } | 358 } |
356 offset += span->length_; | 359 offset += span->length_; |
357 } | 360 } |
358 | 361 |
359 std::string segment_dump_name = | 362 std::string segment_dump_name = base::StringPrintf( |
360 base::StringPrintf("discardable/segment_%d", segment_id); | 363 "%s/segment_%d", kDiscardableSegmentsDumpName, segment_id); |
361 base::trace_event::MemoryAllocatorDump* segment_dump = | 364 base::trace_event::MemoryAllocatorDump* segment_dump = |
362 pmd->CreateAllocatorDump(segment_dump_name); | 365 pmd->CreateAllocatorDump(segment_dump_name); |
363 segment_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 366 segment_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
364 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 367 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
365 static_cast<uint64_t>(size)); | 368 static_cast<uint64_t>(size)); |
366 | 369 |
367 base::trace_event::MemoryAllocatorDump* obj_dump = | 370 base::trace_event::MemoryAllocatorDump* obj_dump = |
368 pmd->CreateAllocatorDump(segment_dump_name + "/allocated_objects"); | 371 pmd->CreateAllocatorDump(segment_dump_name + "/allocated_objects"); |
369 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectsCount, | 372 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectsCount, |
370 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 373 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
(...skipping 13 matching lines...) Expand all Loading... | |
384 GetSegmentGUIDForTracing(tracing_process_id, segment_id); | 387 GetSegmentGUIDForTracing(tracing_process_id, segment_id); |
385 pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid); | 388 pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid); |
386 | 389 |
387 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) | 390 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) |
388 // the tracing UI will account the effective size of the segment to the child. | 391 // the tracing UI will account the effective size of the segment to the child. |
389 const int kImportance = 2; | 392 const int kImportance = 2; |
390 pmd->AddOwnershipEdge(segment_dump->guid(), shared_segment_guid, kImportance); | 393 pmd->AddOwnershipEdge(segment_dump->guid(), shared_segment_guid, kImportance); |
391 } | 394 } |
392 | 395 |
393 // static | 396 // static |
397 void DiscardableSharedMemoryHeap::CreateAllocatedObjectsDump( | |
398 base::trace_event::ProcessMemoryDump* pmd) { | |
399 base::trace_event::MemoryAllocatorDump* objects_dump = | |
400 pmd->CreateAllocatorDump( | |
401 base::DiscardableSharedMemory::kAllocatedObjectsDumpName); | |
402 base::trace_event::MemoryAllocatorDump* discardable_segments_dump = | |
403 pmd->CreateAllocatorDump(kDiscardableSegmentsDumpName); | |
404 | |
405 // The discardable memory segments will be dumped with | |
406 // kDiscardableSegmentsDumpName as the parent and will be owned by | |
407 // sub-allocations dumped with kAllocatedObjectsDumpName as their parent. | |
408 pmd->AddOwnershipEdge(objects_dump->guid(), | |
409 discardable_segments_dump->guid()); | |
410 } | |
411 | |
412 // static | |
394 base::trace_event::MemoryAllocatorDumpGuid | 413 base::trace_event::MemoryAllocatorDumpGuid |
395 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, | 414 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, |
396 int32 segment_id) { | 415 int32 segment_id) { |
397 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | 416 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( |
398 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); | 417 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); |
399 } | 418 } |
400 | 419 |
401 } // namespace content | 420 } // namespace content |
OLD | NEW |