Battery-Historian of Android Performance Optimization (1)

After the APP development reaches a certain stage, power optimization is a problem that has to be faced. Tracking and dividing the power usage of the APP is the only way for us to solve this problem. Although there are many power analysis software, we will focus on this article. Select the battery Historian 2.0  power analysis tool, a new version of Battery Historian released by Google in Google I/O 15  ; But the actual installation process may be different).

step:

1. The new version of Battery Historian is written in Go language, so we need to install the Go development environment first . The  download address is http://golang.org/doc/install  . I chose go1.6.3.windows-amd64.msi version , the reason for using the msi version is that it is easy to install, and it will help us configure environment variables by default;

Note: During the installation process, we can choose the installation directory by ourselves. It is recommended not to change it. Just use the default "C:\Go". I tried to change it and found that although the configuration in the environment variable is also the path I changed, but in The go command cannot be used directly under cmd, the reason is unknown;

Finally, confirm that the environment variable GOROOT is C:\Go\, and add the item C:\Go\bin to Path.



Then open a new command window, type go help, the following shows that the go environment is normal;


Then configure the working directory of Go, I created a new D:\Go\workspace\ directory under the D drive as the working directory;

Type the command in the command window:

C:\Go\bin>set GOPATH=D:\Go\workspace
In order to check whether the Go environment can compile and run normally, you can refer to the official instructions of Go:

Create a new one in the workspace directory src/github.com/user/hello目录,如果有自己的GitHub账户,可以将user换成自己账户的名称;然后再在hello文件加下创建hello.go文件,并写入下面的代码:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

Then type the following command in the command window:

C:\> go install github.com/user/hello

Execute the command again:

C:\> %GOPATH%\bin\hello

will print out in the window:

hello, world
It means that everything is ok in our Go environment;



2. If there is no Git, go to install Git ; the installation process will not be repeated, and finally make sure that the installation directory of Git is added to the environment variable Path as follows:


3. Install Python2.7 (not Python3.X), and download Python ; the installation process is relatively simple, and the default is all the way. Finally, configure the Python installation directory to the environment variable path, as follows:



4. Install the Java environment, not much to say about the installation and configuration process, the computer that develops Android has already been installed; download JavaSE ;

5. After everything is ready, you can start to formally import and use the Battery Historian project;

First clone the project to the working directory of go:

C:\Go\bin>go get -d -u github.com/google/battery-historian/...
After the project is imported, in the command window, switch the current directory to the directory \workspace\src\github.com\google\battery-historian, as follows:



Then enter the command:

go run setup.go

This process is slower, and you need to download the third-party packages that the project depends on;

Enter the command when finished:

go run cmd\battery-historian\battery-historian.go


出现如上图变运行成功,项目服务默认监听9999端口;

然后我在浏览器中输入http://localhost:9999/便可出现如下界面:


截至目前位置,Battery Historian项目算是跑起来了,下篇再来探讨怎么使用;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325901579&siteId=291194637