11

耗电优化(二):Battery Historian

 3 years ago
source link: https://studygolang.com/articles/33230
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

作者:隋胖胖LoveFat

链接: https://www.jianshu.com/p/c223c95744d3

Battery Historian github地址: https://github.com/google/battery-historian

本文介绍在mac/windows上搭建Battery Historian的基本环境,以及如何采集安卓电量数据,最后如何在Battery Historian上分析电量数据。

一、mac上搭建Battery Historian基本环境

1.安装Docker

Docker for Mac 要求系统最低为 macOS 10.10.3 Yosemite,或者 2010 年以后的 Mac 机型,准确说是带 Intel MMU 虚拟化 的,最低 4GB 内存。

手动下载Docker安装包,可以通过这个链接下载: https://download.docker.com/mac/stable/Docker.dmg

同其他应用安装一样,将Docker图标拖到Application中即可。

在应用中找到Docker图标并点击运行:

Vrymayq.png!mobile

img

在右上角菜单栏看到多了一个鲸鱼图标,表明了 Docker正在运行。

aU3Qbei.png!mobile

img

点击菜单栏的Docker图标,可以弹出操作菜单。

在国内使用 Docker 的话,需要配置加速器,在菜单中点击 Preferences...,然后查看 Deamon 标签,在其中的 Registry mirrors 部分里可以点击加号来添加加速器地址。

yUfEF3Q.png!mobile

img

启动终端后,通过命令可以检查安装后的 Docker 版本。

$ docker --version

Docker version 17.06.0-ce, build 02c1d87

2.启动Battery Historian镜像

很简单

打开终端,执行一条指令即可:

docker run -p 9999:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999

如果未曾运行过此 Docker 镜像,将会自动下载此镜像并安装。前一个9999 端口指的是映射到本地端口,这意味着,当镜像执行后,可通过127.0.0.1:9999访问此镜像。可以自行更改此端口。如果成功,将输出如下信息:

2017/08/23 15:42:22 Listening on port: 9999

这时通过localhost:9999地址可以访问到Battery Historian分析平台。

3YbaEr3.png!mobile

img

二、windows上搭建Battery Historian基本环境

1.安装Go编程语言

点击 下载go语言

配置GOROOT、GOPATH、PATH环境变量。

73YVraI.png!mobile

img

JrqqUj6.png!mobile

img

QbErqyr.png!mobile

img

检查go是否安装成功:

au6ZziI.png!mobile

img

2.安装git

点击 下载git 。按照步骤安装。

检查git是否安装成功:

eQjIjqu.png!mobile

img

3.安装python

注意:一定要装python2.7,不能是python3及以上版本~

点击 下载安装python 。按照步骤安装。

配置环境变量,添加python安装路径到path中。

VRvIbmb.png!mobile

img

检查python是否安装成功:

jeaiaaU.png!mobile

img

4.安装java

默认一般电脑上都是安装java的,且java安装教程太多了,可以随意百度~~

5.下载battery historian及运行

(1)输入命令行go get -d -u github.com/google/battery-historian/...

下载源码到GOPATH配置目录下

(2)进入到$GOPATH/src/github.com/google/battery-historian目录下方

JR3mqmY.png!mobile

img

(3)运行Battery Historian

go run cmd/battery-historian/battery-historian.go

VrAJBrm.png!mobile

img

最后检查/battery-historian是否运行,登录网址 http://localhost:9999 查看是否加载运行battery historian。

uaQZ7jn.png!mobile

img

三、生成bugreport文件

将手机用USB连接PC,使用adb 命令清空历史数据:

adb shell dumpsys batterystats --reset

拔出USB。

接下来,操作使用手机一样,操作你想要统计的应用。耗电记录器会在后台统计整台机子所有的耗电情况。

操作差不多之后,连接USB,执行adb bugreport命令:

adb bugreport > bugreport.txt

bugreport.txt 就是记载着整台手机耗电信息的源数据。

遇到的坑:

在执行adb bugreport的时候报错:

Failed to get bugreportz version, which is only available on devices running Android 7.0 or later.

这是因为使用的platform-tools版本为25导致的,可以换成低版本,如21。

四、Battery Historian分析电量数据

在Battery Historian分析平台点击choose a bugreport file,然后选择生成的bugreport文件上传。

y2AR3yi.png!mobile

img

也可以选择前后两个txt文件进行电量数据的对比:

EBJbAjf.png!mobile

img

有疑问加站长微信联系(非本文作者)

eUjI7rn.png!mobile

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK