92

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

What profiling tools or techniques can I use?

David
  • 2,987
  • 1
  • 29
  • 35
teedyay
  • 23,293
  • 19
  • 66
  • 73
  • I'm not familiar with Android. Can you run the app under a debugger that you can interrupt? If so, this method works: http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024 – Mike Dunlavey Oct 06 '10 at 20:57
  • Mmm, interesting. A bit labour-intensive, but potentially useful for spotting the more glaring performance problems. Thanks. – teedyay Oct 07 '10 at 08:10
  • I understand how you could think so: http://stackoverflow.com/questions/2624667/whats-a-very-easy-c-profiler-vc/2624725#2624725 – Mike Dunlavey Oct 07 '10 at 11:26
  • Nowadays you can do nice profiling inside Eclipse. Forget standalone/manual launching of TraceView, etc. I hope to write a blog article about that, with more details. Ping me if You need more details. – KarolDepka Apr 28 '13 at 02:19
  • 2
    You suggest there's something better than TraceView or DDMS. What is it? – Peri Hartman May 04 '13 at 22:07

4 Answers4

37

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

cement
  • 2,905
  • 1
  • 23
  • 20
  • 2
    When I run this it says the command-line version is deprecated and then it exits. What's the new method? – gonzobrains May 09 '13 at 18:51
  • The new method is Android Profiler in Android Studio: https://developer.android.com/studio/profile/android-profiler – mhansen Oct 09 '21 at 00:22
18

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

Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
Shahul3D
  • 2,129
  • 1
  • 15
  • 16
11

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.

David
  • 2,987
  • 1
  • 29
  • 35
0

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.)

Erhannis
  • 4,256
  • 4
  • 34
  • 48