dwmstatus

dwmstatus fork with some Raspberry Pi workaround additions.
git clone git://bsandro.tech/dwmstatus
Log | Files | Refs | LICENSE

commit ef9bbb27e7bf2031fb9221f7ecb640e4922f29ad
parent 10408f07ee24d6f4f7a98736aceb320b6160be95
Author: bsandro <email@bsandro.tech>
Date:   Wed, 19 Jul 2023 23:38:13 +0300

cpu load fix

Diffstat:
Mdwmstatus.c | 44++++++++++----------------------------------
1 file changed, 10 insertions(+), 34 deletions(-)

diff --git a/dwmstatus.c b/dwmstatus.c @@ -119,9 +119,8 @@ char *get_cpu() unsigned long total_new[4]; unsigned long total, active = 0; unsigned long diff_total, diff_active = 0; - double cpu0 = 0, cpu1 = 0; - static unsigned long cpu0_total = 0, cpu0_active = 0; - static unsigned long cpu1_total = 0, cpu1_active = 0; + double cpu = 0; + static unsigned long cpu_total = 0, cpu_active = 0; cpu_fp = fopen("/proc/stat", "r"); @@ -133,7 +132,7 @@ char *get_cpu() if (fgets(buffer, 256, cpu_fp) == NULL) break; - if (strncmp(buffer, "cpu0", 4) == 0) + if (strncmp(buffer, "cpu ", 4) == 0) { sscanf(buffer, "%*s %lu %lu %lu %lu", &total_new[0], @@ -144,42 +143,19 @@ char *get_cpu() total = total_new[0] + total_new[1] + total_new[2] + total_new[3]; active = total - total_new[3]; - diff_total = total - cpu0_total; - diff_active = active - cpu0_active; + diff_total = total - cpu_total; + diff_active = active - cpu_active; - cpu0 = (double) diff_active / diff_total * 100; - - cpu0_total = total; - cpu0_active = active; - } - else if (strncmp(buffer, "cpu1", 4) == 0) - { - sscanf(buffer, "%*s %lu %lu %lu %lu", - &total_new[0], - &total_new[1], - &total_new[2], - &total_new[3]); - - total = total_new[0] + total_new[1] + total_new[2] + total_new[3]; - active = total - total_new[3]; - - diff_total = total - cpu1_total; - diff_active = active - cpu1_active; - - cpu1 = (double) diff_active / diff_total * 100; - - cpu1_total = total; - cpu1_active = active; + cpu = (double) diff_active / diff_total * 100; + cpu_total = total; + cpu_active = active; break; } } fclose(cpu_fp); - - //snprintf(status, 128, "%.0f%% %.0f%%", cpu0, cpu1); - snprintf(status, 128, "%.0f%%", cpu0); - (void)cpu1; + snprintf(status, 128, "%.1f%%", cpu); #ifdef DEBUG printf("CPU: %.0f%% %.0f%%\n", cpu0, cpu1); @@ -323,7 +299,7 @@ main(void) avgs = loadavg(); tmcy = mktimes("%F %H:%M", tzcyprus); - status = smprintf("mem:%s cpu:%s time:%s", get_mem(), get_cpu(), tmcy); + status = smprintf("mem:%s cpu:%s time: %s", get_mem(), get_cpu(), tmcy); setstatus(status); free(avgs);