Chromium Code Reviews| 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"; | |
| 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); | |
| 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 12 matching lines...) Expand all Loading... | |
| 383 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = | 386 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = |
| 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 |
| 396 void DiscardableSharedMemoryHeap::CreateAllocatedObjectsDump( | |
|
petrcermak
2015/07/29 16:38:59
nit: I think you should say "// static" above the
ssid
2015/07/29 16:57:37
Done.
| |
| 397 base::trace_event::ProcessMemoryDump* pmd) { | |
| 398 base::trace_event::MemoryAllocatorDump* objects_dump = | |
| 399 pmd->CreateAllocatorDump( | |
| 400 base::DiscardableSharedMemory::kAllocatedObjectsDumpName); | |
| 401 base::trace_event::MemoryAllocatorDump* discardable_segments_dump = | |
| 402 pmd->CreateAllocatorDump(kDiscardableSegmentsDumpName); | |
| 403 | |
| 404 // The discardable memory segments will contain kDiscardableSegmentsDumpName | |
|
petrcermak
2015/07/29 16:38:59
This is reversed. The dump called kDiscardableSegm
ssid
2015/07/29 16:57:37
Done.
| |
| 405 // as the root and will own any sub-allocations with kAllocatedObjectsDumpName | |
|
petrcermak
2015/07/29 16:38:59
Probably "parent" or "ancestor" instead of "root"
petrcermak
2015/07/29 16:38:59
s/own/be owned by/
ssid
2015/07/29 16:57:37
Done.
| |
| 406 // as the root. | |
| 407 pmd->AddOwnershipEdge(objects_dump->guid(), | |
| 408 discardable_segments_dump->guid()); | |
| 409 } | |
| 410 | |
| 393 // static | 411 // static |
| 394 base::trace_event::MemoryAllocatorDumpGuid | 412 base::trace_event::MemoryAllocatorDumpGuid |
| 395 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, | 413 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, |
| 396 int32 segment_id) { | 414 int32 segment_id) { |
| 397 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | 415 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( |
| 398 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); | 416 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); |
| 399 } | 417 } |
| 400 | 418 |
| 401 } // namespace content | 419 } // namespace content |
| OLD | NEW |