raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=8dd44c13c8d69e75121a5efb7254c7008322b877

commit 8dd44c13c8d69e75121a5efb7254c7008322b877
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Mon Oct 12 21:42:18 2015 +0900

    eina evlog - use CORRECT clock (monotonic) not gettimeofday if possible
---
 src/lib/eina/eina_evlog.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/lib/eina/eina_evlog.c b/src/lib/eina/eina_evlog.c
index 75a377c..de9ecf1 100644
--- a/src/lib/eina/eina_evlog.c
+++ b/src/lib/eina/eina_evlog.c
@@ -26,6 +26,16 @@
 
 #ifdef EINA_HAVE_DEBUG
 
+#ifdef HAVE_EVIL
+# include <Evil.h>
+#endif
+
+#if defined(__APPLE__) && defined(__MACH__)
+# include <mach/mach_time.h>
+#endif
+
+#include <time.h>
+
 # ifdef HAVE_MMAP
 #  include <sys/mman.h>
 # endif
@@ -38,12 +48,42 @@ static int             _evlog_go = 0;
 static Eina_Evlog_Buf *buf; // current event log we are writing events to
 static Eina_Evlog_Buf  buffers[2]; // double-buffer our event log buffers
 
+#if defined (HAVE_CLOCK_GETTIME) || defined (EXOTIC_PROVIDE_CLOCK_GETTIME)
+static clockid_t _eina_evlog_time_clock_id = -1;
+#elif defined(__APPLE__) && defined(__MACH__)
+static double _eina_evlog_time_clock_conversion = 1e-9;
+#endif
+
 static inline double
 get_time(void)
 {
+#if defined (HAVE_CLOCK_GETTIME) || defined (EXOTIC_PROVIDE_CLOCK_GETTIME)
+   struct timespec t;
+
+   if (EINA_UNLIKELY(_eina_evlog_time_clock_id < 0))
+     {
+        if (!clock_gettime(CLOCK_MONOTONIC, &t))
+          _eina_evlog_time_clock_id = CLOCK_MONOTONIC;
+        else
+          _eina_evlog_time_clock_id = CLOCK_REALTIME;
+     }
+
+   if (EINA_UNLIKELY(clock_gettime(_eina_evlog_time_clock_id, &t)))
+     {
+        struct timeval timev;
+        gettimeofday(&timev, NULL);
+        return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000.0);
+     }
+   return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0);
+#elif defined(HAVE_EVIL)
+   return evil_time_get();
+#elif defined(__APPLE__) && defined(__MACH__)
+   return _eina_evlog_time_clock_conversion * (double)mach_absolute_time();
+#else
    struct timeval timev;
    gettimeofday(&timev, NULL);
    return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000.0);
+#endif
 }
 
 static void

-- 


Reply via email to