最新在做Android功耗方面的优化,用到了battery historain工具,配置过程中也遇到了一些小坑,记录一下,方面后边的人快速搞定这个事情。
一、配置Go语言环境
因为battery historain是使用go语言开发的,所以需要配置go语言开发环境
mac下的go语言安装包下载地址如下:
任选红框中的一个下载即可,第一个是压缩包,下载之后解压,我用的是这种方式,好处是能够自己指定安装目录。配置环境变量的时候不用再去找安装在哪了。

配置环境变量
GOROOT=/Users/xsdsd/Develop/go
export GOROOT
export PATH=$PATH:$GOROOT/bin
配置完成之后直接在命令行输入go,回车
如果出现如下提示,则说明go语言开发环境已经配置成功

二、下载安装battery historain
命令如下:
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/google/battery-histrizan
cd $GOPATH/src/github.com/google/battery-historian/
go run setup.go
go run cmd/battery-historian/battery-historian.go
如果你能顺利执行完以上步骤,那么恭喜,battery historain已经成功安装了
我在执行第三步的时候遇到问题了,提示失败,如下图所示

我试图先使用ssh登录github,但是还是有问题,最终的解决办法就是在go的src目录下新建gihub.com/google文件夹,再使用git clone命令把battery historain的代码给down下来
三、使用Battery Historain
执行完go run cmd/battery-historian/battery-historian.go命令之后会出现提示
Listening on port:9999
说明battery historain已经成功启动了
打开浏览器输入http://localhost:9999
记得需要翻墙,不然不能正常打开使用

然后需要生产bugreport文件
Android7.0以上的手机使用如下命令
$ adb bugreport bugreport.zip
Android6.0及以下的手机使用如下命令
$ adb bugreport > bugreport.txt
命令执行完成之后会在执行命令的目录下生成对应的bugreport文件
用刚才的网页打开即可看到效果

当然,battery historain工具提供的只是基础的数据,如果想进行功耗的优化,需要自己对这些数据进行处理。
网友评论