Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

src: Allow the precision of the sub-second field of timestamps to



details:   https://anonhg.NetBSD.org/src/rev/ceeacf817838
branches:  trunk
changeset: 318152:ceeacf817838
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Apr 14 01:45:37 2018 +0000
description:
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...)

diffstat:

 sys/kern/subr_prf.c |  31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diffs (72 lines):

diff -r cfe6a279287f -r ceeacf817838 sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c       Sat Apr 14 01:37:34 2018 +0000
+++ b/sys/kern/subr_prf.c       Sat Apr 14 01:45:37 2018 +0000
@@ -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 @@
 
 #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 @@
        }
 
 #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);
 



Home | Main Index | Thread Index | Old Index