Android - Profiler
This tool helps you find where your app uses more energy than necessary.
It consists of three timelines: Event timeline, Energy timeline and System timeline.
The Profiler monitors the use of CPU, network, GPS and system events and presents them in form of bars and horizontal lines (system events).
The higher/longer the bar is, the more energy is being used.
You can place a mouse over any part of the timeline for more info.
Enabled developer options
- Go to Software info (location varies depending on phone brand)
- Tap multiple times on "Build Number" (or "MIUI version" for Xiaomi devices) until you see a toast message: "You are "X" steps away from being a developer."
- Enable "Developer options" (location varies depending on phone brand)
Enabled USB Debugging + Debug build
- USB debugging (found under "Developer options") set to "ON".
- "Allow USB debugging" prompt set to "OK" and "Always allow from this computer" checked (this prompt shows up when the phone is connected to a computer for the first time).
- Installed debug build of the app you plan to monitor (kindly ask your developer to make one for you). In case your device is rooted, you can monitor any build.
- Download, install and run Android Studio.
- Click on "New Project".
- Select "No Activity" and click Next.
- Set the "Name" and "Android version" that isn't above the one you are running on your test device (otherwise Android Studio will notify you with a warning).
- Your device should be visible in the top bar, next to the green "Play" button (if it isn’t, check the troubleshooting section of this article).
- Click on "Profiler" in the bottom bar of Android Studio.
- Click on "+". Your test device should be present here.
- Select the device and the app you want to monitor. In case your app isn't present, try to run it on your device first to trigger a refresh in Android Studio.
- Once the session starts, the only thing left is to click on the "Energy" timeline to zoom on battery consumption. The monitoring lasts until you press the "Stop" button. After stopping, you can inspect the recorded session.
The Energy Profiler provides the user with insight into the usage of these events and processes to check if there are any excessive impacts on the battery.
For more info about "wake locks", "alarms" and "jobs" check this.
Troubleshooting - what to do if it doesn't work
- Check if you have ADB installed on your computer (if your are not sure or ask yourself "What is ADB?" check this).
- Check if you set "USB debugging" to "ON".
- Try the "Revoke USB debugging authorizations" option, disconnect the phone, connect it again and allow the connection via the prompt that shows up.
- Try other USB cables.
It is not so uncommon to connect the phone to a computer by micro USB cable, only to find out that the cable you used can only charge the device (more info).
USB-C cables are a bit better in that aspect but even they aren't all same.
- Make sure that the app you plan to monitor is a debug build.
- In case you don't see the app you want to monitor in Android Studio - try to run it on the device first, that should trigger a refresh in Android Studio.
Running Android Profiler without Android Studio
There is an option to run Android Profiler without running full Android Studio.
The only requirement is Java installed on the computer you are using and that the Profiler isn’t currently running inside Android Studio.