There are a number of tools you can use to debug a locally-running app that uses wake locks. These tools can help you identify and fix performance issues.
The following tools can help you debug or optimize your wake locks:
- dumpsys provides information about the status of system services on a device.
- System tracing produces a trace file that you can use to generate a system report.
- The Android Studio Background Task Inspector helps you to monitor wake locks, including wake locks that might be acquired by libraries like WorkManager.
dumpsys
dumpsys is a tool that runs on Android devices and provides information about the device's system services.
The following command is particularly useful for debugging wake locks:
adb shell dumpsys batterystats
provides a detailed history of wake locks held by each app. For more information, see the dumpsys Inspect battery diagnostics documentation.
System tracing
System tracing records a wide range of device activity over a short period. System tracing produces a trace file that you can use to generate a system report. This report helps you identify ways to improve your app's performance.
For information on how to get started, see this system tracing quickstart guide. You can also watch this video on improving Android battery efficiency.
Background Task Inspector
You can use Android Studio's Background Task Inspector to monitor wake locks, alarms and jobs.
In particular, the WorkManager library uses JobScheduler to schedule and execute jobs. These jobs hold a wake lock on the app's behalf when running in the background. You can use Background Task Inspector to monitor workers and jobs that execute in the background and see details about their work.