From b61b2ca1a0c63d99c642fe46b0bfef83eb092ba1 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 17 Mar 2015 10:21:15 +0100 Subject: logging: Implement subsecond resolution of extended timestamps Currently when using 'logging print extended-timestamp 1', the subsecond part (milliseconds) of the printed timestamp is always 0. This makes it difficult to correlate log entries with PCAP file entries if there are many of them per second. This patch changes _output in logging.c to use gettimeofday() instead of time() when extended timestamps are enabled and replaces the '000' by the milliseconds computed from tv_usec. Sponsored-by: On-Waves ehf --- src/logging.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/logging.c b/src/logging.c index c007a45f..20b0596b 100644 --- a/src/logging.c +++ b/src/logging.c @@ -38,6 +38,7 @@ #include #endif #include +#include #include #include @@ -254,11 +255,13 @@ static void _output(struct log_target *target, unsigned int subsys, if (!cont) { if (target->print_ext_timestamp) { struct tm tm; - time_t timep = time(NULL); - localtime_r(&timep, &tm); - ret = snprintf(buf + offset, rem, "%04d%02d%02d%02d%02d%02d000 ", + struct timeval tv; + gettimeofday(&tv, NULL); + localtime_r(&tv.tv_sec, &tm); + ret = snprintf(buf + offset, rem, "%04d%02d%02d%02d%02d%02d%03d ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + tm.tm_hour, tm.tm_min, tm.tm_sec, + (int)(tv.tv_usec / 1000)); if (ret < 0) goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); -- cgit v1.2.3