| 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 <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // The dumps of the heap profiler should be created only when heap profiling | 291 // The dumps of the heap profiler should be created only when heap profiling |
| 292 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. | 292 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. |
| 293 // However, when enabled, the overhead of the heap profiler should be always | 293 // However, when enabled, the overhead of the heap profiler should be always |
| 294 // reported to avoid oscillations of the malloc total in LIGHT dumps. | 294 // reported to avoid oscillations of the malloc total in LIGHT dumps. |
| 295 | 295 |
| 296 tid_dumping_heap_ = PlatformThread::CurrentId(); | 296 tid_dumping_heap_ = PlatformThread::CurrentId(); |
| 297 // At this point the Insert/RemoveAllocation hooks will ignore this thread. | 297 // At this point the Insert/RemoveAllocation hooks will ignore this thread. |
| 298 // Enclosing all the temporary data structures in a scope, so that the heap | 298 // Enclosing all the temporary data structures in a scope, so that the heap |
| 299 // profiler does not see unbalanced malloc/free calls from these containers. | 299 // profiler does not see unbalanced malloc/free calls from these containers. |
| 300 { | 300 { |
| 301 size_t shim_allocated_objects_size = 0; | |
| 302 size_t shim_allocated_objects_count = 0; | |
| 303 TraceEventMemoryOverhead overhead; | 301 TraceEventMemoryOverhead overhead; |
| 304 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context; | 302 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context; |
| 305 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { | 303 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { |
| 306 ShardedAllocationRegister::OutputMetrics metrics = | 304 ShardedAllocationRegister::OutputMetrics shim_metrics = |
| 307 allocation_register_.UpdateAndReturnsMetrics(metrics_by_context); | 305 allocation_register_.UpdateAndReturnsMetrics(metrics_by_context); |
| 308 | 306 |
| 309 // Aggregate data for objects allocated through the shim. | 307 // Aggregate data for objects allocated through the shim. |
| 310 shim_allocated_objects_size += metrics.size; | 308 inner_dump->AddScalar("shim_allocated_objects_size", |
| 311 shim_allocated_objects_count += metrics.count; | 309 MemoryAllocatorDump::kUnitsBytes, |
| 310 shim_metrics.size); |
| 311 inner_dump->AddScalar("shim_allocator_object_count", |
| 312 MemoryAllocatorDump::kUnitsObjects, |
| 313 shim_metrics.count); |
| 312 } | 314 } |
| 313 allocation_register_.EstimateTraceMemoryOverhead(&overhead); | 315 allocation_register_.EstimateTraceMemoryOverhead(&overhead); |
| 314 | 316 |
| 315 inner_dump->AddScalar("shim_allocated_objects_size", | |
| 316 MemoryAllocatorDump::kUnitsBytes, | |
| 317 shim_allocated_objects_size); | |
| 318 inner_dump->AddScalar("shim_allocator_object_count", | |
| 319 MemoryAllocatorDump::kUnitsObjects, | |
| 320 shim_allocated_objects_count); | |
| 321 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); | 317 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); |
| 322 } | 318 } |
| 323 tid_dumping_heap_ = kInvalidThreadId; | 319 tid_dumping_heap_ = kInvalidThreadId; |
| 324 | 320 |
| 325 return true; | 321 return true; |
| 326 } | 322 } |
| 327 | 323 |
| 328 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { | 324 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { |
| 329 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 325 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 330 if (enabled) { | 326 if (enabled) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (tid_dumping_heap_ != kInvalidThreadId && | 363 if (tid_dumping_heap_ != kInvalidThreadId && |
| 368 tid_dumping_heap_ == PlatformThread::CurrentId()) | 364 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 369 return; | 365 return; |
| 370 if (!allocation_register_.is_enabled()) | 366 if (!allocation_register_.is_enabled()) |
| 371 return; | 367 return; |
| 372 allocation_register_.Remove(address); | 368 allocation_register_.Remove(address); |
| 373 } | 369 } |
| 374 | 370 |
| 375 } // namespace trace_event | 371 } // namespace trace_event |
| 376 } // namespace base | 372 } // namespace base |
| OLD | NEW |