Skip to content

Commit

Permalink
Merge pull request #198 from marius/master
Browse files Browse the repository at this point in the history
Use the canonical source for the number of CPUs.
  • Loading branch information
brndnmtthws committed Jan 10, 2016
2 parents d2d72e2 + 98c4100 commit fdb8523
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/linux.cc
Expand Up @@ -799,13 +799,14 @@ void get_cpu_count(void)
{
FILE *stat_fp;
static int rep = 0;
int highest_cpu_index;
char buf[256];

if (info.cpu_usage) {
return;
}

if (!(stat_fp = open_file("/proc/stat", &rep))) {
if (!(stat_fp = open_file("/sys/devices/system/cpu/present", &rep))) {
return;
}

Expand All @@ -816,11 +817,8 @@ void get_cpu_count(void)
break;
}

if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
if (info.cpu_count == 0) {
determine_longstat(buf);
}
info.cpu_count++;
if (sscanf(buf, "%*d-%d", &highest_cpu_index) == 1) {
info.cpu_count = highest_cpu_index + 1;
}
}
info.cpu_usage = (float*)malloc((info.cpu_count + 1) * sizeof(float));
Expand Down

0 comments on commit fdb8523

Please sign in to comment.