Skip to content

Commit 75137f2

Browse files
authored
Merge pull request #2216 from Kobzol/benchmark-job-queue-preparation
Preparation for collector job queue integration
2 parents 4700e79 + b83dbcb commit 75137f2

40 files changed

+497
-455
lines changed

collector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = "1.85.0"
99
[dependencies]
1010
anyhow = { workspace = true }
1111
chrono = { workspace = true, features = ["serde"] }
12-
clap = { workspace = true, features = ["derive"] }
12+
clap = { workspace = true, features = ["derive", "env"] }
1313
env_logger = { workspace = true }
1414
hashbrown = { workspace = true }
1515
log = { workspace = true }

collector/benchlib/src/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'a> BenchmarkGroup<'a> {
5858
profile_fn: Box::new(move || profile_function(constructor2.as_ref())),
5959
};
6060
if self.benchmarks.insert(name, benchmark_fns).is_some() {
61-
panic!("Benchmark '{}' was registered twice", name);
61+
panic!("Benchmark '{name}' was registered twice");
6262
}
6363
}
6464

collector/src/bin/collector.rs

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use database::{ArtifactId, ArtifactIdNumber, Commit, CommitType, Connection, Poo
6262

6363
fn n_normal_benchmarks_remaining(n: usize) -> String {
6464
let suffix = if n == 1 { "" } else { "s" };
65-
format!("{} normal benchmark{} remaining", n, suffix)
65+
format!("{n} normal benchmark{suffix} remaining")
6666
}
6767

6868
struct BenchmarkErrors(usize);
@@ -160,7 +160,7 @@ fn generate_diffs(
160160
vec![format!("{:?}", scenario)]
161161
}
162162
Scenario::IncrPatched => (0..benchmark.patches.len())
163-
.map(|i| format!("{:?}{}", scenario, i))
163+
.map(|i| format!("{scenario:?}{i}"))
164164
.collect::<Vec<_>>(),
165165
}
166166
}) {
@@ -175,15 +175,15 @@ fn generate_diffs(
175175
profiler.postfix()
176176
)
177177
};
178-
let id_diff = format!("{}-{}", id1, id2);
178+
let id_diff = format!("{id1}-{id2}");
179179
let prefix = profiler.prefix();
180180
let left = out_dir.join(filename(prefix, id1));
181181
let right = out_dir.join(filename(prefix, id2));
182182
let output = out_dir.join(filename(&format!("{prefix}-diff"), &id_diff));
183183

184184
if let Err(e) = profiler.diff(&left, &right, &output) {
185185
errors.incr();
186-
eprintln!("collector error: {:?}", e);
186+
eprintln!("collector error: {e:?}");
187187
continue;
188188
}
189189

