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

Unified Diff: base/allocator/allocator_extension.cc

Issue 1665553002: metrics: Connect leak detector to allocator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify alloc hook registration; Enclose more stuff in CrOS #ifdef Created 4 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698