...
This commit is contained in:
31
research/zos/src/slicer/resource.rs
Normal file
31
research/zos/src/slicer/resource.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use sysinfo::System;
|
||||
|
||||
/// A struct to hold system resource information.
|
||||
pub struct Resources {
|
||||
/// Total memory in megabytes.
|
||||
pub total_memory_mb: u64,
|
||||
/// Number of CPU cores.
|
||||
pub cpu_cores: usize,
|
||||
}
|
||||
|
||||
impl Resources {
|
||||
/// Detects the system's resources.
|
||||
pub fn new() -> Self {
|
||||
let mut sys = System::new();
|
||||
sys.refresh_all();
|
||||
|
||||
let total_memory_mb = sys.total_memory() / 1024 / 1024;
|
||||
let cpu_cores = sys.cpus().len();
|
||||
|
||||
Self {
|
||||
total_memory_mb,
|
||||
cpu_cores,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Resources {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user