Skip to content

Commit c5f02fb

Browse files
committed
feat: process raw results while running benchmarks
1 parent 1b0a31f commit c5f02fb

2 files changed

Lines changed: 34 additions & 22 deletions

File tree

go-runner/src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn run_benchmarks<P: AsRef<Path>>(
3939

4040
// 2. Generate codspeed runners, build binaries, and execute them
4141
let templater = Templater::new();
42+
let mut threads = Vec::with_capacity(packages.len());
4243
for package in &packages {
4344
info!("Generating custom runner for package: {}", package.name);
4445
let ctx = templater.run(package, &profile_dir)?;
@@ -65,15 +66,23 @@ pub fn run_benchmarks<P: AsRef<Path>>(
6566
error!("Failed to run benchmarks for {}: {error}", package.name);
6667
continue;
6768
}
69+
70+
// Collect the results in a new thread, to avoid blocking the main thread at the end. The
71+
// conversions and computations can take a while when we have a lot of iterations.
72+
let profile_dir = profile_dir.as_ref().to_path_buf();
73+
threads.push(std::thread::spawn(move || {
74+
collect_walltime_results(profile_dir.as_ref()).unwrap();
75+
}));
6876
} else {
6977
info!("Skipping benchmark execution (dry-run mode)");
7078
}
7179
}
7280

73-
// 3. Collect the results
74-
if !cli.dry_run {
75-
collect_walltime_results(profile_dir.as_ref())?;
76-
}
81+
// Wait for all result collection threads to finish
82+
threads.into_iter().for_each(|t| {
83+
t.join()
84+
.expect("Failed to join collect_walltime_results thread")
85+
});
7786

7887
Ok(())
7988
}
@@ -90,11 +99,6 @@ pub fn collect_walltime_results(profile_dir: &Path) -> anyhow::Result<()> {
9099
.push(walltime_result);
91100
}
92101

93-
// Remove raw results directory after processing to save space
94-
if raw_results_dir.exists() {
95-
std::fs::remove_dir_all(&raw_results_dir)?;
96-
}
97-
98102
for (pid, walltime_benchmarks) in benchmarks_by_pid {
99103
let creator = results::walltime_results::Creator {
100104
name: "codspeed-go".into(),

go-runner/src/results/raw_result.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,27 @@ impl RawResult {
2323
.par_bridge()
2424
.filter_map(Result::ok)
2525
.filter_map(|path| {
26-
let file = std::fs::File::open(&path).ok()?;
27-
let reader = std::io::BufReader::new(file);
28-
let json: Self = serde_json::from_reader(reader).ok()?;
29-
Some((
30-
json.pid,
31-
WalltimeBenchmark::from_runtime_data(
32-
json.name,
33-
json.uri,
34-
&json.codspeed_iters_per_round,
35-
&json.codspeed_time_per_round_ns,
36-
None,
37-
),
38-
))
26+
let (pid, bench) = {
27+
let file = std::fs::File::open(&path).ok()?;
28+
let reader = std::io::BufReader::new(file);
29+
let json: Self = serde_json::from_reader(reader).ok()?;
30+
31+
(
32+
json.pid,
33+
WalltimeBenchmark::from_runtime_data(
34+
json.name,
35+
json.uri,
36+
&json.codspeed_iters_per_round,
37+
&json.codspeed_time_per_round_ns,
38+
None,
39+
),
40+
)
41+
};
42+
43+
// Remove the file since we processed it
44+
std::fs::remove_file(path).ok();
45+
46+
Some((pid, bench))
3947
})
4048
.collect();
4149
Ok(result)

0 commit comments

Comments
 (0)