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

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

Issue 2865333002: Adding malloc allocator metric for objects allocated through shim (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (!heap_profiler_enabled_) 287 if (!heap_profiler_enabled_)
288 return true; 288 return true;
289 289
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 temporariy 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 unabalanced 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;
301 size_t shim_allocated_objects_count = 0;
300 TraceEventMemoryOverhead overhead; 302 TraceEventMemoryOverhead overhead;
301 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context; 303 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context;
302 { 304 {
303 AutoLock lock(allocation_register_lock_); 305 AutoLock lock(allocation_register_lock_);
304 if (allocation_register_) { 306 if (allocation_register_) {
305 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { 307 if (args.level_of_detail == MemoryDumpLevelOfDetail::DETAILED) {
306 for (const auto& alloc_size : *allocation_register_) { 308 for (const auto& alloc_size : *allocation_register_) {
307 AllocationMetrics& metrics = metrics_by_context[alloc_size.context]; 309 AllocationMetrics& metrics = metrics_by_context[alloc_size.context];
308 metrics.size += alloc_size.size; 310 metrics.size += alloc_size.size;
309 metrics.count++; 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++;
310 } 316 }
311 } 317 }
312 allocation_register_->EstimateTraceMemoryOverhead(&overhead); 318 allocation_register_->EstimateTraceMemoryOverhead(&overhead);
313 } 319 }
320
321 inner_dump->AddScalar("shim_allocated_objects_size",
322 MemoryAllocatorDump::kUnitsBytes,
323 shim_allocated_objects_size);
324 inner_dump->AddScalar("shim_allocator_object_count",
325 MemoryAllocatorDump::kUnitsObjects,
326 shim_allocated_objects_count);
314 } // lock(allocation_register_lock_) 327 } // lock(allocation_register_lock_)
315 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); 328 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc");
316 } 329 }
317 tid_dumping_heap_ = kInvalidThreadId; 330 tid_dumping_heap_ = kInvalidThreadId;
318 331
319 return true; 332 return true;
320 } 333 }
321 334
322 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { 335 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) {
323 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 336 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 tid_dumping_heap_ == PlatformThread::CurrentId()) 384 tid_dumping_heap_ == PlatformThread::CurrentId())
372 return; 385 return;
373 AutoLock lock(allocation_register_lock_); 386 AutoLock lock(allocation_register_lock_);
374 if (!allocation_register_) 387 if (!allocation_register_)
375 return; 388 return;
376 allocation_register_->Remove(address); 389 allocation_register_->Remove(address);
377 } 390 }
378 391
379 } // namespace trace_event 392 } // namespace trace_event
380 } // namespace base 393 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698