Bytehound - Memory Profiler for Linux Cheatsheet
Bytehound is a memory profiler for Linux that tracks every allocation and deallocation in a program and presents the results in an unusually good web UI. Beyond finding leaks, it shows allocation churn over time, groups allocations by call stack, and lets you filter interactively — “show me allocations larger than 1MB that were never freed, from this module.” It is a Rust-based tool that works with any native program (C, C++, Rust) via LD_PRELOAD.
Installation
| Method | How |
|---|
| Release | Download bytehound + libbytehound.so from GitHub Releases |
| From source | cargo build --release in the repo |
| Requirements | Linux x86-64; program with symbols (-g) |
| Verify | ./bytehound --version |
Profiling a Program
# Preload the profiler and run your program
LD_PRELOAD=./libbytehound.so ./my-program
# This produces memory-profiling_*.dat
| Variable | Purpose |
|---|
LD_PRELOAD=./libbytehound.so | Inject the allocator hooks |
MEMORY_PROFILER_OUTPUT | Output file path |
MEMORY_PROFILER_LOG=warn | Log level |
MEMORY_PROFILER_CULL_TEMPORARY_ALLOCATIONS | Reduce noise from short-lived allocations |
MEMORY_PROFILER_DISABLE_BY_DEFAULT | Start paused, enable programmatically |
Viewing Results
# Start the web UI on the captured data
./bytehound server memory-profiling_*.dat
# → open http://localhost:8080
| View | Shows |
|---|
| Graphs | Memory usage over time (live, leaked, allocated) |
| Allocations | Every allocation with stack, size, lifetime |
| Flame graph | Allocation volume attributed to call stacks |
| Leaked | Allocations never freed |
| Filtering | Interactive query builder |
The Filtering Language
Bytehound’s strength is slicing the data:
| Filter | Finds |
|---|
| Only leaked | Allocations alive at exit |
| Size range | e.g. > 1 MiB |
| Lifetime | Short-lived (churn) vs long-lived |
| Backtrace contains | Allocations from a specific function/module |
| Time range | Allocations during a window |
# Conceptual: leaked allocations over 1MB from the parser module
leaked AND size > 1048576 AND backtrace contains "parser::"
What to Look For
| Symptom | Investigate |
|---|
| RSS grows without bound | ”Leaked” view — allocations never freed |
| High CPU in the allocator | Temporary-allocation churn |
| Memory spike at a moment | Time-range filter around the spike |
| One function dominates | Allocation flame graph |
| Fragmentation | Many small long-lived allocations |
Scripting the Analysis
Bytehound exposes an API and CLI for automation:
| Command | Purpose |
|---|
bytehound server DATA | Interactive UI |
bytehound export-heaptrack DATA | Convert for heaptrack tooling |
| REST API | Query allocations programmatically |
| Scripting | Custom analyses over the dataset |
Reducing Overhead
| Setting | Effect |
|---|
| Cull temporary allocations | Much smaller output, less noise |
| Disable by default + enable in code | Profile only the interesting phase |
| Shorter runs | Data files grow quickly |
Bytehound vs Other Memory Profilers
| Aspect | Bytehound | heaptrack | Valgrind massif | jemalloc prof |
|---|
| Overhead | Low | Low | Very high | Very low |
| UI | Rich web UI | Qt GUI | Text/visualizer | Text + tooling |
| Filtering | Excellent | Good | Limited | Limited |
| Setup | LD_PRELOAD | heaptrack ./prog | valgrind --tool=massif | Allocator config |
| Best for | Interactive exploration | Fast heap profiling | Deep correctness | Production sampling |
Compare with heaptrack for a similar low-overhead approach with a Qt UI; both beat Valgrind for realistic workloads.
Resources