26
1 Power optimization for Android Xavier Hallade, Developer Evangelist at Intel Corporation Google Developer Expert for Android @ph0b – ph0b.com – +XavierHallade

Power optimization for android

  • Upload
    ph0b

  • View
    448

  • Download
    5

Embed Size (px)

Citation preview

Page 1: Power optimization for android

1

Power optimization for AndroidXavier Hallade, Developer Evangelist at Intel CorporationGoogle Developer Expert for Android@ph0b – ph0b.com – +XavierHallade

Page 2: Power optimization for android

2

Power optimization for AndroidXavier Hallade, Developer Evangelist at Intel CorporationGoogle Developer Expert for Android@ph0b – ph0b.com – +XavierHallade

Page 3: Power optimization for android

3

Power optimization for Android - Agenda

Introduction

Understanding power consumption

Measuring power consumption

Optimizing your app

Q&A

Page 4: Power optimization for android

4

Understanding power consumption

Page 5: Power optimization for android

5

Understanding power consumption

Page 6: Power optimization for android

6

Understanding power consumption – for Android devices

Complex systems running on batteryDisplay, Input devices, Sensors, Connectivity, Camera, CPU, GPU, RAM, Storage, A/V decoder, power subsystem

Battery lifetime is one of the main complaints from users

Demand for more performance or less power consumption is driven by new use casesNo one could apply Moore’s law to battery capacity yet…

Page 7: Power optimization for android

7

Power Management – by the OS

Specific applications lifecycleE.g. pausing applications not in foreground.

Project Volta…

but applications have to be optimized for power as well!

Page 8: Power optimization for android

8

What is using power ?

1) Network calls, data transfersbig chunks of data at random times, for

data sync, analytics, ad networks…

2) Location and sensorsalways-on, highest accuracy, maximum rate

3) Inefficient codeuseless work, bad data structures…

Display

45%

Network

30%

CPU

9%

Other

16%

Network

55%

CPU

16%

Other

29%

Page 9: Power optimization for android

9

Measuring power consumption

Page 10: Power optimization for android

10

Measuring power consumption

Page 11: Power optimization for android

11

Measuring power consumption - Hardware

Simply measuring wall power consumption-> not enough

Data Acquisition devices help to monitor multiple power rails

Development board needed

No relation to software state

Page 12: Power optimization for android

12

Measuring power consumption - Software

Often indirect measurement

Need to monitor multiple components:Power statesWakeups

Your app is integrated with the system, impacted by other apps, network states, user behavior…

Actual numbers are hard to get

Page 13: Power optimization for android

13

Intel® Energy Profiler

• Gives exact information on CPU and GPU states and hardware interruptions

• Part of Intel® System Studio• Needs a kernel module

• Only possible on Intel development devices and Intel public devices which support open source builds

https://software.intel.com/en-us/intel-energy-profiler

Page 14: Power optimization for android

14

Battery Historian 1.0 – for devices running 21+

A simple python script generating a HTML report, no readme.

adb shell dumpsys batterystats --enable full-wake-historyadb shell dumpsys batterystats --reset# use your device for some timeadb bugreport > bugreport.txt

./historian.py bugreport.txt > historian_report.html

Page 15: Power optimization for android

15

Battery Historian 2.0

~140 lines readme. Dependency on: Go, Python, Git, Closure compiler, the InternetGives you a local webserver running Battery Historian v2.0 But it’s worth the pain.

Page 16: Power optimization for android

16

Battery Historian 2.0

Page 17: Power optimization for android

17

Battery Historian 2.0

Page 18: Power optimization for android

18

Optimizing your app

Page 19: Power optimization for android

19

Optimizing your app

Page 20: Power optimization for android

20

Optimizing network calls – part 1

Allow for OS timer coalescing:AlarmManager.set()/setInexactRepeating()use a SyncAdapterbetter: android.app.job.JobScheduler (21+) or

GCMNetworkManager (requires Google Play Service, not even GCM)setRequiresCharging/setRequiresIdle/setRequiredNetwork/setExecutionWindow

Don’t poll. Don’t hold TCP connections.

OVERUSE OF INTERNET

MAY CAUSE

SLEEP DEPRIVATION AND

WASTE OF TIME*

*Yes, it’s about devices and apps.

Page 21: Power optimization for android

21

Optimizing network calls – part 2

Prefetch data…but minimize the size of your data transfers

Batch data transfers

Schedule work at times with a wall plugand Wifi connection

Page 22: Power optimization for android

22

Optimizing sensors and other data use

Sensors: set sampling to SENSOR_DELAY_NORMAL (200ms) or SENSOR_DELAY_UI (60ms).

Prefer low power sensors: accelerometer and no gyroscope

GPS: use low accuracy (LocationManager.NETWORK_PROVIDERinstead of LocationManager.GPS_PROVIDER)

Disable receivers when not needed:ComponentName receiver = new ComponentName(context, myReceiver.class);PackageManager pm = context.getPackageManager();pm.setComponentEnabledSetting(receiver,

PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)

Page 23: Power optimization for android

23

Optimizing CPU usage

Race to idle

Batch work

Maximize data locality, use efficient algorithms, hardware accelerators

Profile using Systrace (part of Android tools) and Intel® VtuneAmplifier (part of system studio)

Page 24: Power optimization for android

24

Summary

Power optimization on typical Android devices requires understanding of power consumption of all components

Batch, cache, avoid network requests and CPU work, optimize and schedule it properly.

Measure and analyze your app using software tools:https://github.com/google/battery-historianhttp://intel.ly/system-studio

Want more material? Look at Android Performance Patterns Videoshttp://bit.ly/1KDLqUu

Page 25: Power optimization for android

25

Thank [email protected]@ph0b – ph0b.com – +XavierHallade

Page 26: Power optimization for android

27

Installing and Running Battery Historian 2.0 on Windows

http://ph0b.com/battery-historian-2-0-windows/