platform:mt6739 android 8.1
battery historian是用go语言开发的一个电池耗电分析工具,Android 5.0以后的版本可以使用它,其官方文档地址,以下是google官方关于Battery Historian的说明:
Battery Historian is a tool to inspect battery related information and events on an Android device running Android 5.0 Lollipop (API level 21) and later, while the device was not plugged in. It allows application developers to visualize system and application level events on a timeline with panning and zooming functionality, easily see various aggregated statistics since the device was last fully charged, and select an application and inspect the metrics that impact battery specific to the chosen application. It also allows an A/B comparison of two bugreports, highlighting differences in key battery related metrics.
linux环境下,安装和执行battery historian的过程(基于windows的待验证):
1. Install Docker
For Linux, you're done! Historian will be available at "port".
//尖括号在该文无法识别,"port"使用双引号代替尖括号
2. Go语言执行环境的安装
2.1 Make sure you have at least Golang version 1.8.1
在用户的家目录下创建一个tool的目录,下载Go语言的执行环境源码(包含一些工具,库),是一个类似于"go$VERSION.$OS-$ARCH.tar.gz"的压缩包,然后解压到家目录下。
tar -xzf go$VERSION.$OS-$ARCH.tar.gz -C ~/tool
选择合适的执行环境源码来安装,举例,如果你在64-bit x86 on Linux安装Go version1.2.1,执行环境源码请选择go1.2.1.linux-amd64.tar.gz.
xxx@xxx-virtual-machine:~/tool/go$ ls
api AUTHORS bin bugreport.txt CONTRIBUTING.md CONTRIBUTORS doc favicon.ico lib LICENSE misc PATENTS pkg README.md robots.txt src test VERSION
2.2 增加环境变量
增加~/tool/go/bin到PATH环境变量里面. 你可以在$HOME/.profile或者/etc/profile里面增加如下一行:
export PATH=$PATH:~/tool/go/bin
2.3 检查Go语言执行环境是否安装正确
Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.
在家目录下创建一个go-test目录,然后在这个目录下面创建一个文件命名hello.go,文件的内容如下:
-
package main
-
-
import "fmt"
-
-
func main() {
-
fmt.Printf("hello, world\n")
-
}
然后使用go tool来编译,如下:
xxx@xxx-virtual-machine:~/work/go-test$ go build
xxx@xxx-virtual-machine:~/work/go-test$ ls
go-test hello.go
//编译完成以后,会生成一个go-test的可执行文件
xxx@xxx-virtual-machine:~/work/go-test$ ./go-test
hello, world
//执行go-test这个可执行文件,如果你看到"hello, world"消息,说明Go语言的执行环境安装成功了。
3. install Git from if it's not already installed
4. make sure Python 2.7 (NOT Python 3!) is installed
如果没有安装Python,请参考来安装,然后确保python已经被增加到PATH环境变量里面,我们可以通过执行python来查看python的版本号,如下:
xxx@xxx-virtual-machine:~/work/go-test$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
5. install Java from
6. download the Battery Historian code and its dependencies
我们可以执行去网站下载源码(已经验证过),也可以通过如下命令来下载(没有验证过?):
go get -d -u github.com/google/battery-historian/...
将下载好的Battery Historian源码复制到go执行环境下,如下:
xxx@xxx-virtual-machine:~/tool/go/src/cmd/vendor/github.com/google$ ls
battery-historian pprof
7. 安装和执行battery historian源文件
使用如下命令来安装battery historian源码:
xxx@xxx-virtual-machine:~/tool/go/src/cmd/vendor/github.com/google/battery-historian$ go run setup.go
Generating JS runfiles...
Generating optimized JS runfiles...
//安装battery historian源码需要protobuf的库,如果protobuf不存在,到地址下载源码,然后放到go的安装目录下的github.com/golang目录,如下:
xxx@xxx-virtual-machine:~/tool/go/src/cmd/vendor/github.com/golang$ ls
protobuf
接下来执行Historian(确保PATH环境变量包含~/tool/go/bin):
xxx@xxx-virtual-machine:~/tool/go/src/cmd/vendor/github.com/google/battery-historian$ go run cmd/battery-historian/battery-historian.go
2019/01/04 13:53:07 Listening on port: 9999
//需要注意的是,9999是battery historian默认使用的端口,另外我们必须在~/tool/go/src/cmd/vendor/github.com/google/battery-historian目录下执行go run cmd/battery-historian/battery-historian.go命令
8. 检查battery historian是否执行正确
在执行Historian的时候,我们可以在linux环境下打开浏览器,输入9999/网址,如果出现了"Choose a Bugreport File"的字样,说明battery historian安装正确了。
9. 如果本地没有安装battery historian,也可以打开 bathist.ef.lc 网页进入battery historian(网络需要fanqiang,才能打开这个网页),如下:
导入bugreport.zip以后,会出现"Submit"按钮,点击"Submit"按钮会上传和分析bugreport并得到整机完整的耗电图了
抓取并分析bugreport的步骤:
1.通过如下命令先重置电池统计状态
adb root
adb shell dumpsys batterystats --reset
adb shell dumpsys batterystats --enable full-wake-history
2.拔掉usb手机灭屏待机一段时间(1hr以上)
3.手机连上usb抓取bugreport
adb bugreport>bugreport.txt(Android N)
//执行完这个命令需要几分钟,可以等待一下。
备注:Android O生成的文件在PC当前的路径,文件名为bugreport-xxx.zip
4.在9999/网址里面选择bugreport-xxx.zip,就可以得到整机完整的耗电图了
如上图。
阅读(2137) | 评论(0) | 转发(0) |