关键词不能为空

当前您在: 主页 > 英语 >

Android Log大全

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-17 23:32
tags:

-

2021年2月17日发(作者:听音乐英语)



Android log


系统





light


2011/11/20







Android


系统


log


抓取,实现原理分析



一概述



本文档主要是供


Android


开发人员使用,特别是


Framew ork


开发。因为


Framework



95%


以上的问题都是靠分析


log


解决的,所以开发人员必须对


android

< br>整个


log


系统十分清楚。


什么 问题抓什么


log,


使用什么工具抓


Log


,如何分析


log,


如何在代码 中添加


log.



DDMS log


关于


ddms


是如何工作的和


ddms


的详细功能,见下面


android sdk


中文档详细介绍:



F:02 Android01_SDKGingerbread2.3docs-2.3_



Ddms


工具中打印


log


的几个菜单如下:



Device -> Show process status




Device -> Dump device state




Device -> Dump app state




Device -> Dump radio state




Device -> Run logcat





1




Show process status



菜单



等效于在


adb shell


下执行


adb shell ps



x


命令,该命令打印出

< p>
进程


的详细信息,如


下:



USER






PID




PPID



VSIZE



RSS






WCHAN





PC










NAME


root







1






0






268




180




c009b74c



0000875c




S /init (u:2, s:371)


root







2






0






0







0






c004e72c



00000000



S kthreadd (u:0, s:1)


root







3






2






0







0






c003fdc8



00000000



S ksoftirqd/0 (u:0, s:0)


root







4






2






0







0






c004b2c4



00000000



S events/0 (u:0, s:39)


root







5






2






0







0






c004b2c4



00000000



S khelper (u:0, s:0)


root







6






2






0







0






c004b2c4



00000000



S suspend (u:0, s:0)





USER





用户名,即用户所在组




PID





进程


ID



P rocess ID





PPID





父进程的进程


ID

