如何同步内核时间和logcat时间?

发布于 2024-11-15 13:15:28 字数 260 浏览 5 评论 0原文

我正在开发一款基于 Linux 内核的 Android 手机。我使用 kmsg 来记录内核日志,使用 adb logcat -v time 来记录平台日志。问题是内核日志显示从 0.000000 开始的时间,而 logcat 显示从系统时间开始的时间(例如,如果手机上的时间是 10.43.00,它将显示从该时间开始的第一个日志)

现在我无法比较这两个日志中的事件,因为时基(参考)不同。谁能指出如何同步这两次?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

怀念你的温柔 2024-11-22 13:15:28

另一个解决方案类似于 jpg 的答案,但在另一个方向,重定向
将内核消息写入 logcat。这更好,因为太多的 logcat 消息可能会使串行控制台过载(如果您将其激活)。

您可以在 android shell 中运行此命令:

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

或在主机 shell 中运行此命令:

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

第一次启动该命令时,您将在一个位置看到所有当前 dmesg 消息,但任何其他消息在出现时都会交错排列。

然后在不同的 shell 中检查 logcat。如果您使用 -v time 检查 logcat,那么内核消息将包含 logcat 和内核时间戳。当然,两者之间可能会有延迟。

另一种更简单的查看消息交错的方法是:

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

但在这种情况下,识别来自内核的消息有点困难,并且您无法判断内核时间戳与 logcat 时间戳之间的关系。

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.

[旋木] 2024-11-22 13:15:28

您可以创建一个包含内核日志和平台日志的单个文件,如下所示:

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

您可以使用平台日志中的时间戳来区分这两个日志。 将文件拉到本地驱动器

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

然后使用Refer http://jai-tech.blogspot.com/2012/01/take-kernel-and-platform-logs-of.html。希望这有帮助。

问候,
太平绅士

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

辞旧 2024-11-22 13:15:28

Pavan,

也许你可以用自上次启动以来的时间标记你的 logcat 打印?这应该更接近 kmsg 中显示的时间。

可以使用 elapsedRealtime( 检索自上次启动以来的时间)

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().

像极了他 2024-11-22 13:15:28

上面描述的单文件方法很好,但可能并不总是有用,因为来自 logcat 和 kmsg 的输入可能由于缓冲而延迟。因此,您很可能会看到一个 kmsg 条目块,然后是一个 logcat 条目块,这些条目可能仍然实时交错。

也就是说,您可以通过在 kmsg (grep UTC) 中查找设备挂起消息来同步 kmsg 时间和 logcat 时间:

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

如您所见,kmsg 中的那些条目报告了当前系统然后可以将挂钟时间与 kmsg 时间值同步。但请注意,当设备处于睡眠状态时,kmsg 时间值不会增加,而挂钟时间显然会增加。为此,您必须在每次暂停进入和退出时重新同步挂钟时间,以获得正确的挂钟时间。

The single file method described above is nice but may not always be useful as the input from logcat and kmsg might be delayed due to buffering. So you will most likely see a block of kmsg entries and then a block of logcat entries which might still be interleaved in real time.

That said, you might be able to sync kmsg time and logcat time by looking for device suspend messages in kmsg (grep UTC):

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

As you can see those entries in kmsg report the current system wallclock time which can then be synchronized with the kmsg time value. Note however that the kmsg time value does not increase when the device is asleep while the wallclock time obviously does. To that end you will have to resynchronize on the wallclock time on every suspend entry and exit in order to get the correct wallclock time.

留一抹残留的笑 2024-11-22 13:15:28

我认为它可以这样使用:

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

I think it can use like this:

adb shell logcat -v time -f /dev/kmsg | adb shell cat /proc/kmsg >sample.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文