mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 21:44:36 +03:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
4300897d0c |
@ -1,48 +0,0 @@
|
|||||||
|
|
||||||
#include "AffinityPanel.h"
|
|
||||||
|
|
||||||
#include "Panel.h"
|
|
||||||
#include "CheckItem.h"
|
|
||||||
|
|
||||||
#include "debug.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
Panel* AffinityPanel_new(int processorCount, unsigned long mask) {
|
|
||||||
Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare);
|
|
||||||
this->eventHandler = AffinityPanel_eventHandler;
|
|
||||||
|
|
||||||
Panel_setHeader(this, "Use CPUs:");
|
|
||||||
for (int i = 0; i < processorCount; i++) {
|
|
||||||
char number[10];
|
|
||||||
snprintf(number, 9, "%d", i+1);
|
|
||||||
Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i)));
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long AffinityPanel_getAffinity(Panel* this) {
|
|
||||||
int size = Panel_getSize(this);
|
|
||||||
unsigned long mask = 0;
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
if (CheckItem_get((CheckItem*)Panel_get(this, i)))
|
|
||||||
mask = mask | (1 << i);
|
|
||||||
}
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
|
|
||||||
HandlerResult result = IGNORED;
|
|
||||||
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
|
|
||||||
switch(ch) {
|
|
||||||
case ' ':
|
|
||||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
|
||||||
result = HANDLED;
|
|
||||||
break;
|
|
||||||
case 0x0a:
|
|
||||||
case 0x0d:
|
|
||||||
case KEY_ENTER:
|
|
||||||
result = BREAK_LOOP;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_AffinityPanel
|
|
||||||
#define HEADER_AffinityPanel
|
|
||||||
|
|
||||||
|
|
||||||
#include "Panel.h"
|
|
||||||
#include "CheckItem.h"
|
|
||||||
|
|
||||||
#include "debug.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
Panel* AffinityPanel_new(int processorCount, unsigned long mask);
|
|
||||||
|
|
||||||
unsigned long AffinityPanel_getAffinity(Panel* this);
|
|
||||||
|
|
||||||
HandlerResult AffinityPanel_eventHandler(Panel* this, int ch);
|
|
||||||
|
|
||||||
#endif
|
|
36
CPUMeter.c
36
CPUMeter.c
@ -19,14 +19,14 @@ in the source distribution for its full text.
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
int CPUMeter_attributes[] = {
|
int CPUMeter_attributes[] = {
|
||||||
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT
|
CPU_NICE, CPU_NORMAL, CPU_KERNEL
|
||||||
};
|
};
|
||||||
|
|
||||||
MeterType CPUMeter = {
|
MeterType CPUMeter = {
|
||||||
.setValues = CPUMeter_setValues,
|
.setValues = CPUMeter_setValues,
|
||||||
.display = CPUMeter_display,
|
.display = CPUMeter_display,
|
||||||
.mode = BAR_METERMODE,
|
.mode = BAR_METERMODE,
|
||||||
.items = 6,
|
.items = 3,
|
||||||
.total = 100.0,
|
.total = 100.0,
|
||||||
.attributes = CPUMeter_attributes,
|
.attributes = CPUMeter_attributes,
|
||||||
.name = "CPU",
|
.name = "CPU",
|
||||||
@ -71,22 +71,10 @@ void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
|||||||
ProcessList* pl = this->pl;
|
ProcessList* pl = this->pl;
|
||||||
int processor = this->param;
|
int processor = this->param;
|
||||||
double total = (double) pl->totalPeriod[processor];
|
double total = (double) pl->totalPeriod[processor];
|
||||||
double cpu;
|
|
||||||
this->values[0] = pl->nicePeriod[processor] / total * 100.0;
|
this->values[0] = pl->nicePeriod[processor] / total * 100.0;
|
||||||
this->values[1] = pl->userPeriod[processor] / total * 100.0;
|
this->values[1] = pl->userPeriod[processor] / total * 100.0;
|
||||||
if (pl->detailedCPUTime) {
|
|
||||||
this->values[2] = pl->systemPeriod[processor] / total * 100.0;
|
this->values[2] = pl->systemPeriod[processor] / total * 100.0;
|
||||||
this->values[3] = pl->irqPeriod[processor] / total * 100.0;
|
double cpu = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2])));
|
||||||
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])));
|
|
||||||
} else {
|
|
||||||
this->values[2] = pl->systemAllPeriod[processor] / total * 100.0;
|
|
||||||
this->type->items = 3;
|
|
||||||
cpu = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2])));
|
|
||||||
}
|
|
||||||
snprintf(buffer, size, "%5.1f%%", cpu );
|
snprintf(buffer, size, "%5.1f%%", cpu );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,23 +85,6 @@ void CPUMeter_display(Object* cast, RichString* out) {
|
|||||||
sprintf(buffer, "%5.1f%% ", this->values[1]);
|
sprintf(buffer, "%5.1f%% ", this->values[1]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], ":");
|
RichString_append(out, CRT_colors[METER_TEXT], ":");
|
||||||
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
|
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
|
||||||
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);
|
|
||||||
sprintf(buffer, "%5.1f%% ", this->values[0]);
|
|
||||||
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], "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]);
|
sprintf(buffer, "%5.1f%% ", this->values[2]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
||||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
||||||
@ -121,7 +92,6 @@ void CPUMeter_display(Object* cast, RichString* out) {
|
|||||||
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
||||||
RichString_append(out, CRT_colors[CPU_NICE], buffer);
|
RichString_append(out, CRT_colors[CPU_NICE], buffer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void AllCPUsMeter_init(Meter* this) {
|
void AllCPUsMeter_init(Meter* this) {
|
||||||
int processors = this->pl->processorCount;
|
int processors = this->pl->processorCount;
|
||||||
|
25
CRT.c
25
CRT.c
@ -14,7 +14,6 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||||
@ -94,9 +93,6 @@ typedef enum ColorElements_ {
|
|||||||
CPU_NORMAL,
|
CPU_NORMAL,
|
||||||
CPU_KERNEL,
|
CPU_KERNEL,
|
||||||
HELP_BOLD,
|
HELP_BOLD,
|
||||||
CPU_IOWAIT,
|
|
||||||
CPU_IRQ,
|
|
||||||
CPU_SOFTIRQ,
|
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
@ -164,7 +160,6 @@ void CRT_done() {
|
|||||||
int CRT_readKey() {
|
int CRT_readKey() {
|
||||||
nocbreak();
|
nocbreak();
|
||||||
cbreak();
|
cbreak();
|
||||||
nodelay(stdscr, FALSE);
|
|
||||||
int ret = getch();
|
int ret = getch();
|
||||||
halfdelay(CRT_delay);
|
halfdelay(CRT_delay);
|
||||||
return ret;
|
return ret;
|
||||||
@ -182,7 +177,7 @@ void CRT_enableDelay() {
|
|||||||
|
|
||||||
void CRT_handleSIGSEGV(int signal) {
|
void CRT_handleSIGSEGV(int signal) {
|
||||||
CRT_done();
|
CRT_done();
|
||||||
fprintf(stderr, "htop " VERSION " aborted. Please report bug at http://htop.sf.net\n");
|
fprintf(stderr, "Aborted. Please report bug at http://htop.sf.net");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,9 +250,6 @@ void CRT_setColors(int colorScheme) {
|
|||||||
CRT_colors[CHECK_BOX] = A_BOLD;
|
CRT_colors[CHECK_BOX] = A_BOLD;
|
||||||
CRT_colors[CHECK_MARK] = A_NORMAL;
|
CRT_colors[CHECK_MARK] = A_NORMAL;
|
||||||
CRT_colors[CHECK_TEXT] = A_NORMAL;
|
CRT_colors[CHECK_TEXT] = A_NORMAL;
|
||||||
CRT_colors[CPU_IOWAIT] = A_NORMAL;
|
|
||||||
CRT_colors[CPU_IRQ] = A_BOLD;
|
|
||||||
CRT_colors[CPU_SOFTIRQ] = A_BOLD;
|
|
||||||
} else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE) {
|
} else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE) {
|
||||||
CRT_colors[RESET_COLOR] = ColorPair(Black,White);
|
CRT_colors[RESET_COLOR] = ColorPair(Black,White);
|
||||||
CRT_colors[DEFAULT_COLOR] = ColorPair(Black,White);
|
CRT_colors[DEFAULT_COLOR] = ColorPair(Black,White);
|
||||||
@ -310,9 +302,6 @@ void CRT_setColors(int colorScheme) {
|
|||||||
CRT_colors[CHECK_BOX] = ColorPair(Blue,White);
|
CRT_colors[CHECK_BOX] = ColorPair(Blue,White);
|
||||||
CRT_colors[CHECK_MARK] = ColorPair(Black,White);
|
CRT_colors[CHECK_MARK] = ColorPair(Black,White);
|
||||||
CRT_colors[CHECK_TEXT] = ColorPair(Black,White);
|
CRT_colors[CHECK_TEXT] = ColorPair(Black,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) {
|
} else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE2) {
|
||||||
CRT_colors[RESET_COLOR] = ColorPair(Black,Black);
|
CRT_colors[RESET_COLOR] = ColorPair(Black,Black);
|
||||||
CRT_colors[DEFAULT_COLOR] = ColorPair(Black,Black);
|
CRT_colors[DEFAULT_COLOR] = ColorPair(Black,Black);
|
||||||
@ -365,9 +354,6 @@ void CRT_setColors(int colorScheme) {
|
|||||||
CRT_colors[CHECK_BOX] = ColorPair(Blue,Black);
|
CRT_colors[CHECK_BOX] = ColorPair(Blue,Black);
|
||||||
CRT_colors[CHECK_MARK] = ColorPair(Black,Black);
|
CRT_colors[CHECK_MARK] = ColorPair(Black,Black);
|
||||||
CRT_colors[CHECK_TEXT] = ColorPair(Black,Black);
|
CRT_colors[CHECK_TEXT] = ColorPair(Black,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) {
|
} else if (CRT_colorScheme == COLORSCHEME_MIDNIGHT) {
|
||||||
CRT_colors[RESET_COLOR] = ColorPair(White,Blue);
|
CRT_colors[RESET_COLOR] = ColorPair(White,Blue);
|
||||||
CRT_colors[DEFAULT_COLOR] = ColorPair(White,Blue);
|
CRT_colors[DEFAULT_COLOR] = ColorPair(White,Blue);
|
||||||
@ -420,9 +406,6 @@ void CRT_setColors(int colorScheme) {
|
|||||||
CRT_colors[CHECK_BOX] = ColorPair(Cyan,Blue);
|
CRT_colors[CHECK_BOX] = ColorPair(Cyan,Blue);
|
||||||
CRT_colors[CHECK_MARK] = A_BOLD | ColorPair(White,Blue);
|
CRT_colors[CHECK_MARK] = A_BOLD | ColorPair(White,Blue);
|
||||||
CRT_colors[CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue);
|
CRT_colors[CHECK_TEXT] = A_NORMAL | ColorPair(White,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) {
|
} else if (CRT_colorScheme == COLORSCHEME_BLACKNIGHT) {
|
||||||
CRT_colors[RESET_COLOR] = ColorPair(Cyan,Black);
|
CRT_colors[RESET_COLOR] = ColorPair(Cyan,Black);
|
||||||
CRT_colors[DEFAULT_COLOR] = ColorPair(Cyan,Black);
|
CRT_colors[DEFAULT_COLOR] = ColorPair(Cyan,Black);
|
||||||
@ -475,9 +458,6 @@ void CRT_setColors(int colorScheme) {
|
|||||||
CRT_colors[CHECK_BOX] = ColorPair(Green,Black);
|
CRT_colors[CHECK_BOX] = ColorPair(Green,Black);
|
||||||
CRT_colors[CHECK_MARK] = A_BOLD | ColorPair(Green,Black);
|
CRT_colors[CHECK_MARK] = A_BOLD | ColorPair(Green,Black);
|
||||||
CRT_colors[CHECK_TEXT] = ColorPair(Cyan,Black);
|
CRT_colors[CHECK_TEXT] = ColorPair(Cyan,Black);
|
||||||
CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Black);
|
|
||||||
CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black);
|
|
||||||
CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,Black);
|
|
||||||
} else {
|
} else {
|
||||||
/* Default */
|
/* Default */
|
||||||
CRT_colors[RESET_COLOR] = ColorPair(White,Black);
|
CRT_colors[RESET_COLOR] = ColorPair(White,Black);
|
||||||
@ -531,8 +511,5 @@ void CRT_setColors(int colorScheme) {
|
|||||||
CRT_colors[CHECK_BOX] = ColorPair(Cyan,Black);
|
CRT_colors[CHECK_BOX] = ColorPair(Cyan,Black);
|
||||||
CRT_colors[CHECK_MARK] = A_BOLD;
|
CRT_colors[CHECK_MARK] = A_BOLD;
|
||||||
CRT_colors[CHECK_TEXT] = A_NORMAL;
|
CRT_colors[CHECK_TEXT] = A_NORMAL;
|
||||||
CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black);
|
|
||||||
CRT_colors[CPU_IRQ] = ColorPair(Yellow,Black);
|
|
||||||
CRT_colors[CPU_SOFTIRQ] = ColorPair(Magenta,Black);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
CRT.h
4
CRT.h
@ -17,7 +17,6 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||||
@ -96,9 +95,6 @@ typedef enum ColorElements_ {
|
|||||||
CPU_NORMAL,
|
CPU_NORMAL,
|
||||||
CPU_KERNEL,
|
CPU_KERNEL,
|
||||||
HELP_BOLD,
|
HELP_BOLD,
|
||||||
CPU_IOWAIT,
|
|
||||||
CPU_IRQ,
|
|
||||||
CPU_SOFTIRQ,
|
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
|
61
ChangeLog
61
ChangeLog
@ -1,65 +1,4 @@
|
|||||||
|
|
||||||
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
|
|
||||||
(thanks to Nico Golde for the report)
|
|
||||||
* Fix GCC 4.3 compilation issues
|
|
||||||
(thanks to Martin Michlmayr for the report)
|
|
||||||
* OpenVZ support, enabled at compile-time with
|
|
||||||
the --enable-openvz flag.
|
|
||||||
(thanks to Sergey Lychko)
|
|
||||||
|
|
||||||
What's new in version 0.6.6
|
|
||||||
|
|
||||||
* Add support of NLWP field
|
|
||||||
(thanks to Bert Wesarg)
|
|
||||||
* BUGFIX: Fix use of configurable /proc location
|
|
||||||
(thanks to Florent Thoumie)
|
|
||||||
* Fix memory percentage calculation and make it saner
|
|
||||||
(thanks to Olev Kartau for the report)
|
|
||||||
* Added display of DRS, DT, LRS and TRS
|
|
||||||
(thanks to Matthias Lederhofer)
|
|
||||||
* BUGFIX: LRS and DRS memory values were flipped
|
|
||||||
(thanks to Matthias Lederhofer)
|
|
||||||
* BUGFIX: Don't crash on very high UIDs
|
|
||||||
(thanks to Egmont Koblinger)
|
|
||||||
|
|
||||||
What's new in version 0.6.5
|
|
||||||
|
|
||||||
* Add hardened-debug flags for debugging with Hardened GCC
|
|
||||||
* BUGFIX: Handle error condition when a directory vanishes
|
|
||||||
from /proc
|
|
||||||
* BUGFIX: Fix leak of process command line
|
|
||||||
* BUGFIX: Collect orphaned items when arranging the tree view.
|
|
||||||
(thanks to Wolfram Schlich for assistance with debugging)
|
|
||||||
* Separate proc and memory debugging into separate #defines.
|
|
||||||
* BUGFIX: Fix message when configure fails due to
|
|
||||||
missing libraries
|
|
||||||
(thanks to Jon)
|
|
||||||
* BUGFIX: Don't truncate value when displaying a very large
|
|
||||||
process
|
|
||||||
(thanks to Bo Liu)
|
|
||||||
|
|
||||||
What's new in version 0.6.4
|
|
||||||
|
|
||||||
* Add an option to split the display of kernel time
|
|
||||||
in the CPU meter into system, IO-wait, IRQ and soft-IRQ.
|
|
||||||
(thanks to Philipp Richter)
|
|
||||||
* --sort-key flag in the command-line, overriding the
|
|
||||||
saved setting in .htoprc for the session.
|
|
||||||
(thanks to Rodolfo Borges)
|
|
||||||
* BUGFIX: Fixed string overflow on uptime display.
|
|
||||||
(thanks to Marc Cahalan)
|
|
||||||
|
|
||||||
What's new in version 0.6.3
|
What's new in version 0.6.3
|
||||||
|
|
||||||
* Performance improvements: uses much less CPU than the
|
* Performance improvements: uses much less CPU than the
|
||||||
|
22
CheckItem.c
22
CheckItem.c
@ -16,8 +16,7 @@ in the source distribution for its full text.
|
|||||||
typedef struct CheckItem_ {
|
typedef struct CheckItem_ {
|
||||||
Object super;
|
Object super;
|
||||||
char* text;
|
char* text;
|
||||||
bool value;
|
bool* value;
|
||||||
bool* ref;
|
|
||||||
} CheckItem;
|
} CheckItem;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
@ -28,14 +27,13 @@ char* CHECKITEM_CLASS = "CheckItem";
|
|||||||
#define CHECKITEM_CLASS NULL
|
#define CHECKITEM_CLASS NULL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
|
CheckItem* CheckItem_new(char* text, bool* value) {
|
||||||
CheckItem* this = malloc(sizeof(CheckItem));
|
CheckItem* this = malloc(sizeof(CheckItem));
|
||||||
Object_setClass(this, CHECKITEM_CLASS);
|
Object_setClass(this, CHECKITEM_CLASS);
|
||||||
((Object*)this)->display = CheckItem_display;
|
((Object*)this)->display = CheckItem_display;
|
||||||
((Object*)this)->delete = CheckItem_delete;
|
((Object*)this)->delete = CheckItem_delete;
|
||||||
this->text = text;
|
this->text = text;
|
||||||
this->value = value;
|
this->value = value;
|
||||||
this->ref = ref;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,25 +45,11 @@ void CheckItem_delete(Object* cast) {
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckItem_set(CheckItem* this, bool value) {
|
|
||||||
if (this->ref)
|
|
||||||
*(this->ref) = value;
|
|
||||||
else
|
|
||||||
this->value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckItem_get(CheckItem* this) {
|
|
||||||
if (this->ref)
|
|
||||||
return *(this->ref);
|
|
||||||
else
|
|
||||||
return this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckItem_display(Object* cast, RichString* out) {
|
void CheckItem_display(Object* cast, RichString* out) {
|
||||||
CheckItem* this = (CheckItem*)cast;
|
CheckItem* this = (CheckItem*)cast;
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
||||||
if (CheckItem_get(this))
|
if (*(this->value))
|
||||||
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
||||||
else
|
else
|
||||||
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
||||||
|
@ -18,8 +18,7 @@ in the source distribution for its full text.
|
|||||||
typedef struct CheckItem_ {
|
typedef struct CheckItem_ {
|
||||||
Object super;
|
Object super;
|
||||||
char* text;
|
char* text;
|
||||||
bool value;
|
bool* value;
|
||||||
bool* ref;
|
|
||||||
} CheckItem;
|
} CheckItem;
|
||||||
|
|
||||||
|
|
||||||
@ -29,14 +28,10 @@ extern char* CHECKITEM_CLASS;
|
|||||||
#define CHECKITEM_CLASS NULL
|
#define CHECKITEM_CLASS NULL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value);
|
CheckItem* CheckItem_new(char* text, bool* value);
|
||||||
|
|
||||||
void CheckItem_delete(Object* cast);
|
void CheckItem_delete(Object* cast);
|
||||||
|
|
||||||
void CheckItem_set(CheckItem* this, bool value);
|
|
||||||
|
|
||||||
bool CheckItem_get(CheckItem* this);
|
|
||||||
|
|
||||||
void CheckItem_display(Object* cast, RichString* out);
|
void CheckItem_display(Object* cast, RichString* out);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,6 +23,7 @@ typedef struct ColorsPanel_ {
|
|||||||
|
|
||||||
Settings* settings;
|
Settings* settings;
|
||||||
ScreenManager* scr;
|
ScreenManager* scr;
|
||||||
|
bool check[5];
|
||||||
} ColorsPanel;
|
} ColorsPanel;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
@ -49,9 +50,10 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
|||||||
|
|
||||||
Panel_setHeader(super, "Colors");
|
Panel_setHeader(super, "Colors");
|
||||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
|
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), &(this->check[i])));
|
||||||
|
this->check[i] = false;
|
||||||
}
|
}
|
||||||
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
this->check[settings->colorScheme] = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +75,10 @@ HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
|
|||||||
case 0x0d:
|
case 0x0d:
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
case ' ':
|
case ' ':
|
||||||
for (int i = 0; ColorSchemes[i] != NULL; i++)
|
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||||
CheckItem_set((CheckItem*)Panel_get(super, i), false);
|
this->check[i] = false;
|
||||||
CheckItem_set((CheckItem*)Panel_get(super, mark), true);
|
}
|
||||||
|
this->check[mark] = true;
|
||||||
this->settings->colorScheme = mark;
|
this->settings->colorScheme = mark;
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ typedef struct ColorsPanel_ {
|
|||||||
|
|
||||||
Settings* settings;
|
Settings* settings;
|
||||||
ScreenManager* scr;
|
ScreenManager* scr;
|
||||||
|
bool check[5];
|
||||||
} ColorsPanel;
|
} ColorsPanel;
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,15 +44,6 @@ void ColumnsPanel_delete(Object* object) {
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ColumnsPanel_fieldNameToIndex(const char* name) {
|
|
||||||
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
|
|
||||||
if (String_eq(name, Process_fieldNames[j])) {
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnsPanel_update(Panel* super) {
|
void ColumnsPanel_update(Panel* super) {
|
||||||
ColumnsPanel* this = (ColumnsPanel*) super;
|
ColumnsPanel* this = (ColumnsPanel*) super;
|
||||||
int size = Panel_getSize(super);
|
int size = Panel_getSize(super);
|
||||||
@ -62,9 +53,12 @@ void ColumnsPanel_update(Panel* super) {
|
|||||||
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
|
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
char* text = ((ListItem*) Panel_get(super, i))->value;
|
char* text = ((ListItem*) Panel_get(super, i))->value;
|
||||||
int j = ColumnsPanel_fieldNameToIndex(text);
|
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
|
||||||
if (j > 0)
|
if (String_eq(text, Process_fieldNames[j])) {
|
||||||
this->settings->pl->fields[i] = j;
|
this->settings->pl->fields[i] = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this->settings->pl->fields[size] = 0;
|
this->settings->pl->fields[size] = 0;
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr);
|
|||||||
|
|
||||||
void ColumnsPanel_delete(Object* object);
|
void ColumnsPanel_delete(Object* object);
|
||||||
|
|
||||||
int ColumnsPanel_fieldNameToIndex(const char* name);
|
|
||||||
|
|
||||||
void ColumnsPanel_update(Panel* super);
|
void ColumnsPanel_update(Panel* super);
|
||||||
|
|
||||||
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch);
|
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch);
|
||||||
|
@ -49,11 +49,7 @@ void DebugMemory_new() {
|
|||||||
singleton->allocations = 0;
|
singleton->allocations = 0;
|
||||||
singleton->deallocations = 0;
|
singleton->deallocations = 0;
|
||||||
singleton->size = 0;
|
singleton->size = 0;
|
||||||
#ifdef DEBUG_ALLOC
|
|
||||||
singleton->file = fopen("/tmp/htop-debug-alloc.txt", "w");
|
singleton->file = fopen("/tmp/htop-debug-alloc.txt", "w");
|
||||||
#else
|
|
||||||
singleton->file = NULL;
|
|
||||||
#endif
|
|
||||||
singleton->totals = true;
|
singleton->totals = true;
|
||||||
//singleton->file = NULL;
|
//singleton->file = NULL;
|
||||||
}
|
}
|
||||||
|
@ -28,17 +28,16 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
|||||||
|
|
||||||
this->settings = settings;
|
this->settings = settings;
|
||||||
this->scr = scr;
|
this->scr = scr;
|
||||||
super->eventHandler = DisplayOptionsPanel_eventHandler;
|
super->eventHandler = DisplayOptionsPanel_EventHandler;
|
||||||
|
|
||||||
Panel_setHeader(super, "Display options");
|
Panel_setHeader(super, "Display options");
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false));
|
Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView)));
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
|
Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers)));
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
|
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads)));
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
|
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads)));
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
|
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName)));
|
||||||
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("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes)));
|
||||||
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("Leave a margin around header"), &(settings->header->margin)));
|
||||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ)"), &(settings->pl->detailedCPUTime), false));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ void DisplayOptionsPanel_delete(Object* object) {
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch) {
|
||||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
|
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
|
||||||
|
|
||||||
HandlerResult result = IGNORED;
|
HandlerResult result = IGNORED;
|
||||||
@ -60,7 +59,7 @@ HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
|||||||
case 0x0d:
|
case 0x0d:
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
case ' ':
|
case ' ':
|
||||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
*(selected->value) = ! *(selected->value);
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
|||||||
|
|
||||||
void DisplayOptionsPanel_delete(Object* object);
|
void DisplayOptionsPanel_delete(Object* object);
|
||||||
|
|
||||||
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch);
|
HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
91
Hashtable.c
91
Hashtable.c
@ -9,7 +9,6 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ typedef struct Hashtable_ Hashtable;
|
|||||||
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
||||||
|
|
||||||
typedef struct HashtableItem {
|
typedef struct HashtableItem {
|
||||||
unsigned int key;
|
int key;
|
||||||
void* value;
|
void* value;
|
||||||
struct HashtableItem* next;
|
struct HashtableItem* next;
|
||||||
} HashtableItem;
|
} HashtableItem;
|
||||||
@ -32,36 +31,7 @@ struct Hashtable_ {
|
|||||||
};
|
};
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#ifdef DEBUG
|
HashtableItem* HashtableItem_new(int key, void* value) {
|
||||||
|
|
||||||
bool Hashtable_isConsistent(Hashtable* this) {
|
|
||||||
int items = 0;
|
|
||||||
for (int i = 0; i < this->size; i++) {
|
|
||||||
HashtableItem* bucket = this->buckets[i];
|
|
||||||
while (bucket) {
|
|
||||||
items++;
|
|
||||||
bucket = bucket->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return items == this->items;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Hashtable_count(Hashtable* this) {
|
|
||||||
int items = 0;
|
|
||||||
for (int i = 0; i < this->size; i++) {
|
|
||||||
HashtableItem* bucket = this->buckets[i];
|
|
||||||
while (bucket) {
|
|
||||||
items++;
|
|
||||||
bucket = bucket->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(items == this->items);
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
HashtableItem* HashtableItem_new(unsigned int key, void* value) {
|
|
||||||
HashtableItem* this;
|
HashtableItem* this;
|
||||||
|
|
||||||
this = (HashtableItem*) malloc(sizeof(HashtableItem));
|
this = (HashtableItem*) malloc(sizeof(HashtableItem));
|
||||||
@ -75,16 +45,13 @@ Hashtable* Hashtable_new(int size, bool owner) {
|
|||||||
Hashtable* this;
|
Hashtable* this;
|
||||||
|
|
||||||
this = (Hashtable*) malloc(sizeof(Hashtable));
|
this = (Hashtable*) malloc(sizeof(Hashtable));
|
||||||
this->items = 0;
|
|
||||||
this->size = size;
|
this->size = size;
|
||||||
this->buckets = (HashtableItem**) calloc(sizeof(HashtableItem*), size);
|
this->buckets = (HashtableItem**) calloc(sizeof(HashtableItem*), size);
|
||||||
this->owner = owner;
|
this->owner = owner;
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hashtable_delete(Hashtable* this) {
|
void Hashtable_delete(Hashtable* this) {
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
for (int i = 0; i < this->size; i++) {
|
for (int i = 0; i < this->size; i++) {
|
||||||
HashtableItem* walk = this->buckets[i];
|
HashtableItem* walk = this->buckets[i];
|
||||||
while (walk != NULL) {
|
while (walk != NULL) {
|
||||||
@ -100,12 +67,11 @@ void Hashtable_delete(Hashtable* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline int Hashtable_size(Hashtable* this) {
|
inline int Hashtable_size(Hashtable* this) {
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
return this->items;
|
return this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
|
void Hashtable_put(Hashtable* this, int key, void* value) {
|
||||||
unsigned int index = key % this->size;
|
int index = key % this->size;
|
||||||
HashtableItem** bucketPtr = &(this->buckets[index]);
|
HashtableItem** bucketPtr = &(this->buckets[index]);
|
||||||
while (true)
|
while (true)
|
||||||
if (*bucketPtr == NULL) {
|
if (*bucketPtr == NULL) {
|
||||||
@ -119,53 +85,47 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
|
|||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
bucketPtr = &((*bucketPtr)->next);
|
bucketPtr = &((*bucketPtr)->next);
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Hashtable_remove(Hashtable* this, unsigned int key) {
|
void* Hashtable_remove(Hashtable* this, int key) {
|
||||||
unsigned int index = key % this->size;
|
int index = key % this->size;
|
||||||
|
HashtableItem** bucketPtr = &(this->buckets[index]);
|
||||||
assert(Hashtable_isConsistent(this));
|
while (true)
|
||||||
|
if (*bucketPtr == NULL) {
|
||||||
HashtableItem** bucket;
|
return NULL;
|
||||||
for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) {
|
break;
|
||||||
if ((*bucket)->key == key) {
|
} else if ((*bucketPtr)->key == key) {
|
||||||
void* value = (*bucket)->value;
|
void* savedValue = (*bucketPtr)->value;
|
||||||
HashtableItem* next = (*bucket)->next;
|
HashtableItem* savedNext = (*bucketPtr)->next;
|
||||||
free(*bucket);
|
free(*bucketPtr);
|
||||||
(*bucket) = next;
|
(*bucketPtr) = savedNext;
|
||||||
this->items--;
|
this->items--;
|
||||||
if (this->owner) {
|
if (this->owner) {
|
||||||
free(value);
|
free(savedValue);
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
assert(Hashtable_isConsistent(this));
|
return savedValue;
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
bucketPtr = &((*bucketPtr)->next);
|
||||||
}
|
}
|
||||||
}
|
//#include <stdio.h>
|
||||||
assert(Hashtable_isConsistent(this));
|
inline void* Hashtable_get(Hashtable* this, int key) {
|
||||||
return NULL;
|
int index = key % this->size;
|
||||||
}
|
|
||||||
|
|
||||||
inline void* Hashtable_get(Hashtable* this, unsigned int key) {
|
|
||||||
unsigned int index = key % this->size;
|
|
||||||
HashtableItem* bucketPtr = this->buckets[index];
|
HashtableItem* bucketPtr = this->buckets[index];
|
||||||
|
// fprintf(stderr, "%d -> %d\n", key, index);
|
||||||
while (true) {
|
while (true) {
|
||||||
if (bucketPtr == NULL) {
|
if (bucketPtr == NULL) {
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (bucketPtr->key == key) {
|
} else if (bucketPtr->key == key) {
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
return bucketPtr->value;
|
return bucketPtr->value;
|
||||||
} else
|
} else
|
||||||
bucketPtr = bucketPtr->next;
|
bucketPtr = bucketPtr->next;
|
||||||
|
// fprintf(stderr, "*\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) {
|
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) {
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
for (int i = 0; i < this->size; i++) {
|
for (int i = 0; i < this->size; i++) {
|
||||||
HashtableItem* walk = this->buckets[i];
|
HashtableItem* walk = this->buckets[i];
|
||||||
while (walk != NULL) {
|
while (walk != NULL) {
|
||||||
@ -173,5 +133,4 @@ void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData
|
|||||||
walk = walk->next;
|
walk = walk->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(Hashtable_isConsistent(this));
|
|
||||||
}
|
}
|
||||||
|
23
Hashtable.h
23
Hashtable.h
@ -12,7 +12,6 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ typedef struct Hashtable_ Hashtable;
|
|||||||
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
||||||
|
|
||||||
typedef struct HashtableItem {
|
typedef struct HashtableItem {
|
||||||
unsigned int key;
|
int key;
|
||||||
void* value;
|
void* value;
|
||||||
struct HashtableItem* next;
|
struct HashtableItem* next;
|
||||||
} HashtableItem;
|
} HashtableItem;
|
||||||
@ -33,27 +32,19 @@ struct Hashtable_ {
|
|||||||
bool owner;
|
bool owner;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef DEBUG
|
HashtableItem* HashtableItem_new(int key, void* value);
|
||||||
|
|
||||||
bool Hashtable_isConsistent(Hashtable* this);
|
|
||||||
|
|
||||||
int Hashtable_count(Hashtable* this);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
HashtableItem* HashtableItem_new(unsigned int key, void* value);
|
|
||||||
|
|
||||||
Hashtable* Hashtable_new(int size, bool owner);
|
Hashtable* Hashtable_new(int size, bool owner);
|
||||||
|
|
||||||
void Hashtable_delete(Hashtable* this);
|
void Hashtable_delete(Hashtable* this);
|
||||||
|
|
||||||
extern int Hashtable_size(Hashtable* this);
|
inline int Hashtable_size(Hashtable* this);
|
||||||
|
|
||||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
void Hashtable_put(Hashtable* this, int key, void* value);
|
||||||
|
|
||||||
void* Hashtable_remove(Hashtable* this, unsigned int key);
|
void* Hashtable_remove(Hashtable* this, int key);
|
||||||
|
//#include <stdio.h>
|
||||||
extern void* Hashtable_get(Hashtable* this, unsigned int key);
|
inline void* Hashtable_get(Hashtable* this, int key);
|
||||||
|
|
||||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
||||||
|
|
||||||
|
50
Makefile.am
50
Makefile.am
@ -11,42 +11,28 @@ pixmap_DATA = htop.png
|
|||||||
AM_CFLAGS = -pedantic -Wall -std=c99
|
AM_CFLAGS = -pedantic -Wall -std=c99
|
||||||
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
|
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||||
|
|
||||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
htop_SOURCES = AvailableMetersPanel.c CategoriesPanel.c ClockMeter.c \
|
||||||
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DebugMemory.c \
|
CPUMeter.c CRT.c DebugMemory.c DisplayOptionsPanel.c FunctionBar.c \
|
||||||
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
|
Hashtable.c Header.c htop.c Panel.c ListItem.c LoadAverageMeter.c \
|
||||||
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
|
MemoryMeter.c Meter.c MetersPanel.c Object.c Process.c \
|
||||||
Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
|
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \
|
||||||
SignalItem.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
|
SignalsPanel.c String.c SwapMeter.c TasksMeter.c Vector.c \
|
||||||
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c
|
UptimeMeter.c UsersTable.c AvailableMetersPanel.h CategoriesPanel.h \
|
||||||
|
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \
|
||||||
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
|
DisplayOptionsPanel.h FunctionBar.h Hashtable.h Header.h htop.h Panel.h \
|
||||||
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
|
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \
|
||||||
CPUMeter.h CRT.h DebugMemory.h DisplayOptionsPanel.h FunctionBar.h \
|
MetersPanel.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \
|
||||||
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
|
Settings.h SignalItem.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
|
||||||
Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
|
Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \
|
||||||
ScreenManager.h Settings.h SignalItem.h SignalsPanel.h String.h \
|
ColorsPanel.c ColorsPanel.h TraceScreen.c TraceScreen.h \
|
||||||
SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \
|
AvailableColumnsPanel.c AvailableColumnsPanel.h ColumnsPanel.c \
|
||||||
Process.h AffinityPanel.h
|
ColumnsPanel.h
|
||||||
|
|
||||||
SUFFIXES = .h
|
|
||||||
|
|
||||||
BUILT_SOURCES = $(myhtopheaders)
|
|
||||||
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h
|
|
||||||
|
|
||||||
profile:
|
profile:
|
||||||
$(MAKE) all CFLAGS="-pg -O2"
|
$(MAKE) all CFLAGS="-pg -O2"
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
$(MAKE) all CFLAGS="-ggdb -DDEBUG"
|
$(MAKE) all CFLAGS="-g -DDEBUG"
|
||||||
|
|
||||||
hardened-debug:
|
|
||||||
$(MAKE) all CFLAGS="-ggdb -DDEBUG" LDFLAGS="-nopie"
|
|
||||||
|
|
||||||
debuglite:
|
debuglite:
|
||||||
$(MAKE) all CFLAGS="-ggdb -DDEBUGLITE"
|
$(MAKE) all CFLAGS="-g -DDEBUGLITE"
|
||||||
|
|
||||||
.c.h:
|
|
||||||
scripts/MakeHeader.py $<
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
4
Panel.h
4
Panel.h
@ -72,9 +72,9 @@ void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner)
|
|||||||
|
|
||||||
void Panel_done(Panel* this);
|
void Panel_done(Panel* this);
|
||||||
|
|
||||||
extern void Panel_setRichHeader(Panel* this, RichString header);
|
inline void Panel_setRichHeader(Panel* this, RichString header);
|
||||||
|
|
||||||
extern void Panel_setHeader(Panel* this, char* header);
|
inline void Panel_setHeader(Panel* this, char* header);
|
||||||
|
|
||||||
void Panel_setEventHandler(Panel* this, Panel_EventHandler eh);
|
void Panel_setEventHandler(Panel* this, Panel_EventHandler eh);
|
||||||
|
|
||||||
|
105
Process.c
105
Process.c
@ -25,13 +25,10 @@ in the source distribution for its full text.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sched.h>
|
|
||||||
|
|
||||||
// This works only with glibc 2.1+. On earlier versions
|
// This works only with glibc 2.1+. On earlier versions
|
||||||
// the behavior is similar to have a hardcoded page size.
|
// the behavior is similar to have a hardcoded page size.
|
||||||
#ifndef PAGE_SIZE
|
|
||||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PROCESS_COMM_LEN 300
|
#define PROCESS_COMM_LEN 300
|
||||||
|
|
||||||
@ -42,11 +39,7 @@ typedef enum ProcessField_ {
|
|||||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||||
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
|
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
|
||||||
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
|
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
|
||||||
USER, TIME, NLWP, TGID
|
USER, TIME, LAST_PROCESSFIELD
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
VEID, VPID,
|
|
||||||
#endif
|
|
||||||
LAST_PROCESSFIELD
|
|
||||||
} ProcessField;
|
} ProcessField;
|
||||||
|
|
||||||
struct ProcessList_;
|
struct ProcessList_;
|
||||||
@ -57,16 +50,15 @@ typedef struct Process_ {
|
|||||||
struct ProcessList_ *pl;
|
struct ProcessList_ *pl;
|
||||||
bool updated;
|
bool updated;
|
||||||
|
|
||||||
unsigned int pid;
|
int pid;
|
||||||
char* comm;
|
char* comm;
|
||||||
int indent;
|
int indent;
|
||||||
char state;
|
char state;
|
||||||
bool tag;
|
bool tag;
|
||||||
unsigned int ppid;
|
int ppid;
|
||||||
unsigned int pgrp;
|
int pgrp;
|
||||||
unsigned int session;
|
int session;
|
||||||
unsigned int tty_nr;
|
int tty_nr;
|
||||||
unsigned int tgid;
|
|
||||||
int tpgid;
|
int tpgid;
|
||||||
unsigned long int flags;
|
unsigned long int flags;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -81,7 +73,6 @@ typedef struct Process_ {
|
|||||||
long int cstime;
|
long int cstime;
|
||||||
long int priority;
|
long int priority;
|
||||||
long int nice;
|
long int nice;
|
||||||
long int nlwp;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
long int itrealvalue;
|
long int itrealvalue;
|
||||||
unsigned long int starttime;
|
unsigned long int starttime;
|
||||||
@ -114,10 +105,6 @@ typedef struct Process_ {
|
|||||||
float percent_cpu;
|
float percent_cpu;
|
||||||
float percent_mem;
|
float percent_mem;
|
||||||
char* user;
|
char* user;
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
unsigned int veid;
|
|
||||||
unsigned int vpid;
|
|
||||||
#endif
|
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
@ -129,11 +116,7 @@ char* PROCESS_CLASS = "Process";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *Process_fieldNames[] = {
|
char *Process_fieldNames[] = {
|
||||||
"", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", "STARTTIME", "VSIZE", "RSS", "RLIM", "STARTCODE", "ENDCODE", "STARTSTACK", "KSTKESP", "KSTKEIP", "SIGNAL", "BLOCKED", "SIGIGNORE", "SIGCATCH", "WCHAN", "NSWAP", "CNSWAP", "EXIT_SIGNAL", "PROCESSOR", "M_SIZE", "M_RESIDENT", "M_SHARE", "M_TRS", "M_DRS", "M_LRS", "M_DT", "ST_UID", "PERCENT_CPU", "PERCENT_MEM", "USER", "TIME", "NLWP", "TGID",
|
"", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", "STARTTIME", "VSIZE", "RSS", "RLIM", "STARTCODE", "ENDCODE", "STARTSTACK", "KSTKESP", "KSTKEIP", "SIGNAL", "BLOCKED", "SIGIGNORE", "SIGCATCH", "WCHAN", "NSWAP", "CNSWAP", "EXIT_SIGNAL", "PROCESSOR", "M_SIZE", "M_RESIDENT", "M_SHARE", "M_TRS", "M_DRS", "M_LRS", "M_DT", "ST_UID", "PERCENT_CPU", "PERCENT_MEM", "USER", "TIME", "*** report bug! ***"
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
"VEID", "VPID",
|
|
||||||
#endif
|
|
||||||
"*** report bug! ***"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int Process_getuid = -1;
|
static int Process_getuid = -1;
|
||||||
@ -143,14 +126,12 @@ Process* Process_new(struct ProcessList_ *pl) {
|
|||||||
Object_setClass(this, PROCESS_CLASS);
|
Object_setClass(this, PROCESS_CLASS);
|
||||||
((Object*)this)->display = Process_display;
|
((Object*)this)->display = Process_display;
|
||||||
((Object*)this)->delete = Process_delete;
|
((Object*)this)->delete = Process_delete;
|
||||||
this->pid = 0;
|
|
||||||
this->pl = pl;
|
this->pl = pl;
|
||||||
this->tag = false;
|
this->tag = false;
|
||||||
this->updated = false;
|
this->updated = false;
|
||||||
this->utime = 0;
|
this->utime = 0;
|
||||||
this->stime = 0;
|
this->stime = 0;
|
||||||
this->comm = NULL;
|
this->comm = NULL;
|
||||||
this->indent = 0;
|
|
||||||
if (Process_getuid == -1) Process_getuid = getuid();
|
if (Process_getuid == -1) Process_getuid = getuid();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -158,15 +139,13 @@ Process* Process_new(struct ProcessList_ *pl) {
|
|||||||
Process* Process_clone(Process* this) {
|
Process* Process_clone(Process* this) {
|
||||||
Process* clone = malloc(sizeof(Process));
|
Process* clone = malloc(sizeof(Process));
|
||||||
memcpy(clone, this, sizeof(Process));
|
memcpy(clone, this, sizeof(Process));
|
||||||
this->comm = NULL;
|
|
||||||
this->pid = 0;
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_delete(Object* cast) {
|
void Process_delete(Object* cast) {
|
||||||
Process* this = (Process*) cast;
|
Process* this = (Process*) cast;
|
||||||
assert (this != NULL);
|
|
||||||
if (this->comm) free(this->comm);
|
if (this->comm) free(this->comm);
|
||||||
|
assert (this != NULL);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,16 +174,6 @@ void Process_setPriority(Process* this, int priority) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long Process_getAffinity(Process* this) {
|
|
||||||
unsigned long mask = 0;
|
|
||||||
sched_getaffinity(this->pid, sizeof(unsigned long), (cpu_set_t*) &mask);
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Process_setAffinity(Process* this, unsigned long mask) {
|
|
||||||
sched_setaffinity(this->pid, sizeof(unsigned long), (cpu_set_t*) &mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, int signal) {
|
void Process_sendSignal(Process* this, int signal) {
|
||||||
kill(this->pid, signal);
|
kill(this->pid, signal);
|
||||||
}
|
}
|
||||||
@ -213,26 +182,26 @@ void Process_sendSignal(Process* this, int signal) {
|
|||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
#define ONE_G (ONE_M * ONE_K)
|
#define ONE_G (ONE_M * ONE_K)
|
||||||
|
|
||||||
static void Process_printLargeNumber(Process* this, RichString *str, unsigned long number) {
|
static void Process_printLargeNumber(Process* this, RichString *str, unsigned int number) {
|
||||||
char buffer[11];
|
char buffer[11];
|
||||||
int len;
|
int len;
|
||||||
if(number >= (1000 * ONE_M)) {
|
if(number >= (1000 * ONE_M)) {
|
||||||
len = snprintf(buffer, 10, "%4.2fG ", (float)number / ONE_M);
|
len = snprintf(buffer, 10, "%4.2fG ", (float)number / ONE_M);
|
||||||
RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, len);
|
RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, len);
|
||||||
} else if(number >= (100000)) {
|
} else if(number >= (100000)) {
|
||||||
len = snprintf(buffer, 10, "%4ldM ", number / ONE_K);
|
len = snprintf(buffer, 10, "%4dM ", number / ONE_K);
|
||||||
int attr = this->pl->highlightMegabytes
|
int attr = this->pl->highlightMegabytes
|
||||||
? CRT_colors[PROCESS_MEGABYTES]
|
? CRT_colors[PROCESS_MEGABYTES]
|
||||||
: CRT_colors[PROCESS];
|
: CRT_colors[PROCESS];
|
||||||
RichString_appendn(str, attr, buffer, len);
|
RichString_appendn(str, attr, buffer, len);
|
||||||
} else if (this->pl->highlightMegabytes && number >= 1000) {
|
} else if (this->pl->highlightMegabytes && number >= 1000) {
|
||||||
len = snprintf(buffer, 10, "%2ld", number/1000);
|
len = snprintf(buffer, 10, "%2d", number/1000);
|
||||||
RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer, len);
|
RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer, len);
|
||||||
number %= 1000;
|
number %= 1000;
|
||||||
len = snprintf(buffer, 10, "%03ld ", number);
|
len = snprintf(buffer, 10, "%03d ", number);
|
||||||
RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
|
RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
|
||||||
} else {
|
} else {
|
||||||
len = snprintf(buffer, 10, "%5ld ", number);
|
len = snprintf(buffer, 10, "%5d ", number);
|
||||||
RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
|
RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,15 +257,13 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
int n = PROCESS_COMM_LEN;
|
int n = PROCESS_COMM_LEN;
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case PID: snprintf(buffer, n, "%5u ", this->pid); break;
|
case PID: snprintf(buffer, n, "%5d ", this->pid); break;
|
||||||
case PPID: snprintf(buffer, n, "%5u ", this->ppid); break;
|
case PPID: snprintf(buffer, n, "%5d ", this->ppid); break;
|
||||||
case PGRP: snprintf(buffer, n, "%5u ", this->pgrp); break;
|
case PGRP: snprintf(buffer, n, "%5d ", this->pgrp); break;
|
||||||
case SESSION: snprintf(buffer, n, "%5u ", this->session); break;
|
case SESSION: snprintf(buffer, n, "%5d ", this->session); break;
|
||||||
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
case TTY_NR: snprintf(buffer, n, "%5d ", this->tty_nr); break;
|
||||||
case TGID: snprintf(buffer, n, "%5u ", this->tgid); break;
|
|
||||||
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
|
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
|
||||||
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break;
|
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break;
|
||||||
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
|
|
||||||
case COMM: {
|
case COMM: {
|
||||||
if (!this->pl->treeView || this->indent == 0) {
|
if (!this->pl->treeView || this->indent == 0) {
|
||||||
Process_writeCommand(this, attr, str);
|
Process_writeCommand(this, attr, str);
|
||||||
@ -345,10 +312,6 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
: attr;
|
: attr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M_DRS: Process_printLargeNumber(this, str, this->m_drs * PAGE_SIZE); return;
|
|
||||||
case M_DT: Process_printLargeNumber(this, str, this->m_dt * PAGE_SIZE); return;
|
|
||||||
case M_LRS: Process_printLargeNumber(this, str, this->m_lrs * PAGE_SIZE); return;
|
|
||||||
case M_TRS: Process_printLargeNumber(this, str, this->m_trs * PAGE_SIZE); return;
|
|
||||||
case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE); return;
|
case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE); return;
|
||||||
case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return;
|
case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return;
|
||||||
case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return;
|
case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return;
|
||||||
@ -388,10 +351,6 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
case VEID: snprintf(buffer, n, "%5u ", this->veid); break;
|
|
||||||
case VPID: snprintf(buffer, n, "%5u ", this->vpid); break;
|
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
snprintf(buffer, n, "- ");
|
snprintf(buffer, n, "- ");
|
||||||
}
|
}
|
||||||
@ -428,14 +387,6 @@ int Process_compare(const void* v1, const void* v2) {
|
|||||||
return (p1->state - p2->state);
|
return (p1->state - p2->state);
|
||||||
case NICE:
|
case NICE:
|
||||||
return (p1->nice - p2->nice);
|
return (p1->nice - p2->nice);
|
||||||
case M_DRS:
|
|
||||||
return (p2->m_drs - p1->m_drs);
|
|
||||||
case M_DT:
|
|
||||||
return (p2->m_dt - p1->m_dt);
|
|
||||||
case M_LRS:
|
|
||||||
return (p2->m_lrs - p1->m_lrs);
|
|
||||||
case M_TRS:
|
|
||||||
return (p2->m_trs - p1->m_trs);
|
|
||||||
case M_SIZE:
|
case M_SIZE:
|
||||||
return (p2->m_size - p1->m_size);
|
return (p2->m_size - p1->m_size);
|
||||||
case M_RESIDENT:
|
case M_RESIDENT:
|
||||||
@ -454,14 +405,6 @@ int Process_compare(const void* v1, const void* v2) {
|
|||||||
return ((p2->utime+p2->stime) - (p1->utime+p1->stime));
|
return ((p2->utime+p2->stime) - (p1->utime+p1->stime));
|
||||||
case COMM:
|
case COMM:
|
||||||
return strcmp(p1->comm, p2->comm);
|
return strcmp(p1->comm, p2->comm);
|
||||||
case NLWP:
|
|
||||||
return (p1->nlwp - p2->nlwp);
|
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
case VEID:
|
|
||||||
return (p1->veid - p2->veid);
|
|
||||||
case VPID:
|
|
||||||
return (p1->vpid - p2->vpid);
|
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
return (p1->pid - p2->pid);
|
return (p1->pid - p2->pid);
|
||||||
}
|
}
|
||||||
@ -475,16 +418,11 @@ char* Process_printField(ProcessField field) {
|
|||||||
case PGRP: return " PGRP ";
|
case PGRP: return " PGRP ";
|
||||||
case SESSION: return " SESN ";
|
case SESSION: return " SESN ";
|
||||||
case TTY_NR: return " TTY ";
|
case TTY_NR: return " TTY ";
|
||||||
case TGID: return " TGID ";
|
case TPGID: return " TGID ";
|
||||||
case TPGID: return "TPGID ";
|
|
||||||
case COMM: return "Command ";
|
case COMM: return "Command ";
|
||||||
case STATE: return "S ";
|
case STATE: return "S ";
|
||||||
case PRIORITY: return "PRI ";
|
case PRIORITY: return "PRI ";
|
||||||
case NICE: return " NI ";
|
case NICE: return " NI ";
|
||||||
case M_DRS: return " DATA ";
|
|
||||||
case M_DT: return " DIRTY ";
|
|
||||||
case M_LRS: return " LIB ";
|
|
||||||
case M_TRS: return " CODE ";
|
|
||||||
case M_SIZE: return " VIRT ";
|
case M_SIZE: return " VIRT ";
|
||||||
case M_RESIDENT: return " RES ";
|
case M_RESIDENT: return " RES ";
|
||||||
case M_SHARE: return " SHR ";
|
case M_SHARE: return " SHR ";
|
||||||
@ -496,11 +434,6 @@ char* Process_printField(ProcessField field) {
|
|||||||
case PERCENT_CPU: return "CPU% ";
|
case PERCENT_CPU: return "CPU% ";
|
||||||
case PERCENT_MEM: return "MEM% ";
|
case PERCENT_MEM: return "MEM% ";
|
||||||
case PROCESSOR: return "CPU ";
|
case PROCESSOR: return "CPU ";
|
||||||
case NLWP: return "NLWP ";
|
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
case VEID: return " VEID ";
|
|
||||||
case VPID: return " VPID ";
|
|
||||||
#endif
|
|
||||||
default: return "- ";
|
default: return "- ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
Process.h
29
Process.h
@ -28,13 +28,10 @@ in the source distribution for its full text.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sched.h>
|
|
||||||
|
|
||||||
// This works only with glibc 2.1+. On earlier versions
|
// This works only with glibc 2.1+. On earlier versions
|
||||||
// the behavior is similar to have a hardcoded page size.
|
// the behavior is similar to have a hardcoded page size.
|
||||||
#ifndef PAGE_SIZE
|
|
||||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PROCESS_COMM_LEN 300
|
#define PROCESS_COMM_LEN 300
|
||||||
|
|
||||||
@ -44,11 +41,7 @@ typedef enum ProcessField_ {
|
|||||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||||
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
|
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
|
||||||
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
|
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
|
||||||
USER, TIME, NLWP, TGID,
|
USER, TIME, LAST_PROCESSFIELD
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
VEID, VPID,
|
|
||||||
#endif
|
|
||||||
LAST_PROCESSFIELD
|
|
||||||
} ProcessField;
|
} ProcessField;
|
||||||
|
|
||||||
struct ProcessList_;
|
struct ProcessList_;
|
||||||
@ -59,16 +52,15 @@ typedef struct Process_ {
|
|||||||
struct ProcessList_ *pl;
|
struct ProcessList_ *pl;
|
||||||
bool updated;
|
bool updated;
|
||||||
|
|
||||||
unsigned int pid;
|
int pid;
|
||||||
char* comm;
|
char* comm;
|
||||||
int indent;
|
int indent;
|
||||||
char state;
|
char state;
|
||||||
bool tag;
|
bool tag;
|
||||||
unsigned int ppid;
|
int ppid;
|
||||||
unsigned int pgrp;
|
int pgrp;
|
||||||
unsigned int session;
|
int session;
|
||||||
unsigned int tty_nr;
|
int tty_nr;
|
||||||
unsigned int tgid;
|
|
||||||
int tpgid;
|
int tpgid;
|
||||||
unsigned long int flags;
|
unsigned long int flags;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -83,7 +75,6 @@ typedef struct Process_ {
|
|||||||
long int cstime;
|
long int cstime;
|
||||||
long int priority;
|
long int priority;
|
||||||
long int nice;
|
long int nice;
|
||||||
long int nlwp;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
long int itrealvalue;
|
long int itrealvalue;
|
||||||
unsigned long int starttime;
|
unsigned long int starttime;
|
||||||
@ -116,10 +107,6 @@ typedef struct Process_ {
|
|||||||
float percent_cpu;
|
float percent_cpu;
|
||||||
float percent_mem;
|
float percent_mem;
|
||||||
char* user;
|
char* user;
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
unsigned int veid;
|
|
||||||
unsigned int vpid;
|
|
||||||
#endif
|
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
|
|
||||||
@ -143,10 +130,6 @@ void Process_toggleTag(Process* this);
|
|||||||
|
|
||||||
void Process_setPriority(Process* this, int priority);
|
void Process_setPriority(Process* this, int priority);
|
||||||
|
|
||||||
unsigned long Process_getAffinity(Process* this);
|
|
||||||
|
|
||||||
void Process_setAffinity(Process* this, unsigned long mask);
|
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, int signal);
|
void Process_sendSignal(Process* this, int signal);
|
||||||
|
|
||||||
#define ONE_K 1024
|
#define ONE_K 1024
|
||||||
|
213
ProcessList.c
213
ProcessList.c
@ -37,11 +37,11 @@ in the source distribution for its full text.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PROCSTATFILE
|
#ifndef PROCSTATFILE
|
||||||
#define PROCSTATFILE PROCDIR "/stat"
|
#define PROCSTATFILE "/proc/stat"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PROCMEMINFOFILE
|
#ifndef PROCMEMINFOFILE
|
||||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
#define PROCMEMINFOFILE "/proc/meminfo"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MAX_NAME
|
#ifndef MAX_NAME
|
||||||
@ -52,15 +52,11 @@ in the source distribution for its full text.
|
|||||||
#define MAX_READ 2048
|
#define MAX_READ 2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PER_PROCESSOR_FIELDS
|
|
||||||
#define PER_PROCESSOR_FIELDS 22
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
|
||||||
#ifdef DEBUG_PROC
|
#ifdef DEBUG
|
||||||
typedef int(*vxscanf)(void*, const char*, va_list);
|
typedef int(*vxscanf)(void*, const char*, va_list);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -75,29 +71,16 @@ typedef struct ProcessList_ {
|
|||||||
int totalTasks;
|
int totalTasks;
|
||||||
int runningTasks;
|
int runningTasks;
|
||||||
|
|
||||||
// Must match number of PER_PROCESSOR_FIELDS constant
|
|
||||||
unsigned long long int* totalTime;
|
unsigned long long int* totalTime;
|
||||||
unsigned long long int* userTime;
|
unsigned long long int* userTime;
|
||||||
unsigned long long int* systemTime;
|
unsigned long long int* systemTime;
|
||||||
unsigned long long int* systemAllTime;
|
|
||||||
unsigned long long int* idleAllTime;
|
|
||||||
unsigned long long int* idleTime;
|
unsigned long long int* idleTime;
|
||||||
unsigned long long int* niceTime;
|
unsigned long long int* niceTime;
|
||||||
unsigned long long int* ioWaitTime;
|
|
||||||
unsigned long long int* irqTime;
|
|
||||||
unsigned long long int* softIrqTime;
|
|
||||||
unsigned long long int* stealTime;
|
|
||||||
unsigned long long int* totalPeriod;
|
unsigned long long int* totalPeriod;
|
||||||
unsigned long long int* userPeriod;
|
unsigned long long int* userPeriod;
|
||||||
unsigned long long int* systemPeriod;
|
unsigned long long int* systemPeriod;
|
||||||
unsigned long long int* systemAllPeriod;
|
|
||||||
unsigned long long int* idleAllPeriod;
|
|
||||||
unsigned long long int* idlePeriod;
|
unsigned long long int* idlePeriod;
|
||||||
unsigned long long int* nicePeriod;
|
unsigned long long int* nicePeriod;
|
||||||
unsigned long long int* ioWaitPeriod;
|
|
||||||
unsigned long long int* irqPeriod;
|
|
||||||
unsigned long long int* softIrqPeriod;
|
|
||||||
unsigned long long int* stealPeriod;
|
|
||||||
|
|
||||||
unsigned long long int totalMem;
|
unsigned long long int totalMem;
|
||||||
unsigned long long int usedMem;
|
unsigned long long int usedMem;
|
||||||
@ -119,8 +102,7 @@ typedef struct ProcessList_ {
|
|||||||
bool treeView;
|
bool treeView;
|
||||||
bool highlightBaseName;
|
bool highlightBaseName;
|
||||||
bool highlightMegabytes;
|
bool highlightMegabytes;
|
||||||
bool detailedCPUTime;
|
#ifdef DEBUG
|
||||||
#ifdef DEBUG_PROC
|
|
||||||
FILE* traceFile;
|
FILE* traceFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -129,7 +111,7 @@ typedef struct ProcessList_ {
|
|||||||
|
|
||||||
static ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
static ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
|
|
||||||
#ifdef DEBUG_PROC
|
#ifdef DEBUG
|
||||||
|
|
||||||
#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ )
|
#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ )
|
||||||
#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ )
|
#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ )
|
||||||
@ -191,29 +173,18 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline void ProcessList_allocatePerProcessorBuffers(ProcessList* this, int procs) {
|
|
||||||
unsigned long long int** bufferPtr = &(this->totalTime);
|
|
||||||
unsigned long long int* buffer = calloc(procs * PER_PROCESSOR_FIELDS, sizeof(unsigned long long int));
|
|
||||||
for (int i = 0; i < PER_PROCESSOR_FIELDS; i++) {
|
|
||||||
*bufferPtr = buffer;
|
|
||||||
bufferPtr++;
|
|
||||||
buffer += procs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable) {
|
ProcessList* ProcessList_new(UsersTable* usersTable) {
|
||||||
ProcessList* this;
|
ProcessList* this;
|
||||||
this = malloc(sizeof(ProcessList));
|
this = malloc(sizeof(ProcessList));
|
||||||
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
||||||
this->processTable = Hashtable_new(70, false);
|
this->processTable = Hashtable_new(70, false);
|
||||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
|
||||||
this->prototype = Process_new(this);
|
this->prototype = Process_new(this);
|
||||||
this->usersTable = usersTable;
|
this->usersTable = usersTable;
|
||||||
|
|
||||||
/* tree-view auxiliary buffers */
|
/* tree-view auxiliary buffers */
|
||||||
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
||||||
|
|
||||||
#ifdef DEBUG_PROC
|
#ifdef DEBUG
|
||||||
this->traceFile = fopen("/tmp/htop-proc-trace", "w");
|
this->traceFile = fopen("/tmp/htop-proc-trace", "w");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -227,9 +198,16 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
|
|||||||
} while (String_startsWith(buffer, "cpu"));
|
} while (String_startsWith(buffer, "cpu"));
|
||||||
fclose(status);
|
fclose(status);
|
||||||
this->processorCount = procs - 1;
|
this->processorCount = procs - 1;
|
||||||
|
this->totalTime = calloc(procs, sizeof(long long int));
|
||||||
ProcessList_allocatePerProcessorBuffers(this, procs);
|
this->userTime = calloc(procs, sizeof(long long int));
|
||||||
|
this->systemTime = calloc(procs, sizeof(long long int));
|
||||||
|
this->niceTime = calloc(procs, sizeof(long long int));
|
||||||
|
this->idleTime = calloc(procs, sizeof(long long int));
|
||||||
|
this->totalPeriod = calloc(procs, sizeof(long long int));
|
||||||
|
this->userPeriod = calloc(procs, sizeof(long long int));
|
||||||
|
this->systemPeriod = calloc(procs, sizeof(long long int));
|
||||||
|
this->nicePeriod = calloc(procs, sizeof(long long int));
|
||||||
|
this->idlePeriod = calloc(procs, sizeof(long long int));
|
||||||
for (int i = 0; i < procs; i++) {
|
for (int i = 0; i < procs; i++) {
|
||||||
this->totalTime[i] = 1;
|
this->totalTime[i] = 1;
|
||||||
this->totalPeriod[i] = 1;
|
this->totalPeriod[i] = 1;
|
||||||
@ -250,7 +228,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
|
|||||||
this->treeView = false;
|
this->treeView = false;
|
||||||
this->highlightBaseName = false;
|
this->highlightBaseName = false;
|
||||||
this->highlightMegabytes = false;
|
this->highlightMegabytes = false;
|
||||||
this->detailedCPUTime = false;
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -261,11 +238,18 @@ void ProcessList_delete(ProcessList* this) {
|
|||||||
Vector_delete(this->processes2);
|
Vector_delete(this->processes2);
|
||||||
Process_delete((Object*)this->prototype);
|
Process_delete((Object*)this->prototype);
|
||||||
|
|
||||||
// Free first entry only;
|
|
||||||
// other fields are offsets of the same buffer
|
|
||||||
free(this->totalTime);
|
free(this->totalTime);
|
||||||
|
free(this->userTime);
|
||||||
|
free(this->systemTime);
|
||||||
|
free(this->niceTime);
|
||||||
|
free(this->idleTime);
|
||||||
|
free(this->totalPeriod);
|
||||||
|
free(this->userPeriod);
|
||||||
|
free(this->systemPeriod);
|
||||||
|
free(this->nicePeriod);
|
||||||
|
free(this->idlePeriod);
|
||||||
|
|
||||||
#ifdef DEBUG_PROC
|
#ifdef DEBUG
|
||||||
fclose(this->traceFile);
|
fclose(this->traceFile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -300,26 +284,14 @@ void ProcessList_prune(ProcessList* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_add(ProcessList* this, Process* p) {
|
void ProcessList_add(ProcessList* this, Process* p) {
|
||||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
|
|
||||||
assert(Hashtable_get(this->processTable, p->pid) == NULL);
|
|
||||||
Vector_add(this->processes, p);
|
Vector_add(this->processes, p);
|
||||||
Hashtable_put(this->processTable, p->pid, p);
|
Hashtable_put(this->processTable, p->pid, p);
|
||||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
|
||||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
|
||||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_remove(ProcessList* this, Process* p) {
|
void ProcessList_remove(ProcessList* this, Process* p) {
|
||||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
Hashtable_remove(this->processTable, p->pid);
|
||||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
|
||||||
Process* pp = Hashtable_remove(this->processTable, p->pid);
|
|
||||||
assert(pp == p); (void)pp;
|
|
||||||
unsigned int pid = p->pid;
|
|
||||||
int index = Vector_indexOf(this->processes, p, Process_pidCompare);
|
int index = Vector_indexOf(this->processes, p, Process_pidCompare);
|
||||||
assert(index != -1);
|
|
||||||
Vector_remove(this->processes, index);
|
Vector_remove(this->processes, index);
|
||||||
assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid;
|
|
||||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Process* ProcessList_get(ProcessList* this, int index) {
|
Process* ProcessList_get(ProcessList* this, int index) {
|
||||||
@ -333,22 +305,21 @@ int ProcessList_size(ProcessList* this) {
|
|||||||
static void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) {
|
static void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) {
|
||||||
Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE, Process_compare);
|
Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE, Process_compare);
|
||||||
|
|
||||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
for (int i = 0; i < Vector_size(this->processes); i++) {
|
||||||
Process* process = (Process*) (Vector_get(this->processes, i));
|
Process* process = (Process*) (Vector_get(this->processes, i));
|
||||||
if (process->tgid == pid || (process->tgid == process->pid && process->ppid == pid)) {
|
if (process->ppid == pid) {
|
||||||
Process* process = (Process*) (Vector_take(this->processes, i));
|
Process* process = (Process*) (Vector_take(this->processes, i));
|
||||||
Vector_add(children, process);
|
Vector_add(children, process);
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int size = Vector_size(children);
|
int size = Vector_size(children);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
Process* process = (Process*) (Vector_get(children, i));
|
Process* process = (Process*) (Vector_get(children, i));
|
||||||
int s = this->processes2->items;
|
|
||||||
if (direction == 1)
|
if (direction == 1)
|
||||||
Vector_add(this->processes2, process);
|
Vector_add(this->processes2, process);
|
||||||
else
|
else
|
||||||
Vector_insert(this->processes2, 0, process);
|
Vector_insert(this->processes2, 0, process);
|
||||||
assert(this->processes2->items == s+1); (void)s;
|
|
||||||
int nextIndent = indent;
|
int nextIndent = indent;
|
||||||
if (i < size - 1)
|
if (i < size - 1)
|
||||||
nextIndent = indent | (1 << level);
|
nextIndent = indent | (1 << level);
|
||||||
@ -362,34 +333,18 @@ void ProcessList_sort(ProcessList* this) {
|
|||||||
if (!this->treeView) {
|
if (!this->treeView) {
|
||||||
Vector_sort(this->processes);
|
Vector_sort(this->processes);
|
||||||
} else {
|
} else {
|
||||||
// Save settings
|
|
||||||
int direction = this->direction;
|
int direction = this->direction;
|
||||||
int sortKey = this->sortKey;
|
int sortKey = this->sortKey;
|
||||||
// Sort by PID
|
|
||||||
this->sortKey = PID;
|
this->sortKey = PID;
|
||||||
this->direction = 1;
|
this->direction = 1;
|
||||||
Vector_sort(this->processes);
|
Vector_sort(this->processes);
|
||||||
// Restore settings
|
|
||||||
this->sortKey = sortKey;
|
this->sortKey = sortKey;
|
||||||
this->direction = direction;
|
this->direction = direction;
|
||||||
// Take PID 1 as root and add to the new listing
|
|
||||||
int vsize = Vector_size(this->processes);
|
|
||||||
Process* init = (Process*) (Vector_take(this->processes, 0));
|
Process* init = (Process*) (Vector_take(this->processes, 0));
|
||||||
assert(init->pid == 1);
|
assert(init->pid == 1);
|
||||||
init->indent = 0;
|
init->indent = 0;
|
||||||
Vector_add(this->processes2, init);
|
Vector_add(this->processes2, init);
|
||||||
// Recursively empty list
|
|
||||||
ProcessList_buildTree(this, init->pid, 0, 0, direction);
|
ProcessList_buildTree(this, init->pid, 0, 0, direction);
|
||||||
// Add leftovers
|
|
||||||
while (Vector_size(this->processes)) {
|
|
||||||
Process* p = (Process*) (Vector_take(this->processes, 0));
|
|
||||||
p->indent = 0;
|
|
||||||
Vector_add(this->processes2, p);
|
|
||||||
ProcessList_buildTree(this, p->pid, 0, 0, direction);
|
|
||||||
}
|
|
||||||
assert(Vector_size(this->processes2) == vsize); (void)vsize;
|
|
||||||
assert(Vector_size(this->processes) == 0);
|
|
||||||
// Swap listings around
|
|
||||||
Vector* t = this->processes;
|
Vector* t = this->processes;
|
||||||
this->processes = this->processes2;
|
this->processes = this->processes2;
|
||||||
this->processes2 = t;
|
this->processes2 = t;
|
||||||
@ -403,7 +358,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
|||||||
int size = fread(buf, 1, MAX_READ, f);
|
int size = fread(buf, 1, MAX_READ, f);
|
||||||
if(!size) return 0;
|
if(!size) return 0;
|
||||||
|
|
||||||
assert(proc->pid == atoi(buf));
|
proc->pid = atoi(buf);
|
||||||
char *location = strchr(buf, ' ');
|
char *location = strchr(buf, ' ');
|
||||||
if(!location) return 0;
|
if(!location) return 0;
|
||||||
|
|
||||||
@ -416,9 +371,9 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
|||||||
command[commsize] = '\0';
|
command[commsize] = '\0';
|
||||||
location = end + 2;
|
location = end + 2;
|
||||||
|
|
||||||
#ifdef DEBUG_PROC
|
#ifdef DEBUG
|
||||||
int num = ProcessList_read(this, location,
|
int num = ProcessList_read(this, location,
|
||||||
"%c %u %u %u %u %d %lu %lu %lu %lu "
|
"%c %d %d %d %d %d %lu %lu %lu %lu "
|
||||||
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
||||||
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
||||||
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
||||||
@ -427,7 +382,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
|||||||
&proc->tpgid, &proc->flags,
|
&proc->tpgid, &proc->flags,
|
||||||
&proc->minflt, &proc->cminflt, &proc->majflt, &proc->cmajflt,
|
&proc->minflt, &proc->cminflt, &proc->majflt, &proc->cmajflt,
|
||||||
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
||||||
&proc->priority, &proc->nice, &proc->nlwp, &proc->itrealvalue,
|
&proc->priority, &proc->nice, &zero, &proc->itrealvalue,
|
||||||
&proc->starttime, &proc->vsize, &proc->rss, &proc->rlim,
|
&proc->starttime, &proc->vsize, &proc->rss, &proc->rlim,
|
||||||
&proc->startcode, &proc->endcode, &proc->startstack, &proc->kstkesp,
|
&proc->startcode, &proc->endcode, &proc->startstack, &proc->kstkesp,
|
||||||
&proc->kstkeip, &proc->signal, &proc->blocked, &proc->sigignore,
|
&proc->kstkeip, &proc->signal, &proc->blocked, &proc->sigignore,
|
||||||
@ -436,7 +391,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
|||||||
#else
|
#else
|
||||||
long int uzero;
|
long int uzero;
|
||||||
int num = ProcessList_read(this, location,
|
int num = ProcessList_read(this, location,
|
||||||
"%c %u %u %u %u %d %lu %lu %lu %lu "
|
"%c %d %d %d %d %d %lu %lu %lu %lu "
|
||||||
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
||||||
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
||||||
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
||||||
@ -445,7 +400,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
|||||||
&proc->tpgid, &proc->flags,
|
&proc->tpgid, &proc->flags,
|
||||||
&zero, &zero, &zero, &zero,
|
&zero, &zero, &zero, &zero,
|
||||||
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
||||||
&proc->priority, &proc->nice, &proc->nlwp, &uzero,
|
&proc->priority, &proc->nice, &uzero, &uzero,
|
||||||
&zero, &zero, &uzero, &zero,
|
&zero, &zero, &uzero, &zero,
|
||||||
&zero, &zero, &zero, &zero,
|
&zero, &zero, &zero, &zero,
|
||||||
&zero, &zero, &zero, &zero,
|
&zero, &zero, &zero, &zero,
|
||||||
@ -464,12 +419,10 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
|||||||
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
||||||
char statusfilename[MAX_NAME+1];
|
char statusfilename[MAX_NAME+1];
|
||||||
statusfilename[MAX_NAME] = '\0';
|
statusfilename[MAX_NAME] = '\0';
|
||||||
|
/*
|
||||||
bool success = false;
|
bool success = false;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
buffer[255] = '\0';
|
buffer[255] = '\0';
|
||||||
|
|
||||||
// We need to parse the status file just for tgid, which is missing in stat.
|
|
||||||
snprintf(statusfilename, MAX_NAME, "%s/%s/status", dirname, name);
|
snprintf(statusfilename, MAX_NAME, "%s/%s/status", dirname, name);
|
||||||
FILE* status = ProcessList_fopen(this, statusfilename, "r");
|
FILE* status = ProcessList_fopen(this, statusfilename, "r");
|
||||||
if (status) {
|
if (status) {
|
||||||
@ -477,11 +430,12 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
|||||||
char* ok = fgets(buffer, 255, status);
|
char* ok = fgets(buffer, 255, status);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
break;
|
break;
|
||||||
if (String_startsWith(buffer, "Tgid:")) {
|
if (String_startsWith(buffer, "Uid:")) {
|
||||||
int tgid;
|
int uid1, uid2, uid3, uid4;
|
||||||
int ok = ProcessList_read(this, buffer, "Tgid:\t%d", &tgid);
|
// TODO: handle other uid's.
|
||||||
|
int ok = ProcessList_read(this, buffer, "Uid:\t%d\t%d\t%d\t%d", &uid1, &uid2, &uid3, &uid4);
|
||||||
if (ok >= 1) {
|
if (ok >= 1) {
|
||||||
proc->tgid = tgid;
|
proc->st_uid = uid1;
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -489,6 +443,8 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
|||||||
}
|
}
|
||||||
fclose(status);
|
fclose(status);
|
||||||
}
|
}
|
||||||
|
if (!success) {
|
||||||
|
*/
|
||||||
snprintf(statusfilename, MAX_NAME, "%s/%s", dirname, name);
|
snprintf(statusfilename, MAX_NAME, "%s/%s", dirname, name);
|
||||||
struct stat sstat;
|
struct stat sstat;
|
||||||
int statok = stat(statusfilename, &sstat);
|
int statok = stat(statusfilename, &sstat);
|
||||||
@ -496,6 +452,10 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
|||||||
return false;
|
return false;
|
||||||
proc->st_uid = sstat.st_uid;
|
proc->st_uid = sstat.st_uid;
|
||||||
return true;
|
return true;
|
||||||
|
/*
|
||||||
|
} else
|
||||||
|
return true;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, float period) {
|
void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, float period) {
|
||||||
@ -504,7 +464,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
|||||||
Process* prototype = this->prototype;
|
Process* prototype = this->prototype;
|
||||||
|
|
||||||
dir = opendir(dirname);
|
dir = opendir(dirname);
|
||||||
if (!dir) return;
|
assert(dir != NULL);
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
char* name = entry->d_name;
|
char* name = entry->d_name;
|
||||||
int pid;
|
int pid;
|
||||||
@ -526,24 +486,23 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
|||||||
char subdirname[MAX_NAME+1];
|
char subdirname[MAX_NAME+1];
|
||||||
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
|
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
|
||||||
|
|
||||||
|
if (access(subdirname, X_OK) == 0) {
|
||||||
ProcessList_processEntries(this, subdirname, pid, period);
|
ProcessList_processEntries(this, subdirname, pid, period);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FILE* status;
|
FILE* status;
|
||||||
char statusfilename[MAX_NAME+1];
|
char statusfilename[MAX_NAME+1];
|
||||||
char command[PROCESS_COMM_LEN + 1];
|
char command[PROCESS_COMM_LEN + 1];
|
||||||
|
|
||||||
Process* process = NULL;
|
Process* process;
|
||||||
|
|
||||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
|
||||||
Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid);
|
Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid);
|
||||||
if (existingProcess) {
|
if (existingProcess) {
|
||||||
assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1);
|
|
||||||
process = existingProcess;
|
process = existingProcess;
|
||||||
assert(process->pid == pid);
|
|
||||||
} else {
|
} else {
|
||||||
process = prototype;
|
process = prototype;
|
||||||
assert(process->comm == NULL);
|
process->comm = NULL;
|
||||||
process->pid = pid;
|
process->pid = pid;
|
||||||
if (! ProcessList_readStatusFile(this, process, dirname, name))
|
if (! ProcessList_readStatusFile(this, process, dirname, name))
|
||||||
goto errorReadingProcess;
|
goto errorReadingProcess;
|
||||||
@ -558,7 +517,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
|||||||
}
|
}
|
||||||
int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d",
|
int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d",
|
||||||
&process->m_size, &process->m_resident, &process->m_share,
|
&process->m_size, &process->m_resident, &process->m_share,
|
||||||
&process->m_trs, &process->m_lrs, &process->m_drs,
|
&process->m_trs, &process->m_drs, &process->m_lrs,
|
||||||
&process->m_dt);
|
&process->m_dt);
|
||||||
|
|
||||||
fclose(status);
|
fclose(status);
|
||||||
@ -584,28 +543,6 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
|||||||
if(!existingProcess) {
|
if(!existingProcess) {
|
||||||
process->user = UsersTable_getRef(this->usersTable, process->st_uid);
|
process->user = UsersTable_getRef(this->usersTable, process->st_uid);
|
||||||
|
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
if (access("/proc/vz", R_OK) != 0) {
|
|
||||||
process->vpid = process->pid;
|
|
||||||
process->veid = 0;
|
|
||||||
} else {
|
|
||||||
snprintf(statusfilename, MAX_NAME, "%s/%s/stat", dirname, name);
|
|
||||||
status = ProcessList_fopen(this, statusfilename, "r");
|
|
||||||
if (status == NULL)
|
|
||||||
goto errorReadingProcess;
|
|
||||||
num = ProcessList_fread(this, status,
|
|
||||||
"%*u %*s %*c %*u %*u %*u %*u %*u %*u %*u "
|
|
||||||
"%*u %*u %*u %*u %*u %*u %*u %*u "
|
|
||||||
"%*u %*u %*u %*u %*u %*u %*u %*u "
|
|
||||||
"%*u %*u %*u %*u %*u %*u %*u %*u "
|
|
||||||
"%*u %*u %*u %*u %*u %*u %*u %*u "
|
|
||||||
"%*u %*u %*u %*u %*u %*u %*u "
|
|
||||||
"%u %u",
|
|
||||||
&process->vpid, &process->veid);
|
|
||||||
fclose(status);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
snprintf(statusfilename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
snprintf(statusfilename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
||||||
status = ProcessList_fopen(this, statusfilename, "r");
|
status = ProcessList_fopen(this, statusfilename, "r");
|
||||||
if (!status) {
|
if (!status) {
|
||||||
@ -627,8 +564,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
|||||||
process->percent_cpu = (process->utime + process->stime - lasttimes) /
|
process->percent_cpu = (process->utime + process->stime - lasttimes) /
|
||||||
period * 100.0;
|
period * 100.0;
|
||||||
|
|
||||||
process->percent_mem = (process->m_resident * PAGE_SIZE) /
|
process->percent_mem = process->m_resident /
|
||||||
(float)(this->totalMem) *
|
(float)(this->usedMem - this->cachedMem - this->buffersMem) *
|
||||||
100.0;
|
100.0;
|
||||||
|
|
||||||
this->totalTasks++;
|
this->totalTasks++;
|
||||||
@ -637,28 +574,29 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!existingProcess) {
|
if (!existingProcess) {
|
||||||
ProcessList_add(this, Process_clone(process));
|
process = Process_clone(process);
|
||||||
|
ProcessList_add(this, process);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Exception handler.
|
// Exception handler.
|
||||||
errorReadingProcess: {
|
errorReadingProcess: {
|
||||||
if (process->comm) {
|
|
||||||
free(process->comm);
|
|
||||||
process->comm = NULL;
|
|
||||||
}
|
|
||||||
if (existingProcess)
|
if (existingProcess)
|
||||||
ProcessList_remove(this, process);
|
ProcessList_remove(this, process);
|
||||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
else {
|
||||||
|
if (process->comm)
|
||||||
|
free(process->comm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
prototype->comm = NULL;
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_scan(ProcessList* this) {
|
void ProcessList_scan(ProcessList* this) {
|
||||||
unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime;
|
unsigned long long int usertime, nicetime, systemtime, idletime, totaltime;
|
||||||
unsigned long long int swapFree;
|
unsigned long long int swapFree;
|
||||||
|
|
||||||
FILE* status;
|
FILE* status;
|
||||||
@ -718,41 +656,22 @@ void ProcessList_scan(ProcessList* this) {
|
|||||||
}
|
}
|
||||||
// Fields existing on kernels >= 2.6
|
// Fields existing on kernels >= 2.6
|
||||||
// (and RHEL's patched kernel 2.4...)
|
// (and RHEL's patched kernel 2.4...)
|
||||||
idlealltime = idletime + ioWait;
|
systemtime += ioWait + irq + softIrq + steal;
|
||||||
systemalltime = systemtime + irq + softIrq + steal;
|
totaltime = usertime + nicetime + systemtime + idletime;
|
||||||
totaltime = usertime + nicetime + systemalltime + idlealltime;
|
|
||||||
assert (usertime >= this->userTime[i]);
|
assert (usertime >= this->userTime[i]);
|
||||||
assert (nicetime >= this->niceTime[i]);
|
assert (nicetime >= this->niceTime[i]);
|
||||||
assert (systemtime >= this->systemTime[i]);
|
assert (systemtime >= this->systemTime[i]);
|
||||||
assert (idletime >= this->idleTime[i]);
|
assert (idletime >= this->idleTime[i]);
|
||||||
assert (totaltime >= this->totalTime[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]);
|
|
||||||
assert (steal >= this->stealTime[i]);
|
|
||||||
this->userPeriod[i] = usertime - this->userTime[i];
|
this->userPeriod[i] = usertime - this->userTime[i];
|
||||||
this->nicePeriod[i] = nicetime - this->niceTime[i];
|
this->nicePeriod[i] = nicetime - this->niceTime[i];
|
||||||
this->systemPeriod[i] = systemtime - this->systemTime[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->idlePeriod[i] = idletime - this->idleTime[i];
|
||||||
this->ioWaitPeriod[i] = ioWait - this->ioWaitTime[i];
|
|
||||||
this->irqPeriod[i] = irq - this->irqTime[i];
|
|
||||||
this->softIrqPeriod[i] = softIrq - this->softIrqTime[i];
|
|
||||||
this->stealPeriod[i] = steal - this->stealTime[i];
|
|
||||||
this->totalPeriod[i] = totaltime - this->totalTime[i];
|
this->totalPeriod[i] = totaltime - this->totalTime[i];
|
||||||
this->userTime[i] = usertime;
|
this->userTime[i] = usertime;
|
||||||
this->niceTime[i] = nicetime;
|
this->niceTime[i] = nicetime;
|
||||||
this->systemTime[i] = systemtime;
|
this->systemTime[i] = systemtime;
|
||||||
this->systemAllTime[i] = systemalltime;
|
|
||||||
this->idleAllTime[i] = idlealltime;
|
|
||||||
this->idleTime[i] = idletime;
|
this->idleTime[i] = idletime;
|
||||||
this->ioWaitTime[i] = ioWait;
|
|
||||||
this->irqTime[i] = irq;
|
|
||||||
this->softIrqTime[i] = softIrq;
|
|
||||||
this->stealTime[i] = steal;
|
|
||||||
this->totalTime[i] = totaltime;
|
this->totalTime[i] = totaltime;
|
||||||
}
|
}
|
||||||
float period = (float)this->totalPeriod[0] / this->processorCount;
|
float period = (float)this->totalPeriod[0] / this->processorCount;
|
||||||
|
@ -39,11 +39,11 @@ in the source distribution for its full text.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PROCSTATFILE
|
#ifndef PROCSTATFILE
|
||||||
#define PROCSTATFILE PROCDIR "/stat"
|
#define PROCSTATFILE "/proc/stat"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PROCMEMINFOFILE
|
#ifndef PROCMEMINFOFILE
|
||||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
#define PROCMEMINFOFILE "/proc/meminfo"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MAX_NAME
|
#ifndef MAX_NAME
|
||||||
@ -54,13 +54,9 @@ in the source distribution for its full text.
|
|||||||
#define MAX_READ 2048
|
#define MAX_READ 2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PER_PROCESSOR_FIELDS
|
|
||||||
#define PER_PROCESSOR_FIELDS 22
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
#ifdef DEBUG_PROC
|
|
||||||
typedef int(*vxscanf)(void*, const char*, va_list);
|
typedef int(*vxscanf)(void*, const char*, va_list);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -75,29 +71,16 @@ typedef struct ProcessList_ {
|
|||||||
int totalTasks;
|
int totalTasks;
|
||||||
int runningTasks;
|
int runningTasks;
|
||||||
|
|
||||||
// Must match number of PER_PROCESSOR_FIELDS constant
|
|
||||||
unsigned long long int* totalTime;
|
unsigned long long int* totalTime;
|
||||||
unsigned long long int* userTime;
|
unsigned long long int* userTime;
|
||||||
unsigned long long int* systemTime;
|
unsigned long long int* systemTime;
|
||||||
unsigned long long int* systemAllTime;
|
|
||||||
unsigned long long int* idleAllTime;
|
|
||||||
unsigned long long int* idleTime;
|
unsigned long long int* idleTime;
|
||||||
unsigned long long int* niceTime;
|
unsigned long long int* niceTime;
|
||||||
unsigned long long int* ioWaitTime;
|
|
||||||
unsigned long long int* irqTime;
|
|
||||||
unsigned long long int* softIrqTime;
|
|
||||||
unsigned long long int* stealTime;
|
|
||||||
unsigned long long int* totalPeriod;
|
unsigned long long int* totalPeriod;
|
||||||
unsigned long long int* userPeriod;
|
unsigned long long int* userPeriod;
|
||||||
unsigned long long int* systemPeriod;
|
unsigned long long int* systemPeriod;
|
||||||
unsigned long long int* systemAllPeriod;
|
|
||||||
unsigned long long int* idleAllPeriod;
|
|
||||||
unsigned long long int* idlePeriod;
|
unsigned long long int* idlePeriod;
|
||||||
unsigned long long int* nicePeriod;
|
unsigned long long int* nicePeriod;
|
||||||
unsigned long long int* ioWaitPeriod;
|
|
||||||
unsigned long long int* irqPeriod;
|
|
||||||
unsigned long long int* softIrqPeriod;
|
|
||||||
unsigned long long int* stealPeriod;
|
|
||||||
|
|
||||||
unsigned long long int totalMem;
|
unsigned long long int totalMem;
|
||||||
unsigned long long int usedMem;
|
unsigned long long int usedMem;
|
||||||
@ -119,14 +102,13 @@ typedef struct ProcessList_ {
|
|||||||
bool treeView;
|
bool treeView;
|
||||||
bool highlightBaseName;
|
bool highlightBaseName;
|
||||||
bool highlightMegabytes;
|
bool highlightMegabytes;
|
||||||
bool detailedCPUTime;
|
#ifdef DEBUG
|
||||||
#ifdef DEBUG_PROC
|
|
||||||
FILE* traceFile;
|
FILE* traceFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} ProcessList;
|
} ProcessList;
|
||||||
|
|
||||||
#ifdef DEBUG_PROC
|
#ifdef DEBUG
|
||||||
|
|
||||||
#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ )
|
#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ )
|
||||||
#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ )
|
#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ )
|
||||||
|
18
RichString.c
18
RichString.c
@ -26,21 +26,21 @@ typedef struct RichString_ {
|
|||||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
|
void RichString_write(RichString* this, int attrs, char* data) {
|
||||||
int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
|
RichString_init(this);
|
||||||
for (int i = this->len, j = 0; i < last; i++, j++)
|
RichString_append(this, attrs, data);
|
||||||
this->chstr[i] = data[j] | attrs;
|
|
||||||
this->chstr[last] = 0;
|
|
||||||
this->len = last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void RichString_append(RichString* this, int attrs, char* data) {
|
inline void RichString_append(RichString* this, int attrs, char* data) {
|
||||||
RichString_appendn(this, attrs, data, strlen(data));
|
RichString_appendn(this, attrs, data, strlen(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichString_write(RichString* this, int attrs, char* data) {
|
inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
|
||||||
RichString_init(this);
|
int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
|
||||||
RichString_append(this, attrs, data);
|
for (int i = this->len, j = 0; i < last; i++, j++)
|
||||||
|
this->chstr[i] = data[j] | attrs;
|
||||||
|
this->chstr[last] = 0;
|
||||||
|
this->len = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichString_setAttr(RichString *this, int attrs) {
|
void RichString_setAttr(RichString *this, int attrs) {
|
||||||
|
@ -27,12 +27,12 @@ typedef struct RichString_ {
|
|||||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void RichString_appendn(RichString* this, int attrs, char* data, int len);
|
|
||||||
|
|
||||||
extern void RichString_append(RichString* this, int attrs, char* data);
|
|
||||||
|
|
||||||
void RichString_write(RichString* this, int attrs, char* data);
|
void RichString_write(RichString* this, int attrs, char* data);
|
||||||
|
|
||||||
|
inline void RichString_append(RichString* this, int attrs, char* data);
|
||||||
|
|
||||||
|
inline void RichString_appendn(RichString* this, int attrs, char* data, int len);
|
||||||
|
|
||||||
void RichString_setAttr(RichString *this, int attrs);
|
void RichString_setAttr(RichString *this, int attrs);
|
||||||
|
|
||||||
void RichString_applyAttr(RichString *this, int attrs);
|
void RichString_applyAttr(RichString *this, int attrs);
|
||||||
|
@ -43,7 +43,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
|
|||||||
|
|
||||||
void ScreenManager_delete(ScreenManager* this);
|
void ScreenManager_delete(ScreenManager* this);
|
||||||
|
|
||||||
extern int ScreenManager_size(ScreenManager* this);
|
inline int ScreenManager_size(ScreenManager* this);
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size);
|
void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size);
|
||||||
|
|
||||||
|
@ -139,11 +139,6 @@ bool Settings_read(Settings* this, char* fileName) {
|
|||||||
this->pl->highlightMegabytes = atoi(option[1]);
|
this->pl->highlightMegabytes = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "header_margin")) {
|
} else if (String_eq(option[0], "header_margin")) {
|
||||||
this->header->margin = atoi(option[1]);
|
this->header->margin = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "expand_system_time")) {
|
|
||||||
// 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")) {
|
} else if (String_eq(option[0], "delay")) {
|
||||||
this->delay = atoi(option[1]);
|
this->delay = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "color_scheme")) {
|
} else if (String_eq(option[0], "color_scheme")) {
|
||||||
@ -200,7 +195,6 @@ bool Settings_write(Settings* this) {
|
|||||||
fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes);
|
fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes);
|
||||||
fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView);
|
fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView);
|
||||||
fprintf(fd, "header_margin=%d\n", (int) this->header->margin);
|
fprintf(fd, "header_margin=%d\n", (int) this->header->margin);
|
||||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime);
|
|
||||||
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
||||||
fprintf(fd, "delay=%d\n", (int) this->delay);
|
fprintf(fd, "delay=%d\n", (int) this->delay);
|
||||||
fprintf(fd, "left_meters=");
|
fprintf(fd, "left_meters=");
|
||||||
@ -224,7 +218,6 @@ bool Settings_write(Settings* this) {
|
|||||||
fprintf(fd, "right_meter_modes=");
|
fprintf(fd, "right_meter_modes=");
|
||||||
for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++)
|
for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++)
|
||||||
fprintf(fd, "%d ", Header_readMeterMode(this->header, i, RIGHT_HEADER));
|
fprintf(fd, "%d ", Header_readMeterMode(this->header, i, RIGHT_HEADER));
|
||||||
fprintf(fd, "\n");
|
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
|
|||||||
((Object*)this)->delete = SignalsPanel_delete;
|
((Object*)this)->delete = SignalsPanel_delete;
|
||||||
|
|
||||||
this->signals = Signal_getSignalTable();
|
this->signals = Signal_getSignalTable();
|
||||||
super->eventHandler = SignalsPanel_eventHandler;
|
super->eventHandler = SignalsPanel_EventHandler;
|
||||||
int sigCount = Signal_getSignalCount();
|
int sigCount = Signal_getSignalCount();
|
||||||
for(int i = 0; i < sigCount; i++)
|
for(int i = 0; i < sigCount; i++)
|
||||||
Panel_set(super, i, (Object*) this->signals[i]);
|
Panel_set(super, i, (Object*) this->signals[i]);
|
||||||
@ -51,7 +51,7 @@ void SignalsPanel_reset(SignalsPanel* this) {
|
|||||||
this->state = 0;
|
this->state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
|
HandlerResult SignalsPanel_EventHandler(Panel* super, int ch) {
|
||||||
SignalsPanel* this = (SignalsPanel*) super;
|
SignalsPanel* this = (SignalsPanel*) super;
|
||||||
|
|
||||||
int size = Panel_getSize(super);
|
int size = Panel_getSize(super);
|
||||||
|
@ -27,6 +27,6 @@ void SignalsPanel_delete(Object* object);
|
|||||||
|
|
||||||
void SignalsPanel_reset(SignalsPanel* this);
|
void SignalsPanel_reset(SignalsPanel* this);
|
||||||
|
|
||||||
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch);
|
HandlerResult SignalsPanel_EventHandler(Panel* super, int ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2
String.c
2
String.c
@ -96,7 +96,7 @@ void String_printPointer(void* p) {
|
|||||||
printf("%p", p);
|
printf("%p", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int String_eq(const char* s1, const char* s2) {
|
inline int String_eq(char* s1, char* s2) {
|
||||||
if (s1 == NULL || s2 == NULL) {
|
if (s1 == NULL || s2 == NULL) {
|
||||||
if (s1 == NULL && s2 == NULL)
|
if (s1 == NULL && s2 == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
6
String.h
6
String.h
@ -19,9 +19,9 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||||
|
|
||||||
extern void String_delete(char* s);
|
inline void String_delete(char* s);
|
||||||
|
|
||||||
extern char* String_copy(char* orig);
|
inline char* String_copy(char* orig);
|
||||||
|
|
||||||
char* String_cat(char* s1, char* s2);
|
char* String_cat(char* s1, char* s2);
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ void String_printInt(int i);
|
|||||||
|
|
||||||
void String_printPointer(void* p);
|
void String_printPointer(void* p);
|
||||||
|
|
||||||
extern int String_eq(const char* s1, const char* s2);
|
inline int String_eq(char* s1, char* s2);
|
||||||
|
|
||||||
char** String_split(char* s, char sep);
|
char** String_split(char* s, char sep);
|
||||||
|
|
||||||
|
2
TODO
2
TODO
@ -5,8 +5,6 @@ BUGS:
|
|||||||
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=375219
|
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=375219
|
||||||
* add swap column for swap usage in MB
|
* add swap column for swap usage in MB
|
||||||
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=365038
|
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=365038
|
||||||
* Filter out nonprintable characters in command lines
|
|
||||||
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=419140
|
|
||||||
|
|
||||||
FEATURES:
|
FEATURES:
|
||||||
|
|
||||||
|
@ -165,5 +165,4 @@ void TraceScreen_run(TraceScreen* this) {
|
|||||||
kill(child, SIGTERM);
|
kill(child, SIGTERM);
|
||||||
waitpid(child, NULL, 0);
|
waitpid(child, NULL, 0);
|
||||||
fclose(strace);
|
fclose(strace);
|
||||||
CRT_enableDelay();
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
|||||||
if (days > this->total) {
|
if (days > this->total) {
|
||||||
this->total = days;
|
this->total = days;
|
||||||
}
|
}
|
||||||
char daysbuf[15];
|
char daysbuf[10];
|
||||||
if (days > 100) {
|
if (days > 100) {
|
||||||
sprintf(daysbuf, "%d days(!), ", days);
|
sprintf(daysbuf, "%d days(!), ", days);
|
||||||
} else if (days > 1) {
|
} else if (days > 1) {
|
||||||
|
@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) {
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
char* UsersTable_getRef(UsersTable* this, int uid) {
|
||||||
char* name = (char*) (Hashtable_get(this->users, uid));
|
char* name = (char*) (Hashtable_get(this->users, uid));
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
struct passwd* userData = getpwuid(uid);
|
struct passwd* userData = getpwuid(uid);
|
||||||
|
@ -28,10 +28,10 @@ UsersTable* UsersTable_new();
|
|||||||
|
|
||||||
void UsersTable_delete(UsersTable* this);
|
void UsersTable_delete(UsersTable* this);
|
||||||
|
|
||||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
char* UsersTable_getRef(UsersTable* this, int uid);
|
||||||
|
|
||||||
extern int UsersTable_size(UsersTable* this);
|
inline int UsersTable_size(UsersTable* this);
|
||||||
|
|
||||||
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
Vector.c
14
Vector.c
@ -63,7 +63,6 @@ void Vector_delete(Vector* this) {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
static inline bool Vector_isConsistent(Vector* this) {
|
static inline bool Vector_isConsistent(Vector* this) {
|
||||||
assert(this->items <= this->arraySize);
|
|
||||||
if (this->owner) {
|
if (this->owner) {
|
||||||
for (int i = 0; i < this->items; i++)
|
for (int i = 0; i < this->items; i++)
|
||||||
if (this->array[i] && this->array[i]->class != this->vectorType)
|
if (this->array[i] && this->array[i]->class != this->vectorType)
|
||||||
@ -74,16 +73,6 @@ static inline bool Vector_isConsistent(Vector* this) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector_count(Vector* this) {
|
|
||||||
int items = 0;
|
|
||||||
for (int i = 0; i < this->items; i++) {
|
|
||||||
if (this->array[i])
|
|
||||||
items++;
|
|
||||||
}
|
|
||||||
assert(items == this->items);
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Vector_prune(Vector* this) {
|
void Vector_prune(Vector* this) {
|
||||||
@ -233,9 +222,8 @@ void Vector_add(Vector* this, void* data_) {
|
|||||||
assert(data_ && ((Object*)data_)->class == this->vectorType);
|
assert(data_ && ((Object*)data_)->class == this->vectorType);
|
||||||
Object* data = data_;
|
Object* data = data_;
|
||||||
assert(Vector_isConsistent(this));
|
assert(Vector_isConsistent(this));
|
||||||
int i = this->items;
|
|
||||||
Vector_set(this, this->items, data);
|
Vector_set(this, this->items, data);
|
||||||
assert(this->items == i+1); (void)(i);
|
|
||||||
assert(Vector_isConsistent(this));
|
assert(Vector_isConsistent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
Vector.h
8
Vector.h
@ -41,8 +41,6 @@ void Vector_delete(Vector* this);
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
int Vector_count(Vector* this);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Vector_prune(Vector* this);
|
void Vector_prune(Vector* this);
|
||||||
@ -61,15 +59,15 @@ void Vector_moveDown(Vector* this, int index);
|
|||||||
|
|
||||||
void Vector_set(Vector* this, int index, void* data_);
|
void Vector_set(Vector* this, int index, void* data_);
|
||||||
|
|
||||||
extern Object* Vector_get(Vector* this, int index);
|
inline Object* Vector_get(Vector* this, int index);
|
||||||
|
|
||||||
extern int Vector_size(Vector* this);
|
inline int Vector_size(Vector* this);
|
||||||
|
|
||||||
void Vector_merge(Vector* this, Vector* v2);
|
void Vector_merge(Vector* this, Vector* v2);
|
||||||
|
|
||||||
void Vector_add(Vector* this, void* data_);
|
void Vector_add(Vector* this, void* data_);
|
||||||
|
|
||||||
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
||||||
|
|
||||||
void Vector_foreach(Vector* this, Vector_procedure f);
|
void Vector_foreach(Vector* this, Vector_procedure f);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ(2.57)
|
AC_PREREQ(2.57)
|
||||||
AC_INIT([htop],[0.7],[loderunner@users.sourceforge.net])
|
AC_INIT([htop],[0.6.3],[loderunner@users.sourceforge.net])
|
||||||
AM_INIT_AUTOMAKE
|
AM_INIT_AUTOMAKE
|
||||||
AC_CONFIG_SRCDIR([htop.c])
|
AC_CONFIG_SRCDIR([htop.c])
|
||||||
AC_CONFIG_HEADER([config.h])
|
AC_CONFIG_HEADER([config.h])
|
||||||
@ -15,7 +15,7 @@ AC_CHECK_LIB([ncurses], [refresh], [], [missing_libraries="$missing_libraries li
|
|||||||
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
|
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
|
||||||
|
|
||||||
if test ! -z "$missing_libraries"; then
|
if test ! -z "$missing_libraries"; then
|
||||||
AC_MSG_ERROR([missing libraries: $missing_libraries])
|
AC_MSG_ERROR([missing libraries:$missing_headers])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
@ -58,11 +58,6 @@ AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc fi
|
|||||||
fi,
|
fi,
|
||||||
AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem]))
|
AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem]))
|
||||||
|
|
||||||
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
|
|
||||||
if test "x$enable_openvz" = xyes; then
|
|
||||||
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
||||||
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
||||||
|
|
||||||
|
5
htop.1
5
htop.1
@ -1,4 +1,4 @@
|
|||||||
.TH "htop" "1" "0.7" "Bartosz Fenski <fenio@o2.pl>" "Utils"
|
.TH "htop" "1" "0.6.3" "Bartosz Fenski <fenio@o2.pl>" "Utils"
|
||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
htop \- interactive process viewer
|
htop \- interactive process viewer
|
||||||
.SH "SYNTAX"
|
.SH "SYNTAX"
|
||||||
@ -77,9 +77,6 @@ If none is tagged, sends to the currently selected process.
|
|||||||
.B F10, q
|
.B F10, q
|
||||||
Quit
|
Quit
|
||||||
.TP
|
.TP
|
||||||
.B a (on multiprocessor machines)
|
|
||||||
Set CPU affinity: mark which CPUs a process is allowed to use.
|
|
||||||
.TP
|
|
||||||
.B u
|
.B u
|
||||||
Show only processes owned by a specified user.
|
Show only processes owned by a specified user.
|
||||||
.TP
|
.TP
|
||||||
|
153
htop.c
153
htop.c
@ -25,7 +25,6 @@ in the source distribution for its full text.
|
|||||||
#include "CategoriesPanel.h"
|
#include "CategoriesPanel.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
#include "TraceScreen.h"
|
#include "TraceScreen.h"
|
||||||
#include "AffinityPanel.h"
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -47,13 +46,12 @@ void printHelpFlag() {
|
|||||||
printf("Released under the GNU GPL.\n\n");
|
printf("Released under the GNU GPL.\n\n");
|
||||||
printf("-d DELAY Delay between updates, in tenths of seconds\n\n");
|
printf("-d DELAY Delay between updates, in tenths of seconds\n\n");
|
||||||
printf("-u USERNAME Show only processes of a given user\n\n");
|
printf("-u USERNAME Show only processes of a given user\n\n");
|
||||||
printf("--sort-key COLUMN Sort by this column (use --sort-key help for a column list)\n\n");
|
|
||||||
printf("Press F1 inside htop for online help.\n");
|
printf("Press F1 inside htop for online help.\n");
|
||||||
printf("See the man page for full information.\n\n");
|
printf("See the man page for full information.\n\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showHelp(ProcessList* pl) {
|
void showHelp() {
|
||||||
clear();
|
clear();
|
||||||
attrset(CRT_colors[HELP_BOLD]);
|
attrset(CRT_colors[HELP_BOLD]);
|
||||||
mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2006 Hisham Muhammad.");
|
mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2006 Hisham Muhammad.");
|
||||||
@ -63,20 +61,10 @@ void showHelp(ProcessList* pl) {
|
|||||||
mvaddstr(3, 0, "CPU usage bar: ");
|
mvaddstr(3, 0, "CPU usage bar: ");
|
||||||
#define addattrstr(a,s) attrset(a);addstr(s)
|
#define addattrstr(a,s) attrset(a);addstr(s)
|
||||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||||
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_IRQ], "irq"); addstr("/");
|
|
||||||
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("/");
|
addattrstr(CRT_colors[CPU_NICE], "low-priority"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_KERNEL], "kernel");
|
addattrstr(CRT_colors[CPU_KERNEL], "kernel");
|
||||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||||
}
|
|
||||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
mvaddstr(4, 0, "Memory bar: ");
|
mvaddstr(4, 0, "Memory bar: ");
|
||||||
@ -93,42 +81,36 @@ void showHelp(ProcessList* pl) {
|
|||||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
mvaddstr(6,0, "Type and layout of header meters are configurable in the setup screen.");
|
mvaddstr(6,0, "Type and layout of header meters is configurable in the setup screen.");
|
||||||
mvaddstr(7, 0, "Status: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep");
|
|
||||||
|
|
||||||
mvaddstr( 9, 0, " Arrows: scroll process list F5 t: tree view");
|
mvaddstr( 8, 0, " Arrows: scroll process list F5 t: tree view");
|
||||||
mvaddstr(10, 0, " Digits: incremental PID search u: show processes of a single user");
|
mvaddstr( 9, 0, " Digits: incremental PID search u: show processes of a single user");
|
||||||
mvaddstr(11, 0, " F3 /: incremental name search H: hide/show user threads");
|
mvaddstr(10, 0, " F3 /: incremental name search H: hide/show user threads");
|
||||||
mvaddstr(12, 0, " K: hide/show kernel threads");
|
mvaddstr(11, 0, " K: hide/show kernel threads");
|
||||||
mvaddstr(13, 0, " Space: tag processes F: cursor follows process");
|
mvaddstr(12, 0, " Space: tag processes F: cursor follows process");
|
||||||
mvaddstr(14, 0, " U: untag all processes");
|
mvaddstr(13, 0, " U: untag all processes");
|
||||||
mvaddstr(15, 0, " F9 k: kill process/tagged processes P: sort by CPU%");
|
mvaddstr(14, 0, " F9 k: kill process/tagged processes P: sort by CPU%");
|
||||||
mvaddstr(16, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%");
|
mvaddstr(15, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%");
|
||||||
mvaddstr(17, 0, " - ] F8: higher priority (root only) T: sort by TIME");
|
mvaddstr(16, 0, " - ] F8: higher priority (root only) T: sort by TIME");
|
||||||
if (pl->processorCount > 1)
|
mvaddstr(17, 0, " F4 I: invert sort order");
|
||||||
mvaddstr(18, 0, " a: set CPU affinity F4 I: invert sort order");
|
mvaddstr(18, 0, " F2 S: setup F6 >: select sort column");
|
||||||
else
|
mvaddstr(19, 0, " F1 h: show this help screen");
|
||||||
mvaddstr(18, 0, " F4 I: invert sort order");
|
mvaddstr(20, 0, " F10 q: quit s: trace syscalls with strace");
|
||||||
mvaddstr(19, 0, " F2 S: setup F6 >: select sort column");
|
|
||||||
mvaddstr(20, 0, " F1 h: show this help screen");
|
|
||||||
mvaddstr(21, 0, " F10 q: quit s: trace syscalls with strace");
|
|
||||||
|
|
||||||
attrset(CRT_colors[HELP_BOLD]);
|
attrset(CRT_colors[HELP_BOLD]);
|
||||||
mvaddstr( 9, 0, " Arrows"); mvaddstr( 9,40, " F5 t");
|
mvaddstr( 8, 0, " Arrows"); mvaddstr( 8,40, " F5 t");
|
||||||
mvaddstr(10, 0, " Digits"); mvaddstr(10,40, " u");
|
mvaddstr( 9, 0, " Digits"); mvaddstr( 9,40, " u");
|
||||||
mvaddstr(11, 0, " F3 /"); mvaddstr(11,40, " H");
|
mvaddstr(10, 0, " F3 /"); mvaddstr(10,40, " H");
|
||||||
mvaddstr(12,40, " K");
|
mvaddstr(11,40, " K");
|
||||||
mvaddstr(13, 0, " Space"); mvaddstr(13,40, " F");
|
mvaddstr(12, 0, " Space"); mvaddstr(12,40, " F");
|
||||||
mvaddstr(14, 0, " U");
|
mvaddstr(13, 0, " U");
|
||||||
mvaddstr(15, 0, " F9 k"); mvaddstr(15,40, " P");
|
mvaddstr(14, 0, " F9 k"); mvaddstr(14,40, " P");
|
||||||
mvaddstr(16, 0, " + [ F7"); mvaddstr(16,40, " M");
|
mvaddstr(15, 0, " + [ F7"); mvaddstr(15,40, " M");
|
||||||
mvaddstr(17, 0, " - ] F8"); mvaddstr(17,40, " T");
|
mvaddstr(16, 0, " - ] F8"); mvaddstr(16,40, " T");
|
||||||
mvaddstr(18,40, " F4 I");
|
mvaddstr(17,40, " F4 I");
|
||||||
if (pl->processorCount > 1)
|
mvaddstr(18, 0, " F2 S"); mvaddstr(18,40, " F6 >");
|
||||||
mvaddstr(18, 0, " a:");
|
mvaddstr(19, 0, " F1 h");
|
||||||
mvaddstr(19, 0, " F2 S"); mvaddstr(19,40, " F6 >");
|
mvaddstr(20, 0, " F10 q"); mvaddstr(20,40, " s");
|
||||||
mvaddstr(20, 0, " F1 h");
|
|
||||||
mvaddstr(21, 0, " F10 q"); mvaddstr(21,40, " s");
|
|
||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
|
|
||||||
attrset(CRT_colors[HELP_BOLD]);
|
attrset(CRT_colors[HELP_BOLD]);
|
||||||
@ -175,7 +157,7 @@ static HandlerResult pickWithEnter(Panel* panel, int ch) {
|
|||||||
static Object* pickFromList(Panel* panel, Panel* list, int x, int y, char** keyLabels, FunctionBar* prevBar) {
|
static Object* pickFromList(Panel* panel, Panel* list, int x, int y, char** keyLabels, FunctionBar* prevBar) {
|
||||||
char* fuKeys[2] = {"Enter", "Esc"};
|
char* fuKeys[2] = {"Enter", "Esc"};
|
||||||
int fuEvents[2] = {13, 27};
|
int fuEvents[2] = {13, 27};
|
||||||
if (!list->eventHandler)
|
if (!panel->eventHandler)
|
||||||
Panel_setEventHandler(list, pickWithEnter);
|
Panel_setEventHandler(list, pickWithEnter);
|
||||||
ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, false);
|
ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, false);
|
||||||
ScreenManager_add(scr, list, FunctionBar_new(2, keyLabels, fuKeys, fuEvents), x - 1);
|
ScreenManager_add(scr, list, FunctionBar_new(2, keyLabels, fuKeys, fuEvents), x - 1);
|
||||||
@ -212,40 +194,21 @@ int main(int argc, char** argv) {
|
|||||||
int delay = -1;
|
int delay = -1;
|
||||||
bool userOnly = false;
|
bool userOnly = false;
|
||||||
uid_t userId = 0;
|
uid_t userId = 0;
|
||||||
int sortKey = 0;
|
|
||||||
|
|
||||||
int arg = 1;
|
if (argc > 0) {
|
||||||
while (arg < argc) {
|
if (String_eq(argv[1], "--help")) {
|
||||||
if (String_eq(argv[arg], "--help")) {
|
|
||||||
printHelpFlag();
|
printHelpFlag();
|
||||||
} else if (String_eq(argv[arg], "--version")) {
|
} else if (String_eq(argv[1], "--version")) {
|
||||||
printVersionFlag();
|
printVersionFlag();
|
||||||
} else if (String_eq(argv[arg], "--sort-key")) {
|
} else if (String_eq(argv[1], "-d")) {
|
||||||
if (arg == argc - 1) printHelpFlag();
|
if (argc < 2) printHelpFlag();
|
||||||
arg++;
|
sscanf(argv[2], "%d", &delay);
|
||||||
char* field = argv[arg];
|
|
||||||
if (String_eq(field, "help")) {
|
|
||||||
for (int j = 1; j < LAST_PROCESSFIELD; j++)
|
|
||||||
printf ("%s\n", Process_fieldNames[j]);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
sortKey = ColumnsPanel_fieldNameToIndex(field);
|
|
||||||
if (sortKey == -1) {
|
|
||||||
fprintf(stderr, "Error: invalid column \"%s\".\n", field);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else if (String_eq(argv[arg], "-d")) {
|
|
||||||
if (arg == argc - 1) printHelpFlag();
|
|
||||||
arg++;
|
|
||||||
sscanf(argv[arg], "%d", &delay);
|
|
||||||
if (delay < 1) delay = 1;
|
if (delay < 1) delay = 1;
|
||||||
if (delay > 100) delay = 100;
|
if (delay > 100) delay = 100;
|
||||||
} else if (String_eq(argv[arg], "-u")) {
|
} else if (String_eq(argv[1], "-u")) {
|
||||||
if (arg == argc - 1) printHelpFlag();
|
if (argc < 2) printHelpFlag();
|
||||||
arg++;
|
setUserOnly(argv[2], &userOnly, &userId);
|
||||||
setUserOnly(argv[arg], &userOnly, &userId);
|
|
||||||
}
|
}
|
||||||
arg++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(PROCDIR, R_OK) != 0) {
|
if (access(PROCDIR, R_OK) != 0) {
|
||||||
@ -274,10 +237,6 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
Header* header = Header_new(pl);
|
Header* header = Header_new(pl);
|
||||||
settings = Settings_new(pl, header);
|
settings = Settings_new(pl, header);
|
||||||
if (sortKey > 0) {
|
|
||||||
pl->sortKey = sortKey;
|
|
||||||
pl->treeView = false;
|
|
||||||
}
|
|
||||||
int headerHeight = Header_calculateHeight(header);
|
int headerHeight = Header_calculateHeight(header);
|
||||||
|
|
||||||
// FIXME: move delay code to settings
|
// FIXME: move delay code to settings
|
||||||
@ -324,7 +283,7 @@ int main(int argc, char** argv) {
|
|||||||
incSearchIndex = 0;
|
incSearchIndex = 0;
|
||||||
incSearchBuffer[0] = 0;
|
incSearchBuffer[0] = 0;
|
||||||
int currPos = Panel_getSelectedIndex(panel);
|
int currPos = Panel_getSelectedIndex(panel);
|
||||||
unsigned int currPid = 0;
|
int currPid = 0;
|
||||||
int currScrollV = panel->scrollV;
|
int currScrollV = panel->scrollV;
|
||||||
if (follow)
|
if (follow)
|
||||||
currPid = ProcessList_get(pl, currPos)->pid;
|
currPid = ProcessList_get(pl, currPos)->pid;
|
||||||
@ -418,7 +377,7 @@ int main(int argc, char** argv) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isdigit((char)ch)) {
|
if (isdigit((char)ch)) {
|
||||||
unsigned int pid = ch-48 + acc;
|
int pid = ch-48 + acc;
|
||||||
for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++)
|
for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++)
|
||||||
Panel_setSelected(panel, i);
|
Panel_setSelected(panel, i);
|
||||||
acc = pid * 10;
|
acc = pid * 10;
|
||||||
@ -496,7 +455,7 @@ int main(int argc, char** argv) {
|
|||||||
case KEY_F(1):
|
case KEY_F(1):
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
showHelp(pl);
|
showHelp();
|
||||||
FunctionBar_draw(defaultBar, NULL);
|
FunctionBar_draw(defaultBar, NULL);
|
||||||
refreshTimeout = 0;
|
refreshTimeout = 0;
|
||||||
break;
|
break;
|
||||||
@ -598,36 +557,6 @@ int main(int argc, char** argv) {
|
|||||||
refreshTimeout = 0;
|
refreshTimeout = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'a':
|
|
||||||
{
|
|
||||||
if (pl->processorCount == 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
Process* p = (Process*) Panel_getSelected(panel);
|
|
||||||
unsigned long curr = Process_getAffinity(p);
|
|
||||||
|
|
||||||
Panel* affinityPanel = AffinityPanel_new(pl->processorCount, curr);
|
|
||||||
|
|
||||||
char* fuFunctions[2] = {"Toggle ", "Done "};
|
|
||||||
pickFromList(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar);
|
|
||||||
unsigned long new = AffinityPanel_getAffinity(affinityPanel);
|
|
||||||
bool anyTagged = false;
|
|
||||||
for (int i = 0; i < Panel_getSize(panel); i++) {
|
|
||||||
Process* p = (Process*) Panel_get(panel, i);
|
|
||||||
if (p->tag) {
|
|
||||||
Process_setAffinity(p, new);
|
|
||||||
anyTagged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!anyTagged) {
|
|
||||||
Process* p = (Process*) Panel_getSelected(panel);
|
|
||||||
Process_setAffinity(p, new);
|
|
||||||
}
|
|
||||||
((Object*)affinityPanel)->delete((Object*)affinityPanel);
|
|
||||||
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
|
|
||||||
refreshTimeout = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KEY_F(10):
|
case KEY_F(10):
|
||||||
case 'q':
|
case 'q':
|
||||||
quit = 1;
|
quit = 1;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Encoding=UTF-8
|
Encoding=UTF-8
|
||||||
Version=0.7
|
Version=0.6.3
|
||||||
Name=Htop
|
Name=Htop
|
||||||
Type=Application
|
Type=Application
|
||||||
Comment=Show System Processes
|
Comment=Show System Processes
|
||||||
|
3
htop.h
3
htop.h
@ -29,7 +29,6 @@ in the source distribution for its full text.
|
|||||||
#include "CategoriesPanel.h"
|
#include "CategoriesPanel.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
#include "TraceScreen.h"
|
#include "TraceScreen.h"
|
||||||
#include "AffinityPanel.h"
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -42,7 +41,7 @@ void printVersionFlag();
|
|||||||
|
|
||||||
void printHelpFlag();
|
void printHelpFlag();
|
||||||
|
|
||||||
void showHelp(ProcessList* pl);
|
void showHelp();
|
||||||
|
|
||||||
void addUserToList(int key, void* userCast, void* panelCast);
|
void addUserToList(int key, void* userCast, void* panelCast);
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@ class writer:
|
|||||||
self.file.write(text + "\n")
|
self.file.write(text + "\n")
|
||||||
out = writer(out)
|
out = writer(out)
|
||||||
|
|
||||||
print("Generating "+name+".h")
|
|
||||||
|
|
||||||
selfheader = '#include "' + name + '.h"'
|
selfheader = '#include "' + name + '.h"'
|
||||||
|
|
||||||
out.write( "/* Do not edit this file. It was automatically generated. */" )
|
out.write( "/* Do not edit this file. It was automatically generated. */" )
|
||||||
@ -54,7 +52,7 @@ for line in file.readlines():
|
|||||||
elif equals != -1:
|
elif equals != -1:
|
||||||
out.write("extern " + line[:equals] + ";" )
|
out.write("extern " + line[:equals] + ";" )
|
||||||
elif line[-1] == "{":
|
elif line[-1] == "{":
|
||||||
out.write( line[:-2].replace("inline", "extern") + ";" )
|
out.write( line[:-2] + ";" )
|
||||||
state = SKIP
|
state = SKIP
|
||||||
else:
|
else:
|
||||||
out.write( line )
|
out.write( line )
|
||||||
|
Reference in New Issue
Block a user