summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan-boikov <ik.boikov.public@protonmail.com>2024-02-14 21:47:31 +0100
committerivan-boikov <ik.boikov.public@protonmail.com>2024-02-14 21:47:31 +0100
commitdb8d69656ae4ce7f146e0ac7baea60cf3958a894 (patch)
treed1ab26a20abb785cd9f3872769ab1aa4d1364504
parentfa81583552d358173cd008802f63782977f8ff60 (diff)
Avg cpu freq, bit more compact
-rw-r--r--components/cpu.c23
-rw-r--r--components/netspeeds.c4
-rw-r--r--config.h4
-rw-r--r--util.c2
4 files changed, 18 insertions, 15 deletions
diff --git a/components/cpu.c b/components/cpu.c
index a0b7314..a78f17a 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -7,19 +7,22 @@
#include "../util.h"
#if defined(__linux__)
- #define CPU_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
-
const char *
cpu_freq(const char *unused)
{
- uintmax_t freq;
-
- /* in kHz */
- if (pscanf(CPU_FREQ, "%ju", &freq) != 1)
- return NULL;
+ char cpu[128];
+ unsigned int cores = 0;
+ uintmax_t freq, freq_sum = 0;
+
+ while (1) {
+ sprintf(cpu, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cores);
+ if (pscanf(cpu, "%ju", &freq) != 1)
+ break;
+ freq_sum += freq;
+ cores++;
+ }
- //return fmt_human(freq * 1000, 1000);
- return bprintf("%.1f", freq/1e6);
+ return bprintf("%.1f", freq_sum/1e6/cores);
}
const char *
@@ -44,7 +47,7 @@
if (sum == 0)
return NULL;
- return bprintf("%d", (int)(100 *
+ return bprintf("%4.1f", (float)(100.0 *
((b[0] + b[1] + b[2] + b[5] + b[6]) -
(a[0] + a[1] + a[2] + a[5] + a[6])) / sum));
}
diff --git a/components/netspeeds.c b/components/netspeeds.c
index cde6fa9..118078b 100644
--- a/components/netspeeds.c
+++ b/components/netspeeds.c
@@ -29,7 +29,7 @@
return NULL;
return fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
- 1024);
+ 1000);
}
const char *
@@ -50,7 +50,7 @@
return NULL;
return fmt_human((txbytes - oldtxbytes) * 1000 / interval,
- 1024);
+ 1000);
}
#elif defined(__OpenBSD__) | defined(__FreeBSD__)
#include <ifaddrs.h>
diff --git a/config.h b/config.h
index 928cdc6..c71a4a3 100644
--- a/config.h
+++ b/config.h
@@ -70,8 +70,8 @@ static const struct arg args[] = {
{ cat, " %3s%%]", "/tmp/volume"},
//{ battery_perc, "[%s", "BAT0"},
//{ battery_state, "%s]", "BAT0"},
- { netspeed_rx, "[%8s ", NET_INTERFACE },
- { netspeed_tx, "%8s", NET_INTERFACE },
+ { netspeed_rx, "[%7s ", NET_INTERFACE },
+ { netspeed_tx, "%7s", NET_INTERFACE },
{ vpn_status, "%s", NULL},
//{ wifi_perc, "%s", NET_INTERFACE},
{ cpu_perc, "][%3s%%  ", NULL },
diff --git a/util.c b/util.c
index bca9b2e..85f7bbf 100644
--- a/util.c
+++ b/util.c
@@ -118,7 +118,7 @@ fmt_human(uintmax_t num, int base)
for (i = 0; i < prefixlen && scaled >= base; i++)
scaled /= base;
- return bprintf("%.1f %s", scaled, prefix[i]);
+ return bprintf("%.1f%s", scaled, prefix[i]);
}
int