aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-03-17 10:21:15 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-03-18 21:54:37 +0100
commitb61b2ca1a0c63d99c642fe46b0bfef83eb092ba1 (patch)
tree7ddb66573b9662dae7ab52f7d8918773bd0af561 /src
parent4dafdefa7adaea9ca10b357ed966fdcd183347df (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/logging.c11
1 files changed, 7 insertions, 4 deletions
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 <strings.h>
#endif
#include <time.h>
+#include <sys/time.h>
#include <errno.h>
#include <osmocom/core/talloc.h>
@@ -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);