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

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

Issue 2163783003: Implement a ScopedThreadHeapUsage class to allow profiling per-thread heap usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shim-default
Patch Set: Fix a brain****, may even compile now. Created 4 years, 3 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/trace_event/heap_profiler_allocation_context.h" 12 #include "base/trace_event/heap_profiler_allocation_context.h"
13 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 13 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
14 #include "base/trace_event/heap_profiler_allocation_register.h" 14 #include "base/trace_event/heap_profiler_allocation_register.h"
15 #include "base/trace_event/heap_profiler_heap_dump_writer.h" 15 #include "base/trace_event/heap_profiler_heap_dump_writer.h"
16 #include "base/trace_event/process_memory_dump.h" 16 #include "base/trace_event/process_memory_dump.h"
17 #include "base/trace_event/trace_event_argument.h" 17 #include "base/trace_event/trace_event_argument.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 19
20 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
21 #include <malloc/malloc.h> 21 #include <malloc/malloc.h>
22 #else 22 #else
23 #include <malloc.h> 23 #include <malloc.h>
24 #endif 24 #endif
25 25
26 namespace base { 26 namespace base {
27 namespace trace_event { 27 namespace trace_event {
28 28
29 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 29 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
30
30 namespace { 31 namespace {
31 32
32 using allocator::AllocatorDispatch; 33 using allocator::AllocatorDispatch;
33 34
34 void* HookAlloc(const AllocatorDispatch* self, size_t size) { 35 void* HookAlloc(const AllocatorDispatch* self, size_t size) {
35 const AllocatorDispatch* const next = self->next; 36 const AllocatorDispatch* const next = self->next;
36 void* ptr = next->alloc_function(next, size); 37 void* ptr = next->alloc_function(next, size);
37 if (ptr) 38 if (ptr)
38 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, size); 39 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, size);
39 return ptr; 40 return ptr;
(...skipping 26 matching lines...) Expand all
66 return ptr; 67 return ptr;
67 } 68 }
68 69
69 void HookFree(const AllocatorDispatch* self, void* address) { 70 void HookFree(const AllocatorDispatch* self, void* address) {
70 if (address) 71 if (address)
71 MallocDumpProvider::GetInstance()->RemoveAllocation(address); 72 MallocDumpProvider::GetInstance()->RemoveAllocation(address);
72 const AllocatorDispatch* const next = self->next; 73 const AllocatorDispatch* const next = self->next;
73 next->free_function(next, address); 74 next->free_function(next, address);
74 } 75 }
75 76
77 size_t HookGetSizeEstimate(const AllocatorDispatch* self, void* address) {
Primiano Tucci (use gerrit) 2016/08/24 14:11:46 yeah you don't really need to touch this at all if
Sigurður Ásgeirsson 2016/09/01 15:18:18 Acknowledged.
78 const AllocatorDispatch* const next = self->next;
79 if (!next->get_size_estimate_function)
80 return 0;
81 return next->get_size_estimate_function(next, address);
82 }
83
76 AllocatorDispatch g_allocator_hooks = { 84 AllocatorDispatch g_allocator_hooks = {
77 &HookAlloc, /* alloc_function */ 85 &HookAlloc, /* alloc_function */
78 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ 86 &HookZeroInitAlloc, /* alloc_zero_initialized_function */
79 &HookllocAligned, /* alloc_aligned_function */ 87 &HookllocAligned, /* alloc_aligned_function */
80 &HookRealloc, /* realloc_function */ 88 &HookRealloc, /* realloc_function */
81 &HookFree, /* free_function */ 89 &HookFree, /* free_function */
82 nullptr, /* next */ 90 &HookGetSizeEstimate, /* get_size_estimate_function */
91 nullptr, /* next */
83 }; 92 };
84 93
85 } // namespace 94 } // namespace
86 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 95 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
87 96
88 // static 97 // static
89 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; 98 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects";
90 99
91 // static 100 // static
92 MallocDumpProvider* MallocDumpProvider::GetInstance() { 101 MallocDumpProvider* MallocDumpProvider::GetInstance() {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 tid_dumping_heap_ == PlatformThread::CurrentId()) 257 tid_dumping_heap_ == PlatformThread::CurrentId())
249 return; 258 return;
250 AutoLock lock(allocation_register_lock_); 259 AutoLock lock(allocation_register_lock_);
251 if (!allocation_register_) 260 if (!allocation_register_)
252 return; 261 return;
253 allocation_register_->Remove(address); 262 allocation_register_->Remove(address);
254 } 263 }
255 264
256 } // namespace trace_event 265 } // namespace trace_event
257 } // namespace base 266 } // namespace base
OLDNEW
« base/debug/scoped_heap_usage_unittest.cc ('K') | « base/debug/scoped_heap_usage_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698