1、Building from source code(通過各種配置后從源碼構建)
官方流程看似很麻煩,但一上手,很快就搞定,讓我情何以堪。
ps:以下均是參考官方及網友做的 copy
https://github.com/google/battery-historian#building-from-source-code
http://blog.csdn.net/feitian_666/article/details/52756522
http://blog.csdn.net/feitian_666/article/details/52756522
(1)安裝 Go 語言
-
安裝
-
配置環境變量



- 檢查是否安裝成功:cmd 執行 “go version”

(2)安裝 Python
- 下載:https://www.python.org/ 【注意僅支持 python 2.7,python3.0改變很大】
- 安裝
-
配置環境變量
-
檢查是否安裝成功:cmd 執行 “python –V”【注意是大寫V】

(3)安裝Git
-
安裝
-
檢查是否安裝成功:cmd 執行 “git version”

(4)安裝 Java 環境(JDK)
- 別跟我說你沒有 …
(5)下載 Battery Historian 源碼並且運行
- cmd 執行“go get -d -u github.com/google/battery-historian/…”【注意最后有三個點】

- 進入到“$GOPATH/src/github.com/google/battery-historian”目錄下方【GOPATH即上面配置的工作空間】
ps:我直接“cd $GOPATH/src/github.com/google/battery-historian”不行,耍了點小技巧,直接到指定目錄下運行 cmd,又因為指定目錄下有名為“cmd”的文件夾,只能分兩步走:
![]()
最后發現,先在所在盤符啟動cmd(我是D盤),然后直接 cd 路徑就行:
![]()
-
運行 Battery Historian
-
cmd 執行“go run setup.go”【第一次執行要下載,時間會久一些,以后就快些】
-
cmd 執行“go run cmd/battery-historian/battery-historian.go”
-
ps:http://blog.csdn.net/feitian_666/article/details/52756522 提供了一個在沒有下載成功情況下補充“go run setup.go”的方法:手動下載【closure-library】和【closure-compiler】和【flot-axislabels】,解壓放到 GOROOT 目錄下 third_party 文件夾下方的的 closure-compiler、closure-library 和flot-axislabels 文件夾,如果沒有均手動創建。

- 登錄網址 http://localhost:9999 查看是否運行

二、使用
1、運行 Battery Historian
在上面 Building from source code 均配置成功的情況下:
- 進入到“$GOPATH/src/github.com/google/battery-historian”目錄下方
- cmd 執行“go run setup.go”
- cmd 執行“go run cmd/battery-historian/battery-historian.go”

2、導出手機的 Bugreport 文件:cmd執行“adb bugreport > bugreport.txt”
ps:這時如果有兩個設備在線上,就會報錯,應該可以指定某個設備生成的,懶一點,拔掉其它。只留下一個,ByTheWay,生成的待分析文件會有點大

3、上傳 bugreport.txt 文件至 http://localhost:9999



特效篇:Android性能優化之電量篇 - http://hukai.me/android-performance-battery/
// 得到整個設備的電量消耗信息 $ adb shell dumpsys batterystats > xxx.txt // 得到指定app相關的電量消耗信息 $ adb shell dumpsys batterystats > com.package.name > xxx.txt // 通過Google編寫的python腳本把數據信息轉換成可讀性更好的html文件 // https://github.com/google/battery-historian/blob/master/scripts/historian.py $ python historian.py xxx.txt > xxx.html
參考文章:
https://github.com/google/battery-historian
http://blog.csdn.net/feitian_666/article/details/52756522
http://blog.csdn.net/feitian_666/article/details/52756522
文章轉自:https://blog.csdn.net/zeqiao/article/details/77504477