-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathramstatreader.cpp
More file actions
92 lines (63 loc) · 2.63 KB
/
ramstatreader.cpp
File metadata and controls
92 lines (63 loc) · 2.63 KB
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
88
89
90
91
92
#include "ramstatreader.h"
#include <QFile>
#include <QTextStream>
#include <QThread>
#include <mutex>
RamStatReader::RamStatReader(QObject *parent) : QObject(parent), StatReader("RamStatReader")
{
m_DataVec.append(StatTypes::RamData());
m_DataVec[0].AdapterName = "GenMemory";
m_DataVec[0].currentSwap.resize(m_dataPointsPerMinute,0);
m_DataVec[0].currentUsage.resize(m_dataPointsPerMinute,0);
QFile f("/proc/meminfo");
f.open(QIODevice::ReadOnly | QIODevice::Text);
if(f.isOpen()){
QTextStream in(&f);
QString line = in.readLine();
while(!line.isNull()){
if(line.startsWith("MemTotal")){
auto stringlist = line.split(" ");
m_DataVec[0].RamSizeKiB = stringlist.at(stringlist.size()-2).toInt(); //* 9.53674E-7;//9.3132257461548E-7;
break;
}
line = in.readLine();
}
}
}
void RamStatReader::measure_main_loop()
{
while(!m_quit){
QFile f("/proc/meminfo");
f.open(QIODevice::ReadOnly | QIODevice::Text);
if(f.isOpen()){
QTextStream in(&f);
QString line = in.readLine();
while(!line.isNull()){
std::lock_guard<std::mutex> lck(m_DataVecMutex);
if(line.startsWith("MemAvailable")){
auto stringlist = line.split(" ");
m_DataVec[0].currentUsage.pop_front();
m_DataVec[0].currentUsage.push_back(100*(m_DataVec[0].RamSizeKiB-stringlist.at(stringlist.size()-2).toInt())/m_DataVec[0].RamSizeKiB); //* 9.53674E-7;//9.3132257461548E-7;
}
if(line.startsWith("SwapTotal")){
auto stringlist = line.split(" ");
m_DataVec[0].SwapSizeKiB = stringlist.at(stringlist.size()-2).toInt(); //* 9.53674E-7;//9.3132257461548E-7;
}
if(line.startsWith("SwapFree")){
auto stringlist = line.split(" ");
m_DataVec[0].currentSwap.pop_front();
if(m_DataVec[0].SwapSizeKiB>0){
m_DataVec[0].currentSwap.push_back(100*(m_DataVec[0].SwapSizeKiB-stringlist.at(stringlist.size()-2).toInt())/m_DataVec[0].SwapSizeKiB); //* 9.53674E-7;//9.3132257461548E-7;
}
else m_DataVec[0].currentSwap.push_back(0);
break;
}
line = in.readLine();
}
}
filter_data_deque(m_DataVec[0].currentUsage);
filter_data_deque(m_DataVec[0].currentSwap);
emit data_ready();
QThread::msleep(100);
}
}