I am trying to understand the dmesg timestamp and find it hard to convert that to change it to java date/custom date format.
any help is much appreciated.
Sample dmesg log:
[14614.647880] airo(eth1): link lost (missed beacons)
Thanks!
I am trying to understand the dmesg timestamp and find it hard to convert that to change it to java date/custom date format.
any help is much appreciated.
Sample dmesg log:
[14614.647880] airo(eth1): link lost (missed beacons)
Thanks!
Understanding
dmesg
timestamp is pretty simple: it is time in seconds since the kernel started. So, having time of startup (uptime
), you can add up the seconds and show them in whatever format you like.Or better, you could use the
-T
option and parse the human readable format.From the man page:
you will need to reference the "btime" in /proc/stat, which is the Unix epoch time when the system was latest booted. Then you could base on that system boot time and then add on the elapsed seconds given in dmesg to calculate timestamp for each events.
In recent versions of dmesg, you can just call
dmesg -T
.With older Linux distros yet another option is to use wrapping script, e.g. in Perl or Python.
See solutions here:
http://linuxaria.com/article/how-to-make-dmesg-timestamp-human-readable?lang=en http://jmorano.moretrix.com/2012/03/dmesg-human-readable-timestamps/
If you don't have the
-T
option fordmesg
as for example on Andoid, you can use thebusybox
version. The following solves also some other issues:[0.0000]
format is preceded by something that looks like misplaced color information, prefixes like<6>
.It is inspired by this blog post.
Note, however, that this implementation is quite slow.
With the help of dr answer, I wrote a workaround that makes the conversion to put in your .bashrc. It won't break anything if you don't have any timestamp or already correct timestamps.
Also, a good reading on the dmesg timestamp conversion logic & how to enable timestamps when there are none: https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk92677