summaryrefslogtreecommitdiffstats
path: root/CPUMeter.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2020-08-20 14:47:07 +1000
committerNathan Scott <nathans@redhat.com>2020-08-20 14:47:07 +1000
commit6b443c5da9227221ed793616f156800ab4ee2717 (patch)
treea545f96ff0d3a7c022efec5eccf8a6ec796c9b03 /CPUMeter.c
parent011125dab2338acac9c4bbc7b04604f01f40e54b (diff)
parent81b64691a7ee55e5c665ac78290495b0aea946d7 (diff)
Merge branch 'hishamhm-pull-932'
Diffstat (limited to 'CPUMeter.c')
-rw-r--r--CPUMeter.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/CPUMeter.c b/CPUMeter.c
index 8a23c487..badcedab 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -28,7 +28,8 @@ typedef enum {
CPU_METER_STEAL = 5,
CPU_METER_GUEST = 6,
CPU_METER_IOWAIT = 7,
- CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
+ CPU_METER_FREQUENCY = 8,
+ CPU_METER_ITEMCOUNT = 9, // number of entries in this enum
} CPUMeterValues;
}*/
@@ -63,7 +64,30 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
}
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
double percent = Platform_setCPUValues(this, cpu);
- xSnprintf(buffer, size, "%5.1f%%", percent);
+ if (this->pl->settings->showCPUFrequency) {
+ /* Initial frequency is in MHz. Emit it as GHz if it's larger than 1000MHz */
+ double cpuFrequency = this->values[CPU_METER_FREQUENCY];
+ char unit = 'M';
+ char cpuFrequencyBuffer[16];
+ if (cpuFrequency < 0) {
+ xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A");
+ } else {
+ if (cpuFrequency > 1000) {
+ cpuFrequency /= 1000;
+ unit = 'G';
+ }
+ xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.3f%cHz", cpuFrequency, unit);
+ }
+ if (this->pl->settings->showCPUUsage) {
+ xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer);
+ } else {
+ xSnprintf(buffer, size, "%s", cpuFrequencyBuffer);
+ }
+ } else if (this->pl->settings->showCPUUsage) {
+ xSnprintf(buffer, size, "%5.1f%%", percent);
+ } else if (size > 0) {
+ buffer[0] = '\0';
+ }
}
static void CPUMeter_display(Object* cast, RichString* out) {

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