const char * swap_used(void) { long total, free, cached; if (get_swap_info(&total, &free, &cached)) { return NULL; } return fmt_human((total - free - cached) * 1024, 1024); }
const char * swap_free(void) { long free; if (get_swap_info(NULL, &free, NULL)) { return NULL; } return fmt_human(free * 1024, 1024); }
const char * swap_total(void) { long total; if (get_swap_info(&total, NULL, NULL)) { return NULL; } return fmt_human(total * 1024, 1024); }
const char * swap_free(void) { int total, used; if (getstats(&total, &used)) { return NULL; } return fmt_human((total - used) * 1024, 1024); }
const char * swap_used(void) { int total, used; if (getstats(&total, &used)) { return NULL; } return fmt_human(used * 1024, 1024); }
const char * ram_total(void) { uintmax_t total; if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n", &total) != 1) { return NULL; } return fmt_human(total * 1024, 1024); }
const char * cpu_freq(void) { uintmax_t freq; /* in kHz */ if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/" "scaling_cur_freq", "%ju", &freq) != 1) { return NULL; } return fmt_human(freq * 1000, 1000); }
const char * ram_used(void) { struct uvmexp uvmexp; if (load_uvmexp(&uvmexp)) { return fmt_human(pagetok(uvmexp.active, uvmexp.pageshift) * 1024, 1024); } return NULL; }
const char * ram_free(void) { struct uvmexp uvmexp; int free_pages; if (load_uvmexp(&uvmexp)) { free_pages = uvmexp.npages - uvmexp.active; return fmt_human(pagetok(free_pages, uvmexp.pageshift) * 1024, 1024); } return NULL; }
const char * ram_free(void) { uintmax_t free; if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n" "MemFree: %ju kB\n" "MemAvailable: %ju kB\n", &free, &free, &free) != 3) { return NULL; } return fmt_human(free * 1024, 1024); }
const char * cpu_freq(void) { int freq; size_t size; size = sizeof(freq); /* in MHz */ if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) == -1 || !size) { warn("sysctlbyname 'hw.clockrate':"); return NULL; } return fmt_human(freq * 1E6, 1000); }
const char * ram_used(void) { uintmax_t total, free, buffers, cached; if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n" "MemFree: %ju kB\n" "MemAvailable: %ju kB\n" "Buffers: %ju kB\n" "Cached: %ju kB\n", &total, &free, &buffers, &buffers, &cached) != 5) { return NULL; } return fmt_human((total - free - buffers - cached) * 1024, 1024); }
const char * cpu_freq(void) { int freq, mib[2]; size_t size; mib[0] = CTL_HW; mib[1] = HW_CPUSPEED; size = sizeof(freq); /* in MHz */ if (sysctl(mib, 2, &freq, &size, NULL, 0) < 0) { warn("sysctl 'HW_CPUSPEED':"); return NULL; } return fmt_human(freq * 1E6, 1000); }