From 1056f1bff420657e491dc7777f5713d55108be10 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 26 Sep 2013 11:18:00 +0900 Subject: [PATCH] Replace gettimeofday with clock_get_time Change-Id: I8ef773a50f011a87223738c9b45d4239172a0289 --- CMakeLists.txt | 1 + packaging/liblivebox-viewer.spec | 2 +- src/critical_log.c | 8 +++++++- src/util.c | 28 +++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa1ec0e..0933a34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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\"") diff --git a/packaging/liblivebox-viewer.spec b/packaging/liblivebox-viewer.spec index 2e5f95b..ec545be 100644 --- a/packaging/liblivebox-viewer.spec +++ b/packaging/liblivebox-viewer.spec @@ -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 diff --git a/src/critical_log.c b/src/critical_log.c index 07bb71d..12fd8a1 100644 --- a/src/critical_log.c +++ b/src/critical_log.c @@ -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); diff --git a/src/util.c b/src/util.c index cdafb4f..c58b4f2 100644 --- a/src/util.c +++ b/src/util.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include /* For error code */ @@ -28,6 +29,13 @@ #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) -- 2.7.4