Show navigation Hide navigation

Batterystats & 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

What it's good for:

  • Showing you where and how processes are drawing current from the battery.
  • Identifying tasks in your app that could be deferred or even removed to improve battery life.


Working with Batterystats & Battery Historian

  1. Download the open-source Battery Historion Python script from GitHub (
  2. Unzip the file to extract the Battery Historian folder. Inside the folder, find the 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,
    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; otherewise, 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 batterystats.txt > batterystats.html
  15. Open the batterystats.htm file in your browser.
  16. Continue with Battery Historian Charts.
  17. Figure 1. Battery Historian output.