Skip to content

Commit e0b2d0f

Browse files
committed
ci: track benchmark results with github-action-benchmark
Each bench job writes metrics to a JSONL file, collects into JSON, and feeds to benchmark-action/github-action-benchmark. On push to main, results are stored on gh-pages with trend charts. On PRs, alerts fire if any metric regresses >30%. Linux and Windows use separate data directories to avoid push races. Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent a3a0e61 commit e0b2d0f

1 file changed

Lines changed: 60 additions & 3 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ jobs:
109109
runs-on: ubuntu-latest
110110
needs: build-image
111111
permissions:
112-
contents: read
112+
contents: write
113113
packages: read
114+
pull-requests: write
114115
timeout-minutes: 30
115116
steps:
116117
- uses: actions/checkout@v4
@@ -186,6 +187,7 @@ jobs:
186187
echo "| Runs | $n |"
187188
echo ""
188189
echo "::notice::hello_world: median=${median}ms avg=${avg}ms min=${min}ms max=${max}ms"
190+
echo "{\"name\":\"hello_world (median)\",\"unit\":\"ms\",\"value\":$median}" >> /tmp/bench-results.jsonl
189191
190192
- name: "Perf: pandas (10 runs)"
191193
if: steps.kvm_check.outputs.available == 'true'
@@ -221,6 +223,7 @@ jobs:
221223
echo "| Runs | $n |"
222224
echo ""
223225
echo "::notice::pandas: median=${median}ms avg=${avg}ms min=${min}ms max=${max}ms"
226+
echo "{\"name\":\"pandas (median)\",\"unit\":\"ms\",\"value\":$median}" >> /tmp/bench-results.jsonl
224227
225228
- name: "Density: concurrent VMs (5 VMs)"
226229
if: steps.kvm_check.outputs.available == 'true'
@@ -253,6 +256,7 @@ jobs:
253256
echo "| Total Private_Dirty | $((total_private / 1024)) MB |"
254257
echo ""
255258
echo "::notice::density: ${count} VMs, per_vm=${per_vm}MB private_dirty"
259+
echo "{\"name\":\"density (per VM)\",\"unit\":\"MB\",\"value\":$per_vm}" >> /tmp/bench-results.jsonl
256260
else
257261
echo "::warning::no VMs were alive long enough to measure"
258262
fi
@@ -270,16 +274,41 @@ jobs:
270274
echo "| Disk usage | ${disk} MiB |"
271275
echo ""
272276
echo "::notice::snapshot: apparent=${apparent}MiB disk=${disk}MiB"
277+
echo "{\"name\":\"snapshot (disk)\",\"unit\":\"MiB\",\"value\":$disk}" >> /tmp/bench-results.jsonl
278+
279+
- name: Collect benchmark results
280+
if: steps.kvm_check.outputs.available == 'true'
281+
run: |
282+
if [ -f /tmp/bench-results.jsonl ]; then
283+
jq -s '.' /tmp/bench-results.jsonl > /tmp/bench-results.json
284+
else
285+
echo "[]" > /tmp/bench-results.json
286+
fi
287+
cat /tmp/bench-results.json
288+
289+
- name: Store benchmark results
290+
if: steps.kvm_check.outputs.available == 'true'
291+
uses: benchmark-action/github-action-benchmark@v1
292+
with:
293+
name: Linux Benchmarks
294+
tool: customSmallerIsBetter
295+
output-file-path: /tmp/bench-results.json
296+
github-token: ${{ secrets.GITHUB_TOKEN }}
297+
benchmark-data-dir-path: dev/bench/linux
298+
auto-push: ${{ github.event_name == 'push' }}
299+
comment-on-alert: true
300+
alert-threshold: '130%'
273301

274302
# ------------------------------------------------------------------
275303
# Performance + density on Windows
276304
# ------------------------------------------------------------------
277305
bench-windows:
278306
runs-on: windows-latest
279-
needs: build-image
307+
needs: [build-image, bench-linux]
280308
permissions:
281-
contents: read
309+
contents: write
282310
packages: read
311+
pull-requests: write
283312
timeout-minutes: 30
284313
steps:
285314
- uses: actions/checkout@v4
@@ -339,6 +368,7 @@ jobs:
339368
Write-Host "| Runs | $n |"
340369
Write-Host ""
341370
Write-Host "::notice::hello_world: median=${median}ms avg=${avg}ms min=${min}ms max=${max}ms"
371+
@{name="hello_world (median)"; unit="ms"; value=$median} | ConvertTo-Json -Compress | Out-File -Append bench-results.jsonl -Encoding ascii
342372
343373
- name: "Perf: pandas (10 runs)"
344374
shell: pwsh
@@ -374,6 +404,7 @@ jobs:
374404
Write-Host "| Runs | $n |"
375405
Write-Host ""
376406
Write-Host "::notice::pandas: median=${median}ms avg=${avg}ms min=${min}ms max=${max}ms"
407+
@{name="pandas (median)"; unit="ms"; value=$median} | ConvertTo-Json -Compress | Out-File -Append bench-results.jsonl -Encoding ascii
377408
378409
- name: "Density: concurrent VMs (5 VMs)"
379410
shell: pwsh
@@ -407,6 +438,7 @@ jobs:
407438
Write-Host "| Total Private | ${totalPrivate} MB |"
408439
Write-Host ""
409440
Write-Host "::notice::density: ${count} VMs, per_vm=${perVM}MB private"
441+
@{name="density (per VM)"; unit="MB"; value=$perVM} | ConvertTo-Json -Compress | Out-File -Append bench-results.jsonl -Encoding ascii
410442
} else {
411443
Write-Host "::warning::no VMs were alive long enough to measure"
412444
}
@@ -444,6 +476,31 @@ jobs:
444476
Write-Host "| Disk usage | ${diskMiB} MiB |"
445477
Write-Host ""
446478
Write-Host "::notice::snapshot: apparent=${apparentMiB}MiB disk=${diskMiB}MiB"
479+
@{name="snapshot (disk)"; unit="MiB"; value=$diskMiB} | ConvertTo-Json -Compress | Out-File -Append bench-results.jsonl -Encoding ascii
480+
481+
- name: Collect benchmark results
482+
shell: pwsh
483+
run: |
484+
if (Test-Path bench-results.jsonl) {
485+
$lines = Get-Content bench-results.jsonl
486+
$json = "[" + ($lines -join ",") + "]"
487+
$json | Out-File bench-results.json -Encoding ascii
488+
} else {
489+
"[]" | Out-File bench-results.json -Encoding ascii
490+
}
491+
Get-Content bench-results.json
492+
493+
- name: Store benchmark results
494+
uses: benchmark-action/github-action-benchmark@v1
495+
with:
496+
name: Windows Benchmarks
497+
tool: customSmallerIsBetter
498+
output-file-path: bench-results.json
499+
github-token: ${{ secrets.GITHUB_TOKEN }}
500+
benchmark-data-dir-path: dev/bench/windows
501+
auto-push: ${{ github.event_name == 'push' }}
502+
comment-on-alert: true
503+
alert-threshold: '130%'
447504

448505
all-checks-passed:
449506
if: always()

0 commit comments

Comments
 (0)