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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MemoryInformation(pub(crate) HashMap<MemoryInformationName, u64>);
impl MemoryInformation
{
#[inline]
pub fn get_statistic(&self, memory_information_name: &MemoryInformationName) -> Option<u64>
{
match self.0.get(memory_information_name)
{
None => None,
Some(value) => Some(*value),
}
}
#[inline(always)]
pub fn free_physical_ram(&self) -> Option<u64>
{
self.get_statistic(&MemoryInformationName::FreePhysicalRam)
}
pub fn default_huge_page_size(&self) -> Option<HugePageSize>
{
if let Some(size_in_bytes) = self.get_statistic(&MemoryInformationName::SizeOfAHugePage)
{
HugePageSize::from_proc_mem_info_value(size_in_bytes)
}
else
{
None
}
}
#[inline]
pub fn used_physical_ram(&self) -> Option<u64>
{
if let Some(total_physical_ram) = self.get_statistic(&MemoryInformationName::TotalPhysicalRam)
{
if let Some(free_physical_ram) = self.get_statistic(&MemoryInformationName::FreePhysicalRam)
{
Some(total_physical_ram - free_physical_ram)
}
else
{
None
}
}
else
{
None
}
}
#[inline]
pub fn used_swap(&self) -> Option<u64>
{
if let Some(total_swap) = self.get_statistic(&MemoryInformationName::TotalSwap)
{
if let Some(free_swap) = self.get_statistic(&MemoryInformationName::FreeSwap)
{
Some(total_swap - free_swap)
}
else
{
None
}
}
else
{
None
}
}
}