Quickstart: Heap profiling

Prerequisites

Capture a heap profile

Linux / macOS

Make sure adb is installed and in your PATH.

adb devices -l

If more than one device or emulator is reported you must select one upfront as follows:

export ANDROID_SERIAL=SER123456

Download the tools/heap_profile (if you don't have a perfetto checkout):

curl -LO https://raw.githubusercontent.com/google/perfetto/main/tools/heap_profile chmod +x heap_profile

Then start the profile:

./heap_profile -n system_server

Windows

Make sure that the downloaded adb.exe is in the PATH.

set PATH=%PATH%;%USERPROFILE%\Downloads\platform-tools adb devices -l

If more than one device or emulator is reported you must select one upfront as follows:

set ANDROID_SERIAL=SER123456

Download the heap_profile script. Then start the profile:

python /path/to/heap_profile -n system_server

View profile

Upload the raw-trace file from the output directory to the Perfetto UI and click on diamond marker in the UI track labeled "Heap profile".

Profile Diamond Native Flamegraph

Next steps

Learn more about memory debugging in the Memory Usage on Android Guide and more about the heapprofd data-source