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?
Hi,
In /etc/sysctl.conf I have
kern.msgbuf_show_timestamp=3D1
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?
If not, then what does the number signify?
--
void <void@f-m.fm> wrote:e,
Hi,
In /etc/sysctl.conf I have
kern.msgbuf_show_timestamp=3D1
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 strftim=
it could be converted to use that (gensub will have to be modified)f
gawk is in lang/gawk
Incidentally, if you put the kern.msgbuf_show_timestamp=3D1
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=3D"$(/sbin/sysctl -n kern.boottime | /usr/local/bin/gawk '{print=
"%d", gensub ("^.* sec =3D ([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=3D"$boottime" '
{
uptime =3D gensub ("^\\[([1-9][0-9]*)\\] .*$", "\\1", 1)
if (uptime =3D=3D $0) realtime =3D "??? ?? ??:??;??"
else realtime =3D strftime ("%b %d %T", uptime + boottime)
print realtime " " $0
}'
Very cool!
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.
void <void@f-m.fm> wrote:
...
and so dmsg has things like
[1353919] swp_pager_getswapspace(32): failed
the [1353919] I guess being the timestamp.
...
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.
...
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
}'
FWIW, this is a patch for dmesg(1) I use. You can enable timestamp
conversion using -t and optionally specify a different output format
using -f "fmt".
If interested for inclusion in base, I could try to re-format it
and come up with a manpage diff...
--- sbin/dmesg/dmesg.c 2023-12-27 17:49:57.000000000 +0100
+++ sbin/dmesg/dmesg.c 2026-01-22 09:20:28.987020000 +0100
@@ -60,6 +60,7 @@
#include <unistd.h>
#include <vis.h>
#include <sys/syslog.h>
+#include <time.h>
static struct nlist nl[] = {
#define X_MSGBUF 0
@@ -76,18 +77,23 @@
main(int argc, char *argv[])
{
struct msgbuf *bufp, cur;
+ struct timeval boottime;
+ char timebuf[64];
char *bp, *ep, *memf, *nextp, *nlistf, *p, *q, *visbp;
+ const char *timefmt = "%d %b %T";
kvm_t *kd;
+ time_t time;
size_t buflen, bufpos;
long pri;
- int ch, clear;
+ int ch, clear, timeconv;
bool all;
all = false;
clear = false;
+ timeconv = false;
(void) setlocale(LC_CTYPE, "");
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "acM:N:")) != -1)
+ while ((ch = getopt(argc, argv, "actf:M:N:")) != -1)
switch(ch) {
case 'a':
all = true;
@@ -95,6 +101,12 @@
case 'c':
clear = true;
break;
+ case 't':
+ timeconv = true;
+ break;
+ case 'f':
+ timefmt = optarg;
+ break;
case 'M':
memf = optarg;
break;
@@ -109,6 +121,13 @@
if (argc != 0)
usage();
+ if( timeconv ) {
+ int mib[6] = { CTL_KERN, KERN_BOOTTIME };
+ size_t l = sizeof boottime;
+ if (sysctl(mib, 2, &boottime, &l, 0, 0) < 0)
+ err(1, "sysctl kern.boottime");
+ }
+
if (memf == NULL) {
/*
* Running kernel. Use sysctl. This gives an unwrapped buffer @@ -200,7 +219,22 @@
}
(void)strvisx(visbp, p, nextp - p, 0);
- (void)printf("%s", visbp);
+ bufpos = strspn( visbp+1, "0123456789" ) + 1;
+ if( timeconv != true
+ || bufpos < 2
+ || visbp[0] != '['
+ || visbp[bufpos] != ']'
+ || visbp[bufpos+1] != ' ' ) {
+ (void)printf("%s", visbp);
+ continue;
+ }
+
+ visbp[bufpos] = '\0';
+ time = boottime.tv_sec + strtoull( visbp+1, NULL, 10 );
+ if( strftime( timebuf, sizeof timebuf, timefmt, localtime( &time ) ) != 0 )
+ (void)printf( "[%s]%s", timebuf, visbp + bufpos + 1 ); + else
+ (void)printf("%s", visbp);
}
exit(0);
}
@@ -208,6 +242,6 @@
void
usage(void)
{
- fprintf(stderr, "usage: dmesg [-ac] [-M core [-N system]]\n");
+ fprintf(stderr, "usage: dmesg [-ac] [-t [-f output_fmt]] [-M core [-N system]]\n");
exit(1);
}
-Andre
FWIW, this is a patch for dmesg(1) I use. You can enable timestamp
conversion using -t and optionally specify a different output format
using -f "fmt".
If interested for inclusion in base, I could try to re-format it
and come up with a manpage diff...
On 01/22/2026 2:46 AM CST Andre Albsmeier <mail@fbsd2.e4m.org>
FWIW, this is a patch for dmesg(1) I use. You can enable timestamp
conversion using -t and optionally specify a different output format
using -f "fmt".
If interested for inclusion in base, I could try to re-format it
and come up with a manpage diff...
wrote:ntf
On Fri, 19-Dec-2025 at 20:37:41 +0000, Jamie Landeg-Jones wrote:
void <void@f-m.fm> wrote:
...
and so dmsg has things like
[1353919] swp_pager_getswapspace(32): failed
the [1353919] I guess being the timestamp.
...
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.
...
Cheers, Jamie
#!/bin/sh -efu
set -efu
boottime=3D"$(/sbin/sysctl -n kern.boottime | /usr/local/bin/gawk '{pri=
"%d", gensub ("^.* sec =3D ([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=3D"$boottime" '
{
uptime =3D gensub ("^\\[([1-9][0-9]*)\\] .*$", "\\1", 1)
if (uptime =3D=3D $0) realtime =3D "??? ?? ??:??;??"
else realtime =3D strftime ("%b %d %T", uptime + boottime)
print realtime " " $0
}'
FWIW, this is a patch for dmesg(1) I use. You can enable timestamp
conversion using -t and optionally specify a different output format
using -f "fmt".
If interested for inclusion in base, I could try to re-format it
and come up with a manpage diff...
--- sbin/dmesg/dmesg.c 2023-12-27 17:49:57.000000000 +0100
+++ sbin/dmesg/dmesg.c 2026-01-22 09:20:28.987020000 +0100
@@ -60,6 +60,7 @@
#include <unistd.h>
#include <vis.h>
#include <sys/syslog.h>
+#include <time.h>
static struct nlist nl[] =3D {
#define X_MSGBUF 0
@@ -76,18 +77,23 @@
main(int argc, char *argv[])
{
struct msgbuf *bufp, cur;
+ struct timeval boottime;
+ char timebuf[64];
char *bp, *ep, *memf, *nextp, *nlistf, *p, *q, *visbp;
+ const char *timefmt =3D "%d %b %T";
kvm_t *kd;
+ time_t time;
size_t buflen, bufpos;
long pri;
- int ch, clear;
+ int ch, clear, timeconv;
bool all;
all =3D false;
clear =3D false;
+ timeconv =3D false;
(void) setlocale(LC_CTYPE, "");
memf =3D nlistf =3D NULL;
- while ((ch =3D getopt(argc, argv, "acM:N:")) !=3D -1)
+ while ((ch =3D getopt(argc, argv, "actf:M:N:")) !=3D -1)
switch(ch) {
case 'a':
all =3D true;
@@ -95,6 +101,12 @@
case 'c':
clear =3D true;
break;
+ case 't':
+ timeconv =3D true;
+ break;
+ case 'f':
+ timefmt =3D optarg;
+ break;
case 'M':
memf =3D optarg;
break;
@@ -109,6 +121,13 @@
if (argc !=3D 0)
usage();
+ if( timeconv ) {
+ int mib[6] =3D { CTL_KERN, KERN_BOOTTIME };
+ size_t l =3D sizeof boottime;
+ if (sysctl(mib, 2, &boottime, &l, 0, 0) < 0)
+ err(1, "sysctl kern.boottime");
+ }
+
if (memf =3D=3D NULL) {
/*
* Running kernel. Use sysctl. This gives an unwrapped buffer
@@ -200,7 +219,22 @@
}
(void)strvisx(visbp, p, nextp - p, 0);
- (void)printf("%s", visbp);
+ bufpos =3D strspn( visbp+1, "0123456789" ) + 1;
+ if( timeconv !=3D true(
+ || bufpos < 2
+ || visbp[0] !=3D '['
+ || visbp[bufpos] !=3D ']'
+ || visbp[bufpos+1] !=3D ' ' ) {
+ (void)printf("%s", visbp);
+ continue;
+ }
+
+ visbp[bufpos] =3D '\0';
+ time =3D boottime.tv_sec + strtoull( visbp+1, NULL, 10 );
+ if( strftime( timebuf, sizeof timebuf, timefmt, localtime=
&time ) ) !=3D 0 )
+ (void)printf( "[%s]%s", timebuf, visbp + bufpos +
1 );
+ else
+ (void)printf("%s", visbp);
}
exit(0);
}
@@ -208,6 +242,6 @@
void
usage(void)
{
- fprintf(stderr, "usage: dmesg [-ac] [-M core [-N system]]\n");
+ fprintf(stderr, "usage: dmesg [-ac] [-t [-f output_fmt]] [-M core
[-N system]]\n");
exit(1);
}
-Andre
FWIW, this is a patch for dmesg(1) I use. You can enable timestamp
conversion using -t and optionally specify a different output format
using -f "fmt".
If interested for inclusion in base, I could try to re-format it
and come up with a manpage diff...
On Fri, 23 Jan 2026 09:40:17 +01004m.org>
Andre Albsmeier <mail@fbsd2.e4m.org> wrote:
On Thu, 22-Jan-2026 at 08:31:15 -0700, Warner Losh wrote:
On Thu, Jan 22, 2026 at 1:46=E2=80=AFAM Andre Albsmeier <mail@fbsd2.e=
wrote:'
On Fri, 19-Dec-2025 at 20:37:41 +0000, Jamie Landeg-Jones wrote:
void <void@f-m.fm> wrote:
...
and so dmsg has things like
[1353919] swp_pager_getswapspace(32): failed
the [1353919] I guess being the timestamp.
...
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.
...
Cheers, Jamie
#!/bin/sh -efu
set -efu
'{printfboottime=3D"$(/sbin/sysctl -n kern.boottime | /usr/local/bin/gawk
"%d", gensub ("^.* sec =3D ([1-9][0-9]*), .*$", "\\1", 1)}')"
'^0$|^[1-9][0-9]*$')" ][ -z "$(printf '%s' "$boottime" | /usr/bin/egrep
&& { printf 'Invalid boottime retrieved.\n' >& 2; exit 1; }
/sbin/dmesg "$@" | /usr/local/bin/gawk -v boottime=3D"$boottime" =
t{
uptime =3D gensub ("^\\[([1-9][0-9]*)\\] .*$", "\\1", 1)
if (uptime =3D=3D $0) realtime =3D "??? ?? ??:??;??"
else realtime =3D strftime ("%b %d %T", uptime + boottime)
print realtime " " $0
}'
FWIW, this is a patch for dmesg(1) I use. You can enable timestamp conversion using -t and optionally specify a different output forma=
using -f "fmt".
If interested for inclusion in base, I could try to re-format it
and come up with a manpage diff...
Yes. I've done a quick review inline.
Thanks...
--- sbin/dmesg/dmesg.c 2023-12-27 17:49:57.000000000 +0100
+++ sbin/dmesg/dmesg.c 2026-01-22 09:20:28.987020000 +0100
@@ -60,6 +60,7 @@
#include <unistd.h>
#include <vis.h>
#include <sys/syslog.h>
+#include <time.h>
static struct nlist nl[] =3D {
#define X_MSGBUF 0
@@ -76,18 +77,23 @@
main(int argc, char *argv[])
{
struct msgbuf *bufp, cur;
+ struct timeval boottime;
+ char timebuf[64];
Why 64?
Well, any recommendation? Is the a _MAX define somewhere?
I always use 64 but if there is something better I'll use it.
char *bp, *ep, *memf, *nextp, *nlistf, *p, *q, *visbp;
+ const char *timefmt =3D "%d %b %T";
kvm_t *kd;
+ time_t time;
size_t buflen, bufpos;
long pri;
- int ch, clear;
+ int ch, clear, timeconv;
timeconv should be a bool.
OK...
bool all;
all =3D false;
clear =3D false;
+ timeconv =3D false;
(void) setlocale(LC_CTYPE, "");
memf =3D nlistf =3D NULL;
- while ((ch =3D getopt(argc, argv, "acM:N:")) !=3D -1)
+ while ((ch =3D getopt(argc, argv, "actf:M:N:")) !=3D -1)
switch(ch) {
case 'a':
all =3D true;
@@ -95,6 +101,12 @@
case 'c':
clear =3D true;
break;
+ case 't':
+ timeconv =3D true;
+ break;
+ case 'f':
+ timefmt =3D optarg;
+ break;
case 'M':
memf =3D optarg;
break;
@@ -109,6 +121,13 @@
if (argc !=3D 0)
usage();
+ if( timeconv ) {
preferredSo the spacing doesn't meet style(9). "if (timeconv) {" is the
spacing.
Yes, that's why I offered to re-format it...
+ int mib[6] =3D { CTL_KERN, KERN_BOOTTIME };
+ size_t l =3D sizeof boottime;
sizeof(boottime) is the preferred spelling here.
unwrapped+ if (sysctl(mib, 2, &boottime, &l, 0, 0) < 0)
+ err(1, "sysctl kern.boottime");
+ }
+
if (memf =3D=3D NULL) {
/*
* Running kernel. Use sysctl. This gives an
buffer
@@ -200,7 +219,22 @@
}
(void)strvisx(visbp, p, nextp - p, 0);
- (void)printf("%s", visbp);
+ bufpos =3D strspn( visbp+1, "0123456789" ) + 1;
pointNo check for overflow here. *bufpos may point to a NUL and +1 will
it past that NULL.
bufpos is no pointer but size_t. visbp[ bufpos ] will never point past
'\0' as I start at visbp + 1 for the strspn().
But the test of visbp[ bufpos+1 ] below is not OK. I'll fix that...
It shouldn't, but it might. And you should do something more like
if (!timeconv) {
<the existing printf>;
} else {
decode the buffer
}
I din't want to duplicate <the existing printf> too often in case
timeconv is desired but fails later for whatever reasons. So would
is the recommendation here?
1. Whenever it fails, do <the existing printf> and continue?
2. Place <the existing printf> at the end and "goto" it?
3. ??
YourBut you should check things in the right order so you can't overflow.
code already has a fallback for printing things...
throws*ALSO* The parsing is wrong. When show_timestamp=3D2 it will have a fractional part (so .xxxx) that should be parsed as well. This also
off the math that just adds to the second of time timeval.
Right, the conversion gets aborted in this case (I never used show_timestamp=3D2 ;-)). I'll have a look at it...
10+ if( timeconv !=3D true
+ || bufpos < 2
+ || visbp[0] !=3D '['
+ || visbp[bufpos] !=3D ']'
+ || visbp[bufpos+1] !=3D ' ' ) {
+ (void)printf("%s", visbp);
+ continue;
+ }
+
+ visbp[bufpos] =3D '\0';
+ time =3D boottime.tv_sec + strtoull( visbp+1, NULL,=
);
localtime(+ if( strftime( timebuf, sizeof timebuf, timefmt,
&time ) ) !=3D 0 )
gSame spacing. comment about parens. And note that we're strongly encouraging {} even for single line statements.
OK...
github...
So that's my feedback on the first round of patches. You should do a
is notpull request
or a Phabricator review. Do not put this in a bugzilla bug. Bugzilla
a code review tool
and I suspect that feedback on the revision will be needed (if nothin=
elsea
I'llthan for the man
page that we've not seen yet). github is likely easiest for you, and
keep an eye out there.
Phabricator is a lot more work to get started. If you are going to do=
ebunch of reviews, it
may make sense to climb the hill (or for other parts of the code whos=
kmaintainers don't do
github). If it's just this one, and you have a github account, I'd recommend that as the path
I used Phabricator once (https://reviews.freebsd.org/D46313) but I thin=
I'll follow your advice and try the github way...
-Andre
I think opening review on Phabricator alone is easily missed.
So I basically file a PR on Bugzilla, open review and introduce
the D number of the review on Bugzilla PR.
And pull request on GitHub alone is also easily missed for anyone
without GitHub account like me.
Upcoming (hopefully) moving from GitHub to Forgejo managed by
FreeBSD project could change the situation, but it's still
not official. I'm thinking about how my workflow should be
non the switch.
On 01/23/2026 3:21 AM CST Tomoaki AOKI <junchoon@dec.sakura.ne.jp> wrote:
I think opening review on Phabricator alone is easily missed.
So I basically file a PR on Bugzilla, open review and introduce
the D number of the review on Bugzilla PR.
On 01/23/2026 3:21 AM CST Tomoaki AOKI <junchoon@dec.sakura.ne.jp>wrote:
I think opening review on Phabricator alone is easily missed.
So I basically file a PR on Bugzilla, open review and introduce
the D number of the review on Bugzilla PR.
IMHO the fact that we make our developers jump through these hoops
is proof our tooling is wrong.
Other than duplicating work, he biggest problem with the workflow
above is that Someone (TM) needs to go through the Problem Reports
looking for references to completed DR.
On 01/25/2026 1:57 AM CST Tomoaki AOKI <junchoon@dec.sakura.ne.jp> wrote:
BTW, the account I've registered at Forgejo repo seems to be deleted.
On 01/25/2026 1:57 AM CST Tomoaki AOKI <junchoon@dec.sakura.ne.jp> wrote:
BTW, the account I've registered at Forgejo repo seems to be deleted.
If you are talking about the FreeBSD forgejo instance, IIUC it
is a test instance and not meant for actual users yet.
mcl
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?
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 12:11:44 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
5 files (10,064K bytes) |
| Messages: | 265,377 |