Capture Android JVM heap dump snapshots (requires API 31+ for --type=perfetto, or API 29+ with --type=hprof).
Usage
android profiler heapdump [-h]
Options
-h,--help- Shows the help message for the specified command.
android options:
--sdk=PARAM- Path to the Android SDK.-v,--verbose- Enable verbose output for troubleshooting.-V,--version- Print version information and exit.
Subcommands
capture- Capture a JVM heap snapshot (requires API 31+ for --type=perfetto, or API 29+ with --type=hprof).
Description
The android profiler heapdump command set captures heap dumps of apps running
on a connected Android device or emulator. A heap dump is a snapshot of the
objects in the JVM heap of a process. By default, it's saved as an .hprof
file. Capturing an .hprof file requires a device running Android 10 (API
level 29) or higher, and a debuggable app (for example, a debug build), unless
the device runs a userdebug or eng build of Android. You can also record a
Perfetto heap dump, which is saved as a .perfetto-java-heap-dump file and has
different requirements: see
android profiler heapdump capture. You can open both
.hprof and .perfetto-java-heap-dump files in the Android Studio Memory
Profiler.
To capture a heap dump, run
android profiler heapdump capture. Each capture runs in
its own profiling session, which ends when the capture finishes.
Examples
Capture a heap dump of a running app:
android profiler heapdump capture --process=com.example.app --output=dump.hprof
Run garbage collection first, which frees the objects that are no longer reachable:
android profiler heapdump capture --process=com.example.app --gc --output=dump.hprof
Capture a heap dump as a Perfetto trace:
android profiler heapdump capture --process=com.example.app --type=perfetto --output=dump.perfetto-java-heap-dump
Cancel a stuck capture:
android profiler session terminate