How to synchronize kernel time and logarithm time?

I am working on an Android phone based on the Linux kernel. I use kmsg for kernel logs and adb logcat -v time for platform logs. The problem is that the kernel logs display time from 0.000000 , and logcat is displayed from the beginning of the system time (for example, if the time on the phone is 10.43.00, it displays the first log from that time)

Now I can not compare events from these 2 logs, because the time base (link) is different. Can you please indicate how to synchronize them 2 times?

+6
source share
5 answers

Pavan

Perhaps you can mark your logarithmic fingerprints since the last boot? This should be closer to the time specified in kmsg.

The time since the last boot can be restored using elapsedRealtime() .

+2
source

Another solution would be like a jpg response, but in a different direction - redirecting the kernel message to logcat. This is better because too many logcat messages can overload the serial console (if active).

you can run this in the android shell:

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

or this is in the host shell:

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

The first time you run the command, you will see all current dmesg messages in one place, but any subsequent messages will alternate when they appear.

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

Another, even simpler way to view alternating messages 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 cannot tell how the timestamps of the kernel relate to the logcat timestamps.

+6
source

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

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

You can distinguish between both logs using timestamps in platform logs. Then pull the file to the local drive using

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

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

Regards, In JP

+5
source

The single-file method described above is good, but may not always be useful, as input from logcat and kmsg may be delayed due to buffering. Thus, you will most likely see a block of kmsg records, and then a block of logcat records, which can still be interleaved in real time.

However, you can synchronize the time of kmsg and logcat by looking at the device suspension messages in kmsg (grep UTC):

<6> [249485.550811] suspend: output suspend, ret = 0 (2012-12-27 16: 16: 46.300872527 UTC)

As you can see, these kmsg entries report the current system uptime, which can then be synchronized with the kmsg time value. Please note, however, that the kmsg time does not increase when the device is asleep, while the acceleration time works explicitly. To do this, you will have to re-synchronize the wall time on each suspended input and output in order to get the correct acceleration time.

+2
source

I think he can use it like this:

 adb shell logcat -v time -f /dev/kmsg | adb shell cat /proc/kmsg >sample.txt 
+1
source

Source: https://habr.com/ru/post/890398/


All Articles