This article is the eighth article in the Android Kernel Development series, which focuses on how to analyze the startup log of an Android system and learn to find important nodes in the Android startup process by searching for important tag tags.
To learn to analyze the startup log information of the system, first understand the Android system start-up process, it is recommended to read the "Android Kernel development: Graphic Android system startup process" This article, which details the Android system startup process. Second, you need to know how to crawl the system startup log information, it is recommended to read the "Android Kernel development: How to count the system startup time" This article, it details how to crawl the system's startup log information.
Based on these 2 articles, this paper further describes how to analyze the system startup log information in depth, and find out the specific time nodes consumed by each part of the Android startup process.
First, we give a more comprehensive Android boot diagram (from embeded Android):
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/A3/wKioL1WBbnDTaqQlAAJ4msbU3f0944.jpg "title=" Android boot sequence.png "alt=" Wkiol1wbbndtaqqlaaj4msbu3f0944.jpg "/>
Based on the Android boot block diagram above, we can list several key steps involved in the Android system launch in a sequential manner:
(1) Startup of the Linux kernel
(2) Init program starts and launches various local services (such as HEALTHD, Debuggerd, etc.)
(3) Zygote process Start-up
(4) Zygote process initialization work (preload Class/resource)
(5) Systemserver process starts and starts various Java services (such as Activitymanager, Packagemanager, etc.)
(7) Flag point for end of start
If we can find out the time node of these critical steps from the start log information, we can clearly get the time that each module consumes in the Android system boot process , and when doing the system startup optimization, we know what time-consuming modules to optimize. When you analyze the system startup bug, you know exactly what went wrong.
Below, we analyze the boot log information for the Qualcomm APQ8064 Development Board (Android 4.4.2) as an example (these log files are uploaded to my github: https://github.com/Jhuster/AOSP/tree/ master/logs/apq8064), in fact, each Android system has a similar log output, we only need to focus on the key node of the tag and analysis methods.
1. Configure the system's log output
(1) Print the time information in the kernel log message
To execute make menuconfig in the Linux kernel source tree, tick the following options:
"Kernel hacking", "Show timing information on Printks"
(2) Output the detailed log of the init process to the DMESG file
Change/system/core/rootdir/init.rc, change loglevel from 3 to 7
2. Capture the log information of the system startup
As already mentioned in the previous article, the Android startup log is divided into the log of the Linux kernel and the log of the Android logger system,
Here's how to crawl:
$ adb shell DMESG > Dmesg.txt
$ adb logcat-d-v time-b "main" > Main.txt
$ adb logcat-d-v time-b "System" > System.txt
$ adb logcat-d-v time-b "Events" > events. txt
3. Analyze Log information
(1) Startup of the Linux kernel
The Linux kernel boot log is located in the Dmesg.txt file, starting with the log file until the following message indicates that the Linux kernel has completed booting:
"Freeing init Memory"
As a result, the Linux kernel of the APQ8064 board that we get from the Dmesg.txt file is started with only 6.613s:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/A4/wKioL1WBcBOQBimqAAAouZFmP0c299.jpg "title=" 11.png "alt=" Wkiol1wbcboqbimqaaaouzfmp0c299.jpg "/>
(2) Init program starts and launches various local services (such as HEALTHD, Debuggerd, etc.)
The log information for the INIT program is also located in the Dmesg.txt file, and we can find the program's print message by retrieving "Init".
By retrieving "Init starting", we can find out which local services the Init process started, such as:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/A8/wKiom1WBbouiU3HlAAeKNfLsVoY385.jpg "title=" 12.png "alt=" Wkiom1wbbouiu3hlaaeknflsvoy385.jpg "/>
(3) Zygote process Start-up
The zygote process was started in the Init process, so we retrieved "zygote" from the output log of the Init process above to find out when the zygote process started:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/A4/wKioL1WBcGLxLbvZAAAxIazSkdg520.jpg "title=" 13.png "alt=" Wkiol1wbcglxlbvzaaaxiazskdg520.jpg "/>
(4) Zygote process initialization work (preload Class/resource)
The log information that the zygote process outputs is placed in the/dev/log/main file , so we need to retrieve the log information for Main.txt to get zygote.
Since all subsequent Android applications are forked from the zygote process, the Android system will load some common Java class and resource files into the process's memory during the zygote process initialization process in order to increase application startup speed. This allows you to share common class and resourse resources. This process can be obtained by retrieving the "preload" tag to get the time spent in this process:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/A4/wKioL1WBcI2QQ24VAADbZAseC7w046.jpg "title=" 14.png "alt=" Wkiol1wbci2qq24vaadbzasec7w046.jpg "/>
(5) Systemserver process starts and starts various Java services (such as Activitymanager, Packagemanager, etc.)
Zygote started the systemserver process after the initialization was completed, thelog information for the systemserver process was placed in the/dev/log/system file , so We need to retrieve the System.txt file to get systemserver log information:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/A8/wKiom1WBbv6QYTP9AA1W3Tk_JEk001.jpg "title=" 15.png "alt=" Wkiom1wbbv6qytp9aa1w3tk_jek001.jpg "/>
(7) Flag point for end of start
"Android Kernel development: How to Count system startup time" This article has described in detail how to find the start of the end of time, here to choose one of the methods to repeat again, is to retrieve the Dmesg file "boot_completed" flag, We know the whole system takes a total of 29.913s time to complete the boot:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/A8/wKiom1WBbyHiG2-XAABTfQTyDMI651.jpg "title=" 16.png "alt=" Wkiom1wbbyhig2-xaabtfqtydmi651.jpg "/>
4. Summary
About the deep analysis of the Android system start log information is introduced here, have any questions or suggestions welcome message or letter [email protected] exchange, or follow my Sina Weibo @ Lu _ June get the latest articles and information.
This article is from the "Shadow Three People" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/1662911
Android Kernel Development: Learn to analyze the system's startup log