오늘은 안드로이드 단말에서 배터리 사용량을 분석하는 Battery Historian을 구축 후기(?) 및 기록을 남기려고 한다. 사실 구축을 하기 위해서 많은 것이 필요하지는 않으나 그래도 기록을 남겨두어야 나중에 까먹지 않고 회상하여 빠르게 문제점을 기억하고 회피할 수 있기 때문이다. 일단 Battery Historian 은 구글에서 제공하는 것으로 보인다. repo 자체가 google 하위에 존재한다.
아래 git hub 링크에서 소스를 확인할 수 있다. 사실 도커로 구성하는 것이 매우 간편하게 되어있기에 크게 구축 후기라고 생각할만한 것도 없었다.
GitHub - google/battery-historian: Battery Historian is a tool to analyze battery consumers using Android "bugreport" files.
Battery Historian is a tool to analyze battery consumers using Android "bugreport" files. - GitHub - google/battery-historian: Battery Historian is a tool to analyze battery consumers usi...
github.com
Battery Historian 구축
일단 로컬에서 구축을 해보아야하니 docker를 미리 준비하고 실행을 한다. 필자는 8082 포트를 사용하기로 했다.
# docker -- run -p <port>:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999 라고 기록이 되어있으니 port 부분만 잘 변경하면 된다.
docker -- run -p 8082:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999
실제로 명령어를 수행하면 image 가 없다며 다운로드 받아주고 실행까지 한 번에 시켜준다.
실행할 때 백그라운드로 실행하지 않았기 때문에 커서가 저렇게 표시되고 있다. 나중에 서버를 실제로 기동 할 때는 &(백그라운드 옵션)을 줘서 수행하고 ps -ef | grep battery 명령어를 수행하여 pid(process id)를 알아내서 kill -kill pid로 battery historian을 종료하기를 바란다.
- 실행 시 : docker -- run -p 8082:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999
- 종료 시 : ps -ef | grep battery 로 pid 알아내서 kill 명령어로 종료할 것
- 종료 시 2: docker desktop 이 있다면 해당 이미지를 stop 하면 된다.
서버를 무사히 기동 했다면 아래 그림과 같은 화면이 나타나게 된다. 자 이제 다 된 것 같다.
서버 구축에 실패한 Battery Historian
서버에 Battery Historian 동일하게 docker로 띄우려고 했으나 실패했다. 바로 centos의 docker는 internet 이 안돼서 external javascript 와 Jquery 등을 로드하는데 실패해서 파일을 업로드할 수가 없었다. 열심히 검색해서 bridge를 이용하는 것이 문제가 되어 이것저것 시도해 보았으나 결국 실패하였고 다른 방법을 찾아보기로 했다. 안되면 되게 하면 되는 것 아닌가! 다시 아래 github 링크로 들어가서 Build from source code를 참고하여 진행해보았다.
GitHub - google/battery-historian: Battery Historian is a tool to analyze battery consumers using Android "bugreport" files.
Battery Historian is a tool to analyze battery consumers using Android "bugreport" files. - GitHub - google/battery-historian: Battery Historian is a tool to analyze battery consumers usi...
github.com
여기서 주의할 점은 전역으로 접근이 가능한 user 로 설치해야 한다. 중간에 환경변수 등을 잡아야 하는 내용이 있는데 사용자 개인 계정으로 설정할 경우 bash_profile 등이 일치하지 않아서 담당자 외에는 서버를 기동하고 종료하는 것에 대해서 공유가 되지 않는다. 만약 담당자가 퇴사라도 한다면 다음은 어떻게 될지 한 번쯤 상상해봅시다.
일단 golang, git, java, python 등을 준비해야한다. 아래 가이드를 참고한다.
1. Make sure you have at least Golang version 1.8.1
=> http://golang.org/doc/install
2. Install Git from https://git-scm.com/downloads if it is not already installed.
3. Next, make sure Python 2.7 (NOT Python 3!) is installed. See https://python.org/downloads if it is not, and ensure that python is added to your $PATH environment variable.
4. Next, install Java from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
빌드에 필요한 것들이 준비가 되었다면 battery historian 을 위한 환경 변수를 잡아준다.
# For Linux and Mac OS X, you can add the following lines to your ~/.bashrc or ~/.profile files (assuming your workspace is $HOME/work):
# 여기에서 중요한 것은 계정의 $HOME 폴더 하위에 작업할 work 라는 이름의 폴더를 만들어 두어야한다.
# work 라는 이름이 싫다면 GOPATH 에서 work 를 다른것으로 변경하면 된다.
export GOPATH=$HOME/work
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
자, 이제 거의 다 왔다. 아래 명령어들을 순차적으로 수행하면 잘 된다(?). 였으면 좋겠지만 go run setup.go 에서 thirdparty의 parse 에러가 다수 발생한다.
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>]
go run cmd/battery-historian/battery-historian.go --port portnum(8082) &
열심히 찾아보니 이미 등록된 이슈가 있었고 그에 대한 해결방법이 있었다. (이슈 링크 : https://github.com/google/battery-historian/issues/203) 아래와 같이 수행하면 된다고 한다. 아마도 third-party 에 대한 cdn 이 깨지면서 오류가 발생하는 것 같은데 third-party 만 따로 branch를 만들어 둔 것으로 보인다.
cd "$GOPATH/src/github.com/google/battery-historian/third_party/closure-library"
git checkout v20170409
cd "$GOPATH/src/github.com/google/battery-historian"
go run setup.go
자 그럼 다시 서버를 기동해보자.
cd $GOPATH/src/github.com/google/battery-historian
go run cmd/battery-historian/battery-historian.go --port 8082 &
무사히 서버가 잘 기동 되고 파일 업로드 시 submit 버튼과 분석 결과가 잘 나오길 바란다.
댓글