-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathexecution_context.rs
More file actions
74 lines (66 loc) · 2.61 KB
/
execution_context.rs
File metadata and controls
74 lines (66 loc) · 2.61 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
use super::Config;
use crate::api_client::CodSpeedAPIClient;
use crate::cli::run::logger::Logger;
use crate::config::CodSpeedConfig;
use crate::prelude::*;
use crate::run_environment::{self, RunEnvironment};
use crate::runner_mode::RunnerMode;
use crate::system::{self, SystemInfo};
use std::path::PathBuf;
use super::create_profile_folder;
/// Runtime context for benchmark execution.
///
/// This struct contains all the necessary information and dependencies needed to execute
/// benchmarks, including the execution configuration, system information, environment provider,
/// and logging facilities. It is constructed from a [`Config`] and [`CodSpeedConfig`] and
/// serves as the primary context passed to executors during the benchmark run lifecycle.
pub struct ExecutionContext {
pub config: Config,
/// Directory path where profiling data and results are stored
pub profile_folder: PathBuf,
pub system_info: SystemInfo,
/// The run environment provider (GitHub Actions, GitLab CI, local, etc.)
pub provider: Box<dyn crate::run_environment::RunEnvironmentProvider>,
pub logger: Logger,
}
impl ExecutionContext {
pub fn is_local(&self) -> bool {
self.provider.get_run_environment() == RunEnvironment::Local
}
pub async fn new(
mut config: Config,
codspeed_config: &CodSpeedConfig,
api_client: &CodSpeedAPIClient,
) -> Result<Self> {
let provider = run_environment::get_provider(&config, api_client).await?;
let system_info = SystemInfo::new()?;
system::check_system(&system_info)?;
let logger = Logger::new(provider.as_ref())?;
let profile_folder = if let Some(profile_folder) = &config.profile_folder {
profile_folder.clone()
} else {
create_profile_folder()?
};
if provider.get_run_environment() == RunEnvironment::Local {
if codspeed_config.auth.token.is_none() {
bail!("You have to authenticate the CLI first. Run `codspeed auth login`.");
}
debug!("Using the token from the CodSpeed configuration file");
config.set_token(codspeed_config.auth.token.clone());
}
#[allow(deprecated)]
if config.mode == RunnerMode::Instrumentation {
warn!(
"The 'instrumentation' runner mode is deprecated and will be removed in a future version. \
Please use 'simulation' instead."
);
}
Ok(ExecutionContext {
config,
profile_folder,
system_info,
provider,
logger,
})
}
}