-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpuinfo.cpp
More file actions
78 lines (60 loc) · 1.57 KB
/
cpuinfo.cpp
File metadata and controls
78 lines (60 loc) · 1.57 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
#include "cpuinfo.hpp"
#include "osfile.hpp"
#include <fstream>
#include <sstream>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <iostream>
/*
/sys/devices/system/cpu/cpu%d/topology/
/sys/devices/system/cpu/cpu0/node0/distance
*/
bool CpuInfo::parse(
std::string const &cpuinf_path,
std::vector<CpuInfo::kv_tuple_vector> &res) {
std::stringstream cpuinfstrm;
if(!read_systemfile(cpuinf_path, cpuinfstrm)) {
return false;
}
std::string kvstr, kval, vval;
CpuInfo::kv_tuple_vector tupvec;
while(std::getline(cpuinfstrm, kvstr)) {
if(kvstr == "") {
res.push_back(tupvec);
tupvec.clear();
tupvec.shrink_to_fit();
}
std::stringstream kvstrm(kvstr);
std::getline(kvstrm, kval, ':');
std::getline(kvstrm, vval, ':');
boost::trim(kval); boost::trim(vval);
// loop terminal case
// b/c of how the file
// is read, 1024 blocks
// this test is needed
// to find the end of
// the file
//
//if(vval.size() == 0 && kval.size() == 0) {
// break;
//}
tupvec.push_back(std::make_tuple(kval, vval));
}
return true;
}
bool CpuInfo::cpuinfo_summary(
std::vector<CpuInfo::kv_tuple_vector> &res) {
return CpuInfo::parse("/proc/cpuinfo", res);
}
bool CpuInfo::cpuinfo_online(
std::vector<uint8_t> &res) {
const std::string onlinefpath("/sys/devices/system/cpu/online");
const int count = parse_os_index_file(onlinefpath, res);
if(count < 1) {
return false;
}
return true;
}
bool cpuinfo_details(
const std::vector<uint8_t> &cpus) {
}