Skip to content

Commit bb820ae

Browse files
--wip-- [skip ci]
1 parent 8b7c20c commit bb820ae

13 files changed

Lines changed: 188 additions & 160 deletions

File tree

src/cli/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async fn setup(setup_cache_dir: Option<&Path>) -> Result<()> {
3131
let executors = get_all_executors();
3232
start_group!("Setting up the environment for all executors");
3333
for executor in executors {
34-
match executor.support_level(&system_info.os) {
34+
match executor.support_level(&system_info) {
3535
ExecutorSupport::Unsupported => {
3636
info!(
3737
"Skipping setup for the {} executor: not supported on {}",
@@ -65,7 +65,7 @@ pub fn status() -> Result<()> {
6565
info!("{}", style("Tools").bold());
6666
for executor in get_all_executors() {
6767
// Don't probe for tooling that can't be used on this OS anyway.
68-
if executor.support_level(&system_info.os) == ExecutorSupport::Unsupported {
68+
if executor.support_level(&system_info) == ExecutorSupport::Unsupported {
6969
continue;
7070
}
7171
match executor.tool_status() {

src/executor/helpers/apt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use super::run_with_sudo::run_with_sudo;
22
use crate::prelude::*;
3-
use crate::system::{Os, SystemInfo};
3+
use crate::system::{SupportedOs, SystemInfo};
44
use std::path::Path;
55
use std::process::Command;
66

77
const METADATA_FILENAME: &str = "./tmp/codspeed-cache-metadata.txt";
88

99
fn is_system_compatible(system_info: &SystemInfo) -> bool {
10-
matches!(system_info.os, Os::SupportedLinux { .. })
10+
matches!(system_info.os, SupportedOs::Linux(ref distro) if distro.is_supported())
1111
}
1212

1313
/// Installs packages with caching support.

src/executor/memory/executor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::executor::{ExecutionContext, Executor};
1212
use crate::instruments::mongo_tracer::MongoTracer;
1313
use crate::prelude::*;
1414
use crate::runner_mode::RunnerMode;
15-
use crate::system::{Os, SystemInfo};
15+
use crate::system::{SupportedOs, SystemInfo};
1616
use async_trait::async_trait;
1717
use ipc_channel::ipc;
1818
use memtrack::MemtrackIpcClient;
@@ -77,10 +77,10 @@ impl Executor for MemoryExecutor {
7777
Some(get_memtrack_status())
7878
}
7979

80-
fn support_level(&self, os: &Os) -> ExecutorSupport {
81-
match os {
82-
Os::SupportedLinux { .. } | Os::Other { .. } => ExecutorSupport::FullySupported,
83-
Os::MacOs { .. } => ExecutorSupport::Unsupported,
80+
fn support_level(&self, system_info: &SystemInfo) -> ExecutorSupport {
81+
match &system_info.os {
82+
SupportedOs::Linux(_) => ExecutorSupport::FullySupported,
83+
SupportedOs::Macos { .. } => ExecutorSupport::Unsupported,
8484
}
8585
}
8686

src/executor/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod wall_time;
1515
use crate::instruments::mongo_tracer::{MongoTracer, install_mongodb_tracer};
1616
use crate::prelude::*;
1717
use crate::runner_mode::RunnerMode;
18-
use crate::system::{Os, SystemInfo};
18+
use crate::system::SystemInfo;
1919
use async_trait::async_trait;
2020
pub use config::{BenchmarkTarget, ExecutorConfig, OrchestratorConfig};
2121
pub use execution_context::ExecutionContext;
@@ -73,7 +73,7 @@ pub enum ToolInstallStatus {
7373
NotInstalled,
7474
}
7575

76-
/// How well a given executor runs on a given [`Os`].
76+
/// How well a given executor runs on a given [`SupportedOs`].
7777
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
7878
pub enum ExecutorSupport {
7979
/// The executor cannot run on this OS at all — `run_executor` hard-bails.
@@ -91,10 +91,10 @@ pub trait Executor {
9191
/// Report the installation status of the tool(s) this executor depends on.
9292
fn tool_status(&self) -> Option<ToolStatus>;
9393

94-
/// Declare how well this executor runs on the host OS. Drives whether `setup()` is invoked
94+
/// Declare how well this executor runs on the host system. Drives whether `setup()` is invoked
9595
/// (only when [`ExecutorSupport::FullySupported`]) and whether we bail out of running the
9696
/// executor at all (on [`ExecutorSupport::Unsupported`]).
97-
fn support_level(&self, os: &Os) -> ExecutorSupport;
97+
fn support_level(&self, system_info: &SystemInfo) -> ExecutorSupport;
9898

9999
async fn setup(
100100
&self,
@@ -123,7 +123,7 @@ pub async fn run_executor(
123123
execution_context: &ExecutionContext,
124124
setup_cache_dir: Option<&Path>,
125125
) -> Result<()> {
126-
match executor.support_level(&orchestrator.system_info.os) {
126+
match executor.support_level(&orchestrator.system_info) {
127127
ExecutorSupport::Unsupported => {
128128
bail!(
129129
"The {} executor is not supported on {}",

src/executor/valgrind/executor.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::executor::ToolStatus;
66
use crate::executor::{ExecutionContext, ExecutorName, ExecutorSupport};
77
use crate::instruments::mongo_tracer::MongoTracer;
88
use crate::prelude::*;
9-
use crate::system::{Os, SystemInfo};
9+
use crate::system::{SupportedOs, SystemInfo};
1010

11-
use super::setup::{get_valgrind_status, install_valgrind};
11+
use super::setup::{get_codspeed_valgrind_filename, get_valgrind_status, install_valgrind};
1212
use super::{helpers::perf_maps::harvest_perf_maps, helpers::venv_compat, measure};
1313

1414
pub struct ValgrindExecutor;
@@ -23,11 +23,16 @@ impl Executor for ValgrindExecutor {
2323
Some(get_valgrind_status())
2424
}
2525

26-
fn support_level(&self, os: &Os) -> ExecutorSupport {
27-
match os {
28-
Os::SupportedLinux { .. } => ExecutorSupport::FullySupported,
29-
Os::Other { .. } => ExecutorSupport::RequiresManualInstallation,
30-
Os::MacOs { .. } => ExecutorSupport::Unsupported,
26+
fn support_level(&self, system_info: &SystemInfo) -> ExecutorSupport {
27+
match &system_info.os {
28+
SupportedOs::Linux(_) => {
29+
if get_codspeed_valgrind_filename(system_info).is_ok() {
30+
ExecutorSupport::FullySupported
31+
} else {
32+
ExecutorSupport::RequiresManualInstallation
33+
}
34+
}
35+
SupportedOs::Macos { .. } => ExecutorSupport::Unsupported,
3136
}
3237
}
3338

src/executor/valgrind/setup.rs

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,40 @@ use crate::cli::run::helpers::download_file;
22
use crate::executor::helpers::apt;
33
use crate::executor::{ToolInstallStatus, ToolStatus};
44
use crate::prelude::*;
5-
use crate::system::{Os, SupportedLinuxDistro, SystemInfo};
5+
use crate::system::{LinuxDistribution, SupportedOs, SystemInfo};
66
use crate::{
77
VALGRIND_CODSPEED_DEB_VERSION, VALGRIND_CODSPEED_VERSION, VALGRIND_CODSPEED_VERSION_STRING,
88
};
99
use semver::Version;
1010
use std::{env, path::Path, process::Command};
1111
use url::Url;
1212

13-
fn get_codspeed_valgrind_filename(system_info: &SystemInfo) -> Result<String> {
14-
let Os::SupportedLinux { distro, version } = &system_info.os else {
13+
pub(super) fn get_codspeed_valgrind_filename(system_info: &SystemInfo) -> Result<String> {
14+
let SupportedOs::Linux(distro) = &system_info.os else {
1515
bail!("Unsupported system");
1616
};
1717

18-
let (deb_ubuntu_version, architecture) =
19-
match (distro, version.as_str(), system_info.arch.as_str()) {
20-
(SupportedLinuxDistro::Ubuntu, "22.04", "x86_64")
21-
| (SupportedLinuxDistro::Debian, "12", "x86_64") => ("22.04", "amd64"),
22-
(SupportedLinuxDistro::Ubuntu, "24.04", "x86_64") => ("24.04", "amd64"),
23-
(SupportedLinuxDistro::Ubuntu, "22.04", "aarch64")
24-
| (SupportedLinuxDistro::Debian, "12", "aarch64") => ("22.04", "arm64"),
25-
(SupportedLinuxDistro::Ubuntu, "24.04", "aarch64") => ("24.04", "arm64"),
26-
_ => bail!("Unsupported system"),
27-
};
18+
let (deb_ubuntu_version, architecture) = match (distro, system_info.arch.as_str()) {
19+
(LinuxDistribution::Ubuntu { version }, "x86_64")
20+
| (LinuxDistribution::Debian { version }, "x86_64")
21+
if version == "22.04" || version == "12" =>
22+
{
23+
("22.04", "amd64")
24+
}
25+
(LinuxDistribution::Ubuntu { version }, "x86_64") if version == "24.04" => {
26+
("24.04", "amd64")
27+
}
28+
(LinuxDistribution::Ubuntu { version }, "aarch64")
29+
| (LinuxDistribution::Debian { version }, "aarch64")
30+
if version == "22.04" || version == "12" =>
31+
{
32+
("22.04", "arm64")
33+
}
34+
(LinuxDistribution::Ubuntu { version }, "aarch64") if version == "24.04" => {
35+
("24.04", "arm64")
36+
}
37+
_ => bail!("Unsupported system"),
38+
};
2839

2940
Ok(format!(
3041
"valgrind_{}_ubuntu-{}_{}.deb",
@@ -178,7 +189,9 @@ mod tests {
178189
#[test]
179190
fn test_system_info_to_codspeed_valgrind_version_ubuntu() {
180191
let system_info = SystemInfo {
181-
os: Os::from_id("ubuntu", "22.04"),
192+
os: SupportedOs::Linux(LinuxDistribution::Ubuntu {
193+
version: "22.04".into(),
194+
}),
182195
arch: "x86_64".to_string(),
183196
..SystemInfo::test()
184197
};
@@ -191,7 +204,9 @@ mod tests {
191204
#[test]
192205
fn test_system_info_to_codspeed_valgrind_version_ubuntu_24() {
193206
let system_info = SystemInfo {
194-
os: Os::from_id("ubuntu", "24.04"),
207+
os: SupportedOs::Linux(LinuxDistribution::Ubuntu {
208+
version: "24.04".into(),
209+
}),
195210
arch: "x86_64".to_string(),
196211
..SystemInfo::test()
197212
};
@@ -204,7 +219,9 @@ mod tests {
204219
#[test]
205220
fn test_system_info_to_codspeed_valgrind_version_debian() {
206221
let system_info = SystemInfo {
207-
os: Os::from_id("debian", "12"),
222+
os: SupportedOs::Linux(LinuxDistribution::Debian {
223+
version: "12".into(),
224+
}),
208225
arch: "x86_64".to_string(),
209226
..SystemInfo::test()
210227
};
@@ -217,7 +234,9 @@ mod tests {
217234
#[test]
218235
fn test_system_info_to_codspeed_valgrind_version_ubuntu_arm() {
219236
let system_info = SystemInfo {
220-
os: Os::from_id("ubuntu", "22.04"),
237+
os: SupportedOs::Linux(LinuxDistribution::Ubuntu {
238+
version: "22.04".into(),
239+
}),
221240
arch: "aarch64".to_string(),
222241
..SystemInfo::test()
223242
};
@@ -227,6 +246,28 @@ mod tests {
227246
);
228247
}
229248

249+
#[test]
250+
fn test_codspeed_valgrind_filename_unsupported_os() {
251+
let system_info = SystemInfo {
252+
os: SupportedOs::Macos {
253+
version: "14.0".into(),
254+
},
255+
..SystemInfo::test()
256+
};
257+
assert!(get_codspeed_valgrind_filename(&system_info).is_err());
258+
}
259+
260+
#[test]
261+
fn test_codspeed_valgrind_filename_unsupported_distro() {
262+
let system_info = SystemInfo {
263+
os: SupportedOs::Linux(LinuxDistribution::Ubuntu {
264+
version: "20.04".into(),
265+
}),
266+
..SystemInfo::test()
267+
};
268+
assert!(get_codspeed_valgrind_filename(&system_info).is_err());
269+
}
270+
230271
#[test]
231272
fn test_parse_valgrind_codspeed_version_with_prefix() {
232273
let version = parse_valgrind_codspeed_version("valgrind-3.25.1.codspeed").unwrap();

src/executor/wall_time/executor.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::executor::{ExecutionContext, ExecutorName, ExecutorSupport};
1414
use crate::instruments::mongo_tracer::MongoTracer;
1515
use crate::prelude::*;
1616
use crate::runner_mode::RunnerMode;
17-
use crate::system::{Os, SystemInfo};
17+
use crate::system::{SupportedOs, SystemInfo};
1818
use async_trait::async_trait;
1919
use std::fs::canonicalize;
2020
use std::io::Write;
@@ -127,10 +127,11 @@ impl Executor for WallTimeExecutor {
127127
.map(|_| super::perf::setup::get_perf_status())
128128
}
129129

130-
fn support_level(&self, os: &Os) -> ExecutorSupport {
131-
match os {
132-
Os::SupportedLinux { .. } | Os::MacOs { .. } => ExecutorSupport::FullySupported,
133-
Os::Other { .. } => ExecutorSupport::RequiresManualInstallation,
130+
fn support_level(&self, system_info: &SystemInfo) -> ExecutorSupport {
131+
match &system_info.os {
132+
SupportedOs::Linux(distro) if distro.is_supported() => ExecutorSupport::FullySupported,
133+
SupportedOs::Macos { .. } => ExecutorSupport::FullySupported,
134+
SupportedOs::Linux(_) => ExecutorSupport::RequiresManualInstallation,
134135
}
135136
}
136137

src/system/check.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
use crate::prelude::*;
22

3-
use super::{Os, SystemInfo};
3+
use super::SystemInfo;
44

55
pub fn check_system(system_info: &SystemInfo) -> Result<()> {
66
debug!("System info: {system_info:#?}");
7-
8-
match &system_info.os {
9-
Os::SupportedLinux { .. } | Os::MacOs { .. } => Ok(()),
10-
Os::Other { name, version } => {
11-
warn!(
12-
"Unofficially supported system: {name} {version}. Continuing with best effort support."
13-
);
14-
Ok(())
15-
}
16-
}
7+
Ok(())
178
}

src/system/info.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::process::Command;
22

3-
use serde::{Deserialize, Serialize};
3+
use serde::Serialize;
44
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, RefreshKind, System};
55

66
use crate::prelude::*;
7-
use crate::system::os::Os;
7+
use crate::system::os::SupportedOs;
88

99
fn get_user() -> Result<String> {
1010
let user_output = Command::new("whoami")
@@ -18,12 +18,12 @@ fn get_user() -> Result<String> {
1818
Ok(output_str.trim().to_string())
1919
}
2020

21-
#[derive(Eq, PartialEq, Hash, Serialize, Deserialize, Debug, Clone)]
21+
#[derive(Eq, PartialEq, Hash, Serialize, Debug, Clone)]
2222
#[serde(rename_all = "camelCase")]
2323
pub struct SystemInfo {
24-
/// Flattened to the `os` and `osVersion` fields on the wire via [`Os`]'s serde impl.
24+
/// Flattened to the `os` and `osVersion` fields on the wire via [`SupportedOs`]'s serde impl.
2525
#[serde(flatten)]
26-
pub os: Os,
26+
pub os: SupportedOs,
2727
pub arch: String,
2828
pub host: String,
2929
pub user: String,
@@ -39,7 +39,9 @@ pub struct SystemInfo {
3939
impl SystemInfo {
4040
pub fn test() -> Self {
4141
SystemInfo {
42-
os: Os::from_id("ubuntu", "20.04"),
42+
os: SupportedOs::Linux(crate::system::LinuxDistribution::Ubuntu {
43+
version: "20.04".into(),
44+
}),
4345
arch: "x86_64".to_string(),
4446
host: "host".to_string(),
4547
user: "user".to_string(),
@@ -97,8 +99,7 @@ fn get_cpu_flags() -> Vec<String> {
9799

98100
impl SystemInfo {
99101
pub fn new() -> Result<Self> {
100-
let os_id = System::distribution_id();
101-
let os_version = System::os_version().ok_or(anyhow!("Failed to get OS version"))?;
102+
let os = SupportedOs::from_os(std::env::consts::OS)?;
102103
let arch = System::cpu_arch();
103104
let user = get_user()?;
104105
let host = System::host_name().ok_or(anyhow!("Failed to get host name"))?;
@@ -133,7 +134,7 @@ impl SystemInfo {
133134
let cpu_flags = get_cpu_flags();
134135

135136
Ok(SystemInfo {
136-
os: Os::from_id(&os_id, &os_version),
137+
os,
137138
arch,
138139
host,
139140
user,

src/system/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ mod os;
44

55
pub use check::check_system;
66
pub use info::SystemInfo;
7-
pub use os::{Os, SupportedLinuxDistro};
7+
pub use os::{LinuxDistribution, SupportedOs};

0 commit comments

Comments
 (0)