X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/259e967cbf855d1ed3886c7afafb1bfe6ab11645..abbaa7af4401bbece8c9a9cb27408a0c84421762:/slstatus.c diff --git a/slstatus.c b/slstatus.c index caccc6e..cb4798b 100644 --- a/slstatus.c +++ b/slstatus.c @@ -37,6 +37,7 @@ static char *smprintf(const char *fmt, ...); static char *battery_perc(const char *bat); static char *battery_power(const char *bat); static char *battery_state(const char *bat); +static char *cpu_freq(void); static char *cpu_perc(void); static char *datetime(const char *fmt); static char *disk_free(const char *mnt); @@ -116,7 +117,7 @@ battery_perc(const char *bat) fscanf(fp, "%i", &perc); fclose(fp); - return smprintf("%d%%", perc); + return smprintf("%d", perc); } static char * @@ -167,6 +168,23 @@ battery_state(const char *bat) } } +static char * +cpu_freq(void) +{ + int freq; + FILE *fp; + + fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r"); + if (fp == NULL) { + warn("Failed to open file /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"); + return smprintf("%s", UNKNOWN_STR); + } + fscanf(fp, "%i", &freq); + fclose(fp); + + return smprintf("%d", (freq + 500) / 1000); +} + static char * cpu_perc(void) { @@ -194,7 +212,7 @@ cpu_perc(void) fclose(fp); perc = 100 * ((b[0]+b[1]+b[2]) - (a[0]+a[1]+a[2])) / ((b[0]+b[1]+b[2]+b[3]) - (a[0]+a[1]+a[2]+a[3])); - return smprintf("%d%%", perc); + return smprintf("%d", perc); } static char * @@ -237,7 +255,7 @@ disk_perc(const char *mnt) perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks)); - return smprintf("%d%%", perc); + return smprintf("%d", perc); } static char * @@ -415,7 +433,7 @@ ram_perc(void) fscanf(fp, "Cached: %ld kB\n", &cached); fclose(fp); - return smprintf("%d%%", 100 * ((total - free) - (buffers + cached)) / total); + return smprintf("%d", 100 * ((total - free) - (buffers + cached)) / total); } static char * @@ -554,7 +572,7 @@ swap_perc(void) } sscanf(match, "SwapFree: %ld kB\n", &free); - return smprintf("%d%%", 100 * (total - free - cached) / total); + return smprintf("%d", 100 * (total - free - cached) / total); } static char * @@ -643,7 +661,7 @@ temp(const char *file) fscanf(fp, "%d", &temp); fclose(fp); - return smprintf("%d°C", temp / 1000); + return smprintf("%d", temp / 1000); } static char * @@ -710,7 +728,7 @@ vol_perc(const char *card) close(afd); - return smprintf("%d%%", v & 0xff); + return smprintf("%d", v & 0xff); } static char * @@ -752,7 +770,7 @@ wifi_perc(const char *iface) datastart = (datastart+(strlen(iface)+1)); sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc); - return smprintf("%d%%", perc); + return smprintf("%d", perc); } static char *