Note: An updated version of this document is located here: http://mostly-tech.com/2015/05/28/how-to-measure-the-power-consumption-of-your-mobile-app-using-free-software/
Software Power Measurement Best Practices
Here are some best practices for measuring power with Trepn Profiler:
- 1. Remove your USB cable – Trepn cannot display accurate power readings when your mobile device is charging or connected to a computer.
- Tip: Use ADB over Wi-Fi as described here, but be aware that this could cause power spikes that slightly increase your power averages.
- 2. Make sure your device reports accurate battery power – How do you know if your device reports accurate battery power? Battery power should appear in the list of Trepn data points in Settings. After you check the "Battery Power" data point, touch the Back button and "Profile System." Then go to "Stats" view." You should see a value in the average power column when your device is idle between 400mW to 1000mW for smartphones with 4” to 5” screens, 700 mW to 2500mW for 6” smartphones or 7” tablets, and 2000mW to 4000mW for 10” or larger tablets. Devices that are known to report accurate battery power are listed here. If you see readings like 0 or 1.80mW, your device cannot display accurate battery power.
- 3. Make sure your processor stays awake – Check “Acquire Wakelock while Profiling” on the Trepn General Settings page. Why this is needed: Without forcing the processor to stay awake, the average power reading was 1223mW. With a processor wakelock set, the power measured was 301mW. That’s a difference of over 900mW and shows how important this setting can be. When the processor goes to sleep, data collection in Trepn could temporarily stop, or power readings could drop to a level that is lower than it should be. When data collection stops for long periods, your average power readings could be higher than they should be, because Trepn will average any power spikes over a much shorter time period. The only time you should not check "Acquire wakelocks..." is when you are using Trepn to test whether an app is keeping the processor awake by holding a partial wakelock.
- 4. Minimize background processes/reduce system overhead – It’s not enough to close everything in Recent Apps. Open the Apps manager, go to Running and close all remaining unneeded apps, and stop all unneeded services. How much power can background apps consume? I measured 1043mW power on my idle tablet before I closed all unused apps. After closing unused apps the power consumed dropped to 726mW. That’s a 30% reduction in power. Recommendations:
- - Pure Android devices like the Nexus 5 or Nexus 7 are better for testing, because they have fewer preinstalled apps and less services running in the background.
- - Don’t check more data points than you need. This increases system resource consumption.
- - Make sure “Show Per-Application Statistics” is unchecked -- unless you need to see the mobile and Wi-Fi data transmitted.
- - Profile in the background with no visible graphs or on-screen overlays. This results in almost half the power consumption, and more accurate power readings. After profiling, data can be viewed or saved so it can be analyzed later. Step-by-step instructions are list here.
- - Pause or disable step counters like "S Health" or "Google Fit." These apps can consume significant amounts of CPU cycles while your mobile device is idle.
- - Turn off "Google Now" to prevent your device from downloading cards in the background and always listening for the "OK Google" keyword (if you've set it up to do so).
- - Consider uninstalling apps like Microsoft’s “One Drive” or Nokia’s “Here” that relaunch themselves after you close them.
- - Do not setup your device for use with multiple users.
- - Avoid using your device with a wearable, because they require that multiple apps are running at once and Bluetooth is always active.
- - Most popular apps have analytics that send data to the cloud periodically. To prevent this, turn on Airplane Mode if your app doesn't need to communicate with the cloud.
- 5. Focus on what you’re measuring – Turn off everything that is not related to what you want to measure. If network connectivity is not needed, put your device in Airplane Mode. This will prevent your device from updating software in the background. Other things you may wish to turn off: Display (when possible), Bluetooth, Location (GPS), Wi-Fi and Mobile networks (if not already in Airplane mode).
- 6. Be precise and test several times – It’s important that you are consistent and confirm your test results by retesting. Here are some suggestions how to do this:
- - Use a stopwatch to make sure your tests run the same duration every time.
- - When measuring average power consumption, profile for at least two minutes in Trepn Profiler’s Advanced Mode. Then save your results as a Trepn .db file. Touch the ‘Analyze Run’ button and select the saved file. This will provide more accurate average values than the ones displayed while profiling.
- - Run each test at least two or three times and average the results. Throw out any values that are noticeably higher than the rest and retest.
- - Be very aware of your screen background. Light backgrounds use considerably more power than dark backgrounds. Try to be consistent and document what the background is on each test (e.g. stock Nexus 6 home screen).
- - Keep everything as close to the same as possible on your tests, including background apps and services. After you finish a test, go back and check the running apps, if the list of apps is different, close the newly opened apps and test again.
- 7. Minimize the impact of the screen – The display and its backlight are often the biggest consumers of power in a mobile device.
- - Turn screen brightness to the lowest possible level on your tests. Avoid using the Android Settings page to set screen brightness levels because the slider calibration varies from device to device. Also slider settings are not easily reproducible.
- For rooted commercial devices (set brightness to 10):
adb shell "su -c 'echo 10 > /sys/class/leds/lcd-backlight/brightness'"
For rooted MDPs:
adb shell "echo 10 > /sys/class/leds/lcd-backlight/brightness"
- - Always document screen brightness levels to make sure you are consistent.
- 8. Compare apples to apples – Don’t try to compare on-target measurements with off-target (e.g. Monsoon Power Monitor) measurements. On-target measurements and always going to be higher – sometimes significantly higher, so you cannot compare them with off-target measurements using hardware.
Hopefully you will find these tips to be helpful. If you have any tips of your own, please share them below.