Turn: Android App performance test

Source: Internet
Author: User
<span id="Label3"></p><span style="text-decoration: underline;"><span style="text-decoration: underline;"><strong>Android</strong></span></span>Users may often encounter the following problems: 1) application background open,<span style="text-decoration: underline;"><span style="text-decoration: underline;"><strong>Mobile Phone</strong></span></span>It's running out of Power. 2) First/non-first start-up application, very slow application start-up 3) application use process, more and more card--cpu capacity/memory leak 4) Application page lag--low frame rate, page lag therefore, for the development of Android applications, it must be<span style="text-decoration: underline;"><span style="text-decoration: underline;"><strong>Performance Testing</strong></span></span>, or it will directly affect the user Experience.<strong><strong>I. Start-up Time</strong></strong>Start-up time also follow the 2-5-8 principle, the so-called 2-5-8 principle is that when the user can start the application within 2 seconds to enter the first frame, the system will feel the response quickly, when the user in 2-5 seconds to get a response, the system will feel the response speed, and when the user is within 5-8 seconds to respond, The system responds slowly but is acceptable, and when the user is still unable to get a response after more than 8 seconds, the system sucks or thinks the system has lost its response, opting out of the app or uninstalling the app.  therefore, the startup time plays a vital role in the User's usage Behavior.  There are two types of startup time: the first boot (cold start) and the time it takes for a non-first-boot (hot-start) Application.   Before testing the app launch time, Let's take a look at this classic activity life cycle diagram, 1.  Figure 1 Overview of activity Lifecycle Processes: 1. Start activity: The system calls the OnCreate method first, then calls the OnStart method, and finally calls Onresume,activity into the running State.  2. Current activity is overwritten or locked by other activity: the system calls the OnPause method to pause the execution of the current Activity.  3. The current activity is returned to the foreground or unlock screen by the overwritten state: the system calls the Onresume method and enters the running state again.  4. The current activity goes to the new activity interface or press the home key to return to the main screen, itself back to the background: the system will first call the OnPause method, and then call the OnStop method, into a stagnant state.  5. The user backs back to this activity: the system calls the Onrestart method first, then calls the OnStart method, and finally calls the Onresume method, again into the running State. 6. Current activity is in a covered state or the background is not visible, that is, the 2nd and 4th steps, The system is out of memory, kill the current activity, and then the user returned to the current Activity: call OnCreate method again, OnStart method, Onresume method  To enter a running State.  7. The user exits the current activity: the system calls the OnPause method first, then calls the OnStop method, and finally calls the Ondestory method to end the current Activity. From the Activity's life cycle flowchart, We can see that the start time is the time that the OnCreate () method starts executing to the end of the Onresume () method execution, that is, when the activity is fully started.<strong><strong>so how to get the time</strong></strong>?  Method One: get through the relevant data of Activitymanager in Logcat.  1) DDMS Set Filter conditions "by Log Tag": activitymanager; 2) launch the app to see the Log captured by Ddms.  Take the 2345 Ace Browser app as an example, and you can view the log as follows: in addition to crawling through ddms, you can also get through the ADB logcat command. &GT;ADB logcat-d-s activitymanager|findstr "Displayed" >d:\log.txt Actually the information obtained is the same (this is not the same start, so the startup time is a little different). It's just DDMS caught. usually in the main cache, which is the log file that the application prints, it can be viewed in real time.  The command can only be redirected to the file, after the capture can be Viewed. Method two: the ADB command gets, in the previous blog post commonly used in the ADB command to the ADB<span style="text-decoration: underline;"><span style="text-decoration: underline;"><strong>Shell</strong></span></span>There is a little bit of introduction. 1) get the app package name and class name >adb shell Dumpsys activity|findstr mfocusedactivity 2) get start time >adb shell am start-w–n <packagen Ame>/<activityname> by comparison, It can be found that both methods acquire the same time. (note: Both methods are the same start, not the same start, there will be differences) for these times, the quote from the author Gracker answers: "if You only care about an Application's own startup time-consuming, refer to totaltime; If you care about system startup Refer to waittime; If the application has an interface activity start time, refer to Thistime. ”<strong><strong>two. Performance Test Tool--emmagee</strong></strong>The Emmagee is an easy-to-use Android performance detection gadget designed to monitor the performance status of a single App's cpu, memory, traffic, startup time, power, and Current.  1) through the official website installation (individual models are not currently supported), set the "app after exiting the background can still listen" for automated testing.  2) pull out the test results CSV document in the SDcard directory via the ADB command (you can also configure the mailbox via the app to send to your mailbox).  3) View the test results csv document, here to Baidu Browser app as an example, the test results are as Follows. Note: models that are not known to be supported are available here: https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported current: less than 0 is discharge greater than 0 is charge start time:    Null is the application started or not collected to start time N/a: unsupported or data exception 4) using Excel to generate statistical charts, convenient Analysis. The results of this tool test can be used as a test reference, and the frame rate can also be tested with the FPS meter Tool.<strong><strong>Three. Monitor app-related performance information with ADB commands</strong></strong>It's not a demonstration here. Memory Utilization 1.adb Shell Dumpsys meminfo <pakagename> 2. Tested with android-provided API (activitymanager.memoryinfo ())//cpu occupancy 1.adb shell top 2.adb shell Dumpsys cpuinfo//power consumption 1.adb shel L Dumpsys Battery 2. Test via the Android API (prowermanager.wakelock) <table align="center"> <tbody> <tr> <td>View overall CPU Usage # Cat/proc/stat//view The CPU usage of the process # Cat/proc/<pid>/stat//view the overall ram# cat/proc/meminfo | Head-n 4//view process ram# dumpsys meminfo <packagename># dumpsys meminfo <pid>//view The current ram# procrank//of the process Total traffic after boot (bytes) # cat proc/self/net/dev//upload traffic/upstream Traffic # cat/proc/uid_stat/2000/tcp_snd//download traffic/downstream Traffic # cat/proc/uid_stat/2000/ Tcp_rcv</td> </tr> </tbody> </table>    <strong><strong>four. stability test/stress test</strong></strong>The ADB shell Monkey has been introduced in the previous Blog's frequently used ADB commands to stress test the app, please refer to.<p><p>Turn: Android App performance test</p></p></span>
Related Article

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.