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 base::trace_event::MemoryAllocatorDump* | |
| 64 DiscardableSharedMemoryHeap::ScopedMemorySegment::CreateMemoryAllocatorDump( | |
| 65 Span* span, | |
| 66 const char* name, | |
| 67 base::trace_event::ProcessMemoryDump* pmd) const { | |
| 68 if (shared_memory_ != span->shared_memory()) | |
| 69 return nullptr; | |
| 70 | |
| 71 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name); | |
| 72 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 73 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 74 static_cast<uint64_t>(span->length())); | |
| 75 | |
| 76 pmd->AddSuballocation(dump->guid(), | |
| 77 base::StringPrintf("discardable/segment_%d", id_)); | |
| 78 return dump; | |
| 79 } | |
| 80 | |
| 63 void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump( | 81 void DiscardableSharedMemoryHeap::ScopedMemorySegment::OnMemoryDump( |
| 64 base::trace_event::ProcessMemoryDump* pmd) const { | 82 base::trace_event::ProcessMemoryDump* pmd) const { |
| 65 heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd); | 83 heap_->OnMemoryDump(shared_memory_.get(), size_, id_, pmd); |
| 66 } | 84 } |
| 67 | 85 |
| 68 DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size) | 86 DiscardableSharedMemoryHeap::DiscardableSharedMemoryHeap(size_t block_size) |
| 69 : block_size_(block_size), num_blocks_(0), num_free_blocks_(0) { | 87 : block_size_(block_size), num_blocks_(0), num_free_blocks_(0) { |
| 70 DCHECK_NE(block_size_, 0u); | 88 DCHECK_NE(block_size_, 0u); |
| 71 DCHECK(IsPowerOfTwo(block_size_)); | 89 DCHECK(IsPowerOfTwo(block_size_)); |
| 72 } | 90 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 } | 409 } |
| 392 | 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 |
| 419 base::trace_event::MemoryAllocatorDump* | |
| 420 DiscardableSharedMemoryHeap::CreateMemoryAllocatorDump( | |
| 421 Span* span, | |
| 422 const char* name, | |
| 423 base::trace_event::ProcessMemoryDump* pmd) const { | |
| 424 if (span->shared_memory() == nullptr) | |
|
reveman
2015/08/21 18:05:24
nit: !span->shared_memory()
ssid
2015/08/24 14:52:10
Done.
| |
| 425 return nullptr; | |
| 426 | |
| 427 base::trace_event::MemoryAllocatorDump* allocator_dump; | |
| 428 std::for_each( | |
|
reveman
2015/08/21 18:05:24
can you instead do a std:::find_if for span->share
ssid
2015/08/21 19:02:30
I cannot do it because I have to match the span->s
reveman
2015/08/22 14:21:16
How about adding a "bool ScopedMemorySegment::Cont
ssid
2015/08/22 14:50:19
Yes I planned that at first, but I also need to ad
reveman
2015/08/22 15:04:07
I was thinking you could use the ScopedMemorySegme
ssid
2015/08/22 15:13:00
Ah sorry, I see what you meant now, sounds good, t
ssid
2015/08/24 14:52:10
Done.
| |
| 429 memory_segments_.begin(), memory_segments_.end(), | |
| 430 [span, name, pmd, &allocator_dump](const ScopedMemorySegment* segment) { | |
| 431 base::trace_event::MemoryAllocatorDump* dump = | |
| 432 segment->CreateMemoryAllocatorDump(span, name, pmd); | |
| 433 if (dump != nullptr) | |
| 434 allocator_dump = dump; | |
| 435 }); | |
| 436 | |
| 437 // Span with a shared memory should be found in some segment. | |
| 438 DCHECK(allocator_dump != nullptr); | |
| 439 return allocator_dump; | |
| 440 } | |
| 441 | |
| 401 } // namespace content | 442 } // namespace content |
| OLD | NEW |