Skip to content
Latchkey

heaptrack: Low-Overhead Heap Profiling

heaptrack traces every heap allocation in a native program with its call stack, at much lower overhead than valgrind Massif.

heaptrack answers "what allocated this memory and how often" for C and C++ programs. It is faster than Massif and records allocation counts, not just peak size.

What it does

heaptrack injects an allocation tracker into a program (via LD_PRELOAD) and records every malloc/free with a stack trace and timestamp into a .gz data file. heaptrack_print produces a text report, and heaptrack_gui explores it visually.

Common usage

Terminal
heaptrack ./my-program
# analyze the recorded data as text
heaptrack_print heaptrack.my-program.12345.gz
# attach to a running process
heaptrack --pid 12345

Options

Command / FlagWhat it does
heaptrack <cmd>Run and record allocations of a command
heaptrack --pid <pid>Attach to a running process
heaptrack_print <file.gz>Print a text report of the recording
heaptrack_gui <file.gz>Open the recording in the GUI (needs a display)

In CI

Record in the pipeline and archive the .gz file, then analyze with heaptrack_print in-log or heaptrack_gui on a workstation. Its overhead is lower than Massif, so it is more practical for realistic workloads, though still slower than native.

Common errors in CI

"heaptrack: command not found" means the package is not installed (it is not in most base images). A recording that stops early usually means the process was OOM-killed or hit the step timeout. heaptrack_gui fails with "Could not connect to display" on headless runners; use heaptrack_print there. Missing symbols in the report mean the binary was stripped; keep debug info.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →