From 45ae223ac654c0ab6cdc4eaacca693244802383e Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 6 May 2022 11:31:18 -0600 Subject: msgbuf: Allow microsecond granularity timestamps Today, kern.msgbuf_show_timestamp=1 will give 1 second granularity timestamps on dmesg lines. When kern.msgbuf_show_timestamp=2, we'll produce microsecond level graunlarity. For example: old (== 1): [13] Dual Console: Video Primary, Serial Secondary [14] lo0: link state changed to UP [15] bxe0: NIC Link is Up, 10000 Mbps full duplex, Flow control: ON - receive & transmit [15] bxe0: link state changed to UP new (== 2): [13.807015] Dual Console: Video Primary, Serial Secondary [14.544150] lo0: link state changed to UP [15.272044] bxe0: NIC Link is Up, 10000 Mbps full duplex, Flow control: ON - receive & transmit [15.272052] bxe0: link state changed to UP Sponsored by: Netflix --- sys/kern/subr_msgbuf.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sys') diff --git a/sys/kern/subr_msgbuf.c b/sys/kern/subr_msgbuf.c index b41e78dd886e..4664e742c5fb 100644 --- a/sys/kern/subr_msgbuf.c +++ b/sys/kern/subr_msgbuf.c @@ -234,8 +234,16 @@ msgbuf_addstr(struct msgbuf *mbp, int pri, const char *str, int filter_cr) if (msgbuf_show_timestamp && needtime == 1 && (mbp->msg_flags & MSGBUF_NEEDNL) == 0) { - snprintf(buf, sizeof(buf), "[%jd] ", - (intmax_t)time_uptime); + if (msgbuf_show_timestamp == 1) { + snprintf(buf, sizeof(buf), "[%jd] ", + (intmax_t)time_uptime); + } else { + struct timeval tv; + + microuptime(&tv); + snprintf(buf, sizeof(buf), "[%jd.%06d] ", + (intmax_t)tv.tv_sec, (int)tv.tv_usec); + } for (j = 0; buf[j] != '\0'; j++) msgbuf_do_addchar(mbp, buf[j]); needtime = 0; -- cgit v1.3