Show used memory & small comment additions
This commit is contained in:
parent
4f3d421ba7
commit
e384e07806
1 changed files with 10 additions and 2 deletions
12
src/main.rs
12
src/main.rs
|
@ -5,11 +5,13 @@ fn main() {
|
|||
get_sys_info();
|
||||
}
|
||||
|
||||
// Function to apply fixed width string printing
|
||||
fn printify<A: AsRef<str>, B: Display>(a: A, b: B) {
|
||||
println!("{:30}{}", a.as_ref(), b);
|
||||
}
|
||||
|
||||
fn get_sys_info() {
|
||||
// Store conversion from bytes to GiB
|
||||
let bytes_per_gib: u64 = 2u64.pow(30);
|
||||
|
||||
// Please note that we use "new_all" to ensure that all list of
|
||||
|
@ -23,23 +25,29 @@ fn get_sys_info() {
|
|||
// Store all system information:
|
||||
let hostname = System::host_name().unwrap();
|
||||
|
||||
// Store os related information:
|
||||
let os_name = System::name().unwrap();
|
||||
let os_version = System::long_os_version().unwrap();
|
||||
|
||||
// Store uptime related information:
|
||||
let uptime_hours = System::uptime() / 3600;
|
||||
let uptime_minutes = (System::uptime() % 3600) / 60;
|
||||
let uptime = format!("{} hour(s) and {} minute(s)", uptime_hours, uptime_minutes);
|
||||
|
||||
// Store kernel version:
|
||||
let kernel_version = System::kernel_version().unwrap();
|
||||
|
||||
// Store cpu related information:
|
||||
let cpu_model = sys.cpus()[0].brand();
|
||||
let cpu_cores = sys.physical_core_count().unwrap();
|
||||
let cpu_threads = sys.cpus().len();
|
||||
let cpu_topology = format!("{} cores {} threads", cpu_cores, cpu_threads);
|
||||
let cpu_architecture = System::cpu_arch().unwrap();
|
||||
|
||||
// Store memory related information:
|
||||
let used_memory = sys.used_memory() as f64 / bytes_per_gib as f64;
|
||||
let total_memory = sys.total_memory() as f64 / bytes_per_gib as f64;
|
||||
let memory = format!("{:.2} GB", total_memory);
|
||||
let memory = format!("{:.2} GB / {:.2} GB", used_memory, total_memory);
|
||||
|
||||
// Print system information:
|
||||
printify("Hostname:", hostname);
|
||||
|
@ -54,5 +62,5 @@ fn get_sys_info() {
|
|||
printify("CPU Architecture:", cpu_architecture);
|
||||
|
||||
// Print memory information:
|
||||
printify("Total Memory:", memory);
|
||||
printify("Memory:", memory);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue