First, what is the startup duration?
1, start-up time generally includes three kinds of scenes, namely: the first time to start the package, cold start time, hot start length
Cold start and hot start:
(1) cold start: When the application is launched, the background does not have the process of the program, at this point, the system will be assigned a new process to the application.
(2) Hot start: The process of the program is still present, start through the existing process to enter the activity Display page, is hot start, or from the Android official website to see what we get is actually warm start time, that is, activity does not exist.
(3) The starting length of the newly installed package:
The start-up length of the newly installed package is the longest, and the performance is different on Android systems under 5.0 and above 5.0, because Android 5.0 and later use the runtime named Art, which natively supports loading multiple Dex files from the apk file. When the app is installed, it performs precompilation, scanning classes (. N). dex files are then compiled into a single. oat file for execution. and Android5.0 The following system is not supported, only after the program click Start, the loading of multiple Dex files, if it is on the model below Android5.0 to obtain the length, you can obviously see the newly installed package start longer than the other boot length.
The cold start process is as follows:
The time the system starts to start activity is the time it takes to start the activity from start u0, which is the time it was printed in front of the log:
12-14 16:45:51.483 I/activitymanager (1370): START u0 {act=android.intent.action.main cat=[ Android.intent.category.LAUNCHER] flg=0x10200000 Cmp=com.ganji.android/.control. Launchactivity bnds=[571,684][763,876] (have extras)} from the UID 10021 on display 0
When the first frame of the activity is displayed, the display's log information is printed, such as:
12-14 16:45:52.023 I/activitymanager (1370): Displayed Com.ganji.android/.control. Launchactivity: +521ms
This time from start u0 to the first frame of display includes all the time from the START process to the first layout and drawing. This is basically the main time you need to know. It does not contain the time that the user clicks on the app icon and then the system starts to start the activity, which is OK
2, about the three kinds of scenarios we want to get started
(1) Three scenarios are three typical scenarios that are launched, and these three scenarios do not include the removal of cache and data, with the most user experience being "cold start time" and "Hot start duration"
(2) The first boot time of the newly installed package is usually the most, and the process of loading multiple Dex files from the apk file on the Android5.0 system is included.
The cold boot time is second, because the cache in memory after the kill process is lost, many data needs to be re-requested, and the process needs to be restarted;
The length of the hot start is the shortest.
(3) We want to get a start time scenario:
Is the time from the initial launchactivity page into the next actionable page;
For example, take go as an example, after the first launch of the package will jump to select the city page, we need to get the length of time is from the Launchactivity page into the selectcityactivity page
Because users generally use the scene is: Select the city to enter the main page, the next start is directly into the main page, so wrote a uiautomator script, can choose the city by UITest Way, and then get "cold start Time" and "Hot Start Time" respectively, The start time of the kill process and the normal exit program
Second, how to obtain?
1, because the Logcat print log filter Activitymanager way to get the boot time, can be applied to other apps, so finally determined in this way.
One of the market life for example, the new package for the first time to start the acquisition, need to obtain is: from the start of the launchactivity, to displayed out Selectcityactivity, just started with the displayed of the back of this time, But with the development confirmation, he said that this time is less than the user's actual perception of the process of time, and finally determined that:
Gets the time from start u0 launchactivity to display actionable activity, takes the previous time node, and then calculates
Take go as an example, under the three scenarios under the Xiaomi 4 + Android4.4.4 model, the logs captured by Logcat are as follows:
The newly installed package first launches from the launch interface into the Select City interface:
12-12 17:08:51.101 I/activitymanager (1191): START u0 {act=android.intent.action.main cat=[ Android.intent.category.LAUNCHER] flg=0x10000000 Cmp=com.ganji.android/.control. Launchactivity} from PID 5656
12-12 17:08:58.141 I/activitymanager (1191): Displayed Com.ganji.android/.control. Launchactivity: +6s803ms
12-12 17:08:59.041 I/activitymanager (1191): START u0 {flg=0x200000 Cmp=com.ganji.android/.control. Bettercityactivity (have extras)} from PID 5668
12-12 17:08:59.711 I/activitymanager (1191): Displayed Com.ganji.android/.control. Bettercityactivity: +654ms
Hot Start Duration:
12-12 17:11:23.571 I/activitymanager (1191): START u0 {act=android.intent.action.main cat=[ Android.intent.category.LAUNCHER] flg=0x10000000 Cmp=com.ganji.android/.control. Launchactivity} from PID 6369
12-12 17:11:24.021 I/activitymanager (1191): Displayed Com.ganji.android/.control. Launchactivity: +264ms
12-12 17:11:25.311 I/activitymanager (1191): START u0 {Cmp=com.ganji.android/.control. Mainactivity} from PID 5668
12-12 17:11:27.311 I/activitymanager (1191): Displayed Com.ganji.android/.control. Mainactivity: +1s989ms
Cold start Duration:
12-12 17:13:16.981 I/activitymanager (1191): START u0 {act=android.intent.action.main cat=[ Android.intent.category.LAUNCHER] flg=0x10000000 Cmp=com.ganji.android/.control. Launchactivity} from PID 6625
12-12 17:13:18.231 I/activitymanager (1191): Displayed Com.ganji.android/.control. Launchactivity: +1s237ms
12-12 17:13:19.231 I/activitymanager (1191): START u0 {Cmp=com.ganji.android/.control. Mainactivity} from PID 6637
12-12 17:13:22.811 I/activitymanager (1191): Displayed Com.ganji.android/.control. Mainactivity: +3s556ms
Three scenarios, you need to start u0 CMP = launchactivity time, to displayed the time of the next activity ends
2, of course, can also be recorded by the way the screen, the command is:
ADB Shell Screenrecord--bugreport/sdcard/launch.mp4
Then press CTRL + C to end, then export the video file, then use a player that can be played by frame.
When playing with the player, you can start from the moment the user taps the screen, which can be accurate to MS, then end with the page you reached, and wait until the asynchronous load is complete.
This takes longer than the 1 approach, because it includes the user's touch after the click, then the system responds, then the system starts responding to the startup process, creates the activity, loads the view, measures and makes the overall display of the activity.
And through the Logcat way, can only use in activity from a jump to B this situation, if the activity does not change, only the page data is refreshed, Logcat cannot print out the log through Activitymanager.
The final scenario determines:
Finally, according to our communication with the development, and through the two ways of comparison, but also for the subsequent can be easily written in the form of automation, the first choice of And added a case to support automation by completing the city selection via Uiautomator and clicking the Back button to exit the app's UI Automation.
Iii. finalized programmes, implementation of programmes and implementation of tools
For the above requirements:
1, easy to obtain the competitor's comparative data, need to be executed on the same model, and preferably executed multiple times, select an average
2, the convenience of the universality of the program, as well as automated implementation
Through the program implementation, mainly contains the following procedures:
1, automatic packaging
2. Start Logcat, clear Logcat cache, execute adb logcat-v time-s activitymanager, and output output to a file
3, start the application, through the ADB shell am start launchactivity, get the start time of the newly installed package, then perform the UI operation through Uiautomator, finish the hot start time, then through the ADB shell am Force-stop PKG Package name of the way to kill the process, and then start to complete the cold start time acquisition
3. Pull the log files out of the phone
4, the log file analysis, because the front has been added to the-V time option, log can be printed out specific to MS, can be based on the rules you set, directly get a log before the time
5. After getting the start time and end time, subtract the start time by the end time
"Android APP startup time Acquisition" Start-up time acquisition scheme and implementation