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

Unified 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, 11 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/malloc_dump_provider.cc
diff --git a/base/trace_event/malloc_dump_provider.cc b/base/trace_event/malloc_dump_provider.cc
index 4683694d6bb60dc15a59b544dcadf639a7464e84..220b93e82d18fc4ef0295051c56d0a4dfc03ce4b 100644
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -82,14 +82,49 @@ size_t HookGetSizeEstimate(const AllocatorDispatch* self, void* address) {
return next->get_size_estimate_function(next, address);
}
+unsigned HookBatchMalloc(const AllocatorDispatch* self,
+ size_t size,
+ void** results,
+ unsigned num_requested) {
+ const AllocatorDispatch* const next = self->next;
+ unsigned count =
+ next->batch_malloc_function(next, size, results, num_requested);
+ for (unsigned i = 0; i < count; ++i) {
+ MallocDumpProvider::GetInstance()->InsertAllocation(results[i], size);
+ }
+ return count;
+}
+
+void HookBatchFree(const AllocatorDispatch* self,
+ void** to_be_freed,
+ unsigned num_to_be_freed) {
+ const AllocatorDispatch* const next = self->next;
+ for (unsigned i = 0; i < num_to_be_freed; ++i) {
+ MallocDumpProvider::GetInstance()->RemoveAllocation(to_be_freed[i]);
+ }
+ next->batch_free_function(next, to_be_freed, num_to_be_freed);
+}
+
+void HookFreeDefiniteSize(const AllocatorDispatch* self,
+ void* ptr,
+ size_t size) {
+ if (ptr)
+ MallocDumpProvider::GetInstance()->RemoveAllocation(ptr);
+ const AllocatorDispatch* const next = self->next;
+ next->free_definite_size_function(next, ptr, size);
+}
+
AllocatorDispatch g_allocator_hooks = {
- &HookAlloc, /* alloc_function */
- &HookZeroInitAlloc, /* alloc_zero_initialized_function */
- &HookllocAligned, /* alloc_aligned_function */
- &HookRealloc, /* realloc_function */
- &HookFree, /* free_function */
- &HookGetSizeEstimate, /* get_size_estimate_function */
- nullptr, /* next */
+ &HookAlloc, /* alloc_function */
+ &HookZeroInitAlloc, /* alloc_zero_initialized_function */
+ &HookllocAligned, /* alloc_aligned_function */
+ &HookRealloc, /* realloc_function */
+ &HookFree, /* free_function */
+ &HookGetSizeEstimate, /* get_size_estimate_function */
+ &HookBatchMalloc, /* batch_malloc_function */
+ &HookBatchFree, /* batch_free_function */
+ &HookFreeDefiniteSize, /* free_definite_size_function */
+ nullptr, /* next */
};
#endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
« 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