Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

#DevConf @riggaroo What went wrong?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

#DevConf @riggaroo Types of Performance Issues

Slide 7

Slide 7 text

@riggaroo #DevConf Application not responding (ANR)

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

@riggaroo #DevConf Draining a users battery

Slide 11

Slide 11 text

#DevConf @riggaroo Pixel Pushin’ Rendering Analysis

Slide 12

Slide 12 text

@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

Slide 13

Slide 13 text

@riggaroo #DevConf

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

@riggaroo #DevConf

Slide 16

Slide 16 text

@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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

@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

Slide 19

Slide 19 text

@riggaroo #DevConf

Slide 20

Slide 20 text

@riggaroo #DevConf No Memory Leak Memory Leak

Slide 21

Slide 21 text

@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

Slide 22

Slide 22 text

@riggaroo #DevConf

Slide 23

Slide 23 text

@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

Slide 24

Slide 24 text

#DevConf @riggaroo Does not compute Compute Analysis

Slide 25

Slide 25 text

@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

Slide 26

Slide 26 text

@riggaroo #DevConf

Slide 27

Slide 27 text

@riggaroo #DevConf NimbleDroid • Automated performance analysis tool • Easy to use - upload your APK and get a report • Measures cold start time • https://nimbledroid.com

Slide 28

Slide 28 text

@riggaroo #DevConf

Slide 29

Slide 29 text

#DevConf @riggaroo Save the Battery! Battery Analysis

Slide 30

Slide 30 text

@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

Slide 31

Slide 31 text

@riggaroo #DevConf

Slide 32

Slide 32 text

@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

Slide 33

Slide 33 text

@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!

Slide 34

Slide 34 text

@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

Slide 35

Slide 35 text

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