Skip to content

Commit 543122d

Browse files
Share target directories between benchmarks
1 parent 0185d8d commit 543122d

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

collector/src/execute.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,24 +1005,24 @@ impl Benchmark {
10051005
pub fn measure(
10061006
&self,
10071007
processor: &mut dyn Processor,
1008-
build_kinds: &[BuildKind],
1008+
build_kinds_and_target_dir: &[(BuildKind, &Path)],
10091009
run_kinds: &[RunKind],
10101010
compiler: Compiler<'_>,
10111011
iterations: usize,
10121012
) -> anyhow::Result<()> {
10131013
let iterations = cmp::min(iterations, self.config.runs);
10141014

1015-
if self.config.disabled || build_kinds.is_empty() {
1015+
if self.config.disabled || build_kinds_and_target_dir.is_empty() {
10161016
eprintln!("Skipping {}: disabled", self.name);
10171017
bail!("disabled benchmark");
10181018
}
10191019

10201020
eprintln!("Preparing {}", self.name);
10211021

10221022
// These directories are *target* directories.
1023-
let build_kind_dirs = build_kinds
1023+
let build_kind_dirs = build_kinds_and_target_dir
10241024
.iter()
1025-
.map(|kind| Ok((*kind, TempDir::new()?, self.make_temp_dir(&self.path)?)))
1025+
.map(|(kind, target_dir)| Ok((*kind, target_dir, self.make_temp_dir(&self.path)?)))
10261026
.collect::<anyhow::Result<Vec<_>>>()?;
10271027

10281028
// In parallel (but with a limit to the number of CPUs), prepare all
@@ -1051,7 +1051,7 @@ impl Benchmark {
10511051
for (build_kind, target_dir, src_dir) in &build_kind_dirs {
10521052
let server = server.clone();
10531053
s.spawn::<_, anyhow::Result<()>>(move |_| {
1054-
self.mk_cargo_process(compiler, target_dir.path(), src_dir.path(), *build_kind)
1054+
self.mk_cargo_process(compiler, target_dir, src_dir.path(), *build_kind)
10551055
.jobserver(server)
10561056
.run_rustc(false)?;
10571057
Ok(())
@@ -1077,7 +1077,7 @@ impl Benchmark {
10771077
}
10781078
}
10791079
log::debug!("Benchmark iteration {}/{}", i + 1, iterations);
1080-
let target_dir = self.make_temp_dir(target_dir.path())?;
1080+
let target_dir = self.make_temp_dir(target_dir)?;
10811081
let target_dir = target_dir.path();
10821082
let src_dir = self.make_temp_dir(src_dir.path())?;
10831083
let src_dir = src_dir.path();

collector/src/main.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::path::{Path, PathBuf};
1313
use std::process;
1414
use std::process::Command;
1515
use std::{str, time::Instant};
16+
use tempfile::TempDir;
1617
use tokio::runtime::Runtime;
1718

1819
mod execute;
@@ -207,6 +208,16 @@ fn bench(
207208
);
208209
}
209210

211+
let bk_and_targets = build_kinds
212+
.iter()
213+
.map(|kind| Ok((*kind, TempDir::new()?)))
214+
.collect::<anyhow::Result<Vec<_>>>()
215+
.expect("created temp directories");
216+
let bk_and_targets = bk_and_targets
217+
.iter()
218+
.map(|(k, td)| (*k, td.path()))
219+
.collect::<Vec<_>>();
220+
210221
let steps = benchmarks
211222
.iter()
212223
.map(|b| b.name.to_string())
@@ -250,8 +261,13 @@ fn bench(
250261
interned_cid,
251262
self_profile,
252263
);
253-
let result =
254-
benchmark.measure(&mut processor, build_kinds, run_kinds, compiler, iterations);
264+
let result = benchmark.measure(
265+
&mut processor,
266+
&bk_and_targets,
267+
run_kinds,
268+
compiler,
269+
iterations,
270+
);
255271
if let Err(s) = result {
256272
eprintln!(
257273
"collector error: Failed to benchmark '{}', recorded: {}",
@@ -734,12 +750,22 @@ fn main_result() -> anyhow::Result<i32> {
734750

735751
eprintln!("Profiling with {:?}", profiler);
736752

753+
let bk_and_targets = build_kinds
754+
.iter()
755+
.map(|kind| Ok((*kind, TempDir::new()?)))
756+
.collect::<anyhow::Result<Vec<_>>>()
757+
.expect("created temp directories");
758+
let bk_and_targets = bk_and_targets
759+
.iter()
760+
.map(|(k, td)| (*k, td.path()))
761+
.collect::<Vec<_>>();
762+
737763
let mut errors = BenchmarkErrors::new();
738764
for (i, benchmark) in benchmarks.iter().enumerate() {
739765
eprintln!("{}", n_benchmarks_remaining(benchmarks.len() - i));
740766
let mut processor = execute::ProfileProcessor::new(profiler, &out_dir, &id);
741767
let result =
742-
benchmark.measure(&mut processor, &build_kinds, &run_kinds, compiler, 1);
768+
benchmark.measure(&mut processor, &bk_and_targets, &run_kinds, compiler, 1);
743769
if let Err(ref s) = result {
744770
errors.incr();
745771
eprintln!(

0 commit comments

Comments
 (0)