1、dmesg指令打印的内容只与kernel相关,它的log源于内核缓冲区。可以用来调试内核相关的驱动程序。
也可以使用cat /proc/kmsg,该指令与dmesg显示log的方式不同,dmesg指令会一次性将内核缓冲区内的信息全部打印出来,从时间戳0.000000到当前时间戳(如果缓冲区大小满足的话)。
而第一次执行/proc/kmsg 会打印截止到当前时间的所有内核信息,再次执行cat /proc/kmsg,不会再打印已经打印的信息,只打印上一次执行之后的新的信息。有点类似于管道FIFO中读消息的特点。
通过dmesg --help指令,可以查看到dmesg指令在Linux系统中使用功能更为丰富,而在Android系统中,dmesg指令更像是Linux的阉割版本。在Android系统中,dmesg指令常有以下用法:
dmesg --help dmesg指令的详细用法
adb shell dmesg > kernel.log 将log信息保存在当前路径下的kernel.log文件中。
也可搭配grep指令进行特定字符串的过滤。
dmesg | grep “ffffff”
dmesg | grep -i “ffffff”
dmesg | grep “ffffff” > kernel.log
dmesg -C 显示的同时清空buffer数据,重新开始记录 ;
dmesg -n 打印级别,设置记录控制台输出最低级别;

2、logcat指令是安卓系统的专用指令,打印的内容只与应用程序相关,也就是只打印用户态的log信息;比如加速度传感器G-sensor上报input系统的坐标,或者TP触摸的坐标,都可以实时的显示出来。
使用方法有以下这些:
logcat --help
logcat | grep “ffffff” 查找带有“ffffff”字符串的log信息
logcat | grep “ffffff” > app.log 将过滤后的信息保存在当前路径下的app.log文件中。
logcat | grep -i “ffffff” > app.log 忽略字符串大小写
logcat -v time -b all > app.log (all表示将main radio system events同时抓取到文件中)
adb logcat -c 清除之前缓存的数据,只抓取自己当前准备获取的日志信息。

3、一般查看内核启动相关的信息,如驱动信息,硬件相关的初始化信息等这些使用dmesg指令;当驱动程序运行起来,查看数据或者与系统相关的信息,使用logcat比较合适。

/*
LOGCAT-- This is used in Android , to see the different messages written by the activity managers inside the Android , u see android also uses the linux kernel , but what it does is, once the kernel boots ( the hardware initialization /probing has been taken care of) , the android starts a process called init which parses the init.rc file which contains all the android system activities , i mean the basic processes for android to boot , in this init.rc file there’s a process called zygote which starts the Dalvik Virtual Machine , and after that all the other activity managers , which will be used by the application to interact with the hardware . so its basically messages from the VM , for the application programmers to debug it .

Dmesg- it is messages from the kernel , suppose u write a driver , it can be used as a tool for debugging drivers and other kernel code, most of them are driver messages its a good way of debugging , the kernel , driver etc…

Logcat is only for android and its not available in any other OS , both Logcat and dmesg is available on Android but not the vice versa for any linux distros .

dmesg prints the contents of the kernel’s ring buffer. So dmesg will print only what system writes to kernel log, logcat will output only android app’s logs.
*/

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