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

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

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: Address comments 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (--enable-heap-profiling) AND a DETAILED dump is requested.
290 // However, when enabled, the overhead of the heap profiler should be always 290 // However, when enabled, the overhead of the heap profiler should be always
ssid 2017/03/16 02:09:20 I think this comment should be moved to process_me
291 // reported to avoid oscillations of the malloc total in LIGHT dumps. 291 // reported to avoid oscillations of the malloc total in LIGHT dumps.
292 292
293 tid_dumping_heap_ = PlatformThread::CurrentId(); 293 tid_dumping_heap_ = PlatformThread::CurrentId();
294 // At this point the Insert/RemoveAllocation hooks will ignore this thread. 294 // 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 295 // 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. 296 // profiler does not see unabalanced malloc/free calls from these containers.
297 { 297 {
298 TraceEventMemoryOverhead overhead; 298 AutoLock lock(allocation_register_lock_);
299 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; 299 if (allocation_register_) {
300 { 300 pmd->DumpHeapUsage(*allocation_register_, "malloc");
301 AutoLock lock(allocation_register_lock_); 301 }
302 if (allocation_register_) {
303 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) {
304 for (const auto& alloc_size : *allocation_register_) {
305 AllocationMetrics& metrics = metrics_by_context[alloc_size.context];
306 metrics.size += alloc_size.size;
307 metrics.count++;
308 }
309 }
310 allocation_register_->EstimateTraceMemoryOverhead(&overhead);
311 }
312 } // lock(allocation_register_lock_)
313 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc");
314 } 302 }
315 tid_dumping_heap_ = kInvalidThreadId; 303 tid_dumping_heap_ = kInvalidThreadId;
316 304
317 return true; 305 return true;
318 } 306 }
319 307
320 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { 308 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) {
321 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 309 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
322 if (enabled) { 310 if (enabled) {
323 { 311 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 tid_dumping_heap_ == PlatformThread::CurrentId()) 357 tid_dumping_heap_ == PlatformThread::CurrentId())
370 return; 358 return;
371 AutoLock lock(allocation_register_lock_); 359 AutoLock lock(allocation_register_lock_);
372 if (!allocation_register_) 360 if (!allocation_register_)
373 return; 361 return;
374 allocation_register_->Remove(address); 362 allocation_register_->Remove(address);
375 } 363 }
376 364
377 } // namespace trace_event 365 } // namespace trace_event
378 } // namespace base 366 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698