From 766f920b9faabee1f9af1052305cfa7c7ba1daf0 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 2 Oct 2021 21:06:21 -0400 Subject: [PATCH] Add dep-graph collector --- collector/README.md | 6 ++++++ collector/src/execute.rs | 21 +++++++++++++++++++++ collector/src/main.rs | 4 ++-- collector/src/rustc-fake.rs | 9 +++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/collector/README.md b/collector/README.md index 459fd3821..6a343f74c 100644 --- a/collector/README.md +++ b/collector/README.md @@ -366,6 +366,12 @@ The mandatory `` argument must be one of the following. - **Output**. File per CGU, currently, placed in a directory inside results. - **Notes**. Will likely work best with `Full` builds, on either Debug or Opt profiles. +- `dep-graph`: Dump the incremental dependency graph (as produced by + -Zdump-dep-graph). + - **Purpose**. This is useful when debugging changes to incremental behavior. + - **Slowdown**. Equivalent to normal compilation. + - **Output**. .dot and .txt file (.txt likely is what you want to see first). + - **Notes**. Works primarily with incremental compilation kinds. The mandatory `` argument is a patch to a rustc executable, similar to `bench_local`. diff --git a/collector/src/execute.rs b/collector/src/execute.rs index 1581adc85..fe82e70a2 100644 --- a/collector/src/execute.rs +++ b/collector/src/execute.rs @@ -180,6 +180,7 @@ pub enum Profiler { Eprintln, LlvmLines, MonoItems, + DepGraph, } impl Profiler { @@ -201,6 +202,7 @@ impl Profiler { "eprintln" => Ok(Profiler::Eprintln), "llvm-lines" => Ok(Profiler::LlvmLines), "mono-items" => Ok(Profiler::MonoItems), + "dep-graph" => Ok(Profiler::DepGraph), _ => Err(anyhow!("'{}' is not a known profiler", name)), } } @@ -222,6 +224,7 @@ impl Profiler { Profiler::Eprintln => "eprintln", Profiler::LlvmLines => "llvm-lines", Profiler::MonoItems => "mono-items", + Profiler::DepGraph => "dep-graph", } } @@ -241,6 +244,7 @@ impl Profiler { | Profiler::Callgrind | Profiler::DHAT | Profiler::Massif + | Profiler::DepGraph | Profiler::MonoItems | Profiler::Eprintln => { if build_kind == BuildKind::Doc { @@ -272,6 +276,8 @@ impl Profiler { | Profiler::Massif | Profiler::MonoItems | Profiler::Eprintln => true, + // only incremental + Profiler::DepGraph => scenario_kind != ScenarioKind::Full, Profiler::LlvmLines => scenario_kind == ScenarioKind::Full, } } @@ -1183,6 +1189,21 @@ impl<'a> Processor for ProfileProcessor<'a> { } } + Profiler::DepGraph => { + let tmp_file = filepath(data.cwd.as_ref(), "dep_graph.txt"); + let output = + filepath(self.output_dir, &out_file("dep-graph")).with_extension("txt"); + + fs::copy(&tmp_file, &output)?; + + let tmp_file = filepath(data.cwd.as_ref(), "dep_graph.dot"); + let output = + filepath(self.output_dir, &out_file("dep-graph")).with_extension("dot"); + + // May not exist if not incremental, but then that's OK. + fs::copy(&tmp_file, &output)?; + } + // `cargo llvm-lines` writes its output to stdout. We copy that // output into a file in the output dir. Profiler::LlvmLines => { diff --git a/collector/src/main.rs b/collector/src/main.rs index a556af2ff..190961970 100644 --- a/collector/src/main.rs +++ b/collector/src/main.rs @@ -674,7 +674,7 @@ fn main_result() -> anyhow::Result { (@arg PROFILER: +required +takes_value "One of: 'self-profile', 'time-passes', 'perf-record',\n\ 'oprofile', 'cachegrind', 'callgrind', 'dhat', 'massif',\n\ - 'eprintln', 'llvm-lines', 'mono-items'") + 'eprintln', 'llvm-lines', 'mono-items', 'dep-graph'") (@arg RUSTC: +required +takes_value "The path to the local rustc to benchmark") (@arg ID: +required +takes_value "Identifier to associate benchmark results with") @@ -703,7 +703,7 @@ fn main_result() -> anyhow::Result { (@arg PROFILER: +required +takes_value "One of: 'self-profile', 'time-passes', 'perf-record',\n\ 'oprofile', 'cachegrind', 'callgrind', 'dhat', 'massif',\n\ - 'eprintln', 'llvm-lines', 'mono-items'") + 'eprintln', 'llvm-lines', 'mono-items', 'dep-graph'") (@arg RUSTC_BEFORE: +required +takes_value "The path to the local rustc to benchmark") (@arg RUSTC_AFTER: +required +takes_value "The path to the local rustc to benchmark") diff --git a/collector/src/rustc-fake.rs b/collector/src/rustc-fake.rs index a6a74dcf4..32e936e3d 100644 --- a/collector/src/rustc-fake.rs +++ b/collector/src/rustc-fake.rs @@ -294,6 +294,15 @@ fn main() { assert!(cmd.status().expect("failed to spawn").success()); } + "dep-graph" => { + args.push("-Zdump-dep-graph".into()); + args.push("-Zquery-dep-graph".into()); + let mut cmd = Command::new(tool); + cmd.args(&args); + + assert!(cmd.status().expect("failed to spawn").success()); + } + _ => { panic!("unknown wrapper: {}", wrapper); }