23 #include <sys/resource.h>
81 if (
p != std::string::npos) {
84 s =
s.erase(0,
s.find_first_not_of(
drop));
90 for (std::string::const_iterator iter =
s.begin(); iter !=
s.end(); iter++) {
111 bool getCpuSetSize(
unsigned &set_size) {
114 unsigned current_size = 128;
115 unsigned cpu_count = 0;
116 while (current_size * 2 > current_size) {
117 cpusetp = CPU_ALLOC(current_size);
118 CPU_ZERO_S(CPU_ALLOC_SIZE(current_size), cpusetp);
120 if (sched_getaffinity(0, CPU_ALLOC_SIZE(current_size), cpusetp)) {
122 if (errno == EINVAL) {
128 cpu_count = CPU_COUNT_S(CPU_ALLOC_SIZE(current_size), cpusetp);
132 set_size = cpu_count;
141 : reportCPUProperties_(iPS.getUntrackedParameter<
bool>(
"reportCPUProperties")) {
150 descriptions.
add(
"CPU", desc);
156 std::vector<std::pair<std::string, std::string>>
info;
163 unsigned totalNumberCPUs = 0;
164 std::map<std::string, std::string> currentCoreProperties;
168 if (
entry.first ==
"processor") {
170 if (currentCore.empty()) {
171 currentCore =
entry.second;
173 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-" + currentCore, currentCoreProperties);
174 currentCoreProperties.clear();
175 currentCore =
entry.second;
180 currentCoreProperties.insert(
entry);
184 reportSvc->reportPerformanceForModule(
"SystemCPU",
"CPU-" + currentCore, currentCoreProperties);
187 std::map<std::string, std::string> reportCPUProperties{
188 {
"totalCPUs",
i2str(totalNumberCPUs)}, {
"averageCoreSpeed",
d2str(avgSpeed)}, {
"CPUModels",
models}};
189 unsigned set_size = -1;
190 if (getCpuSetSize(set_size)) {
191 reportCPUProperties.insert(std::make_pair(
"cpusetCount",
i2str(set_size)));
193 reportSvc->reportPerformanceSummary(
"SystemCPU", reportCPUProperties);
197 std::vector<std::pair<std::string, std::string>>
info;
209 std::ifstream fcpuinfo(
"/proc/cpuinfo");
210 if (!fcpuinfo.is_open()) {
213 while (!fcpuinfo.eof()) {
215 std::getline(fcpuinfo,
buf);
217 std::istringstream iss(
buf);
224 while (std::getline(iss,
token,
':')) {
240 if (property.empty()) {
244 if (property ==
"model name") {
253 std::set<std::string>
models;
255 if (
entry.first ==
"model name") {
259 std::stringstream
ss;
261 for (
const auto &modelname :
models) {
271 double averageCoreSpeed = 0.0;
272 unsigned coreCount = 0;
274 if (
entry.first ==
"cpu MHz") {
275 averageCoreSpeed += str2d(
entry.second);
282 return averageCoreSpeed / static_cast<double>(coreCount);