@@ -249,7 +249,7 @@ fn main() {
249249
match main_result() {
250250
Ok(code) => process::exit(code),
251251
Err(err) => {
252-
eprintln!("collector error: {:?}", err);
252+
eprintln!("collector error: {err:?}");
253253
process::exit(1);
254254
}
255255
}
@@ -411,7 +411,7 @@ struct DbOption {
411411
/// Database output file
412412
// This would be better as a `PathBuf`, but it's used in various ways that
413413
// make that tricky without adjusting several points in the code.
414-
#[arg(long, default_value = "results.db")]
414+
#[arg(long, default_value = "results.db", env = "DATABASE_URL")]
415415
db: String,
416416
}
417417

@@ -668,20 +668,26 @@ enum Commands {
668668
modified: Option<String>,
669669
},
670670

671-
/// Registers a collector in the database
671+
/// Registers a new collector in the database.
672+
/// Use `--is_active` to immediately mark the collector as active.
672673
AddCollector {
673674
#[command(flatten)]
674675
db: DbOption,
675676

677+
/// Name of the collector.
676678
#[arg(long)]
677679
collector_name: String,
678680

681+
/// Target tuple which will the collector be benchmarking.
679682
#[arg(long)]
680683
target: String,
681684

685+
/// Should the collector be marked as active immediately?
686+
/// Only active collectors will receive jobs.
682687
#[arg(long)]
683688
is_active: bool,
684689

690+
/// The benchmark set index that the collector will be benchmarking.
685691
#[arg(long)]
686692
benchmark_set: u32,
687693
},
@@ -766,14 +772,15 @@ fn main_result() -> anyhow::Result<i32> {
766772
runtime: &runtime_benchmark_dir,
767773
};
768774

769-
// XXX: This doesn't necessarily work for all archs
770-
let target_triple = format!("{}-unknown-linux-gnu", std::env::consts::ARCH);
775+
// This clearly won't work for all architectures, but should be good enough for x64 Linux
776+
// and ARM 64-bit Linux.
777+
let host_target_tuple = format!("{}-unknown-linux-gnu", std::env::consts::ARCH);
771778

772779
match args.command {
773780
Commands::BinaryStats { mode, symbols } => {
774781
match mode {
775782
BinaryStatsMode::Compile(args) => {
776-
binary_stats_compile(args, symbols, &target_triple)?;
783+
binary_stats_compile(args, symbols, &host_target_tuple)?;
777784
}
778785
BinaryStatsMode::Local(args) => {
779786
binary_stats_local(args, symbols)?;
@@ -792,7 +799,7 @@ fn main_result() -> anyhow::Result<i32> {
792799
purge,
793800
} => {
794801
log_db(&db);
795-
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &target_triple)?;
802+
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &host_target_tuple)?;
796803
let pool = Pool::open(&db.db);
797804

798805
let isolation_mode = if no_isolate {
@@ -846,7 +853,7 @@ fn main_result() -> anyhow::Result<i32> {
846853
rustc,
847854
ToolchainConfig::default(),
848855
id,
849-
target_triple.clone(),
856+
host_target_tuple.clone(),
850857
)?;
851858
let suite = prepare_runtime_benchmark_suite(
852859
&toolchain,
@@ -903,7 +910,7 @@ fn main_result() -> anyhow::Result<i32> {
903910
rustc,
904911
ToolchainConfig::default(),
905912
id,
906-
target_triple.clone(),
913+
host_target_tuple.clone(),
907914
)?;
908915
Ok::<_, anyhow::Error>(toolchain)
909916
};
@@ -946,7 +953,7 @@ fn main_result() -> anyhow::Result<i32> {
946953
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
947954
.id(local.id.as_deref()),
948955
"",
949-
target_triple,
956+
host_target_tuple,
950957
)?;
951958

952959
let mut benchmarks = get_compile_benchmarks(&compile_benchmark_dir, (&local).into())?;
@@ -991,7 +998,7 @@ fn main_result() -> anyhow::Result<i32> {
991998
println!("processing artifacts");
992999
let client = reqwest::blocking::Client::new();
9931000
let response: collector::api::next_artifact::Response = client
994-
.get(format!("{}/perf/next_artifact", site_url))
1001+
.get(format!("{site_url}/perf/next_artifact"))
9951002
.send()?
9961003
.json()?;
9971004
let next = if let Some(c) = response.artifact {
@@ -1015,7 +1022,7 @@ fn main_result() -> anyhow::Result<i32> {
10151022
match next {
10161023
NextArtifact::Release(tag) => {
10171024
let toolchain =
1018-
create_toolchain_from_published_version(&tag, &target_triple)?;
1025+
create_toolchain_from_published_version(&tag, &host_target_tuple)?;
10191026
let conn = rt.block_on(pool.connection());
10201027
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))
10211028
}
@@ -1055,10 +1062,9 @@ fn main_result() -> anyhow::Result<i32> {
10551062
}
10561063
};
10571064
let sha = commit.sha.to_string();
1058-
let sysroot = Sysroot::install(sha.clone(), &target_triple, &backends)
1059-
.with_context(|| {
1060-
format!("failed to install sysroot for {:?}", commit)
1061-
})?;
1065+
let sysroot = rt
1066+
.block_on(Sysroot::install(sha.clone(), &host_target_tuple, &backends))
1067+
.with_context(|| format!("failed to install sysroot for {commit:?}"))?;
10621068

10631069
let mut benchmarks = get_compile_benchmarks(
10641070
&compile_benchmark_dir,
@@ -1118,7 +1124,7 @@ fn main_result() -> anyhow::Result<i32> {
11181124
}
11191125
});
11201126
// We need to send a message to this endpoint even if the collector panics
1121-
client.post(format!("{}/perf/onpush", site_url)).send()?;
1127+
client.post(format!("{site_url}/perf/onpush")).send()?;
11221128

11231129
match res {
11241130
Ok(res) => res?,
@@ -1134,7 +1140,8 @@ fn main_result() -> anyhow::Result<i32> {
11341140
let pool = database::Pool::open(&db.db);
11351141
let rt = build_async_runtime();
11361142
let conn = rt.block_on(pool.connection());
1137-
let toolchain = create_toolchain_from_published_version(&toolchain, &target_triple)?;
1143+
let toolchain =
1144+
create_toolchain_from_published_version(&toolchain, &host_target_tuple)?;
11381145
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))?;
11391146
Ok(0)
11401147
}
@@ -1182,7 +1189,7 @@ fn main_result() -> anyhow::Result<i32> {
11821189
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
11831190
.id(local.id.as_deref()),
11841191
suffix,
1185-
target_triple.clone(),
1192+
host_target_tuple.clone(),
11861193
)?;
11871194
let id = toolchain.id.clone();
11881195
profile_compile(
@@ -1245,7 +1252,13 @@ fn main_result() -> anyhow::Result<i32> {
12451252
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
12461253
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
12471254
let commit = get_commit_or_fake_it(last_sha).expect("success");
1248-
let mut sysroot = Sysroot::install(commit.sha, &target_triple, &codegen_backends.0)?;
1255+
1256+
let rt = build_async_runtime();
1257+
let mut sysroot = rt.block_on(Sysroot::install(
1258+
commit.sha,
1259+
&host_target_tuple,
1260+
&codegen_backends.0,
1261+
))?;
12491262
sysroot.preserve(); // don't delete it
12501263

12511264
// Print the directory containing the toolchain.
@@ -1313,7 +1326,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
13131326
let target = database::Target::from_str(&target).map_err(|e| anyhow::anyhow!(e))?;
13141327
rt.block_on(conn.add_collector_config(
13151328
&collector_name,
1316-
&target,
1329+
target,
13171330
benchmark_set,
13181331
is_active,
13191332
))?;
@@ -1331,8 +1344,9 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
13311344

13321345
// Obtain the configuration and validate that it matches the
13331346
// collector's setup
1334-
let collector_config: database::CollectorConfig =
1335-
rt.block_on(conn.get_collector_config(&collector_name))?;
1347+
let collector_config: database::CollectorConfig = rt
1348+
.block_on(conn.get_collector_config(&collector_name))?
1349+
.unwrap();
13361350

13371351
let collector_target = collector_config.target();
13381352
if collector_target.as_str() != target {
@@ -1350,7 +1364,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
13501364

13511365
if let Some(benchmark_job) = benchmark_job {
13521366
// TODO; process the job
1353-
println!("{:?}", benchmark_job);
1367+
println!("{benchmark_job:?}");
13541368
}
13551369

13561370
Ok(0)
@@ -1642,7 +1656,7 @@ fn print_binary_stats(
16421656
.corner_top_right('│'),
16431657
),
16441658
);
1645-
println!("{}", table);
1659+
println!("{table}");
16461660
}
16471661

16481662
fn get_local_toolchain_for_runtime_benchmarks(
@@ -1912,16 +1926,13 @@ async fn bench_compile(
19121926
);
19131927
let result = measure(&mut processor).await;
19141928
if let Err(s) = result {
1915-
eprintln!(
1916-
"collector error: Failed to benchmark '{}', recorded: {:#}",
1917-
benchmark_name, s
1918-
);
1929+
eprintln!("collector error: Failed to benchmark '{benchmark_name}', recorded: {s:#}");
19191930
errors.incr();
19201931
tx.conn()
19211932
.record_error(
19221933
collector.artifact_row_id,
19231934
&benchmark_name.0,
1924-
&format!("{:?}", s),
1935+
&format!("{s:?}"),
19251936
)
19261937
.await;
19271938
};

collector/src/bin/rustc-fake.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ fn run_with_determinism_env(mut cmd: Command) {
3030
let status = cmd.status().expect("failed to spawn");
3131
assert!(
3232
status.success(),
33-
"command did not complete successfully: {:?}",
34-
cmd
33+
"command did not complete successfully: {cmd:?}"
3534
);
3635
}
3736

@@ -70,7 +69,7 @@ fn main() {
7069
.ok()
7170
.and_then(|v| v.parse::<u32>().ok())
7271
{
73-
args.push(OsString::from(format!("-Zthreads={}", count)));
72+
args.push(OsString::from(format!("-Zthreads={count}")));
7473
}
7574

7675
args.push(OsString::from("-Adeprecated"));
@@ -408,7 +407,7 @@ fn main() {
408407
}
409408

410409
_ => {
411-
panic!("unknown wrapper: {}", wrapper);
410+
panic!("unknown wrapper: {wrapper}");
412411
}
413412
}
414413
} else if args.iter().any(|arg| arg == "--skip-this-rustc") {
@@ -421,7 +420,7 @@ fn main() {
421420
.iter()
422421
.any(|arg| arg == "-vV" || arg == "--print=file-names")
423422
{
424-
eprintln!("{:?} {:?}", tool, args);
423+
eprintln!("{tool:?} {args:?}");
425424
eprintln!("exiting -- non-wrapped rustc");
426425
std::process::exit(1);
427426
}
@@ -441,7 +440,7 @@ fn process_self_profile_output(prof_out_dir: PathBuf, args: &[OsString]) {
441440
.and_then(|args| args[1].to_str())
442441
.expect("rustc to be invoked with crate name");
443442
println!("!self-profile-dir:{}", prof_out_dir.to_str().unwrap());
444-
println!("!self-profile-crate:{}", crate_name);
443+
println!("!self-profile-crate:{crate_name}");
445444
}
446445

447446
#[cfg(windows)]
@@ -456,9 +455,9 @@ fn exec(cmd: &mut Command) -> ! {
456455
#[cfg(unix)]
457456
fn exec(cmd: &mut Command) -> ! {
458457
use std::os::unix::prelude::*;
459-
let cmd_d = format!("{:?}", cmd);
458+
let cmd_d = format!("{cmd:?}");
460459
let error = cmd.exec();
461-
panic!("failed to exec `{}`: {}", cmd_d, error);
460+
panic!("failed to exec `{cmd_d}`: {error}");
462461
}
463462

464463
#[cfg(unix)]

collector/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn write_diff<W: Write>(writer: &mut W, use_color: bool, diff: &CodegenDiff) ->
203203
style.apply_to(change)
204204
)?;
205205
} else {
206-
write!(writer, "{}{}", sign, change)?;
206+
write!(writer, "{sign}{change}")?;
207207
}
208208
}
209209
writeln!(writer, "-----------------------------")?;
@@ -227,7 +227,7 @@ fn get_codegen(
227227
}
228228
CodegenType::LLVM | CodegenType::MIR => {}
229229
}
230-
cmd.arg(format!("{}", function_index));
230+
cmd.arg(format!("{function_index}"));
231231

232232
Ok(String::from_utf8(command_output(&mut cmd)?.stdout)?)
233233
}

collector/src/compile/benchmark/codegen_backend.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ impl From<CodegenBackend> for database::CodegenBackend {
1919
}
2020
}
2121
}
22+
23+
impl From<database::CodegenBackend> for CodegenBackend {
24+
fn from(value: database::CodegenBackend) -> Self {
25+
match value {
26+
database::CodegenBackend::Llvm => CodegenBackend::Llvm,
27+
database::CodegenBackend::Cranelift => CodegenBackend::Cranelift,
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)