Skip to content
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

Add benchmarks for rustdoc #675

Merged
merged 9 commits into from
Jul 14, 2020
Merged
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
34 changes: 22 additions & 12 deletions collector/src/bin/rustc-fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ use std::process::Command;
use std::time::{Duration, Instant};

fn main() {
let mut args = env::args_os().skip(1).collect::<Vec<_>>();
let mut args_os = env::args_os();
let name = args_os.next().unwrap().into_string().unwrap();

let mut args = args_os.collect::<Vec<_>>();
let rustc = env::var_os("RUSTC_REAL").unwrap();
let rustdoc = env::var_os("RUSTDOC_REAL").unwrap();
let actually_rustdoc = name.ends_with("rustdoc-fake");
let tool = if actually_rustdoc {
rustdoc
} else {
rustc
};

if let Some(count) = env::var("RUSTC_THREAD_COUNT")
.ok()
Expand Down Expand Up @@ -36,7 +46,7 @@ fn main() {
.arg("instructions:u,cycles:u,task-clock,cpu-clock,faults")
.arg("--log-fd")
.arg("1")
.arg(&rustc)
.arg(&tool)
.args(&args);

let prof_out_dir = std::env::current_dir().unwrap().join("self-profile-output");
Expand Down Expand Up @@ -91,14 +101,14 @@ fn main() {
}

"self-profile" => {
let mut cmd = Command::new(&rustc);
let mut cmd = Command::new(&tool);
cmd.arg("-Zself-profile=Zsp").args(&args);

assert!(cmd.status().expect("failed to spawn").success());
}

"time-passes" => {
let mut cmd = Command::new(&rustc);
let mut cmd = Command::new(&tool);
cmd.arg("-Ztime-passes").args(&args);

assert!(cmd.status().expect("failed to spawn").success());
Expand All @@ -113,7 +123,7 @@ fn main() {
.arg("--output=perf")
.arg("--freq=299")
.arg("--event=cycles:u,instructions:u")
.arg(&rustc)
.arg(&tool)
.args(&args);

assert!(cmd.status().expect("failed to spawn").success());
Expand All @@ -124,7 +134,7 @@ fn main() {
let has_oprofile = cmd.output().is_ok();
assert!(has_oprofile);
// Other possibly useful args: --callgraph, --separate-thread
cmd.arg("operf").arg(&rustc).args(&args);
cmd.arg("operf").arg(&tool).args(&args);

assert!(cmd.status().expect("failed to spawn").success());
}
Expand All @@ -140,7 +150,7 @@ fn main() {
.arg("--cache-sim=no")
.arg("--branch-sim=no")
.arg("--cachegrind-out-file=cgout")
.arg(&rustc)
.arg(&tool)
.args(&args);

assert!(cmd.status().expect("failed to spawn").success());
Expand All @@ -157,7 +167,7 @@ fn main() {
.arg("--cache-sim=no")
.arg("--branch-sim=no")
.arg("--callgrind-out-file=clgout")
.arg(&rustc)
.arg(&tool)
.args(&args);

assert!(cmd.status().expect("failed to spawn").success());
Expand All @@ -170,7 +180,7 @@ fn main() {
cmd.arg("--tool=dhat")
.arg("--num-callers=4")
.arg("--dhat-out-file=dhout")
.arg(&rustc)
.arg(&tool)
.args(&args);

assert!(cmd.status().expect("failed to spawn").success());
Expand All @@ -186,14 +196,14 @@ fn main() {
.arg("--threshold=0.2")
.arg("--massif-out-file=msout")
.arg("--alloc-fn=__rdl_alloc")
.arg(&rustc)
.arg(&tool)
.args(&args);

assert!(cmd.status().expect("failed to spawn").success());
}

"eprintln" | "llvm-lines" => {
let mut cmd = Command::new(&rustc);
let mut cmd = Command::new(&tool);
cmd.args(&args);

assert!(cmd.status().expect("failed to spawn").success());
Expand All @@ -204,7 +214,7 @@ fn main() {
}
}
} else {
let mut cmd = Command::new(&rustc);
let mut cmd = Command::new(&tool);
cmd.args(&args);
exec(&mut cmd);
}
Expand Down
72 changes: 44 additions & 28 deletions collector/src/bin/rustc-perf-collector/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Profiler {

// What cargo subcommand do we need to run for this profiler? If not
// `rustc`, must be a subcommand that itself invokes `rustc`.
fn subcommand(&self) -> &'static str {
fn subcommand(&self, build_kind: BuildKind) -> Option<&'static str> {
match self {
Profiler::PerfStat
| Profiler::PerfStatSelfProfile
Expand All @@ -158,25 +158,17 @@ impl Profiler {
| Profiler::Callgrind
| Profiler::DHAT
| Profiler::Massif
| Profiler::Eprintln => "rustc",
Profiler::LlvmLines => "llvm-lines",
}
}

fn is_build_kind_allowed(&self, build_kind: BuildKind) -> bool {
match self {
Profiler::PerfStat
| Profiler::PerfStatSelfProfile
| Profiler::SelfProfile
| Profiler::TimePasses
| Profiler::PerfRecord
| Profiler::OProfile
| Profiler::Cachegrind
| Profiler::Callgrind
| Profiler::DHAT
| Profiler::Massif
| Profiler::Eprintln => true,
Profiler::LlvmLines => build_kind != BuildKind::Check,
| Profiler::Eprintln => {
if build_kind == BuildKind::Doc {
Some("rustdoc")
} else {
Some("rustc")
}
}
Profiler::LlvmLines => match build_kind {
BuildKind::Debug | BuildKind::Opt => Some("rustc"),
BuildKind::Check | BuildKind::Doc => None,
},
}
}

Expand Down Expand Up @@ -242,6 +234,10 @@ impl<'a> CargoProcess<'a> {
.arg(subcommand)
.arg("--manifest-path")
.arg(&self.manifest_path);

if let Some(r) = &self.compiler.rustdoc {
cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r);
}
cmd
}

Expand All @@ -263,20 +259,22 @@ impl<'a> CargoProcess<'a> {
// machinery works).
let subcommand = if let Some((ref mut processor, run_kind, ..)) = self.processor_etc {
let profiler = processor.profiler();
if !profiler.is_build_kind_allowed(self.build_kind) {
return Err(anyhow::anyhow!(
"this profiler doesn't support {:?} builds",
self.build_kind
));
}
if !profiler.is_run_kind_allowed(run_kind) {
return Err(anyhow::anyhow!(
"this profiler doesn't support {:?} runs",
run_kind
));
}

profiler.subcommand()
match profiler.subcommand(self.build_kind) {
None => {
return Err(anyhow::anyhow!(
"this profiler doesn't support {:?} builds",
self.build_kind
))
}
Some(sub) => sub,
}
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
} else {
"rustc"
};
Expand All @@ -288,6 +286,7 @@ impl<'a> CargoProcess<'a> {
cmd.arg("--profile").arg("check");
}
BuildKind::Debug => {}
BuildKind::Doc => {}
BuildKind::Opt => {
cmd.arg("--release");
}
Expand All @@ -301,8 +300,9 @@ impl<'a> CargoProcess<'a> {
// onto rustc for the final crate, which is exactly the crate for which
// we want to wrap rustc.
if let Some((ref mut processor, ..)) = self.processor_etc {
let profiler = processor.profiler().name();
cmd.arg("--wrap-rustc-with");
cmd.arg(processor.profiler().name());
cmd.arg(profiler);
cmd.args(&self.rustc_args);
}

Expand Down Expand Up @@ -339,6 +339,21 @@ lazy_static::lazy_static! {
fake_rustc.push("rustc-fake");
fake_rustc
};
static ref FAKE_RUSTDOC: PathBuf = {
let mut fake_rustdoc = env::current_exe().unwrap();
fake_rustdoc.pop();
fake_rustdoc.push("rustdoc-fake");
// link from rustc-fake to rustdoc-fake
if !fake_rustdoc.exists() {
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::symlink_file as symlink;

symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link");
}
fake_rustdoc
};
}

/// Used to indicate if we need to retry a run.
Expand Down Expand Up @@ -438,6 +453,7 @@ impl<'a> MeasureProcessor<'a> {
let profile = match build_kind {
BuildKind::Check => database::Profile::Check,
BuildKind::Debug => database::Profile::Debug,
BuildKind::Doc => database::Profile::Doc,
BuildKind::Opt => database::Profile::Opt,
};
let mut buf = FuturesUnordered::new();
Expand Down
Loading