Module Name: src
Committed By: kre
Date: Sat Apr 14 01:45:37 UTC 2018
Modified Files:
src/sys/kern: subr_prf.c
Log Message:
Allow the precision of the sub-second field of timestamps to
be controlled - for now that is done by editing this file and
recompiling (or using gdb or equiv to patch /netbsd or /dev/kmem)
but adding a sysctl to allow dynamic userland control should be easy.
Also reduce the initial seconds field width of timestamp from 5 to 4
(it grows wider as needed.)
Avoid printing timestamps if we cannot be sure there will be
a message to accompany them. (Observed happening...)
To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/kern/subr_prf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_prf.c
diff -u src/sys/kern/subr_prf.c:1.168 src/sys/kern/subr_prf.c:1.169
--- src/sys/kern/subr_prf.c:1.168 Fri Apr 13 09:21:16 2018
+++ src/sys/kern/subr_prf.c Sat Apr 14 01:45:37 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prf.c,v 1.168 2018/04/13 09:21:16 christos Exp $ */
+/* $NetBSD: subr_prf.c,v 1.169 2018/04/14 01:45:37 kre Exp $ */
/*-
* Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.168 2018/04/13 09:21:16 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.169 2018/04/14 01:45:37 kre Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -484,17 +484,34 @@ putlogpri(int level)
#ifndef KLOG_NOTIMESTAMP
static int needtstamp = 1;
+int log_ts_prec = 9;
static void
addtstamp(int flags, struct tty *tp)
{
char buf[64];
struct timespec ts;
- int n;
+ int n, prec;
+ long fsec;
+
+ prec = log_ts_prec;
+ if (prec < 0) {
+ prec = 0;
+ log_ts_prec = prec;
+ } else if (prec > 9) {
+ prec = 9;
+ log_ts_prec = prec;
+ }
getnanouptime(&ts);
- n = snprintf(buf, sizeof(buf), "[% 5jd.%.9ld] ",
- (intmax_t)ts.tv_sec, ts.tv_nsec);
+
+ for (n = prec, fsec = ts.tv_nsec; n < 8; n++)
+ fsec /= 10;
+ if (n < 9)
+ fsec = (fsec / 10) + ((fsec % 10) >= 5);
+
+ n = snprintf(buf, sizeof(buf), "[% 4jd.%.*ld] ",
+ (intmax_t)ts.tv_sec, prec, fsec);
for (int i = 0; i < n; i++)
putone(buf[i], flags, tp);
@@ -517,13 +534,13 @@ putchar(int c, int flags, struct tty *tp
}
#ifndef KLOG_NOTIMESTAMP
- if (needtstamp) {
+ if (c != '\0' && c != '\n' && needtstamp) {
addtstamp(flags, tp);
needtstamp = 0;
}
if (c == '\n')
- needtstamp++;
+ needtstamp = 1;
#endif
putone(c, flags, tp);