of bytes, cycles and battery life

31
Of Bytes, Cycles and Battery Life

Upload: mario-zechner

Post on 13-Jul-2015

5.908 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Of Bytes, Cycles and Battery Life

Of Bytes, Cycles and Battery Life

Page 2: Of Bytes, Cycles and Battery Life

Who am I?

@badlogicgameshttp://www.badlogicgames.com

[2]

[1]

Page 3: Of Bytes, Cycles and Battery Life

• How to reduce your APK size

• Memory Analysis Tools

• Performance Analysis Tools

What i‘ll talk about

Page 4: Of Bytes, Cycles and Battery Life

• Reduce asset size– pngcrush your PNGs [3]– SVG (YMMV) [4]– lower bit-rates for audio

• Reduce code size– Remove unnecessary dependencies!– Proguard, for Class files [5] [6]– Dexguard, for Dex files [7]

How to reduce your APK size

Page 5: Of Bytes, Cycles and Battery Life

• Multiple-APKs to the „rescue“ [8]– One APK per screen density– One APK per texture compression algorithm– Use Google Play filters– Easier with new Android Gradle build system

• APK Expansion files [9]– hosted by Google

• Roll your own „Expansion files“– Avoid if you can!

„But i can‘t reduce my APK size“

Page 6: Of Bytes, Cycles and Battery Life

Memory Analysis Tools

• „But we have a Garbage Collector!“– You can still „leak“ memory

– Nasty static vars referencing unused objects

– Hidden object references

– Native memory allocated by Java classes

• If you write games, GC kills your steadyframerate

Page 7: Of Bytes, Cycles and Battery Life

DDMS [10] Heap View

Page 8: Of Bytes, Cycles and Battery Life

DDMS Allocation Tracker

Page 9: Of Bytes, Cycles and Battery Life

HPROF/Eclipse MAT [11]

• Select the process

• Click

• Save to a location of your choice

• Convert to „real“ HPROF file

• Open in Eclipse MAT [12]

Page 10: Of Bytes, Cycles and Battery Life

HPROF/Eclipse MAT

Page 11: Of Bytes, Cycles and Battery Life

HPROF/Eclipse MAT

Page 12: Of Bytes, Cycles and Battery Life

HPROF/Eclipse MAT

Page 13: Of Bytes, Cycles and Battery Life

Performance Analysis Tools• Why do we want to analyse?

– Jerky animations– Do less, conserve battery– Better user Experience

• What do we want to analyse?– Time spent in Java code– Time spent in Native code– Time spent drawing stuff

Page 14: Of Bytes, Cycles and Battery Life

Before we start...

• Never use the emulator!

– Ever, think of the kittens

• Identify hotspots in your app, not in microbenchmarks

• Only spend time if you have a real problem

Page 15: Of Bytes, Cycles and Battery Life

Java Profilers• DDMS

– Quite capable method level profiler– Good enough for 99% of use cases– Works with any Android version

• 4.1+ Profiling tools– Systrace [13], More powerful, also tracks OS calls

• Needs root and Android 4.1+

– We‘ll check out the graphical parts later

Page 16: Of Bytes, Cycles and Battery Life

DDMS

• Start app

• Navigate to problematic activity, hit

• Wait a bit, hit

• View profiling data– Ignore absolute time, only care for relative timings

– Ignore trivial getters/setters, instrumentation messeswith timings

Page 17: Of Bytes, Cycles and Battery Life

DDMS

Page 18: Of Bytes, Cycles and Battery Life

Native Code Profilers• Android NDK Profiler [14]

– Not an official NDK tool– Setup a bit involved

• Device specific CPU profilers– NVIDIA Nsight [15], ...

• Roll your own– Instrument manually– Track down hotspots

Page 19: Of Bytes, Cycles and Battery Life

Graphics Profilers

• What do we analyse?– Overdraw, your biggest enemy

– Draw calls, your second biggest enemy• Use DDMS/systrace

– Related to memory• Textures on VRAM (which is usually RAM)

• Bitmaps in RAM

Page 20: Of Bytes, Cycles and Battery Life

Graphics Profilers

• 4.1+ Profiling tools

• GPU Vendor Specific

– NVIDIA [16], Qualcomm [17], Imagination Technologies [18]

– Outside of scope of this talk

Page 21: Of Bytes, Cycles and Battery Life

Visualize Overdraw [19]

Page 22: Of Bytes, Cycles and Battery Life

Visualize Overdraw

• Normal Color – 0 Overdraw

• Blue – 1x Overdraw

• Green – 2x Overdraw

• Light Red – 3x Overdraw

• Dark Red – +4x Overdraw

Page 23: Of Bytes, Cycles and Battery Life

Visualize Overdraw

• Hierarchy View [20]

• Window -> Open Perspective -> Other...

Page 24: Of Bytes, Cycles and Battery Life

Visualize Overdraw

Page 25: Of Bytes, Cycles and Battery Life

Visualize Overdraw

• Tracer for OpenGL [21]

• Window -> Open Perspective -> Other ...

• Click

• Enter package name

• Wait

Page 26: Of Bytes, Cycles and Battery Life

Visualize Overdraw

Page 27: Of Bytes, Cycles and Battery Life

Visualize Overdraw

Page 28: Of Bytes, Cycles and Battery Life

Closing Words

• So much to tell, so little time

• See Dalvik Performance Tips [22]

• Read all references

– Your users will thank you for excellent battery lifeand buttery smooth UIs

Page 29: Of Bytes, Cycles and Battery Life

FIN

Thanks for Listening

Questions?

Page 30: Of Bytes, Cycles and Battery Life

References[1] http://www.amazon.com/Beginning-Android-Games-Mario-Zechner/dp/1430246774

[2] http://libgdx.badlogicgames.com/

[3] http://pmt.sourceforge.net/pngcrush/

[4] https://code.google.com/p/svg-android/

[5] http://developer.android.com/tools/help/proguard.html

[6] http://proguard.sourceforge.net/index.html

[7] http://www.saikoa.com/dexguard

[8] http://developer.android.com/google/play/publishing/multiple-apks.html

[9] http://developer.android.com/google/play/expansion-files.html

[10] http://developer.android.com/tools/debugging/ddms.html

[11] http://android-developers.blogspot.co.at/2011/03/memory-analysis-for-android.html

Page 31: Of Bytes, Cycles and Battery Life

References[12] http://www.eclipse.org/mat/

[13] http://developer.android.com/tools/help/systrace.html

[14] https://code.google.com/p/android-ndk-profiler/

[15] http://www.nvidia.com/object/nsight.html

[16] https://developer.nvidia.com/tegra-profiler

[17] https://developer.qualcomm.com/mobile-development/mobile-technologies/gaming-graphics-optimization-adreno/tools-and-resources

[18] http://www.imgtec.com/powervr/insider/sdkdownloads/

[19] http://www.curious-creature.org/2012/12/01/android-performance-case-study/

[20] http://developer.android.com/tools/debugging/debugging-ui.html

[21] http://developer.android.com/tools/help/gltracer.html

[22] http://developer.android.com/training/articles/perf-tips.html