Skip to content

Allow specifying the number of executed iterations for runtime benchmarks #1468

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

Merged
merged 1 commit into from
Oct 17, 2022
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
6 changes: 6 additions & 0 deletions collector/src/bin/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ enum Commands {
/// Include only benchmarks matching a prefix in this comma-separated list
#[clap(long)]
include: Option<String>,

/// How many iterations of each benchmark should be executed.
#[clap(long, default_value = "5")]
iterations: u32,
},
/// Benchmarks a local rustc
BenchLocal {
Expand Down Expand Up @@ -706,12 +710,14 @@ fn main_result() -> anyhow::Result<i32> {
id,
exclude,
include,
iterations,
} => {
bench_runtime(
&rustc,
id.as_deref(),
BenchmarkFilter::new(exclude, include),
runtime_benchmark_dir,
iterations,
)?;
Ok(0)
}
Expand Down
6 changes: 5 additions & 1 deletion collector/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn bench_runtime(
id: Option<&str>,
filter: BenchmarkFilter,
benchmark_dir: PathBuf,
iterations: u32,
) -> anyhow::Result<()> {
let toolchain = get_local_toolchain(&[Profile::Opt], rustc, None, None, id, "")?;
let output = compile_runtime_benchmark_binaries(&toolchain, &benchmark_dir)?;
Expand All @@ -33,7 +34,7 @@ pub fn bench_runtime(

let mut benchmark_index = 0;
for binary in suite.groups {
for message in execute_runtime_benchmark_binary(&binary.binary, &filter)? {
for message in execute_runtime_benchmark_binary(&binary.binary, &filter, iterations)? {
let message = message.map_err(|err| {
anyhow::anyhow!(
"Cannot parse BenchmarkMessage from benchmark {}: {err:?}",
Expand Down Expand Up @@ -65,13 +66,16 @@ pub fn bench_runtime(
fn execute_runtime_benchmark_binary(
binary: &Path,
filter: &BenchmarkFilter,
iterations: u32,
) -> anyhow::Result<impl Iterator<Item = anyhow::Result<BenchmarkMessage>>> {
// Turn off ASLR
let mut command = Command::new("setarch");
command.arg(std::env::consts::ARCH);
command.arg("-R");
command.arg(binary);
command.arg("run");
command.arg("--iterations");
command.arg(&iterations.to_string());

if let Some(ref exclude) = filter.exclude {
command.args(&["--exclude", exclude]);
Expand Down