Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore


Modified Files:
        Ecore.h Makefile.am ecore.c ecore_main.c ecore_private.h 


Log Message:


debugging stuff to help profile an application using evas/ecore etc. to see
where (rougly) time is spent (as it runs - dynamically). quite useful if your
code is dropping frames to keep animation going - but u'd like to know when
exactly its happening so you can lean down the graphics design or the code in
those situations.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Ecore.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- Ecore.h     29 Feb 2004 05:08:26 -0000      1.6
+++ Ecore.h     17 Mar 2004 05:14:12 -0000      1.7
@@ -36,6 +36,7 @@
    typedef void Ecore_Timer; /**< A handle for timers */
    typedef void Ecore_Idler; /**< A handle for idlers */
    typedef void Ecore_Idle_Enterer; /**< A handle for idle enterers */
+   typedef void Ecore_Idle_Exiter; /**< A handle for idle exiters */
    typedef void Ecore_Fd_Handler; /**< A handle for Fd hanlders */
    typedef void Ecore_Event_Handler; /**< A handle for an event handler */
    typedef void Ecore_Event_Filter; /**< A handle for an event filter */
@@ -118,6 +119,9 @@
    Ecore_Idle_Enterer *ecore_idle_enterer_add(int (*func) (void *data), const void 
*data);
    void               *ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
 
+   Ecore_Idle_Exiter *ecore_idle_exiter_add(int (*func) (void *data), const void 
*data);
+   void              *ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter);
+
    void              ecore_main_loop_iterate(void);
    void              ecore_main_loop_begin(void);
    void              ecore_main_loop_quit(void);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- Makefile.am 23 Sep 2003 08:09:29 -0000      1.2
+++ Makefile.am 17 Mar 2004 05:14:13 -0000      1.3
@@ -12,6 +12,7 @@
 ecore_events.c \
 ecore_exe.c \
 ecore_idle_enterer.c \
+ecore_idle_exiter.c \
 ecore_idler.c \
 ecore_list.c \
 ecore_main.c \
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ecore.c     20 Feb 2004 07:06:25 -0000      1.4
+++ ecore.c     17 Mar 2004 05:14:13 -0000      1.5
@@ -4,6 +4,8 @@
 static const char *_ecore_magic_string_get(Ecore_Magic m);
 static int _ecore_init_count = 0;
 