< br>(


Parent Process id





VSZ





进程所使用的虚拟内存的大小(


Virtual Size





RSS





进程使用的驻留集大小或者是实际内存的大小,


Kbytes< /p>


字节。




WCHAN



进程正在睡眠的内核函数名称;


该函数的名称是从


/roo t/


文件中


获得的




Exploring Processes


You can see the output of


ps -x


for a specific VM by selecting


Device


>


Show process


status


... in the menu bar.




2




Dump device state



菜单



等效于执行



/system/bin/dumpstate




/proc/self/fd/0



等效于执行


adb shell dumpstate


命令




To run


dumpstate


from Dalvik, select


Device


>


Dump device state...


in the menu bar.



3




Dump app state



菜单



等效于执行


adb shell


dumpsys


命令



输出


android


服务状态信息,即输出服务中


dump


函数的


log.



4




Dump radiostate



菜单



等效于执行


adb shell cat /data/logs/radio


命令



Examine Radio State


By default, radio state is not output during a standard logcat (it is a lot of information). To see


radio information, either click


Device


>


Dump radio state...


or run logcat as described in


Logging Radio Information


.




5




Run logcat



菜单



等效于执行


adb logcat




To run


dumpsys


(logcat) from Dalvik, select


Device


>


Run logcat...


in the menu bar.




总结:


除了


Run logcat



菜单是实时输出设备中的


log


外,


其他菜单都是输出设备中缓存的


log





Adb Log


Android sdk


文档中对

adb


的介绍见下:



F:02 Android01_SDKGingerbread2.3docs-2.3_




adb 1.0.26


版本共有


2


条命令打印


log,

如下:



adb logcat [ ] - View device log


adb bugreport















- return all information from the device

































that should be included in a bug report.


Adb logcat


常用命令



logcat -c


清除已有


log


信息

< p>


logcat -b main


显示主缓冲区的


log


logcat -b radio


显示无线缓冲区的


log


logcat -b events


显示事件缓冲区的


log


logcat -f [filename]



log


保存到指定的文件中,例如



logcat -b radio -f /data/


比较常用的是显示时间


:logcat -v time &


logcat -g


查看缓冲区的大小



logcat -g main


logcat -g radio


logcat -g events


logcat

< p>
打印


/dev/log


设备下的三个文件



radio, events, main


数据



logcat


默认是输出


main


缓冲区的


log



控制日志输出格式



日志信息包括了许 多元数据域包括标签和优先级。


可以修改日志的输出格式,


所以 可以显示


出特定的元数据域。可以通过



-v


选项得到格式化输出日志的相关信息


.



brief



Display priority/tag and PID of originating process (the default format).


process



Display PID only.


tag



Display the priority/tag only.


thread



Display process:thread and priority/tag only.


raw



Display the raw log message, with no other metadata fields.


time



Display the date, invocation time, priority/tag, and PID of the originating process.


long



Display all metadata fields and separate messages with a blank lines.


当启动了


logcat


,你可以通过


-v


选项来指定输出格式


:



[adb] logcat [-v ]




此外,


adb shell


cmd, cmd



/system/ bin


目录下抓


log


的可执行程序,



dumpsys , dumpstate




< p>
Adb


下的


log


命令:



Adb logcat


Adb bugreport



Adb shell dumpsys


Adb shell dumpstate


Adb shell dmesg //


导出当前缓存的


kernel log


Adb shell kmsgcat //


实时查看


kernel log



其他查看系统当前信息命令



Adb shell ps //


查看系统进程信息,可以加很多有用信息



Adb shell pm //


查看


package


相关信息



Adb shell am //


启动


apk


应 用



Adb shell setprop //


设置系统属性



Adb shell getprop //


查看所有系统属性



Adb shell reboot


Adb shell kill //


通过进程


ID


杀死指定 的进程



Adb shell top //


查看当前运行进程信息



Adb shell vmstat //


查看虚拟机信息



Adb shell bootanimation //


播放开机动画



Adb shell df //


查看分区信息



Adb shell monkey //


跑自动化测试用例






四保存在手机的


Log


1

< p>
、手机


dropbox


默认路径:



/data/system/dropbox/


实现机制:




log


文件什么场景产生?




Log


文件分析:





2


、手机


anr


日志默认路径:



/data/anr/


实现机制:




log


文件什么场景产生?




Log


文件分析:






4



tombstones


路径:

< p>


/data/tombstones


log


文件什么场景产生?




Log


文件分析:







五如何实现后台抓


Log


如:



adb logcat -v time -r 1024 -n 16 -f /sdcard/bugreports/applogcat-log





log


执行程序实现机制



1



Logcat

< br>LogCat


是在文件


system/core/log cat/


中实现的。




Logger


设备驱动的实现知道,


Log


的读取是阻塞的操作,亦即,有数据可用,读出数


据;否则,读操作会被


BLOCK


,相应的读进程也会被挂起等待。下面看应用程序< /p>


LogCat


中如何实现读的,这可能需要不断回头与写操作和驱 动实现结合来看。



看具体实现之前,先看一个


logcat


中定义的重要的结构体


log_devi ce_t


。其中的重


要的成员在后面用到的时候再具体解释。< /p>




Android


Logcat


命令详解的命令参数


-b


知道,


logcat


是可以通过参数来指定对


哪个


buffer(main /radio/event)


进行操作的。


Logcat



b


参数解析的地方,是通过传递进




参数


< p>
main/radio/event




创建


了一


个上


面的



构变


量,


而这< /p>


些结构




lo g_device_


链接起来



因为< /p>


logcat


可能会同时操作多个


Buf fer


,而


read()


会阻塞读取进 程,对其他


Buffer


的读


取就不能 进行,所以这里用


select()


来判断可读取的

< p>
Buffer








2



Bugreport


I:00_AndriodSourceandroid-gingerbread- srcframeworksbasecmdsbugreport


#include


#include



int main(int argc, char *argv[]) {






char buffer[65536];






int i, s;






/* start the dumpstate service */



property_set(


启动


dumpstate


服务








/* socket will not be available until service starts */






for (i = 0; i < 10; i++) {










s = socket_local_client(































ANDROID_SOCKET_NAMESPACE_RESERVED,































SOCK_STREAM);










if (s >= 0)














break;










/* try again in 1 second */










sleep(1);






}







if (s < 0) {










fprintf(stderr,










exit(1);






}







while (1) {










int length = read(s, buffer, sizeof(buffer));

-


-


-


-


-


-


-


-



本文更新与2021-02-17 23:32,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/663664.html

Android Log大全的相关文章