-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathshared.rs
More file actions
151 lines (127 loc) · 5.28 KB
/
shared.rs
File metadata and controls
151 lines (127 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use crate::VERSION;
use crate::local_logger::CODSPEED_U8_COLOR_CODE;
use crate::prelude::*;
use crate::run_environment::interfaces::RepositoryProvider;
use crate::runner_mode::{RunnerMode, load_shell_session_mode};
use clap::Args;
use clap::ValueEnum;
use console::style;
use std::path::PathBuf;
pub(crate) fn show_banner() {
let logo = r#" ______ __ _____ __
/ ____/____ ____/ // ___/ ____ ___ ___ ____/ /
/ / / __ \ / __ / \__ \ / __ \ / _ \ / _ \ / __ /
/ /___ / /_/ // /_/ / ___/ // /_/ // __// __// /_/ /
\____/ \____/ \__,_/ /____// .___/ \___/ \___/ \__,_/
/_/"#;
let version_tag = style(format!("v{VERSION}")).bold();
let url = style("codspeed.io").color256(CODSPEED_U8_COLOR_CODE);
let separator = style("─".repeat(52)).dim();
eprintln!();
eprintln!("{}", style(logo).color256(CODSPEED_U8_COLOR_CODE).bold());
eprintln!(" {separator}");
eprintln!(" {url} {version_tag}");
eprintln!();
debug!("codspeed v{VERSION}");
}
/// Arguments shared between run and exec commands
#[derive(Args, Debug, Clone)]
pub struct ExecAndRunSharedArgs {
/// The upload URL to use for uploading the results, useful for on-premises installations
#[arg(long, env = "CODSPEED_UPLOAD_URL")]
pub upload_url: Option<String>,
/// The token to use for uploading the results,
///
/// It can be either a CodSpeed token retrieved from the repository setting
/// or an OIDC token issued by the identity provider.
#[arg(long, env = "CODSPEED_TOKEN")]
pub token: Option<String>,
/// The repository the benchmark is associated with, under the format `owner/repo`.
#[arg(short, long, env = "CODSPEED_REPOSITORY")]
pub repository: Option<String>,
/// The repository provider to use in case --repository is used. Defaults to github
#[arg(
long,
env = "CODSPEED_PROVIDER",
requires = "repository",
ignore_case = true
)]
pub provider: Option<RepositoryProvider>,
/// The directory where the command will be executed.
#[arg(long)]
pub working_directory: Option<String>,
/// The mode to run the benchmarks in.
/// If not provided, the mode will be loaded from the shell session (set via `codspeed use <mode>`).
#[arg(short, long, value_enum, env = "CODSPEED_RUNNER_MODE")]
pub mode: Option<RunnerMode>,
/// Profile folder to use for the run.
#[arg(long)]
pub profile_folder: Option<PathBuf>,
/// Only for debugging purposes, skips the upload of the results
#[arg(
long,
default_value = "false",
hide = true,
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)]
pub skip_setup: bool,
/// Allow runs without any benchmarks to succeed instead of failing
#[arg(long, default_value = "false", hide = true)]
pub allow_empty: bool,
/// The version of the go-runner to use (e.g., 1.2.3, 1.0.0-beta.1)
/// If not specified, the latest version will be installed
#[arg(long, env = "CODSPEED_GO_RUNNER_VERSION", value_parser = parse_version)]
pub go_runner_version: Option<semver::Version>,
#[command(flatten)]
pub perf_run_args: PerfRunArgs,
}
impl ExecAndRunSharedArgs {
/// Resolves the runner mode from CLI argument, shell session, or returns an error.
///
/// Priority:
/// 1. CLI argument (--mode or -m)
/// 2. Shell session mode (set via `codspeed use <mode>`)
/// 3. Error if neither is available
pub fn resolve_mode(&self) -> Result<RunnerMode> {
if let Some(mode) = &self.mode {
return Ok(mode.clone());
}
if let Some(mode) = load_shell_session_mode()? {
debug!("Loaded mode from shell session: {mode:?}");
return Ok(mode);
}
Err(anyhow!(
"No runner mode specified. Use --mode <mode> or set the mode for this shell session with `codspeed use <mode>`."
))
}
}
#[derive(Debug, Copy, Clone, PartialEq, ValueEnum, Default)]
pub enum UnwindingMode {
/// Use the frame pointer for unwinding. Requires the binary to be compiled with frame pointers enabled.
#[clap(name = "fp")]
FramePointer,
/// Use DWARF unwinding. This does not require any special compilation flags and is enabled by default.
#[default]
Dwarf,
}
#[derive(Args, Debug, Clone)]
pub struct PerfRunArgs {
/// Enable the linux perf profiler to collect granular performance data.
/// This is only supported on Linux.
#[arg(long, env = "CODSPEED_PERF_ENABLED", default_value_t = true)]
pub enable_perf: bool,
/// The unwinding mode that should be used with perf to collect the call stack.
#[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE")]
pub perf_unwinding_mode: Option<UnwindingMode>,
}
/// Parser for go-runner version that validates semver format
fn parse_version(s: &str) -> Result<semver::Version, String> {
semver::Version::parse(s).map_err(|e| format!("Invalid semantic version: {e}"))
}