rsblocks/src/utils/load_average.rs
Shoelace 2a23bd2044
Threaded to async (#58)
* Add async deps

* Rename blocks to 'BlockManager'

* Refactor "Blocks" to own module

* Make all util fn async

* Remove stray println
2021-05-19 22:44:58 +03:00

17 lines
436 B
Rust

use crate::config::CONFIG;
use crate::types::ThreadsData;
use nix::libc::{c_double, c_int, getloadavg};
pub async fn get_load_avg() -> ThreadsData {
let mut data: [c_double; 3] = [0f64; 3];
unsafe { getloadavg(data.as_mut_ptr(), data.len() as c_int) };
let [load, _, _] = data;
let data = format!(
" {} {:.2} {}",
CONFIG.loadavg.icon, load, CONFIG.seperator
);
ThreadsData::LoadAvg(data)
}