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

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

Issue 2601573002: mac: Hook up allocator shim. (Closed)
Patch Set: Clean up. Created 3 years, 12 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"
(...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 if (to_be_freed[i] != nullptr) {
104 MallocDumpProvider::GetInstance()->RemoveAllocation(to_be_freed[i]);
105 }
106 }
107 next->batch_free_function(next, to_be_freed, num_to_be_freed);
108 }
109
85 AllocatorDispatch g_allocator_hooks = { 110 AllocatorDispatch g_allocator_hooks = {
86 &HookAlloc, /* alloc_function */ 111 &HookAlloc, /* alloc_function */
87 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ 112 &HookZeroInitAlloc, /* alloc_zero_initialized_function */
88 &HookllocAligned, /* alloc_aligned_function */ 113 &HookllocAligned, /* alloc_aligned_function */
89 &HookRealloc, /* realloc_function */ 114 &HookRealloc, /* realloc_function */
90 &HookFree, /* free_function */ 115 &HookFree, /* free_function */
91 &HookGetSizeEstimate, /* get_size_estimate_function */ 116 &HookGetSizeEstimate, /* get_size_estimate_function */
117 &HookBatchMalloc, /* get_size_estimate_function */
118 &HookBatchFree, /* get_size_estimate_function */
92 nullptr, /* next */ 119 nullptr, /* next */
93 }; 120 };
94 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 121 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
95 122
96 #if defined(OS_WIN) 123 #if defined(OS_WIN)
97 // A structure containing some information about a given heap. 124 // A structure containing some information about a given heap.
98 struct WinHeapInfo { 125 struct WinHeapInfo {
99 size_t committed_size; 126 size_t committed_size;
100 size_t uncommitted_size; 127 size_t uncommitted_size;
101 size_t allocated_size; 128 size_t allocated_size;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 tid_dumping_heap_ == PlatformThread::CurrentId()) 340 tid_dumping_heap_ == PlatformThread::CurrentId())
314 return; 341 return;
315 AutoLock lock(allocation_register_lock_); 342 AutoLock lock(allocation_register_lock_);
316 if (!allocation_register_) 343 if (!allocation_register_)
317 return; 344 return;
318 allocation_register_->Remove(address); 345 allocation_register_->Remove(address);
319 } 346 }
320 347
321 } // namespace trace_event 348 } // namespace trace_event
322 } // namespace base 349 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698