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
49 changes: 49 additions & 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 crates/cargo-codspeed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ itertools = { workspace = true }
anstyle = "1.0.8"
serde = { workspace = true }
serde_json = { workspace = true }
flate2 = "1.1"
toml = "0.8"
codspeed = { path = "../codspeed", version = "=6.0.0" }

Expand Down
37 changes: 26 additions & 11 deletions crates/cargo-codspeed/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use crate::{
use anyhow::Context;
use cargo_metadata::{Metadata, Package};
use codspeed::walltime_results::WalltimeResults;
use flate2::{write::GzEncoder, Compression};
use std::{
io::{self, Write},
io,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -172,7 +173,7 @@ pub fn run_benches(
}

fn aggregate_raw_walltime_data(workspace_root: &Path) -> Result<()> {
let results = WalltimeResults::collect_walltime_results(workspace_root)
let mut results = WalltimeResults::collect_walltime_results(workspace_root)
.with_context(|| {
format!(
"Failed to collect walltime results. This may be due to version incompatibility. \
Expand All @@ -196,18 +197,32 @@ fn aggregate_raw_walltime_data(workspace_root: &Path) -> Result<()> {
}
}

let results_folder = std::env::var("CODSPEED_PROFILE_FOLDER")
let profile_folder = std::env::var("CODSPEED_PROFILE_FOLDER")
.map(PathBuf::from)
.unwrap_or_else(|_| workspace_root.join("target/codspeed/profiles"))
.join("results");
.unwrap_or_else(|_| workspace_root.join("target/codspeed/profiles"));
let results_folder = profile_folder.join("results");
std::fs::create_dir_all(&results_folder).context("Failed to create results folder")?;

let walltime_rounds = results.take_walltime_rounds();
let results_path = results_folder.join(format!("{}.json", std::process::id()));
let mut results_file =
std::fs::File::create(&results_path).context("Failed to create results file")?;
serde_json::to_writer_pretty(&results_file, &results)?;
results_file
.flush()
.context("Failed to flush results file")?;
std::fs::write(&results_path, serde_json::to_vec_pretty(&results)?)
.context("Failed to write results file")?;

if let Some(walltime_rounds) = walltime_rounds {
let rounds_folder = profile_folder.join("walltime_rounds");
std::fs::create_dir_all(&rounds_folder).context("Failed to create rounds folder")?;
let rounds_file =
std::fs::File::create(rounds_folder.join(format!("{}.json.gz", std::process::id())))
.context("Failed to create rounds file")?;
let mut rounds_writer =
io::BufWriter::new(GzEncoder::new(rounds_file, Compression::fast()));
serde_json::to_writer(&mut rounds_writer, &walltime_rounds)
Comment thread
fargito marked this conversation as resolved.
Resolved
.context("Failed to write rounds file")?;
rounds_writer
.into_inner()
.map_err(io::IntoInnerError::into_error)
.and_then(GzEncoder::finish)
.context("Failed to finish rounds file")?;
}
Ok(())
}
Loading
Loading