溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

app電量測試之Battery Historian介紹

發(fā)布時(shí)間:2020-10-03 07:59:25 來源:網(wǎng)絡(luò) 閱讀:6452 作者:流光漏洞 欄目:移動開發(fā)

Battery Historian 

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


安裝

一、首先安裝Go編程語言

  1. 點(diǎn)擊下載【下載】;

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

  3. 配置GOROOT和GOPATH

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

     app電量測試之Battery Historian介紹

 

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

     app電量測試之Battery Historian介紹

 

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

     app電量測試之Battery Historian介紹

 

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

   app電量測試之Battery Historian介紹

 

二、安裝Git

  1. 點(diǎn)擊下載【下載】;

  2. 按照步驟安裝;

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

   app電量測試之Battery Historian介紹

   也可以直接打開git bash檢查

   app電量測試之Battery Historian介紹

 

三、安裝Python

  1. 點(diǎn)擊下載【下載】,注意僅支持python2.7

  2. 安裝完成;

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

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

     app電量測試之Battery Historian介紹

 

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

  1. 點(diǎn)擊下載【下載】;

  2. 完成安裝。

 

五、下載Battery Historian源碼并且運(yùn)行

  1. git目錄下點(diǎn)擊git-bash.exe,輸入命令行g(shù)o get -d -u github.com/google/battery-historian/...

     app電量測試之Battery Historian介紹

     **下載到GOPATH配置目錄下

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

  3. 運(yùn)行Battery Historian

    輸入 $ go run setup.go

    # Compile Javascript files using the Closure compiler


    app電量測試之Battery Historian介紹

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

    **下載【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是否運(yùn)行,登錄網(wǎng)址 http://localhost:9999查看



生成bugreport

  一、數(shù)據(jù)準(zhǔn)備

    1.windows cmd下執(zhí)行以下命令,開啟電池?cái)?shù)據(jù)獲取

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

    2.windows cmd下執(zhí)行以下命令,重置電池?cái)?shù)據(jù)

        adb shell dumpsys batterystats --reset


  二、操作應(yīng)用,生成bugreport

      拔掉USB,然后對待測app進(jìn)行相關(guān)操作,一段時(shí)間后,插上USB,運(yùn)行一下兩條命令。

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

          adb bugreport > bugreport.txt

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

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

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

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

  app電量測試之Battery Historian介紹


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

 

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

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

    wifi連接活躍時(shí)間。
  • screen:

    屏幕點(diǎn)亮?xí)r間。
  • phone_in_call:

    通話時(shí)間。
  • wake_lock

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

    cpu運(yùn)行時(shí)間。
  • wake_reason

    內(nèi)核最后一次喚醒的原因。如果是由你的應(yīng)用喚醒,請確定是否必要這么做。
  • mobile_radio

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

    gps開啟的時(shí)間。
  • sync: 

    正在后臺同步的應(yīng)用。


 注意,上面的每行分類只是根據(jù)當(dāng)前開啟的功能或服務(wù),應(yīng)用收集的數(shù)據(jù)。并不是每次都一樣,如wifi沒開,就不會有wifi相關(guān)的數(shù)據(jù),gps沒開就沒有g(shù)ps相關(guān)數(shù)據(jù)。
 

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


 batterystats.txt 顯示的是全部數(shù)據(jù)。batterystats.html顯示的只是它分析時(shí)所需的數(shù)據(jù)。

 

      app電量測試之Battery Historian介紹

          Figure 2.Example of filtered batterystats output.

  • Battery History:

    與電量相關(guān)行為的的歷史記錄。
  • Per-PID Stats

    每個(gè)應(yīng)用進(jìn)程運(yùn)行的時(shí)間。
  • Statistics since last charge

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

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

    使用無線電設(shè)備傳輸數(shù)據(jù)的時(shí)間間隔。好的應(yīng)用會以密集批量方式傳輸。
  • All partial wake locks

    wakelocks的統(tǒng)計(jì)。

     

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


 最后我們還可以看到相關(guān)進(jìn)程耗費(fèi)的電量(估算值):

  app電量測試之Battery Historian介紹


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI