Skip to content

Commit 12d8979

Browse files
Merge pull request #739 from rust-lang/revert-738-share-build-cache
Revert "Share target directories between benchmarks"
2 parents fe431ec + 5dfa802 commit 12d8979

File tree

2 files changed

+31
-66
lines changed

2 files changed

+31
-66
lines changed

collector/src/execute.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ impl Profiler {
198198

199199
struct CargoProcess<'a> {
200200
compiler: Compiler<'a>,
201-
src_dir: &'a Path,
202-
target_directory: &'a Path,
201+
cwd: &'a Path,
203202
build_kind: BuildKind,
204203
incremental: bool,
205204
processor_etc: Option<(&'a mut dyn Processor, RunKind, &'a str, Option<&'a Patch>)>,
@@ -228,7 +227,7 @@ impl<'a> CargoProcess<'a> {
228227
self
229228
}
230229

231-
fn base_command(&self, subcommand: &str) -> Command {
230+
fn base_command(&self, cwd: &Path, subcommand: &str) -> Command {
232231
let mut cmd = Command::new(Path::new(self.compiler.cargo));
233232
cmd
234233
// Not all cargo invocations (e.g. `cargo clean`) need all of these
@@ -240,7 +239,7 @@ impl<'a> CargoProcess<'a> {
240239
// and any in-tree dependencies, and we don't want that; it wastes
241240
// time.
242241
.env("CARGO_INCREMENTAL", "0")
243-
.current_dir(self.src_dir)
242+
.current_dir(cwd)
244243
.arg(subcommand)
245244
.arg("--manifest-path")
246245
.arg(&self.manifest_path);
@@ -251,10 +250,10 @@ impl<'a> CargoProcess<'a> {
251250
cmd
252251
}
253252

254-
fn get_pkgid(&self) -> anyhow::Result<String> {
255-
let mut pkgid_cmd = self.base_command("pkgid");
253+
fn get_pkgid(&self, cwd: &Path) -> anyhow::Result<String> {
254+
let mut pkgid_cmd = self.base_command(cwd, "pkgid");
256255
let out = command_output(&mut pkgid_cmd)
257-
.with_context(|| format!("failed to obtain pkgid in '{:?}'", self.src_dir))?
256+
.with_context(|| format!("failed to obtain pkgid in '{:?}'", cwd))?
258257
.stdout;
259258
let package_id = str::from_utf8(&out).unwrap();
260259
Ok(package_id.trim().to_string())
@@ -306,8 +305,8 @@ impl<'a> CargoProcess<'a> {
306305
}
307306
};
308307

309-
let mut cmd = self.base_command(subcommand);
310-
cmd.arg("-p").arg(self.get_pkgid()?);
308+
let mut cmd = self.base_command(self.cwd, subcommand);
309+
cmd.arg("-p").arg(self.get_pkgid(self.cwd)?);
311310
match self.build_kind {
312311
BuildKind::Check => {
313312
cmd.arg("--profile").arg("check");
@@ -323,8 +322,6 @@ impl<'a> CargoProcess<'a> {
323322
cmd.arg("-Zunstable-options");
324323
cmd.arg("-Ztimings");
325324
}
326-
// --target-dir is not universally read, but this hopefully is.
327-
cmd.env("CARGO_TARGET_DIR", self.target_directory);
328325
cmd.arg("--");
329326
// --wrap-rustc-with is not a valid rustc flag. But rustc-fake
330327
// recognizes it, strips it (and its argument) out, and uses it as an
@@ -356,10 +353,10 @@ impl<'a> CargoProcess<'a> {
356353
// in-tree (e.g., in the case of the servo crates there are a lot of
357354
// other components).
358355
if let Some(file) = &self.touch_file {
359-
touch(&self.src_dir, Path::new(&file))?;
356+
touch(&self.cwd, Path::new(&file))?;
360357
} else {
361358
touch_all(
362-
&self.src_dir.join(
359+
&self.cwd.join(
363360
Path::new(&self.manifest_path)
364361
.parent()
365362
.expect("manifest has parent"),
@@ -377,7 +374,7 @@ impl<'a> CargoProcess<'a> {
377374
if self.incremental {
378375
cmd.arg("-C");
379376
let mut incr_arg = std::ffi::OsString::from("incremental=");
380-
incr_arg.push(self.target_directory.join("incremental-state"));
377+
incr_arg.push(self.cwd.join("incremental-state"));
381378
cmd.arg(incr_arg);
382379
}
383380

@@ -391,7 +388,7 @@ impl<'a> CargoProcess<'a> {
391388
if let Some((ref mut processor, run_kind, run_kind_str, patch)) = self.processor_etc {
392389
let data = ProcessOutputData {
393390
name: self.processor_name.clone(),
394-
cwd: self.src_dir,
391+
cwd: self.cwd,
395392
build_kind: self.build_kind,
396393
run_kind,
397394
run_kind_str,
@@ -955,8 +952,7 @@ impl Benchmark {
955952
fn mk_cargo_process<'a>(
956953
&'a self,
957954
compiler: Compiler<'a>,
958-
target_directory: &'a Path,
959-
src_dir: &'a Path,
955+
cwd: &'a Path,
960956
build_kind: BuildKind,
961957
) -> CargoProcess<'a> {
962958
let mut cargo_args = self
@@ -977,8 +973,7 @@ impl Benchmark {
977973
CargoProcess {
978974
compiler,
979975
processor_name: self.name.clone(),
980-
target_directory,
981-
src_dir,
976+
cwd,
982977
build_kind,
983978
incremental: false,
984979
processor_etc: None,
@@ -1005,24 +1000,22 @@ impl Benchmark {
10051000
pub fn measure(
10061001
&self,
10071002
processor: &mut dyn Processor,
1008-
build_kinds_and_target_dir: &[(BuildKind, &Path)],
1003+
build_kinds: &[BuildKind],
10091004
run_kinds: &[RunKind],
10101005
compiler: Compiler<'_>,
10111006
iterations: usize,
10121007
) -> anyhow::Result<()> {
10131008
let iterations = cmp::min(iterations, self.config.runs);
10141009

1015-
if self.config.disabled || build_kinds_and_target_dir.is_empty() {
1010+
if self.config.disabled || build_kinds.is_empty() {
10161011
eprintln!("Skipping {}: disabled", self.name);
10171012
bail!("disabled benchmark");
10181013
}
10191014

10201015
eprintln!("Preparing {}", self.name);
1021-
1022-
// These directories are *target* directories.
1023-
let build_kind_dirs = build_kinds_and_target_dir
1016+
let build_kind_dirs = build_kinds
10241017
.iter()
1025-
.map(|(kind, target_dir)| Ok((*kind, target_dir, self.make_temp_dir(&self.path)?)))
1018+
.map(|kind| Ok((*kind, self.make_temp_dir(&self.path)?)))
10261019
.collect::<anyhow::Result<Vec<_>>>()?;
10271020

10281021
// In parallel (but with a limit to the number of CPUs), prepare all
@@ -1048,10 +1041,10 @@ impl Benchmark {
10481041
// target-directory global lock during compilation.
10491042
crossbeam_utils::thread::scope::<_, anyhow::Result<()>>(|s| {
10501043
let server = jobserver::Client::new(num_cpus::get()).context("jobserver::new")?;
1051-
for (build_kind, target_dir, src_dir) in &build_kind_dirs {
1044+
for (build_kind, prep_dir) in &build_kind_dirs {
10521045
let server = server.clone();
10531046
s.spawn::<_, anyhow::Result<()>>(move |_| {
1054-
self.mk_cargo_process(compiler, target_dir, src_dir.path(), *build_kind)
1047+
self.mk_cargo_process(compiler, prep_dir.path(), *build_kind)
10551048
.jobserver(server)
10561049
.run_rustc(false)?;
10571050
Ok(())
@@ -1061,7 +1054,7 @@ impl Benchmark {
10611054
})
10621055
.unwrap()?;
10631056

1064-
for (build_kind, target_dir, src_dir) in build_kind_dirs {
1057+
for (build_kind, prep_dir) in build_kind_dirs {
10651058
eprintln!("Running {}: {:?} + {:?}", self.name, build_kind, run_kinds);
10661059

10671060
// We want at least two runs for all benchmarks (since we run
@@ -1077,14 +1070,12 @@ impl Benchmark {
10771070
}
10781071
}
10791072
log::debug!("Benchmark iteration {}/{}", i + 1, iterations);
1080-
let target_dir = self.make_temp_dir(target_dir)?;
1081-
let target_dir = target_dir.path();
1082-
let src_dir = self.make_temp_dir(src_dir.path())?;
1083-
let src_dir = src_dir.path();
1073+
let timing_dir = self.make_temp_dir(prep_dir.path())?;
1074+
let cwd = timing_dir.path();
10841075

10851076
// A full non-incremental build.
10861077
if run_kinds.contains(&RunKind::Full) {
1087-
self.mk_cargo_process(compiler, target_dir, src_dir, build_kind)
1078+
self.mk_cargo_process(compiler, cwd, build_kind)
10881079
.processor(processor, RunKind::Full, "Full", None)
10891080
.run_rustc(true)?;
10901081
}
@@ -1097,15 +1088,15 @@ impl Benchmark {
10971088
|| run_kinds.contains(&RunKind::IncrUnchanged)
10981089
|| run_kinds.contains(&RunKind::IncrPatched)
10991090
{
1100-
self.mk_cargo_process(compiler, target_dir, src_dir, build_kind)
1091+
self.mk_cargo_process(compiler, cwd, build_kind)
11011092
.incremental(true)
11021093
.processor(processor, RunKind::IncrFull, "IncrFull", None)
11031094
.run_rustc(true)?;
11041095
}
11051096

11061097
// An incremental build with no changes (fastest incremental case).
11071098
if run_kinds.contains(&RunKind::IncrUnchanged) {
1108-
self.mk_cargo_process(compiler, target_dir, src_dir, build_kind)
1099+
self.mk_cargo_process(compiler, cwd, build_kind)
11091100
.incremental(true)
11101101
.processor(processor, RunKind::IncrUnchanged, "IncrUnchanged", None)
11111102
.run_rustc(true)?;
@@ -1114,12 +1105,12 @@ impl Benchmark {
11141105
if run_kinds.contains(&RunKind::IncrPatched) {
11151106
for (i, patch) in self.patches.iter().enumerate() {
11161107
log::debug!("applying patch {}", patch.name);
1117-
patch.apply(src_dir).map_err(|s| anyhow::anyhow!("{}", s))?;
1108+
patch.apply(cwd).map_err(|s| anyhow::anyhow!("{}", s))?;
11181109

11191110
// An incremental build with some changes (realistic
11201111
// incremental case).
11211112
let run_kind_str = format!("IncrPatched{}", i);
1122-
self.mk_cargo_process(compiler, target_dir, src_dir, build_kind)
1113+
self.mk_cargo_process(compiler, cwd, build_kind)
11231114
.incremental(true)
11241115
.processor(
11251116
processor,

collector/src/main.rs

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

1918
mod execute;
@@ -208,16 +207,6 @@ fn bench(
208207
);
209208
}
210209

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-
221210
let steps = benchmarks
222211
.iter()
223212
.map(|b| b.name.to_string())
@@ -261,13 +250,8 @@ fn bench(
261250
interned_cid,
262251
self_profile,
263252
);
264-
let result = benchmark.measure(
265-
&mut processor,
266-
&bk_and_targets,
267-
run_kinds,
268-
compiler,
269-
iterations,
270-
);
253+
let result =
254+
benchmark.measure(&mut processor, build_kinds, run_kinds, compiler, iterations);
271255
if let Err(s) = result {
272256
eprintln!(
273257
"collector error: Failed to benchmark '{}', recorded: {}",
@@ -750,22 +734,12 @@ fn main_result() -> anyhow::Result<i32> {
750734

751735
eprintln!("Profiling with {:?}", profiler);
752736

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-
763737
let mut errors = BenchmarkErrors::new();
764738
for (i, benchmark) in benchmarks.iter().enumerate() {
765739
eprintln!("{}", n_benchmarks_remaining(benchmarks.len() - i));
766740
let mut processor = execute::ProfileProcessor::new(profiler, &out_dir, &id);
767741
let result =
768-
benchmark.measure(&mut processor, &bk_and_targets, &run_kinds, compiler, 1);
742+
benchmark.measure(&mut processor, &build_kinds, &run_kinds, compiler, 1);
769743
if let Err(ref s) = result {
770744
errors.incr();
771745
eprintln!(

0 commit comments

Comments
 (0)