How to Measure Power Consumption Using Free Software

This article is the first in a series for mobile software developers. It is intended to help developers create apps with better battery life. Most developers don’t know if their app has a problem with excessive power consumption, because they don’t have an effective way to measure the amount of power their app consumes. If you can measure it, you can act on it. This article will focus on Best Practices for software power measurement. A subsequent article will show you how to measure power consumption using specialized hardware. Reducing power consumption results in longer battery life and happier users.

It's easy to measure the power consumption of a mobile device

It’s easy to measure the power consumption of a mobile device

There are two different ways to measure power on a mobile device. You can do it using hardware or software. I’ll cover the hardware-based method in a separate article. This post will focus on software-based power measurement. Trepn Profiler is an Android application that can display the real-time power consumption on a smartphone or tablet. I happen to work on the team who created it, but I that’s not why I include it in this article. I include it because it’s the only app I’ve found that reports accurate real-time power consumption. GameBench is a great app, but the current version has to run a few minutes before power data is reported. If you are aware of other app that report accurate real-time power, please mention them in the comments section below and I will include them in this article. Because Trepn runs on-target, your mobile device doesn’t have to be connected to a computer or special hardware in order to capture power data. You can use your phone on-the-go, and profile in the foreground or background. If you want to give it a try, Trepn is available as a free download from Google Play.

Here are just a few of the questions you can answer with software like Trepn Profiler:

  • Which Android video conferencing app uses less power: Google Hangouts, ooVoo, Skype, Tango or Viber?
  • Should I wait to download updates over Wi-Fi if my battery is low and I’m only getting two bars?
  • How much more power does a free app with ads consume over a paid app without ads?
  • Does a dark background really consume less power than a light one?
  • How much power do I save when I use hardware decoding on a high-resolution video file?
  • Does that new phone you’re considering buying consume more or less power than your current one?
  • What is the impact of settings on power consumption (e.g. do you save noticeable amounts of power when you turn off Bluetooth, Wi-Fi or 4G?)
  • Which activity consumes more power? Gaming or 4K video recording?


Before you start profiling, there are several things you should do to increase your chances of getting the most accurate power measurements possible.

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: If you need a USB connection for device control and data transfer, use ADB over Wi-Fi as described here, but be aware it can cause power spikes that slightly increase your power readings.

  1. 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 data points in Trepn Profiler. 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 values like 0 or 1.80mW, your device cannot display accurate battery power.

awake

  1. Make sure your processor stays awake– To do this, check “Acquire Wakelock while Profiling” on the Trepn General Settings page. To illustrate the importance of this, I did two power tests Without forcing the processor to stay awake, the average power reading was 456mW. With a processor wakelock set, the power was 249mW. That’s an 83% error, which shows how important this setting can be. When the processor goes to sleep, data collection in Trepn may temporarily stop, or power readings can jump to levels that are lower or higher than they should be. When data collection stops for long periods, your average power readings will be higher than they should be, because Trepn will average any power spikes over a 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.

asleep

  1. 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 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. Here are some recommendations how to minimize background activity:
    Minimize the number of apps you have running

    Minimize the number of apps you have running

      • Pure Android devices like the Nexus 5 or Nexus 7 are better for testing, because they have fewer preinstalled apps and less things 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 listed 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 step-counters and always-listening apps like Google Now

    Turn off step-counters and always-listening apps like Google Now

      • Turn off ‘Google Now’ as follows: Turn off “Ok Google” Detection by going to Settings > Accounts > Google > Search > Voice. Select “Ok Google” detection and turn off ‘From the Google app’ and ‘From any screen.’ Turn off ‘Show cards’ under Settings > Accounts > Google > Search > ‘Now cards.’
      • Consider uninstalling apps like Microsoft’s “One Drive” or Nokia’s “Here” that relaunch themselves after you close them.
    Use  Quick Settings to turn off things like sync

    Use Quick Settings to turn off things like sync

    • 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.
  2. 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 doing software updates in the background. Make sure Wi-Fi is off too. Some devices turn it off automatically when Airplane mode is enabled, others do not. Other things you may wish to turn off: Display (when possible), Ambient screen, Bluetooth, Location (GPS), Wi-Fi and Mobile networks (if not already in Airplane Mode).You may want to also turn off all syncing options under Settings > Accounts > Google. When performing screen power tests, set to processor to its lowest possible frequency to reduce effect of CPU on power.
  1. 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:
    Dark backgrounds use much less power

    Dark backgrounds use much less power

    • Be very aware of your screen background. Light backgrounds use more power than dark backgrounds. How much more? The average power consumed by the Google News & Weather app with a light theme selected is 893 mW. With a dark theme selected, only 410 mW of power is consumed. That’s a power reduction of 54%.
    • 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. If you have a rooted device, consider using software like RepetiTouch to record your keystrokes. This will ensure your test runs are the same each time.
    • 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.
  1. Minimize the impact of the screen – The display and its backlight are often the biggest consumers of power in a mobile device. 
  2. Always document screen brightness levels to make sure you are consistent.
  3. 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.
  4.  

    For rooted commercial devices (set brightness to 10):

    adb shell “su -c ‘echo 10 > /sys/class/leds/lcd-backlight/brightness'”

     

    For rooted MDPs:

    adb root
    adb wait-for-device
    adb remount
    adb shell “echo 10 > /sys/class/leds/lcd-backlight/brightness”

    1. Compare apples to apples – Don’t 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. However, when you run Trepn on a device connected to a Monsoon, you’ll find it’s very accurate (as shown in the chart below).
    Trepn is surprisingly  accurate -- even when compared to expensive hardware like the Monsoon Power Monitor

    Trepn is surprisingly accurate — even when compared to expensive hardware like a Monsoon Power Monitor

    After using Trepn, you should know exactly how much power your app consumes. Measure the power your app uses when idle and in-use and compare this with apps of the same type. A follow-up article will tell you how to reduce the power consumption of your app.

– Rick

Copyright 2015 Rick Schwartz. All rights reserved. Linking to this article is encouraged. All of the comments in this blog are Rick’s alone, and do not reflect the views of his employer.
Follow me on Twitter @mostlytech1

Software Power Measurement Best Practices

Advertisements

About Rick E. Schwartz
Rick Schwartz is blogger from San Diego. You can learn more about Rick by clicking on the "About" tab at the top of mostly-tech.com.

3 Responses to How to Measure Power Consumption Using Free Software

  1. Pingback: How to Power Profile A Mobile App Using Hardware | Mostly-Tech

  2. Pingback: Measuring Android Power Consumption | App Inventor 2 – Learn to Code!

  3. Pingback: How to Accurately Measure Power Consumption on Android Devices Using Free Software - CodeMobile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: