测试电池使用情况 [英] Testing Battery Usage
问题描述
我想测试我的应用程序如何影响手机/平板电脑的电池.
I want to test how my application effects the battery of a phone/tablet.
是否有任何测试工具可以让我这样做?
Are there any testing tools which will allow me to do so?
例如,我想测试我的应用程序的哪些模块消耗的电池电量最多,等等.
For example, I want to test which modules of my application are consuming the most amount of battery, etc.
推荐答案
Android 5.0 附带了一个新工具.
There is a new tool which comes with Android 5.0.
你可以运行
adb shell dumpsys batterystats > dump.txt
获取设备的完整电池转储.您还可以添加一些选项,例如 --unplugged
(仅输出自上次拔出后的数据)或 --charged
(仅输出自上次充电以来的数据).您还可以添加一个包名以仅获取此包/应用程序的信息:
To get the full battery dump of you device. You also can add some options like --unplugged
(only output data since last unplugged) or --charged
(only output data since last charged). You can also add a packagename to get informations for this package/app only:
adb shell dumpsys batterystats --unplugged your.package.name > dump.txt
部分<代码>>dump.txt 将所有内容放入一个文件中(也许只适用于 Windows,不确定.但您可以将其放在一边,转储将直接打印在控制台中,您可以将其复制并放入文件中).
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).
这仅适用于搭载 Android 5.x 的设备.如果你有较低级别的设备可以尝试使用
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
但是这个文件会非常非常大.(~8mb+)
But this file will be very very big. (~8mb+)
创建此文件后,您可以使用 Google 的历史工具
After creating this file you can use the Historian Tool of Google
要使用它,您必须安装 Python 2.7.9 并运行以下命令
To use it you have to install Python 2.7.9 and run following command
python /path/to/historian.py dump.txt > battery.html
这将创建一个battery.html文件,您可以在其中以更有用的格式查看数据.
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
(仅适用于 Android 5.x)
(just works with Android 5.x)
这篇关于测试电池使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!