工具開源地址:https://github.com/google/battery-historian
根據(jù)
gitbub上面介紹,Battery History工具的安裝有兩種方式:
1. 通過安裝
Docker環(huán)境來安裝。(這種方式很簡單雕凹,Docker真心好用,太彪悍了!)
Docker是一種容器,一般用于云計算和大數(shù)據(jù)平臺任洞。提倡的一種思想就是:軟件即服務(wù)。這句話不是蓋的发侵,一句話就可以將別人發(fā)布的docker服務(wù)環(huán)境一次全部copy過來(注意是整個軟件環(huán)境哦交掏,相當(dāng)于復(fù)制了一臺一模一樣的主機(jī),連軟件都不要安裝了刃鳄,全有了盅弛。彪悍吧!)
Docker只支持Windows10
Gitbub上面是這樣的命令及地址:
docker -- run -p <port>:9999 gcr.io/android-battery-historian:2.1 --port 9999
docker run -d -p 9999:9999 bhaavan/battery-historian
2.通過編譯gitbub上面的源碼來安裝叔锐。
這個就很麻煩了挪鹏,要裝一堆軟件哦。見下面(“一愉烙、”到“五讨盒、”步驟)
一、GO環(huán)境安裝:
1.下載
下載目錄:
https://golang.org/doc/install
https://golang.org/doc/install?download=go1.7.3.windows-amd64.msi
2.安裝GO
3. 配置GOROOT和GOPATH(注意環(huán)境變量的配置)
a. GOROOT的作用是告訴Go 命令和其他相關(guān)工具步责,在哪里去找到安裝在你系統(tǒng)上的Go包,所以這里配置的是GO的安裝目錄
b.GOPATH可以簡單理解為是工程的目錄返顺,所以創(chuàng)建一個GO的工程路徑
C.最后配置一下環(huán)境變量,把Go的bin目錄放到path環(huán)境變量中
d.查看配置是否正確 go env
4. 檢查Go是否安裝成功蔓肯,打開命令行輸入Go version (路徑不能一致遂鹊,win10 上下的環(huán)境變量配置)
二、安裝Git
1. 點擊下載(https://git-scm.com/)蔗包;
2. 按照步驟安裝稿辙;
3. 安裝完成檢查:命令行輸入 git version
也可以直接打開git bash檢查
三、安裝Python
1. 點擊下載【下載】气忠,注意僅支持python2.7 (https://www.python.org/ )
2. 安裝完成邻储;
環(huán)境變量配置,添加Path的路徑旧噪,是Python的安裝路徑
4.輸入命令行 python –V(注意是大寫V)檢查是否安裝成功
四吨娜、安裝Java環(huán)境
- 點擊下載【下載】;
- 完成安裝淘钟。
五宦赠、下載Battery Historian源碼并且運(yùn)行
1.輸入命令行g(shù)o get -d -u github.com/google/battery-historian/…
**下載到GOPATH配置目錄下 自動
2.進(jìn)入到$GOPATH/src/github.com/google/battery-historian目錄下方
$ cd $GOPATH/src/github.com/google/battery-historian
3.運(yùn)行Battery Historian
1) go run setup.go
$ go run setup.go
等待數(shù)分鐘或者
10分鐘左右,如果仍然沒有下載成功米母,可以手動下載勾扭,如下操作
**下載【closure-library】【[closurecompiler(https://github.com/google/closure-compiler)】和【flot-axislabels】,解壓放到GOROOT目錄下third_party文件夾下方的的closure-compiler和closure-library和flot-axislabels
文件夾../battery-historian\third_party铁瞒;如果沒有均手動創(chuàng)建
2)go run cmd/battery-historian/battery-historian.go
cd $GOPATH/src/github.com/google/battery-historian
$ go run cmd/battery-historian/battery-historian.go [--port <default:9999>]
4. 檢查/battery-historian是否運(yùn)行妙色,登錄網(wǎng)址http://localhost:9999查看 (沒有提交,換個瀏覽器試試)
六慧耍、導(dǎo)出手機(jī)的Bugreport日志
1.輸入指令adb bugreport > bugreport.txt導(dǎo)出身辨。
或者用下面的命令也可以:
adb shell dumpsys batterystats > batterystats.txt
adb shell dumpsys batterystats > com.example.android.sunshine.app > batterystats.txt
七、上傳bugreport.txt文件至*http://localhost:9999
1.上傳bug日志
2.查看結(jié)果
historian-V1之前的版本分析方式:
將txt文檔轉(zhuǎn)化為html文件芍碧,命令如下煌珊。
python historian.py -a bugreport.txt > battery.html
可以進(jìn)入安裝的目錄D:\goproject\src\github.com\google\battery-historian\scripts
如果有zip 請解壓zip 獲取bugreport.txt 文件來轉(zhuǎn)換
參考資料:
https://github.com/google/battery-historian#wakelock-analysis