fix(kon): harden core crate — shared System instance, accurate CPU field, serialisable errors
- 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>
This commit is contained in:
@@ -13,7 +13,7 @@ pub struct SystemProfile {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CpuInfo {
|
||||
pub core_count: usize,
|
||||
pub logical_processors: usize,
|
||||
pub brand: String,
|
||||
}
|
||||
|
||||
@@ -49,16 +49,16 @@ pub enum Os {
|
||||
Android,
|
||||
}
|
||||
|
||||
pub fn probe_ram() -> Megabytes {
|
||||
let sys = System::new_all();
|
||||
/// 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))
|
||||
}
|
||||
|
||||
pub fn probe_cpu() -> CpuInfo {
|
||||
let sys = System::new_all();
|
||||
/// Probes CPU info from a shared `System` instance.
|
||||
fn probe_cpu_from(sys: &System) -> CpuInfo {
|
||||
CpuInfo {
|
||||
core_count: sys.cpus().len(),
|
||||
logical_processors: sys.cpus().len(),
|
||||
brand: sys
|
||||
.cpus()
|
||||
.first()
|
||||
@@ -75,32 +75,30 @@ pub fn probe_gpu() -> Option<GpuInfo> {
|
||||
|
||||
pub fn probe_os() -> Os {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
Os::Windows
|
||||
}
|
||||
return Os::Windows;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
Os::Linux
|
||||
}
|
||||
return Os::Linux;
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
Os::MacOs
|
||||
}
|
||||
return Os::MacOs;
|
||||
#[cfg(target_os = "ios")]
|
||||
{
|
||||
Os::Ios
|
||||
}
|
||||
return Os::Ios;
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
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. No logic here — just assembly.
|
||||
/// 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(),
|
||||
cpu: probe_cpu(),
|
||||
ram: probe_ram_from(&sys),
|
||||
cpu: probe_cpu_from(&sys),
|
||||
gpu: probe_gpu(),
|
||||
os: probe_os(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user