|
69 | 69 | │ │ ├── syntax-checks.yaml # Code style and linting |
70 | 70 | │ │ ├── codeql-analysis.yml # Security analysis |
71 | 71 | │ │ ├── performance.yaml # Performance benchmarking |
| 72 | +│ │ ├── profiling.yaml # Pre-solver profiling on PRs |
72 | 73 | │ │ └── release-packages.yaml # Release automation |
73 | 74 | │ └── dependabot.yml # Dependency update automation |
74 | 75 | ├── CODING_STANDARD.md # Coding conventions |
@@ -214,6 +215,8 @@ Unit tests using the Catch framework: |
214 | 215 |
|
215 | 216 | - Build helpers and utilities |
216 | 217 | - `cpplint.py` - Style checker |
| 218 | +- `profile_cbmc.py` - Performance profiling tool (see [Profiling CBMC](#6-profiling-cbmc)) |
| 219 | +- `profiling/` - Profiling package (analysis, benchmarks, runner, utils) |
217 | 220 | - `test.pl` - Regression test runner (in `regression/`) |
218 | 221 | - CI/CD related scripts |
219 | 222 |
|
@@ -764,6 +767,46 @@ cd regression/cbmc |
764 | 767 | make test |
765 | 768 | ``` |
766 | 769 |
|
| 770 | +### 6. Profiling CBMC |
| 771 | + |
| 772 | +The profiling tool (`scripts/profile_cbmc.py`) profiles CBMC's pre-solver |
| 773 | +stages using `perf` and generates flamegraphs. Solver time is excluded by |
| 774 | +default so results reflect only CBMC's own code. |
| 775 | + |
| 776 | +**Prerequisites:** Linux with `perf` installed. |
| 777 | + |
| 778 | +```bash |
| 779 | +# Profile a single file |
| 780 | +scripts/profile_cbmc.py test.c -- --bounds-check --unwind 100 |
| 781 | + |
| 782 | +# Run 3 built-in benchmarks (linked_list, array_ops, structs) |
| 783 | +scripts/profile_cbmc.py --auto |
| 784 | + |
| 785 | +# Extended suite (10 benchmarks) plus CSmith-generated tests |
| 786 | +scripts/profile_cbmc.py --auto-large --auto-csmith |
| 787 | + |
| 788 | +# Multiple runs for statistical significance (reports mean ± stddev) |
| 789 | +scripts/profile_cbmc.py --auto --runs 3 |
| 790 | + |
| 791 | +# Source-level call site resolution (build a debug binary first) |
| 792 | +cmake -S . -Bbuild-debug -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_JBMC=OFF |
| 793 | +cmake --build build-debug --target cbmc -j$(nproc) |
| 794 | +scripts/profile_cbmc.py --auto --debug-binary build-debug/bin/cbmc |
| 795 | + |
| 796 | +# Differential profiling: compare two git refs |
| 797 | +scripts/profile_cbmc.py --diff develop my-optimization-branch |
| 798 | +``` |
| 799 | + |
| 800 | +**Outputs** (in `profile-results/` by default): |
| 801 | +- `flamegraph.svg` per benchmark - Interactive flamegraph |
| 802 | +- `aggregated.svg` - Combined flamegraph across all benchmarks |
| 803 | +- `summary.txt` - Text summary with hotspot analysis and optimization suggestions |
| 804 | +- `results.json` - Machine-readable results |
| 805 | + |
| 806 | +**CI integration:** The `profiling.yaml` workflow runs `--auto --runs 3` on |
| 807 | +every PR, posts the summary to the GitHub step summary, and uploads |
| 808 | +flamegraph SVGs as downloadable artifacts. |
| 809 | + |
767 | 810 | --- |
768 | 811 |
|
769 | 812 | ## Navigation Tips |
@@ -894,6 +937,7 @@ To understand how data flows through CBMC: |
894 | 937 | | Create GOTO binary | `goto-cc -o out.gb input.c` | |
895 | 938 | | View GOTO program | `goto-instrument --show-goto-functions prog.gb` | |
896 | 939 | | Run CBMC | `cbmc program.gb` or `cbmc program.c` | |
| 940 | +| Profile CBMC | `scripts/profile_cbmc.py --auto --runs 3` | |
897 | 941 |
|
898 | 942 | ### Key Files to Know |
899 | 943 |
|
|
0 commit comments