手機每一個硬件的耗電量是不同的!好比屏幕就是耗電大戶!其它一些元件則耗電量很是小!
使用android dumpsys工具能夠獲取電池以及電量消耗信息!
dumpsys工具:battery、batterystatushtml
adb命令:adb shell dumpsys battery
獲得信息以下:python
AC powered: false USB powered: true Wireless powered: false status: 1 #電池狀態:2:充電狀態 ,其餘數字爲非充電狀態 health: 2 present: true level: 55 #電量: 百分比 scale: 100 voltage: 3977 current now: -335232 temperature: 335 #電池狀態 technology: Li-poly
手機鏈接到電腦,默認爲充電狀態android
切換手機電池爲非充電狀態: adb shell dumpsys battery set status 1
git
改變手機電量! 親,這是真的 !神奇的一刻github
讓手機電量顯示百分百: adb shell dumpsys battery set level 100
讓手機電量顯示1: adb shell dumpsys battery set level 1
shell
關於電量,主要是經過battery-historian工具來獲取。
https://github.com/google/battery-historianwindows
獲取整個設備的電量消耗信息: adb shell dumpsys batterystats | more 獲取某個apk的電量消耗信息: adb shell dumpsys batterystats com.Package.name | more
因爲輸出信息太多,可以使用命令more 或者 less 分篇查看
輸出信息以下(因爲篇幅,只粘貼部分):性能優化
Battery History: -1d04h22m36s181ms 044 20080000 status=charging health=good plug=usb temp=335 volt=3809 +plugged +sensor -1d04h21m27s713ms 044 640a0000 +wifi +wifi_running +wake_lock -1d04h21m23s278ms 044 6c0a0100 +phone_scanning phone_state=out -1d04h21m19s102ms 044 2c0a0100 -wake_lock -1d04h21m05s005ms 044 6c0a0100 +wake_lock -1d04h20m51s486ms 044 6d0a0100 +wifi_scan -1d04h20m49s211ms 044 6c0a0100 -wifi_scan -1d04h20m41s478ms 044 6c0a0100 -1d04h20m31s476ms 044 6d0a0100 +wifi_scan -1d04h20m29s174ms 044 6c0a0100 -wifi_scan -1d04h20m24s353ms 044 2c0a0100 -wake_lock -1d04h20m21s474ms 044 6d0a0100 +wifi_scan +wake_lock -1d04h20m21s125ms 044 6d0a0100 -1d04h20m16s847ms 044 2c0a0100 -wifi_scan -wake_lock
也能夠將上述命令標準輸出到一個文件,來進行分析。less
命令:python historian.py xxx.txt > xxx.html
Google Python腳本下載地址:https://github.com/google/battery-historian工具