#![doc = include_str!("../examples/percpu.rs")]
use std::fs;
use glob::glob;
enum Kind {
Governor,
Freq,
Driver,
}
fn get_value(n: Kind) -> Vec<String> {
let mut data = vec![];
let path = match n {
Kind::Governor => "/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor",
Kind::Freq => "/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq",
Kind::Driver => "/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_driver",
};
for entry in glob(path).expect("glob pattern is ok") {
let info = match entry {
Ok(path) => fs::read_to_string(path).expect("/sys fs should be avaliable for reading.").trim().to_owned(),
Err(e) => { eprintln!("{e}"); "Unavaliable".to_owned() },
};
data.push(info);
}
data
}
pub fn governor() -> Vec<String> {
get_value(Kind::Governor)
}
pub fn freq() -> Vec<String> {
get_value(Kind::Freq)
}
pub fn driver() -> Vec<String> {
get_value(Kind::Driver)
}