Skip to content

Commit d4039c6

Browse files
Merge pull request #1420 from rust-lang/bench-next-artifacts
Add support for benchmarking published artifacts in `BenchNext`
2 parents 79ba00d + 3192d66 commit d4039c6

File tree

7 files changed

+234
-108
lines changed

7 files changed

+234
-108
lines changed

collector/src/api.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
pub mod next_commit {
1+
pub mod next_artifact {
22
use database::Commit;
33

44
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
5-
pub struct NextCommit {
6-
pub commit: Commit,
7-
pub include: Option<String>,
8-
pub exclude: Option<String>,
9-
pub runs: Option<i32>,
5+
pub enum NextArtifact {
6+
Release(String),
7+
Commit {
8+
commit: Commit,
9+
include: Option<String>,
10+
exclude: Option<String>,
11+
runs: Option<i32>,
12+
},
1013
}
1114

1215
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1316
pub struct Response {
14-
pub commit: Option<NextCommit>,
17+
pub artifact: Option<NextArtifact>,
1518
}
1619
}

collector/src/main.rs

Lines changed: 112 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
use anyhow::{bail, Context};
44
use clap::Parser;
5+
use collector::api::next_artifact::NextArtifact;
56
use collector::category::Category;
6-
use database::{ArtifactId, Commit, CommitType};
7+
use database::{ArtifactId, Commit, CommitType, Pool};
78
use log::debug;
89
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
910
use std::collections::HashMap;
@@ -834,7 +835,7 @@ enum Commands {
834835
self_profile: SelfProfileOption,
835836
},
836837

837-
/// Benchmarks the next commit for perf.rust-lang.org
838+
/// Benchmarks the next commit or release for perf.rust-lang.org
838839
BenchNext {
839840
/// Site URL
840841
site_url: String,
@@ -995,113 +996,64 @@ fn main_result() -> anyhow::Result<i32> {
995996
bench_rustc,
996997
self_profile,
997998
} => {
998-
println!("processing commits");
999+
println!("processing artifacts");
9991000
let client = reqwest::blocking::Client::new();
1000-
let response: collector::api::next_commit::Response = client
1001-
.get(&format!("{}/perf/next_commit", site_url))
1001+
let response: collector::api::next_artifact::Response = client
1002+
.get(&format!("{}/perf/next_artifact", site_url))
10021003
.send()?
10031004
.json()?;
1004-
let next = if let Some(c) = response.commit {
1005+
let next = if let Some(c) = response.artifact {
10051006
c
10061007
} else {
1007-
println!("no commit to benchmark");
1008-
// no missing commits
1008+
println!("no artifact to benchmark");
1009+
// no missing artifacts
10091010
return Ok(0);
10101011
};
10111012

10121013
let pool = database::Pool::open(&db.db);
10131014

1014-
let sysroot = Sysroot::install(next.commit.sha.to_string(), &target_triple)
1015-
.with_context(|| format!("failed to install sysroot for {:?}", next.commit))?;
1016-
1017-
let mut benchmarks = get_benchmarks(
1018-
&benchmark_dir,
1019-
next.include.as_deref(),
1020-
next.exclude.as_deref(),
1021-
)?;
1022-
benchmarks.retain(|b| b.category().is_primary_or_secondary());
1015+
match next {
1016+
NextArtifact::Release(tag) => {
1017+
bench_published_artifact(tag, pool, &mut rt, &target_triple, &benchmark_dir)?;
1018+
}
1019+
NextArtifact::Commit {
1020+
commit,
1021+
include,
1022+
exclude,
1023+
runs,
1024+
} => {
1025+
let sysroot = Sysroot::install(commit.sha.to_string(), &target_triple)
1026+
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
1027+
1028+
let mut benchmarks =
1029+
get_benchmarks(&benchmark_dir, include.as_deref(), exclude.as_deref())?;
1030+
benchmarks.retain(|b| b.category().is_primary_or_secondary());
1031+
1032+
let res = bench(
1033+
&mut rt,
1034+
pool,
1035+
&ArtifactId::Commit(commit),
1036+
&Profile::all(),
1037+
&Scenario::all(),
1038+
bench_rustc.bench_rustc,
1039+
Compiler::from_sysroot(&sysroot),
1040+
&benchmarks,
1041+
runs.map(|v| v as usize),
1042+
self_profile.self_profile,
1043+
);
10231044

1024-
let res = bench(
1025-
&mut rt,
1026-
pool,
1027-
&ArtifactId::Commit(next.commit),
1028-
&Profile::all(),
1029-
&Scenario::all(),
1030-
bench_rustc.bench_rustc,
1031-
Compiler::from_sysroot(&sysroot),
1032-
&benchmarks,
1033-
next.runs.map(|v| v as usize),
1034-
self_profile.self_profile,
1035-
);
1045+
client.post(&format!("{}/perf/onpush", site_url)).send()?;
10361046

1037-
client.post(&format!("{}/perf/onpush", site_url)).send()?;
1047+
res.fail_if_nonzero()?;
1048+
}
1049+
}
10381050

1039-
res.fail_if_nonzero()?;
10401051
Ok(0)
10411052
}
10421053

10431054
Commands::BenchPublished { toolchain, db } => {
1044-
let status = Command::new("rustup")
1045-
.args(&["install", "--profile=minimal", &toolchain])
1046-
.status()
1047-
.context("rustup install")?;
1048-
if !status.success() {
1049-
anyhow::bail!("failed to install toolchain for {}", toolchain);
1050-
}
1051-
10521055
let pool = database::Pool::open(&db.db);
1053-
1054-
let profiles = if collector::version_supports_doc(&toolchain) {
1055-
Profile::all()
1056-
} else {
1057-
Profile::all_non_doc()
1058-
};
1059-
let scenarios = if collector::version_supports_incremental(&toolchain) {
1060-
Scenario::all()
1061-
} else {
1062-
Scenario::all_non_incr()
1063-
};
1064-
1065-
let which = |tool| {
1066-
String::from_utf8(
1067-
Command::new("rustup")
1068-
.arg("which")
1069-
.arg("--toolchain")
1070-
.arg(&toolchain)
1071-
.arg(tool)
1072-
.output()
1073-
.context(format!("rustup which {}", tool))?
1074-
.stdout,
1075-
)
1076-
.context("utf8")
1077-
};
1078-
let rustc = which("rustc")?;
1079-
let rustdoc = which("rustdoc")?;
1080-
let cargo = which("cargo")?;
1081-
1082-
// Exclude benchmarks that don't work with a stable compiler.
1083-
let mut benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
1084-
benchmarks.retain(|b| b.category().is_stable());
1085-
1086-
let res = bench(
1087-
&mut rt,
1088-
pool,
1089-
&ArtifactId::Tag(toolchain),
1090-
&profiles,
1091-
&scenarios,
1092-
/* bench_rustc */ false,
1093-
Compiler {
1094-
rustc: Path::new(rustc.trim()),
1095-
rustdoc: Some(Path::new(rustdoc.trim())),
1096-
cargo: Path::new(cargo.trim()),
1097-
is_nightly: false,
1098-
triple: &target_triple,
1099-
},
1100-
&benchmarks,
1101-
Some(3),
1102-
/* is_self_profile */ false,
1103-
);
1104-
res.fail_if_nonzero()?;
1056+
bench_published_artifact(toolchain, pool, &mut rt, &target_triple, &benchmark_dir)?;
11051057
Ok(0)
11061058
}
11071059

@@ -1248,6 +1200,75 @@ fn main_result() -> anyhow::Result<i32> {
12481200
}
12491201
}
12501202

1203+
fn bench_published_artifact(
1204+
toolchain: String,
1205+
pool: Pool,
1206+
rt: &mut Runtime,
1207+
target_triple: &str,
1208+
benchmark_dir: &Path,
1209+
) -> anyhow::Result<()> {
1210+
let status = Command::new("rustup")
1211+
.args(&["install", "--profile=minimal", &toolchain])
1212+
.status()
1213+
.context("rustup install")?;
1214+
if !status.success() {
1215+
anyhow::bail!("failed to install toolchain for {}", toolchain);
1216+
}
1217+
1218+
let profiles = if collector::version_supports_doc(&toolchain) {
1219+
Profile::all()
1220+
} else {
1221+
Profile::all_non_doc()
1222+
};
1223+
let scenarios = if collector::version_supports_incremental(&toolchain) {
1224+
Scenario::all()
1225+
} else {
1226+
Scenario::all_non_incr()
1227+
};
1228+
1229+
let which = |tool| {
1230+
String::from_utf8(
1231+
Command::new("rustup")
1232+
.arg("which")
1233+
.arg("--toolchain")
1234+
.arg(&toolchain)
1235+
.arg(tool)
1236+
.output()
1237+
.context(format!("rustup which {}", tool))?
1238+
.stdout,
1239+
)
1240+
.context("utf8")
1241+
};
1242+
let rustc = which("rustc")?;
1243+
let rustdoc = which("rustdoc")?;
1244+
let cargo = which("cargo")?;
1245+
1246+
// Exclude benchmarks that don't work with a stable compiler.
1247+
let mut benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
1248+
benchmarks.retain(|b| b.category().is_stable());
1249+
1250+
let res = bench(
1251+
rt,
1252+
pool,
1253+
&ArtifactId::Tag(toolchain),
1254+
&profiles,
1255+
&scenarios,
1256+
/* bench_rustc */ false,
1257+
Compiler {
1258+
rustc: Path::new(rustc.trim()),
1259+
rustdoc: Some(Path::new(rustdoc.trim())),
1260+
cargo: Path::new(cargo.trim()),
1261+
is_nightly: false,
1262+
triple: &target_triple,
1263+
},
1264+
&benchmarks,
1265+
Some(3),
1266+
/* is_self_profile */ false,
1267+
);
1268+
res.fail_if_nonzero()?;
1269+
Ok(())
1270+
}
1271+
12511272
fn add_perf_config(directory: &PathBuf, category: Category) {
12521273
let data = serde_json::json!({
12531274
"category": category.to_string()

database/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ pub struct ArtifactIdNumber(pub u32);
487487
pub struct Index {
488488
/// Id look for a commit
489489
commits: Indexed<Commit>,
490-
/// Id lookup of the errors for a crate
490+
/// Id lookup of published release artifacts
491491
artifacts: Indexed<Box<str>>,
492492
/// Id lookup of the errors for a crate
493493
errors: Indexed<Benchmark>,

0 commit comments

Comments
 (0)