Re: What are the in-kernel functions to print human readable timestamps (bintime)?

From: Jamie Landeg-Jones <jamie_at_catflap.org>
Date: Fri, 11 Mar 2022 17:20:34 UTC
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