-
-
Notifications
You must be signed in to change notification settings - Fork 599
/
memory_info.cpp
69 lines (59 loc) · 1.52 KB
/
memory_info.cpp
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
#include "memory_info.h"
#include <QDebug>
MemoryInfo::MemoryInfo():
memTotal(0),
memFree(0),
memUsed(0)
{ }
/* https://access.redhat.com/solutions/406773
*
* https://stackoverflow.com/questions/41224738/
* Total used memory = MemTotal - MemFree
* Non cache/buffer memory (green) = Total used memory - (Buffers + Cached memory)
* Buffers (blue) = Buffers
* Cached memory (yellow) = Cached + SReclaimable - Shmem
* Swap = SwapTotal - SwapFree
*/
void MemoryInfo::updateMemoryInfo()
{
QStringList lines = FileUtil::readListFromFile(PROC_MEMINFO)
.filter(QRegExp("^MemTotal|^MemFree|^Buffers|^Cached|^SwapTotal|^SwapFree|^Shmem|^SReclaimable"));
QRegExp sep("\\s+");
#define getValue(l) lines.at(l).split(sep).at(1).toLong() << 10;
memTotal = getValue(0);
memFree = getValue(1);
buffers = getValue(2);
cached = getValue(3);
swapTotal = getValue(4);
swapFree = getValue(5);
sreclaimable = getValue(6);
shmem = getValue(7);
#undef getValue
cached = (cached + sreclaimable - shmem);
memUsed = (memTotal - (memFree + buffers + cached));
swapUsed = (swapTotal - swapFree);
}
quint64 MemoryInfo::getSwapUsed() const
{
return swapUsed;
}
quint64 MemoryInfo::getSwapFree() const
{
return swapFree;
}
quint64 MemoryInfo::getSwapTotal() const
{
return swapTotal;
}
quint64 MemoryInfo::getMemUsed() const
{
return memUsed;
}
quint64 MemoryInfo::getMemFree() const
{
return memFree;
}
quint64 MemoryInfo::getMemTotal() const
{
return memTotal;
}