blob: d9a9993a5bfa028cbd095ba367eab966d69092ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use heim::units::information;
#[derive(Debug, Clone)]
pub struct MemHarvest {
pub mem_total_in_mb: u64,
pub mem_used_in_mb: u64,
}
impl Default for MemHarvest {
fn default() -> Self {
MemHarvest {
mem_total_in_mb: 0,
mem_used_in_mb: 0,
}
}
}
pub async fn get_mem_data_list() -> crate::utils::error::Result<MemHarvest> {
let memory = heim::memory::memory().await?;
Ok(MemHarvest {
mem_total_in_mb: memory.total().get::<information::megabyte>(),
mem_used_in_mb: memory.total().get::<information::megabyte>()
- memory.available().get::<information::megabyte>(),
})
}
pub async fn get_swap_data_list() -> crate::utils::error::Result<MemHarvest> {
let memory = heim::memory::swap().await?;
Ok(MemHarvest {
mem_total_in_mb: memory.total().get::<information::megabyte>(),
mem_used_in_mb: memory.used().get::<information::megabyte>(),
})
}
|