Android手机app的adb命令测试电量
Android手机app电量测试
Android 5.0及以上的设备, 允许我们通过adb命令dump出电量使用统计信息
第一步:手机安装要测试的应用,打开手机开发者模式-USB模式,运行cmd.exe:
adb kill-server
adb devices //查看手机连接是否正常
第二步:因为电量统计数据是持续的, 会非常大, 统计我们的待测试App之前先reset下, 连上设备, 命令行执行。
adb shell dumpsys batterystats --reset
此时,手机里电量统计被清除,建议确定手机连接成功,多清理几次。而后再断开USB数据线,操作要测试的app相应的测试流程。
第三步:重新连接手机
adb devices //再次确认是否连接成功
//此命令持续记录输出,要想停止记录时按Ctrl+C退出
adb shell dumpsys batterystats > E:\batterystats1.txt
导出的统计数据存储到batterystats1.txt,我们可以在此文件中间看到电池的消耗情况:
Estimated power use (mAh):
Capacity: 3100, Computed drain: 206, actual drain: 186-217
Screen: 66.4
Uid u0a723: 55.7 ( cpu=47.3 wifi=8.29 gps=0.00237 sensor=0.0443 )
Uid 1000: 21.9 ( cpu=21.8 wifi=0.104 )
Idle: 20.2
Uid u0a34: 14.0 ( cpu=0.145 gps=13.9 )
Cell standby: 8.34 ( radio=8.34 )
Uid 0: 5.05 ( cpu=5.05 )
Uid 1021: 4.12 ( cpu=1.56 sensor=2.56 )
Uid u0a463: 3.27 ( cpu=2.80 wifi=0.281 gps=0.195 )
Wifi: 1.98 ( cpu=0.383 wifi=1.60 )
Bluetooth: 1.59 ( cpu=1.59 )
Uid u0a44: 0.982 ( cpu=0.982 )
Uid u0a462: 0.930 ( cpu=0.814 sensor=0.116 )
Uid u0a66: 0.486 ( cpu=0.486 )
Uid 1036: 0.455 ( cpu=0.455 )
Uid u0a518: 0.228 ( cpu=0.228 )
Uid 1001: 0.184 ( cpu=0.184 )
Uid 1041: 0.116 ( cpu=0.116 )
Uid u0a65: 0.116 ( cpu=0.116 )
Uid u0a90: 0.0506 ( cpu=0.0506 )
Uid u0a67: 0.0486 ( cpu=0.0486 )
Uid u0a5: 0.0397 ( cpu=0.0397 )
Uid u0a61: 0.0329 ( cpu=0.0329 )
Uid u0a41: 0.0275 ( cpu=0.0275 )
Uid 1013: 0.0195 ( cpu=0.0195 )
Uid u0a55: 0.0144 ( cpu=0.0144 )
Uid u0a63: 0.00667 ( cpu=0.00667 )
Uid u0a64: 0.00549 ( cpu=0.00549 )
Uid 1027: 0.00510 ( cpu=0.00510 )
Uid u0a103: 0.00454 ( cpu=0.00454 )
Uid u0a25: 0.00333 ( cpu=0.00333 )
Uid u0a15: 0.00300 ( cpu=0.00300 )
Uid u0a20: 0.00276 ( cpu=0.00276 )
Uid 1019: 0.00163 ( cpu=0.00163 )
Uid 1017: 0.000933 ( cpu=0.000933 )
Uid u0a10: 0.000732 ( cpu=0.000732 )
Uid u0a17: 0.000711 ( cpu=0.000711 )
Uid u0a58: 0.000666 ( cpu=0.000666 )
Uid u0a14: 0.000535 ( cpu=0.000535 )
Uid u0a53: 0.000535 ( cpu=0.000535 )
Uid u0a2: 0.000533 ( cpu=0.000533 )
Uid u0a75: 0.000278 ( cpu=0.000278 )
Uid u0a82: 0.000212 ( cpu=0.000212 )
Uid u0a78: 0.000180 ( cpu=0.000180 )
Computed drain 显示的是总电量,Screen 显示的是屏幕使用电量,在日志的后面可以看出 Uid u0a723 是操作的应用,Idle 显示的是重定时器使用电量;
一般是 功耗的计算=CPU消耗+Wake lock消耗+数据传输消耗+GPS消耗+ Wi-Fi连接消耗
这次我测试的是 Screen + Uid u0a723 + Idle + Wifi + Bluetooth 的电量。
注:这是我此次工作中的学习总结,后面持续需改完善。
本文地址:https://blog.csdn.net/weixin_45590490/article/details/108551214