Skip to content

Commit 2527c20

Browse files
committed
fixup: add benches arg for run cmd
1 parent e621f28 commit 2527c20

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

go-runner/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ mod results;
1111
/// Builds the specified go project and writes the benchmarks to the .codspeed folder.
1212
pub fn build_benchmarks(project_dir: &Path) -> anyhow::Result<Vec<PathBuf>> {
1313
// 1. Benchmark and package discovery
14-
//
1514
let benchmark_packages = builder::discovery::run(project_dir)?;
1615
info!("Discovered {} packages", benchmark_packages.len());
1716
debug!("Packages: {:?}", benchmark_packages.keys());
@@ -49,8 +48,7 @@ pub fn build_benchmarks(project_dir: &Path) -> anyhow::Result<Vec<PathBuf>> {
4948
Ok(binaries)
5049
}
5150

52-
/// This will be invoked by `codspeed run -- run_benchmarks`
53-
pub fn run_benchmarks() -> anyhow::Result<()> {
51+
pub fn run_benchmarks(bench: &str) -> anyhow::Result<()> {
5452
// 1. Discover the benchmarks
5553
let codspeed_dir = std::env::current_dir()?.join(".codspeed").join("walltime");
5654
let benchmark_packages = std::fs::read_dir(&codspeed_dir)?
@@ -64,7 +62,7 @@ pub fn run_benchmarks() -> anyhow::Result<()> {
6462
info!("Running: {}", bench_path.display());
6563

6664
let cmd = std::process::Command::new(bench_path)
67-
.arg("-test.bench=.") // TODO: Pass the args
65+
.arg(format!("-test.bench={bench}"))
6866
.output()?;
6967

7068
// Check if the command was successful
@@ -83,6 +81,7 @@ pub fn run_benchmarks() -> anyhow::Result<()> {
8381
}
8482
}
8583

84+
// 3. Collect the results
8685
collect_walltime_results()?;
8786

8887
Ok(())

go-runner/src/main.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ enum Commands {
1717
path: PathBuf,
1818
},
1919
/// Run the already built benchmarks
20-
Run,
20+
Run {
21+
/// Equivalent to the `-bench regexp` flag in `go test`.
22+
///
23+
/// Run only those benchmarks matching a regular expression.
24+
/// By default, no benchmarks are run.
25+
/// To run all benchmarks, use '-bench .' or '-bench=.'.
26+
/// The regular expression is split by unbracketed slash (/)
27+
/// characters into a sequence of regular expressions, and each
28+
/// part of a benchmark's identifier must match the corresponding
29+
/// element in the sequence, if any.
30+
#[arg(long, default_value = ".")]
31+
bench: String,
32+
},
2133
}
2234

2335
fn main() -> anyhow::Result<()> {
@@ -29,8 +41,8 @@ fn main() -> anyhow::Result<()> {
2941
Commands::Build { path } => {
3042
go_runner::build_benchmarks(path)?;
3143
}
32-
Commands::Run => {
33-
go_runner::run_benchmarks()?;
44+
Commands::Run { bench } => {
45+
go_runner::run_benchmarks(bench)?;
3446
}
3547
}
3648

0 commit comments

Comments
 (0)