How do I calculate the App startup time in Android?

Source: Internet
Author: User

Turn: http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0105/3830.html

How do you calculate the boot time of the APK using Python or directly with the ADB command? is to calculate the time taken from the click icon to the APK full boot. For example, for the game is to click the game icon to enter the login screen during this time.
Two known methods seem to be available, but the feeling results are inaccurate: one is, adb shell am start-w packagename/activity, this can get two values, Thistime and totaltime, do not know what the difference between the two, And it does not match the actual boot time, both of which may be smaller than the actual start-up time (the difference between testing the game is greater), and the other is the way the ADB logcat, feeling that the results obtained are different from the actual.

Apply First Boot

That's what we often call cold start, when your application's process is not created. This is also a usage scenario for most applications. After the user clicks on your app's icon on the desktop, the first thing to do is to create a process before starting mainactivity.
The result of the ADB shell am start-w packagename/mainactivity return is the standard application startup time (note that the phone before Android 5.0 is not WaitTime this value):

  1. ? adb shell am start -W com. Media. Painter/com. Media. Painter. Paintermainactivity
  2. Starting: intent {  act=android.. Action. Main cat=[android.. Category. Launcher] cmp=com media./. Paintermainactivity }
  3. Status: OK
  4. Activity: com. Media. Painter/. Paintermainactivity
  5. Thistime: 355
  6. TotalTime: 355
  7. WaitTime: 365
  8. Complete

A total of three results have been returned, and we shall prevail on the WaitTime.

The following is an explanation of the difference between Thistime/totaltime/waittime:

The implementation of "ADB shell am start-w" is in the Frameworks\base\cmds\am\src\com\android\commands\am\am.java file. is actually to call the activitymanagerservice.startactivityandwait () interface across the binder (the Activitymanagerservice is referred to as AMS later), The results returned by this interface include the Thistime, TotalTime time printed above.

    • StartTime the point in time that the startactivityandwait () was just ready to be called

    • Endtime records the point in time that the startactivityandwait () function call returned

    • WaitTime = startactivityandwait () call time-consuming.

The calculation of Thistime and TotalTime in the Frameworks\base\services\core\java\com\android\server\am\activityrecord.java file The reportlaunchtimelocked () function.

Let's explain the Curtime, Displaystarttime, mlaunchstarttime three time variables in the code.

    • Curtime represents the point in time for the function call.

    • Displaystarttime represents the start point of the last activity in a series of startup activity.

    • Mlaunchstarttime represents the start point of the first activity in a series of startup activity.

Under normal circumstances, click on the desktop icon to start an Activity with the interface, Displaystarttime and Mlaunchstarttime point at the same point in time, at this time thistime=totaltime. Another case is that clicking on the Desktop icon application will start a non-interface activity to do the logical processing, and then start an interface activity, in the case of the start of a series of activity (known as the start is the case), Displaystarttime Point to the start point of the last activity, Mlaunchstarttime points to the start point of the first non-interface activity, at which time thistime! =totaltime. Both of these situations are as follows:

In the above figure, I marked three time periods with ①②③, what did I do in the three time periods respectively?

    • During the ① time period, AMS creates a Activityrecord record block and selects a reasonable Task to pause the Activity of the current resume

    • In the ② time period, start the process, invoke onCreate () such as no interface activity, Pause/finish no interface activity

    • In the ③ time period, call the OnCreate, Onresume with interface Activity

See here should be clear thistime, TotalTime, WaitTime three time relationship:

    • WaitTime is the total time consuming, including the previous application Activity pause and the time when the new app started;

    • Thistime indicates that the start of the last activity of a series of start-up activity is time consuming;

    • TotalTime indicates the time-consuming startup of a new application, including the start of a new process and the start of the Activity, but excluding the previous

A time-consuming application of Activity pause. In other words, developers generally only care about totaltime, this time is the actual start of their own application time-consuming.

The table of two values in Tag=am_activity_launch_time in Event log represents thistime, TotalTime, and is consistent with the values obtained through "ADB shell am start-w".

Finally, the system according to what to judge the end of the application start. We know that application launches include process initiation, activity lifecycle Oncreate/onresume, and so on. In the first onresume when adding a window to the WMS, and then Measure/layout/draw, the window is drawn after the completion of the notification WMS,WMS the appropriate timing control interface to start the display (mixed with the interface Switch animation logic). Remember that after the window interface is displayed, the WMS calls Reportlaunchtimelocked () to notify the AMS Activity to start completion.

Finally, if you only care about the startup time of an application, refer to TotalTime, if you are concerned about the time-consuming system startup application, refer to waittime; If you are concerned about the application with interface activity start time, refer to Thistime.

1.2 Apply non-first boot

If you press the back key and do not kill the application process, then executing the above command will be faster because there is no need to create a process, just start an activity. This is what we call the application hot start.

2 game Launch scene

When the game starts, it does not apply the command line method to start, because from the user clicks the desktop icon to the login interface, both the system part also has the game own part.

2.1 System Section

The game also has an activity, so the start of the time will still go to start the activity, so the system startup part is the user clicks the Desktop Desktop response to the activity to start.

2.2 Game Section

After the main Activity of the game is started, it will also do some time-consuming things, when you see the interface is not operational, such as: Loading game data, networking Update data, read and update configuration files, game engine initialization and other operations. From the game development point of view, to the real user can manipulate the interface is considered a game when the real load completed.
Then this time, you have to use log to record, because loading game data, network update data, read and update configuration files, game engine initialization These operations are the game's own logic, and system-independent, so the game itself to define the point of loading completed.

For the game start time, we are more inclined to calculate from the click of the desktop icon to the user can interact with the game this time period as a game startup time.

3 Summary

The most fascinating thing about computers is its accuracy, which is always equal to 2, how long it takes to start, and how long it may be, each time it's different, but the exact time of the day.

However, each company has different positioning for the application, so the application launch requirements are not the same. For example, some do ROM company, its built-in application start time must be very fast, so that the user's first feeling is fast, smooth; The internet company app is not very concerned about the startup speed, most of the Internet company's applications have a launch page, used to display ads or feature introduction, etc. The main interface is then entered. The demand is different, so it is understandable, but from the consumer's point of view, the sooner you see the main interface of course the better.

So when making an Android app, be sure to remember to apply the startup time as a performance indicator, after all:

The World martial arts, only fast not broken!

Original link: http://androidperformance.com/2015/12/31/How-to-calculation-android-app-lunch-time.html

How do I calculate the App startup time in Android?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.