From d1ce34964bc76c85c286ffe73017842336c46b87 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 18 Mar 2010 14:43:39 +0000 Subject: [PATCH] * ecore: Add memory statistic support. Set ECORE_MEM_STAT environment variable to get them. SVN revision: 47319 --- legacy/ecore/configure.ac | 10 +++++ legacy/ecore/src/lib/ecore/ecore.c | 70 +++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/legacy/ecore/configure.ac b/legacy/ecore/configure.ac index 13074d15ba..1ee7fa3369 100644 --- a/legacy/ecore/configure.ac +++ b/legacy/ecore/configure.ac @@ -950,6 +950,15 @@ if test "x$have_atfile_source" != "xno"; then ]) fi +### Checks for optionnal feature +AC_CHECK_FUNC(mallinfo, + [ + have_mallinfo=yes + AC_DEFINE(HAVE_MALLINFO, 1, [Gather memory statistic]) + ], [ + have_mallinfo=no + ]) + ### Ecore modules ## Core modules @@ -1360,6 +1369,7 @@ echo echo " Ecore........................: always" echo " Thread support.............: $have_pthread" echo " GLib support...............: $have_glib" +echo " Gathering memory statistic.: $have_mallinfo" echo " Ecore_Con....................: $have_ecore_con" if test "x$have_ecore_con" = "xyes" ; then echo $ECHO_N " OpenSSL....................: $have_openssl $ECHO_C" diff --git a/legacy/ecore/src/lib/ecore/ecore.c b/legacy/ecore/src/lib/ecore/ecore.c index 45243bb019..8ad0dfba58 100644 --- a/legacy/ecore/src/lib/ecore/ecore.c +++ b/legacy/ecore/src/lib/ecore/ecore.c @@ -33,6 +33,19 @@ #include "Ecore.h" #include "ecore_private.h" +#if HAVE_MALLINFO +#include + +#define KEEP_MAX(Global, Local) \ + if (Global < (Local)) \ + Global = Local; + +static int _ecore_memory_statistic(void *data); +static int _ecore_memory_max_total = 0; +static int _ecore_memory_max_free = 0; +static pid_t _ecore_memory_pid = 0; +#endif + static const char *_ecore_magic_string_get(Ecore_Magic m); static int _ecore_init_count = 0; EAPI int _ecore_log_dom = -1; @@ -103,9 +116,17 @@ ecore_init(void) _ecore_job_init(); _ecore_loop_time = ecore_time_get(); +#if HAVE_MALLINFO + if (getenv("ECORE_MEM_STAT")) + { + _ecore_memory_pid = getpid(); + ecore_animator_add(_ecore_memory_statistic, NULL); + } +#endif + return _ecore_init_count; - shutdown_log_dom: + shutdown_log_dom: eina_shutdown(); shutdown_evil: #ifdef HAVE_EVIL @@ -144,6 +165,19 @@ ecore_shutdown(void) _ecore_event_shutdown(); _ecore_main_shutdown(); _ecore_signal_shutdown(); + +#if HAVE_MALLINFO + if (getenv("ECORE_MEM_STAT")) + { + _ecore_memory_statistic(NULL); + + ERR("[%i] Memory MAX total: %i, free: %i", + _ecore_memory_pid, + _ecore_memory_max_total, + _ecore_memory_max_free); + } +#endif + eina_log_domain_unregister(_ecore_log_dom); _ecore_log_dom = -1; eina_shutdown(); @@ -340,3 +374,37 @@ _ecore_fps_debug_runtime_add(double t) *(_ecore_fps_runtime_mmap) += tm; } } + +#if HAVE_MALLINFO +static int +_ecore_memory_statistic(__UNUSED__ void *data) +{ + struct mallinfo mi; + static int uordblks = 0; + static int fordblks = 0; + Eina_Bool changed = EINA_FALSE; + + mi = mallinfo(); + +#define HAS_CHANGED(Global, Local) \ + if (Global != Local) \ + { \ + Global = Local; \ + changed = EINA_TRUE; \ + } + + HAS_CHANGED(uordblks, mi.uordblks); + HAS_CHANGED(fordblks, mi.fordblks); + + if (changed) + ERR("[%i] Memory total: %i, free: %i", + _ecore_memory_pid, + mi.uordblks, + mi.fordblks); + + KEEP_MAX(_ecore_memory_max_total, mi.uordblks); + KEEP_MAX(_ecore_memory_max_free, mi.fordblks); + + return 1; +} +#endif