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

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

Issue 2658723007: Hook up allocator shim on mac. (Closed)
Patch Set: remove a debugging test. Created 3 years, 10 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 | « base/debug/thread_heap_usage_tracker_unittest.cc ('k') | build/config/allocator.gni » ('j') | 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 "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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 MallocDumpProvider::GetInstance()->RemoveAllocation(address); 75 MallocDumpProvider::GetInstance()->RemoveAllocation(address);
76 const AllocatorDispatch* const next = self->next; 76 const AllocatorDispatch* const next = self->next;
77 next->free_function(next, address); 77 next->free_function(next, address);
78 } 78 }
79 79
80 size_t HookGetSizeEstimate(const AllocatorDispatch* self, void* address) { 80 size_t HookGetSizeEstimate(const AllocatorDispatch* self, void* address) {
81 const AllocatorDispatch* const next = self->next; 81 const AllocatorDispatch* const next = self->next;
82 return next->get_size_estimate_function(next, address); 82 return next->get_size_estimate_function(next, address);
83 } 83 }
84 84
85 unsigned HookBatchMalloc(const AllocatorDispatch* self,
86 size_t size,
87 void** results,
88 unsigned num_requested) {
89 const AllocatorDispatch* const next = self->next;
90 unsigned count =
91 next->batch_malloc_function(next, size, results, num_requested);
92 for (unsigned i = 0; i < count; ++i) {
93 MallocDumpProvider::GetInstance()->InsertAllocation(results[i], size);
94 }
95 return count;
96 }
97
98 void HookBatchFree(const AllocatorDispatch* self,
99 void** to_be_freed,
100 unsigned num_to_be_freed) {
101 const AllocatorDispatch* const next = self->next;
102 for (unsigned i = 0; i < num_to_be_freed; ++i) {
103 MallocDumpProvider::GetInstance()->RemoveAllocation(to_be_freed[i]);
104 }
105 next->batch_free_function(next, to_be_freed, num_to_be_freed);
106 }
107
108 void HookFreeDefiniteSize(const AllocatorDispatch* self,
109 void* ptr,
110 size_t size) {
111 if (ptr)
112 MallocDumpProvider::GetInstance()->RemoveAllocation(ptr);
113 const AllocatorDispatch* const next = self->next;
114 next->free_definite_size_function(next, ptr, size);
115 }
116
85 AllocatorDispatch g_allocator_hooks = { 117 AllocatorDispatch g_allocator_hooks = {
86 &HookAlloc, /* alloc_function */ 118 &HookAlloc, /* alloc_function */
87 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ 119 &HookZeroInitAlloc, /* alloc_zero_initialized_function */
88 &HookllocAligned, /* alloc_aligned_function */ 120 &HookllocAligned, /* alloc_aligned_function */
89 &HookRealloc, /* realloc_function */ 121 &HookRealloc, /* realloc_function */
90 &HookFree, /* free_function */ 122 &HookFree, /* free_function */
91 &HookGetSizeEstimate, /* get_size_estimate_function */ 123 &HookGetSizeEstimate, /* get_size_estimate_function */
92 nullptr, /* next */ 124 &HookBatchMalloc, /* batch_malloc_function */
125 &HookBatchFree, /* batch_free_function */
126 &HookFreeDefiniteSize, /* free_definite_size_function */
127 nullptr, /* next */
93 }; 128 };
94 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 129 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
95 130
96 #if defined(OS_WIN) 131 #if defined(OS_WIN)
97 // A structure containing some information about a given heap. 132 // A structure containing some information about a given heap.
98 struct WinHeapInfo { 133 struct WinHeapInfo {
99 size_t committed_size; 134 size_t committed_size;
100 size_t uncommitted_size; 135 size_t uncommitted_size;
101 size_t allocated_size; 136 size_t allocated_size;
102 size_t block_count; 137 size_t block_count;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 tid_dumping_heap_ == PlatformThread::CurrentId()) 351 tid_dumping_heap_ == PlatformThread::CurrentId())
317 return; 352 return;
318 AutoLock lock(allocation_register_lock_); 353 AutoLock lock(allocation_register_lock_);
319 if (!allocation_register_) 354 if (!allocation_register_)
320 return; 355 return;
321 allocation_register_->Remove(address); 356 allocation_register_->Remove(address);
322 } 357 }
323 358
324 } // namespace trace_event 359 } // namespace trace_event
325 } // namespace base 360 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/thread_heap_usage_tracker_unittest.cc ('k') | build/config/allocator.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698