#!/bin/bash
#!/bin
#$1 is systrace file; $2 is kernel time match with systrace start 0
#set -x
grep -A 80 "entries-in-buffer/entries-written" "$1"
echo ""
echo "-------------------------------------手动校准方法----------------------------------------------\n"
echo "生成的systrace文件中的时间戳并不是从0开始,和chrome中从0点显示的时间轴不能对应起来,所以需要找
到systrace文件中哪个时间戳对应chrome时间轴上的零点.一般先在chrome中找到距离零点最近的一个event,
比如cpu2上的一个ipi中断(Start 0.001 ms/Wall Duration 0.003 ms),然后在systrace文件中找到这个中
断对应的开始时间:
<...>-11024 (11024) [002] dn.. 1152.860744: ipi_entry: (Rescheduling interrupts)
<...>-11024 (11024) [002] dn.. 1152.860747: ipi_exit: (Rescheduling interrupts)
由此可知1152.860744时间点对应chrome中的零点运行了0.001 ms,systrace文件中的零点时间戳即是:
1152.860744-0.000001=1152.860743 ms."
echo "--------------------------------------------------------------------------------------------------\n"
echo -n "\033[31m 手动校准方法输入零点时间戳,自动校准方式直接按enter: \033[0m"
read ts0
if [ ! "$ts0" ];then
echo "正使用自动校准方式 ..... "
ts0=`grep "\[00[0-7]\]" "$1" | grep -E "cpu_idle|sched_switch|irq_handler_entry|sched_wakeup|ipi_entry|softirq_entry" -m 1 | grep -o "[0-9]*\.[0-9][0-9][0-9][0-9][0-9][0-9]"`
echo "自动校准零点时间戳 $ts0"
fi
echo "please wait for a few minutes ....."
awk -v timezero=$ts0 -F "guanglei" '{gsub(/[0-9]*[.][0-9][0-9][0-9][0-9][0-9][0-9][:]/,"guanglei&guanglei");if($0~/\[00[0-7]\]/) printf("%6f ", $2-timezero);gsub(/guanglei/,"",$0);if($0~/\[00[0-7]\]/) print $0}' $1 > $1.timestamp