主要分为2步骤
1、收集app耗电数据
adb devices #连接手机
adb shell dumpsys batterystats --reset #设备耗电量数据重置
adb shell dumpsys batterystats --enable full-wake-history #清除已有的耗电量数据
断开usb数据线测试,链接usb会充电,无法统计正确
adb shell dumpsys batterystats >>d:/batterystats.txt #导出为txt
2. 确定app包名
通过包名确定UID
提取该UID相关日志
提取该UID使用的电量,*mAh
Capacity为电池总容量,Computed drain为从reset到测试结束总耗电量
2、导出数据,报表分析
可以通过Battery Historian将batterystats.txt 生成html文件格式
2.1、下载https://github.com/google/battery-historian
2.2、运行python historian.py batterystats.txt > batterystats.html