| Crates.io | callgrind-compare |
| lib.rs | callgrind-compare |
| version | 0.2.0 |
| created_at | 2025-07-25 11:47:39.282116+00 |
| updated_at | 2025-07-25 19:15:19.088167+00 |
| description | A modern tool to compare callgrind_annotate outputs and track performance changes over time. Enhanced fork with new features including CSV support, mixed input types, and advanced column naming. |
| homepage | https://github.com/levu12/callgrind-compare |
| repository | https://github.com/levu12/callgrind-compare |
| max_upload_size | |
| id | 1767514 |
| size | 73,736 |
A modern tool to compare callgrind_annotate outputs and track performance changes over time.
callgrind-compare allows for precise analysis of instruction count differences between different versions of your programs by comparing the output of valgrind's callgrind_annotate tool.
cargo install callgrind-compare
# 1. Run your program through callgrind
valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes ./your_program
# 2. Generate annotate file
callgrind_annotate --auto=no --threshold=99.99 callgrind.out.12345 > baseline.cg
# 3. Make changes, recompile, and repeat steps 1-2 to create optimized.cg
# 4. Compare the results
callgrind-compare baseline.cg optimized.cg
callgrind_annotate files and CSV files in any combination--csv-names for better organization
This screenshot shows comparison of the same program across 8 different optimization stages. The first column serves as the reference, with subsequent columns showing both absolute instruction counts and percentage changes.
Compare two callgrind annotate outputs:
callgrind-compare baseline.cg optimized.cg
Compare multiple versions:
callgrind-compare v1.cg v2.cg v3.cg v4.cg
Export results for further analysis:
callgrind-compare baseline.cg optimized.cg --csv-export results.csv
# Export with percentages and differences
callgrind-compare baseline.cg v1.cg v2.cg \
--csv-export results.csv \
--csv-all-data \
--csv-names "Baseline" --csv-names "Version1" --csv-names "Version2"
You can mix callgrind files and CSV files:
callgrind-compare baseline.cg intermediate.csv final.cg
# C/C++
gcc -O2 -g -o my_program my_program.c
# Rust
export CARGO_PROFILE_RELEASE_DEBUG=true
cargo build --release
valgrind --tool=callgrind \
--dump-instr=yes \
--collect-jumps=yes \
--separate-threads=yes \
./your_program [arguments]
Flag explanations:
--dump-instr=yes: Collect instruction-level information--collect-jumps=yes: Collect jump/branch information--separate-threads=yes: Handle multi-threaded programs properly# Find the callgrind output
callgrind_file=$(ls -t callgrind.out.* | head -n1)
# Generate annotate file
callgrind_annotate --auto=no --threshold=99.99 "$callgrind_file" > my_run.cg
Threshold recommendations:
--threshold=99.99: Very comprehensive (includes functions down to 0.01%)--threshold=95.0: Balanced view (functions down to 5%)--threshold=90.0: High-level overview-a, --all: Show all symbols, even those without changes--show [OPTIONS]: Control what information to display
ircount: Show instruction countspercentagediff: Show percentage changesircountdiff: Show raw differencesall: Show all three (default)--sort-by <CRITERION>: Control result sorting
symbol: Alphabetical by symbol name (default)first-ir: By first column instruction countlast-ir: By last column instruction countcolumnX: By column X instruction count (0-indexed)- for descending order--relative-to <REFERENCE>: Choose reference for comparisons
first: Use first column as reference (default)last: Use last column as referenceprevious: Each column compares to the previous onecolumnX: Use column X as reference (0-indexed)--csv-export <PATH>: Export results to CSV--csv-percentages: Include percentage columns--csv-differences: Include difference columns--csv-all-data: Include both percentages and differences--csv-names [NAME]: Custom column names (use multiple times for multiple names)-c, --color <MODE>: Control colored output
default: Auto-detect terminal (default)always: Force colorsnever: Disable colors--string-replace [REPLACEMENTS]: Replace strings in symbol names
old/new (e.g., __ZN/simplified)# Compile and profile baseline
gcc -O2 -g -o program program.c
valgrind --tool=callgrind ./program input.txt
callgrind_annotate --threshold=99.99 callgrind.out.* > baseline.cg
# Make optimizations and profile again
# ... make changes ...
gcc -O2 -g -o program program.c
valgrind --tool=callgrind ./program input.txt
callgrind_annotate --threshold=99.99 callgrind.out.* > optimized.cg
# Compare results
callgrind-compare baseline.cg optimized.cg
# Compare across git branches
for branch in v1.0 v1.1 v1.2; do
git checkout $branch
cargo build --release
valgrind --tool=callgrind ./target/release/program
callgrind_annotate --threshold=99.99 callgrind.out.* > ${branch}.cg
done
callgrind-compare v1.0.cg v1.1.cg v1.2.cg \
--csv-export evolution.csv \
--csv-all-data \
--csv-names "v1.0" --csv-names "v1.1" --csv-names "v1.2"
# Show only functions that changed, sorted by impact
callgrind-compare baseline.cg optimized.cg \
--sort-by=-last-ir \
--show percentagediff,ircountdiff
git clone https://github.com/levu12/callgrind-compare
cd callgrind-compare
cargo build --release
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
This project was inspired by and builds upon callgrind_differ by Ethiraric. While callgrind-compare has evolved significantly with new features like CSV support, mixed input types, advanced column naming, and enhanced usability, we acknowledge the original work that provided the foundation for comparing callgrind_annotate outputs.
Key enhancements in callgrind-compare: