Skip to content

Commit be3c3b2

Browse files
feat: collect cpu flags in system info
1 parent d3731f7 commit be3c3b2

5 files changed

Lines changed: 72 additions & 7 deletions

src/system/info.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct SystemInfo {
3030
pub cpu_vendor_id: String,
3131
pub cpu_cores: usize,
3232
pub total_memory_gb: u64,
33+
pub cpu_flags: Vec<String>,
3334
}
3435

3536
#[cfg(test)]
@@ -46,10 +47,53 @@ impl SystemInfo {
4647
cpu_vendor_id: "GenuineIntel".to_string(),
4748
cpu_cores: 2,
4849
total_memory_gb: 8,
50+
cpu_flags: vec![
51+
"sse2".to_string(),
52+
"avx".to_string(),
53+
"avx2".to_string(),
54+
"erms".to_string(),
55+
],
4956
}
5057
}
5158
}
5259

60+
#[cfg(target_os = "linux")]
61+
fn get_cpu_flags() -> Vec<String> {
62+
use procfs::Current;
63+
64+
let cpuinfo = match procfs::CpuInfo::current() {
65+
Ok(cpuinfo) => cpuinfo,
66+
Err(e) => {
67+
warn!("Failed to read /proc/cpuinfo: {e}");
68+
return Vec::new();
69+
}
70+
};
71+
72+
// /proc/cpuinfo uses "flags" on x86_64 and "Features" on aarch64
73+
let field_name = if cfg!(target_arch = "x86_64") {
74+
"flags"
75+
} else if cfg!(target_arch = "aarch64") {
76+
"Features"
77+
} else {
78+
return Vec::new();
79+
};
80+
81+
let mut flags: Vec<String> = match cpuinfo.get_field(0, field_name) {
82+
Some(value) => value.split_whitespace().map(|s| s.to_string()).collect(),
83+
None => {
84+
warn!("No CPU flags found in /proc/cpuinfo (field: {field_name})");
85+
return Vec::new();
86+
}
87+
};
88+
flags.sort();
89+
flags
90+
}
91+
92+
#[cfg(not(target_os = "linux"))]
93+
fn get_cpu_flags() -> Vec<String> {
94+
Vec::new()
95+
}
96+
5397
impl SystemInfo {
5498
pub fn new() -> Result<Self> {
5599
let os = System::distribution_id();
@@ -85,6 +129,8 @@ impl SystemInfo {
85129
let cpu_name = cpu.name().to_string();
86130
let cpu_vendor_id = cpu.vendor_id().to_string();
87131

132+
let cpu_flags = get_cpu_flags();
133+
88134
Ok(SystemInfo {
89135
os,
90136
os_version,
@@ -96,6 +142,7 @@ impl SystemInfo {
96142
cpu_vendor_id,
97143
cpu_cores,
98144
total_memory_gb,
145+
cpu_flags,
99146
})
100147
}
101148
}

src/upload/interfaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::instruments::InstrumentName;
55
use crate::run_environment::{RepositoryProvider, RunEnvironment, RunEnvironmentMetadata, RunPart};
66
use crate::system::SystemInfo;
77

8-
pub const LATEST_UPLOAD_METADATA_VERSION: u32 = 9;
8+
pub const LATEST_UPLOAD_METADATA_VERSION: u32 = 10;
99

1010
#[derive(Deserialize, Serialize, Debug)]
1111
#[serde(rename_all = "camelCase")]

src/upload/snapshots/codspeed_runner__upload__upload_metadata__tests__get_local_metadata_hash-2.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: upload_metadata
44
---
55
{
66
"repositoryProvider": "PROJECT",
7-
"version": 9,
7+
"version": 10,
88
"tokenless": false,
99
"profileMd5": "tfC4VxYiYdJcTWpHpv4Ouw==",
1010
"profileEncoding": "gzip",
@@ -22,7 +22,13 @@ expression: upload_metadata
2222
"cpuName": "cpu0",
2323
"cpuVendorId": "GenuineIntel",
2424
"cpuCores": 6,
25-
"totalMemoryGb": 16
25+
"totalMemoryGb": 16,
26+
"cpuFlags": [
27+
"sse2",
28+
"avx",
29+
"avx2",
30+
"erms"
31+
]
2632
},
2733
"runEnvironment": "LOCAL",
2834
"runPart": {

src/upload/snapshots/codspeed_runner__upload__upload_metadata__tests__get_metadata_hash-2.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: upload_metadata
44
---
55
{
66
"repositoryProvider": "GITHUB",
7-
"version": 9,
7+
"version": 10,
88
"tokenless": true,
99
"profileMd5": "jp/k05RKuqP3ERQuIIvx4Q==",
1010
"profileEncoding": "gzip",
@@ -24,7 +24,13 @@ expression: upload_metadata
2424
"cpuName": "cpu0",
2525
"cpuVendorId": "GenuineIntel",
2626
"cpuCores": 2,
27-
"totalMemoryGb": 8
27+
"totalMemoryGb": 8,
28+
"cpuFlags": [
29+
"sse2",
30+
"avx",
31+
"avx2",
32+
"erms"
33+
]
2834
},
2935
"runEnvironment": "GITHUB_ACTIONS",
3036
"runPart": {

src/upload/upload_metadata.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod tests {
7777
hash,
7878
// Caution: when changing this value, we need to ensure that
7979
// the related backend snapshot remains the same
80-
@"b2c6175fa81d4c4c5eb215e2e77667891f33abca9f8614b45899e3ee070bdca6"
80+
@"0afc09ee58a610d400aa6b3fbdddf628608ed2e11aed39585a50abe96e1c9284"
8181
);
8282
assert_json_snapshot!(upload_metadata);
8383
}
@@ -106,6 +106,12 @@ mod tests {
106106
cpu_vendor_id: "GenuineIntel".to_string(),
107107
cpu_cores: 6,
108108
total_memory_gb: 16,
109+
cpu_flags: vec![
110+
"sse2".to_string(),
111+
"avx".to_string(),
112+
"avx2".to_string(),
113+
"erms".to_string(),
114+
],
109115
},
110116
},
111117
run_environment: RunEnvironment::Local,
@@ -139,7 +145,7 @@ mod tests {
139145
hash,
140146
// Caution: when changing this value, we need to ensure that
141147
// the related backend snapshot remains the same
142-
@"47b6317da2747edae177d8a99143efc6f7516beb3222b9d45331ba48d4e1c369"
148+
@"26c83ef306f189fe5b725043577dbc09a204bbd1c973dd7d1e974ff88235dd84"
143149
);
144150
assert_json_snapshot!(upload_metadata);
145151
}

0 commit comments

Comments
 (0)