From 6bf6e2ea4867f34368acef7034b22de0d8382a85 Mon Sep 17 00:00:00 2001 From: Dennis Boone Date: Tue, 23 Jun 2020 17:15:35 -0400 Subject: [PATCH] Nanosecond log resolution for SMLC debug log Using clock_gettime(), fetch the realtime clock, which has as much as nanosecond resolution. (In reality, it will likely ben more like microseconds, though it returns the value in nanoseconds.) Use the nanosecond value in SMLC log entries. On modern systems and over ethernet links, second resolution is probably fairly coarse for trying to debug RJE problems. --- devsmlc.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/devsmlc.h b/devsmlc.h index abf35ef..527dc4a 100644 --- a/devsmlc.h +++ b/devsmlc.h @@ -49,6 +49,7 @@ */ #include +#include #define SMLC_DEVICEID 0050 /* HSSMLC/MDLC is '50, SMLC is '56 */ @@ -126,7 +127,7 @@ static void smlclogflush(void); static FILE *smlclog = NULL; static char smlclogbuf[LogLineLength + 1]; static int smlclogbytescol = 0; -static char smlctimestamp[10]; +static char smlctimestamp[20]; #endif /* connection states */ @@ -285,12 +286,14 @@ int devsmlc (int class, int func, int device) { fd_set writefds; #if DEBUG struct tm *tp; + struct timespec sts; #endif currenttime = time(0); #if DEBUG tp = localtime(¤ttime); - sprintf(smlctimestamp, "%02d:%02d:%02d", tp->tm_hour, tp->tm_min, tp->tm_sec); + clock_gettime(CLOCK_REALTIME, &sts); + sprintf(smlctimestamp, "%02d:%02d:%02d.%09d", tp->tm_hour, tp->tm_min, tp->tm_sec, sts.tv_nsec); #endif switch (device) {