37 lines
860 B
Rust
37 lines
860 B
Rust
use std::fs;
|
|
use std::str;
|
|
use std::process::Command;
|
|
|
|
|
|
pub fn get_cpu_usage() -> Vec<u32> {
|
|
let stats = fs::read_to_string("/proc/stat").expect("Aren't you running linux?");
|
|
|
|
let elements: Vec<u32> = stats
|
|
.split("\n")
|
|
.map(|line| line
|
|
.split_whitespace()
|
|
.collect()
|
|
)
|
|
.filter(|line: &Vec<&str>| line.len() > 0 && line[0] != "cpu" && line[0].starts_with("cpu"))
|
|
.map(|line| line[1].parse::<u32>().unwrap() + line[3].parse::<u32>().unwrap())
|
|
.collect();
|
|
|
|
elements
|
|
}
|
|
|
|
pub fn get_clk_tck() -> u32 {
|
|
let clk_tck = str::from_utf8(&Command::new("getconf")
|
|
.arg("CLK_TCK")
|
|
.output()
|
|
.expect("Are you running Linux???")
|
|
.stdout
|
|
)
|
|
.unwrap()
|
|
.trim()
|
|
.parse::<u32>()
|
|
.unwrap();
|
|
|
|
clk_tck
|
|
}
|
|
|