app电量测试之BatteryHistorian介绍

Battery Historian 

成都创新互联公司专业提供资阳托管服务器服务,为用户提供五星数据中心、电信、双线接入解决方案,用户可自行在线购买资阳托管服务器服务,并享受7*24小时金牌售后服务。

  battery historian是一款用于检测与电池有关的信息和事件的工具,运行在Android 5.0 Lollipop (API level 21)及其之后。它会生成一张具有时间坐标的图纸,用户可以查看各种事件耗电时间。

安装

一、首先安装Go编程语言

  1. 点击下载【下载】;

  2. 安装Go;
    app电量测试之Battery Historian介绍

  3. 配置GOROOT和GOPATH

a. GOROOT的作用是告诉Go 命令和其他相关工具,在哪里去找到安装在你系统上的Go包,所以这里配置的是GO的安装目录

 app电量测试之Battery Historian介绍

 

b.GOPATH可以简单理解为是工程的目录,所以创建一个GO的工程路径

 app电量测试之Battery Historian介绍

 

         C.最后配置一下环境变量,把Go的bin目录放到path环境变量中

 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. 环境变量配置,添加Path的路径,是Python的安装路径
    app电量测试之Battery Historian介绍

  4. 输入命令行 python –V(注意是大写V)检查是否安装成功

 app电量测试之Battery Historian介绍

 

四、安装Java环境

  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;如果没有均手动创建

     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下执行以下命令,开启电池数据获取

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

    2.windows cmd下执行以下命令,重置电池数据

        adb shell dumpsys batterystats --reset

  二、操作应用,生成bugreport

      拔掉USB,然后对待测app进行相关操作,一段时间后,插上USB,运行一下两条命令。

      1.windows cmd下执行以下命令,将bugreport信息保存到相应路径下,等待执行完毕

          adb bugreport > bugreport.txt

      2.windows cmd 下执行以下命令,将以上txt文档转化为html文件

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

          注:现在不知道为什么会提示错误,找不到historian.py这个文件

      上面的historian.py 就是用python写的脚本,所以需要python环境,可以从github上下载,以上命令执行完后,会发现两个文件,bugreport.txt和battery.html,这个时候用谷歌浏览器输入http://localhost:9999,上传bugreport.txt或者是直接打开battery.html就可以了,视图如下:

  app电量测试之Battery Historian介绍

以上是V2.0版的,你可以自己切换到1版,现在来分析下各个参数的意义:

 

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

    收集电量数据时,系统中处于top的应用,如果你的应用是前台的,请确保它是top的。除非你想知道你的应用在后台时的电量消耗。
  • wifi_running

    wifi连接活跃时间。
  • screen:

    屏幕点亮时间。
  • phone_in_call:

    通话时间。
  • wake_lock

    注意,在表格中,它是代*的,它是最重要的参考。
    通常应用的运行周期是启动,运行一些作业,然后睡觉。启动是最费资源的,如果在这行里出现多个小坚条,说明有问题。
  • running

    cpu运行时间。
  • wake_reason

    内核最后一次唤醒的原因。如果是由你的应用唤醒,请确定是否必要这么做。
  • mobile_radio

    无线电开启的时间,开无线电非常耖电。这里出现密集的小坚条,说明有优化空间。
  • 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

    最近一次充电时系统参数的统计,如电池信号等级,屏幕亮度。
  • Estimated power use (mAh) by UID and peripheral:

    粗略统计电池的mAh。
  • Per-app mobile ms per packet

    使用无线电设备传输数据的时间间隔。好的应用会以密集批量方式传输。
  • All partial wake locks

    wakelocks的统计。

     

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

 最后我们还可以看到相关进程耗费的电量(估算值):

  app电量测试之Battery Historian介绍

分享标题:app电量测试之BatteryHistorian介绍
文章出自:https://www.cdcxhl.com/article20/gijjjo.html

成都网站建设公司_创新互联,为您提供企业网站制作网站收录网站设计公司网站改版网站策划微信公众号

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都app开发公司