void cpustats_init(void) { if ((cpustats_fd = open("/proc/stat", O_RDONLY)) < 0) epanic("failed to open /proc/stat"); if ((cpustats_load_fd = open("/proc/loadavg", O_RDONLY)) < 0) epanic("failed to open /proc/loadavg"); // Find the maximum number of CPU's we'll need char *poss = read_all("/sys/devices/system/cpu/possible"); cpustats_cpus = cpuset_max(poss) + 1; free(poss); // Allocate a big buffer to read /proc/stat in to cpustats_buf_size = cpustats_cpus * 128; if (!(cpustats_buf = malloc(cpustats_buf_size))) epanic("allocating cpustats file buffer"); }
void cpustats_init(void) { cpustats_findproc(); // Find the maximum number of CPU's we'll need #ifdef __FreeBSD__ size_t oldlenp = sizeof(cpustats_cpus); if (sysctlbyname("kern.smp.maxcpus", &cpustats_cpus, &oldlenp, NULL, 0)) epanic("failed to read kern.smp.maxcpus sysctl"); #else char *poss = read_all("/sys/devices/system/cpu/possible"); cpustats_cpus = cpuset_max(poss) + 1; free(poss); #endif //__FreeBSD__ // Allocate a big buffer to read /proc/stat in to cpustats_buf_size = cpustats_cpus * 128; if (!(cpustats_buf = malloc(cpustats_buf_size))) epanic("allocating cpustats file buffer"); }