| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/malloc_dump_provider.h" | 5 #include "base/trace_event/malloc_dump_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
| 10 #include "base/allocator/allocator_shim.h" | 10 #include "base/allocator/allocator_shim.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. | 171 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. |
| 172 // However, when enabled, the overhead of the heap profiler should be always | 172 // However, when enabled, the overhead of the heap profiler should be always |
| 173 // reported to avoid oscillations of the malloc total in LIGHT dumps. | 173 // reported to avoid oscillations of the malloc total in LIGHT dumps. |
| 174 | 174 |
| 175 tid_dumping_heap_ = PlatformThread::CurrentId(); | 175 tid_dumping_heap_ = PlatformThread::CurrentId(); |
| 176 // At this point the Insert/RemoveAllocation hooks will ignore this thread. | 176 // At this point the Insert/RemoveAllocation hooks will ignore this thread. |
| 177 // Enclosing all the temporariy data structures in a scope, so that the heap | 177 // Enclosing all the temporariy data structures in a scope, so that the heap |
| 178 // profiler does not see unabalanced malloc/free calls from these containers. | 178 // profiler does not see unabalanced malloc/free calls from these containers. |
| 179 { | 179 { |
| 180 TraceEventMemoryOverhead overhead; | 180 TraceEventMemoryOverhead overhead; |
| 181 hash_map<AllocationContext, size_t> bytes_by_context; | 181 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; |
| 182 { | 182 { |
| 183 AutoLock lock(allocation_register_lock_); | 183 AutoLock lock(allocation_register_lock_); |
| 184 if (allocation_register_) { | 184 if (allocation_register_) { |
| 185 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { | 185 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { |
| 186 for (const auto& alloc_size : *allocation_register_) | 186 for (const auto& alloc_size : *allocation_register_) { |
| 187 bytes_by_context[alloc_size.context] += alloc_size.size; | 187 AllocationMetrics& metrics = metrics_by_context[alloc_size.context]; |
| 188 metrics.size += alloc_size.size; |
| 189 metrics.count++; |
| 190 } |
| 188 } | 191 } |
| 189 allocation_register_->EstimateTraceMemoryOverhead(&overhead); | 192 allocation_register_->EstimateTraceMemoryOverhead(&overhead); |
| 190 } | 193 } |
| 191 } // lock(allocation_register_lock_) | 194 } // lock(allocation_register_lock_) |
| 192 | 195 |
| 193 if (!bytes_by_context.empty()) { | 196 if (!metrics_by_context.empty()) { |
| 194 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( | 197 std::unique_ptr<TracedValue> heap_dump = ExportHeapDump( |
| 195 bytes_by_context, pmd->session_state()->stack_frame_deduplicator(), | 198 metrics_by_context, pmd->session_state()->stack_frame_deduplicator(), |
| 196 pmd->session_state()->type_name_deduplicator()); | 199 pmd->session_state()->type_name_deduplicator()); |
| 197 pmd->AddHeapDump("malloc", std::move(heap_dump)); | 200 pmd->AddHeapDump("malloc", std::move(heap_dump)); |
| 198 } | 201 } |
| 199 overhead.DumpInto("tracing/heap_profiler_malloc", pmd); | 202 overhead.DumpInto("tracing/heap_profiler_malloc", pmd); |
| 200 } | 203 } |
| 201 tid_dumping_heap_ = kInvalidThreadId; | 204 tid_dumping_heap_ = kInvalidThreadId; |
| 202 | 205 |
| 203 return true; | 206 return true; |
| 204 } | 207 } |
| 205 | 208 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 tid_dumping_heap_ == PlatformThread::CurrentId()) | 255 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 253 return; | 256 return; |
| 254 AutoLock lock(allocation_register_lock_); | 257 AutoLock lock(allocation_register_lock_); |
| 255 if (!allocation_register_) | 258 if (!allocation_register_) |
| 256 return; | 259 return; |
| 257 allocation_register_->Remove(address); | 260 allocation_register_->Remove(address); |
| 258 } | 261 } |
| 259 | 262 |
| 260 } // namespace trace_event | 263 } // namespace trace_event |
| 261 } // namespace base | 264 } // namespace base |
| OLD | NEW |