-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.cpp
61 lines (51 loc) · 1.01 KB
/
cpu.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
#include <stdio.h>
#include <string>
#include <vector>
#include <regex>
#include <sstream>
#include "command.cpp"
using namespace std;
string probeCpu() {
return execCommand("sensors");
}
vector<string> split(const string &s, char delim) {
stringstream ss(s);
string item;
vector<string> tokens;
while (getline(ss, item, delim)) {
tokens.push_back(item);
}
return tokens;
}
vector<double> parseCpuTemp(const string &cpu_temp) {
vector<string> lines = split(cpu_temp.c_str(), '\n');
vector<double> temps;
regex core_temp ("Core[^+|-]*([^°]*).*");
smatch matches;
for (int i = 0; i < lines.size(); i++) {
regex_match(lines[i], matches, core_temp);
if (matches.size() == 2) {
double temp = stod(matches.str(1));
temps.push_back(temp);
}
}
return temps;
}
vector<double> getCpuTemp() {
}
class CPU
{
private:
vector<double> temps;
public:
CPU()
{
}
void update()
{
temps = parseCpuTemp(probeCpu());
}
vector<double> getTemps() {
return temps;
}
};