400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

app电量测试之BatteryHistorian介绍-创新互联

Battery Historian

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了郊区免费建站欢迎大家使用!

 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 ]

  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

You should also read

  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  各字段的含义 

 注意,上面的每行分类只是根据当前开启的功能或服务,应用收集的数据。并不是每次都一样,如wifi没开,就不会有wifi相关的数据,gps没开就没有gps相关数据。
 

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

 batterystats.txt 显示的是全部数据。batterystats.html显示的只是它分析时所需的数据。

app电量测试之Battery Historian介绍

Figure 2.Example of filtered batterystats output.

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

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

  app电量测试之Battery Historian介绍

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:app电量测试之BatteryHistorian介绍-创新互联
文章位置:http://mzwzsj.com/article/dioijo.html

其他资讯

让你的专属顾问为你服务