何为Battery Historian
Battery Historian是Android提供的用于分析功耗问题的工具,它有如下适用场景:
- 显示进程从什么位置以及通过何种方式消耗电池电量。
- 识别系统为了延长电池续航时间可能会延迟甚至移除应用中的哪些任务。
具体详见官网:https://developer.android.google.cn/topic/performance/power/setup-battery-historian?hl=zh_cn
怎么安装Battery Historian
具体安装方法,详见google提供的方法:https://github.com/google/battery-historian
建议不要用docker的方式安装,因为该方式安装后,在没有出现submit后,要去Battery Historian目录下解决对应问题会比较麻烦。因此,建议使用“Building from source code”的安装方法。
在按照官网的方法,完成了go和Battery Historian的安装后,有下面几个问题需要处理:
(1)执行“go run setup.go”命令时,会出现无法找不到github.com等的若干提示,此时需要去其他网站下载这些文件,然后根据报错的提示,将这些文件放到对应的位置;
(2)执行“go run cmd/battery-historian/battery-historian.go [--port <default:9999>]”后,然后按下电脑键盘上的F12按键,此时会发现有许多的js和css文件无法找到,这些也需要到其他网站下载然后放到对应的位置。总共有三个地方需要注意:
其一:在目录go/src/vendor中放置如下文件
├── github.com
│ ├── golang
│ └── google
├── golang.org
│ └── x
├── google.golang.org
│ └── protobuf
其二:在go/src/vendor/github.com/google/battery-historian/third_party目录中放置如下文件
├── closure-compiler
├── closure-library
├── flot-axislabels
└── jquery.flot.orderBars.js
其三:更改go/src/vendor/github.com/google/battery-historian/templates/base.html文件,将那些无法找到的js和css文件的链接换成可以找到的地方,如
<html lang="en">
<head>
<link rel="stylesheet" href="//cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.css">
<script src="//libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.4/select2.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/1.6.6/jquery.contextMenu.css">
<link rel="stylesheet" href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.4/select2.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/1.6.6/jquery.contextMenu.js"></script>
<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.4/moment-timezone-with-data.js"></script>
<script type="text/javascript" src="https://www.google.cn/jsapi"></script>
上述仅进行粗略的描述,操作起来还是需要一些时间去寻找相关文件的,以下链接是我验证可行的包含了go和battery-historian所有文件的压缩包,你只需要将其解压到本地,直接运行命令go run cmd/battery-historian/battery-historian.go [--port <default:9999>],然后通过链接http://localhost:9999打开即可。
下载链接:https://download.csdn.net/download/jidapenglin28/21889639
运行后的结果示意图: