HEAP_PROFILE(1)
NAME
heap_profile - record a native heap profile on Android or local Linux
DESCRIPTION
tools/heap_profile collects native memory profiles. It exposes two
subcommands:
heap_profile android- profile a process on a connected Android device viaadb(the previous behavior, still the default if no subcommand is given).heap_profile host- profile a local Linux process viaLD_PRELOAD. The script auto-downloadstraceboxandlibheapprofd_glibc_preload.soand manages a localtraceddaemon for the duration of the session.
See Recording traces for more details about the data source.
usage: heap_profile [-h] [common options] {android,host} ...
positional arguments:
{android,host}
android Profile a process on a connected Android device via adb
(default).
host Profile a local Linux process via LD_PRELOAD.usage: heap_profile android [-h] [-i INTERVAL] [-d DURATION] [--no-start]
[-p PIDS] [-n NAMES] [-c CONTINUOUS_DUMP]
[--heaps HEAPS] [--all-heaps]
[--no-android-tree-symbolization]
[--disable-selinux] [--no-versions] [--no-running]
[--no-startup] [--shmem-size SHMEM_SIZE]
[--block-client]
[--block-client-timeout BLOCK_CLIENT_TIMEOUT]
[--no-block-client] [--idle-allocations]
[--dump-at-max] [--disable-fork-teardown]
[--simpleperf]
[--traceconv-binary TRACECONV_BINARY]
[--no-annotations] [--print-config] [-o DIRECTORY]usage: heap_profile host [-h] [-i INTERVAL] [-d DURATION] [--no-start]
[-n NAMES] [-c CONTINUOUS_DUMP]
[--heaps HEAPS] [--all-heaps]
[--shmem-size SHMEM_SIZE] [--block-client]
[--block-client-timeout BLOCK_CLIENT_TIMEOUT]
[--no-block-client] [--idle-allocations]
[--dump-at-max] [--disable-fork-teardown]
[--traceconv-binary TRACECONV_BINARY]
[--no-annotations] [--print-config] [-o DIRECTORY]
[--preload-library PRELOAD_LIBRARY]
[--tracebox-binary TRACEBOX_BINARY]
-- COMMAND [ARGS...]COMMON OPTIONS
These flags apply to both android and host subcommands.
-n,--nameNAMESComma-separated list of process names to profile. On
host, if omitted, the basename of the command after--is used.
-i,--intervalSampling interval. Default 4096 (4KiB).
-o,--outputDIRECTORYOutput directory. Must be empty if it already exists.
--all-heapsCollect allocations from all heaps registered by target.
--heapsHEAPSComma-separated list of heaps to collect, e.g.:
libc.malloc,com.android.art. Requires Android 12.
--block-clientWhen buffer is full, block the client to wait for buffer space. Use with caution as this can significantly slow down the client. This is the default.
--block-client-timeoutIf
--block-clientis given, do not block any allocation for longer than this timeout (us).
--no-block-clientWhen buffer is full, stop the profile early.
-c,--continuous-dumpDump interval in ms. 0 to disable continuous dump.
-d,--durationDuration of profile (ms). 0 to run until interrupted. Default: until interrupted by user.
--disable-fork-teardownDo not tear down client in forks. This can be useful for programs that use vfork. Android 11+ only.
--dump-at-maxDump the maximum memory usage rather than at the time of the dump.
--idle-allocationsKeep track of how many bytes were unused since the last dump, per callstack.
--no-annotationsDo not suffix the pprof function names with Android ART mode annotations such as
[jit].
--no-runningDo not target already running processes. Requires Android 11.
--no-startNo-op, kept for backwards compatibility.
--no-startupDo not target processes that start during the profile. Requires Android 11.
--print-configPrint config instead of running. For debugging.
--shmem-sizeSize of buffer between client and heapprofd. Default 8MiB. Needs to be a power of two multiple of 4096, at least 8192.
--traceconv-binaryPath to local traceconv. For debugging.
-h,--helpShow help message and exit.
ANDROID-ONLY OPTIONS
These flags are gated on args.subcommand == 'android' in the script and
have no effect when passed to host.
-p,--pidPIDSComma-separated list of PIDs to profile.
--disable-selinuxDisable SELinux enforcement for duration of profile.
--no-android-tree-symbolizationDo not symbolize using currently lunched target in the Android tree.
--no-versionsDo not get version information about APKs.
--simpleperfGet simpleperf profile of heapprofd. This is only for heapprofd development.
HOST-ONLY OPTIONS
--preload-libraryPRELOAD_LIBRARYPath to
libheapprofd_glibc_preload.so. If omitted the prebuilt is downloaded automatically (linux-amd64/arm/arm64).
--tracebox-binaryTRACEBOX_BINARYPath to a local tracebox binary. For debugging.
--COMMAND [ARGS...]Required positional. The command to launch under
LD_PRELOAD. The binary is run withPERFETTO_HEAPPROFD_BLOCKING_INIT=1so the first allocation blocks until heapprofd attaches.
EXAMPLES
Profile system_server on a connected Android device until interrupted:
tools/heap_profile android -n system_serverProfile a local Linux binary, capturing every allocation from startup:
tools/heap_profile host -- ./my_binary --some-flagPeriodic 5-second snapshots of com.example.app:
tools/heap_profile android -n com.example.app -c 5000Print the trace config a given invocation would emit, without running it:
tools/heap_profile android -n system_server --print-configNOTES
- The bare invocation
heap_profile -n NAME(without a subcommand) is preserved for backwards compatibility and is equivalent toheap_profile android -n NAME. New scripts should use the explicit form. - The
hostsubcommand only runs on Linux; it errors out on other platforms. - For symbolization and Java/Kotlin deobfuscation of the resulting trace, see Symbolization and deobfuscation.