Analyze and optimize application power
In the Android project, it is difficult to monitor the power consumption of applications, but users are very concerned about the standby time of mobile phones. applications with excessive power consumption will be ruthlessly uninstalled by users. Do not be lucky enough to bring opportunities to competing products. therefore, we need to study and optimize the power consumption of applications. this article explains Battery Historian, a power analysis tool for Android systems provided by Google. the page displays the power consumption process of the mobile phone. Enter the power analysis file to display the power consumption. finally, some power optimization methods are provided for reference.
1. Install Go
Battery HistorianIt is developed in the Go language and requires the Go compiling environment to be installed.
Download the installation package for Mac and check the Go version.
? ~ go versiongo version go1.6 darwin/amd64
In.bash_profile, Set the Go language variable
#Go Settingsexport GOPATH=/Users/.../Workspace/GoWorkspaceexport GOBIN=/Users/.../Workspace/GoWorkspace/bin
GOPATH Source Code address. GOBIN generation address. $ GOPATH/bin is recommended.
Runsource .bash_profile, Apply profile configuration.
Create a src folder and add a HelloWorld Filehello.go.
package mainimport "fmt"func main() { fmt.Printf("hello, world\n")}
Install hello. go
go install hello.go
Run
$GOBIN/hello
Ifhello, worldIndicates that the installation is complete.
2. Battery Historian
Install wget in advance when installing Battery Historian.
sudo brew install wget
FollowBattery HistorianThe GitHub document.
Go get-u github.com/golang/protobuf/protogo get-u github.com/golang/protobuf/protoc-gen-gogo get-u ready $ GOPATH/src/github.com/google/battery-historianbash setup. sh # run Go script, default port 9999 go run cmd/battery-historian/battery-historian.go [-- port
]
Start command
cd $GOPATH/src/github.com/google/battery-historiango run cmd/battery-historian/battery-historian.go [--port
]
In the browser, enterHttp: // localhost: 9999/To start the power detection page.
When starting the page, you may need to connect to the VPN to access Google information.
3. Analysis
Obtain the power file of the mobile phone and export it to the root directory for backupBattery HistorianUse.
adb bugreport > bugreport.txt
UseBattery HistorianWebpage LoadingBugreport.txtFile.
Submit again if you have any questions.Bugreport.txtFile.
System status
Application Status (simplified)
4. Power Optimization
AccordingBattery HistorianIndicates the power consumption information, including
Wake-up lock \ SyncManager synchronization Manager \ audio/video \ traffic.
Optimization Method:
(1) Check allWakeup lockWhether there are redundant or useless locations.
(2) centralized relatedData Request, Unified transmission; streamline data and reduce the transmission of useless data.
(3) analysis and statisticsNot importantOperation can be performed when the power is sufficient or WIFI is connected. For more information, see JobScheduler.
(4) Streamlined and redundantService)To avoid consuming power for a long time.
(5) NotePositioningInformation Acquisition, closed in time after use.
It is not difficult to optimize power consumption, but you need to be familiar with your business, understand the usage of some power consumption operations, and optimize the power consumption in a timely manner. only by providing Refined User Experience can users like our applications better. This is the essence of a service-oriented society.