|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +source .buildkite/scripts/common.sh |
| 6 | + |
| 7 | +add_bin_path |
| 8 | + |
| 9 | +with_go |
| 10 | + |
| 11 | +export TYPE=${1} |
| 12 | +#export BRANCH="${BUILDKITE_BRANCH}" |
| 13 | +export BENCHMARK_ARGS="-count=8 -benchmem" |
| 14 | + |
| 15 | +if [[ ${TYPE} == "pr" ]]; then |
| 16 | + echo "Starting the go benchmark for the pull request" |
| 17 | + BENCH_BASE=next.out make benchmark |
| 18 | + BENCH=$(cat build/next.out) |
| 19 | + buildkite-agent annotate --style 'info' --context "gobench_pr" --append << _EOF_ |
| 20 | +#### Benchmark for pull request |
| 21 | +<details><summary>go bench output</summary> |
| 22 | +
|
| 23 | +\`\`\`bash |
| 24 | +${BENCH} |
| 25 | +\`\`\` |
| 26 | +
|
| 27 | +</details> |
| 28 | +
|
| 29 | +Download <a href="artifact://build/next.out">next.out</a> |
| 30 | +_EOF_ |
| 31 | +fi |
| 32 | + |
| 33 | +if [[ ${TYPE} == "base" ]]; then |
| 34 | + echo "Starting the go benchmark for the pull request" |
| 35 | + git checkout ${BUILDKITE_PULL_REQUEST_BASE_BRANCH} |
| 36 | + BENCH_BASE=base.out make benchmark |
| 37 | + BENCH=$(cat build/base.out) |
| 38 | + buildkite-agent annotate --style 'info' --context "gobench_base" --append << _EOF_ |
| 39 | +#### Benchmark for the ${BUILDKITE_PULL_REQUEST_BASE_BRANCH} |
| 40 | +<details><summary>go bench output for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}</summary> |
| 41 | +
|
| 42 | +\`\`\`bash |
| 43 | +${BENCH} |
| 44 | +\`\`\` |
| 45 | +
|
| 46 | +</details> |
| 47 | +
|
| 48 | +Download <a href="artifact://build/base.out">${BUILDKITE_PULL_REQUEST_BASE_BRANCH}.out</a> |
| 49 | +_EOF_ |
| 50 | +fi |
| 51 | + |
| 52 | +if [[ ${TYPE} == "compare" ]]; then |
| 53 | + echo "Comparing go benchmarks" |
| 54 | + go install go.bobheadxi.dev/gobenchdata@latest |
| 55 | + buildkite-agent artifact download "build/base.out" . |
| 56 | + buildkite-agent artifact download "build/next.out" . |
| 57 | + |
| 58 | + cat build/base.out| gobenchdata --json build/base.json |
| 59 | + cat build/next.out| gobenchdata --json build/next.json |
| 60 | + set +e # suppress error handling of gobenchdata |
| 61 | + gobenchdata checks eval build/base.json build/next.json --json build/full_report.json |
| 62 | + status=$(jq -r '.Status' build/full_report.json) |
| 63 | + if [[ $status == "fail" ]]; then |
| 64 | + cat build/full_report.json| \ |
| 65 | + jq 'del(.Checks.timePerOp.Diffs[]| select(.Status == "pass") )'| \ |
| 66 | + tee build/failed_report.json |
| 67 | + gobenchdata checks report build/failed_report.json | tee build/failed_summary.md |
| 68 | + BENCH_COMPARE=$(cat build/failed_summary.md) |
| 69 | + buildkite-agent annotate --style 'error' --context "benchstat" --append << _EOF_ |
| 70 | +#### Benchmark comparison |
| 71 | +<details><summary>Comparison table of benchmark results of HEAD compared to ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}</summary> |
| 72 | +
|
| 73 | +${BENCH_COMPARE} |
| 74 | +
|
| 75 | +</details> |
| 76 | +
|
| 77 | +Download <a href="artifact://build/failed_summary.md">failed_summary.md</a> , <a href="artifact://build/full_report.json">full_report.json</a> |
| 78 | +_EOF_ |
| 79 | + #exit 1 # fail the build if the status is fail |
| 80 | + else |
| 81 | + BENCH_COMPARE=$(gobenchdata checks report build/full_report.json) |
| 82 | + buildkite-agent annotate --style 'success' --context "benchstat" --append << _EOF_ |
| 83 | +#### Benchmark comparison |
| 84 | +<details><summary>No significant performance issue detect against ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}</summary> |
| 85 | +
|
| 86 | +${BENCH_COMPARE} |
| 87 | +
|
| 88 | +</details> |
| 89 | +
|
| 90 | +Download <a href="artifact://build/full_report.json">full_report.json</a> |
| 91 | +_EOF_ |
| 92 | + fi |
| 93 | +fi |
| 94 | + |
| 95 | + |
0 commit comments