Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: base/trace_event/malloc_dump_provider.cc

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: Fix rebase damage Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/allocator/allocator_extension.h" 11 #include "base/allocator/allocator_extension.h"
12 #include "base/allocator/allocator_shim.h" 12 #include "base/allocator/allocator_shim.h"
13 #include "base/allocator/features.h" 13 #include "base/allocator/features.h"
14 #include "base/debug/profiler.h" 14 #include "base/debug/profiler.h"
15 #include "base/trace_event/heap_profiler_allocation_context.h" 15 #include "base/trace_event/heap_profiler_allocation_context.h"
16 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 16 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
17 #include "base/trace_event/heap_profiler_allocation_register.h" 17 #include "base/trace_event/heap_profiler_allocation_register.h"
18 #include "base/trace_event/heap_profiler_heap_dump_writer.h" 18 #include "base/trace_event/heap_profiler_event_writer.h"
19 #include "base/trace_event/process_memory_dump.h" 19 #include "base/trace_event/process_memory_dump.h"
20 #include "base/trace_event/trace_event_argument.h" 20 #include "base/trace_event/trace_event_argument.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 22
23 #if defined(OS_MACOSX) 23 #if defined(OS_MACOSX)
24 #include <malloc/malloc.h> 24 #include <malloc/malloc.h>
25 #else 25 #else
26 #include <malloc.h> 26 #include <malloc.h>
27 #endif 27 #endif
28 #if defined(OS_WIN) 28 #if defined(OS_WIN)
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // The dumps of the heap profiler should be created only when heap profiling 290 // The dumps of the heap profiler should be created only when heap profiling
291 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. 291 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested.
292 // However, when enabled, the overhead of the heap profiler should be always 292 // However, when enabled, the overhead of the heap profiler should be always
293 // reported to avoid oscillations of the malloc total in LIGHT dumps. 293 // reported to avoid oscillations of the malloc total in LIGHT dumps.
294 294
295 tid_dumping_heap_ = PlatformThread::CurrentId(); 295 tid_dumping_heap_ = PlatformThread::CurrentId();
296 // At this point the Insert/RemoveAllocation hooks will ignore this thread. 296 // At this point the Insert/RemoveAllocation hooks will ignore this thread.
297 // Enclosing all the temporary data structures in a scope, so that the heap 297 // Enclosing all the temporary data structures in a scope, so that the heap
298 // profiler does not see unbalanced malloc/free calls from these containers. 298 // profiler does not see unbalanced malloc/free calls from these containers.
299 { 299 {
300 size_t shim_allocated_objects_size = 0; 300 AutoLock lock(allocation_register_lock_);
301 size_t shim_allocated_objects_count = 0; 301 if (allocation_register_) {
302 TraceEventMemoryOverhead overhead; 302 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) {
303 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context; 303 size_t shim_allocated_objects_size = 0;
304 { 304 size_t shim_allocated_objects_count = 0;
305 AutoLock lock(allocation_register_lock_); 305 for (const auto& alloc_size : *allocation_register_) {
306 if (allocation_register_) { 306 // Aggregate data for objects allocated through the shim.
307 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { 307 shim_allocated_objects_size += alloc_size.size;
308 for (const auto& alloc_size : *allocation_register_) { 308 shim_allocated_objects_count++;
309 AllocationMetrics& metrics = metrics_by_context[alloc_size.context];
310 metrics.size += alloc_size.size;
311 metrics.count++;
312
313 // Aggregate data for objects allocated through the shim.
314 shim_allocated_objects_size += alloc_size.size;
315 shim_allocated_objects_count++;
316 }
317 } 309 }
318 allocation_register_->EstimateTraceMemoryOverhead(&overhead); 310 inner_dump->AddScalar("shim_allocated_objects_size",
311 MemoryAllocatorDump::kUnitsBytes,
312 shim_allocated_objects_size);
313 inner_dump->AddScalar("shim_allocator_object_count",
314 MemoryAllocatorDump::kUnitsObjects,
315 shim_allocated_objects_count);
319 } 316 }
320 317 pmd->DumpHeapUsage(*allocation_register_, "malloc");
321 inner_dump->AddScalar("shim_allocated_objects_size", 318 }
322 MemoryAllocatorDump::kUnitsBytes,
323 shim_allocated_objects_size);
324 inner_dump->AddScalar("shim_allocator_object_count",
325 MemoryAllocatorDump::kUnitsObjects,
326 shim_allocated_objects_count);
327 } // lock(allocation_register_lock_)
328 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc");
329 } 319 }
330 tid_dumping_heap_ = kInvalidThreadId; 320 tid_dumping_heap_ = kInvalidThreadId;
331 321
332 return true; 322 return true;
333 } 323 }
334 324
335 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { 325 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) {
336 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 326 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
337 if (enabled) { 327 if (enabled) {
338 { 328 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 tid_dumping_heap_ == PlatformThread::CurrentId()) 374 tid_dumping_heap_ == PlatformThread::CurrentId())
385 return; 375 return;
386 AutoLock lock(allocation_register_lock_); 376 AutoLock lock(allocation_register_lock_);
387 if (!allocation_register_) 377 if (!allocation_register_)
388 return; 378 return;
389 allocation_register_->Remove(address); 379 allocation_register_->Remove(address);
390 } 380 }
391 381
392 } // namespace trace_event 382 } // namespace trace_event
393 } // namespace base 383 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_type_name_deduplicator_unittest.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698