Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync Kernel time and logcat time?

I am working on an Android phone based on the Linux Kernel. I'm using kmsg for kernel logs and adb logcat -v time for platform logs. The problem is Kernel logs shows time from 0.000000 and logcat is showing from the start of system time ( For example, if time on the phone is 10.43.00, it'll show the first log from this time )

Now I am unable to compare events from these 2 logs as the time base ( reference) is different. Can anyone kindly point out how to sync these 2 times?

like image 204
Pavan Manjunath Avatar asked Jun 13 '11 11:06

Pavan Manjunath


3 Answers

Another solution would be similar to jpg's answer, but in the other direction, redirect the kernel messages into logcat. This is better, because too many logcat messages might overload the serial console (if you have it active).

you can run this in an android shell:

cat /proc/kmsg | while read LINE; do echo '\06kernel\0'$LINE'\0' > /dev/log/main; done

or this in a host shell:

adb shell '(cat /proc/kmsg | while read LINE; do echo \\06kernel\\0$LINE\\0 > /dev/log/main; done)'

The first time you start the command you will see all of the current dmesg messages in one place, but any further messages will be interleaved, when they appear.

and then examine logcat in a different shell. If you examine logcat with -v time, then the kernel messages will contain both the logcat and the kernel timestamps. Of course there may be delays between the two.

Another, even simpler way to see messages interleaved would be:

adb shell '(logcat & cat /proc/kmsg) > /path/to/log/file'

But in this case it's a little harder to identify messages coming from the kernel, and you can't tell how kernel timestamps relate to logcat timestamps.

like image 81
Purdea Andrei Avatar answered Nov 09 '22 02:11

Purdea Andrei


you can create a single file containing both kernel and platform logs as follows:

$adb shell    
$logcat -v time -f /dev/kmsg | cat /proc/kmsg > /data/klog_plog_log.txt

you can differentiate both the logs using time stamps in the platform logs. And then pull the file to your local drive using

adb pull /data/klog_plog_log.txt > sample.txt

Refer http://jai-tech.blogspot.com/2012/01/taking-kernel-and-platform-logs-of.html . Hope this helps.

Regards, JP

like image 5
jaiprakashgogi Avatar answered Nov 09 '22 00:11

jaiprakashgogi


Pavan,

Perhaps with you can tag your logcat prints with the time since last boot? This should be closer to the time shown in kmsg.

Time since last boot can be retrieved with elapsedRealtime().

like image 2
Will Tate Avatar answered Nov 09 '22 01:11

Will Tate