Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/collectors/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ struct CpuidData {
fn gather_cpuid() -> Option<CpuidData> {
let cpuid = raw_cpuid::CpuId::new();

let vendor = match cpuid.get_vendor_info() {
Some(v) => match v.as_str() {
let vendor = {
let v = cpuid.get_vendor_info()?;
match v.as_str() {
"GenuineIntel" => CpuVendor::Intel,
"AuthenticAMD" => CpuVendor::Amd,
other => CpuVendor::Unknown(other.to_string()),
},
None => return None,
}
};

let brand = cpuid
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn read_u32_le(data: &[u8], offset: usize) -> Option<u32> {

/// Read a non-zero u16 value; returns `None` for 0 or 0xFFFF (unknown).
fn read_u16_nonzero(data: &[u8], offset: usize) -> Option<u16> {
read_u16_le(data, offset).and_then(|v| if v == 0 || v == 0xFFFF { None } else { Some(v) })
read_u16_le(data, offset).filter(|&v| !(v == 0 || v == 0xFFFF))
}

// ---------------------------------------------------------------------------
Expand Down
23 changes: 20 additions & 3 deletions src/sensors/rapl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::model::sensor::{SensorCategory, SensorId, SensorReading, SensorUnit};
use crate::platform::sysfs::{self, CachedFile};
use std::path::Path;
use std::time::Instant;

pub struct RaplSource {
Expand All @@ -14,19 +15,35 @@ struct RaplDomain {
prev_time: Instant,
}

fn parse_domain(dir: &Path) -> Option<String> {
Some(
dir.to_str()?
.chars()
.skip_while(|c| !c.is_ascii_digit())
.take_while(|c| c.is_ascii_digit())
.collect::<String>(),
)
}

impl RaplSource {
pub fn discover() -> Self {
let mut domains = Vec::new();

for dir in sysfs::glob_paths("/sys/class/powercap/intel-rapl:*") {
// Skip sub-domains like intel-rapl:0:1 at top level; we enumerate them
// separately via the glob which catches all levels.
// RAPL subdomains like intel-rapl:0:1 are included in the glob;
// in case the name of the subdomain does not have a distinctive number like `dram-0` a number will get added based on the RAPL domain.
let name_path = dir.join("name");
let name = match sysfs::read_string_optional(&name_path) {
let mut name = match sysfs::read_string_optional(&name_path) {
Some(n) => n,
None => continue,
};

if !name.chars().any(|c| c.is_ascii_digit())
&& let Some(rapl_domain) = parse_domain(&dir)
{
name = format!("{name}-{rapl_domain}");
}

let energy_path = dir.join("energy_uj");
let max_path = dir.join("max_energy_range_uj");

Expand Down
Loading