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

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

Issue 2658723007: Hook up allocator shim on mac. (Closed)
Patch Set: Rebase. 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
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) {
Primiano Tucci (use gerrit) 2017/01/28 05:10:02 do you know if this will actually happen frequenty
erikchen 2017/01/31 02:21:22 *shrug*, okay. I was just mirroring the format of
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 tid_dumping_heap_ == PlatformThread::CurrentId()) 343 tid_dumping_heap_ == PlatformThread::CurrentId())
317 return; 344 return;
318 AutoLock lock(allocation_register_lock_); 345 AutoLock lock(allocation_register_lock_);
319 if (!allocation_register_) 346 if (!allocation_register_)
320 return; 347 return;
321 allocation_register_->Remove(address); 348 allocation_register_->Remove(address);
322 } 349 }
323 350
324 } // namespace trace_event 351 } // namespace trace_event
325 } // namespace base 352 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698