|
| 1 | +# CBMC Profiling Workflow |
| 2 | +# |
| 3 | +# Two modes: |
| 4 | +# |
| 5 | +# 1. On PRs: builds both the base branch and the PR branch, profiles each, |
| 6 | +# and posts a differential comparison plus the PR's hotspot analysis to |
| 7 | +# the GitHub step summary. Flamegraph SVGs are uploaded as artifacts. |
| 8 | +# |
| 9 | +# 2. On pushes to develop: profiles the current develop tip and publishes |
| 10 | +# the flamegraphs to GitHub Pages at /profiling/ so they are always |
| 11 | +# available at https://diffblue.github.io/cbmc/profiling/ |
| 12 | +# |
| 13 | +# The benchmarks exercise different CBMC subsystems: |
| 14 | +# - linked_list: pointer analysis + symbolic execution |
| 15 | +# - array_ops: array flattening + propositional encoding |
| 16 | +# - structs: type checking + goto conversion |
| 17 | +# |
| 18 | +# Solver time is excluded (--dimacs --outfile /dev/null) so that results |
| 19 | +# reflect only CBMC's own code, not the SAT solver. |
| 20 | +# |
| 21 | +# To run locally: |
| 22 | +# scripts/profile_cbmc.py --auto --runs 3 |
| 23 | + |
| 24 | +name: Profiling |
| 25 | +on: |
| 26 | + pull_request: |
| 27 | + branches: [ develop ] |
| 28 | + push: |
| 29 | + branches: [ develop ] |
| 30 | + |
| 31 | +jobs: |
| 32 | + # ── PR job: differential profiling (base vs PR) ────────────────────── |
| 33 | + profile-pr: |
| 34 | + if: github.event_name == 'pull_request' |
| 35 | + runs-on: ubuntu-24.04 |
| 36 | + steps: |
| 37 | + - name: Check out repository |
| 38 | + uses: actions/checkout@v6 |
| 39 | + with: |
| 40 | + submodules: recursive |
| 41 | + fetch-depth: 0 |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + env: |
| 45 | + DEBIAN_FRONTEND: noninteractive |
| 46 | + run: | |
| 47 | + sudo apt-get update |
| 48 | + sudo apt-get install --no-install-recommends -yq \ |
| 49 | + cmake ninja-build gcc g++ flex bison ccache libgoogle-perftools-dev \ |
| 50 | + linux-tools-common linux-tools-generic |
| 51 | + PERF_REAL=$(find /usr/lib/linux-tools-*/perf -maxdepth 0 2>/dev/null | head -1) |
| 52 | + if [ -z "$PERF_REAL" ]; then |
| 53 | + echo "::error::No perf binary found under /usr/lib/linux-tools-*" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + echo "$(dirname "$PERF_REAL")" >> "$GITHUB_PATH" |
| 57 | + "$PERF_REAL" --version |
| 58 | + sudo sysctl kernel.perf_event_paranoid=-1 |
| 59 | +
|
| 60 | + - name: Restore ccache |
| 61 | + uses: actions/cache/restore@v5 |
| 62 | + with: |
| 63 | + path: .ccache |
| 64 | + key: ${{ runner.os }}-24.04-Release-profile-${{ github.sha }} |
| 65 | + restore-keys: | |
| 66 | + ${{ runner.os }}-24.04-Release-profile |
| 67 | + ${{ runner.os }}-24.04-Release |
| 68 | + - run: echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV |
| 69 | + |
| 70 | + # Build the base branch first in a worktree. Building base before |
| 71 | + # the PR branch means the PR build gets good ccache hit rates (most |
| 72 | + # object files are shared). |
| 73 | + - name: Build and profile base branch |
| 74 | + run: | |
| 75 | + BASE_SHA="${{ github.event.pull_request.base.sha }}" |
| 76 | + git worktree add --detach ../base-worktree "$BASE_SHA" |
| 77 | + (cd ../base-worktree && git submodule update --init) |
| 78 | + cmake -S ../base-worktree -B../base-worktree/build -G Ninja \ |
| 79 | + -DWITH_JBMC=OFF -DCMAKE_BUILD_TYPE=Release \ |
| 80 | + -DCMAKE_C_COMPILER=/usr/bin/gcc \ |
| 81 | + -DCMAKE_CXX_COMPILER=/usr/bin/g++ |
| 82 | + touch ../base-worktree/build/src/{ansi-c,cpp}/library-check.stamp |
| 83 | + ninja -C ../base-worktree/build cbmc -j$(nproc) |
| 84 | + python3 scripts/profile_cbmc.py --auto --runs 3 --timeout 120 \ |
| 85 | + --build-dir ../base-worktree/build --output-dir base-results |
| 86 | +
|
| 87 | + - name: Build PR branch (Release) |
| 88 | + run: | |
| 89 | + cmake -S . -Bbuild -G Ninja -DWITH_JBMC=OFF \ |
| 90 | + -DCMAKE_BUILD_TYPE=Release \ |
| 91 | + -DCMAKE_C_COMPILER=/usr/bin/gcc \ |
| 92 | + -DCMAKE_CXX_COMPILER=/usr/bin/g++ |
| 93 | + touch build/src/{ansi-c,cpp}/library-check.stamp |
| 94 | + ninja -C build cbmc -j$(nproc) |
| 95 | +
|
| 96 | + - name: Profile PR branch (3 runs per benchmark) |
| 97 | + run: | |
| 98 | + python3 scripts/profile_cbmc.py --auto --runs 3 --timeout 120 \ |
| 99 | + --output-dir profile-results |
| 100 | +
|
| 101 | + - name: Generate differential summary |
| 102 | + if: always() |
| 103 | + run: | |
| 104 | + if [ -f base-results/results.json ] && [ -f profile-results/results.json ]; then |
| 105 | + python3 scripts/profile_cbmc.py \ |
| 106 | + --compare base-results profile-results \ |
| 107 | + --compare-labels \ |
| 108 | + "${{ github.event.pull_request.base.ref }}" \ |
| 109 | + "${{ github.event.pull_request.head.ref }}" \ |
| 110 | + --output-dir diff-results |
| 111 | + fi |
| 112 | +
|
| 113 | + - name: Post summary |
| 114 | + if: always() |
| 115 | + run: | |
| 116 | + if [ -f diff-results/diff_summary.txt ]; then |
| 117 | + echo '### Differential Profile (base → PR)' >> "$GITHUB_STEP_SUMMARY" |
| 118 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 119 | + cat diff-results/diff_summary.txt >> "$GITHUB_STEP_SUMMARY" |
| 120 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 121 | + echo '' >> "$GITHUB_STEP_SUMMARY" |
| 122 | + fi |
| 123 | + if [ -f profile-results/summary.txt ]; then |
| 124 | + echo '### PR Branch Profile' >> "$GITHUB_STEP_SUMMARY" |
| 125 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 126 | + cat profile-results/summary.txt >> "$GITHUB_STEP_SUMMARY" |
| 127 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 128 | + fi |
| 129 | + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 130 | + echo '' >> "$GITHUB_STEP_SUMMARY" |
| 131 | + echo '---' >> "$GITHUB_STEP_SUMMARY" |
| 132 | + echo "📊 **[Download flamegraph SVGs](${RUN_URL}#artifacts)** — open in a browser for interactive exploration." >> "$GITHUB_STEP_SUMMARY" |
| 133 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 134 | + echo "🔥 **[Latest develop flamegraphs](https://diffblue.github.io/cbmc/profiling/)**" >> "$GITHUB_STEP_SUMMARY" |
| 135 | +
|
| 136 | + - name: Clean up worktree |
| 137 | + if: always() |
| 138 | + run: git worktree remove --force ../base-worktree 2>/dev/null || true |
| 139 | + |
| 140 | + - name: Upload artifacts |
| 141 | + if: always() |
| 142 | + uses: actions/upload-artifact@v7 |
| 143 | + with: |
| 144 | + name: profile-results |
| 145 | + path: | |
| 146 | + profile-results/**/flamegraph.svg |
| 147 | + profile-results/aggregated.svg |
| 148 | + profile-results/summary.txt |
| 149 | + profile-results/results.json |
| 150 | + base-results/results.json |
| 151 | + diff-results/diff_summary.txt |
| 152 | + retention-days: 14 |
| 153 | + |
| 154 | + - name: Save ccache |
| 155 | + if: always() |
| 156 | + uses: actions/cache/save@v5 |
| 157 | + with: |
| 158 | + path: .ccache |
| 159 | + key: ${{ runner.os }}-24.04-Release-profile-${{ github.sha }} |
| 160 | + |
| 161 | + # ── Develop job: profile and publish flamegraphs to GitHub Pages ───── |
| 162 | + profile-develop: |
| 163 | + if: github.event_name == 'push' |
| 164 | + runs-on: ubuntu-24.04 |
| 165 | + steps: |
| 166 | + - name: Check out repository |
| 167 | + uses: actions/checkout@v6 |
| 168 | + with: |
| 169 | + submodules: recursive |
| 170 | + |
| 171 | + - name: Install dependencies |
| 172 | + env: |
| 173 | + DEBIAN_FRONTEND: noninteractive |
| 174 | + run: | |
| 175 | + sudo apt-get update |
| 176 | + sudo apt-get install --no-install-recommends -yq \ |
| 177 | + cmake ninja-build gcc g++ flex bison ccache libgoogle-perftools-dev \ |
| 178 | + linux-tools-common linux-tools-generic |
| 179 | + PERF_REAL=$(find /usr/lib/linux-tools-*/perf -maxdepth 0 2>/dev/null | head -1) |
| 180 | + if [ -z "$PERF_REAL" ]; then |
| 181 | + echo "::error::No perf binary found under /usr/lib/linux-tools-*" |
| 182 | + exit 1 |
| 183 | + fi |
| 184 | + echo "$(dirname "$PERF_REAL")" >> "$GITHUB_PATH" |
| 185 | + "$PERF_REAL" --version |
| 186 | + sudo sysctl kernel.perf_event_paranoid=-1 |
| 187 | +
|
| 188 | + - name: Restore ccache |
| 189 | + uses: actions/cache/restore@v5 |
| 190 | + with: |
| 191 | + path: .ccache |
| 192 | + key: ${{ runner.os }}-24.04-Release-profile-${{ github.sha }} |
| 193 | + restore-keys: | |
| 194 | + ${{ runner.os }}-24.04-Release-profile |
| 195 | + ${{ runner.os }}-24.04-Release |
| 196 | + - run: echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV |
| 197 | + |
| 198 | + - name: Build CBMC (Release) |
| 199 | + run: | |
| 200 | + cmake -S . -Bbuild -G Ninja -DWITH_JBMC=OFF \ |
| 201 | + -DCMAKE_BUILD_TYPE=Release \ |
| 202 | + -DCMAKE_C_COMPILER=/usr/bin/gcc \ |
| 203 | + -DCMAKE_CXX_COMPILER=/usr/bin/g++ |
| 204 | + touch build/src/{ansi-c,cpp}/library-check.stamp |
| 205 | + ninja -C build cbmc -j$(nproc) |
| 206 | +
|
| 207 | + - name: Profile develop (3 runs per benchmark) |
| 208 | + run: | |
| 209 | + python3 scripts/profile_cbmc.py --auto --runs 3 --timeout 120 \ |
| 210 | + --output-dir profile-results |
| 211 | +
|
| 212 | + - name: Post summary |
| 213 | + if: always() |
| 214 | + run: | |
| 215 | + if [ -f profile-results/summary.txt ]; then |
| 216 | + echo '### develop Profile' >> "$GITHUB_STEP_SUMMARY" |
| 217 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 218 | + cat profile-results/summary.txt >> "$GITHUB_STEP_SUMMARY" |
| 219 | + echo '```' >> "$GITHUB_STEP_SUMMARY" |
| 220 | + echo '' >> "$GITHUB_STEP_SUMMARY" |
| 221 | + echo '---' >> "$GITHUB_STEP_SUMMARY" |
| 222 | + echo '🔥 **[Interactive flamegraphs on GitHub Pages](https://diffblue.github.io/cbmc/profiling/)**' >> "$GITHUB_STEP_SUMMARY" |
| 223 | + fi |
| 224 | +
|
| 225 | + - name: Prepare pages content |
| 226 | + if: always() |
| 227 | + run: | |
| 228 | + mkdir -p pages-out |
| 229 | + # Copy all flamegraph SVGs |
| 230 | + find profile-results -name 'flamegraph.svg' | while read f; do |
| 231 | + bench=$(basename "$(dirname "$f")") |
| 232 | + cp "$f" "pages-out/${bench}.svg" |
| 233 | + done |
| 234 | + [ -f profile-results/aggregated.svg ] && cp profile-results/aggregated.svg pages-out/ |
| 235 | + [ -f profile-results/summary.txt ] && cp profile-results/summary.txt pages-out/ |
| 236 | + [ -f profile-results/results.json ] && cp profile-results/results.json pages-out/ |
| 237 | + # Generate a simple index page |
| 238 | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-8) |
| 239 | + cat > pages-out/index.html <<'HEADER' |
| 240 | + <!DOCTYPE html> |
| 241 | + <html><head><meta charset="utf-8"> |
| 242 | + <title>CBMC Profiling — develop</title> |
| 243 | + <style> |
| 244 | + body { font-family: system-ui, sans-serif; max-width: 900px; margin: 2em auto; padding: 0 1em; } |
| 245 | + h1 { border-bottom: 2px solid #333; padding-bottom: 0.3em; } |
| 246 | + a { color: #0366d6; } |
| 247 | + .meta { color: #666; font-size: 0.9em; } |
| 248 | + ul { line-height: 1.8; } |
| 249 | + pre { background: #f6f8fa; padding: 1em; overflow-x: auto; font-size: 0.85em; } |
| 250 | + </style> |
| 251 | + </head><body> |
| 252 | + HEADER |
| 253 | + echo "<h1>CBMC Profiling — develop</h1>" >> pages-out/index.html |
| 254 | + echo "<p class='meta'>Commit: <code>${SHORT_SHA}</code> — $(date -u '+%Y-%m-%d %H:%M UTC')</p>" >> pages-out/index.html |
| 255 | + echo "<h2>Flamegraphs</h2><p>Click to open interactive SVG (searchable, zoomable):</p><ul>" >> pages-out/index.html |
| 256 | + for svg in pages-out/*.svg; do |
| 257 | + name=$(basename "$svg") |
| 258 | + echo "<li><a href=\"${name}\">${name%.svg}</a></li>" >> pages-out/index.html |
| 259 | + done |
| 260 | + echo "</ul>" >> pages-out/index.html |
| 261 | + if [ -f pages-out/summary.txt ]; then |
| 262 | + echo "<h2>Summary</h2><pre>" >> pages-out/index.html |
| 263 | + cat pages-out/summary.txt >> pages-out/index.html |
| 264 | + echo "</pre>" >> pages-out/index.html |
| 265 | + fi |
| 266 | + echo "<p><a href=\"https://github.com/${{ github.repository }}\">← Back to repository</a></p>" >> pages-out/index.html |
| 267 | + echo "</body></html>" >> pages-out/index.html |
| 268 | +
|
| 269 | + - name: Publish to GitHub Pages |
| 270 | + if: always() |
| 271 | + uses: JamesIves/github-pages-deploy-action@v4 |
| 272 | + with: |
| 273 | + branch: gh-pages |
| 274 | + folder: pages-out |
| 275 | + target-folder: profiling |
| 276 | + clean: true |
| 277 | + |
| 278 | + - name: Save ccache |
| 279 | + if: always() |
| 280 | + uses: actions/cache/save@v5 |
| 281 | + with: |
| 282 | + path: .ccache |
| 283 | + key: ${{ runner.os }}-24.04-Release-profile-${{ github.sha }} |
0 commit comments