support mtrace in eina at runtime. easier now to enable via env vars.

SVN revision: 63498
This commit is contained in:
Carsten Haitzler 2011-09-20 11:28:25 +00:00
parent c07415b8bd
commit 495f658861
2 changed files with 32 additions and 0 deletions

View File

@ -488,6 +488,9 @@ AC_SUBST([dlopen_libs])
EFL_CHECK_FNMATCH([], [AC_MSG_ERROR([Cannot find fnmatch()])])
AC_CHECK_HEADERS([mcheck.h], [AC_DEFINE([HAVE_MCHECK], [1], [Have mcheck.h])])
AC_CHECK_FUNCS([mtrace], [AC_DEFINE([HAVE_MTRACE], [1], [Have mtrace])])
# iconv library
have_iconv="no"
AC_ARG_WITH([iconv-link],

View File

@ -37,6 +37,16 @@
# endif
#endif
#ifdef HAVE_MCHECK
# ifdef HAVE_MTRACE
# define MT 1
# endif
#endif
#ifdef MT
#include <mcheck.h>
#endif
#include "eina_lock.h"
#include "eina_config.h"
#include "eina_private.h"
@ -97,6 +107,10 @@ EAPI pthread_t _eina_main_loop;
static pid_t _eina_pid;
#endif
#ifdef MT
static int _mt_enabled = 0;
#endif
#ifdef EINA_HAVE_DEBUG_THREADS
EAPI int _eina_threads_debug = 0;
EAPI pthread_mutex_t _eina_tracking_lock;
@ -213,6 +227,14 @@ eina_init(void)
if (EINA_LIKELY(_eina_main_count > 0))
return ++_eina_main_count;
#ifdef MT
if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE")))
{
_mt_enabled = 1;
mtrace();
}
#endif
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
@ -273,6 +295,13 @@ eina_shutdown(void)
#ifdef EINA_HAVE_DEBUG_THREADS
pthread_mutex_destroy(&_eina_tracking_lock);
#endif
#ifdef MT
if (_mt_enabled)
{
muntrace();
_mt_enabled = 0;
}
#endif
}
return _eina_main_count;