- Share single System::new_all() in probe_system() instead of calling it twice - Rename CpuInfo::core_count to logical_processors (sys.cpus().len() returns logical, not physical) - Add fallback arm to probe_os() for unsupported cfg targets - Add serde::Serialize to KonError for structured frontend error reporting - Annotate dead code (ProviderRegistry, TranscriptMetadata) with #[allow(dead_code)] + TODO comments - Update downstream references in recommendation tests and tauri hardware command Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
106 lines
2.3 KiB
Rust
106 lines
2.3 KiB
Rust
use sysinfo::System;
|
|
|
|
use crate::types::Megabytes;
|
|
|
|
/// Detected system capabilities.
|
|
#[derive(Debug, Clone)]
|
|
pub struct SystemProfile {
|
|
pub ram: Megabytes,
|
|
pub cpu: CpuInfo,
|
|
pub gpu: Option<GpuInfo>,
|
|
pub os: Os,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct CpuInfo {
|
|
pub logical_processors: usize,
|
|
pub brand: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct GpuInfo {
|
|
pub vendor: GpuVendor,
|
|
pub vram: Megabytes,
|
|
pub acceleration: GpuAcceleration,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum GpuVendor {
|
|
Nvidia,
|
|
Amd,
|
|
Intel,
|
|
Apple,
|
|
Unknown,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct GpuAcceleration {
|
|
pub cuda: bool,
|
|
pub metal: bool,
|
|
pub vulkan: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum Os {
|
|
Windows,
|
|
Linux,
|
|
MacOs,
|
|
Ios,
|
|
Android,
|
|
}
|
|
|
|
/// Probes RAM from a shared `System` instance.
|
|
fn probe_ram_from(sys: &System) -> Megabytes {
|
|
let total_bytes = sys.total_memory();
|
|
Megabytes(total_bytes / (1024 * 1024))
|
|
}
|
|
|
|
/// Probes CPU info from a shared `System` instance.
|
|
fn probe_cpu_from(sys: &System) -> CpuInfo {
|
|
CpuInfo {
|
|
logical_processors: sys.cpus().len(),
|
|
brand: sys
|
|
.cpus()
|
|
.first()
|
|
.map(|c| c.brand().to_string())
|
|
.unwrap_or_default(),
|
|
}
|
|
}
|
|
|
|
pub fn probe_gpu() -> Option<GpuInfo> {
|
|
// GPU detection via wgpu or platform-specific APIs.
|
|
// Placeholder: returns None until wgpu or nvml integration is added.
|
|
None
|
|
}
|
|
|
|
pub fn probe_os() -> Os {
|
|
#[cfg(target_os = "windows")]
|
|
return Os::Windows;
|
|
#[cfg(target_os = "linux")]
|
|
return Os::Linux;
|
|
#[cfg(target_os = "macos")]
|
|
return Os::MacOs;
|
|
#[cfg(target_os = "ios")]
|
|
return Os::Ios;
|
|
#[cfg(target_os = "android")]
|
|
return Os::Android;
|
|
|
|
// Fallback for unsupported targets — treat as Linux since
|
|
// most exotic/embedded targets are Unix-like.
|
|
#[allow(unreachable_code)]
|
|
Os::Linux
|
|
}
|
|
|
|
/// Composes the individual probes using a single `System` snapshot.
|
|
/// `System::new_all()` is expensive — calling it once rather than
|
|
/// per-probe avoids redundant OS queries.
|
|
pub fn probe_system() -> SystemProfile {
|
|
let sys = System::new_all();
|
|
SystemProfile {
|
|
ram: probe_ram_from(&sys),
|
|
cpu: probe_cpu_from(&sys),
|
|
gpu: probe_gpu(),
|
|
os: probe_os(),
|
|
}
|
|
}
|