* ecore: Add memory statistic support. Set ECORE_MEM_STAT environment
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 18 Mar 2010 14:43:39 +0000 (14:43 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 18 Mar 2010 14:43:39 +0000 (14:43 +0000)
variable to get them.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@47319 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

configure.ac
src/lib/ecore/ecore.c

index 13074d1..1ee7fa3 100644 (file)
@@ -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"
index 45243bb..8ad0dfb 100644 (file)
 #include "Ecore.h"
 #include "ecore_private.h"
 
+#if HAVE_MALLINFO
+#include <malloc.h>
+
+#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