How can I profile my Android app?

JavaAndroidPerformanceProfiling

Java Problem Overview


I need to find where the bottlenecks are in my Android app.

What profiling tools or techniques can I use?

Java Solutions


Solution 1 - Java

You can use Traceview. It is far from ideal, but works. This article describes how to use it.

Solution 2 - Java

DDMS is the best for Android. By default it get included with the ADT plugin.

This document with detailed example should help you to deal with DDMS.


For memory Analysis, try Eclipse MAT

Solution 3 - Java

It depends what're you going to test.

In case you develop applications for Android you should try out the TimingLogger class. Take a look at this article describing the usage of the TimingLogger helper class.

A very good tool is JMeter and there is a plugin for Android as well.

if you don't want to use external tools, but a very standard way, to measure elapsed time, you must use System.nanoTime(). You shouldn't use currentTimeMillis, because it measures wall-clock time ans, as no computer's clock is perfect (them all occasionally needs to be corrected) there's a process that runs and continually issues small corrections to the system clock. Not to mention the leap second correction.

Although currentTimeMillis is often used, it's still incorrect to measure elapsed time and timing. Anyhow, as the invocation takes some time, you should not expect to correctly time very very small intervals. But that shouldn't be an issue working with Android.

I'll show you an example:

long startTime = System.nanoTime();

// run/call the method

long endTime = System.nanoTime();
long diff = endTime - startTime ;
System.out.println("Elapsed milliseconds: " + diff /1000000);

You could have a look at this free library as well: http://jetm.void.fm/ .

You can also find tutorial for JMeter as well.

Solution 4 - Java

Another tool recommended in http://developer.android.com/training/articles/perf-tips.html is Caliper: https://code.google.com/p/caliper/. (I haven't used it, so I don't know much about it.)

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
QuestionteedyayView Question on Stackoverflow
Solution 1 - JavacementView Answer on Stackoverflow
Solution 2 - JavaShahul3DView Answer on Stackoverflow
Solution 3 - JavaDavidView Answer on Stackoverflow
Solution 4 - JavaErhannisView Answer on Stackoverflow