Re: kern.msgbuf_show_timestamp=1

Jamie Landeg-Jones <[email protected]>
Newsgroups gmane.os.freebsd.stable
Organization Dyslexic Fish
Message-ID <[email protected]>
void <[email protected]> wrote:

> Hi,
>
> In /etc/sysctl.conf I have
>
> kern.msgbuf_show_timestamp=1
>
> and so dmsg has things like
>
> [1353919] swp_pager_getswapspace(32): failed
>
> the [1353919] I guess being the timestamp.
>
> But what is it?
>
> Seconds since boot?
>
> If it's that, then where can the true boot time be 
> found?

Yes! You can get the value from sysctl kern.boottime.

Here is a small program I wrote a while back, just call it
as a dmesg substitute.

It uses gawk because of strftime, but now that native awk handles strftime,
it could be converted to use that (gensub will have to be modified)

gawk is in lang/gawk

Incidentally, if you put the kern.msgbuf_show_timestamp=1
in boot/loader.conf instead, it starts much earlier in the boot process,
useful if you are anal about the format of bootup dmesg output!

Cheers, Jamie

#!/bin/sh -efu
set -efu

boottime="$(/sbin/sysctl -n kern.boottime | /usr/local/bin/gawk '{printf "%d", gensub ("^.* sec = ([1-9][0-9]*), .*$", "\\1", 1)}')"

[ -z "$(printf '%s' "$boottime" | /usr/bin/egrep '^0$|^[1-9][0-9]*$')" ] && { printf 'Invalid boottime retrieved.\n' >& 2; exit 1; }

/sbin/dmesg "$@" | /usr/local/bin/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
    }'
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.