| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // The dumps of the heap profiler should be created only when heap profiling | 235 // The dumps of the heap profiler should be created only when heap profiling |
| 236 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. | 236 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. |
| 237 // However, when enabled, the overhead of the heap profiler should be always | 237 // However, when enabled, the overhead of the heap profiler should be always |
| 238 // reported to avoid oscillations of the malloc total in LIGHT dumps. | 238 // reported to avoid oscillations of the malloc total in LIGHT dumps. |
| 239 | 239 |
| 240 tid_dumping_heap_ = PlatformThread::CurrentId(); | 240 tid_dumping_heap_ = PlatformThread::CurrentId(); |
| 241 // At this point the Insert/RemoveAllocation hooks will ignore this thread. | 241 // At this point the Insert/RemoveAllocation hooks will ignore this thread. |
| 242 // Enclosing all the temporariy data structures in a scope, so that the heap | 242 // Enclosing all the temporariy data structures in a scope, so that the heap |
| 243 // profiler does not see unabalanced malloc/free calls from these containers. | 243 // profiler does not see unabalanced malloc/free calls from these containers. |
| 244 { | 244 { |
| 245 TraceEventMemoryOverhead overhead; | 245 AutoLock lock(allocation_register_lock_); |
| 246 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; | 246 if (allocation_register_) { |
| 247 { | 247 pmd->DumpHeapUsage(*allocation_register_, "malloc"); |
| 248 AutoLock lock(allocation_register_lock_); | 248 } |
| 249 if (allocation_register_) { | |
| 250 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { | |
| 251 for (const auto& alloc_size : *allocation_register_) { | |
| 252 AllocationMetrics& metrics = metrics_by_context[alloc_size.context]; | |
| 253 metrics.size += alloc_size.size; | |
| 254 metrics.count++; | |
| 255 } | |
| 256 } | |
| 257 allocation_register_->EstimateTraceMemoryOverhead(&overhead); | |
| 258 } | |
| 259 } // lock(allocation_register_lock_) | |
| 260 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); | |
| 261 } | 249 } |
| 262 tid_dumping_heap_ = kInvalidThreadId; | 250 tid_dumping_heap_ = kInvalidThreadId; |
| 263 | 251 |
| 264 return true; | 252 return true; |
| 265 } | 253 } |
| 266 | 254 |
| 267 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { | 255 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { |
| 268 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 256 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 269 if (enabled) { | 257 if (enabled) { |
| 270 { | 258 { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 tid_dumping_heap_ == PlatformThread::CurrentId()) | 304 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 317 return; | 305 return; |
| 318 AutoLock lock(allocation_register_lock_); | 306 AutoLock lock(allocation_register_lock_); |
| 319 if (!allocation_register_) | 307 if (!allocation_register_) |
| 320 return; | 308 return; |
| 321 allocation_register_->Remove(address); | 309 allocation_register_->Remove(address); |
| 322 } | 310 } |
| 323 | 311 |
| 324 } // namespace trace_event | 312 } // namespace trace_event |
| 325 } // namespace base | 313 } // namespace base |
| OLD | NEW |