draft of lscpu
This commit is contained in:
parent
8976320220
commit
8bba913e56
src/uu/lscpu
12
src/uu/lscpu/Cargo.toml
Normal file
12
src/uu/lscpu/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "uu_lscpu"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
name = "lscpu"
|
||||
path = "src/lscpu.rs"
|
||||
|
||||
[dependencies]
|
||||
regex = { workspace = true }
|
||||
sysinfo = { workspace = true }
|
31
src/uu/lscpu/src/lscpu.rs
Normal file
31
src/uu/lscpu/src/lscpu.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use sysinfo::{System};
|
||||
use regex::Regex;
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let system = System::new_all();
|
||||
let cpu = system.global_cpu_info();
|
||||
|
||||
println!("Architecture: {}", get_architecture());
|
||||
println!("CPU(s): {}", system.cpus().len());
|
||||
// Add more CPU information here...
|
||||
|
||||
// Example: Parsing /proc/cpuinfo for additional details
|
||||
if let Ok(contents) = fs::read_to_string("/proc/cpuinfo") {
|
||||
let re = Regex::new(r"^model name\s+:\s+(.*)$").unwrap();
|
||||
for cap in re.captures_iter(&contents) {
|
||||
println!("Model name: {}", &cap[1]);
|
||||
break; // Assuming all CPUs have the same model name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_architecture() -> String {
|
||||
if cfg!(target_arch = "x86") {
|
||||
"x86".to_string()
|
||||
} else if cfg!(target_arch = "x86_64") {
|
||||
"x86_64".to_string()
|
||||
} else {
|
||||
"Unknown".to_string()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user