1

How to measure app power consumption when I connect my device with my pc?

I've read about batterystats from Android Studio. And I've followed the instructions and get a batterystats dumpsys. However, I can't not let my device consistently plugged on usb port because the result of dumpsys will have a missing part called "Estimated power use". Which is the most important part of the whole test because the app power consumption it contained.

I've tried using StopCharge app to interrupt phone charging. But the prerequisite is that the device need to get ROOT.

Other options like power tutor is outdated. Information out from the application can't quite fit my request(Android 6.0 or upper).

Is it possible to get the power consumption measurement of an application when it's charging or is my mind out of the roof?

Thank you in advance!

p.s the following is a sample of the method of Android Studio batterystats

Estimated power use (mAh)
Capacity: 2930, Computed drain: 43.9, actual drain: 58.6-87.9
Screen: 35.6
Unaccounted: 14.7 ( )
Uid u0a2618: 2.91 ( cpu=2.17 wake=0.657 wifi=0.00656 sensor=0.0732 )
wadestrikers
  • 147
  • 1
  • 2
  • 12

1 Answers1

3

I think when you plug, the battery stats are not very accurate. There's two ways i usually do:

  1. Connect the adb by wi-fi and run batterystats

    • In Android Studio go to preferences->Plugins and search for Wi-fi, this way you connect the device on USB, go to plugin and he do the wifi connection

Or if you don't wanna a new plugin

  • Run adb tcpip 5555 and adb connect 192.168.0.101:5555 if you already have usb access (More info.)

-

  1. Use the Google Battery Historian:

    • In this link, download the project following the guidelines
    • In your adb, run adb shell dumpsys batterystats --reset to clear all the history
    • Use your App for some time
    • Go back on ADB an generate the log: adb bugreport > bugreport.txt
    • Then Upload the file to the Battery Historian site that you will host by following the instructions, and you are done.

Image of the Battery Historian:Screenshot of the Battery Historian

Community
  • 1
  • 1
  • First of all, thanks for answering my question Lucas. My unit test is based on plugged. I've tried to use adb over tcp, but with the limitation of testing when plugged, I've already give up on it. And with the limitation of automatically doing tests. I have no chance of using Android batterystats. Still, thanks for answering! – wadestrikers Aug 18 '16 at 01:47
  • I followed your approach. I generated bugreport.txt and tried to upload the file into Battery Historian site to get a graph as you posted but when I uploaded I got a message as "bugreport.txt does not contain a valid bugreport file". Can you help me out here to generate a graph as like yours – John Sep 15 '16 at 13:55
  • @John if you have a device with Android 7 and higher you need to do `adb bugreport bugreport.zip` and use the zip file. The command `adb bugreport > bugreport.txt` works for Android 6 and lower... – Stefan Oct 16 '20 at 10:41