耗电优化(二):Battery Historian
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.
作者:隋胖胖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图标并点击运行:
img
在右上角菜单栏看到多了一个鲸鱼图标,表明了 Docker正在运行。
img
点击菜单栏的Docker图标,可以弹出操作菜单。
在国内使用 Docker 的话,需要配置加速器,在菜单中点击 Preferences...,然后查看 Deamon 标签,在其中的 Registry mirrors 部分里可以点击加号来添加加速器地址。
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分析平台。
img
二、windows上搭建Battery Historian基本环境
1.安装Go编程语言
点击 下载go语言 。
配置GOROOT、GOPATH、PATH环境变量。
img
img
img
检查go是否安装成功:
img
2.安装git
点击 下载git 。按照步骤安装。
检查git是否安装成功:
img
3.安装python
注意:一定要装python2.7,不能是python3及以上版本~
点击 下载安装python 。按照步骤安装。
配置环境变量,添加python安装路径到path中。
img
检查python是否安装成功:
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目录下方
img
(3)运行Battery Historian
go run cmd/battery-historian/battery-historian.go
img
最后检查/battery-historian是否运行,登录网址 http://localhost:9999 查看是否加载运行battery historian。
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文件上传。
img
也可以选择前后两个txt文件进行电量数据的对比:
img
有疑问加站长微信联系(非本文作者)
Recommend
-
29
README.md Battery Historian Battery Historian is a tool to inspect battery related information and events on an Android device running Androi...
-
9
Why skin tone modifiers don’t work for , explained by an emoji historian by
-
1
Why skin tone modifiers don’t work for 🤝, explained by an emoji historianIt's the symbol of racial unity we all needThe Unicode Consortium kicked off a revolution of internet proportions when i...
-
7
This Historian Can Nail Exactly When Vintage Photos Were ShotAn urban history expert recently purchased vintage photos of New York City on eBay and followed several clues that led him to determine the exact month and year the images were take...
-
6
如果某个App耗电量过大会导致手机发烫,会导致电池寿命变短,会导致用户体验不好。 本文给出Energy impact、Energy Log、sysdiagnose三种耗电检测方案,帮你找到耗电的代码,帮你提高用户体验 Energy impactEdit Sche...
-
5
Canceled YouTuber Shane Dawson Is Back, For Some ReasonShane Dawson is set to make a video with fellow canceled YouTuber Jeffree Star, about their makeup collaboration being sold at discount stores.
-
3
How a Librarian and a Food Historian Rediscovered the Recipes of Moorish Spain A new cookbook is a translation of a rare, 13th-century volume. by
-
5
The Artificial Intelligence Historian November 8, 2021 The past actually happened but history is only what someone wrote down—Whitney Brown Pamela McCorduck passed...
-
6
WANTED: Pokémon Historian to Create ‘Pokémon Archive and Museum’The Pokémon Company says it's creating an "internal museum" to all things Pokémon.July 15, 2022, 4:00pm
-
8
Home ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK