Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Performance Testing Tools in Android - DevConf

Performance Testing Tools in Android - DevConf

Developing an app for the fragmented Android ecosystem can be a difficult task. Problems such as small amounts of RAM or low performance GPUs on some devices makes the job of an Android developer a difficult one. In this talk, we will discuss various tools (and how to use them) to ensure your app isn’t slow or dropping frames. Enabling your app to run smoothly across a larger set of devices.


Rebecca Franks

March 08, 2016


  1. #DevConf @riggaroo Performance Testing Tools in Android Rebecca Franks @riggaroo

  2. #DevConf @riggaroo Rebecca Franks Android Developer & Google Developer Expert

    DVT / DStv www.riggaroo.co.za @riggaroo
  3. @riggaroo #DevConf Overview • What went wrong? • Types of

    Performance Issues • Analysing Performance issues • Pixel Pushin’ (Rendering Analysis) • Where did I put that object again? (Memory Analysis) • Does not Compute (Compute Analysis) • Battery Drain (Battery Analysis)
  4. #DevConf @riggaroo What went wrong?

  5. @riggaroo #DevConf “…slow…” “…laggy…” “…keeps freezing…” “…frustrating…”

  6. #DevConf @riggaroo Types of Performance Issues

  7. @riggaroo #DevConf Application not responding (ANR)

  8. @riggaroo #DevConf OutOfMemoryError (OOM) java.lang.OutOfMemoryError: Failed to allocate a 4308492

    byte allocation with 467872 free bytes and 456KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java: 988) at android.content.res.Resources.loadDrawableForCookie(Resources.java:2580) at android.content.res.Resources.loadDrawable(Resources.java:2487) at android.content.res.Resources.getDrawable(Resources.java:814) at android.content.res.Resources.getDrawable(Resources.java:767)
  9. @riggaroo #DevConf Dropped Frames, Stuttering & Slow animations 60 fps

    = 16ms per frame
  10. @riggaroo #DevConf Draining a users battery

  11. #DevConf @riggaroo Pixel Pushin’ Rendering Analysis

  12. @riggaroo #DevConf GPU Overdraw • Colour coding to show how

    many times each pixel is redrawn on the screen • Used for: • Reducing rendering overhead. 1x Overdraw 2x Overdraw 3x Overdraw 4x Overdraw
  13. @riggaroo #DevConf <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">

  14. @riggaroo #DevConf Hierarchy Viewer • Visualises your app’s view hierarchy

    • Profiles rendering speed • Good for: • Simplifying view hierarchy • Finding rendering performance bottlenecks
  15. @riggaroo #DevConf

  16. @riggaroo #DevConf Profile GPU Rendering • Quick visual representation of

    how much time it takes to render the frames of a UI window • 16-ms-per-frame benchmark. • Good for: • Quickly seeing how a UI window performs against the 16-ms-per- frame target. • Looking for spikes in frame rendering time
  17. #DevConf @riggaroo Where did I put that object again? Memory

  18. @riggaroo #DevConf Memory Monitor • Real time report on how

    much memory your app is using • Shows available memory & GC Events • Good for: • Quickly picking up OOM • If slowness is related to many GC Events
  19. @riggaroo #DevConf

  20. @riggaroo #DevConf No Memory Leak Memory Leak

  21. @riggaroo #DevConf Heap Viewer • Real-time what types of objects

    your app has allocated, how many, their sizes on the heap • Eclipse Memory Analyser has a few more advanced features • Good for: • Identifying memory leaks • Seeing how your app allocates & deallocates memory
  22. @riggaroo #DevConf

  23. @riggaroo #DevConf Avoiding memory leaks in Android • Never store

    a Context or View in a static variable. • Avoid non-static inner class declarations especially AsyncTasks/Threads • Don’t store strong references to Activity/View in your AsyncTasks or background threads • Always unregister listeners in the onPause() or onDestroy() methods
  24. #DevConf @riggaroo Does not compute Compute Analysis

  25. @riggaroo #DevConf Systrace • Captures & displays execution times of

    your application processes • Useful for diagnosing display issues when: • Slow to draw • Stutters during animation • App is keeping to 60fps
  26. @riggaroo #DevConf

  27. @riggaroo #DevConf NimbleDroid • Automated performance analysis tool • Easy

    to use - upload your APK and get a report • Measures cold start time • https://nimbledroid.com
  28. @riggaroo #DevConf

  29. #DevConf @riggaroo Save the Battery! Battery Analysis

  30. @riggaroo #DevConf Battery Historian • Collects battery data (batterystats) from

    device & converts into HTML visualisation • Good For: • Showing where and how processes are drawing current from the battery • Identifying tasks that can be deferred or removed • https://github.com/google/battery-historian • adb bugreport > logs.txt
  31. @riggaroo #DevConf

  32. @riggaroo #DevConf Avoiding Battery Drain •Avoid wake locks if possible

    •Defer operations that are not important •Batch operations to reduce mobile radio usage •Take advantage of the OS - JobScheduler API, SyncAdapter
  33. @riggaroo #DevConf Conclusion • Lots of other tools available: Network

    monitor, CPU monitor, TraceView, Allocation Tracker • Use ProGuard to strip out unused code (shrinkResources & minifyEnabled) • Your users matter (especially the ones with low end devices) • Fast App = Happy Users = Good Reviews = Happy devs!
  34. @riggaroo #DevConf Links • GPU Overdraw - http://developer.android.com/tools/performance/debug-gpu-overdraw/ index.html •

    Hierarchy Viewer - http://developer.android.com/tools/performance/hierarchy- viewer/index.html • GL Tracer - http://developer.android.com/tools/help/gltracer.html • Memory Monitor - http://developer.android.com/tools/performance/memory-monitor/ index.html • Fixing Memory leaks - http://riggaroo.co.za/fixing-memory-leaks-in-android- outofmemoryerror/ • Heap Viewer - http://developer.android.com/tools/performance/heap-viewer/ index.html • Systrace - http://developer.android.com/tools/help/systrace.html • NimbleDroid - https://nimbledroid.com/ • Battery Historian - https://github.com/google/battery-historian
  35. Thank you! Questions? @riggaroo +RebeccaFranksSA http://riggaroo.co.za @riggaroo Rate me www.devconf.co.za/rate