#[cfg(feature = "standalone")]
use crate::standalone::colors::Colorize;
const NAM_VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Debug, Clone)]
pub struct SystemSnapshot {
pub version: &'static str,
pub arch: &'static str,
pub os: &'static str,
pub kernel: String,
pub features: Vec<String>,
pub pipewire_version: Option<String>,
}
impl SystemSnapshot {
pub fn capture() -> Self {
let kernel = read_kernel_version();
let features = detect_advanced_features();
let pipewire_version = Some(pw_library_version());
Self {
version: NAM_VERSION,
arch: std::env::consts::ARCH,
os: std::env::consts::OS,
kernel,
features,
pipewire_version,
}
}
pub fn emit_irq_advisory(&self, core: usize) {
if core >= 64 {
return;
}
let mask = 0xFFFFFFFFFFFFFFFFu64 ^ (1u64 << core);
#[cfg(feature = "standalone")]
log::info!(
"{} For minimum latency, isolate core {} from system IRQs (as sudo): echo {:X} > /proc/irq/default_smp_affinity",
"💡".yellow(),
core,
mask
);
#[cfg(not(feature = "standalone"))]
log::info!(
"💡 For minimum latency, isolate core {} from system IRQs (as sudo): echo {:X} > /proc/irq/default_smp_affinity",
core,
mask
);
}
}
fn read_kernel_version() -> String {
std::fs::read_to_string("/proc/version")
.ok()
.and_then(|v| {
v.split_whitespace().nth(2).map(String::from)
})
.unwrap_or_else(|| "unknown".to_string())
}
fn detect_advanced_features() -> Vec<String> {
let mut features = Vec::new();
if std::is_x86_feature_detected!("avx512f") {
features.push("avx512f".to_string());
}
if std::is_x86_feature_detected!("avx512bw") {
features.push("avx512bw".to_string());
}
if std::is_x86_feature_detected!("avx512dq") {
features.push("avx512dq".to_string());
}
if std::is_x86_feature_detected!("avx512vl") {
features.push("avx512vl".to_string());
}
if std::is_x86_feature_detected!("avx512vnni") {
features.push("avx512vnni".to_string());
}
if std::is_x86_feature_detected!("avx512bf16") {
features.push("avx512bf16".to_string());
}
features
}
#[cfg(feature = "standalone")]
fn pw_library_version() -> String {
unsafe extern "C" {
fn pw_get_library_version() -> *const std::ffi::c_char;
}
unsafe {
let ptr = pw_get_library_version();
if ptr.is_null() {
return "unknown".to_string();
}
std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned()
}
}
#[cfg(not(feature = "standalone"))]
fn pw_library_version() -> String {
"N/A (feature standalone disabled)".to_string()
}