前言
耗電量指標(biāo)
待機(jī)時(shí)間成關(guān)注目標(biāo)
提升用戶體驗(yàn)
通過不同的測(cè)試場(chǎng)景,找出App高耗電的場(chǎng)景并解決
01需要的環(huán)境準(zhǔn)備
1、Python2.7(必須是2.7,3.X版本是不支持的)
2、golang語言的開發(fā)環(huán)境
3、Android SDK
此三個(gè)的環(huán)境搭建這里就不詳細(xì)說了,自行在網(wǎng)上找資料吧
02battery-historian服務(wù)搭建
1、克隆安裝包
git clone
https://github.com/google/battery-historian.git
2、下載battery-historian的代碼和依賴
go get -d -u
github.com/google/battery-historian/...
3、修改setup.go文件的參數(shù)
closureCompilerVersion = "20170409"
值修改為
closureCompilerVersion = "20190513"
因?yàn)榘姹静灰粯樱幾g會(huì)失敗,所以升級(jí)到穩(wěn)定版本
4、切換到setup.go所在的目錄,進(jìn)行編譯
go run setup.go

5、啟動(dòng)battery-historian服務(wù)
go run
cmd/battery-historian/battery-historian.go

6、驗(yàn)證是否安裝成功http://localhost:9999/,出現(xiàn)如下,則ok

03進(jìn)行耗電量數(shù)據(jù)收集
1、清理耗電量數(shù)據(jù)
adb kill-server
adb start-server
adb shell dumpsys batterystats --reset
adb shell dumpsys batterystats --enable full-wake-history
2、運(yùn)行測(cè)試用例/手工操作
使用monkey或appium來操作想要被測(cè)試的Android應(yīng)用,最好就持續(xù)幾個(gè)鐘,效果才比較明顯,這里具體就不展開詳細(xì)說明了
3、收集數(shù)據(jù)
Android 7.0以上版本使用的命令 :adb bugreport bugreport.zip
Android 6.0 或以下使用的命令:adb bugreport > bugreport.txt


04上傳數(shù)據(jù),進(jìn)行數(shù)據(jù)分析
