#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;
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);
+}
#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__ */
#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 */
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)
* limitations under the License.
*/
+#include <glib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#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;
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