Chromium Code Reviews| Index: base/allocator/allocator_extension.cc |
| diff --git a/base/allocator/allocator_extension.cc b/base/allocator/allocator_extension.cc |
| index 17682f85d4950acd837f268056afa3ae49fc43c2..30eb65e9bf693cb4859c6218d0b29a7434613e23 100644 |
| --- a/base/allocator/allocator_extension.cc |
| +++ b/base/allocator/allocator_extension.cc |
| @@ -9,6 +9,7 @@ |
| #if defined(USE_TCMALLOC) |
| #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
| #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
| +#include "third_party/tcmalloc/chromium/src/gperftools/malloc_hook.h" |
| #endif |
| namespace base { |
| @@ -34,5 +35,37 @@ bool IsHeapProfilerRunning() { |
| return false; |
| } |
| +void SetHooks(AllocHookFunc alloc_hook, FreeHookFunc free_hook) { |
| +#if defined(USE_TCMALLOC) |
| + // Make sure no hooks get overwritten. |
| + auto prev_alloc_hook = MallocHook::SetNewHook(alloc_hook); |
| + if (alloc_hook) |
| + DCHECK(!prev_alloc_hook); |
| + |
| + auto prev_free_hook = MallocHook::SetDeleteHook(free_hook); |
| + if (free_hook) |
| + DCHECK(!prev_free_hook); |
| +#endif |
|
Primiano Tucci (use gerrit)
2016/03/02 22:16:11
Ok this looks great now, thanks :)
|
| +} |
| + |
| +bool RemoveHooks(AllocHookFunc alloc_hook, FreeHookFunc free_hook) { |
|
Primiano Tucci (use gerrit)
2016/03/02 22:16:11
Is this a leftover? This doesn't seem neither decl
Simon Que
2016/03/02 22:35:25
Done.
|
| +#if defined(USE_TCMALLOC) |
| + return MallocHook::RemoveNewHook(alloc_hook) && |
| + MallocHook::RemoveDeleteHook(free_hook); |
| +#endif |
| + return false; |
| +} |
| + |
| +int GetCallStack(void** stack, int max_stack_size, int /* skip_count */) { |
| +#if defined(USE_TCMALLOC) |
| + // |skip_count| is not used by the following function. Instead, the number of |
| + // frames to skip is determined internally. |
| + // See MallocHook_GetCallerStackTrace() in |
| + // third_party/tcmalloc/chromium/src/malloc_hook.cc. |
| + return MallocHook::GetCallerStackTrace(stack, max_stack_size, 0); |
| +#endif |
| + return 0; |
| +} |
| + |
| } // namespace allocator |
| } // namespace base |