- 通过执⾏battery命令(不需要root)
- adb命令获取电量量消耗信息
- 获取整个设备的电量量消耗信息
- 获取某个apk的电量量消耗信息
- batterystats使用步骤
通过执⾏battery命令(不需要root)
通过 adb shell dumpsys battery,返回结果后有电池的各种信息,其中就包括
level(百分⽐比)
adb命令查看电池电量量信息:
adb shell dumpsys battery
eroqltechn:/ $ dumpsys battery Current Battery Service state:
mBootCompleted: true
AC powered: false #有线充电器状态
USB powered: true #USB连接状态
Wireless powered: false #无线充电状态
Max charging current: 0 #最大充电电流,单位微安(uA)
Max charging voltage: 0 #最大充电电压,单位微伏(uV)
Charge counter: 0
status: 2 #充电状态,UNKNOWN=1,CHARGING=2,DISCHARGING=3,
NOT_CHARGING=4,FULL=5
health: 2 #电池健康状态:只有数字2表示goodpresent: true #电池是否安装在机身
level: 93 #电量: 百分比
scale: 100 #满电100%
voltage: 4265 #电池电压
temperature: 289 #电池温度,单位是0.1摄氏度technology: Li-ion #电池种类batterySWSelfDischarging: falsebatteryMiscEvent: 0
mSecPlugTypeSummary: 2
LED Charging: true
LED Low Battery: true
current now: 217 #电流值,负数表示正在充电charge counter: 0
Adaptive Fast Charging Settings: true
USE_FAKE_BATTERY: false SEC_FEATURE_BATTERY_SIMULATION: false FEATURE_WIRELESS_FAST_CHARGER_CONTROL: true
mWasUsedWirelessFastChargerPreviously: false
mWirelessFastChargingSettingsEnable: true BatteryInfoBackUp
mSavedBatteryAsoc: 88 mSavedBatteryMaxTemp: 429 mSavedBatteryMaxCurrent: 1746 mSavedBatteryUsage: 6447 FEATURE_SAVE_BATTERY_CYCLE: true
adb命令获取电量量消耗信息
获取整个设备的电量量消耗信息
adb shell dumpsys batterystats | more
获取某个apk的电量量消耗信息
adb shell dumpsys batterystats com.sdu.didi.psnger | more
由于输出信息太多,可使⽤用命令more 或者 less 分篇查看 输出信息如下(由于篇幅, 只粘贴部分)
heroqltechn:/ $ dumpsys batterystats com.sdu.didi.psnger Discharge step durations:
#0: +1h43m34s304ms to 92 (screen-off, power-save-off, device- idle-on)
#1: +1h54m26s635ms to 93 (screen-off, power-save-off, device- idle-on)
#2: +1h59m33s225ms to 94 (screen-off, power-save-off, device- idle-on)
#3: +1h58m56s325ms to 95 (screen-off, power-save-off, device- idle-on)
#4: +2h2m44s341ms to 96 (screen-off, power-save-off, device-idle- on)
#5: +2h2m20s111ms to 97 (screen-off, power-save-off, device-idle- on)
#6: +1h46m1s361ms to 98 (screen-off, power-save-off, device-idle- on)
Estimated screen off time: 8d 0h 17m 12s 800ms Estimated screen off device idle time: 8d 0h 17m 12s 800ms
Daily stats: Current start time: 2019-01-22-04-46-42 Next min deadline: 2019-01-23-01-00-00 Next max deadline: 2019-01-23-03-00-00 Current daily steps:
Discharge total time: 7d 19h 32m 18s 800ms (from 3 steps) Discharge screen off time: 7d 19h 32m 18s 800ms (from 3 steps) Discharge screen off device idle time: 7d 19h 32m 18s 800ms
(from 3 steps)
Daily from 2019-01-21-11-43-46 to 2019-01-22-04-46-42:
Discharge total time: 8d 3h 3m 13s 700ms (from 3 steps) Discharge screen off time: 8d 3h 3m 13s 700ms (from 3 steps) Discharge screen off device idle time: 8d 3h 3m 13s 700ms
(from 3 steps)
Charge total time: 6h 35m 21s 800ms (from 18 steps)
也可以将上述命令标准输出到⼀一个⽂文件,来进⾏行行分析。 windows : > xxx.txt Mac/Linux: > xxx.txt
将获得的数据转换为可视化的html⽂文件 命令:python historian.py xxx.txt > xxx.html
关于电量,还可以通过battery-historian⼯工具来获取。https://github.com/google/battery-historian
batterystats使用步骤
第一步:清除手机电量消耗历史情况(连接手机)
adb shell dumpsys batterystats -enable full-wake-history =====打开全量日志记录
adb shell dumpsys batterystats --reset =====清空电量数据
第二步:设计场景测试(注:不链接手机)
\
第三步:导出测试数据
adb shell dumpsys batterystats > d:/batterystat.txt =======生成TXT文件(导出到本地)
adb shell dumpsys batterystats > /sdcard/batterystat.txt =======生成TXT文件(导出到SD卡)
exit-----退出shell命令