Upload
ph0b
View
448
Download
5
Tags:
Embed Size (px)
Citation preview
1
Power optimization for AndroidXavier Hallade, Developer Evangelist at Intel CorporationGoogle Developer Expert for Android@ph0b – ph0b.com – +XavierHallade
2
Power optimization for AndroidXavier Hallade, Developer Evangelist at Intel CorporationGoogle Developer Expert for Android@ph0b – ph0b.com – +XavierHallade
3
Power optimization for Android - Agenda
Introduction
Understanding power consumption
Measuring power consumption
Optimizing your app
Q&A
4
Understanding power consumption
5
Understanding power consumption
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…
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!
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%
9
Measuring power consumption
10
Measuring power consumption
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
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
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
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
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.
16
Battery Historian 2.0
17
Battery Historian 2.0
18
Optimizing your app
19
Optimizing your app
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.
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
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)
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)
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
25
Thank [email protected]@ph0b – ph0b.com – +XavierHallade
27
Installing and Running Battery Historian 2.0 on Windows
http://ph0b.com/battery-historian-2-0-windows/