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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsUsed() const { | 55 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsUsed() const { |
| 56 return heap_->IsMemoryUsed(shared_memory_.get(), size_); | 56 return heap_->IsMemoryUsed(shared_memory_.get(), size_); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const { | 59 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::IsResident() const { |
| 60 return heap_->IsMemoryResident(shared_memory_.get()); | 60 return heap_->IsMemoryResident(shared_memory_.get()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool DiscardableSharedMemoryHeap::ScopedMemorySegment::ContainsSpan( | |
| 64 Span* span) const { | |
| 65 return shared_memory_ == span->shared_memory(); | |
| 66 } | |
| 67 | |
| 68 base::trace_event::MemoryAllocatorDump* | |
| 69 DiscardableSharedMemoryHeap::ScopedMemorySegment::CreateMemoryAllocatorDump( | |
| 70 Span* span, | |
| 71 const char* name, | |
| 72 base::trace_event::ProcessMemoryDump* pmd) const { | |
| 73 DCHECK_EQ(shared_memory_, span->shared_memory()); | |
| 74 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name); | |
| 75 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 76 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 77 static_cast<uint64_t>(span->length())); | |
| 78 | |
| 79 pmd->AddSuballocation(dump->guid(), | |
| 80 base::StringPrintf("discardable/segment_%d", id_)); | |
| 81 return dump; | |
| 82 } | |
| 83 | |
| 63 void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump( | 84 void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump( |
| 64 base::trace_event::ProcessMemoryDump* pmd) const { | 85 base::trace_event::ProcessMemoryDump* pmd) const { |
| 65 heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd); | 86 heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd); |
| 66 } | 87 } |
| 67 | 88 |
| 68 DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size) | 89 DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size) |
| 69 : block_size_(block_size), num_blocks_(0), num_free_blocks_(0) { | 90 : block_size_(block_size), num_blocks_(0), num_free_blocks_(0) { |
| 70 DCHECK_NE(block_size_, 0u); | 91 DCHECK_NE(block_size_, 0u); |
| 71 DCHECK(IsPowerOfTwo(block_size_)); | 92 DCHECK(IsPowerOfTwo(block_size_)); |
| 72 } | 93 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 } | 412 } |
| 392 | 413 |
| 393 // static | 414 // static |
| 394 base::trace_event::MemoryAllocatorDumpGuid | 415 base::trace_event::MemoryAllocatorDumpGuid |
| 395 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, | 416 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing(uint64 tracing_process_id, |
| 396 int32 segment_id) { | 417 int32 segment_id) { |
| 397 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | 418 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( |
| 398 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); | 419 "discardable-x-process/%" PRIx64 "/%d", tracing_process_id, segment_id)); |
| 399 } | 420 } |
| 400 | 421 |
| 422 base::trace_event::MemoryAllocatorDump* | |
| 423 DiscardableSharedMemoryHeap::CreateMemoryAllocatorDump( | |
| 424 Span* span, | |
| 425 const char* name, | |
| 426 base::trace_event::ProcessMemoryDump* pmd) const { | |
| 427 if (!span->shared_memory()) { | |
| 428 base::trace_event::MemoryAllocatorDump* dump = | |
| 429 pmd->CreateAllocatorDump(name); | |
| 430 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 431 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 0u); | |
| 432 return dump; | |
| 433 } | |
| 434 | |
| 435 base::trace_event::MemoryAllocatorDump* allocator_dump; | |
| 436 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.
| |
| 437 memory_segments_.begin(), memory_segments_.end(), | |
| 438 [span, name, pmd, &allocator_dump](const ScopedMemorySegment* segment) { | |
| 439 if (segment->ContainsSpan(span)) | |
| 440 allocator_dump = segment->CreateMemoryAllocatorDump(span, name, pmd); | |
| 441 }); | |
| 442 | |
| 443 // Span with a shared memory should be found in some segment. | |
| 444 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.
| |
| 445 return allocator_dump; | |
| 446 } | |
| 447 | |
| 401 } // namespace content | 448 } // namespace content |
| OLD | NEW |