Skip to content
Open
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CI tests against Go 1.24.x, 1.25.x, 1.26.x and 1.27.x. Go 1.24 tests require `GO

Rust workspace with a single crate: `go-runner/` (`codspeed-go-runner`), edition 2024, toolchain 1.90.0.

**Flow:** `main.rs` parses CLI args → `runner::run()` generates overlay + runs `go test` → Go benchmarks write raw JSON results to `$CODSPEED_PROFILE_FOLDER/raw_results/` → `collect_walltime_results()` aggregates into `results/{pid}.json`.
**Flow:** `main.rs` parses CLI args → `runner::run()` generates overlay + runs `go test` → Go benchmarks write raw JSON results to `$CODSPEED_PROFILE_FOLDER/raw_results/` → `collect_walltime_results()` aggregates into `results/{pid}.json` and writes the rounds to `walltime_rounds/{pid}.json.gz`.

**Overlay mechanism:** Three files are overlaid into `$GOROOT/src/testing/`:
- `benchmark.go` — replaces the standard `testing.B` implementation (version-specific: 1.24, 1.25 or 1.26+)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env_logger = "0.11"
glob = "0.3"
log = "0.4"
regex = "1.11"
getrandom = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
statrs = { version = "0.18", default-features = false }
Expand Down
59 changes: 57 additions & 2 deletions go-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use crate::{
prelude::*,
results::{raw_result::RawResult, walltime_results::WalltimeBenchmark},
};
use std::{collections::HashMap, path::Path};
use flate2::{Compression, write::GzEncoder};
use std::{
collections::HashMap,
io::{BufWriter, IntoInnerError},
path::Path,
};

pub mod cli;
pub mod prelude;
Expand Down Expand Up @@ -53,11 +58,61 @@ pub fn collect_walltime_results(profile_dir: &Path) -> anyhow::Result<()> {
std::fs::create_dir_all(&results_dir)?;

let results_file = results_dir.join(format!("{pid}.json"));
let walltime_results =
let mut walltime_results =
results::walltime_results::WalltimeResults::new(walltime_benchmarks, creator)?;
std::fs::write(&results_file, serde_json::to_string(&walltime_results)?)?;
info!("Results written to {results_file:?}");

let rounds_dir = profile_dir.join("walltime_rounds");
std::fs::create_dir_all(&rounds_dir)?;
let rounds_file = std::fs::File::create(rounds_dir.join(format!("{pid}.json.gz")))?;
let mut rounds_writer = BufWriter::new(GzEncoder::new(rounds_file, Compression::fast()));
serde_json::to_writer(&mut rounds_writer, &walltime_results.take_walltime_rounds())?;
rounds_writer
.into_inner()
.map_err(IntoInnerError::into_error)?
.finish()?;
Comment thread
fargito marked this conversation as resolved.
Resolved
}

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use flate2::read::GzDecoder;

#[test]
fn test_collect_walltime_results_writes_gzipped_rounds() {
let profile_dir = tempfile::TempDir::new().unwrap();
let raw_results_dir = profile_dir.path().join("raw_results");
std::fs::create_dir_all(&raw_results_dir).unwrap();
std::fs::write(
raw_results_dir.join("bench.json"),
serde_json::json!({
"name": "BenchmarkFoo",
"uri": "pkg/foo_test.go::BenchmarkFoo",
"pid": 42,
"codspeed_time_per_round_ns": [3000, 1000, 2000],
"codspeed_iters_per_round": [3, 1, 2],
})
.to_string(),
)
.unwrap();

collect_walltime_results(profile_dir.path()).unwrap();

let rounds_file =
std::fs::File::open(profile_dir.path().join("walltime_rounds/42.json.gz")).unwrap();
let rounds: serde_json::Value =
serde_json::from_reader(GzDecoder::new(rounds_file)).unwrap();
assert_eq!(
rounds,
serde_json::json!({"benchmarks": [{
"uri": "pkg/foo_test.go::BenchmarkFoo",
"times_per_round_ns": [3000, 1000, 2000],
"iters_per_round": [3, 1, 2],
}]})
);
}
}
4 changes: 2 additions & 2 deletions go-runner/src/results/raw_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl RawResult {
WalltimeBenchmark::from_runtime_data(
json.name,
json.uri,
&json.codspeed_iters_per_round,
&json.codspeed_time_per_round_ns,
json.codspeed_iters_per_round,
json.codspeed_time_per_round_ns,
None,
),
)
Expand Down
Loading
Loading