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..c2ad9f4ed5f64d385e35d3b72bf036c8d55203ac 100644 |
--- a/base/trace_event/malloc_dump_provider.cc |
+++ b/base/trace_event/malloc_dump_provider.cc |
@@ -82,6 +82,31 @@ 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) { |
+ 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
|
+ MallocDumpProvider::GetInstance()->RemoveAllocation(to_be_freed[i]); |
+ } |
+ } |
+ next->batch_free_function(next, to_be_freed, num_to_be_freed); |
+} |
+ |
AllocatorDispatch g_allocator_hooks = { |
&HookAlloc, /* alloc_function */ |
&HookZeroInitAlloc, /* alloc_zero_initialized_function */ |
@@ -89,6 +114,8 @@ AllocatorDispatch g_allocator_hooks = { |
&HookRealloc, /* realloc_function */ |
&HookFree, /* free_function */ |
&HookGetSizeEstimate, /* get_size_estimate_function */ |
+ &HookBatchMalloc, /* get_size_estimate_function */ |
+ &HookBatchFree, /* get_size_estimate_function */ |
nullptr, /* next */ |
}; |
#endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |