AC_DEFINE([HAVE_DIRFD], [1], [ Define to 1 if you have the `dirfd' function or macro.])
fi
+# check debug information for malloc
+AC_CHECK_FUNCS([malloc_usable_size], [malloc_true_size="yes"], [malloc_true_size="no"])
+if test "x${malloc_true_size}" = "xyes" ; then
+ AC_DEFINE([HAVE_MALLOC_USABLE_SIZE], [1], [We will be able to know the exact amount of wasted memory])
+fi
+
+want_debug_malloc="no"
+AC_ARG_ENABLE([debug-malloc],
+ [AC_HELP_STRING([--enable-debug-malloc], [enable debugging of malloc usage overhead in our allocator @<:@default=enabled@:>@])],
+ [
+ if test "x${enableval}" = "xyes" ; then
+ want_debug_malloc="yes"
+ else
+ want_debug_malloc="no"
+ fi
+ ], [want_debug_malloc="no"])
+
+if test "x${malloc_true_size}" = "xyes" -a "x${want_debug_malloc}" = "xyes"; then
+ AC_DEFINE([EINA_DEBUG_MALLOC], [1], [Turn on debugging overhead in mempool])
+fi
+
# dlopen and dladdr
dlopen_libs=""
case "$host_os" in
# endif
#endif
+#ifdef EINA_DEBUG_MALLOC
+# include <malloc.h>
+#endif
+
#ifdef EFL_HAVE_WIN32_THREADS
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <valgrind/memcheck.h>
#endif
-#ifdef DEBUG
+#if defined DEBUG || defined EINA_DEBUG_MALLOC
#include <assert.h>
#include "eina_log.h"
int alloc_size;
int group_size;
int usage;
+#ifdef EINA_DEBUG_MALLOC
+ int minimal_size;
+#endif
#ifdef EFL_DEBUG_THREADS
pthread_t self;
#endif
return NULL;
}
+#ifdef EINA_DEBUG_MALLOC
+ {
+ size_t sz;
+
+ sz = malloc_usable_size(p);
+ if (sz - pool->minimal_size > 0)
+ INF("Just allocated %0.2f%% to much memory in '%s' for one block of size %i that means %i bytes to much.",
+ ((float)(sz - pool->minimal_size) * 100) / (float) (pool->alloc_size),
+ pool->name,
+ pool->alloc_size,
+ sz - pool->minimal_size);
+ }
+#endif
+
alignof = eina_mempool_alignof(sizeof(Chained_Pool));
ptr = (unsigned char *)p + alignof;
p->usage = 0;
memcpy((char *)mp->name, context, length);
}
+#ifdef EINA_DEBUG_MALLOC
+ mp->minimal_size = item_size * mp->pool_size + sizeof(Chained_Pool);
+#endif
+
mp->item_alloc = eina_mempool_alignof(item_size);
mp->group_size = mp->item_alloc * mp->pool_size;
mp->alloc_size = mp->group_size + eina_mempool_alignof(sizeof(Chained_Pool));
Eina_Bool chained_init(void)
{
-#ifdef DEBUG
+#if defined DEBUG || defined EINA_DEBUG_MALLOC
_eina_chained_mp_log_dom = eina_log_domain_register("eina_mempool",
EINA_LOG_COLOR_DEFAULT);
if (_eina_chained_mp_log_dom < 0)
void chained_shutdown(void)
{
eina_mempool_unregister(&_eina_chained_mp_backend);
-#ifdef DEBUG
+#if defined DEBUG || defined EINA_DEBUG_MALLOC
eina_log_domain_unregister(_eina_chained_mp_log_dom);
_eina_chained_mp_log_dom = -1;
#endif