From 2d52ff9170df2dd66eaf31922807d0360fa77e1b Mon Sep 17 00:00:00 2001 From: Thomas Porzelt Date: Sat, 26 Nov 2011 16:07:38 +0100 Subject: [PATCH] [mempool] support profiler for mmap allocations. use g_malloc/free instead malloc/free --- src/common/mempool.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/common/mempool.c b/src/common/mempool.c index 8010b3e..0321381 100644 --- a/src/common/mempool.c +++ b/src/common/mempool.c @@ -1,6 +1,10 @@ #include +#ifdef WITH_PROFILER +#include +#endif + /* * available #defines: * - MEMPOOL_MALLOC @@ -166,10 +170,17 @@ static inline void* mp_alloc_page(gsize size) { g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes with mmap", G_STRLOC, size); } # else - if (G_UNLIKELY(NULL == (ptr = malloc(size)))) { + if (G_UNLIKELY(NULL == (ptr = g_malloc(size)))) { g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes", G_STRLOC, size); } # endif + +#ifdef WITH_PROFILER + if (G_UNLIKELY(li_profiler_enabled)) { + li_profiler_hashtable_insert((gpointer)ptr, size); + } +#endif + return ptr; } @@ -178,8 +189,14 @@ static inline void mp_free_page(const void *ptr, gsize size) { # ifdef MAP_ANON munmap((void*) ptr, size); # else - free(ptr); + g_free(ptr); # endif + +#ifdef WITH_PROFILER + if (G_UNLIKELY(li_profiler_enabled)) { + li_profiler_hashtable_remove((gpointer)ptr); + } +#endif } /* how many chunks in an arey for a chunk size? */