Quickstart: Heap profiling

Prerequisites

  • A host running macOS or Linux.
  • A device running Android 10+.
  • A Profileable or Debuggable app. If you are running on a “user” build of Android (as opposed to “userdebug” or “eng”), your app needs to be marked as profileable or debuggable in its manifest. See the heapprofd documentation for more details.

Capture a heap profile

Download the tools/heap_profile (if you don't have a perfetto checkout) and run it as follows:

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

./heap_profile -n system_server

Profiling active. Press Ctrl+C to terminate.
You may disconnect your device.

Wrote profiles to /tmp/profile-1283e247-2170-4f92-8181-683763e17445 (symlink /tmp/heap_profile-latest)
These can be viewed using pprof. Googlers: head to pprof/ and upload them.

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