From 306c587fec093501cd537c72eb22096aa5ea37a5 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 22 Jan 2018 20:29:43 +0900 Subject: [PATCH] log: add monotonic time logs Change-Id: If220dfb11bf82ead8a2aa89ed307543231004165 --- include/tdm_log.h | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/include/tdm_log.h b/include/tdm_log.h index e43a4af..d402a99 100644 --- a/include/tdm_log.h +++ b/include/tdm_log.h @@ -38,6 +38,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -70,17 +71,37 @@ void tdm_log_set_debug_level(int level); void tdm_log_print(int level, const char *fmt, ...); #define TDM_DBG(fmt, args...) \ - tdm_log_print(TDM_LOG_LEVEL_DBG, "[%d][%s %d]"fmt"\n", \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args) + do { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } while (0) #define TDM_INFO(fmt, args...) \ - tdm_log_print(TDM_LOG_LEVEL_INFO, "[%d][%s %d]"fmt"\n", \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args) + do { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } while (0) #define TDM_WRN(fmt, args...) \ - tdm_log_print(TDM_LOG_LEVEL_WRN, "[%d][%s %d]"fmt"\n", \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args) + do { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } while (0) #define TDM_ERR(fmt, args...) \ - tdm_log_print(TDM_LOG_LEVEL_ERR, "[%d][%s %d]"fmt"\n", \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args) + do { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } while (0) #ifdef __cplusplus } -- 2.7.4