电量优化之Battery Historian

电量的监测是一件很麻烦的事情,但是这件事在5.0以上手机将会轻松获得,下面就为大家介绍下google官方提供的工具,Battery Historizan。

官方文档见下:http://developer.android.com/tools/performance/batterystats-battery-historian/index.html

在官方文档中,为我们提供了2种方法,我们采用以下这种,因为它可以更加清晰的展示各个App的使用电量情况,网络发包情况,Cpu 使用,屏幕唤醒等等情况。

文档见下:https://github.com/google/battery-historian

If you are new to the Go programming language:

  • Follow the instructions available at http://golang.org/doc/install for downloading and installing the Go compilers, tools, and libraries.
  • Create a workspace directory according to the instructions at http://golang.org/doc/code.html#Organization.
  • Ensure that GOPATH and GOBIN environment variables are appropriately set and added to your $PATH environment variable. $GOBIN should be set to $GOPATH/bin.

    • For Windows, you may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.
    • For Linux and Mac OS X, you can add the following lines to your ~/.bashrc or ~/.profile files (assuming your workspace is $HOME/work):

        export GOPATH=$HOME/work
        export GOBIN=$GOPATH/bin
        export PATH=$PATH:$GOBIN
      

Next, install Git from https://git-scm.com/downloads if it's not already installed.

Next, make sure Python 2.7 (NOT Python 3!) is installed. See https://python.org/downloads if it isn't, and ensure that python is added to your $PATH environment variable.

Next, install Java from http://www.oracle.com/technetwork/java/javase/downloads/index.html.

Next, download the Battery Historian code and its dependencies:

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

Finally, run 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>]

Remember, you must always run battery-historian from inside the $GOPATH/src/github.com/google/battery-historiandirectory:

cd $GOPATH/src/github.com/google/battery-historian
go run cmd/battery-historian/battery-historian.go [--port <default:9999>]
How to take a bug report

To take a bug report from your Android device, you will need to enable USB debugging under Settings > System > Developer Options. On Android 4.2 and higher, the Developer options screen is hidden by default. You can enable this by following the instructions here.

To obtain a bug report from your development device:

$ adb bugreport > bugreport.txt

Start analyzing!

You are all set now. Run historian and visit http://localhost:9999 and upload the bugreport.txt file to start analyzing.

现在,我对英文说明简要的解释下:

1.首先要去官网下载软件,并安装

2.在你的目录中创建文件夹,如goworkspace,其中该文件夹包含3个子文件夹,src,bin,pkg。

3.配置环境变量 ,我用的是mac电脑。

查看你的go 是否安装成功,在终端输入命令行。go version  ,会看到 

go version go1.6.1 darwin/amd64 


将路径配置到环境变量,输入open -e .bash_profile ,

export GOPATH=/Users/cccc/goworkspace (输入go workspace的路径)
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

然后关闭编辑,保存source ~/.bash_profile

4.查看你的go 的环境是否配置成功

输入 go env



5. 安装git

6. 安装python ,make sure Python 2.7 (NOT Python 3!)

输入whereas python ,查看安装地址

python version,查看版本。

7.如果以上步骤都成功,恭喜你马上就可以看到了

download the Battery Historian code and its dependencies:

$ go get -d -u github.com/google/battery-historian/...
8. Finally, run 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>]
9. adb shell dumpsys batterystats —reset

10.断开手机,使用App

11.adb bugreport > bugreport.txt

12.打开 网页http://localhost:9999


13.上传bugreport.txt,然后选择你要查看的App




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值