+int _ecore_fps_debug = 0;
+
 /**
  * Set up connections, signal handlers, sockets etc.
  * @return 1 or greater on success, 0 otherwise
@@ -30,7 +32,11 @@
 ecore_init(void)
 {
    if (++_ecore_init_count == 1)
-      _ecore_signal_init();
+     {
+       if (getenv("ECORE_FPS_DEBUG")) _ecore_fps_debug = 1;
+       if (_ecore_fps_debug) _ecore_fps_debug_init();
+       _ecore_signal_init();
+     }
 
    return _ecore_init_count;
 }
@@ -39,8 +45,8 @@
  * Shut down connections, signal handlers sockets etc.
  * 
  * This function shuts down all things set up in ecore_init() and cleans up all
- * event queues, handlers, filters, timers, idlers, idle enterers etc. set up
- * after ecore_init() was called.
+ * event queues, handlers, filters, timers, idlers, idle enterers/exiters
+ * etc. set up after ecore_init() was called.
  * 
  * Do not call this function from any callback that may be called from the main
  * loop, as the main loop will then fall over and not function properly.
@@ -51,8 +57,10 @@
    if (--_ecore_init_count)
       return _ecore_init_count;
 
+   if (_ecore_fps_debug) _ecore_fps_debug_shutdown();
    _ecore_exe_shutdown();
    _ecore_idle_enterer_shutdown();
+   _ecore_idle_exiter_shutdown();
    _ecore_idler_shutdown();
    _ecore_timer_shutdown();
    _ecore_event_shutdown();
@@ -107,6 +115,9 @@
       case ECORE_MAGIC_IDLE_ENTERER:
        return "Ecore_Idle_Enterer (Idler Enterer)";
        break;
+      case ECORE_MAGIC_IDLE_EXITER:
+       return "Ecore_Idle_Exiter (Idler Exiter)";
+       break;
       case ECORE_MAGIC_FD_HANDLER:
        return "Ecore_Fd_Handler (Fd Handler)";
        break;
@@ -121,3 +132,77 @@
      };
    return "<UNKNOWN>";
 }
+
+/* fps debug calls - for debugging how much time your app actually spends */
+/* "running" (and the inverse being time spent running)... this does not */
+/* account for other apps and multitasking... */
+
+static _ecore_fps_debug_init_count = 0;
+static int _ecore_fps_debug_fd = -1;
+unsigned int *_ecore_fps_runtime_mmap = NULL;
+
+void
+_ecore_fps_debug_init(void)
+{
+   char buf[4096];
+   
+   _ecore_fps_debug_init_count++;
+   if (_ecore_fps_debug_init_count > 1) return;
+   snprintf(buf, sizeof(buf), "/tmp/.ecore_fps_debug-%i", (int)getpid());
+   _ecore_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR);
+   if (_ecore_fps_debug_fd < 0)
+     {
+       unlink(buf);
+       _ecore_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR);
+     }
+   if (_ecore_fps_debug_fd >= 0)
+     {
+       unsigned int zero = 0;
+       
+       write(_ecore_fps_debug_fd, &zero, sizeof(unsigned int));
+       _ecore_fps_runtime_mmap = mmap(NULL, sizeof(unsigned int),
+                                      PROT_READ | PROT_WRITE,
+                                      MAP_SHARED,
+                                      _ecore_fps_debug_fd, 0);
+     }
+}
+
+void
+_ecore_fps_debug_shutdown(void)
+{
+   _ecore_fps_debug_init_count--;
+   if (_ecore_fps_debug_init_count > 0) return;
+   if (_ecore_fps_debug_fd >= 0)
+     {
+       char buf[4096];
+       
+       snprintf(buf, sizeof(buf), "/tmp/.ecore_fps_debug-%i", (int)getpid());
+       unlink(buf);
+       if (_ecore_fps_runtime_mmap)
+         {
+            munmap(_ecore_fps_runtime_mmap, sizeof(int));
+            _ecore_fps_runtime_mmap = NULL;
+         }
+       close(_ecore_fps_debug_fd);
+       _ecore_fps_debug_fd = -1;
+     }
+}
+
+void
+_ecore_fps_debug_runtime_add(double t)
+{
+   if ((_ecore_fps_debug_fd >= 0) && 
+       (_ecore_fps_runtime_mmap))
+     {
+       unsigned int tm;
+       
+       tm = (unsigned int)(t * 1000000.0);
+       /* i know its not 100% theoretically guaranteed, but i'd say a write */
+       /* of an int could be considered atomic for all practical purposes */
+       /* oh and since this is cumulative, 1 second = 1,000,000 ticks, so */
+       /* this can run for about 4294 seconds becore looping. if you are */
+       /* doing performance testing in one run for over an hour... well */
+       /* time to restart or handle a loop condition :) */
+       *(_ecore_fps_runtime_mmap) += tm;
+     }
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- ecore_main.c        25 Feb 2004 02:24:59 -0000      1.6
+++ ecore_main.c        17 Mar 2004 05:14:13 -0000      1.7
@@ -17,6 +17,9 @@
 static Ecore_Fd_Handler *fd_handlers = NULL;
 static int               fd_handlers_delete_me = 0;
 
+static double            t1 = 0.0;
+static double            t2 = 0.0;
+
 /**
  * Run 1 iteration of the main loop and process everything on the queue.
  * 
@@ -446,6 +449,12 @@
        return;
      }
    
+   if (_ecore_fps_debug)
+     {
+       t2 = ecore_time_get();
+       if ((t1 > 0.0) && (t2 > 0.0))
+         _ecore_fps_debug_runtime_add(t2 - t1);
+     }
    start_loop:
    /* init flags */
    have_event = have_signal = 0;
@@ -514,6 +523,13 @@
               }
          }
      }
