Skip to content

Commit 789fe2e

Browse files
authored
chore: fix bencher (#382)
# Summary - Fix issues in bencher CI now that I can do that off of a PR
1 parent 06c1537 commit 789fe2e

File tree

3 files changed

+87
-32
lines changed

3 files changed

+87
-32
lines changed

.github/workflows/bevy_mod_scripting.yml

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
echo "Convert to single line JSON"
7373
jq -c . matrix.json > matrix-one-line.json
7474
echo "matrix=$(cat matrix-one-line.json)" >> $GITHUB_OUTPUT
75+
env:
76+
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }}
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7578

7679
check:
7780
needs: [check-needs-run, generate-job-matrix]

.github/workflows/snapshot_benchmark_main.yml

-32
This file was deleted.

crates/xtask/src/main.rs

+84
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ impl App {
349349
Xtasks::Install { binary } => {
350350
cmd.arg("install").arg(binary.as_ref());
351351
}
352+
Xtasks::Bench {} => {
353+
cmd.arg("bench");
354+
}
352355
}
353356

354357
cmd
@@ -634,6 +637,8 @@ enum Xtasks {
634637
/// ]
635638
///
636639
CiMatrix,
640+
/// Runs bencher in dry mode by default if not on the main branch
641+
Bench {},
637642
}
638643

639644
#[derive(Serialize, Clone)]
@@ -709,6 +714,7 @@ impl Xtasks {
709714
bevy_features,
710715
} => Self::codegen(app_settings, output_dir, bevy_features),
711716
Xtasks::Install { binary } => Self::install(app_settings, binary),
717+
Xtasks::Bench {} => Self::bench(app_settings),
712718
}?;
713719

714720
Ok("".into())
@@ -1208,6 +1214,77 @@ impl Xtasks {
12081214
Ok(())
12091215
}
12101216

1217+
fn bench(app_settings: GlobalArgs) -> Result<()> {
1218+
// first of all figure out which branch we're on
1219+
// run // git rev-parse --abbrev-ref HEAD
1220+
1221+
let command = Command::new("git")
1222+
.args(["rev-parse", "--abbrev-ref", "HEAD"])
1223+
.current_dir(Self::workspace_dir(&app_settings).unwrap())
1224+
.output()
1225+
.with_context(|| "Trying to figure out which branch we're on in benchmarking")?;
1226+
let branch = String::from_utf8(command.stdout)?;
1227+
1228+
let is_main = branch.trim() == "main";
1229+
1230+
// figure out if we're running in github actions
1231+
let github_token = std::env::var("GITHUB_TOKEN").ok();
1232+
1233+
// get testbed
1234+
// we want this to be a combination of
1235+
// is_github_ci?
1236+
// OS
1237+
// machine id
1238+
1239+
let os = std::env::consts::OS;
1240+
1241+
let testbed = format!(
1242+
"{os}{}",
1243+
github_token.is_some().then_some("-gha").unwrap_or_default()
1244+
);
1245+
1246+
// also figure out if we're on a fork
1247+
1248+
let token = std::env::var("BENCHER_API_TOKEN").ok();
1249+
1250+
let mut bencher_cmd = Command::new("bencher");
1251+
bencher_cmd
1252+
.stdout(std::process::Stdio::inherit())
1253+
.stderr(std::process::Stdio::inherit())
1254+
.current_dir(Self::workspace_dir(&app_settings).unwrap())
1255+
.arg("run")
1256+
.args(["--project", "bms"])
1257+
.args(["--branch", &format!("\"{branch}\"")])
1258+
.args(["--token", &token.unwrap_or_default()])
1259+
.args(["--testbed", &testbed])
1260+
.args(["--build-time"])
1261+
.args(["--threshold-measure", "latency"])
1262+
.args(["--threshold-test", "t_test"])
1263+
.args(["--threshold-max-sample-size", "64"])
1264+
.args(["--threshold-upper-boundary", "0.99"])
1265+
.args(["--thresholds-reset"])
1266+
.args(["--err"]);
1267+
1268+
if let Some(token) = github_token {
1269+
bencher_cmd.args(["--github-actions", &token]);
1270+
}
1271+
1272+
if !is_main {
1273+
bencher_cmd.args(["--dry-run"]);
1274+
}
1275+
1276+
bencher_cmd
1277+
.args(["--adapter", "rust_criterion"])
1278+
.arg("cargo bench --features=lua54");
1279+
1280+
let out = bencher_cmd.output()?;
1281+
if !out.status.success() {
1282+
bail!("Failed to run bencher: {:?}", out);
1283+
}
1284+
1285+
Ok(())
1286+
}
1287+
12111288
fn set_cargo_coverage_settings() {
12121289
// This makes local dev hell
12131290
// std::env::set_var("CARGO_INCREMENTAL", "0");
@@ -1369,6 +1446,13 @@ impl Xtasks {
13691446
},
13701447
});
13711448

1449+
// also run a benchmark
1450+
// on non-main branches this will just dry run
1451+
output.push(App {
1452+
global_args: default_args.clone(),
1453+
subcmd: Xtasks::Bench {},
1454+
});
1455+
13721456
// and finally run tests with coverage
13731457
output.push(App {
13741458
global_args: default_args

0 commit comments

Comments
 (0)