Skip to content

Preparation for collector job queue integration #2216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rust-version = "1.85.0"
[dependencies]
anyhow = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
clap = { workspace = true, features = ["derive"] }
clap = { workspace = true, features = ["derive", "env"] }
env_logger = { workspace = true }
hashbrown = { workspace = true }
log = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion collector/benchlib/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<'a> BenchmarkGroup<'a> {
profile_fn: Box::new(move || profile_function(constructor2.as_ref())),
};
if self.benchmarks.insert(name, benchmark_fns).is_some() {
panic!("Benchmark '{}' was registered twice", name);
panic!("Benchmark '{name}' was registered twice");
}
}

Expand Down
75 changes: 45 additions & 30 deletions collector/src/bin/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use database::{ArtifactId, ArtifactIdNumber, Commit, CommitType, Connection, Poo

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

struct BenchmarkErrors(usize);
Expand Down Expand Up @@ -160,7 +160,7 @@ fn generate_diffs(
vec![format!("{:?}", scenario)]
}
Scenario::IncrPatched => (0..benchmark.patches.len())
.map(|i| format!("{:?}{}", scenario, i))
.map(|i| format!("{scenario:?}{i}"))
.collect::<Vec<_>>(),
}
}) {
Expand All @@ -175,15 +175,15 @@ fn generate_diffs(
profiler.postfix()
)
};
let id_diff = format!("{}-{}", id1, id2);
let id_diff = format!("{id1}-{id2}");
let prefix = profiler.prefix();
let left = out_dir.join(filename(prefix, id1));
let right = out_dir.join(filename(prefix, id2));
let output = out_dir.join(filename(&format!("{prefix}-diff"), &id_diff));

if let Err(e) = profiler.diff(&left, &right, &output) {
errors.incr();
eprintln!("collector error: {:?}", e);
eprintln!("collector error: {e:?}");
continue;
}

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

Expand Down Expand Up @@ -668,20 +668,26 @@ enum Commands {
modified: Option<String>,
},

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

/// Name of the collector.
#[arg(long)]
collector_name: String,

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

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

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

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

