如何安装和使用battery-historian

如何安装和使用battery-historian1

1st, 安装docker

安装环境:Ubuntu 14.04

$ sudo apt-get install docker.io

注意,不是sudo apt-get install docker哈

$ sudo docker -- run -p 8888:9999 gcr.io/android-battery-historian:2.1 --port 9999
Unable to find image 'gcr.io/android-battery-historian:2.1' locally
2.1: Pulling from gcr.io/android-battery-historian
58488e45273c: Pull complete 
25810b66099e: Pull complete 
6571ba684f54: Pull complete 
6ed49a73d8f0: Pull complete 
c53777cbfc31: Pull complete 
801f200083c1: Pull complete 
9790d6886da2: Pull complete 
57f4ce395f3e: Pull complete 
29200783fa94: Pull complete 
384304f39faf: Pull complete 
eccc5106f465: Pull complete 
91642318fc3e: Pull complete 
a76d9ce5d6cb: Pull complete 
592b4bbc2727: Pull complete 
ac590fb09999: Pull complete 
0b9679e44c58: Pull complete 
198aa29ac5bc: Pull complete 
2d217ec9c34a: Pull complete 
0e23a5dd4f83: Pull complete 
4499afe9afa5: Pull complete 
Digest: sha256:4b973376e09c9ebb7f269ceca3079eab084b14fe80d4f08c8921c9ea2fe2b527
Status: Downloaded newer image for gcr.io/android-battery-historian:2.1
2017/08/05 02:17:16 Listening on port:  9999

从上面的提示信息看,

Unable to find image 'gcr.io/android-battery-historian:2.1' locally
2.1: Pulling from gcr.io/android-battery-historian

也就是,在本地找不到android-battery-historian:2.1,那么会从网上自动下载.

2nd, 打开分析网页

打开:http://localhost:
从本例来看,我们直接在浏览器中打开:http://localhost:8888即可.
页面如下:

如何安装和使用battery-historian_第1张图片

3rd,从设备端获取待分析的Battery信息

To obtain a bug report from your development device running Android 7.0 and higher:
$ adb bugreport bugreport.zip
For devices 6.0 and lower:
$ adb bugreport > bugreport.txt

本例中:

$ adb bugreport bugreport.zip
Bugreport is in progress and it could take minutes to complete.
Please be patient and do not cancel or disconnect your device until it completes.
[100%] pulling bugreport.zip
然后点击Browse,然后选择生成的bugreport.zip,然后点击submit按钮,我发现部分浏览器这个按钮不显示,如果不显示,可以尝试换个浏览器,估计是插件的问题,这不重要,不再进行深入调查.

submit后的曲线图如下所示:
如何安装和使用battery-historian_第2张图片

4th, battery historian源码

如果对Battery historian源码感兴趣,可以下载对应的源码,方法参考如下:

4.1 安装go语言

登录官网:

https://golang.org/doc/install

下载并解压安装包

tar -zxvf go1.8.3.linux-amd64.tar.gz

配置go语言到环境变量

vim ~/.bashrc

添加如下,注意,这个GOBIN就是go1.8.3.linux-amd64.tar.gz解压后的路径,我直接将其解压到/usr/local/下了

GOBIN=/usr/local/go/bin
export PATH=$PATH:$GOBIN

然后让环境变量生效:

source ~/.bashrc

4.2 验证go语言安装是否ok

老办法,还是写个Hello, world!

mkdir src
vim hello.go

将下述内容添加进去

package main 
import "fmt"
func main(){
    fmt.Printf("hello, world\n")
}

编译

go build

然后生成了可执行文件 hello
运行

$ ./hello 
hello, world

下载源码,它会将源码下载到:~/go/src/github.com/google (~/go是go语言默认的下载路径,具体的请参考Reference的网站)

$ go get -d -u github.com/google/battery-historian/...

编译,运行

$ cd $GOPATH/src/github.com/google/battery-historian

# Compile Javascript files using the Closure compiler
$ go run setup.go

# Run Historian on your machine (make sure $PATH contains $GOBIN)
$ go run cmd/battery-historian/battery-historian.go [--port <default:9999>]

区别:一个是用docker运行,一个是用go来运行,这里列出来,对比下:

1st: docker -- run -p <port>:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999
2nd: go run cmd/battery-historian/battery-historian.go [--port <default:9999>]

结论:简单分析电池耗电情况,直接按1-3步骤就ok了.
Good luck!


References:


  1. https://github.com/google/battery-historian
    https://golang.org/doc/install ↩

你可能感兴趣的:(功耗优化)