Skip to content

Commit 6dd5c9c

Browse files
refactor: create a module for shared structs between exec and run
1 parent bbe2df7 commit 6dd5c9c

7 files changed

Lines changed: 140 additions & 128 deletions

File tree

src/cli/exec/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use super::ExecAndRunSharedArgs;
12
use crate::api_client::CodSpeedAPIClient;
23
use crate::binary_installer::ensure_binary_installed;
3-
use crate::cli::run::show_banner;
44
use crate::config::CodSpeedConfig;
55
use crate::executor;
66
use crate::prelude::*;
@@ -37,7 +37,7 @@ pub fn wrap_with_exec_harness(
3737
#[derive(Args, Debug)]
3838
pub struct ExecArgs {
3939
#[command(flatten)]
40-
pub shared: crate::cli::run::ExecAndRunSharedArgs,
40+
pub shared: ExecAndRunSharedArgs,
4141

4242
#[command(flatten)]
4343
pub walltime_args: exec_harness::walltime::WalltimeExecutionArgs,
@@ -99,7 +99,7 @@ pub async fn execute_with_harness(
9999
let mut execution_context = executor::ExecutionContext::try_from((config, codspeed_config))?;
100100

101101
if execution_context.is_local() {
102-
show_banner();
102+
super::show_banner();
103103
}
104104

105105
debug!("config: {:#?}", execution_context.config);

src/cli/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ mod auth;
22
pub(crate) mod exec;
33
pub(crate) mod run;
44
mod setup;
5+
mod shared;
6+
7+
pub(crate) use shared::*;
58

69
use std::path::PathBuf;
710

src/cli/run/mod.rs

Lines changed: 5 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::VERSION;
1+
use super::ExecAndRunSharedArgs;
22
use crate::api_client::CodSpeedAPIClient;
33
use crate::config::CodSpeedConfig;
44
use crate::executor;
@@ -7,129 +7,14 @@ use crate::prelude::*;
77
use crate::project_config::ProjectConfig;
88
use crate::project_config::merger::ConfigMerger;
99
use crate::run_environment::interfaces::RepositoryProvider;
10-
use crate::runner_mode::RunnerMode;
1110
use crate::upload::UploadResult;
1211
use clap::{Args, ValueEnum};
1312
use std::path::Path;
14-
use std::path::PathBuf;
1513

1614
pub mod helpers;
1715
pub mod logger;
1816
mod poll_results;
1917

20-
pub(crate) fn show_banner() {
21-
let banner = format!(
22-
r#"
23-
______ __ _____ __
24-
/ ____/____ ____/ // ___/ ____ ___ ___ ____/ /
25-
/ / / __ \ / __ / \__ \ / __ \ / _ \ / _ \ / __ /
26-
/ /___ / /_/ // /_/ / ___/ // /_/ // __// __// /_/ /
27-
\____/ \____/ \__,_/ /____// .___/ \___/ \___/ \__,_/
28-
https://codspeed.io /_/ runner v{VERSION}
29-
"#
30-
);
31-
println!("{banner}");
32-
debug!("codspeed v{VERSION}");
33-
}
34-
35-
#[derive(Debug, Copy, Clone, PartialEq, ValueEnum, Default)]
36-
pub enum UnwindingMode {
37-
/// Use the frame pointer for unwinding. Requires the binary to be compiled with frame pointers enabled.
38-
#[clap(name = "fp")]
39-
FramePointer,
40-
41-
/// Use DWARF unwinding. This does not require any special compilation flags and is enabled by default.
42-
#[default]
43-
Dwarf,
44-
}
45-
46-
#[derive(Args, Debug, Clone)]
47-
pub struct PerfRunArgs {
48-
/// Enable the linux perf profiler to collect granular performance data.
49-
/// This is only supported on Linux.
50-
#[arg(long, env = "CODSPEED_PERF_ENABLED", default_value_t = true)]
51-
pub enable_perf: bool,
52-
53-
/// The unwinding mode that should be used with perf to collect the call stack.
54-
#[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE")]
55-
pub perf_unwinding_mode: Option<UnwindingMode>,
56-
}
57-
58-
/// Arguments shared between run and exec commands
59-
#[derive(Args, Debug, Clone)]
60-
pub struct ExecAndRunSharedArgs {
61-
/// The upload URL to use for uploading the results, useful for on-premises installations
62-
#[arg(long, env = "CODSPEED_UPLOAD_URL")]
63-
pub upload_url: Option<String>,
64-
65-
/// The token to use for uploading the results,
66-
///
67-
/// It can be either a CodSpeed token retrieved from the repository setting
68-
/// or an OIDC token issued by the identity provider.
69-
#[arg(long, env = "CODSPEED_TOKEN")]
70-
pub token: Option<String>,
71-
72-
/// The repository the benchmark is associated with, under the format `owner/repo`.
73-
#[arg(short, long, env = "CODSPEED_REPOSITORY")]
74-
pub repository: Option<String>,
75-
76-
/// The repository provider to use in case --repository is used. Defaults to github
77-
#[arg(
78-
long,
79-
env = "CODSPEED_PROVIDER",
80-
requires = "repository",
81-
ignore_case = true
82-
)]
83-
pub provider: Option<RepositoryProvider>,
84-
85-
/// The directory where the command will be executed.
86-
#[arg(long)]
87-
pub working_directory: Option<String>,
88-
89-
/// The mode to run the benchmarks in.
90-
#[arg(short, long, value_enum, env = "CODSPEED_RUNNER_MODE")]
91-
pub mode: RunnerMode,
92-
93-
/// Profile folder to use for the run.
94-
#[arg(long)]
95-
pub profile_folder: Option<PathBuf>,
96-
97-
/// Only for debugging purposes, skips the upload of the results
98-
#[arg(
99-
long,
100-
default_value = "false",
101-
hide = true,
102-
env = "CODSPEED_SKIP_UPLOAD"
103-
)]
104-
pub skip_upload: bool,
105-
106-
/// Used internally to upload the results after running the benchmarks in a sandbox environment
107-
/// with no internet access
108-
#[arg(long, default_value = "false", hide = true)]
109-
pub skip_run: bool,
110-
111-
/// Only for debugging purposes, skips the setup of the runner
112-
#[arg(long, default_value = "false", hide = true)]
113-
pub skip_setup: bool,
114-
115-
/// Allow runs without any benchmarks to succeed instead of failing
116-
#[arg(long, default_value = "false", hide = true)]
117-
pub allow_empty: bool,
118-
119-
/// The version of the go-runner to use (e.g., 1.2.3, 1.0.0-beta.1)
120-
/// If not specified, the latest version will be installed
121-
#[arg(long, env = "CODSPEED_GO_RUNNER_VERSION", value_parser = parse_version)]
122-
pub go_runner_version: Option<semver::Version>,
123-
124-
#[command(flatten)]
125-
pub perf_run_args: PerfRunArgs,
126-
}
127-
128-
/// Parser for go-runner version that validates semver format
129-
fn parse_version(s: &str) -> Result<semver::Version, String> {
130-
semver::Version::parse(s).map_err(|e| format!("Invalid semantic version: {e}"))
131-
}
132-
13318
#[derive(Args, Debug)]
13419
pub struct RunArgs {
13520
#[command(flatten)]
@@ -175,6 +60,9 @@ pub enum MessageFormat {
17560
impl RunArgs {
17661
/// Constructs a new `RunArgs` with default values for testing purposes
17762
pub fn test() -> Self {
63+
use super::PerfRunArgs;
64+
use crate::RunnerMode;
65+
17866
Self {
17967
shared: ExecAndRunSharedArgs {
18068
upload_url: None,
@@ -259,7 +147,7 @@ pub async fn run(
259147
executor::ExecutionContext::try_from((config, codspeed_config))?;
260148

261149
if !execution_context.is_local() {
262-
show_banner();
150+
super::show_banner();
263151
}
264152
debug!("config: {:#?}", execution_context.config);
265153

src/cli/shared.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
use crate::VERSION;
2+
use crate::prelude::*;
3+
use crate::run_environment::interfaces::RepositoryProvider;
4+
use crate::runner_mode::RunnerMode;
5+
use clap::Args;
6+
use clap::ValueEnum;
7+
use std::path::PathBuf;
8+
9+
pub(crate) fn show_banner() {
10+
let banner = format!(
11+
r#"
12+
______ __ _____ __
13+
/ ____/____ ____/ // ___/ ____ ___ ___ ____/ /
14+
/ / / __ \ / __ / \__ \ / __ \ / _ \ / _ \ / __ /
15+
/ /___ / /_/ // /_/ / ___/ // /_/ // __// __// /_/ /
16+
\____/ \____/ \__,_/ /____// .___/ \___/ \___/ \__,_/
17+
https://codspeed.io /_/ runner v{VERSION}
18+
"#
19+
);
20+
println!("{banner}");
21+
debug!("codspeed v{VERSION}");
22+
}
23+
24+
/// Arguments shared between run and exec commands
25+
#[derive(Args, Debug, Clone)]
26+
pub struct ExecAndRunSharedArgs {
27+
/// The upload URL to use for uploading the results, useful for on-premises installations
28+
#[arg(long, env = "CODSPEED_UPLOAD_URL")]
29+
pub upload_url: Option<String>,
30+
31+
/// The token to use for uploading the results,
32+
///
33+
/// It can be either a CodSpeed token retrieved from the repository setting
34+
/// or an OIDC token issued by the identity provider.
35+
#[arg(long, env = "CODSPEED_TOKEN")]
36+
pub token: Option<String>,
37+
38+
/// The repository the benchmark is associated with, under the format `owner/repo`.
39+
#[arg(short, long, env = "CODSPEED_REPOSITORY")]
40+
pub repository: Option<String>,
41+
42+
/// The repository provider to use in case --repository is used. Defaults to github
43+
#[arg(
44+
long,
45+
env = "CODSPEED_PROVIDER",
46+
requires = "repository",
47+
ignore_case = true
48+
)]
49+
pub provider: Option<RepositoryProvider>,
50+
51+
/// The directory where the command will be executed.
52+
#[arg(long)]
53+
pub working_directory: Option<String>,
54+
55+
/// The mode to run the benchmarks in.
56+
#[arg(short, long, value_enum, env = "CODSPEED_RUNNER_MODE")]
57+
pub mode: RunnerMode,
58+
59+
/// Profile folder to use for the run.
60+
#[arg(long)]
61+
pub profile_folder: Option<PathBuf>,
62+
63+
/// Only for debugging purposes, skips the upload of the results
64+
#[arg(
65+
long,
66+
default_value = "false",
67+
hide = true,
68+
env = "CODSPEED_SKIP_UPLOAD"
69+
)]
70+
pub skip_upload: bool,
71+
72+
/// Used internally to upload the results after running the benchmarks in a sandbox environment
73+
/// with no internet access
74+
#[arg(long, default_value = "false", hide = true)]
75+
pub skip_run: bool,
76+
77+
/// Only for debugging purposes, skips the setup of the runner
78+
#[arg(long, default_value = "false", hide = true)]
79+
pub skip_setup: bool,
80+
81+
/// Allow runs without any benchmarks to succeed instead of failing
82+
#[arg(long, default_value = "false", hide = true)]
83+
pub allow_empty: bool,
84+
85+
/// The version of the go-runner to use (e.g., 1.2.3, 1.0.0-beta.1)
86+
/// If not specified, the latest version will be installed
87+
#[arg(long, env = "CODSPEED_GO_RUNNER_VERSION", value_parser = parse_version)]
88+
pub go_runner_version: Option<semver::Version>,
89+
90+
#[command(flatten)]
91+
pub perf_run_args: PerfRunArgs,
92+
}
93+
94+
#[derive(Debug, Copy, Clone, PartialEq, ValueEnum, Default)]
95+
pub enum UnwindingMode {
96+
/// Use the frame pointer for unwinding. Requires the binary to be compiled with frame pointers enabled.
97+
#[clap(name = "fp")]
98+
FramePointer,
99+
100+
/// Use DWARF unwinding. This does not require any special compilation flags and is enabled by default.
101+
#[default]
102+
Dwarf,
103+
}
104+
105+
#[derive(Args, Debug, Clone)]
106+
pub struct PerfRunArgs {
107+
/// Enable the linux perf profiler to collect granular performance data.
108+
/// This is only supported on Linux.
109+
#[arg(long, env = "CODSPEED_PERF_ENABLED", default_value_t = true)]
110+
pub enable_perf: bool,
111+
112+
/// The unwinding mode that should be used with perf to collect the call stack.
113+
#[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE")]
114+
pub perf_unwinding_mode: Option<UnwindingMode>,
115+
}
116+
117+
/// Parser for go-runner version that validates semver format
118+
fn parse_version(s: &str) -> Result<semver::Version, String> {
119+
semver::Version::parse(s).map_err(|e| format!("Invalid semantic version: {e}"))
120+
}

src/executor/config.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use crate::cli::UnwindingMode;
12
use crate::cli::exec::wrap_with_exec_harness;
2-
use crate::cli::run::{RunArgs, UnwindingMode};
3+
use crate::cli::run::RunArgs;
34
use crate::instruments::Instruments;
45
use crate::prelude::*;
56
use crate::run_environment::RepositoryProvider;
@@ -177,15 +178,15 @@ impl TryFrom<crate::cli::exec::ExecArgs> for Config {
177178

178179
#[cfg(test)]
179180
mod tests {
180-
use crate::cli::run::PerfRunArgs;
181+
use crate::cli::PerfRunArgs;
181182
use crate::instruments::MongoDBConfig;
182183

183184
use super::*;
184185

185186
#[test]
186187
fn test_try_from_env_empty() {
187188
let config = Config::try_from(RunArgs {
188-
shared: crate::cli::run::ExecAndRunSharedArgs {
189+
shared: crate::cli::ExecAndRunSharedArgs {
189190
upload_url: None,
190191
token: None,
191192
repository: None,
@@ -224,7 +225,7 @@ mod tests {
224225
#[test]
225226
fn test_try_from_args() {
226227
let config = Config::try_from(RunArgs {
227-
shared: crate::cli::run::ExecAndRunSharedArgs {
228+
shared: crate::cli::ExecAndRunSharedArgs {
228229
upload_url: Some("https://example.com/upload".into()),
229230
token: Some("token".into()),
230231
repository: Some("owner/repo".into()),
@@ -307,7 +308,7 @@ mod tests {
307308
#[test]
308309
fn test_try_from_exec_args_default_url() {
309310
let exec_args = crate::cli::exec::ExecArgs {
310-
shared: crate::cli::run::ExecAndRunSharedArgs {
311+
shared: crate::cli::ExecAndRunSharedArgs {
311312
upload_url: None,
312313
token: None,
313314
repository: None,

src/executor/wall_time/perf/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(not(unix), allow(dead_code, unused_mut))]
22

3-
use crate::cli::run::UnwindingMode;
3+
use crate::cli::UnwindingMode;
44
use crate::executor::Config;
55
use crate::executor::helpers::command::CommandBuilder;
66
use crate::executor::helpers::env::is_codspeed_debug_enabled;

src/project_config/merger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cli::run::ExecAndRunSharedArgs;
1+
use crate::cli::ExecAndRunSharedArgs;
22
use exec_harness::walltime::WalltimeExecutionArgs;
33

44
use super::{ProjectOptions, WalltimeOptions};
@@ -69,7 +69,7 @@ impl ConfigMerger {
6969
#[cfg(test)]
7070
mod tests {
7171
use super::*;
72-
use crate::cli::run::PerfRunArgs;
72+
use crate::cli::PerfRunArgs;
7373
use crate::runner_mode::RunnerMode;
7474

7575
#[test]

0 commit comments

Comments
 (0)