match args.command {
Commands::BinaryStats { mode, symbols } => {
match mode {
BinaryStatsMode::Compile(args) => {
binary_stats_compile(args, symbols, &target_triple)?;
binary_stats_compile(args, symbols, &host_target_tuple)?;
}
BinaryStatsMode::Local(args) => {
binary_stats_local(args, symbols)?;
Expand All @@ -792,7 +799,7 @@ fn main_result() -> anyhow::Result<i32> {
purge,
} => {
log_db(&db);
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &target_triple)?;
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &host_target_tuple)?;
let pool = Pool::open(&db.db);

let isolation_mode = if no_isolate {
Expand Down Expand Up @@ -846,7 +853,7 @@ fn main_result() -> anyhow::Result<i32> {
rustc,
ToolchainConfig::default(),
id,
target_triple.clone(),
host_target_tuple.clone(),
)?;
let suite = prepare_runtime_benchmark_suite(
&toolchain,
Expand Down Expand Up @@ -903,7 +910,7 @@ fn main_result() -> anyhow::Result<i32> {
rustc,
ToolchainConfig::default(),
id,
target_triple.clone(),
host_target_tuple.clone(),
)?;
Ok::<_, anyhow::Error>(toolchain)
};
Expand Down Expand Up @@ -946,7 +953,7 @@ fn main_result() -> anyhow::Result<i32> {
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
.id(local.id.as_deref()),
"",
target_triple,
host_target_tuple,
)?;

let mut benchmarks = get_compile_benchmarks(&compile_benchmark_dir, (&local).into())?;
Expand Down Expand Up @@ -991,7 +998,7 @@ fn main_result() -> anyhow::Result<i32> {
println!("processing artifacts");
let client = reqwest::blocking::Client::new();
let response: collector::api::next_artifact::Response = client
.get(format!("{}/perf/next_artifact", site_url))
.get(format!("{site_url}/perf/next_artifact"))
.send()?
.json()?;
let next = if let Some(c) = response.artifact {
Expand All @@ -1015,7 +1022,7 @@ fn main_result() -> anyhow::Result<i32> {
match next {
NextArtifact::Release(tag) => {
let toolchain =
create_toolchain_from_published_version(&tag, &target_triple)?;
create_toolchain_from_published_version(&tag, &host_target_tuple)?;
let conn = rt.block_on(pool.connection());
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))
}
Expand Down Expand Up @@ -1055,9 +1062,10 @@ fn main_result() -> anyhow::Result<i32> {
}
};
let sha = commit.sha.to_string();
let sysroot = Sysroot::install(sha.clone(), &target_triple, &backends)
let sysroot = rt
.block_on(Sysroot::install(sha.clone(), &host_target_tuple, &backends))
.with_context(|| {
format!("failed to install sysroot for {:?}", commit)
format!("failed to install sysroot for {commit:?}")
})?;

let mut benchmarks = get_compile_benchmarks(
Expand Down Expand Up @@ -1118,7 +1126,7 @@ fn main_result() -> anyhow::Result<i32> {
}
});
// We need to send a message to this endpoint even if the collector panics
client.post(format!("{}/perf/onpush", site_url)).send()?;
client.post(format!("{site_url}/perf/onpush")).send()?;

match res {
Ok(res) => res?,
Expand All @@ -1134,7 +1142,8 @@ fn main_result() -> anyhow::Result<i32> {
let pool = database::Pool::open(&db.db);
let rt = build_async_runtime();
let conn = rt.block_on(pool.connection());
let toolchain = create_toolchain_from_published_version(&toolchain, &target_triple)?;
let toolchain =
create_toolchain_from_published_version(&toolchain, &host_target_tuple)?;
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))?;
Ok(0)
}
Expand Down Expand Up @@ -1182,7 +1191,7 @@ fn main_result() -> anyhow::Result<i32> {
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
.id(local.id.as_deref()),
suffix,
target_triple.clone(),
host_target_tuple.clone(),
)?;
let id = toolchain.id.clone();
profile_compile(
Expand Down Expand Up @@ -1245,7 +1254,13 @@ fn main_result() -> anyhow::Result<i32> {
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
let commit = get_commit_or_fake_it(last_sha).expect("success");
let mut sysroot = Sysroot::install(commit.sha, &target_triple, &codegen_backends.0)?;

let rt = build_async_runtime();
let mut sysroot = rt.block_on(Sysroot::install(
commit.sha,
&host_target_tuple,
&codegen_backends.0,
))?;
sysroot.preserve(); // don't delete it

// Print the directory containing the toolchain.
Expand Down Expand Up @@ -1313,7 +1328,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
let target = database::Target::from_str(&target).map_err(|e| anyhow::anyhow!(e))?;
rt.block_on(conn.add_collector_config(
&collector_name,
&target,
target,
benchmark_set,
is_active,
))?;
Expand All @@ -1331,8 +1346,9 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc

// Obtain the configuration and validate that it matches the
// collector's setup
let collector_config: database::CollectorConfig =
rt.block_on(conn.get_collector_config(&collector_name))?;
let collector_config: database::CollectorConfig = rt
.block_on(conn.get_collector_config(&collector_name))?
.unwrap();

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

if let Some(benchmark_job) = benchmark_job {
// TODO; process the job
println!("{:?}", benchmark_job);
println!("{benchmark_job:?}");
}

Ok(0)
Expand Down Expand Up @@ -1642,7 +1658,7 @@ fn print_binary_stats(
.corner_top_right('│'),
),
);
println!("{}", table);
println!("{table}");
}

fn get_local_toolchain_for_runtime_benchmarks(
Expand Down Expand Up @@ -1913,15 +1929,14 @@ async fn bench_compile(
let result = measure(&mut processor).await;
if let Err(s) = result {
eprintln!(
"collector error: Failed to benchmark '{}', recorded: {:#}",
benchmark_name, s
"collector error: Failed to benchmark '{benchmark_name}', recorded: {s:#}"
);
errors.incr();
tx.conn()
.record_error(
collector.artifact_row_id,
&benchmark_name.0,
&format!("{:?}", s),
&format!("{s:?}"),
)
.await;
};
Expand Down
15 changes: 7 additions & 8 deletions collector/src/bin/rustc-fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ fn run_with_determinism_env(mut cmd: Command) {
let status = cmd.status().expect("failed to spawn");
assert!(
status.success(),
"command did not complete successfully: {:?}",
cmd
"command did not complete successfully: {cmd:?}"
);
}

Expand Down Expand Up @@ -70,7 +69,7 @@ fn main() {
.ok()
.and_then(|v| v.parse::<u32>().ok())
{
args.push(OsString::from(format!("-Zthreads={}", count)));
args.push(OsString::from(format!("-Zthreads={count}")));
}

args.push(OsString::from("-Adeprecated"));
Expand Down Expand Up @@ -408,7 +407,7 @@ fn main() {
}

_ => {
panic!("unknown wrapper: {}", wrapper);
panic!("unknown wrapper: {wrapper}");
}
}
} else if args.iter().any(|arg| arg == "--skip-this-rustc") {
Expand All @@ -421,7 +420,7 @@ fn main() {
.iter()
.any(|arg| arg == "-vV" || arg == "--print=file-names")
{
eprintln!("{:?} {:?}", tool, args);
eprintln!("{tool:?} {args:?}");
eprintln!("exiting -- non-wrapped rustc");
std::process::exit(1);
}
Expand All @@ -441,7 +440,7 @@ fn process_self_profile_output(prof_out_dir: PathBuf, args: &[OsString]) {
.and_then(|args| args[1].to_str())
.expect("rustc to be invoked with crate name");
println!("!self-profile-dir:{}", prof_out_dir.to_str().unwrap());
println!("!self-profile-crate:{}", crate_name);
println!("!self-profile-crate:{crate_name}");
}

#[cfg(windows)]
Expand All @@ -456,9 +455,9 @@ fn exec(cmd: &mut Command) -> ! {
#[cfg(unix)]
fn exec(cmd: &mut Command) -> ! {
use std::os::unix::prelude::*;
let cmd_d = format!("{:?}", cmd);
let cmd_d = format!("{cmd:?}");
let error = cmd.exec();
panic!("failed to exec `{}`: {}", cmd_d, error);
panic!("failed to exec `{cmd_d}`: {error}");
}

#[cfg(unix)]
Expand Down
4 changes: 2 additions & 2 deletions collector/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn write_diff<W: Write>(writer: &mut W, use_color: bool, diff: &CodegenDiff) ->
style.apply_to(change)
)?;
} else {
write!(writer, "{}{}", sign, change)?;
write!(writer, "{sign}{change}")?;
}
}
writeln!(writer, "-----------------------------")?;
Expand All @@ -227,7 +227,7 @@ fn get_codegen(
}
CodegenType::LLVM | CodegenType::MIR => {}
}
cmd.arg(format!("{}", function_index));
cmd.arg(format!("{function_index}"));

Ok(String::from_utf8(command_output(&mut cmd)?.stdout)?)
}
Expand Down
9 changes: 9 additions & 0 deletions collector/src/compile/benchmark/codegen_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ impl From<CodegenBackend> for database::CodegenBackend {
}
}
}

impl From<database::CodegenBackend> for CodegenBackend {
fn from(value: database::CodegenBackend) -> Self {
match value {
database::CodegenBackend::Llvm => CodegenBackend::Llvm,
database::CodegenBackend::Cranelift => CodegenBackend::Cranelift,
}
}
}
Loading
Loading