分析和最佳化應用電量

來源:互聯網
上載者:User

分析和最佳化應用電量

在Android項目中, 較難監控應用的電量消耗, 但是使用者卻非常關心手機的待機時間. 過度耗電的應用, 會遭到使用者無情的卸載, 不要存在僥倖心理, 給競品帶來機會. 因此, 我們需要研究應用的耗電量, 並進行最佳化. 本文講解一下Battery Historian, 是一款由Google提供的Android系統電量分析工具. 在網頁中展示手機的電量消耗過程, 輸入電量分析檔案, 顯示消耗情況. 最後提供一些電量最佳化的方法, 可供參考.

1. 安裝Go

Battery Historian是Go語言開發, 需要安裝Go編譯環境.
下載Mac版的安裝包, 執行完成, 檢查Go版本

?  ~ go versiongo version go1.6 darwin/amd64

.bash_profile中, 設定Go語言變數

#Go Settingsexport GOPATH=/Users/.../Workspace/GoWorkspaceexport GOBIN=/Users/.../Workspace/GoWorkspace/bin

GOPATH源碼地址. GOBIN產生地址, 推薦$GOPATH/bin.
執行source .bash_profile, 應用profile配置.

建立src檔案夾, 添加HelloWorld檔案hello.go.

package mainimport "fmt"func main() {    fmt.Printf("hello, world\n")}

安裝hello.go

go install hello.go

執行

$GOBIN/hello

如果顯示hello, world, 即表示安裝完成.

2. Battery Historian

在安裝Battery Historian時, 需要提前安裝wget.

sudo brew install wget

按照Battery Historian的GitHub文檔執行操作即可.

go get -u github.com/golang/protobuf/protogo get -u github.com/golang/protobuf/protoc-gen-gogo get -u github.com/google/battery-historian/...cd $GOPATH/src/github.com/google/battery-historianbash setup.sh# 運行Go指令碼, 預設連接埠9999 go run cmd/battery-historian/battery-historian.go [--port ]

啟動命令

cd $GOPATH/src/github.com/google/battery-historiango run cmd/battery-historian/battery-historian.go [--port ]

在瀏覽器中, 輸入http://localhost:9999/, 即可啟動電量檢測頁面.

在啟動頁面時, 可能需要串連VPN, 訪問Google資訊.

3. 分析

擷取手機的電量檔案, 匯出到根目錄, 以備Battery Historian使用.

adb bugreport > bugreport.txt

使用Battery Historian的網頁載入bugreport.txt檔案.

如遇到一些問題, 重新提交bugreport.txt檔案.

系統狀態

應用狀態(簡書)

4. 電量最佳化

根據Battery Historian的電量提示資訊, 消耗電量包含
喚醒鎖\SyncManager同步處理管理員\音視頻\流量.

最佳化方式:
(1) 檢查全部喚醒鎖, 是否存在冗餘或者無用的位置.
(2) 集中相關的資料請求, 統一發送; 精簡資料, 減少無用資料的傳輸.
(3) 分析和統計等非重要操作, 可以在電量充足或串連WIFI時進行, 參考JobScheduler.
(4) 精簡冗餘的服務(Service), 避免長時間執行耗電操作.
(5) 注意定位資訊的擷取, 使用後及時關閉.

電量最佳化並不是很難, 但需要對業務非常熟悉, 瞭解一些耗電操作的使用方式, 及時最佳化. 只有給使用者精緻的體驗, 使用者才能更加喜歡我們的應用, 這就是服務型社會的本質.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.