mirror of https://github.com/xzeldon/htop.git
Show N/A instead of 0KHz when CPU frequency is not available.
This commit is contained in:
parent
1d5e6a27a0
commit
1acfb0a752
24
CPUMeter.c
24
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 */
|
/* 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];
|
double cpuFrequency = this->values[CPU_METER_FREQUENCY];
|
||||||
char unit = 'K';
|
char unit = 'K';
|
||||||
if (cpuFrequency > 1000) {
|
char cpuFrequencyBuffer[16];
|
||||||
cpuFrequency /= 1000;
|
if (cpuFrequency < 0) {
|
||||||
unit = 'M';
|
xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A");
|
||||||
}
|
} else {
|
||||||
if (cpuFrequency > 1000) {
|
if (cpuFrequency > 1000) {
|
||||||
cpuFrequency /= 1000;
|
cpuFrequency /= 1000;
|
||||||
unit = 'G';
|
unit = 'M';
|
||||||
|
}
|
||||||
|
if (cpuFrequency > 1000) {
|
||||||
|
cpuFrequency /= 1000;
|
||||||
|
unit = 'G';
|
||||||
|
}
|
||||||
|
xSnprintf(cpuFrequencyBuffer, 15, "%.3f%cHz", cpuFrequency, unit);
|
||||||
}
|
}
|
||||||
if (this->pl->settings->showCPUUsage) {
|
if (this->pl->settings->showCPUUsage) {
|
||||||
xSnprintf(buffer, size, "%5.1f%% %.3f%cHz", percent, cpuFrequency, unit);
|
xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer);
|
||||||
} else {
|
} else {
|
||||||
xSnprintf(buffer, size, "%.3f%cHz", cpuFrequency, unit);
|
xSnprintf(buffer, size, "%s", cpuFrequencyBuffer);
|
||||||
}
|
}
|
||||||
} else if (this->pl->settings->showCPUUsage) {
|
} else if (this->pl->settings->showCPUUsage) {
|
||||||
xSnprintf(buffer, size, "%5.1f%%", percent);
|
xSnprintf(buffer, size, "%5.1f%%", percent);
|
||||||
|
|
|
@ -193,10 +193,10 @@ double Platform_setCPUValues(Meter* this, int cpu) {
|
||||||
percent = CLAMP(percent, 0.0, 100.0);
|
percent = CLAMP(percent, 0.0, 100.0);
|
||||||
if (isnan(percent)) percent = 0.0;
|
if (isnan(percent)) percent = 0.0;
|
||||||
|
|
||||||
v[CPU_METER_FREQUENCY] = 0;
|
v[CPU_METER_FREQUENCY] = -1;
|
||||||
if (this->pl->settings->showCPUFrequency) {
|
if (this->pl->settings->showCPUFrequency) {
|
||||||
char filename[63+1];
|
char filename[64];
|
||||||
xSnprintf(filename, 63, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1);
|
xSnprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cpu - 1);
|
||||||
FILE* fd = fopen(filename, "r");
|
FILE* fd = fopen(filename, "r");
|
||||||
if (fd) {
|
if (fd) {
|
||||||
unsigned int cpuFrequency;
|
unsigned int cpuFrequency;
|
||||||
|
|
Loading…
Reference in New Issue