app電量測試之BatteryHistorian介紹-創(chuàng)新互聯(lián)

Battery Historian

網站建設哪家好,找創(chuàng)新互聯(lián)!專注于網頁設計、網站建設、微信開發(fā)、微信小程序定制開發(fā)、集團企業(yè)網站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了郊區(qū)免費建站歡迎大家使用!

 battery historian是一款用于檢測與電池有關的信息和事件的工具,運行在Android 5.0 Lollipop (API level 21)及其之后。它會生成一張具有時間坐標的圖紙,用戶可以查看各種事件耗電時間。

安裝

一、首先安裝Go編程語言

  1. 點擊下載【下載】;

  2. 安裝Go;
    app電量測試之Battery Historian介紹

  3. 配置GOROOT和GOPATH

a. GOROOT的作用是告訴Go 命令和其他相關工具,在哪里去找到安裝在你系統(tǒng)上的Go包,所以這里配置的是GO的安裝目錄

 app電量測試之Battery Historian介紹

b.GOPATH可以簡單理解為是工程的目錄,所以創(chuàng)建一個GO的工程路徑

 app電量測試之Battery Historian介紹

        C.最后配置一下環(huán)境變量,把Go的bin目錄放到path環(huán)境變量中

 app電量測試之Battery Historian介紹

4. 檢查Go是否安裝成功,打開命令行輸入Go version

   app電量測試之Battery Historian介紹

二、安裝Git

  1. 點擊下載【下載】;

  2. 按照步驟安裝;

  3. 安裝完成檢查:命令行輸入git version

 app電量測試之Battery Historian介紹

   也可以直接打開git bash檢查

   app電量測試之Battery Historian介紹

三、安裝Python

  1. 點擊下載【下載】,注意僅支持python2.7

  2. 安裝完成;

  3. 環(huán)境變量配置,添加Path的路徑,是Python的安裝路徑
    app電量測試之Battery Historian介紹

  4. 輸入命令行 python –V(注意是大寫V)檢查是否安裝成功

 app電量測試之Battery Historian介紹

四、安裝Java環(huán)境

  1. 點擊下載【下載】;

  2. 完成安裝。

五、下載Battery Historian源碼并且運行

  1. git目錄下點擊git-bash.exe,輸入命令行go get -d -u github.com/google/battery-historian/...

     app電量測試之Battery Historian介紹

     **下載到GOPATH配置目錄下

  2. 進入到$GOPATH/src/github.com/google/battery-historian目錄下方
    app電量測試之Battery Historian介紹

  3. 運行Battery Historian

    輸入 $ go run setup.go

    # Compile Javascript files using the Closure compiler

    app電量測試之Battery Historian介紹

    等待數分鐘,如果仍然沒有下載成功,可以手動下載,如下操作

    **下載【closure-library】和【closure-compiler】和【flot-axislabels】,解壓放到GOROOT目錄下third_party文件夾下方的的closure-compiler和closure-library和flot-axislabels文件夾 ../battery-historian\third_party;如果沒有均手動創(chuàng)建

     app電量測試之Battery Historian介紹

    b. go run cmd/battery-historian/battery-historian.go

    # Run Historian on your machine (make sure $PATH contains $GOBIN)

    $ go run cmd/battery-historian/battery-historian.go [--port <default:9999>]

  4. 檢查/battery-historian是否運行,登錄網址 http://localhost:9999查看

