add fuctions to get low resolution time 92/179292/2
authorJeonghoon Park <jh1979.park@samsung.com>
Thu, 17 May 2018 04:11:01 +0000 (13:11 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Thu, 17 May 2018 04:56:46 +0000 (13:56 +0900)
Change-Id: Ia5056761239f5b0eb797cffdde63a05843354745

common/common-util.c
common/common-util.h
daemon/src/tizen-things-daemon.c
daemon/src/ttd-log.c

index dbb04c0..1f15fbe 100644 (file)
 
 #include <time.h>
 
+#ifndef CLOCK_REALTIME_COARSE
+#define CLOCK_REALTIME_COARSE CLOCK_REALTIME
+#endif
+
+#ifndef CLOCK_MONOTONIC_COARSE
+#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
+#endif
+
 unsigned long long common_get_monotonic_time(void)
 {
        struct timespec ts;
@@ -28,3 +36,54 @@ unsigned long long common_get_monotonic_time(void)
 
        return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
 }
+
+unsigned long long common_get_monotonic_coarse_time(void)
+{
+       struct timespec ts;
+       int result;
+
+       result = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
+
+       if (result != 0)
+               return 0;
+
+       return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
+}
+
+unsigned long long common_get_epoch_time(void)
+{
+       unsigned long long int ret_time = 0;
+       struct timespec time_s;
+
+       if (0 == clock_gettime(CLOCK_REALTIME, &time_s))
+               ret_time = time_s.tv_sec;
+
+       return ret_time;
+}
+
+unsigned long long common_get_epoch_coarse_time(void)
+{
+       unsigned long long int ret_time = 0;
+       struct timespec time_s;
+
+       if (0 == clock_gettime(CLOCK_REALTIME_COARSE, &time_s))
+               ret_time = time_s.tv_sec;
+
+       return ret_time;
+}
+
+int common_get_epoch_timespec(struct timespec *tp)
+{
+       if (!tp)
+               return -1;
+
+       return clock_gettime(CLOCK_REALTIME, tp);
+}
+
+int common_get_epoch_coarse_timespec(struct timespec *tp)
+{
+       if (!tp)
+               return -1;
+
+       return clock_gettime(CLOCK_REALTIME_COARSE, tp);
+}
index 62d7a31..f7c574c 100644 (file)
 #ifndef __TTD_COMMON_UTIL_H__
 #define __TTD_COMMON_UTIL_H__
 
+#include <time.h>
+
+#define EPOCH_TIME_REF 1526515200000000 /* 2018-05-17 GMT */
+
 unsigned long long common_get_monotonic_time(void);
+unsigned long long common_get_monotonic_coarse_time(void);
+
+unsigned long long common_get_epoch_time(void);
+unsigned long long common_get_epoch_coarse_time(void);
+int common_get_epoch_timespec(struct timespec *tp);
+int common_get_epoch_coarse_timespec(struct timespec *tp);
 
 #endif /* __TTD_COMMON_UTIL_H__ */
index e725d97..8d3665b 100644 (file)
@@ -28,6 +28,7 @@
 #include "ttd-parse-cmd.h"
 #include "ttd-worker-interface.h"
 #include "ttd-worker-handle.h"
+#include "common-util.h"
 
 #ifndef SERVER_URL
 /* TODO : remove it after test */
@@ -46,17 +47,12 @@ static gboolean __cloud_try_connect(gpointer data);
 
 static unsigned long long _get_monotonic_time(void)
 {
-       struct timespec ts;
-       int result;
-
-       result = clock_gettime(CLOCK_MONOTONIC, &ts);
-
-       if (result != 0) {
+       unsigned long long m_time = 0;
+       m_time  = common_get_monotonic_time();
+       if (m_time == 0)
                _E("failed to get monotonic time");
-               return 0;
-       }
 
-       return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
+       return m_time;
 }
 
 static const char *__ttd_get_cloud_url(void)
index 2652e7c..5019f57 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <glib.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -21,6 +22,7 @@
 #include <dlog.h>
 #include <tzplatform_config.h>
 #include "ttd-log.h"
+#include "common-util.h"
 
 static FILE *log_fp = NULL;
 static log_type ltype = LOG_TYPE_DLOG;
@@ -43,11 +45,14 @@ static inline char* getFormattedTime(void)
        struct tm *ptm;
        static char res_time[40] = {0, };
 
-       if (0 == clock_gettime(CLOCK_REALTIME, &time_s)) {
+       time_s.tv_sec = 0;
+       time_s.tv_nsec = 0;
+
+       if (0 == common_get_epoch_coarse_timespec(&time_s)) {
                ptm = localtime((const time_t *)&time_s.tv_sec);
 
                // format : YY-MM-DD hh:mm:ss:uuuuuu
-               snprintf(res_time, sizeof(res_time),
+               g_snprintf(res_time, sizeof(res_time),
                        "%04d-%02d-%02d %02d:%02d:%02d:%06ld"
                        , ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday
                        , ptm->tm_hour, ptm->tm_min, ptm->tm_sec