shared: fix incorrect timestamps 22/198322/3
authorMichal Bloch <m.bloch@samsung.com>
Wed, 23 Jan 2019 19:22:01 +0000 (20:22 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 24 Jan 2019 11:32:15 +0000 (11:32 +0000)
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 <m.bloch@samsung.com>
include/queued_entry.h
src/shared/logprint.c

index 449660d..8192864 100644 (file)
@@ -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 */
index 72dc33c..3980c1c 100644 (file)
@@ -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;