Skip to content

Most visited

Recently visited

navigation

Batterystats and Battery Historian Walkthrough

This walkthrough shows the basic usage and workflow for the Batterystats tool and the Battery Historian script.

Batterystats collects battery data from your device, and Battery Historian converts that data into an HTML visualization that you can view in your Browser. Batterystats is part of the Android framework, and Battery Historian is open-sourced and available on GitHub at https://github.com/google/battery-historian.

What it's good for:

Prerequisites

Working with Batterystats & Battery Historian

  1. Download the open-source Battery Historion Python script from GitHub (https://github.com/google/battery-historian).
  2. Unzip the file to extract the Battery Historian folder. Inside the folder, find the historian.py file and move it to the Desktop or another writable directory.
  3. Connect your mobile device to your computer.
  4. On your computer, open a Terminal window.
  5. Change to the directory where you've saved historian.py,
    for example: cd ~/Desktop
  6. Shut down your running adb server.
    > adb kill-server
  7. Restart adb and check for connected devices.
    > adb devices

    If you don't see any devices, make sure your phone is connected, and USB Debugging is turned on, and then kill and restart adb.
  8. Reset battery data gathering.
    > adb shell dumpsys batterystats --reset

    Resetting erases old battery collection data; otherwise, the output will be huge.

  9. Disconnect your device from your computer so that you are only drawing current from the device's battery.
  10. Play with your app for a short time.
  11. Reconnect your phone.
  12. Make sure your phone is recognized: > adb devices
  13. Dump all battery data. This can take a while:
    > adb shell dumpsys batterystats > batterystats.txt
  14. Create a HTML version of the data dump for Battery Historian:
    > python historian.py batterystats.txt > batterystats.html
  15. Open the batterystats.html file in your browser.
  16. Continue with Battery Historian Charts.
  17. Figure 1. Battery Historian output.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)