In order to fulfill the basic functions of our service, the user hereby agrees to allow Xiaomi to collect, process and use personal information which shall include but not be limited to written threads, pictures, comments, replies in the Mi Community, and relevant data types listed in Xiaomi's Private Policy. By selecting "Agree", you agree to Xiaomi's Private Policy and Content Policy .
Agree

Tips & Tricks

[Tutorial] [Step-By-Step] Analyze Your Battery Like A PRO with Battery Historian!

2016-09-04 21:40:47
8674 24


Hello there,
Battery-Lovers

One of the most common thing every droidian talks about is battery, we love battery talks!
well we do have many tools out there for analyzing when things go haywire but almost all require rooting which is not liked by everyone. without root or required permissions it leaves you in very limited scope of digging in.
Ever wondered, how developers might be tracking down bits & bytes of battery data? what if I tell you that even without rooting you can have the most possible richest information possible, that too in an official way.
The Answer is: Bug Report!

You heard it right! well I know the android bugreport is kinda boring with all the data in it.
Likewise every each of you, Devs love visualization too & so google devs came up with a tool called Battery Historian.
Recently, silently it got new update too to v2.

Battery Historian is a tool which takes your bugreport as input, works over it and outputs a best possible timeline in a nice visual graph, all this with just a one time setup, which i wlll show you setting up here.
After that, you run your battery historian, generate your bugreport, upload to it & have the best details to track it down further.

we will cover this in three different steps:

1. Setting up Prerequisites (for windows)
2. Running Battery-Historian
3. Understanding Battery-Historian


Prerequisites

Step 1
- Go to http://golang.org/doc/install,
- Click "Download Go" & Choose your installation type, for windows user click on windows type.



- After the installation file gets downloaded, execute it & follow it (Everything Default)



- After installation of go, check if everything is working via command: "go version



Step 1.1
Setting up your WORKSPACE for go
- Create folder structure like this in, C:\


Step 1.2
Creating GOPATH Environment Variable
- Go to, Computer - Properties - Advanced system settings - Environment variables
- Click 'New' under 'System Variable'


- Add, GOPATH as variable name & path of workspace(we just created): C:\Projects\Go as variable value



- Open new cmd window (close any left open) and check via command: echo %GOPATH%


Step 2
- Download git from https://git-scm.com/downloads , for windows.
- Execute the downloaded file & Install it (Everything Default)


Step 3
- Go to https://www.python.org/downloads/ & Download Python 2.7 (NOT Python 3!)
- Execute the file (Everything Default)



Creating PATH variable for Python
- Go to, Computer - Properties - Advanced system settings - Environment variables
- Under System Variable, find PATH
- Click edit for PATH & add C:\Python27 in the list



Step 4
- Download JRE from here, http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Execute the file (Everything Default)

Troubleshooting for prerequisites:
- Ensure that GOPATH & GOBIN Environment variables are set in %path%
- Ensure Python is added to your system's %path% variable
- Check them via Computer - Properties - Advanced system settings - Environment variables - path

Run Battery Historian

Step 1
- Download the Battery Historian Code & it's dependencies, run the below command
go get -d -u github.com/google/battery-historian/...


It will take time downloading (no progress bar will be shown) & return the command prompt upon successful execution
Step 2
Go to the Battery-historian dir
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



Voila! You have your Battery-historian running on Port 9999 of localhost

- Incase you want to run on another port, then append "--port xxxx" to command like this


- Now open your browser and type this address
http://localhost:9999

Here it is running, waiting for your input to unveil the tons of information lying around.



Remember from next time run battery-historian from inside the %GOPATH%/src/github.com/google/battery-historian directory
or just two commands
cd %GOPATH%/src/github.com/google/battery-historian
go run cmd/battery-historian/battery-historian.go

TIP:

- Paste this two lines of code in a histrorian.txt file & rename it to historian.cmd.
- All you have to do is run this file everytime you want battery historian :)

Generate Bugreport

- Charge your device from 100% , let it come to your desired baterry level you want - when things go haywire using your battery
- Dial *#*#284#*#* , which will genrate bugreport & can be found in /sdcard/MIUI/debug_log/- You can use 'adb bugreport' too if you have developer options enabled in phone & using it.
- Now upload it in battery historian tab in browser with browse button.

Understanding Battery-Historian

After it completes analyzing, Battery Historian will present the visualization into mostly three parts

1. Timeline Graph
2. Tables - breakdowns of battery performance (including wakelocks)
3. File Info (Bugreport File Information)


We will cover the first two:
1. Timeline Graph

Timeline graph shows eveything that happened on a low system level along side the time & battery curve to investigate

It presents two versions of graph in two tabs
- Historian V2
- Historian V1 (old format)

Historian V2, currently shows time vs 39 parameters vs battery level to relate to particular events.I have shown 35 only, you can check/uncheck from drop-down menu.



Timeline can be scrolled on a desired battery drop & investigated further.
It also has a pan & zoom facility on a seconds level too for particular bits if you keep clicking one bit, Pretty neat ah!


Along with that, if you wish to select any specific chunk of paticular element/parameter just click over it & it will show hovering info for it.elAs i showed for doze below:



The rest & understanding of diffrent parameters I leave up to your exploration, as space & time might not be enough for it.
Though I will try adding information time to time.

2. Tables

Tables are nothing but all the info eloquently put in a categorical manner, which includes:

1. System Stats (sub-stats in image)
2. History Stats (sub-stats in image)
3. App Stats (per app basis)

you can select anyone of them from down left selection pane, Each one has sub-stats in it, as shown below:



If you click any of them from left, it will be expanded on the down right pane fully

System Stats
These are further divided Into total of 11

Aggregated Checkin Stats:
This shows aggregated info of most important entities at one placewhich includes:
- Screen on/off discharge rate, Screen on time
- Screen off uptime (imp)
- Userspace wakelock time (imp), Wakeup reasons
- Full wakelock time (imp)
- CPU usage - /user /system
- App wakeup Alarms, Sync activities
- Signal scanning time
- Idle mode & Idling time
- Total GPS, Wifi , Bluetooth times
- +others from other 10 entities under it



Device's Power Estimates:
This is basically the same "Battery" menu of android


Userspace Wakelocks:
This is a breakdown of how much time and how many times each of the apps on your device kept the CPU awake.


SyncManager Syncs:
This has the duration and count of all the account syncs your device does. This is stuff like refreshing calendar, all mi cloud syncing or fetching emails.


CPU Usage By App:
This shows CPU usage /app basis


WiFi Scan Activity Per App:
This shows list of what performed Wifi scans


WiFi Full Lock Activity Per App:
This shows apps which acquired Full Lock


WiFi Traffic Per App:
Pretty Straightforward


Kernel Wakesources:
Seems kernel wake sources on a hardware level names
Total time equals to the kernel overhead time, if you count


App Wakeup Alarms
seems total number of counts the app tried to wakeup


Camera Use By App
Straightforward, camera use per app basis


History Stats

According to your unplugging & Plugging of USB activity, it creates different Summary sessions.
Under each it shows total of 13 summaries broken apart, each are straighforward for it's name.

- Device State Summary
- DataConnectionSummary
- ConnectivitySummary
- PerAppSyncSummary
- FirstWakelockAfterSuspend
- DetailedWakelockSummary
- ForegroundProcessSummary
- PhoneStateSummary
- ScheduledJobSummary
- WifiSupplicantSummary
- PhoneSignalStrengthSummary
- WifiSignalStrengthSummary
- TopApplicationSummary
- DozeModeSummary


App Stats

For per app basis, you can sort the list of app with according to different criteria
& then select the name from the list, both shown jointly below:



on selecting one app, It will generate elements of table according to your usage of that app.

This is it, break down the stiff curve of severe battery drop, look into it
Find the problematic app or settings & do necessary changes.

I will be adding information time to time, meanwhile Happy Exploring!
Have a Better Better-y Day! Your comments are welcomed.


Bonus Tip
- Think too much of hassle running a local server? let me give you address of online server hosting Battery-historian
Click Here (Host Down)

All you have to do is just upload a bugreport now - just one step away! - Be cautious while using online server your bugreport might include your personal infomation.


Signing Off,
R0user

Rate

Number of participants 7 Experience +61 Pack Reason

View Rating Log

2016-09-04 21:40:47
Favorites23 RateRate
This is a pro original thread. Thanks for ur hardwork bro
2016-09-04 21:48:53
Fantastic thread as always...
2016-09-04 22:06:14

Advanced Bunny

Dr.Chinmay | from mobile

#3

Wow, that's really awesome, you just created a virtual app,  it will definitely help in soving battery ey issues
2016-09-04 22:29:02
Bhai now I will track every discharge like a pro XD
2016-09-04 22:32:43
Awesome work.
2016-09-04 22:48:21
Proud Mi Fan
As always... R0user's one more unique & useful thread..
I wonder if he is behind developing Android OS itself
2016-09-04 23:30:21

MIUI Beta Tester

Harish Mohanty | from mobile

#7

Really a pro post... It will help everyone
2016-09-05 00:20:33
MI FC BHUBANESWAR PRESIDENT

Admin

R0user Author |

#8

Dr.Chinmay replied at 2016-09-04 10:29 PM
Wow, that's really awesome, you just created a virtual app,  it will definitely help in soving batte ...

Thanks to Google devs for creating the script, with v2 the things became pretty neat now
2016-09-05 16:22:14

Admin

R0user Author |

#9

Er. Deep replied at 2016-09-04 11:30 PM
As always... R0user's one more unique & useful thread..
I wonder if he is behind developing Android ...

haha nothing like that buddy :p
2016-09-05 16:23:56
Outstanding !

Thank you for taking the time to collect all the information and sharing it with us  :)
2016-09-06 01:32:13
please sign in to reply.
Sign In Sign Up
Beta Tester
MIUI 8
Power At Last
AP2 Livestream
2016 Diwali with Mi
3 Days Check-In
7 Days Check-In
21 Days Check-In
40 Days Check-In
70 Days Check-In
100 Days Check-In
Shake!!Shake!!
Lucky Draw No.
500K Members
2016 Christmas
Mi Explorers
2016 #ThrowbackwithMiComm
1 million members
Xiaomi 7th Birthday
Fitness Guru
June-100 replies in a month
Тема мая 2017
1st Anniversary
Columnist
71st Independence Day
MIUI 9
MIUI 7th Anniversary
2 million registered members
Mi A1 Review Contest
Newbie Member
Diwali
Twitter Medal
Android O Tester
Mi Apps
Christmas 2017
2018 New Year Medal
ThrowBackWithMiCommunity
MIUI Instagram
MIUI Beta Tester
Mi Community Updater
STAR Bug Hunter
5-Star Motivator
MIUI 10
MIUI Subscriber
MIUI 8th Anniversary
5 Million Registered Users
Mi Music: 20 FREE Downloads
Ringtones Mania
App Review Team
10 Million Downloads
2019
Throwback With Mi 2018
Xiaomi's 9th Birthday
9 Years of MIUI

Copyright©2016-2019 Xiaomi.com, All Rights Reserved
Content Policy
Quick Reply To Top Return to the list