Friday, 15 July 2011

Profiling an Android application tutorial

I'm spending some spare time on an Android Reversi game which could need some performance tuning. After figuring out how the tooling works for Android profiling it works like a charm.

There are two ways to profile an application, using the debugging server DDMS or manually decide which parts of the code base are interesting for inspection. DDMS could be useful if you are inspecting code you might not be able to recompile. DDMS can also be used to inspect memory usage and more.

The easiest approach however is to use the debug interface provided by the Android API in your sources to specify when to start generating profiling information and when to end.


public int[] alphabeta(Board b, int maxDepth, long maxTime) {
      
      Debug.startMethodTracing("othello_profiling");

      // Here goes code to profile
  
      Debug.stopMethodTracing();
      return result;
   }

Run your program and you'll see in the VM logs when the profiler kicks in. (As usual the performance of your app in the emulator will sink to the bottom when profiling is enabled)



Now you got your profiling info written to the SD card of your Android emulator device. If you run into permission issues when writing to the SD card, add something like this to your Android Manifest.

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

To fetch the file to your development computer use the adb tool that comes with the Android SDK. On my Windows machine I did something like this.


C:\Program Files (x86)\Android\android-sdk\platform-tools>adb pull /sdcard/othello_profiling.trace c:\temp\othello_profiling.trace
126 KB/s (2266911 bytes in 17.491s)


The tool traceview can interprete the file.

C:\Program Files (x86)\Android\android-sdk\tools>traceview.bat c:\Temp\othello_profiling.trace


Voila! You get a profiling view similar to what you get from common profilers like JProfiler, hprof etcetera. Here you can see each methods execution time and which parents and children methods it has connection to and much more.


Theres more you can do with the trace file. Traceview can also show you each threads exectution and calls in chronological order. You can simple zoom in on the interesting parts.



You may also want to try the tool dmtracdedump to create graphs over your call stack. See the Android documentation for more information.

30 comments:

  1. Your contents are too simple to read and easy to understand.
    -----------------------------------------------------------------------------
    Android Application Developer India & Android Application Development Company

    ReplyDelete
  2. Great Post Thanks For Sharing

    For More Information You Can Visit This Website Android Application Development Solutions

    ReplyDelete
  3. Wow this is a great post and Such a nice information you shared in this article, I like it. app development in dubai

    ReplyDelete
  4. That’s a great post. very informative article.

    For VoIP Dialers, WebRTC development, Digital Marketing and Social Media just try visiting our site!
    Digital Communications Specialist
    Our Main Services>Web Based Chat

    ReplyDelete
  5. We specialized in quality VoIP dialer development, VoIP dialer for CRM and SIP dialer development, audio and video calling and chat development services.

    VoIP Dialer Development
    Best Chat Development

    ReplyDelete
  6. Nice Blog!
    Facing error while using QuickBooks get instant solution with our QuickBooks experts.Dial +1-855-533-6333 QuickBooks Enterprise Support Phone Number

    ReplyDelete
  7. Wonderful blog you have shared over here, i like the way you presented it. Thanks and keep it up.

    WebRTC Application Development in India

    ReplyDelete
  8. Hi, constantly i used to check website here early in the daylight,

    ReplyDelete
  9. Software play an vital role in multi level marketing, Get your mlm software simply contact us we are the best mlm software company in lucknow.

    mlm software development company in lucknow
    mlm software company in lucknow




    ReplyDelete
  10. The ‘Signature IT software Designers Pvt. Ltd’ based in Lucknow is an internationally trusted IT Company excelling in microfinance software development.
    Microfinance software development lucknow
    microfinance software solutions


    ReplyDelete