最近在排查一个core问题,对dmesg的时间戳,做了一个转化工具:ts_dmesg.sh
借助awk 和shell实现:
#!/bin/sh
uptime_ts=`cat /proc/uptime | awk '{ print $1}'`
#echo $uptime_ts
dmesg | awk -v uptime_ts=$uptime_ts 'BEGIN {
now_ts = systime();
start_ts = now_ts - uptime_ts;
#print "system start time seconds:", start_ts;
#print "system start time:", strftime("[%Y/%m/%d %H:%M:%S]", start_ts);
}
{
print strftime("[%Y/%m/%d %H:%M:%S]", start_ts + substr($1, 2, length($1) - 2)), $0
}'
关于dmesg的原始时间戳,是系统的产生mesg的系统uptime时间,故需要获取系统的启动时间;
关于系统uptime时间: