Skip to content

Commit 3563130

Browse files
authored
Merge pull request #1608 from Kobzol/runtime-compare-refactoring
Refactor `site` to make it easier to introduce runtime benchmarks
2 parents 8a3cf28 + 58920cb commit 3563130

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+512
-720
lines changed

collector/benchlib/src/benchmark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ impl BenchmarkGroup {
110110
pub fn passes_filter(name: &str, exclude: Option<&str>, include: Option<&str>) -> bool {
111111
match (exclude, include) {
112112
(Some(exclude), Some(include)) => {
113-
let included = include.split(",").any(|filter| name.starts_with(filter));
114-
let excluded = exclude.split(",").any(|filter| name.starts_with(filter));
113+
let included = include.split(',').any(|filter| name.starts_with(filter));
114+
let excluded = exclude.split(',').any(|filter| name.starts_with(filter));
115115
included && !excluded
116116
}
117-
(None, Some(include)) => include.split(",").any(|filter| name.starts_with(filter)),
118-
(Some(exclude), None) => !exclude.split(",").any(|filter| name.starts_with(filter)),
117+
(None, Some(include)) => include.split(',').any(|filter| name.starts_with(filter)),
118+
(Some(exclude), None) => !exclude.split(',').any(|filter| name.starts_with(filter)),
119119
(None, None) => true,
120120
}
121121
}

collector/src/benchmark/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Benchmark {
8888
}
8989
}
9090

91-
let mut patches: Vec<_> = patches.into_iter().map(|p| Patch::new(p)).collect();
91+
let mut patches: Vec<_> = patches.into_iter().map(Patch::new).collect();
9292
patches.sort_by_key(|p| p.index);
9393

9494
let config_path = path.join("perf-config.json");
@@ -205,7 +205,7 @@ impl Benchmark {
205205
let iterations = iterations.unwrap_or(self.config.runs);
206206

207207
let profiles: Vec<Profile> = profiles
208-
.into_iter()
208+
.iter()
209209
.copied()
210210
.filter(|profile| !self.config.excluded_profiles.contains(profile))
211211
.collect();
@@ -216,7 +216,7 @@ impl Benchmark {
216216
}
217217

218218
let scenarios: Vec<Scenario> = scenarios
219-
.into_iter()
219+
.iter()
220220
.copied()
221221
.filter(|scenario| !self.config.excluded_scenarios.contains(scenario))
222222
.collect();
@@ -346,7 +346,7 @@ impl Benchmark {
346346
processor,
347347
Scenario::IncrPatched,
348348
&scenario_str,
349-
Some(&patch),
349+
Some(patch),
350350
)
351351
.run_rustc(true)?;
352352
}

collector/src/benchmark/patch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Patch {
3030
assert!(path.is_file());
3131
let (index, name) = {
3232
let file_name = path.file_name().unwrap().to_string_lossy();
33-
let mut parts = file_name.split("-");
33+
let mut parts = file_name.split('-');
3434
let index = parts.next().unwrap().parse().unwrap_or_else(|e| {
3535
panic!(
3636
"{:?} should be in the format 000-name.patch, \
@@ -61,7 +61,7 @@ impl Patch {
6161
log::debug!("applying {} to {:?}", self.name, dir);
6262

6363
let mut cmd = Command::new("git");
64-
cmd.current_dir(dir).args(&["apply"]).arg(&*self.path);
64+
cmd.current_dir(dir).args(["apply"]).arg(&*self.path);
6565

6666
command_output(&mut cmd)?;
6767

collector/src/bin/bootstrap-rustc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fn run() -> i32 {
1515
let status = cmd.status().expect("spawned");
1616

1717
if status.success() {
18-
return 0;
18+
0
1919
} else {
20-
return 1;
20+
1
2121
}
2222
}
2323

collector/src/bin/collector.rs

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use collector::benchmark::{
1313
use collector::{runtime, utils, CollectorCtx, CollectorStepBuilder};
1414
use database::{ArtifactId, Commit, CommitType, Connection, Pool};
1515
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
16+
use std::cmp::Ordering;
1617
use std::ffi::OsStr;
1718
use std::fs;
1819
use std::fs::File;
@@ -57,6 +58,7 @@ impl BenchmarkErrors {
5758
}
5859
}
5960

61+
#[allow(clippy::too_many_arguments)]
6062
fn bench(
6163
rt: &mut Runtime,
6264
mut conn: Box<dyn Connection>,
@@ -326,6 +328,7 @@ fn cg_annotate(cgout: &Path, path: &Path) -> anyhow::Result<()> {
326328
Ok(())
327329
}
328330

331+
#[allow(clippy::too_many_arguments)]
329332
fn profile(
330333
compiler: Compiler,
331334
id: &str,
@@ -348,8 +351,7 @@ fn profile(
348351
let benchmark_id = format!("{} ({}/{})", benchmark.name, i + 1, benchmarks.len());
349352
eprintln!("Executing benchmark {benchmark_id}");
350353
let mut processor = ProfileProcessor::new(profiler, out_dir, id);
351-
let result =
352-
benchmark.measure(&mut processor, &profiles, &scenarios, compiler, Some(1));
354+
let result = benchmark.measure(&mut processor, profiles, scenarios, compiler, Some(1));
353355
eprintln!("Finished benchmark {benchmark_id}");
354356

355357
if let Err(ref s) = result {
@@ -400,7 +402,7 @@ impl TypedValueParser for ProfileArgParser {
400402
let profiles: Result<Vec<Profile>, _> = value
401403
.to_str()
402404
.unwrap()
403-
.split(",")
405+
.split(',')
404406
.map(|item| clap::value_parser!(Profile).parse_ref(cmd, arg, OsStr::new(item)))
405407
.collect();
406408

@@ -410,7 +412,7 @@ impl TypedValueParser for ProfileArgParser {
410412

411413
fn possible_values(&self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>> {
412414
let values = Profile::value_variants()
413-
.into_iter()
415+
.iter()
414416
.filter_map(|item| item.to_possible_value())
415417
.chain([PossibleValue::new("All")]);
416418
Some(Box::new(values))
@@ -438,7 +440,7 @@ impl TypedValueParser for ScenarioArgParser {
438440
let scenarios: Result<Vec<Scenario>, _> = value
439441
.to_str()
440442
.unwrap()
441-
.split(",")
443+
.split(',')
442444
.map(|item| clap::value_parser!(Scenario).parse_ref(cmd, arg, OsStr::new(item)))
443445
.collect();
444446

@@ -448,7 +450,7 @@ impl TypedValueParser for ScenarioArgParser {
448450

449451
fn possible_values(&self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>> {
450452
let values = Scenario::value_variants()
451-
.into_iter()
453+
.iter()
452454
.filter_map(|item| item.to_possible_value())
453455
.chain([PossibleValue::new("All")]);
454456
Some(Box::new(values))
@@ -711,7 +713,7 @@ fn main_result() -> anyhow::Result<i32> {
711713
let pool = Pool::open(&db.db);
712714

713715
let suite = runtime::discover_benchmarks(&toolchain, &runtime_benchmark_dir)?;
714-
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
716+
let artifact_id = ArtifactId::Tag(toolchain.id);
715717
let (conn, collector) = rt.block_on(async {
716718
let mut conn = pool.connection().await;
717719
let collector = CollectorStepBuilder::default()
@@ -744,7 +746,7 @@ fn main_result() -> anyhow::Result<i32> {
744746
let pool = database::Pool::open(&db.db);
745747

746748
let toolchain = get_local_toolchain(
747-
&profiles,
749+
profiles,
748750
&local.rustc,
749751
opts.rustdoc.as_deref(),
750752
local.cargo.as_deref(),
@@ -771,8 +773,8 @@ fn main_result() -> anyhow::Result<i32> {
771773
let res = bench(
772774
&mut rt,
773775
conn,
774-
&profiles,
775-
&scenarios,
776+
profiles,
777+
scenarios,
776778
Compiler::from_toolchain(&toolchain, &target_triple),
777779
&benchmarks,
778780
Some(iterations),
@@ -792,7 +794,7 @@ fn main_result() -> anyhow::Result<i32> {
792794
println!("processing artifacts");
793795
let client = reqwest::blocking::Client::new();
794796
let response: collector::api::next_artifact::Response = client
795-
.get(&format!("{}/perf/next_artifact", site_url))
797+
.get(format!("{}/perf/next_artifact", site_url))
796798
.send()?
797799
.json()?;
798800
let next = if let Some(c) = response.artifact {
@@ -815,7 +817,7 @@ fn main_result() -> anyhow::Result<i32> {
815817
&compile_benchmark_dir,
816818
)?;
817819

818-
client.post(&format!("{}/perf/onpush", site_url)).send()?;
820+
client.post(format!("{}/perf/onpush", site_url)).send()?;
819821
}
820822
NextArtifact::Commit {
821823
commit,
@@ -853,7 +855,7 @@ fn main_result() -> anyhow::Result<i32> {
853855
collector,
854856
);
855857

856-
client.post(&format!("{}/perf/onpush", site_url)).send()?;
858+
client.post(format!("{}/perf/onpush", site_url)).send()?;
857859

858860
res.fail_if_nonzero()?;
859861
}
@@ -912,8 +914,8 @@ fn main_result() -> anyhow::Result<i32> {
912914
let mut get_toolchain_and_profile =
913915
|rustc: &str, suffix: &str| -> anyhow::Result<String> {
914916
let toolchain = get_local_toolchain(
915-
&profiles,
916-
&rustc,
917+
profiles,
918+
rustc,
917919
opts.rustdoc.as_deref(),
918920
local.cargo.as_deref(),
919921
local.id.as_deref(),
@@ -926,8 +928,8 @@ fn main_result() -> anyhow::Result<i32> {
926928
profiler,
927929
&out_dir,
928930
&benchmarks,
929-
&profiles,
930-
&scenarios,
931+
profiles,
932+
scenarios,
931933
&mut errors,
932934
);
933935
Ok(toolchain.id)
@@ -950,20 +952,23 @@ fn main_result() -> anyhow::Result<i32> {
950952
&id2,
951953
&out_dir,
952954
&benchmarks,
953-
&profiles,
954-
&scenarios,
955+
profiles,
956+
scenarios,
955957
&mut errors,
956958
);
957-
if diffs.len() > 1 {
958-
eprintln!("Diffs:");
959-
for diff in diffs {
960-
eprintln!("{}", diff.to_string_lossy());
959+
match diffs.len().cmp(&1) {
960+
Ordering::Equal => {
961+
let short = out_dir.join("cgann-diff-latest");
962+
std::fs::copy(&diffs[0], &short).expect("copy to short path");
963+
eprintln!("Original diff at: {}", diffs[0].to_string_lossy());
964+
eprintln!("Short path: {}", short.to_string_lossy());
965+
}
966+
_ => {
967+
eprintln!("Diffs:");
968+
for diff in diffs {
969+
eprintln!("{}", diff.to_string_lossy());
970+
}
961971
}
962-
} else if diffs.len() == 1 {
963-
let short = out_dir.join("cgann-diff-latest");
964-
std::fs::copy(&diffs[0], &short).expect("copy to short path");
965-
eprintln!("Original diff at: {}", diffs[0].to_string_lossy());
966-
eprintln!("Short path: {}", short.to_string_lossy());
967972
}
968973
}
969974
} else {
@@ -983,8 +988,8 @@ fn main_result() -> anyhow::Result<i32> {
983988
.unwrap();
984989
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
985990
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
986-
let commit = get_commit_or_fake_it(&last_sha).expect("success");
987-
let mut sysroot = Sysroot::install(commit.sha.to_string(), &target_triple)?;
991+
let commit = get_commit_or_fake_it(last_sha).expect("success");
992+
let mut sysroot = Sysroot::install(commit.sha, &target_triple)?;
988993
sysroot.preserve(); // don't delete it
989994

990995
// Print the directory containing the toolchain.
@@ -1021,7 +1026,7 @@ async fn init_compile_collector(
10211026
) -> (Box<dyn Connection>, CollectorCtx) {
10221027
let mut conn = pool.connection().await;
10231028
let collector = CollectorStepBuilder::default()
1024-
.record_compile_benchmarks(&benchmarks, bench_rustc)
1029+
.record_compile_benchmarks(benchmarks, bench_rustc)
10251030
.start_collection(conn.as_mut(), artifact_id)
10261031
.await;
10271032
(conn, collector)
@@ -1035,7 +1040,7 @@ fn bench_published_artifact(
10351040
benchmark_dir: &Path,
10361041
) -> anyhow::Result<()> {
10371042
let status = Command::new("rustup")
1038-
.args(&["install", "--profile=minimal", &toolchain])
1043+
.args(["install", "--profile=minimal", &toolchain])
10391044
.status()
10401045
.context("rustup install")?;
10411046
if !status.success() {
@@ -1071,7 +1076,7 @@ fn bench_published_artifact(
10711076
let cargo = which("cargo")?;
10721077

10731078
// Exclude benchmarks that don't work with a stable compiler.
1074-
let mut benchmarks = get_compile_benchmarks(&benchmark_dir, None, None, None)?;
1079+
let mut benchmarks = get_compile_benchmarks(benchmark_dir, None, None, None)?;
10751080
benchmarks.retain(|b| b.category().is_stable());
10761081

10771082
let artifact_id = ArtifactId::Tag(toolchain);
@@ -1091,7 +1096,7 @@ fn bench_published_artifact(
10911096
rustdoc: Some(Path::new(rustdoc.trim())),
10921097
cargo: Path::new(cargo.trim()),
10931098
is_nightly: false,
1094-
triple: &target_triple,
1099+
triple: target_triple,
10951100
},
10961101
&benchmarks,
10971102
Some(3),
@@ -1102,7 +1107,7 @@ fn bench_published_artifact(
11021107
Ok(())
11031108
}
11041109

1105-
fn add_perf_config(directory: &PathBuf, category: Category) {
1110+
fn add_perf_config(directory: &Path, category: Category) {
11061111
let data = serde_json::json!({
11071112
"category": category.to_string()
11081113
});
@@ -1118,10 +1123,12 @@ fn add_perf_config(directory: &PathBuf, category: Category) {
11181123
fn check_target_dir(target_dir: &Path, force: bool) -> anyhow::Result<()> {
11191124
if target_dir.exists() {
11201125
if force {
1121-
std::fs::remove_dir_all(&target_dir).expect(&format!(
1122-
"Cannot remove previous directory at {}",
1123-
target_dir.display()
1124-
));
1126+
std::fs::remove_dir_all(target_dir).unwrap_or_else(|_| {
1127+
panic!(
1128+
"Cannot remove previous directory at {}",
1129+
target_dir.display()
1130+
)
1131+
});
11251132
} else {
11261133
return Err(anyhow::anyhow!(
11271134
"Directory {} already exists",
@@ -1138,9 +1145,9 @@ fn get_downloaded_crate_target(benchmark_dir: &Path, cmd: &DownloadCommand) -> P
11381145
// URLs in general can end with /, which we also want to remove to make sure that the
11391146
// last part of the URL is the repository name.
11401147
DownloadSubcommand::Git { url } => url
1141-
.trim_end_matches("/")
1148+
.trim_end_matches('/')
11421149
.trim_end_matches(".git")
1143-
.split("/")
1150+
.split('/')
11441151
.last()
11451152
.expect("Crate name could not be determined from git URL")
11461153
.to_string(),
@@ -1168,7 +1175,7 @@ fn download_from_git(target: &Path, url: &str) -> anyhow::Result<()> {
11681175
log::error!("Could not delete .git directory: {error:?}");
11691176
}
11701177

1171-
utils::fs::rename(&tmpdir, &target)?;
1178+
utils::fs::rename(&tmpdir, target)?;
11721179
Ok(())
11731180
}
11741181

@@ -1198,7 +1205,7 @@ fn download_from_crates_io(target_dir: &Path, krate: &str, version: &str) -> any
11981205
// under <crate-name>-<version> directory.
11991206
let unpacked_dir = tmpdir.path().join(format!("{krate}-{version}"));
12001207
generate_lockfile(&unpacked_dir);
1201-
utils::fs::rename(&unpacked_dir, &target_dir)?;
1208+
utils::fs::rename(&unpacked_dir, target_dir)?;
12021209

12031210
Ok(())
12041211
}
@@ -1235,7 +1242,7 @@ fn get_commit_or_fake_it(sha: &str) -> anyhow::Result<Commit> {
12351242
log::warn!("utilizing fake commit!");
12361243
Commit {
12371244
sha: sha.into(),
1238-
date: database::Date::ymd_hms(2000, 01, 01, 0, 0, 0),
1245+
date: database::Date::ymd_hms(2000, 1, 1, 0, 0, 0),
12391246
r#type: CommitType::Master,
12401247
}
12411248
}))

0 commit comments

Comments
 (0)