page.title=Batterystats & Battery Historian Walkthrough meta.tags="android, performance, profiling, tools, battery, batterystats, historian, batterydrain page.tags="android", "performance", "profiling", "tools", "battery", "batterystats", "historian", "batterydrain" page.metaDescription=Collect battery usage data from your device and display it graphically in your browser. page.image=tools/performance/thumbnails/tools_battery_historian.png page.article=true @jd:body

You should also read

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; 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 historian.py 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.