summaryrefslogtreecommitdiffstats
path: root/CPUMeter.c
diff options
context:
space:
mode:
authorArnavion <arnavion@gmail.com>2019-08-10 11:37:35 -0700
committerArnavion <arnavion@gmail.com>2019-08-10 11:37:35 -0700
commit1acfb0a75223068c676e06967003fe989400e21d (patch)
tree147b8755eddd8c59962f7efe0c11c2f32aa5bb70 /CPUMeter.c
parent1d5e6a27a05ed44e6364a5b14c925503f8604a1f (diff)
Show N/A instead of 0KHz when CPU frequency is not available.
Diffstat (limited to 'CPUMeter.c')
-rw-r--r--CPUMeter.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/CPUMeter.c b/CPUMeter.c
index ef01e0ff..561f5132 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -68,18 +68,24 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
/* Initial frequency is in KHz. Divide it by 1000 till it's less than 1000, and emit unit accordingly */
double cpuFrequency = this->values[CPU_METER_FREQUENCY];
char unit = 'K';
- if (cpuFrequency > 1000) {
- cpuFrequency /= 1000;
- unit = 'M';
- }
- if (cpuFrequency > 1000) {
- cpuFrequency /= 1000;
- unit = 'G';
+ char cpuFrequencyBuffer[16];
+ if (cpuFrequency < 0) {
+ xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A");
+ } else {
+ if (cpuFrequency > 1000) {
+ cpuFrequency /= 1000;
+ unit = 'M';
+ }
+ if (cpuFrequency > 1000) {
+ cpuFrequency /= 1000;
+ unit = 'G';
+ }
+ xSnprintf(cpuFrequencyBuffer, 15, "%.3f%cHz", cpuFrequency, unit);
}
if (this->pl->settings->showCPUUsage) {
- xSnprintf(buffer, size, "%5.1f%% %.3f%cHz", percent, cpuFrequency, unit);
+ xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer);
} else {
- xSnprintf(buffer, size, "%.3f%cHz", cpuFrequency, unit);
+ xSnprintf(buffer, size, "%s", cpuFrequencyBuffer);
}
} else if (this->pl->settings->showCPUUsage) {
xSnprintf(buffer, size, "%5.1f%%", percent);

© 2014-2024 Faster IT GmbH | imprint | privacy policy