测试电池使用情况

Arn*_*rty 66 testing android

我想测试我的应用程序如何影响手机/平板电脑的电池.

是否有任何测试工具可以让我这样做?

例如,我想测试我的应用程序的哪些模块消耗最多的电池等.

Inf*_*0re 29

Android 5.0附带了一个新工具.

你可以跑

adb shell dumpsys batterystats > dump.txt
Run Code Online (Sandbox Code Playgroud)

要获得设备的完整电池转储.您还可以添加一些选项--unplugged(例如,自上次拔出后--charged仅输出数据)或(仅自上次收费后输出数据).您还可以添加包名称以仅获取此包/应用程序的信息:

adb shell dumpsys batterystats --unplugged your.package.name > dump.txt
Run Code Online (Sandbox Code Playgroud)

The part > dump.txt put everything into a file (maybe just works on Windows, not sure. But you can just leave it away, the dump will be printed right in the console where you can copy it and put it in a file).

This works just if you have a device with Android 5.x. If you have a device with a lower level you can try to use

adb shell bugreport > bugreport.txt
Run Code Online (Sandbox Code Playgroud)

But this file will be very very big. (~8mb+)

After creating this file you can use the Historian Tool of Google

To use it you have to install Python 2.7.9 and run following command

python /path/to/historian.py dump.txt > battery.html
Run Code Online (Sandbox Code Playgroud)

This will create a battery.html file where you can see the data in a more usefull formatting.

Last thing: If you want to reset the stats of the battery dump just call

adb shell dumpsys batterystats --reset
Run Code Online (Sandbox Code Playgroud)

(just works with Android 5.x)


P.T*_*.T. 22

在实践中,我相信大多数有电源问题的应用程序也存在"CPU"问题.也就是说,应用程序CPU使用率的配置文件可能是您电池消耗的一个很好的近似值.例如,如果您的应用程序使用GPU,无线网络,存储等执行昂贵的操作,并且昂贵的操作不占用大量CPU时间,则需要注意和例外.

这是一个有趣的博客,关于"Power Tutor"应用程序,它提供了比内置电池应用程序更精确的运行系统测量:http: //gigaom.com/mobile/android-power-consumption-app/.我没试过.

另一个细节,这里有一篇论文,分解了手机的哪些组件吸收了最多的汁液(注意论文是从2010年开始):http://www.usenix.org/event/usenix10/tech/full_papers/Carroll .pdf (跳到第5节阅读他们的结果).他们说屏幕亮度是最大的罪魁祸首.

如果屏幕亮度是最大的罪魁祸首,请确保在测量自己的应用程序使用情况时将其设置为固定级别.

如果您真的对测量功耗感兴趣,可以按照他们的方法(打开手机并贴上测量设备).

  • GPS也消耗很多电池! (4认同)