diff options
author | Arnavion <arnavion@gmail.com> | 2019-08-09 21:34:48 -0700 |
---|---|---|
committer | Arnavion <arnavion@gmail.com> | 2019-08-09 21:34:48 -0700 |
commit | 4b0600d8f8f1f6aaae6fc2e59e8697ff8779cf64 (patch) | |
tree | db0ed0d99d936058105a431371a3137a5f87dd40 /linux | |
parent | 402e46bb82964366746b86d77eb5afa69c279539 (diff) |
Add new display option to also show CPU frequency in CPU meters.
The option is only implemented on Linux. On other platforms, and on Linuxes
that do not expose the relevant sysfs file, the frequency will be 0.
The "CPU average" meter does not show a frequency, only
the individual per-CPU meters.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/Platform.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74..e92d0c51 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -192,6 +192,22 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; + + v[CPU_METER_FREQUENCY] = 0; + if (this->pl->settings->showCPUFrequency) { + char filename[63+1]; + xSnprintf(filename, 63, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1); + FILE* fd = fopen(filename, "r"); + if (fd) { + unsigned int cpuFrequency; + int n = fscanf(fd, "%u", &cpuFrequency); + fclose(fd); + if (n > 0) { + v[CPU_METER_FREQUENCY] = cpuFrequency; + } + } + } + return percent; } |