Loading...
Loading...
heaptrack memory profiler skill for Linux. Use when tracking heap allocations, finding memory leaks, measuring peak heap usage, identifying allocation hotspots, or comparing allocation behaviour between runs. Activates on queries about heaptrack, heap profiling, memory allocation analysis, heaptrack_print, allocation hotspots, or memory leak detection with heaptrack.
npx skill4agent add mohitmishra786/low-level-dev-skills heaptrack# Ubuntu/Debian
sudo apt-get install heaptrack heaptrack-gui
# Fedora
sudo dnf install heaptrack
# Arch
sudo pacman -S heaptrack
# Build from source
git clone https://github.com/KDE/heaptrack.git
cmake -S heaptrack -B heaptrack-build -DCMAKE_BUILD_TYPE=Release
cmake --build heaptrack-build -j$(nproc)# Profile a program (generates heaptrack.<prog>.<pid>.zst)
heaptrack ./myapp arg1 arg2
# Attach to running process
heaptrack --pid 12345
# Analyse the trace file
heaptrack_print heaptrack.myapp.12345.zst
# GUI analysis (if heaptrack-gui installed)
heaptrack_gui heaptrack.myapp.12345.zst# Build with debug symbols (essential for readable backtraces)
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build
# Then profile
heaptrack ./build/myappheaptrack_print heaptrack.myapp.*.zst 2>/dev/nulltotal runtime: 2.34s
calls to allocation functions: 145,234 (62,064/s)
temporary allocations: 89,123 (38,087/s)
peak heap memory consumption: 45.23MB
peak RSS (including heap): 78.45MB
total memory leaked: 2.34MB
# Top allocation hotspots (by peak memory)
hotspot 1: 12.34MB peak
myapp::cache::Cache::insert(...)
at src/cache.cpp:142
...
# Top leaked allocations
leak 1: 2.34MB leaked in 1,234 allocations
myapp::connection::Connection::new(...)
at src/connection.cpp:67| Metric | Meaning |
|---|---|
| Memory allocated but never freed |
| Maximum live heap at any point |
| Allocated and freed within one call stack |
| Total malloc/new/realloc calls |
# Show top N hotspots
heaptrack_print -p 10 heaptrack.myapp.*.zst # top 10 hotspots
# Show flamegraph data
heaptrack_print -f heaptrack.myapp.*.zst > alloc.folded
flamegraph.pl alloc.folded > alloc.svg
# Show only leaked allocations
heaptrack_print -l heaptrack.myapp.*.zst
# Show allocations above threshold
heaptrack_print --min-cost 1048576 heaptrack.myapp.*.zst # >1MB only
# Short summary
heaptrack_print -s heaptrack.myapp.*.zst# Record baseline
heaptrack ./myapp --config baseline.conf
mv heaptrack.myapp.*.zst before.zst
# Make changes, record again
heaptrack ./myapp --config new.conf
mv heaptrack.myapp.*.zst after.zst
# Compare (shows diff of hotspots)
heaptrack_print before.zst | head -20 > before.txt
heaptrack_print after.zst | head -20 > after.txt
diff before.txt after.txt| Feature | heaptrack | Valgrind massif |
|---|---|---|
| Overhead | ~2-3x | ~20x |
| Output | Compressed trace + GUI | Text/ms_print |
| Leak detection | Yes | Yes |
| Peak tracking | Yes | Yes |
| Temporal view | Yes (GUI) | Yes (ms_print) |
| Platform | Linux only | Linux, macOS |
| Needs recompile | No | No |
| Call graph | Full stack traces | Full stack traces |
// Rust: use system allocator so heaptrack can intercept
use std::alloc::System;
#[global_allocator]
static A: System = System;# Profile Rust binary
cargo build --release
heaptrack ./target/release/myapp
# Note: debug symbols improve backtraces
cargo build --profile release-with-debug
heaptrack ./target/release-with-debug/myappskills/profilers/valgrindskills/profilers/linux-perfskills/rust/rust-profilingskills/runtimes/sanitizers