The document discusses various ways mobile app developers can lower the power consumption of their apps without affecting performance. It begins by explaining that most apps do not efficiently use system resources like the processor, cellular radio, and display, wasting power and reducing battery life. It then provides tips for optimizing specific areas of power consumption, such as using the cellular radio efficiently by bundling network traffic, offloading tasks to hardware accelerators like the DSP to reduce CPU usage, and managing the display to minimize brightness. The document stresses that measuring power consumption is key, and provides tools developers can use to profile and optimize the power impact of their apps.
Precise and Complete Requirements? An Elusive Goal
How to Lower App Power Usage Without Slowing Performance
1. How to lower the power consumption of
your app, without affecting performance
Rick Schwartz
Qualcomm Technologies, Inc.
developer.qualcomm.com
mostly-tech.com
2. About this session
•Most mobile apps do not use the processor, cellular radio
and other system resources efficiently
• This wastes power, which has a negative effect on battery
life
•It’s easy to measure power consumption. If you can
measure it, you can act on it
•Solutions to common power problems are readily available
•Better battery life = happier users
4. Why long battery life is such a challenge
Hardware specs have increased dramatically, but batteries have not
Source: Samsung.com/us website
Samsung Galaxy SIII
Samsung Galaxy S6
5. So, where does the power go?
Source: Android Power Profile for the Nexus 6 smartphone. Data provided by device
manufacture. Current converted to power
#1
#3
#2 CPU
#4
#5
#6
6. How to get a power profile for any phone
•Read up on Android Power Profiles:
https://source.android.com/devices/tech/power/index.html
•Where to find one on your device:
platform/frameworks/base/core/res/res/xml/power_profile.xml
•There’s also an app for this
•Values are displayed in current
P = I x V (battery voltage)
Power Profile app on Google Play
8. Measuring power using Trepn™ Profiler
Launch Trepn, go to Settings
and select Battery Power
Check “Acquire Wakelock to
keep the processor awake
Select an app to profile
1 2 3
Source: Trepn Profiler screenshots. Trepn is a product of Qualcomm Technologies Inc.
9. Measuring power using Trepn Profiler
Source: Trepn Profiler screenshots. Trepn is a product of Qualcomm Technologies Inc.
4 Select how to view the power data
10. Other software options are available
Android 5.0 Battery app GSam Battery Monitor Pro GameBench Power Tutor
11. If you can measure it, you can act on it
•First, measure the power of your device idle with the
screen on and off
•Next, measure the average power of your app when it’s
idle and in-use
•Compare the power consumption of your app to other
similar apps
•Try different things:
- Does code A or code B consume more power?
12. Inserting markers into your code
Trepn Profiler’s application states help identify the cause of power spikes
Step 1: Insert application state markers into your code
Step 2: Look for spikes in Trepn’s graph
view. Determine which section of code they
occur in
Source: Trepn Profiler 5.0 screenshots
Step 3: Make changes to your code, and look at the average
power readings for each state in Trepn’s Stats view
13. Reading the power consumption from the power management IC results in a strong
correlation between system resource usage and the power used
Source: Trepn Profiler 5.0 running GLBench
The advantage of direct power measurement
14. Are software power measurements accurate?
The chart shows how Trepn’s power readings compare to a Monsoon Power Monitor
Source: Qualcomm internal power measurements of a Nexus 6 running Trepn software at various screen brightness levels
15. How to perform automated testing
A simple example how this can be done
Source: Trepn Profiler 5.0 screenshot
16. Making intelligent decisions
Source: Trepn screenshots of Nexus 5 running MX Player
Video playback using S/W decoder Video playback using H/W decoder
43% less power consumedAlmost 3x more CPU load
Trepn shows how much power is saved when using hardware decoding
17. Pros and cons of software and hardware power
measurement
Software Power Measurement
• Much easier – Doesn’t require modifications to the battery or phone
• More portable – Doesn’t require a cable connection; Supports mobile use
cases
• Capable of per-rail power measurements for hardware blocks
• Not every device supports direct power measurement
Hardware Power Measurement
• More accurate - Off-target, so it doesn’t consume processor cycles
• Often provides more detailed and customizable graphs
• Misses less spikes - Capable of higher sample rates
18. Measuring per-rail power consumption
Snapdragon development tablets are available from
• The Snapdragon 805 (8084) MDP displays power for the CPU, Camera, Digital Core, GPU,
Internal Memory, LCD Backlight, SD Card and WLAN/Bluetooth
• The Snapdragon 810 (8994) MDP displays power for the CPU Cores 0-3, CPU Cores 4-7,
GPU, LCD Backlight, Front Camera, Rear Camera, System Memory, Internal Memory/SD
Card, Wi-Fi/Bluetooth, Sensors and USB
Power delta before photo taken Power delta after photo taken
Source: Trepn Profiler 5.0 screenshots
Qualcomm Snapdragon is a product of Qualcomm Technologies, Inc.
19. 1. Direct connection to the battery
contacts via mini-grabber cables
2. Using flat insulated copper tape
3 different ways to connect your device to
power measurement hardware*
3. Circuit board modification
Sources: Nexus photos taken by the authorNote: Any connection to power measurement hardware is done at your own risk
20. Power Measurement Best Practices
1. Remove your USB cable – You cannot display accurate power readings when your
mobile device is charging or connected to a computer. Tip: Use ADB over Wi-Fi
2. Make sure the CPU in the device capturing the power data stays awake
3. Minimize background processes – Open the Apps manager, go to Running and close
all remaining unneeded apps and stop all unneeded services
4. Focus on what you’re measuring – Turn off everything that is not related to what
you want to measure (e.g., Wi-Fi, Mobile networks, Location (GPS), Bluetooth,
Google Now, etc.)
5. Minimize the impact of the screen – The screen is the biggest consumer of power.
Turn the brightness down to the minimum possible level or turn it off
6. More power measurement Best Practices are available here
24. Many apps don’t use the cellular radio efficiently
Multiple apps acting independently creates
network signaling congestion
• Apps pull notifications, updates and message users -
- even when a phone is not being used
• Most news and social networking apps wake up your
device at least four times an hour
Source: The Smartphone Challenge: Signaling Congestion and Power Consumption - Gerardo Giaretta - Qualcomm
25. Why is this a problem?
• A dormant cellular radio consumes
about 10-12 mA
• When data is sent or received, the
radio comes up and goes into an
active state, consuming 250-350mA
• When not sending data, the radio
drops down to idle, but still
consumes about 30mA to 150mA
• After a timeout of 8 to 15 seconds,
the radio finally goes back to a
dormant state
Source: Qualcomm Technologies Inc. internal testing
26. Is your app is using the cellular radio efficiently?
Use AT&T’s Application Resource Optimizer (ARO )to find out
You can download it here: https://developer.att.com/application-resource-optimizer/get-aro
Source: Screen image used with permission
27. What else can you do with ARO?
• Collects traces from a test device or Android emulators
• Provides detailed recommendations how to fix problems
• Open-source code can be integrated into automated test suites
Source: Screen image used with permission
29. Real world cellular radio power consumption
1. Radio goes from idle to transmitting
- Power increase >800mW
2. Radio back to idle
- Power decrease >800mW
3. Radio goes from idle to transmitting
- Power increase >1200mW
4. Radio goes from idle to transmitting
- Power increase >600mW
5. Radio goes from idle to transmitting
- Power increase <500mW
6. Radio goes from idle to transmitting
- Power increase <500mW
7. Radio goes from idle to dormant
- Power decrease ~600mW
8. Radio goes from idle to transmitting
- Power decrease ~500mW
1 2 3 4 5 6 7 8
Source: Qualcomm Technologies Inc. internal testing using Trepn Profiler to graph the
mobile data states of a Nexus 7 with LTE accessing data from Google Drive
30. Charts make it easier to correlate actions with
system resource consumption
Source: Trepn plug-in for Eclipse running on an active Samsung Galaxy Note 3
31. Don’t forget to check idle behavior
All 4 cores are
active here
GPU active here
250mA to 350mA of
power is used here Even though the cellular radio is idle, it still consumers up to 150mA of power
GPS active here
Wi-Fi active
here
Source: Trepn plug-in for Eclipse running on an idle Samsung Galaxy Note 3
32. Make changes and see the impact
Mobile data transmitted before Google Now turned off
Mobile data transmitted after Google Now turned off
Google Search app
Source: Trepn plug-in screen excerpts
Small changes can make a big difference in cellular radio usage
34. How to efficiently use the cellular radio
1. Connect less often – After you transmit the radio stays on for 10+ sec1
2. Push, don’t poll – Send packets and wait to see if they respond. Use
the Google Cloud Messaging system (GCM) API instead. Have it send you
data when things have changed. Specify how often items are delivered2
3. Don’t continuously scan1
1. Create timeouts appropriately when scanning for Wi-Fi networks or GPS signals
4. Offer ad-free versions – Apps without ads connect to the network much
less often
5. Use analytics wisely1
1. Capture data locally and group transmissions to your server. Extend the time
between transmissions
1 Source: AT&T “Tips to Increase Battery Life Handout” from AnDevCon 2013
2 Source: Google Developer Advocate Colt McAnlis at from “Efficient battery use on mobile” at “Perf Like a Pirate.”
35. Analytic and ad services vary greatly
Source: Data provided by Crittercism
Error rates and response times by top services
Findings
• Google Analytics has lowest error
rate (0.1%); error rate is percent of
errors per number of service calls
made
• Of top public services, Google
Analytics has lowest average latency
Takeaway
• Even top services like Google
Analytics and Facebook experience
latency and error rates
• Teams must manage every aspect of
mobile app performance, including
third-party services
36. Follow the leader(s)
BBC News App (23 SDKs) BBC website (38 SDKs)
Source: Data provided by MixRank
See which SDKs popular apps and sites use
Apache Commons ChartBeat
Simple Logging Façade for Java Facebook Open Graph
Android Volley Adobe Analytics/Omniture
OpenUDID Bing Webmaster Tools
Omniture Effective Measure
17,289 7,87329,386 46,675
12,475 4,47225,905 38,380
9,166 5,1414,285 13,451
3,296 1,3996,657 9,953
1,196 396794 1,990
Current installs Uninstalls Total installs Developers
Current installs Uninstalls Total installs Developers
Current installs Uninstalls Total installs Developers
Current installs Uninstalls Total installs Developers
Current installs Uninstalls Total installs Developers
36,641 189K Dec 4, 2013
5,880,253 402K
224,454 1M
813,284 109
8,735 975K
Websites Times Seen First Seen Last Seen
Websites Times Seen First Seen Last Seen
Websites Times Seen First Seen Last Seen
Websites Times Seen First Seen Last Seen
Websites Times Seen First Seen Last Seen
May 12, 2015
Jan 29, 2012 May 12, 2015
Jan 29, 2012 Apr 20, 2015
Apr 10, 2015
Apr 10, 2015
Jan 29, 2012
Jan 29, 2012
37. How to efficiently use the cellular radio
6. Don’t continuously stream – Download streams in chunks1
7. Use the JobScheduler APIs that are part of Android 5.02
1 Source: AT&T “Tips to Increase Battery Life Handout” from AnDevCon 2013
2 Google I/O 2014 - Introduction to Project Volta by (Meghan Desai and Matthew Jay Williams)
Before
After
38. Bundling traffic reduces overhead-to-data ratio
Source: The Smartphone Challenge: Signaling Congestion and Power Consumption - Gerardo Giaretta - Qualcomm
39. Use Battery Historian to view wakelocks & radio usage
One-time setup in order to run Battery Historian
1. Download and install Python 2.7 (if it’s not already installed)
2. Download battery-historian from GitHub
3. Extract “historian.py” from the zip file and copy it to the Python2.7 directory
Running Battery Historian
Type the following into the command prompt after connecting to an Android 5.x device:
40. How to efficiently use the cellular radio
6. Wait for the right connection – Avoid sending packets on slow
cellular connections. Wait until you are on Wi-Fi, if possible.
Some apps provide users with
the option to only upload when
charging. Choice is good.
Source: Microsoft OneDrive screen capture
41. Why should you wait for Wi-Fi?
Source: Qualcomm tests. Monsoon power measurement from a download of 3 apps
over a 1-2 bar 3G/4G cellular connection using a Verizon Galaxy Note 3
More power is consumed
• Power before download 723 mW
• Power during download 3279mW
• Radio power use: ~2556mW
• Downloading large files over
Wi-Fi consumes less than half
the power
• Estimated battery life dropped
from 15.8 hours to 5.1 hours
Mobile data wasted: 67.68MB
Time wasted: 11 minutes
Downloading data over a cellular radio with a
weak signal requires more power
43. How to tell if your app keeps the processor from
going to sleep?
Using Wakelock Detector (WLD) to identify processor sleep problems
CPU Wakelocks Wakeup Triggers
• A recent study found that 23% of
apps have problems with
wakelocks. This can drain the
battery of an inactive handset in as
little as 5 hours
• Wakelocks do have a place, because
your processor goes to sleep when
it’s idle. Apps need wakelocks for
alarms, GPS location and to wake
up the processor to check for new
messages.
44. An easy way to spot excess resource consumption
Processor stats can be viewed by going to Settings > Battery and
selecting your application
Source: Android 5.0 battery stats screenshots
If your app is not in the foreground, there should be a good reason why it’s keeping the processor awake and consuming data
45. How to avoid keeping the processor awake
1. Do not acquire PowerManager.Wakelocks unless you really need them
Battery life will be significantly affected by the use of this API
• Use the minimum levels needed
• Release wakelocks as soon as possible
2. Consider using AlarmManager in situations when you want to have your
application code run at a specific time
• Beginning with KitKat, the OS shifts alarms to minimize wakeups and
battery usage
3. For normal timeouts, it’s easier and more efficient to use Handler
46. Does your app manage the display in a power
efficient manner?
47. Managing display power efficiently
1. Full wakelocks keep your screen from turning off.
To keep the display lit when your app is in the
foreground, use FLAG_KEEP_SCREEN_ON
2. There is a direct correlation between screen
brightness and power consumption
3. Offer a dark theme option. Gray or black
backgrounds consume less than half the power of
a white background
Source: Qualcomm average power measurements using a Monsoon Power Monitor of the Google New & Weather app on a Samsung Galaxy Note 3 with the display at 50% screen brightness
Source: Qualcomm tests of Nexus 6 average power consumption using a Monsoon Power monitor
49. Some apps don’t use resources efficiently
Source: Trepn Profiler 5.0 screenshots
50. Is your app CPU bound or GPU bound?
Source: Trepn Profiler 5.0 screenshots
51. Does it use all available CPU cores?
Source: Trepn Profiler 5.0 screenshots
52. Heterogeneous computing is key
Run the right task on the right processing engine
Source: Qualcomm internal power tests using QEPM software eQualcomm SeeMore demo using the MARE SDK
a product of Qualcomm Technologies, Inc.
53. Qualcomm Multicore Asynchronous Runtime
Environment
MARE is a developer programming library, API and
runtime system for heterogeneous programming
55. Benefits of offloading to DSP
• Extends music playback time to 60 hours. A 50% increase.
• When batching sensor data, 8 hours of sleep tracking only
uses 10 to 20% of available battery life
• Running FastCV™ facial detection on DSP instead of the CPU
uses 32% less power
1. Audio playback done using a Nexus 5 using Bluetooth headphones and the display off.
2. Sensor batching done on Samsung Gear Live with Sleep as Android app
3. Power measured at the device battery. Source: Qualcomm Technologies Inc. internal measurements
57. How to save power when using the GPS
1. Make sure you don’t take a GPS fix when
it’s not needed
2. Use coarse GPS fixes when possible,
because they require less power
3. Let LocationManager find the best provider
4. Have a timeout if you can’t find a satellite
5. Disable GPS when your app sleeps to save
power
6. Make it easy for users to disable location
tracking without crippling their device
Source: Android 5.0 Location Settings on Samsung device
58. Perf Matters Too!
Use tools like these to confirm your perf hasn’t changed
•ARM Streamline, GameBench, Adreno Profiler, Trepn
Profiler, PerfMon, Intel INDE or Qualcomm® Snapdragon™
Profiler
Real-time or post-capture viewing
and analysis of a wide range of
system and app level power,
performance, thermal and
network usage metrics
Coming Soon: Snapdragon Profiler
Qualcomm Snapdragon and Qualcomm Adreno are products of Qualcomm Technologies, Inc.
59. Recap of power saving tips
• Use wakelocks only when necessary
• Close TCP sockets when done. Otherwise, you unnecessarily bring up the network just
to tear down. This simple fix can reduce network power up to 20%
• Group network activity when possible
• Keep performance headroom for additional power savings. Saves significantly in overall
system power.
- Optimize your app to run at 60fps, but then frame-rate limit it to lower rate (ideally
30fps). This cuts GPU, CPU and memory utilization and hence related power by 50%.
Also guarantees smooth consistent UX flow at same framerate
• Avoid rendering at full native display resolutions. This saves GPU power.
- Test rendering applications at lower resolutions
- Games should ideally render at 1080p or lower resolutions natively
61. Helpful mobile power-related links
• Software power measurement best practices – Rick Schwartz
• Hardware power measurement best practices – Rick Schwartz
• Battery Drain and Networking – Colt McAnlis
• What These Apps Did May Shock You - Doug Sillars
• Understanding Battery Drain on Android – Colt McAnlis
• How to power profile an app using hardware – Rick Schwartz
• Battery Drain and WakeLocks – Colt McAnlis
• AT&T Application Resource Optimizer demo - Doug Sillars
• Monsoon Power Monitor - Tips & Tricks – Rick Schwartz