use std::fs::File;
use std::io;
use std::io::BufRead;
use std::path::PathBuf;
use sysinfo::System;
pub fn print_line() {
let logo_path = PathBuf::from(crate::commons::service_home()).join("./resources/logo.txt");
if let Ok(file) = File::open(logo_path) {
let reader = io::BufReader::new(file);
for line in reader.lines().map_while(Result::ok) {
crate::commons::print_line(line);
}
}
let mut sys = System::new_all();
sys.refresh_all();
sys.refresh_memory();
crate::commons::print_line("--------------------- CPU INFO ---------------------".to_string());
crate::commons::print_line(format!("{}: {}", "操作系统", std::env::consts::OS));
crate::commons::print_line(format!("{}: {}", "处理器架构", std::env::consts::ARCH));
crate::commons::print_line(format!("{}: {}", "逻辑CPU数量", num_cpus::get()));
crate::commons::print_line(format!("{}: {}", "物理CPU数量", num_cpus::get_physical()));
crate::commons::print_line(format!("{}: {}", "总核数", sys.cpus().len()));
crate::commons::print_line(format!(
"{}: {:.2} GB",
"总内存",
sys.total_memory() as f64 / 1024.0 / 1024.0 / 1024.0
));
crate::commons::print_line(format!(
"{}: {:.2} GB",
"Swap(交换分区)总量",
sys.total_swap() as f64 / 1024.0 / 1024.0 / 1024.0
));
#[cfg(any(
target_arch = "x86",
target_arch = "x86_64",
// target_arch = "aarch64"
))]
{
use raw_cpuid::CpuId;
let cpuid = CpuId::new();
if let Some(vf) = cpuid.get_vendor_info() {
crate::commons::print_line(format!("{}: {}", "CPU厂商", vf.as_str()));
}
if let Some(bf) = cpuid.get_processor_brand_string() {
crate::commons::print_line(format!("{}: {}", "CPU型号", bf.as_str()));
}
if let Some(feat) = cpuid.get_feature_info() {
crate::commons::print_line(format!("{} {}", "支持SSE?", feat.has_sse()));
crate::commons::print_line(format!("{} {}", "支持AVX?", feat.has_avx()));
crate::commons::print_line(format!("{} {}", "支持HyperThreading?", feat.has_htt()));
}
}
crate::commons::print_line("----------------------------------------------------".to_string());
}