How to test the performance of an Android application?

AndroidPerformanceTesting

Android Problem Overview


How can I test an application for performance in Android? What is the support provided in Android and how do I use it?

Android Solutions


Solution 1 - Android

If you want to profile your application to find performance bottlenecks you can use the traceview tool. This gives you a graphical view of performance traces of your application.

[https://content.screencast.com/users/davweb/folders/Snagit/media/03df8bcc-606c-4ebb-8330-ab206ae30099/12.24.2009-08.57.51.png" width="300">][2]

To create a trace add the following to your code where you want to start tracing:

Debug.startMethodTracing("myapp");

and then put the following when you want to stop tracing:

Debug.stopMethodTracing();

This will create a trace file call myapp.trace in the root directory of the SD Card. As it is written to the SD Card:

  • If you're using the emulator you'll need to [add an SD card to your AVD][3].

  • You'll need to give you app permission to write the SD card by adding the following to your Manifest:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Once the file has been created you'll need to copy it to your PC. You can do this using the adb command:

adb pull /sdcard/myapp.trace c:/my/dir/myapp.trace

Finally, start traceview giving it the full path to the trace file:

traceview c:/my/dir/myapp.trace

I did have some problems with traceview failing with OutOfMemory exceptions. I fixed this on Windows by changing the last line of traceview.bat from:

call java -Djava.ext.dirs=%javaextdirs% -Dcom.android.traceview.toolsdir= -jar %jarpath% %*

to:

call java -Xmx1g -Djava.ext.dirs=%javaextdirs% -Dcom.android.traceview.toolsdir= -jar %jarpath% %*

Adding the -Xmx1g option allows traceview to use more memory.

[2]: https://content.screencast.com/users/davweb/folders/Snagit/media/03df8bcc-606c-4ebb-8330-ab206ae30099/12.24.2009-08.57.51.png "Click for full size" [3]: https://stackoverflow.com/questions/1952345/how-do-i-simulate-that-the-emulator-has-as-an-sd-card/1952358#1952358

Solution 2 - Android

Also, theoretically, DDMS can get memory allocations for your program and then you can analyze the dump using profilers. DDMS Reference.
The reason why I have theoretically in italics is that I myself have not tried doing anything such, yet.

Solution 3 - Android

I think traceView contains too much information, you can easily get lost.

My solution is just log the system time at three place in the code.

Before and after and center at the potiential slow code.

like binary search, next time, narrow it down step by step, then finally find the culprit code.

Solution 4 - Android

you can use load runner.,

use this link to find more about it.,

http://www.perftesting.co.uk/recording-and-performance-testing-android-applications-with-hp-loadrunner-vugen/2011/11/14/

Steps to be followed are:

  1. Create New VuGen Script
  2. Select Mobile Application-HTTP/HTML
  3. Recording Options--> Select Record Emulator
  4. Give the path to Record Emulator as D:\android\AVD Manager.exe
  5. In the command line -avd AVD_NAME -netspeed full -netdelay none where AVD_Name is the name of your Device
  6. select the working directory
  7. click finish

Now you can perform your test.,

Solution 5 - Android

Another way to test is Using TruClient on Load Runner

Steps to be followed for Mobile Web are:

  1. New VuGen Script
  2. Mobile Protocol
  3. Select TruClient Mobile Web
  4. Click Create
  5. Now you can generate scripts
  6. Click Develop Script button
  7. PoP up window appears to select the device
  8. Select Actions and you can record the scripts

Steps to be followed for Native Mobile are:

  1. New VuGen Script
  2. Mobile Protocol
  3. Select TruClient Native Mobile
  4. Click Create
  5. Now you can generate scripts
  6. click develop script
  7. TruClient window that plugged with Firefox appears
  8. Click General Settings
  9. Configure the SERVER URL PORT
  10. If u don't know the server url port means install OS MONITOR application on your device. here you can find the ip address
  11. Enter User Name and Password
  12. Click done

you can record the scripts and perform your testing....

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBharat PawarView Question on Stackoverflow
Solution 1 - AndroidDave WebbView Answer on Stackoverflow
Solution 2 - AndroidSamuhView Answer on Stackoverflow
Solution 3 - AndroidcoocoodView Answer on Stackoverflow
Solution 4 - AndroidPaarthiban NKView Answer on Stackoverflow
Solution 5 - AndroidPaarthiban NKView Answer on Stackoverflow