Skip to content
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
14 changes: 14 additions & 0 deletions src/run/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use crate::run::instruments::Instruments;
use std::path::PathBuf;
use url::Url;

use crate::run::run_environment::RepositoryProvider;
Expand All @@ -18,7 +19,9 @@ pub struct Config {
pub mode: RunnerMode,
pub instruments: Instruments,

pub profile_folder: Option<PathBuf>,
pub skip_upload: bool,
pub skip_run: bool,
pub skip_setup: bool,
}

Expand Down Expand Up @@ -47,7 +50,9 @@ impl Config {
command: "".into(),
mode: RunnerMode::Instrumentation,
instruments: Instruments::test(),
profile_folder: None,
skip_upload: false,
skip_run: false,
skip_setup: false,
}
}
Expand Down Expand Up @@ -82,7 +87,9 @@ impl TryFrom<RunArgs> for Config {
mode: args.mode,
instruments,
command: args.command.join(" "),
profile_folder: args.profile_folder,
skip_upload: args.skip_upload,
skip_run: args.skip_run,
skip_setup: args.skip_setup,
})
}
Expand Down Expand Up @@ -113,7 +120,9 @@ mod tests {
instruments: vec![],
mongo_uri_env_name: None,
message_format: None,
profile_folder: None,
skip_upload: false,
skip_run: false,
skip_setup: false,
command: vec!["cargo".into(), "codspeed".into(), "bench".into()],
})
Expand All @@ -124,6 +133,7 @@ mod tests {
assert_eq!(config.working_directory, None);
assert_eq!(config.instruments, Instruments { mongodb: None });
assert!(!config.skip_upload);
assert!(!config.skip_run);
assert!(!config.skip_setup);
assert_eq!(config.command, "cargo codspeed bench");
}
Expand All @@ -140,7 +150,9 @@ mod tests {
instruments: vec!["mongodb".into()],
mongo_uri_env_name: Some("MONGODB_URI".into()),
message_format: Some(crate::run::MessageFormat::Json),
profile_folder: Some("./codspeed.out".into()),
skip_upload: true,
skip_run: true,
skip_setup: true,
command: vec!["cargo".into(), "codspeed".into(), "bench".into()],
})
Expand Down Expand Up @@ -168,7 +180,9 @@ mod tests {
})
}
);
assert_eq!(config.profile_folder, Some("./codspeed.out".into()));
assert!(config.skip_upload);
assert!(config.skip_run);
assert!(config.skip_setup);
assert_eq!(config.command, "cargo codspeed bench");
}
Expand Down
58 changes: 37 additions & 21 deletions src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use instruments::mongo_tracer::{install_mongodb_tracer, MongoTracer};
use run_environment::interfaces::{RepositoryProvider, RunEnvironment};
use runner::get_run_data;
use serde::Serialize;
use std::path::PathBuf;

pub mod check_system;
pub mod helpers;
Expand Down Expand Up @@ -79,6 +80,10 @@ pub struct RunArgs {
#[arg(long)]
pub mongo_uri_env_name: Option<String>,

/// Profile folder to use for the run.
#[arg(long)]
pub profile_folder: Option<PathBuf>,

#[arg(long, hide = true)]
pub message_format: Option<MessageFormat>,

Expand All @@ -90,6 +95,10 @@ pub struct RunArgs {
env = "CODSPEED_SKIP_UPLOAD"
)]
pub skip_upload: bool,
/// Used internally to upload the results after running the benchmarks in a sandbox environment
/// with no internet access
#[arg(long, default_value = "false", hide = true)]
pub skip_run: bool,

/// Only for debugging purposes, skips the setup of the runner
#[arg(long, default_value = "false", hide = true)]
Expand Down Expand Up @@ -126,7 +135,9 @@ impl RunArgs {
instruments: vec![],
mongo_uri_env_name: None,
message_format: None,
profile_folder: None,
skip_upload: false,
skip_run: false,
skip_setup: false,
command: vec![],
}
Expand Down Expand Up @@ -172,35 +183,40 @@ pub async fn run(
end_group!();
}

let run_data = get_run_data()?;
let run_data = get_run_data(&config)?;

start_opened_group!("Running the benchmarks");

// TODO: refactor and move directly in the Instruments struct as a `start` method
let mongo_tracer = if let Some(mongodb_config) = &config.instruments.mongodb {
let mut mongo_tracer = MongoTracer::try_from(&run_data.profile_folder, mongodb_config)?;
mongo_tracer.start().await?;
Some(mongo_tracer)
} else {
None
};
if !config.skip_run {
start_opened_group!("Running the benchmarks");

executor
.run(&config, &system_info, &run_data, &mongo_tracer)
.await?;
// TODO: refactor and move directly in the Instruments struct as a `start` method
let mongo_tracer = if let Some(mongodb_config) = &config.instruments.mongodb {
let mut mongo_tracer = MongoTracer::try_from(&run_data.profile_folder, mongodb_config)?;
mongo_tracer.start().await?;
Some(mongo_tracer)
} else {
None
};

// TODO: refactor and move directly in the Instruments struct as a `stop` method
if let Some(mut mongo_tracer) = mongo_tracer {
mongo_tracer.stop().await?;
}
executor
.run(&config, &system_info, &run_data, &mongo_tracer)
.await?;

executor.teardown(&config, &system_info, &run_data).await?;
// TODO: refactor and move directly in the Instruments struct as a `stop` method
if let Some(mut mongo_tracer) = mongo_tracer {
mongo_tracer.stop().await?;
}
executor.teardown(&config, &system_info, &run_data).await?;

end_group!();
end_group!();
} else {
debug!("Skipping the run of the benchmarks");
};

if !config.skip_upload {
start_group!("Uploading performance data");
logger.persist_log_to_profile_folder(&run_data)?;
if !config.skip_run {
logger.persist_log_to_profile_folder(&run_data)?;
}
let upload_result =
uploader::upload(&config, &system_info, &provider, &run_data, executor.name()).await?;
end_group!();
Expand Down
10 changes: 7 additions & 3 deletions src/run/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use crate::prelude::*;

use super::RunnerMode;
use super::{config::Config, RunnerMode};

mod executor;
mod helpers;
Expand Down Expand Up @@ -41,7 +41,11 @@ pub fn get_all_executors() -> Vec<Box<dyn Executor>> {
]
}

pub fn get_run_data() -> Result<RunData> {
let profile_folder = create_profile_folder()?;
pub fn get_run_data(config: &Config) -> Result<RunData> {
let profile_folder = if let Some(profile_folder) = &config.profile_folder {
profile_folder.clone()
} else {
create_profile_folder()?
};
Ok(RunData { profile_folder })
}