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

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

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: DCHECK for continuous mode Created 3 years, 9 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 "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"
11 #include "base/allocator/features.h" 11 #include "base/allocator/features.h"
12 #include "base/debug/profiler.h" 12 #include "base/debug/profiler.h"
13 #include "base/trace_event/heap_profiler_allocation_context.h" 13 #include "base/trace_event/heap_profiler_allocation_context.h"
14 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 14 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
15 #include "base/trace_event/heap_profiler_allocation_register.h" 15 #include "base/trace_event/heap_profiler_allocation_register.h"
16 #include "base/trace_event/heap_profiler_heap_dump_writer.h" 16 #include "base/trace_event/heap_profiler_event_writer.h"
17 #include "base/trace_event/process_memory_dump.h" 17 #include "base/trace_event/process_memory_dump.h"
18 #include "base/trace_event/trace_event_argument.h" 18 #include "base/trace_event/trace_event_argument.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 20
21 #if defined(OS_MACOSX) 21 #if defined(OS_MACOSX)
22 #include <malloc/malloc.h> 22 #include <malloc/malloc.h>
23 #else 23 #else
24 #include <malloc.h> 24 #include <malloc.h>
25 #endif 25 #endif
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // The dumps of the heap profiler should be created only when heap profiling 282 // The dumps of the heap profiler should be created only when heap profiling
283 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested. 283 // was enabled (--enable-heap-profiling) AND a DETAILED dump is requested.
284 // However, when enabled, the overhead of the heap profiler should be always 284 // However, when enabled, the overhead of the heap profiler should be always
285 // reported to avoid oscillations of the malloc total in LIGHT dumps. 285 // reported to avoid oscillations of the malloc total in LIGHT dumps.
286 286
287 tid_dumping_heap_ = PlatformThread::CurrentId(); 287 tid_dumping_heap_ = PlatformThread::CurrentId();
288 // At this point the Insert/RemoveAllocation hooks will ignore this thread. 288 // At this point the Insert/RemoveAllocation hooks will ignore this thread.
289 // Enclosing all the temporariy data structures in a scope, so that the heap 289 // Enclosing all the temporariy data structures in a scope, so that the heap
290 // profiler does not see unabalanced malloc/free calls from these containers. 290 // profiler does not see unabalanced malloc/free calls from these containers.
291 { 291 {
292 TraceEventMemoryOverhead overhead; 292 AutoLock lock(allocation_register_lock_);
293 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; 293 if (allocation_register_) {
294 { 294 pmd->DumpHeapUsage(*allocation_register_, "malloc");
295 AutoLock lock(allocation_register_lock_); 295 }
296 if (allocation_register_) {
297 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) {
298 for (const auto& alloc_size : *allocation_register_) {
299 AllocationMetrics& metrics = metrics_by_context[alloc_size.context];
300 metrics.size += alloc_size.size;
301 metrics.count++;
302 }
303 }
304 allocation_register_->EstimateTraceMemoryOverhead(&overhead);
305 }
306 } // lock(allocation_register_lock_)
307 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc");
308 } 296 }
309 tid_dumping_heap_ = kInvalidThreadId; 297 tid_dumping_heap_ = kInvalidThreadId;
310 298
311 return true; 299 return true;
312 } 300 }
313 301
314 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { 302 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) {
315 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 303 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
316 if (enabled) { 304 if (enabled) {
317 { 305 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 tid_dumping_heap_ == PlatformThread::CurrentId()) 351 tid_dumping_heap_ == PlatformThread::CurrentId())
364 return; 352 return;
365 AutoLock lock(allocation_register_lock_); 353 AutoLock lock(allocation_register_lock_);
366 if (!allocation_register_) 354 if (!allocation_register_)
367 return; 355 return;
368 allocation_register_->Remove(address); 356 allocation_register_->Remove(address);
369 } 357 }
370 358
371 } // namespace trace_event 359 } // namespace trace_event
372 } // namespace base 360 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698