+   if (_ecore_fps_debug)
+     {
+       t1 = ecore_time_get();
+     }
+   /* we came out of our "wait state" so idle has exited */
+   if (!once_only)
+     _ecore_idle_exiter_call();
    /* call the fd handler per fd that became alive... */
    /* this should read or write any data to the monitored fd and then */
    /* post events onto the ecore event pipe if necessary */
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_private.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ecore_private.h     24 Feb 2004 19:45:01 -0000      1.4
+++ ecore_private.h     17 Mar 2004 05:14:13 -0000      1.5
@@ -7,12 +7,17 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <signal.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
 
 #define ECORE_MAGIC_NONE            0x1234fedc
 #define ECORE_MAGIC_EXE             0xf7e812f5
 #define ECORE_MAGIC_TIMER           0xf7d713f4
 #define ECORE_MAGIC_IDLER           0xf7c614f3
 #define ECORE_MAGIC_IDLE_ENTERER    0xf7b515f2
+#define ECORE_MAGIC_IDLE_EXITER     0xf7601afd
 #define ECORE_MAGIC_FD_HANDLER      0xf7a416f1
 #define ECORE_MAGIC_EVENT_HANDLER   0xf79317f0
 #define ECORE_MAGIC_EVENT_FILTER    0xf78218ff
@@ -47,6 +52,7 @@
 typedef struct _Ecore_Timer         Ecore_Timer;
 typedef struct _Ecore_Idler         Ecore_Idler;
 typedef struct _Ecore_Idle_Enterer  Ecore_Idle_Enterer;
+typedef struct _Ecore_Idle_Exiter   Ecore_Idle_Exiter;
 typedef struct _Ecore_Fd_Handler    Ecore_Fd_Handler;
 typedef struct _Ecore_Event_Handler Ecore_Event_Handler;
 typedef struct _Ecore_Event_Filter  Ecore_Event_Filter;
@@ -90,6 +96,15 @@
    void        *data;
 };
 
+struct _Ecore_Idle_Exiter
+{
+   Ecore_List   __list_data;
+   ECORE_MAGIC;
+   int          delete_me : 1;
+   int        (*func) (void *data);   
+   void        *data;
+};
+
 struct _Ecore_Fd_Handler
 {
    Ecore_List               __list_data;
@@ -138,6 +153,7 @@
    void       (*func_free) (void *data, void *ev);
    void        *data;
 };
+
 #endif
 
 void          _ecore_magic_fail(void *d, Ecore_Magic m, Ecore_Magic req_m, const char 
*fname);
@@ -156,6 +172,10 @@
 void          _ecore_idle_enterer_call(void);
 int           _ecore_idle_enterer_exist(void);
 
+void          _ecore_idle_exiter_shutdown(void);
+void          _ecore_idle_exiter_call(void);
+int           _ecore_idle_exiter_exist(void);
+
 void          _ecore_event_shutdown(void);
 int           _ecore_event_exist(void);    
 Ecore_Event  *_ecore_event_add(int type, void *ev, void (*func_free) (void *data, 
void *ev), void *data);
@@ -191,4 +211,12 @@
 void         *_ecore_list_remove           (void *in_list, void *in_item);
 void         *_ecore_list_find             (void *in_list, void *in_item);
 
+void          _ecore_fps_debug_init(void);
+void          _ecore_fps_debug_shutdown(void);
+void          _ecore_fps_debug_runtime_add(double t);
+
+
+
+extern int    _ecore_fps_debug;
+
 #endif




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to