Replace gettimeofday with clock_get_time
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 02:18:00 +0000 (11:18 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 02:18:00 +0000 (11:18 +0900)
Change-Id: I8ef773a50f011a87223738c9b45d4239172a0289

CMakeLists.txt
packaging/liblivebox-viewer.spec
src/critical_log.c
src/util.c

index fa1ec0e..0933a34 100644 (file)
@@ -39,6 +39,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"LIVEBOX_VIEWER\"")
 ADD_DEFINITIONS("-DNDEBUG")
+ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
 #ADD_DEFINITIONS("-DFLOG")
 ADD_DEFINITIONS("-DMASTER_PKGNAME=\"data-provider-master\"")
 ADD_DEFINITIONS("-DINFO_SOCKET=\"/opt/usr/share/live_magazine/.live.socket\"")
index 2e5f95b..ec545be 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for developing the application.
-Version: 0.14.3
+Version: 0.14.4
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index 07bb71d..12fd8a1 100644 (file)
@@ -50,14 +50,20 @@ int critical_log(const char *func, int line, const char *fmt, ...)
 {
        va_list ap;
        int ret;
-       struct timeval tv;
 
        if (!s_info.fp) {
                return LB_STATUS_ERROR_IO;
        }
 
+#if defined(_USE_ECORE_TIME_GET)
+       double tv;
+       tv = util_timestamp();
+       fprintf(s_info.fp, "%d %lf [%s:%d] ", getpid(), tv, util_basename((char *)func), line);
+#else
+       struct timeval tv;
        gettimeofday(&tv, NULL);
        fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, util_basename((char *)func), line);
+#endif
 
        va_start(ap, fmt);
        ret = vfprintf(s_info.fp, fmt, ap);
index cdafb4f..c58b4f2 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/time.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <time.h>
 
 #include <dlog.h>
 #include <livebox-errno.h> /* For error code */
 #include "util.h"
 
 int errno;
+#if defined(_USE_ECORE_TIME_GET)
+static struct {
+       clockid_t type;
+} s_info = {
+       .type = CLOCK_MONOTONIC,
+};
+#endif
 
 int util_check_extension(const char *filename, const char *check_ptr)
 {
@@ -47,11 +55,29 @@ int util_check_extension(const char *filename, const char *check_ptr)
 
 double util_timestamp(void)
 {
+#if defined(_USE_ECORE_TIME_GET)
+       struct timespec ts;
+
+       do {
+               if (clock_gettime(s_info.type, &ts) == 0) {
+                       return ts.tv_sec + ts.tv_nsec / 1000000000.0f;
+               }
+
+               ErrPrint("%d: %s\n", s_info.type, strerror(errno));
+               if (s_info.type == CLOCK_MONOTONIC) {
+                       s_info.type = CLOCK_REALTIME;
+               } else if (s_info.type == CLOCK_REALTIME) {
+                       break;
+               }
+       } while (1);
+
+       return 0.0f;
+#else
        struct timeval tv;
 
        gettimeofday(&tv, NULL);
-
        return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+#endif
 }
 
 const char *util_basename(const char *name)