Skip to content

Commit 7eb6112

Browse files
committed
fixup: minor chnages in UX
1 parent 38d39e2 commit 7eb6112

File tree

5 files changed

+38
-66
lines changed

5 files changed

+38
-66
lines changed

go-runner/src/builder/patcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn patch_imports<P: AsRef<Path>>(
4545
bail!("Failed to install codspeed-go dependency: {}", stderr);
4646
}
4747

48-
info!("Successfully installed codspeed-go dependency");
48+
debug!("Successfully installed codspeed-go dependency");
4949

5050
Ok(())
5151
}

go-runner/src/builder/runner.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use crate::prelude::*;
2-
use std::{
3-
path::{Path, PathBuf},
4-
process::Command,
5-
};
2+
use std::{path::Path, process::Command};
63

7-
pub fn build<P: AsRef<Path>>(runner_go_path: P) -> anyhow::Result<PathBuf> {
4+
pub fn run<P: AsRef<Path>>(runner_go_path: P, run_args: &[&str]) -> anyhow::Result<()> {
85
// Extract the directory containing runner.go to use as working directory
96
let runner_go_path = runner_go_path.as_ref();
107
let file_dir = runner_go_path.parent().unwrap();
@@ -16,24 +13,27 @@ pub fn build<P: AsRef<Path>>(runner_go_path: P) -> anyhow::Result<PathBuf> {
1613
module_root
1714
);
1815

19-
// Run go build -tags=codspeed <path>
16+
// Run go run -tags=codspeed <path> {args}
2017
let output = Command::new("go")
21-
.arg("build")
18+
.arg("run")
2219
.arg("-tags=codspeed")
2320
.arg(relative_path)
21+
.args(run_args)
2422
.current_dir(module_root)
23+
.stdout(std::process::Stdio::inherit())
24+
.stderr(std::process::Stdio::inherit())
2525
.output()
2626
.context("Failed to execute go build command")?;
2727

2828
if !output.status.success() {
29+
let stdout = String::from_utf8_lossy(&output.stdout);
2930
let stderr = String::from_utf8_lossy(&output.stderr);
30-
bail!("Go build failed: {}", stderr);
31-
}
3231

33-
let runner_executable = module_root.join("runner");
34-
if !runner_executable.exists() {
35-
bail!("Runner executable not found at {:?}", runner_executable);
32+
warn!("Command output: {stdout}");
33+
warn!("Command error output: {stderr}");
34+
35+
bail!("Failed to run benchmark. Exit status: {}", output.status);
3636
}
3737

38-
Ok(runner_executable)
38+
Ok(())
3939
}

go-runner/src/builder/template.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"io"
65
"time"
76
"reflect"
@@ -77,10 +76,6 @@ func main() {
7776
{{/each}}
7877
}
7978

80-
for i := 0; i < len(benchmarks); i++ {
81-
fmt.Printf("Benchmark %d: %s\n", i, benchmarks[i].Name)
82-
}
83-
8479
m := codspeed_testing.MainStart(simpleDeps{}, tests, benchmarks, fuzzTargets, examples)
8580
m.Run()
8681
}

go-runner/src/lib.rs

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ mod integration_tests;
1515

1616
/// Builds and runs the specified Go project benchmarks, writing results to the .codspeed folder.
1717
pub fn run_benchmarks(project_dir: &Path, bench: &str) -> anyhow::Result<()> {
18-
let binary_dir = project_dir.join(".codspeed").join("walltime");
18+
let profile_dir = std::env::var("CODSPEED_PROFILE_FOLDER")
19+
.context("CODSPEED_PROFILE_FOLDER env var not set")?;
20+
std::fs::remove_dir_all(&profile_dir).ok();
1921

2022
// 1. Build phase - Benchmark and package discovery
2123
let packages = BenchmarkPackage::from_project(project_dir)?;
@@ -30,58 +32,32 @@ pub fn run_benchmarks(project_dir: &Path, bench: &str) -> anyhow::Result<()> {
3032

3133
let total_benchmarks: usize = packages.iter().map(|p| p.benchmarks.len()).sum();
3234
info!("Total benchmarks discovered: {total_benchmarks}");
35+
for (name, path) in &bench_name_to_path {
36+
info!("Found {name:30} in {path:?}");
37+
}
3338

34-
debug!("Creating binary directory: {binary_dir:?}");
35-
std::fs::create_dir_all(&binary_dir)?;
36-
37-
// 2. Generate codspeed runners and build binaries
38-
let mut binaries = Vec::new();
39+
// 2. Generate codspeed runners and execute them
3940
for package in &packages {
40-
info!("Processing package: {}", package.name);
41+
info!("Generating custom runner for package: {}", package.name);
4142
let (_target_dir, runner_path) = builder::templater::run(package)?;
4243

43-
info!("Building benchmarks for: {runner_path:?}");
44-
let binary_path = builder::runner::build(&runner_path)?;
45-
46-
// Create a unique filename to avoid accidentally overwriting existing benchmarks.
47-
let filename = binary_path.file_name().unwrap().to_string_lossy();
48-
let unique_filename: String = format!("{}_{:08x}", filename, rand::random::<u32>());
49-
let target_path = binary_dir.join(unique_filename);
50-
51-
debug!("Copying {binary_path:?} to {target_path:?}");
52-
std::fs::copy(binary_path, &target_path)?;
53-
binaries.push(target_path);
54-
}
55-
56-
// 3. Run phase - Execute the built benchmarks
57-
for bench_path in &binaries {
58-
info!("Running: {bench_path:?}");
59-
60-
// Use a single iteration in tests to speed up execution, otherwise use 5 seconds
61-
let benchtime = if cfg!(test) { "1x" } else { "5s" };
62-
63-
let cmd = std::process::Command::new(bench_path)
64-
.arg(format!("-test.bench={bench}"))
65-
.arg(format!("-test.benchtime={benchtime}"))
66-
.output()
67-
.context("Failed to execute benchmark command")?;
68-
69-
// Check if the command was successful
70-
if !cmd.status.success() {
71-
let stdout = String::from_utf8_lossy(&cmd.stdout);
72-
let stderr = String::from_utf8_lossy(&cmd.stderr);
73-
74-
warn!("Command output: {stdout}");
75-
warn!("Command error output: {stderr}");
76-
77-
bail!(
78-
"Failed to run benchmark: {bench_path:?}. Exit status: {}",
79-
cmd.status
80-
);
81-
}
44+
let args = [
45+
"-test.bench",
46+
bench,
47+
// Use a single iteration in tests to speed up execution, otherwise use 5 seconds
48+
"-test.benchtime",
49+
if cfg!(test) || std::env::var("CODSPEED_ENV").is_err() {
50+
"1x"
51+
} else {
52+
"5s"
53+
},
54+
];
55+
56+
info!("Running benchmarks for package: {}", package.name);
57+
builder::runner::run(&runner_path, &args)?;
8258
}
8359

84-
// 4. Collect the results
60+
// 3. Collect the results
8561
collect_walltime_results(bench_name_to_path)?;
8662

8763
Ok(())

go-runner/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fn main() -> anyhow::Result<()> {
55
env_logger::builder()
66
.parse_env("CODSPEED_LOG")
77
.filter_module("handlebars", log::LevelFilter::Off)
8+
.format_timestamp(None)
89
.init();
910

1011
let cli = Cli::parse();

0 commit comments

Comments
 (0)