| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/trace_event/sharded_allocation_register.h" | 5 #include "base/trace_event/sharded_allocation_register.h" |
| 6 | 6 |
| 7 #include "base/trace_event/trace_event_memory_overhead.h" | 7 #include "base/trace_event/trace_event_memory_overhead.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 RegisterAndLock& ral = allocation_registers_[i]; | 62 RegisterAndLock& ral = allocation_registers_[i]; |
| 63 AutoLock lock(ral.lock); | 63 AutoLock lock(ral.lock); |
| 64 allocated += ral.allocation_register.EstimateAllocatedMemory(); | 64 allocated += ral.allocation_register.EstimateAllocatedMemory(); |
| 65 resident += ral.allocation_register.EstimateResidentMemory(); | 65 resident += ral.allocation_register.EstimateResidentMemory(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 overhead->Add(TraceEventMemoryOverhead::kHeapProfilerAllocationRegister, | 68 overhead->Add(TraceEventMemoryOverhead::kHeapProfilerAllocationRegister, |
| 69 allocated, resident); | 69 allocated, resident); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ShardedAllocationRegister::OutputMetrics | 72 void ShardedAllocationRegister::VisitAllocations( |
| 73 ShardedAllocationRegister::UpdateAndReturnsMetrics(MetricsMap& map) const { | 73 const AllocationVisitor& visitor) const { |
| 74 OutputMetrics output_metrics; | |
| 75 output_metrics.size = 0; | |
| 76 output_metrics.count = 0; | |
| 77 for (size_t i = 0; i < ShardCount; ++i) { | 74 for (size_t i = 0; i < ShardCount; ++i) { |
| 78 RegisterAndLock& ral = allocation_registers_[i]; | 75 RegisterAndLock& ral = allocation_registers_[i]; |
| 79 AutoLock lock(ral.lock); | 76 AutoLock lock(ral.lock); |
| 80 for (const auto& alloc_size : ral.allocation_register) { | 77 for (const auto& alloc : ral.allocation_register) { |
| 81 AllocationMetrics& metrics = map[alloc_size.context]; | 78 visitor.Run(alloc); |
| 82 metrics.size += alloc_size.size; | |
| 83 metrics.count++; | |
| 84 | |
| 85 output_metrics.size += alloc_size.size; | |
| 86 output_metrics.count++; | |
| 87 } | 79 } |
| 88 } | 80 } |
| 89 return output_metrics; | |
| 90 } | 81 } |
| 91 | 82 |
| 92 ShardedAllocationRegister::RegisterAndLock::RegisterAndLock() = default; | 83 ShardedAllocationRegister::RegisterAndLock::RegisterAndLock() = default; |
| 93 ShardedAllocationRegister::RegisterAndLock::~RegisterAndLock() = default; | 84 ShardedAllocationRegister::RegisterAndLock::~RegisterAndLock() = default; |
| 94 | 85 |
| 95 } // namespace trace_event | 86 } // namespace trace_event |
| 96 } // namespace base | 87 } // namespace base |
| OLD | NEW |