From 1361e20cdf30bf38c248484cd0cdd32c668b7171 Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Wed, 23 Jan 2019 20:22:01 +0100 Subject: [PATCH] shared: fix incorrect timestamps The RECV_REALTIME and RWTIME formats would print an incorrect timestamp when used alongside default-monotonic log sources. Change-Id: I0a67f35a60b77052528349d88b11f905a7afcb50 Signed-off-by: Michal Bloch --- include/queued_entry.h | 3 +++ src/shared/logprint.c | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/queued_entry.h b/include/queued_entry.h index 449660d..8192864 100644 --- a/include/queued_entry.h +++ b/include/queued_entry.h @@ -44,6 +44,9 @@ enum { #define ENTRY_SENT_SEC(e) (((e)->default_send_ts_type == LOGGER_ENTRY_REALTIME) ? (e)->sec_sent_real : (e)->sec_sent_mono) #define ENTRY_SENT_NSEC(e) (((e)->default_send_ts_type == LOGGER_ENTRY_REALTIME) ? (e)->nsec_sent_real : (e)->nsec_sent_mono) +#define ENTRY_RECV_SEC(e) (((e)->default_send_ts_type == LOGGER_ENTRY_REALTIME) ? (e)->sec_recv_real : (e)->sec_recv_mono) +#define ENTRY_RECV_NSEC(e) (((e)->default_send_ts_type == LOGGER_ENTRY_REALTIME) ? (e)->nsec_recv_real : (e)->nsec_recv_mono) + struct logger_entry { uint16_t len; /* length of the payload */ diff --git a/src/shared/logprint.c b/src/shared/logprint.c index 72dc33c..3980c1c 100644 --- a/src/shared/logprint.c +++ b/src/shared/logprint.c @@ -671,6 +671,10 @@ char *log_format_log_line( sec_sent = ENTRY_SENT_SEC(entry); nsec_sent = ENTRY_SENT_NSEC(entry); + long int sec_recv, nsec_recv; + sec_recv = ENTRY_RECV_SEC(entry); + nsec_recv = ENTRY_RECV_NSEC(entry); + time_t_temp = sec_sent; #if defined(HAVE_LOCALTIME_R) ptm = localtime_r((const time_t*)&time_t_temp, &tmBuf); @@ -681,7 +685,7 @@ char *log_format_log_line( return NULL; strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm); - time_t_temp = (time_t)entry->sec_recv_real; + time_t_temp = sec_recv; #if defined(HAVE_LOCALTIME_R) ptm = localtime_r((const time_t*)&time_t_temp, &tmBuf); #else @@ -749,7 +753,7 @@ char *log_format_log_line( case FORMAT_RECV_REALTIME: prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%s.%03ld %c/%-8s(P%5d, T%5d): ", - recvTimeBuf, (long int)entry->nsec_recv_real / 1000000, + recvTimeBuf, nsec_recv / 1000000, priChar, tag, (int)entry->pid, (int)entry->tid); strncpy(suffixBuf, "\n", 2); suffixLen = 1; @@ -757,7 +761,7 @@ char *log_format_log_line( case FORMAT_RWTIME: prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "%s [%5lu.%03ld] %c/%-8s(P%5d, T%5d): ", - recvTimeBuf, (long int)entry->sec_recv_real, (long int)entry->nsec_recv_real / 1000000, + recvTimeBuf, sec_recv, nsec_recv / 1000000, priChar, tag, (int)entry->pid, (int)entry->tid); strncpy(suffixBuf, "\n", 2); suffixLen = 1; -- 2.7.4