Search code examples
androidperformancegpsadbbattery

TOTAL power consumption by Android App (CPU, GPS, Network, WiFi).


I am developing an application that tracks user movement using GPS and Network location information. I use Services, Activity Recognition, different sampling rates and gps/network timeouts for battery efficiency.

The question is How can I measure an exact amount (mV, mA/hour or % of total consumption) of power consumed by my App? Not only base on CPU usage, but also by calling GPS, Network, WiFi. So I can make a conclusion about the app battery efficiency.

I am getting battery statistic by adb shell dumpsys batterystats.

This is what I see for 1 hour of usage during travelling by foot and train:

Mobile network: 10.61KB received, 7.41KB sent (packets 26 received, 34 sent)
Mobile radio active: 18s 180ms (0.7%) 8x @ 303 mspp
Wifi Running: 0ms (0.0%)
Full Wifi Lock: 2m 8s 907ms (3.9%)

**Wifi Scan: 3m 20s 904ms (6.1%)**

Wake lock NlpCollectorWakeLock: 1m 23s 525ms partial (100 times) realtime
Wake lock *alarm*: 269ms partial (97 times) realtime
Wake lock NlpWakeLock: 264ms partial (83 times) realtime
Wake lock LocationManagerService: 64ms partial (19 times) realtime
TOTAL wake: 1m 24s 122ms partial realtime

**Sensor GPS: 5m 15s 109ms realtime (185 times)**

Foreground activities: 2m 40s 107ms realtime (10 times)
Foreground for: 51m 51s 176ms 
Active for: 55m 1s 142ms 
Proc xxxxxxxxxxx:

  **CPU: 30s 670ms usr + 6s 800ms krn ; 7s 810ms fg**

Proc *wakelock*:

  **CPU: 12s 660ms usr + 15s 40ms krn ; 0ms fg**

Apk xxxxxxxxxxx:
  122 wakeup alarms
  Service xxxxxxxxxxx.ActivityRecognitionIntentService:
    Created for: 6s 652ms uptime
    Starts: 356, launches: 356
Apk com.google.android.gms:
  (nothing executed)

I guess that the most power consuming thing are Sensor GPS calls, CPU usage and Wifi.

Questions:

1) How can I interpret this numbers? Is it possible to find out how much each GPS call (or realtime) is power expensive?

2) Is there are better ways to find out the total power consumption of the App?


Solution

  • As talked about in Battery Performance 101 and Understanding Battery Drain Android does not expose low-level counters about battery draw per chip. The overhead of tracking that data would be significant from both a logging, and hardware level.

    The only true way to get this information is to hook up your android to a MONSOON device but even then, your results will be skew'd, as the power draw changes between devices & form factors.

    The middle ground is the Battery Historian tool, which tells you what important systems are active, allowing you to then find correlation between those events and what hardware was responsible. It's worth noting that Battery Historian is just a UI-conversion for the BatteryStats tool (which you're already using). It does all the work to scrape and interpret that data into a visual form for you.

    Although this isn't 100% on-point; As you can see with Battery Drain and Networking, optimizing your battery usage is about looking for patterns in Battery Historian, that are known to be problematic, and trying to change the code to impact them. So, when diagnosing some things, there's a little hand-waving going on.

    At this time, this is suggested way to find accurate information about your battery usage.