Skip to content

Commit 36ae8d5

Browse files
committed
Get host tuple from rustc used for benchmarking/profiling, if possible
1 parent 8b605be commit 36ae8d5

File tree

1 file changed

+56
-12
lines changed

1 file changed

+56
-12
lines changed

collector/src/bin/collector.rs

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -794,16 +794,45 @@ fn main_result() -> anyhow::Result<i32> {
794794
runtime: &runtime_benchmark_dir,
795795
};
796796

797-
let host_target_tuple =
798-
String::from_utf8(command_output(Command::new("rustc").arg("--print=host-tuple"))?.stdout)?
799-
.trim()
800-
.to_string();
797+
let used_rustc: Option<String> = match &args.command {
798+
Commands::BinaryStats {
799+
mode: BinaryStatsMode::Compile(args),
800+
..
801+
} => Some(args.local.rustc.clone()),
802+
Commands::BenchRuntimeLocal { local, .. } => Some(local.rustc.clone()),
803+
Commands::ProfileRuntime { rustc, .. } => Some(rustc.clone()),
804+
Commands::CodegenDiff { rustc1, .. } => Some(rustc1.clone()),
805+
Commands::BenchLocal { local, .. } => Some(local.rustc.clone()),
806+
Commands::ProfileLocal { local, .. } => Some(local.rustc.clone()),
807+
Commands::BinaryStats {
808+
mode: BinaryStatsMode::Local(_),
809+
..
810+
}
811+
| Commands::BenchNext { .. }
812+
| Commands::BenchPublished { .. }
813+
| Commands::InstallNext { .. }
814+
| Commands::Download(_)
815+
| Commands::PurgeArtifact { .. }
816+
| Commands::BenchCmp { .. }
817+
| Commands::AddCollector { .. }
818+
| Commands::BenchmarkJobQueue { .. } => None,
819+
};
820+
821+
let host_target_tuple = match used_rustc {
822+
Some(rustc) => get_host_tuple_from_rustc(&rustc),
823+
None => get_host_tuple_from_rustc("rustc"),
824+
};
825+
let require_host_target_tuple = || {
826+
host_target_tuple.expect(
827+
"Cannot determine host target tuple. Please make a `rustc` binary available in PATH.",
828+
)
829+
};
801830

802831
match args.command {
803832
Commands::BinaryStats { mode, symbols } => {
804833
match mode {
805834
BinaryStatsMode::Compile(args) => {
806-
binary_stats_compile(args, symbols, &host_target_tuple)?;
835+
binary_stats_compile(args, symbols, &require_host_target_tuple())?;
807836
}
808837
BinaryStatsMode::Local(args) => {
809838
binary_stats_local(args, symbols)?;
@@ -822,7 +851,8 @@ fn main_result() -> anyhow::Result<i32> {
822851
purge,
823852
} => {
824853
log_db(&db);
825-
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &host_target_tuple)?;
854+
let toolchain =
855+
get_local_toolchain_for_runtime_benchmarks(&local, &require_host_target_tuple())?;
826856
let pool = Pool::open(&db.db);
827857

828858
let isolation_mode = if no_isolate {
@@ -871,6 +901,7 @@ fn main_result() -> anyhow::Result<i32> {
871901
rustc2,
872902
benchmark,
873903
} => {
904+
let host_target_tuple = require_host_target_tuple();
874905
let get_suite = |rustc: &str, id: &str| {
875906
let toolchain = get_local_toolchain(
876907
&[Profile::Opt],
@@ -928,6 +959,7 @@ fn main_result() -> anyhow::Result<i32> {
928959
rustc1: rustc,
929960
rustc2,
930961
} => {
962+
let host_target_tuple = require_host_target_tuple();
931963
let get_toolchain = |rustc: &str, id: &str| {
932964
let toolchain = get_local_toolchain(
933965
&[Profile::Opt],
@@ -978,7 +1010,7 @@ fn main_result() -> anyhow::Result<i32> {
9781010
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
9791011
.id(local.id.as_deref()),
9801012
"",
981-
host_target_tuple,
1013+
require_host_target_tuple(),
9821014
)?;
9831015

9841016
let mut benchmarks = get_compile_benchmarks(&compile_benchmark_dir, (&local).into())?;
@@ -1047,8 +1079,10 @@ fn main_result() -> anyhow::Result<i32> {
10471079

10481080
match next {
10491081
NextArtifact::Release(tag) => {
1050-
let toolchain =
1051-
create_toolchain_from_published_version(&tag, &host_target_tuple)?;
1082+
let toolchain = create_toolchain_from_published_version(
1083+
&tag,
1084+
&require_host_target_tuple(),
1085+
)?;
10521086
let conn = rt.block_on(pool.connection());
10531087
rt.block_on(bench_published_artifact(
10541088
conn,
@@ -1097,7 +1131,7 @@ fn main_result() -> anyhow::Result<i32> {
10971131
.block_on(Sysroot::install(
10981132
Path::new(TOOLCHAIN_CACHE_DIRECTORY),
10991133
sha.clone(),
1100-
&host_target_tuple,
1134+
&require_host_target_tuple(),
11011135
&backends,
11021136
))
11031137
.map_err(SysrootDownloadError::as_anyhow_error)
@@ -1180,7 +1214,7 @@ fn main_result() -> anyhow::Result<i32> {
11801214
let rt = build_async_runtime();
11811215
let conn = rt.block_on(pool.connection());
11821216
let toolchain =
1183-
create_toolchain_from_published_version(&toolchain, &host_target_tuple)?;
1217+
create_toolchain_from_published_version(&toolchain, &require_host_target_tuple())?;
11841218
rt.block_on(bench_published_artifact(
11851219
conn,
11861220
toolchain,
@@ -1221,6 +1255,7 @@ fn main_result() -> anyhow::Result<i32> {
12211255
.build_global()
12221256
.unwrap();
12231257

1258+
let host_target_tuple = require_host_target_tuple();
12241259
let mut get_toolchain_and_profile =
12251260
|rustc: &str, suffix: &str| -> anyhow::Result<String> {
12261261
let toolchain = get_local_toolchain(
@@ -1295,7 +1330,7 @@ fn main_result() -> anyhow::Result<i32> {
12951330
.block_on(Sysroot::install(
12961331
Path::new(TOOLCHAIN_CACHE_DIRECTORY),
12971332
commit.sha,
1298-
&host_target_tuple,
1333+
&require_host_target_tuple(),
12991334
&codegen_backends.0,
13001335
))
13011336
.map_err(SysrootDownloadError::as_anyhow_error)?;
@@ -1407,6 +1442,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
14071442
)
14081443
})?;
14091444

1445+
let host_target_tuple = require_host_target_tuple();
14101446
if collector_config.target().as_str() != host_target_tuple {
14111447
return Err(anyhow::anyhow!(
14121448
"The collector `{collector_name}` is configured for target `{}`, but the current host target seems to be `{host_target_tuple}`",
@@ -1437,6 +1473,14 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
14371473
}
14381474
}
14391475

1476+
fn get_host_tuple_from_rustc(rustc: &str) -> anyhow::Result<String> {
1477+
Ok(
1478+
String::from_utf8(command_output(Command::new(rustc).arg("--print=host-tuple"))?.stdout)?
1479+
.trim()
1480+
.to_string(),
1481+
)
1482+
}
1483+
14401484
/// Maximum number of failures before a job will be marked as failed.
14411485
const MAX_JOB_FAILS: u32 = 3;
14421486

0 commit comments

Comments
 (0)