Date: Fri, 11 Mar 2022 17:20:34 +0000 From: Jamie Landeg-Jones <jamie@catflap.org> To: imp@bsdimp.com, Alexander@leidinger.net Cc: current@FreeBSD.org Subject: Re: What are the in-kernel functions to print human readable timestamps (bintime)? Message-ID: <202203111720.22BHKYOY085155@donotpassgo.dyslexicfish.net> In-Reply-To: <CANCZdfoEOY6%2BokeVJLDwTF5qXxwYs-Wupn6o6JvH-OAO3oj=JQ@mail.gmail.com> References: <20220311105149.Horde.uO0yyQjwC3xmwZvuZWV1ADl@webmail.leidinger.net> <CANCZdfoEOY6%2BokeVJLDwTF5qXxwYs-Wupn6o6JvH-OAO3oj=JQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Warner Losh <imp@bsdimp.com> wrote: > since we already add stuff to what's printed for the priority. We could say > <3,seconds-since-boot.fracsec> instead of just <3> and hack dmesg > to print the right thing. Isn't that what kern.msgbuf_show_timestamp does already? I use that, along with this script: 17:15 (40.0°C 400) [2] (49) "completions" root@thompson# cat /usr/common/bin/dmesg-uptime-to-date #!/bin/sh -efu set -efu boottime="$(sysctl -n kern.boottime | gawk '{printf "%d", gensub ("^.* sec = ([1-9][0-9]*), .*$", "\\1", 1)}')" [ -z "$(printf '%s' "$boottime" | egrep '^0$|^[1-9][0-9]*$')" ] && { printf 'Invalid boottime retrieved.\n' >& 2; exit 1; } dmesg "$@" | gawk -v boottime="$boottime" ' { uptime = gensub ("^\\[([1-9][0-9]*)\\] .*$", "\\1", 1) if (uptime == $0) realtime = "??? ?? ??:??;??" else realtime = strftime ("%b %d %T", uptime + boottime) print realtime " " $0 }' Mar 11 00:41:51 [3568757] Limiting closed port RST response from 313 to 200 packets/sec Mar 11 00:41:54 [3568760] Limiting closed port RST response from 308 to 200 packets/sec Mar 11 06:23:28 [3589254] icmp redirect from 183.196.23.176: 192.168.2.104 => 183.196.23.161 etc. Cheers, Jamie
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202203111720.22BHKYOY085155>