Skip to content

Commit 6579610

Browse files
feat: make codspeed target path different depending on measurement mode
1 parent 99e839d commit 6579610

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

crates/cargo-codspeed/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub fn build_benches(
174174
);
175175
}
176176

177-
let codspeed_target_dir = get_codspeed_target_dir(metadata);
177+
let codspeed_target_dir = get_codspeed_target_dir(metadata, measurement_mode);
178178
let built_bench_count = built_benches.len();
179179

180180
// Create and clear packages codspeed target directories

crates/cargo-codspeed/src/helpers.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
use crate::prelude::*;
1+
use crate::{measurement_mode::MeasurementMode, prelude::*};
22
use cargo_metadata::Metadata;
33
use std::path::{Path, PathBuf};
44

5-
pub fn get_codspeed_target_dir(metadata: &Metadata) -> PathBuf {
6-
metadata.target_directory.join("codspeed").into()
5+
pub fn get_codspeed_target_dir(metadata: &Metadata, measurement_mode: MeasurementMode) -> PathBuf {
6+
metadata
7+
.target_directory
8+
.join("codspeed")
9+
.join(measurement_mode.to_string())
10+
.into()
711
}
812

913
pub fn clear_dir<P>(dir: P) -> Result<()>

crates/cargo-codspeed/src/measurement_mode.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::ValueEnum;
22
use serde::Serialize;
3-
use std::env;
3+
use std::{env, path::Path};
44

55
#[derive(Debug, Clone, ValueEnum, Serialize, PartialEq, Eq)]
66
#[serde(rename_all = "lowercase")]
@@ -18,3 +18,16 @@ impl Default for MeasurementMode {
1818
}
1919
}
2020
}
21+
22+
impl fmt::Display for MeasurementMode {
23+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24+
write!(
25+
f,
26+
"{}",
27+
match self {
28+
MeasurementMode::Instrumentation => "instrumentation",
29+
MeasurementMode::Walltime => "walltime",
30+
}
31+
)
32+
}
33+
}

crates/cargo-codspeed/src/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn run_benches(
9999
filters: Filters,
100100
measurement_mode: MeasurementMode,
101101
) -> Result<()> {
102-
let codspeed_target_dir = get_codspeed_target_dir(metadata);
102+
let codspeed_target_dir = get_codspeed_target_dir(metadata, measurement_mode);
103103
let workspace_root = metadata.workspace_root.as_std_path();
104104
if measurement_mode == MeasurementMode::Walltime {
105105
clear_raw_walltime_data(workspace_root)?;

crates/codspeed/src/walltime.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub fn collect_raw_walltime_results(
6565
data.dump_to_results(&workspace_root, scope);
6666
}
6767

68+
// FIXME: This assumes that the cargo target dir is `target`, and duplicates information with
69+
// `cargo-codspeed::helpers::get_codspeed_target_dir`
6870
pub fn get_raw_result_dir_from_workspace_root(workspace_root: &Path) -> PathBuf {
6971
workspace_root
7072
.join("target")

0 commit comments

Comments
 (0)