Skip to content

Make cargo-codspeed build targets to different directories between walltime and instrumented #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
24 changes: 12 additions & 12 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions crates/cargo-codspeed/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ struct Cli {

/// The measurement tool to use for measuring performance.
/// Automatically set to `walltime` on macro runners
// This is an Option even if MeasurementMode has a default because
// the default is dynamic and this would mislead the user
#[arg(short, long, global = true, env = "CODSPEED_RUNNER_MODE")]
measurement_mode: Option<MeasurementMode>,

Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-codspeed/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn build_benches(
);
}

let codspeed_target_dir = get_codspeed_target_dir(metadata);
let codspeed_target_dir = get_codspeed_target_dir(metadata, measurement_mode);
let built_bench_count = built_benches.len();

// Create and clear packages codspeed target directories
Expand Down
10 changes: 7 additions & 3 deletions crates/cargo-codspeed/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::prelude::*;
use crate::{measurement_mode::MeasurementMode, prelude::*};
use cargo_metadata::Metadata;
use std::path::{Path, PathBuf};

pub fn get_codspeed_target_dir(metadata: &Metadata) -> PathBuf {
metadata.target_directory.join("codspeed").into()
pub fn get_codspeed_target_dir(metadata: &Metadata, measurement_mode: MeasurementMode) -> PathBuf {
metadata
.target_directory
.join("codspeed")
.join(measurement_mode.to_string())
.into()
}

pub fn clear_dir<P>(dir: P) -> Result<()>
Expand Down
24 changes: 14 additions & 10 deletions crates/cargo-codspeed/src/measurement_mode.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use clap::ValueEnum;
use serde::Serialize;
use std::env;
use std::fmt;

#[derive(Debug, Clone, ValueEnum, Serialize, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, ValueEnum, Serialize, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum MeasurementMode {
Walltime,
#[default]
Instrumentation,
Walltime,
}

impl Default for MeasurementMode {
fn default() -> Self {
if env::var("CODSPEED_ENV").is_ok() {
MeasurementMode::Instrumentation
} else {
MeasurementMode::Walltime
}
impl fmt::Display for MeasurementMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
MeasurementMode::Instrumentation => "instrumentation",
MeasurementMode::Walltime => "walltime",
}
)
}
}
2 changes: 1 addition & 1 deletion crates/cargo-codspeed/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn run_benches(
filters: Filters,
measurement_mode: MeasurementMode,
) -> Result<()> {
let codspeed_target_dir = get_codspeed_target_dir(metadata);
let codspeed_target_dir = get_codspeed_target_dir(metadata, measurement_mode);
let workspace_root = metadata.workspace_root.as_std_path();
if measurement_mode == MeasurementMode::Walltime {
clear_raw_walltime_data(workspace_root)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/codspeed/src/walltime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub fn collect_raw_walltime_results(
data.dump_to_results(&workspace_root, scope);
}

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