| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 other_dump->AddScalar(MemoryAllocatorDump::kNameSize, | 279 other_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
| 280 MemoryAllocatorDump::kUnitsBytes, | 280 MemoryAllocatorDump::kUnitsBytes, |
| 281 resident_size - allocated_objects_size); | 281 resident_size - allocated_objects_size); |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Heap profiler dumps. | 284 // Heap profiler dumps. |
| 285 if (!heap_profiler_enabled_) | 285 if (!heap_profiler_enabled_) |
| 286 return true; | 286 return true; |
| 287 | 287 |
| 288 // The dumps of the heap profiler should be created only when heap profiling | 288 // The dumps of the heap profiler should be created only when heap profiling |
| 289 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. | 289 // was enabled with any mode AND a DETAILED dump is requested or heap |
| 290 // However, when enabled, the overhead of the heap profiler should be always | 290 // profiling was enabled with BACKGROUND mode AND BACKGROUND dump is |
| 291 // reported to avoid oscillations of the malloc total in LIGHT dumps. | 291 // requested. However, when enabled, the overhead of the heap profiler should |
| 292 // be always reported to avoid oscillations of the malloc total in LIGHT |
| 293 // dumps. |
| 292 | 294 |
| 293 tid_dumping_heap_ = PlatformThread::CurrentId(); | 295 tid_dumping_heap_ = PlatformThread::CurrentId(); |
| 294 // At this point the Insert/RemoveAllocation hooks will ignore this thread. | 296 // At this point the Insert/RemoveAllocation hooks will ignore this thread. |
| 295 // Enclosing all the temporariy data structures in a scope, so that the heap | 297 // Enclosing all the temporariy data structures in a scope, so that the heap |
| 296 // profiler does not see unabalanced malloc/free calls from these containers. | 298 // profiler does not see unabalanced malloc/free calls from these containers. |
| 297 { | 299 { |
| 298 TraceEventMemoryOverhead overhead; | 300 TraceEventMemoryOverhead overhead; |
| 299 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; | 301 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; |
| 300 { | 302 { |
| 301 AutoLock lock(allocation_register_lock_); | 303 AutoLock lock(allocation_register_lock_); |
| 302 if (allocation_register_) { | 304 if (allocation_register_) { |
| 303 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { | 305 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED || |
| 306 (args.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND && |
| 307 AllocationContextTracker::capture_mode() == |
| 308 AllocationContextTracker::CaptureMode::BACKGROUND)) { |
| 304 for (const auto& alloc_size : *allocation_register_) { | 309 for (const auto& alloc_size : *allocation_register_) { |
| 305 AllocationMetrics& metrics = metrics_by_context[alloc_size.context]; | 310 AllocationMetrics& metrics = metrics_by_context[alloc_size.context]; |
| 306 metrics.size += alloc_size.size; | 311 metrics.size += alloc_size.size; |
| 307 metrics.count++; | 312 metrics.count++; |
| 308 } | 313 } |
| 309 } | 314 } |
| 310 allocation_register_->EstimateTraceMemoryOverhead(&overhead); | 315 allocation_register_->EstimateTraceMemoryOverhead(&overhead); |
| 311 } | 316 } |
| 312 } // lock(allocation_register_lock_) | 317 } // lock(allocation_register_lock_) |
| 313 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); | 318 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 tid_dumping_heap_ == PlatformThread::CurrentId()) | 374 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 370 return; | 375 return; |
| 371 AutoLock lock(allocation_register_lock_); | 376 AutoLock lock(allocation_register_lock_); |
| 372 if (!allocation_register_) | 377 if (!allocation_register_) |
| 373 return; | 378 return; |
| 374 allocation_register_->Remove(address); | 379 allocation_register_->Remove(address); |
| 375 } | 380 } |
| 376 | 381 |
| 377 } // namespace trace_event | 382 } // namespace trace_event |
| 378 } // namespace base | 383 } // namespace base |
| OLD | NEW |