1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-29 21:49:07 +00:00

Merge pull request #198 from marius/master

Use the canonical source for the number of CPUs.
This commit is contained in:
Brenden Matthews 2016-01-10 14:05:37 -08:00
commit fdb8523d26

View File

@ -799,13 +799,14 @@ void get_cpu_count(void)
{ {
FILE *stat_fp; FILE *stat_fp;
static int rep = 0; static int rep = 0;
int highest_cpu_index;
char buf[256]; char buf[256];
if (info.cpu_usage) { if (info.cpu_usage) {
return; return;
} }
if (!(stat_fp = open_file("/proc/stat", &rep))) { if (!(stat_fp = open_file("/sys/devices/system/cpu/present", &rep))) {
return; return;
} }
@ -816,11 +817,8 @@ void get_cpu_count(void)
break; break;
} }
if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) { if (sscanf(buf, "%*d-%d", &highest_cpu_index) == 1) {
if (info.cpu_count == 0) { info.cpu_count = highest_cpu_index + 1;
determine_longstat(buf);
}
info.cpu_count++;
} }
} }
info.cpu_usage = (float*)malloc((info.cpu_count + 1) * sizeof(float)); info.cpu_usage = (float*)malloc((info.cpu_count + 1) * sizeof(float));