生成bugreport

 一、數據準備

  1.windows cmd下執(zhí)行以下命令,開啟電池數據獲取

    adb shell dumpsys batterystats --enable full-wake-history

  2.windows cmd下執(zhí)行以下命令,重置電池數據

    adb shell dumpsys batterystats --reset

 二、操作應用,生成bugreport

   拔掉USB,然后對待測app進行相關操作,一段時間后,插上USB,運行一下兩條命令。

   1.windows cmd下執(zhí)行以下命令,將bugreport信息保存到相應路徑下,等待執(zhí)行完畢

     adb bugreport > bugreport.txt

   2.windows cmd 下執(zhí)行以下命令,將以上txt文檔轉化為html文件

     python historian.py -a bugreport.txt >battery.html

     注:現(xiàn)在不知道為什么會提示錯誤,找不到historian.py這個文件

   上面的historian.py 就是用python寫的腳本,所以需要python環(huán)境,可以從github上下載,以上命令執(zhí)行完后,會發(fā)現(xiàn)兩個文件,bugreport.txt和battery.html,這個時候用谷歌瀏覽器輸入http://localhost:9999,上傳bugreport.txt或者是直接打開battery.html就可以了,視圖如下:

  app電量測試之Battery Historian介紹

以上是V2.0版的,你可以自己切換到1版,現(xiàn)在來分析下各個參數的意義:

Battery Historian Charts

  • Battery usage categories

  • Filtering batterystats output

You should also read

  • Batterystats & Battery Historian Walkthrough

  • Systrace Walkthrough

  The Battery Historian chart graphs power-relevant events over time.

Each row shows a colored bar segment when a system component is active and thus drawing current from the battery. The chart does not show how much battery was used by the component, only that the app was active. Charts are organized by category.

app電量測試之Battery Historian介紹

Figure 1.Example of Battery Historian output.

Battery usage categories  各字段的含義 

  • battery_level:

    電量消耗速度等級,值是百分比,093就是93%
  • top:

    收集電量數據時,系統(tǒng)中處于top的應用,如果你的應用是前臺的,請確保它是top的。除非你想知道你的應用在后臺時的電量消耗。
  • wifi_running:

    wifi連接活躍時間。
  • screen:

    屏幕點亮時間。
  • phone_in_call:

    通話時間。
  • wake_lock:

    注意,在表格中,它是代*的,它是最重要的參考。
    通常應用的運行周期是啟動,運行一些作業(yè),然后睡覺。啟動是最費資源的,如果在這行里出現(xiàn)多個小堅條,說明有問題。
  • running:

    cpu運行時間。
  • wake_reason:

    內核最后一次喚醒的原因。如果是由你的應用喚醒,請確定是否必要這么做。
  • mobile_radio:

    無線電開啟的時間,開無線電非常耖電。這里出現(xiàn)密集的小堅條,說明有優(yōu)化空間。
  • gps:

    gps開啟的時間。
  • sync:

    正在后臺同步的應用。

 注意,上面的每行分類只是根據當前開啟的功能或服務,應用收集的數據。并不是每次都一樣,如wifi沒開,就不會有wifi相關的數據,gps沒開就沒有gps相關數據。
 

Filtering batterystats output 一些在上述html中未顯示信息

 batterystats.txt 顯示的是全部數據。batterystats.html顯示的只是它分析時所需的數據。

app電量測試之Battery Historian介紹

Figure 2.Example of filtered batterystats output.

  • Battery History:

    與電量相關行為的的歷史記錄。
  • Per-PID Stats:

    每個應用進程運行的時間。
  • Statistics since last charge:

    最近一次充電時系統(tǒng)參數的統(tǒng)計,如電池信號等級,屏幕亮度。
  • Estimated power use (mAh) by UID and peripheral:

    粗略統(tǒng)計電池的mAh。
  • Per-app mobile ms per packet:

    使用無線電設備傳輸數據的時間間隔。好的應用會以密集批量方式傳輸。
  • All partial wake locks:

    wakelocks的統(tǒng)計。

分析V1.0,可以參考http://blog.csdn.net/itfootball/article/details/44084159

 最后我們還可以看到相關進程耗費的電量(估算值):

  app電量測試之Battery Historian介紹

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

名稱欄目:app電量測試之BatteryHistorian介紹-創(chuàng)新互聯(lián)
標題鏈接:http://bm7419.com/article20/dioijo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供移動網站建設網站設計公司、電子商務、域名注冊、商城網站、企業(yè)建站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

商城網站建設