Skip to content

Commit 85c27ad

Browse files
EtiennePerotgvisor-bot
authored andcommitted
PGO: Don't re-run benchmarks if their results will be discarded.
This moves the "should this be skipped?" logic earlier in the pipeline so that it can be used prior to running benchmarks at all, which consume a bunch of machine-hours for no reason if their results will be discarded. BuildKite doesn't seem to have a way for an intermediate step to mark the whole pipeline as skippable, so this refactors the skip logic to its own script that can be used as `skip-or.sh || else_do_this`. Use it in all steps. PiperOrigin-RevId: 773103605
1 parent 95d8752 commit 85c27ad

File tree

3 files changed

+65
-21
lines changed

3 files changed

+65
-21
lines changed

.buildkite/pgo.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ steps:
2323
label: ":arrows_counterclockwise: Refresh PGO profiles (x86_64 Systrap)"
2424
if: build.branch == "master" && build.tag == null
2525
commands:
26-
- make ARCH=x86_64 benchmark-refresh-pgo BENCHMARKS_PLATFORMS=systrap
27-
- ./.buildkite/scripts/pgo/commit-update.sh
26+
- ./.buildkite/scripts/pgo/maybe-skip.sh --tolerate-no-profile-changes make ARCH=x86_64 benchmark-refresh-pgo BENCHMARKS_PLATFORMS=systrap
27+
- ./.buildkite/scripts/pgo/mabe-skip.sh ./.buildkite/scripts/pgo/commit-update.sh
2828
agents:
2929
arch: "amd64"

.buildkite/scripts/pgo/commit-update.sh

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,15 @@
1616

1717
set -euxo pipefail
1818

19-
if [[ "$(git status --porcelain | wc -l)" == 0 ]]; then
20-
echo "No changes to runsc profiles." >&2
21-
exit 0
22-
fi
23-
2419
today="$(date +"%Y-%m-%d")"
2520
repo_url="https://github.com/google/gvisor.git"
2621
pgo_branch_name="pgo/update-${today}"
2722

28-
# If the remote branch already exists, do nothing.
29-
existing_remote="$(git ls-remote --heads "$repo_url" "refs/heads/${pgo_branch_name}" || true)"
30-
if [[ -n "$existing_remote" ]]; then
31-
echo "Remote branch '$pgo_branch_name' already exists, skipping." >&2
32-
exit 0
33-
fi
34-
3523
# GitHub CLI authentication.
3624
gh --version
3725
gh auth login --with-token < "$HOME/.github-token"
3826
gh auth setup-git
3927

40-
# If there is already an open PR for PGO update, do nothing.
41-
if [[ "$(gh pr --repo="$repo_url" list --label pgo-update --state open --json title --jq length)" -gt 0 ]]; then
42-
echo "There is already an open PR for PGO update, skipping." >&2
43-
PAGER=cat gh pr --repo="$repo_url" list --label pgo-update --state open
44-
exit 0
45-
fi
46-
4728
# Create new branch for the PR and stages changes in it.
4829
git stash
4930
git pull --rebase=true "$repo_url" master
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The gVisor Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script executes the argv it gets as arguments, unless it
18+
# determines that the PGO profile update should be skipped.
19+
# Takes the optional argument '--tolerate-no-profile-changes' which can be
20+
# used to tolerate the case where no profile changes are detected.
21+
22+
set -euxo pipefail
23+
24+
today="$(date +"%Y-%m-%d")"
25+
repo_url="https://github.com/google/gvisor.git"
26+
pgo_branch_name="pgo/update-${today}"
27+
28+
tolerate_no_profile_changes=false
29+
for arg; do
30+
if [[ "$arg" == '--tolerate-no-profile-changes' ]]; then
31+
tolerate_no_profile_changes=true
32+
shift
33+
fi
34+
done
35+
36+
# If the remote branch already exists, do nothing.
37+
existing_remote="$(git ls-remote --heads "$repo_url" "refs/heads/${pgo_branch_name}" || true)"
38+
if [[ -n "$existing_remote" ]]; then
39+
echo "Remote branch '$pgo_branch_name' already exists, skipping." >&2
40+
exit 0
41+
fi
42+
43+
# GitHub CLI authentication.
44+
gh --version
45+
gh auth login --with-token < "$HOME/.github-token"
46+
gh auth setup-git
47+
48+
# If there is already an open PR for PGO update, do nothing.
49+
if [[ "$(gh pr --repo="$repo_url" list --label pgo-update --state open --json title --jq length)" -gt 0 ]]; then
50+
echo "There is already an open PR for PGO update, skipping." >&2
51+
PAGER=cat gh pr --repo="$repo_url" list --label pgo-update --state open
52+
exit 0
53+
fi
54+
55+
if ! echo "$@" | grep -qFe '--tolerate-no-profile-changes'; then
56+
if [[ "$(git status --porcelain | wc -l)" == 0 ]]; then
57+
echo "No changes to runsc profiles; skipping." >&2
58+
exit 0
59+
fi
60+
fi
61+
62+
echo "Running:" "$@" >&2
63+
exec "$@"

0 commit comments

Comments
 (0)