From 855d9eaf9abb82c4775c5be143e71c9de1cd22b3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 9 Nov 2007 00:40:59 +0000 Subject: [PATCH] IO-wait time now counts as idle time, which is a more accurate description. It is still available in split time, now called detailed CPU time. (thanks to Samuel Thibault for the report) --- CPUMeter.c | 20 ++++++++++---------- CRT.c | 10 +++++----- ChangeLog | 4 ++++ DisplayOptionsPanel.c | 2 +- ProcessList.c | 18 ++++++++++++------ ProcessList.h | 6 ++++-- RichString.c | 18 +++++++++--------- RichString.h | 4 ++-- Settings.c | 7 +++++-- htop.c | 6 +++--- 10 files changed, 55 insertions(+), 40 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index a252d5a5..1fdac5ca 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -19,7 +19,7 @@ in the source distribution for its full text. #include int CPUMeter_attributes[] = { - CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IOWAIT, CPU_IRQ, CPU_SOFTIRQ + CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT }; MeterType CPUMeter = { @@ -74,14 +74,14 @@ void CPUMeter_setValues(Meter* this, char* buffer, int size) { double cpu; this->values[0] = pl->nicePeriod[processor] / total * 100.0; this->values[1] = pl->userPeriod[processor] / total * 100.0; - if (pl->expandSystemTime) { + if (pl->detailedCPUTime) { this->values[2] = pl->systemPeriod[processor] / total * 100.0; - this->values[3] = pl->ioWaitPeriod[processor] / total * 100.0; - this->values[4] = pl->irqPeriod[processor] / total * 100.0; - this->values[5] = pl->softIrqPeriod[processor] / total * 100.0; + this->values[3] = pl->irqPeriod[processor] / total * 100.0; + this->values[4] = pl->softIrqPeriod[processor] / total * 100.0; + this->values[5] = pl->ioWaitPeriod[processor] / total * 100.0; this->type->items = 6; cpu = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2]+ - this->values[3]+this->values[4]+this->values[5]))); + this->values[3]+this->values[4]))); } else { this->values[2] = pl->systemAllPeriod[processor] / total * 100.0; this->type->items = 3; @@ -97,7 +97,7 @@ void CPUMeter_display(Object* cast, RichString* out) { sprintf(buffer, "%5.1f%% ", this->values[1]); RichString_append(out, CRT_colors[METER_TEXT], ":"); RichString_append(out, CRT_colors[CPU_NORMAL], buffer); - if (this->pl->expandSystemTime) { + if (this->pl->detailedCPUTime) { sprintf(buffer, "%5.1f%% ", this->values[2]); RichString_append(out, CRT_colors[METER_TEXT], "sy:"); RichString_append(out, CRT_colors[CPU_KERNEL], buffer); @@ -105,14 +105,14 @@ void CPUMeter_display(Object* cast, RichString* out) { RichString_append(out, CRT_colors[METER_TEXT], "ni:"); RichString_append(out, CRT_colors[CPU_NICE], buffer); sprintf(buffer, "%5.1f%% ", this->values[3]); - RichString_append(out, CRT_colors[METER_TEXT], "wa:"); - RichString_append(out, CRT_colors[CPU_IOWAIT], buffer); - sprintf(buffer, "%5.1f%% ", this->values[4]); RichString_append(out, CRT_colors[METER_TEXT], "hi:"); RichString_append(out, CRT_colors[CPU_IRQ], buffer); sprintf(buffer, "%5.1f%% ", this->values[4]); RichString_append(out, CRT_colors[METER_TEXT], "si:"); RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer); + sprintf(buffer, "%5.1f%% ", this->values[5]); + RichString_append(out, CRT_colors[METER_TEXT], "wa:"); + RichString_append(out, CRT_colors[CPU_IOWAIT], buffer); } else { sprintf(buffer, "%5.1f%% ", this->values[2]); RichString_append(out, CRT_colors[METER_TEXT], "sys:"); diff --git a/CRT.c b/CRT.c index f922a9b6..5c0eac80 100644 --- a/CRT.c +++ b/CRT.c @@ -255,7 +255,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CHECK_BOX] = A_BOLD; CRT_colors[CHECK_MARK] = A_NORMAL; CRT_colors[CHECK_TEXT] = A_NORMAL; - CRT_colors[CPU_IOWAIT] = A_BOLD; + CRT_colors[CPU_IOWAIT] = A_NORMAL; CRT_colors[CPU_IRQ] = A_BOLD; CRT_colors[CPU_SOFTIRQ] = A_BOLD; } else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE) { @@ -310,7 +310,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CHECK_BOX] = ColorPair(Blue,White); CRT_colors[CHECK_MARK] = ColorPair(Black,White); CRT_colors[CHECK_TEXT] = ColorPair(Black,White); - CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,White); + CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black); CRT_colors[CPU_IRQ] = ColorPair(Blue,White); CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,White); } else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE2) { @@ -365,7 +365,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CHECK_BOX] = ColorPair(Blue,Black); CRT_colors[CHECK_MARK] = ColorPair(Black,Black); CRT_colors[CHECK_TEXT] = ColorPair(Black,Black); - CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Black); + CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black); CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black); CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,Black); } else if (CRT_colorScheme == COLORSCHEME_MIDNIGHT) { @@ -420,7 +420,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CHECK_BOX] = ColorPair(Cyan,Blue); CRT_colors[CHECK_MARK] = A_BOLD | ColorPair(White,Blue); CRT_colors[CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue); - CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Yellow,Blue); + CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Blue); CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue); CRT_colors[CPU_SOFTIRQ] = ColorPair(Black,Blue); } else if (CRT_colorScheme == COLORSCHEME_BLACKNIGHT) { @@ -531,7 +531,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CHECK_BOX] = ColorPair(Cyan,Black); CRT_colors[CHECK_MARK] = A_BOLD; CRT_colors[CHECK_TEXT] = A_NORMAL; - CRT_colors[CPU_IOWAIT] = ColorPair(Cyan,Black); + CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black); CRT_colors[CPU_IRQ] = ColorPair(Yellow,Black); CRT_colors[CPU_SOFTIRQ] = ColorPair(Magenta,Black); } diff --git a/ChangeLog b/ChangeLog index ae4d9f7b..733c666c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ What's new in version 0.7 * CPU affinity configuration ('a' key) * Improve display of tree view, properly nesting threads of the same app based on TGID. +* IO-wait time now counts as idle time, which is a more + accurate description. It is still available in + split time, now called detailed CPU time. + (thanks to Samuel Thibault for the report) * BUGFIX: Correct display of TPGID field * Add TGID field * BUGFIX: Don't crash with invalid command-line flags diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index fa40283f..2eeeb8aa 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -38,7 +38,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false)); Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes), false)); Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false)); - Panel_add(super, (Object*) CheckItem_new(String_copy("Split System Time into System/IO-Wait/Hard-IRQ/Soft-IRQ"), &(settings->pl->expandSystemTime), false)); + Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ)"), &(settings->pl->detailedCPUTime), false)); return this; } diff --git a/ProcessList.c b/ProcessList.c index 4b22bc08..6b18e04d 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -53,7 +53,7 @@ in the source distribution for its full text. #endif #ifndef PER_PROCESSOR_FIELDS -#define PER_PROCESSOR_FIELDS 20 +#define PER_PROCESSOR_FIELDS 22 #endif }*/ @@ -80,6 +80,7 @@ typedef struct ProcessList_ { unsigned long long int* userTime; unsigned long long int* systemTime; unsigned long long int* systemAllTime; + unsigned long long int* idleAllTime; unsigned long long int* idleTime; unsigned long long int* niceTime; unsigned long long int* ioWaitTime; @@ -90,6 +91,7 @@ typedef struct ProcessList_ { unsigned long long int* userPeriod; unsigned long long int* systemPeriod; unsigned long long int* systemAllPeriod; + unsigned long long int* idleAllPeriod; unsigned long long int* idlePeriod; unsigned long long int* nicePeriod; unsigned long long int* ioWaitPeriod; @@ -117,7 +119,7 @@ typedef struct ProcessList_ { bool treeView; bool highlightBaseName; bool highlightMegabytes; - bool expandSystemTime; + bool detailedCPUTime; #ifdef DEBUG_PROC FILE* traceFile; #endif @@ -248,7 +250,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) { this->treeView = false; this->highlightBaseName = false; this->highlightMegabytes = false; - this->expandSystemTime = false; + this->detailedCPUTime = false; return this; } @@ -656,7 +658,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl } void ProcessList_scan(ProcessList* this) { - unsigned long long int usertime, nicetime, systemtime, systemalltime, idletime, totaltime; + unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime; unsigned long long int swapFree; FILE* status; @@ -716,14 +718,16 @@ void ProcessList_scan(ProcessList* this) { } // Fields existing on kernels >= 2.6 // (and RHEL's patched kernel 2.4...) - systemalltime = systemtime + ioWait + irq + softIrq + steal; - totaltime = usertime + nicetime + systemalltime + idletime; + idlealltime = idletime + ioWait; + systemalltime = systemtime + irq + softIrq + steal; + totaltime = usertime + nicetime + systemalltime + idlealltime; assert (usertime >= this->userTime[i]); assert (nicetime >= this->niceTime[i]); assert (systemtime >= this->systemTime[i]); assert (idletime >= this->idleTime[i]); assert (totaltime >= this->totalTime[i]); assert (systemalltime >= this->systemAllTime[i]); + assert (idlealltime >= this->idleAllTime[i]); assert (ioWait >= this->ioWaitTime[i]); assert (irq >= this->irqTime[i]); assert (softIrq >= this->softIrqTime[i]); @@ -732,6 +736,7 @@ void ProcessList_scan(ProcessList* this) { this->nicePeriod[i] = nicetime - this->niceTime[i]; this->systemPeriod[i] = systemtime - this->systemTime[i]; this->systemAllPeriod[i] = systemalltime - this->systemAllTime[i]; + this->idleAllPeriod[i] = idlealltime - this->idleAllTime[i]; this->idlePeriod[i] = idletime - this->idleTime[i]; this->ioWaitPeriod[i] = ioWait - this->ioWaitTime[i]; this->irqPeriod[i] = irq - this->irqTime[i]; @@ -742,6 +747,7 @@ void ProcessList_scan(ProcessList* this) { this->niceTime[i] = nicetime; this->systemTime[i] = systemtime; this->systemAllTime[i] = systemalltime; + this->idleAllTime[i] = idlealltime; this->idleTime[i] = idletime; this->ioWaitTime[i] = ioWait; this->irqTime[i] = irq; diff --git a/ProcessList.h b/ProcessList.h index 8707ce42..578edb9e 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -55,7 +55,7 @@ in the source distribution for its full text. #endif #ifndef PER_PROCESSOR_FIELDS -#define PER_PROCESSOR_FIELDS 20 +#define PER_PROCESSOR_FIELDS 22 #endif @@ -80,6 +80,7 @@ typedef struct ProcessList_ { unsigned long long int* userTime; unsigned long long int* systemTime; unsigned long long int* systemAllTime; + unsigned long long int* idleAllTime; unsigned long long int* idleTime; unsigned long long int* niceTime; unsigned long long int* ioWaitTime; @@ -90,6 +91,7 @@ typedef struct ProcessList_ { unsigned long long int* userPeriod; unsigned long long int* systemPeriod; unsigned long long int* systemAllPeriod; + unsigned long long int* idleAllPeriod; unsigned long long int* idlePeriod; unsigned long long int* nicePeriod; unsigned long long int* ioWaitPeriod; @@ -117,7 +119,7 @@ typedef struct ProcessList_ { bool treeView; bool highlightBaseName; bool highlightMegabytes; - bool expandSystemTime; + bool detailedCPUTime; #ifdef DEBUG_PROC FILE* traceFile; #endif diff --git a/RichString.c b/RichString.c index 3bdc82b4..2cc7d172 100644 --- a/RichString.c +++ b/RichString.c @@ -26,15 +26,6 @@ typedef struct RichString_ { #define MIN(a,b) ((a)<(b)?(a):(b)) #endif -void RichString_write(RichString* this, int attrs, char* data) { - RichString_init(this); - RichString_append(this, attrs, data); -} - -inline void RichString_append(RichString* this, int attrs, char* data) { - RichString_appendn(this, attrs, data, strlen(data)); -} - inline void RichString_appendn(RichString* this, int attrs, char* data, int len) { int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len); for (int i = this->len, j = 0; i < last; i++, j++) @@ -43,6 +34,15 @@ inline void RichString_appendn(RichString* this, int attrs, char* data, int len) this->len = last; } +inline void RichString_append(RichString* this, int attrs, char* data) { + RichString_appendn(this, attrs, data, strlen(data)); +} + +void RichString_write(RichString* this, int attrs, char* data) { + RichString_init(this); + RichString_append(this, attrs, data); +} + void RichString_setAttr(RichString *this, int attrs) { chtype* ch = this->chstr; for (int i = 0; i < this->len; i++) { diff --git a/RichString.h b/RichString.h index 6972afec..6eed0d92 100644 --- a/RichString.h +++ b/RichString.h @@ -27,11 +27,11 @@ typedef struct RichString_ { #define MIN(a,b) ((a)<(b)?(a):(b)) #endif -void RichString_write(RichString* this, int attrs, char* data); +extern void RichString_appendn(RichString* this, int attrs, char* data, int len); extern void RichString_append(RichString* this, int attrs, char* data); -extern void RichString_appendn(RichString* this, int attrs, char* data, int len); +void RichString_write(RichString* this, int attrs, char* data); void RichString_setAttr(RichString *this, int attrs); diff --git a/Settings.c b/Settings.c index 4c2595a4..e53358c4 100644 --- a/Settings.c +++ b/Settings.c @@ -140,7 +140,10 @@ bool Settings_read(Settings* this, char* fileName) { } else if (String_eq(option[0], "header_margin")) { this->header->margin = atoi(option[1]); } else if (String_eq(option[0], "expand_system_time")) { - this->pl->expandSystemTime = atoi(option[1]); + // Compatibility option. + this->pl->detailedCPUTime = atoi(option[1]); + } else if (String_eq(option[0], "detailed_cpu_time")) { + this->pl->detailedCPUTime = atoi(option[1]); } else if (String_eq(option[0], "delay")) { this->delay = atoi(option[1]); } else if (String_eq(option[0], "color_scheme")) { @@ -197,7 +200,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes); fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView); fprintf(fd, "header_margin=%d\n", (int) this->header->margin); - fprintf(fd, "expand_system_time=%d\n", (int) this->pl->expandSystemTime); + fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime); fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme); fprintf(fd, "delay=%d\n", (int) this->delay); fprintf(fd, "left_meters="); diff --git a/htop.c b/htop.c index d5bebd47..15e3c3e9 100644 --- a/htop.c +++ b/htop.c @@ -63,13 +63,13 @@ void showHelp(ProcessList* pl) { mvaddstr(3, 0, "CPU usage bar: "); #define addattrstr(a,s) attrset(a);addstr(s) addattrstr(CRT_colors[BAR_BORDER], "["); - if (pl->expandSystemTime) { + if (pl->detailedCPUTime) { addattrstr(CRT_colors[CPU_NICE], "low"); addstr("/"); addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/"); addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/"); - addattrstr(CRT_colors[CPU_IOWAIT], "io-wait"); addstr("/"); addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/"); - addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); + addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/"); + addattrstr(CRT_colors[CPU_IOWAIT], "io-wait"); addattrstr(CRT_colors[BAR_SHADOW], " used%"); } else { addattrstr(CRT_colors[CPU_NICE], "low-priority"); addstr("/");