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
Tweet

More Decks by Rebecca Franks

Other Decks in Technology

Transcript

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

    View Slide

  2. #DevConf @riggaroo
    Rebecca Franks
    Android Developer & Google Developer Expert
    DVT / DStv
    www.riggaroo.co.za
    @riggaroo

    View Slide

  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)

    View Slide

  4. #DevConf @riggaroo
    What went wrong?

    View Slide

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

    View Slide

  6. #DevConf @riggaroo
    Types of Performance
    Issues

    View Slide

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

    View Slide

  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)

    View Slide

  9. @riggaroo
    #DevConf
    Dropped Frames, Stuttering &
    Slow animations
    60 fps = 16ms per frame

    View Slide

  10. @riggaroo
    #DevConf
    Draining a users battery

    View Slide

  11. #DevConf @riggaroo
    Pixel Pushin’
    Rendering Analysis

    View Slide

  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

    View Slide

  13. @riggaroo
    #DevConf
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    View Slide

  14. @riggaroo
    #DevConf
    Hierarchy Viewer
    • Visualises your app’s view
    hierarchy
    • Profiles rendering speed
    • Good for:
    • Simplifying view hierarchy
    • Finding rendering
    performance bottlenecks

    View Slide

  15. @riggaroo
    #DevConf

    View Slide

  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

    View Slide

  17. #DevConf @riggaroo
    Where did I put that
    object again?
    Memory Analysis

    View Slide

  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

    View Slide

  19. @riggaroo
    #DevConf

    View Slide

  20. @riggaroo
    #DevConf
    No Memory Leak
    Memory Leak

    View Slide

  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

    View Slide

  22. @riggaroo
    #DevConf

    View Slide

  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

    View Slide

  24. #DevConf @riggaroo
    Does not compute
    Compute Analysis

    View Slide

  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

    View Slide

  26. @riggaroo
    #DevConf

    View Slide

  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

    View Slide

  28. @riggaroo
    #DevConf

    View Slide

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

    View Slide

  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

    View Slide

  31. @riggaroo
    #DevConf

    View Slide

  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

    View Slide

  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!

    View Slide

  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

    View Slide

  35. Thank you!
    Questions?
    @riggaroo
    +RebeccaFranksSA
    http://riggaroo.co.za
    @riggaroo
    Rate me
    www.devconf.co.za/rate

    View Slide