mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 13:34:35 +03:00
Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
7abfcb3ce7 | |||
0cd4f69091 | |||
b75b1a5818 | |||
bd0f30dcd6 | |||
855d9eaf9a | |||
b70b35ea65 | |||
a7c2aedcec | |||
46631b59fb | |||
e3acb5e07a | |||
5a91824e46 | |||
f356997269 | |||
e685bdeea0 | |||
4c51ad0e35 | |||
d357c67717 | |||
e1a7e2bdef | |||
d2f767e607 | |||
b1e9d716f2 | |||
6271138237 | |||
255c62a460 | |||
9710a43001 | |||
df20abfd67 | |||
d46dcf99fd | |||
f56c8014f7 | |||
a227b20fef |
48
AffinityPanel.c
Normal file
48
AffinityPanel.c
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
#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;
|
||||
}
|
19
AffinityPanel.h
Normal file
19
AffinityPanel.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* 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
|
20
CPUMeter.c
20
CPUMeter.c
@ -19,7 +19,7 @@ in the source distribution for its full text.
|
||||
#include <assert.h>
|
||||
|
||||
int CPUMeter_attributes[] = {
|
||||
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IOWAIT, CPU_IRQ, CPU_SOFTIRQ
|
||||
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT
|
||||
};
|
||||
|
||||
MeterType CPUMeter = {
|
||||
@ -74,14 +74,14 @@ void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
double cpu;
|
||||
this->values[0] = pl->nicePeriod[processor] / total * 100.0;
|
||||
this->values[1] = pl->userPeriod[processor] / total * 100.0;
|
||||
if (pl->expandSystemTime) {
|
||||
if (pl->detailedCPUTime) {
|
||||
this->values[2] = pl->systemPeriod[processor] / total * 100.0;
|
||||
this->values[3] = pl->ioWaitPeriod[processor] / total * 100.0;
|
||||
this->values[4] = pl->irqPeriod[processor] / total * 100.0;
|
||||
this->values[5] = pl->softIrqPeriod[processor] / total * 100.0;
|
||||
this->values[3] = pl->irqPeriod[processor] / total * 100.0;
|
||||
this->values[4] = pl->softIrqPeriod[processor] / total * 100.0;
|
||||
this->values[5] = pl->ioWaitPeriod[processor] / total * 100.0;
|
||||
this->type->items = 6;
|
||||
cpu = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2]+
|
||||
this->values[3]+this->values[4]+this->values[5])));
|
||||
this->values[3]+this->values[4])));
|
||||
} else {
|
||||
this->values[2] = pl->systemAllPeriod[processor] / total * 100.0;
|
||||
this->type->items = 3;
|
||||
@ -97,7 +97,7 @@ void CPUMeter_display(Object* cast, RichString* out) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[1]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], ":");
|
||||
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
|
||||
if (this->pl->expandSystemTime) {
|
||||
if (this->pl->detailedCPUTime) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[2]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
||||
@ -105,14 +105,14 @@ void CPUMeter_display(Object* cast, RichString* out) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
||||
RichString_append(out, CRT_colors[CPU_NICE], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[3]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "wa:");
|
||||
RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[4]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "hi:");
|
||||
RichString_append(out, CRT_colors[CPU_IRQ], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[4]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "si:");
|
||||
RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[5]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "wa:");
|
||||
RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
|
||||
} else {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[2]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
||||
|
13
CRT.c
13
CRT.c
@ -14,6 +14,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include "String.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||
@ -181,7 +182,7 @@ void CRT_enableDelay() {
|
||||
|
||||
void CRT_handleSIGSEGV(int signal) {
|
||||
CRT_done();
|
||||
fprintf(stderr, "Aborted. Please report bug at http://htop.sf.net");
|
||||
fprintf(stderr, "htop " VERSION " aborted. Please report bug at http://htop.sf.net\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -254,7 +255,7 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colors[CHECK_BOX] = A_BOLD;
|
||||
CRT_colors[CHECK_MARK] = A_NORMAL;
|
||||
CRT_colors[CHECK_TEXT] = A_NORMAL;
|
||||
CRT_colors[CPU_IOWAIT] = A_BOLD;
|
||||
CRT_colors[CPU_IOWAIT] = A_NORMAL;
|
||||
CRT_colors[CPU_IRQ] = A_BOLD;
|
||||
CRT_colors[CPU_SOFTIRQ] = A_BOLD;
|
||||
} else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE) {
|
||||
@ -309,7 +310,7 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colors[CHECK_BOX] = ColorPair(Blue,White);
|
||||
CRT_colors[CHECK_MARK] = ColorPair(Black,White);
|
||||
CRT_colors[CHECK_TEXT] = ColorPair(Black,White);
|
||||
CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,White);
|
||||
CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black);
|
||||
CRT_colors[CPU_IRQ] = ColorPair(Blue,White);
|
||||
CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,White);
|
||||
} else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE2) {
|
||||
@ -364,7 +365,7 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colors[CHECK_BOX] = ColorPair(Blue,Black);
|
||||
CRT_colors[CHECK_MARK] = ColorPair(Black,Black);
|
||||
CRT_colors[CHECK_TEXT] = ColorPair(Black,Black);
|
||||
CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Black);
|
||||
CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black);
|
||||
CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black);
|
||||
CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,Black);
|
||||
} else if (CRT_colorScheme == COLORSCHEME_MIDNIGHT) {
|
||||
@ -419,7 +420,7 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colors[CHECK_BOX] = ColorPair(Cyan,Blue);
|
||||
CRT_colors[CHECK_MARK] = A_BOLD | ColorPair(White,Blue);
|
||||
CRT_colors[CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue);
|
||||
CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Yellow,Blue);
|
||||
CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Blue);
|
||||
CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue);
|
||||
CRT_colors[CPU_SOFTIRQ] = ColorPair(Black,Blue);
|
||||
} else if (CRT_colorScheme == COLORSCHEME_BLACKNIGHT) {
|
||||
@ -530,7 +531,7 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colors[CHECK_BOX] = ColorPair(Cyan,Black);
|
||||
CRT_colors[CHECK_MARK] = A_BOLD;
|
||||
CRT_colors[CHECK_TEXT] = A_NORMAL;
|
||||
CRT_colors[CPU_IOWAIT] = ColorPair(Cyan,Black);
|
||||
CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black);
|
||||
CRT_colors[CPU_IRQ] = ColorPair(Yellow,Black);
|
||||
CRT_colors[CPU_SOFTIRQ] = ColorPair(Magenta,Black);
|
||||
}
|
||||
|
1
CRT.h
1
CRT.h
@ -17,6 +17,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include "String.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||
|
34
ChangeLog
34
ChangeLog
@ -1,4 +1,38 @@
|
||||
|
||||
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
|
||||
|
22
CheckItem.c
22
CheckItem.c
@ -16,7 +16,8 @@ in the source distribution for its full text.
|
||||
typedef struct CheckItem_ {
|
||||
Object super;
|
||||
char* text;
|
||||
bool* value;
|
||||
bool value;
|
||||
bool* ref;
|
||||
} CheckItem;
|
||||
|
||||
}*/
|
||||
@ -27,13 +28,14 @@ char* CHECKITEM_CLASS = "CheckItem";
|
||||
#define CHECKITEM_CLASS NULL
|
||||
#endif
|
||||
|
||||
CheckItem* CheckItem_new(char* text, bool* value) {
|
||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
|
||||
CheckItem* this = malloc(sizeof(CheckItem));
|
||||
Object_setClass(this, CHECKITEM_CLASS);
|
||||
((Object*)this)->display = CheckItem_display;
|
||||
((Object*)this)->delete = CheckItem_delete;
|
||||
this->text = text;
|
||||
this->value = value;
|
||||
this->ref = ref;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -45,11 +47,25 @@ void CheckItem_delete(Object* cast) {
|
||||
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) {
|
||||
CheckItem* this = (CheckItem*)cast;
|
||||
assert (this != NULL);
|
||||
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
||||
if (*(this->value))
|
||||
if (CheckItem_get(this))
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
||||
else
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
||||
|
@ -18,7 +18,8 @@ in the source distribution for its full text.
|
||||
typedef struct CheckItem_ {
|
||||
Object super;
|
||||
char* text;
|
||||
bool* value;
|
||||
bool value;
|
||||
bool* ref;
|
||||
} CheckItem;
|
||||
|
||||
|
||||
@ -28,10 +29,14 @@ extern char* CHECKITEM_CLASS;
|
||||
#define CHECKITEM_CLASS NULL
|
||||
#endif
|
||||
|
||||
CheckItem* CheckItem_new(char* text, bool* value);
|
||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value);
|
||||
|
||||
void CheckItem_delete(Object* cast);
|
||||
|
||||
void CheckItem_set(CheckItem* this, bool value);
|
||||
|
||||
bool CheckItem_get(CheckItem* this);
|
||||
|
||||
void CheckItem_display(Object* cast, RichString* out);
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,6 @@ typedef struct ColorsPanel_ {
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
bool check[5];
|
||||
} ColorsPanel;
|
||||
|
||||
}*/
|
||||
@ -50,10 +49,9 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
|
||||
Panel_setHeader(super, "Colors");
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), &(this->check[i])));
|
||||
this->check[i] = false;
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
|
||||
}
|
||||
this->check[settings->colorScheme] = true;
|
||||
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -75,10 +73,9 @@ HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
case ' ':
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||
this->check[i] = false;
|
||||
}
|
||||
this->check[mark] = true;
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++)
|
||||
CheckItem_set((CheckItem*)Panel_get(super, i), false);
|
||||
CheckItem_set((CheckItem*)Panel_get(super, mark), true);
|
||||
this->settings->colorScheme = mark;
|
||||
result = HANDLED;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ typedef struct ColorsPanel_ {
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
bool check[5];
|
||||
} ColorsPanel;
|
||||
|
||||
|
||||
|
@ -28,17 +28,17 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = DisplayOptionsPanel_EventHandler;
|
||||
super->eventHandler = DisplayOptionsPanel_eventHandler;
|
||||
|
||||
Panel_setHeader(super, "Display options");
|
||||
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)));
|
||||
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)));
|
||||
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)));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin)));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Split System Time into System/IO-Wait/Hard-IRQ/Soft-IRQ"), &(settings->pl->expandSystemTime)));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ)"), &(settings->pl->detailedCPUTime), false));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ void DisplayOptionsPanel_delete(Object* object) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch) {
|
||||
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
@ -60,7 +60,7 @@ HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch) {
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
case ' ':
|
||||
*(selected->value) = ! *(selected->value);
|
||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
||||
result = HANDLED;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||
|
||||
void DisplayOptionsPanel_delete(Object* object);
|
||||
|
||||
HandlerResult DisplayOptionsPanel_EventHandler(Panel* super, int ch);
|
||||
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
|
||||
#endif
|
||||
|
16
Hashtable.c
16
Hashtable.c
@ -19,7 +19,7 @@ typedef struct Hashtable_ Hashtable;
|
||||
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
||||
|
||||
typedef struct HashtableItem {
|
||||
int key;
|
||||
unsigned int key;
|
||||
void* value;
|
||||
struct HashtableItem* next;
|
||||
} HashtableItem;
|
||||
@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) {
|
||||
|
||||
#endif
|
||||
|
||||
HashtableItem* HashtableItem_new(int key, void* value) {
|
||||
HashtableItem* HashtableItem_new(unsigned int key, void* value) {
|
||||
HashtableItem* this;
|
||||
|
||||
this = (HashtableItem*) malloc(sizeof(HashtableItem));
|
||||
@ -104,8 +104,8 @@ inline int Hashtable_size(Hashtable* this) {
|
||||
return this->items;
|
||||
}
|
||||
|
||||
void Hashtable_put(Hashtable* this, int key, void* value) {
|
||||
int index = key % this->size;
|
||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
|
||||
unsigned int index = key % this->size;
|
||||
HashtableItem** bucketPtr = &(this->buckets[index]);
|
||||
while (true)
|
||||
if (*bucketPtr == NULL) {
|
||||
@ -122,8 +122,8 @@ void Hashtable_put(Hashtable* this, int key, void* value) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
}
|
||||
|
||||
void* Hashtable_remove(Hashtable* this, int key) {
|
||||
int index = key % this->size;
|
||||
void* Hashtable_remove(Hashtable* this, unsigned int key) {
|
||||
unsigned int index = key % this->size;
|
||||
|
||||
assert(Hashtable_isConsistent(this));
|
||||
|
||||
@ -149,8 +149,8 @@ void* Hashtable_remove(Hashtable* this, int key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline void* Hashtable_get(Hashtable* this, int key) {
|
||||
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];
|
||||
while (true) {
|
||||
if (bucketPtr == NULL) {
|
||||
|
12
Hashtable.h
12
Hashtable.h
@ -21,7 +21,7 @@ typedef struct Hashtable_ Hashtable;
|
||||
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
||||
|
||||
typedef struct HashtableItem {
|
||||
int key;
|
||||
unsigned int key;
|
||||
void* value;
|
||||
struct HashtableItem* next;
|
||||
} HashtableItem;
|
||||
@ -41,19 +41,19 @@ int Hashtable_count(Hashtable* this);
|
||||
|
||||
#endif
|
||||
|
||||
HashtableItem* HashtableItem_new(int key, void* value);
|
||||
HashtableItem* HashtableItem_new(unsigned int key, void* value);
|
||||
|
||||
Hashtable* Hashtable_new(int size, bool owner);
|
||||
|
||||
void Hashtable_delete(Hashtable* this);
|
||||
|
||||
inline int Hashtable_size(Hashtable* this);
|
||||
extern int Hashtable_size(Hashtable* this);
|
||||
|
||||
void Hashtable_put(Hashtable* this, int key, void* value);
|
||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
||||
|
||||
void* Hashtable_remove(Hashtable* this, int key);
|
||||
void* Hashtable_remove(Hashtable* this, unsigned int key);
|
||||
|
||||
inline void* Hashtable_get(Hashtable* this, int key);
|
||||
extern void* Hashtable_get(Hashtable* this, unsigned int key);
|
||||
|
||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
||||
|
||||
|
42
Makefile.am
42
Makefile.am
@ -11,22 +11,27 @@ pixmap_DATA = htop.png
|
||||
AM_CFLAGS = -pedantic -Wall -std=c99
|
||||
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
|
||||
htop_SOURCES = AvailableMetersPanel.c CategoriesPanel.c ClockMeter.c \
|
||||
CPUMeter.c CRT.c DebugMemory.c DisplayOptionsPanel.c FunctionBar.c \
|
||||
Hashtable.c Header.c htop.c Panel.c ListItem.c LoadAverageMeter.c \
|
||||
MemoryMeter.c Meter.c MetersPanel.c Object.c Process.c \
|
||||
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \
|
||||
SignalsPanel.c String.c SwapMeter.c TasksMeter.c Vector.c \
|
||||
UptimeMeter.c UsersTable.c AvailableMetersPanel.h CategoriesPanel.h \
|
||||
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \
|
||||
DisplayOptionsPanel.h FunctionBar.h Hashtable.h Header.h htop.h Panel.h \
|
||||
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \
|
||||
MetersPanel.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \
|
||||
Settings.h SignalItem.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
|
||||
Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \
|
||||
ColorsPanel.c ColorsPanel.h TraceScreen.c TraceScreen.h \
|
||||
AvailableColumnsPanel.c AvailableColumnsPanel.h ColumnsPanel.c \
|
||||
ColumnsPanel.h
|
||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DebugMemory.c \
|
||||
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
|
||||
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
|
||||
Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
|
||||
SignalItem.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
|
||||
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c
|
||||
|
||||
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
|
||||
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
|
||||
CPUMeter.h CRT.h DebugMemory.h DisplayOptionsPanel.h FunctionBar.h \
|
||||
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
|
||||
Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
|
||||
ScreenManager.h Settings.h SignalItem.h SignalsPanel.h String.h \
|
||||
SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \
|
||||
Process.h AffinityPanel.h
|
||||
|
||||
SUFFIXES = .h
|
||||
|
||||
BUILT_SOURCES = $(myhtopheaders)
|
||||
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h
|
||||
|
||||
profile:
|
||||
$(MAKE) all CFLAGS="-pg -O2"
|
||||
@ -40,3 +45,8 @@ hardened-debug:
|
||||
debuglite:
|
||||
$(MAKE) all CFLAGS="-ggdb -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);
|
||||
|
||||
inline void Panel_setRichHeader(Panel* this, RichString header);
|
||||
extern void Panel_setRichHeader(Panel* this, RichString header);
|
||||
|
||||
inline void Panel_setHeader(Panel* this, char* header);
|
||||
extern void Panel_setHeader(Panel* this, char* header);
|
||||
|
||||
void Panel_setEventHandler(Panel* this, Panel_EventHandler eh);
|
||||
|
||||
|
89
Process.c
89
Process.c
@ -25,10 +25,13 @@ in the source distribution for its full text.
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <pwd.h>
|
||||
#include <sched.h>
|
||||
|
||||
// This works only with glibc 2.1+. On earlier versions
|
||||
// the behavior is similar to have a hardcoded page size.
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
||||
#endif
|
||||
|
||||
#define PROCESS_COMM_LEN 300
|
||||
|
||||
@ -39,7 +42,11 @@ typedef enum ProcessField_ {
|
||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||
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,
|
||||
USER, TIME, LAST_PROCESSFIELD
|
||||
USER, TIME, NLWP, TGID
|
||||
#ifdef HAVE_OPENVZ
|
||||
VEID, VPID,
|
||||
#endif
|
||||
LAST_PROCESSFIELD
|
||||
} ProcessField;
|
||||
|
||||
struct ProcessList_;
|
||||
@ -50,15 +57,16 @@ typedef struct Process_ {
|
||||
struct ProcessList_ *pl;
|
||||
bool updated;
|
||||
|
||||
int pid;
|
||||
unsigned int pid;
|
||||
char* comm;
|
||||
int indent;
|
||||
char state;
|
||||
bool tag;
|
||||
int ppid;
|
||||
int pgrp;
|
||||
int session;
|
||||
int tty_nr;
|
||||
unsigned int ppid;
|
||||
unsigned int pgrp;
|
||||
unsigned int session;
|
||||
unsigned int tty_nr;
|
||||
unsigned int tgid;
|
||||
int tpgid;
|
||||
unsigned long int flags;
|
||||
#ifdef DEBUG
|
||||
@ -73,6 +81,7 @@ typedef struct Process_ {
|
||||
long int cstime;
|
||||
long int priority;
|
||||
long int nice;
|
||||
long int nlwp;
|
||||
#ifdef DEBUG
|
||||
long int itrealvalue;
|
||||
unsigned long int starttime;
|
||||
@ -105,6 +114,10 @@ typedef struct Process_ {
|
||||
float percent_cpu;
|
||||
float percent_mem;
|
||||
char* user;
|
||||
#ifdef HAVE_OPENVZ
|
||||
unsigned int veid;
|
||||
unsigned int vpid;
|
||||
#endif
|
||||
} Process;
|
||||
|
||||
}*/
|
||||
@ -116,7 +129,11 @@ char* PROCESS_CLASS = "Process";
|
||||
#endif
|
||||
|
||||
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", "*** report bug! ***"
|
||||
"", "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",
|
||||
#ifdef HAVE_OPENVZ
|
||||
"VEID", "VPID",
|
||||
#endif
|
||||
"*** report bug! ***"
|
||||
};
|
||||
|
||||
static int Process_getuid = -1;
|
||||
@ -178,6 +195,16 @@ 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) {
|
||||
kill(this->pid, signal);
|
||||
}
|
||||
@ -261,13 +288,15 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
int n = PROCESS_COMM_LEN;
|
||||
|
||||
switch (field) {
|
||||
case PID: snprintf(buffer, n, "%5d ", this->pid); break;
|
||||
case PPID: snprintf(buffer, n, "%5d ", this->ppid); break;
|
||||
case PGRP: snprintf(buffer, n, "%5d ", this->pgrp); break;
|
||||
case SESSION: snprintf(buffer, n, "%5d ", this->session); break;
|
||||
case TTY_NR: snprintf(buffer, n, "%5d ", this->tty_nr); break;
|
||||
case PID: snprintf(buffer, n, "%5u ", this->pid); break;
|
||||
case PPID: snprintf(buffer, n, "%5u ", this->ppid); break;
|
||||
case PGRP: snprintf(buffer, n, "%5u ", this->pgrp); break;
|
||||
case SESSION: snprintf(buffer, n, "%5u ", this->session); break;
|
||||
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
||||
case TGID: snprintf(buffer, n, "%5u ", this->tgid); break;
|
||||
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
|
||||
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break;
|
||||
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
|
||||
case COMM: {
|
||||
if (!this->pl->treeView || this->indent == 0) {
|
||||
Process_writeCommand(this, attr, str);
|
||||
@ -316,6 +345,10 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
: attr;
|
||||
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_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return;
|
||||
case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return;
|
||||
@ -355,6 +388,10 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_OPENVZ
|
||||
case VEID: snprintf(buffer, n, "%5u ", this->veid); break;
|
||||
case VPID: snprintf(buffer, n, "%5u ", this->vpid); break;
|
||||
#endif
|
||||
default:
|
||||
snprintf(buffer, n, "- ");
|
||||
}
|
||||
@ -391,6 +428,14 @@ int Process_compare(const void* v1, const void* v2) {
|
||||
return (p1->state - p2->state);
|
||||
case 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:
|
||||
return (p2->m_size - p1->m_size);
|
||||
case M_RESIDENT:
|
||||
@ -409,6 +454,14 @@ int Process_compare(const void* v1, const void* v2) {
|
||||
return ((p2->utime+p2->stime) - (p1->utime+p1->stime));
|
||||
case 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:
|
||||
return (p1->pid - p2->pid);
|
||||
}
|
||||
@ -422,11 +475,16 @@ char* Process_printField(ProcessField field) {
|
||||
case PGRP: return " PGRP ";
|
||||
case SESSION: return " SESN ";
|
||||
case TTY_NR: return " TTY ";
|
||||
case TPGID: return " TGID ";
|
||||
case TGID: return " TGID ";
|
||||
case TPGID: return "TPGID ";
|
||||
case COMM: return "Command ";
|
||||
case STATE: return "S ";
|
||||
case PRIORITY: return "PRI ";
|
||||
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_RESIDENT: return " RES ";
|
||||
case M_SHARE: return " SHR ";
|
||||
@ -438,6 +496,11 @@ char* Process_printField(ProcessField field) {
|
||||
case PERCENT_CPU: return "CPU% ";
|
||||
case PERCENT_MEM: return "MEM% ";
|
||||
case PROCESSOR: return "CPU ";
|
||||
case NLWP: return "NLWP ";
|
||||
#ifdef HAVE_OPENVZ
|
||||
case VEID: return " VEID ";
|
||||
case VPID: return " VPID ";
|
||||
#endif
|
||||
default: return "- ";
|
||||
}
|
||||
}
|
||||
|
29
Process.h
29
Process.h
@ -28,10 +28,13 @@ in the source distribution for its full text.
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <pwd.h>
|
||||
#include <sched.h>
|
||||
|
||||
// This works only with glibc 2.1+. On earlier versions
|
||||
// the behavior is similar to have a hardcoded page size.
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
||||
#endif
|
||||
|
||||
#define PROCESS_COMM_LEN 300
|
||||
|
||||
@ -41,7 +44,11 @@ typedef enum ProcessField_ {
|
||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||
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,
|
||||
USER, TIME, LAST_PROCESSFIELD
|
||||
USER, TIME, NLWP, TGID,
|
||||
#ifdef HAVE_OPENVZ
|
||||
VEID, VPID,
|
||||
#endif
|
||||
LAST_PROCESSFIELD
|
||||
} ProcessField;
|
||||
|
||||
struct ProcessList_;
|
||||
@ -52,15 +59,16 @@ typedef struct Process_ {
|
||||
struct ProcessList_ *pl;
|
||||
bool updated;
|
||||
|
||||
int pid;
|
||||
unsigned int pid;
|
||||
char* comm;
|
||||
int indent;
|
||||
char state;
|
||||
bool tag;
|
||||
int ppid;
|
||||
int pgrp;
|
||||
int session;
|
||||
int tty_nr;
|
||||
unsigned int ppid;
|
||||
unsigned int pgrp;
|
||||
unsigned int session;
|
||||
unsigned int tty_nr;
|
||||
unsigned int tgid;
|
||||
int tpgid;
|
||||
unsigned long int flags;
|
||||
#ifdef DEBUG
|
||||
@ -75,6 +83,7 @@ typedef struct Process_ {
|
||||
long int cstime;
|
||||
long int priority;
|
||||
long int nice;
|
||||
long int nlwp;
|
||||
#ifdef DEBUG
|
||||
long int itrealvalue;
|
||||
unsigned long int starttime;
|
||||
@ -107,6 +116,10 @@ typedef struct Process_ {
|
||||
float percent_cpu;
|
||||
float percent_mem;
|
||||
char* user;
|
||||
#ifdef HAVE_OPENVZ
|
||||
unsigned int veid;
|
||||
unsigned int vpid;
|
||||
#endif
|
||||
} Process;
|
||||
|
||||
|
||||
@ -130,6 +143,10 @@ void Process_toggleTag(Process* this);
|
||||
|
||||
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);
|
||||
|
||||
#define ONE_K 1024
|
||||
|
@ -37,11 +37,11 @@ in the source distribution for its full text.
|
||||
#endif
|
||||
|
||||
#ifndef PROCSTATFILE
|
||||
#define PROCSTATFILE "/proc/stat"
|
||||
#define PROCSTATFILE PROCDIR "/stat"
|
||||
#endif
|
||||
|
||||
#ifndef PROCMEMINFOFILE
|
||||
#define PROCMEMINFOFILE "/proc/meminfo"
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
@ -53,7 +53,7 @@ in the source distribution for its full text.
|
||||
#endif
|
||||
|
||||
#ifndef PER_PROCESSOR_FIELDS
|
||||
#define PER_PROCESSOR_FIELDS 20
|
||||
#define PER_PROCESSOR_FIELDS 22
|
||||
#endif
|
||||
|
||||
}*/
|
||||
@ -80,6 +80,7 @@ typedef struct ProcessList_ {
|
||||
unsigned long long int* userTime;
|
||||
unsigned long long int* systemTime;
|
||||
unsigned long long int* systemAllTime;
|
||||
unsigned long long int* idleAllTime;
|
||||
unsigned long long int* idleTime;
|
||||
unsigned long long int* niceTime;
|
||||
unsigned long long int* ioWaitTime;
|
||||
@ -90,6 +91,7 @@ typedef struct ProcessList_ {
|
||||
unsigned long long int* userPeriod;
|
||||
unsigned long long int* systemPeriod;
|
||||
unsigned long long int* systemAllPeriod;
|
||||
unsigned long long int* idleAllPeriod;
|
||||
unsigned long long int* idlePeriod;
|
||||
unsigned long long int* nicePeriod;
|
||||
unsigned long long int* ioWaitPeriod;
|
||||
@ -117,7 +119,7 @@ typedef struct ProcessList_ {
|
||||
bool treeView;
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool expandSystemTime;
|
||||
bool detailedCPUTime;
|
||||
#ifdef DEBUG_PROC
|
||||
FILE* traceFile;
|
||||
#endif
|
||||
@ -248,7 +250,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
|
||||
this->treeView = false;
|
||||
this->highlightBaseName = false;
|
||||
this->highlightMegabytes = false;
|
||||
this->expandSystemTime = false;
|
||||
this->detailedCPUTime = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -312,7 +314,7 @@ void ProcessList_remove(ProcessList* this, Process* p) {
|
||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
||||
Process* pp = Hashtable_remove(this->processTable, p->pid);
|
||||
assert(pp == p); (void)pp;
|
||||
int pid = p->pid;
|
||||
unsigned int pid = p->pid;
|
||||
int index = Vector_indexOf(this->processes, p, Process_pidCompare);
|
||||
assert(index != -1);
|
||||
Vector_remove(this->processes, index);
|
||||
@ -333,7 +335,7 @@ static void ProcessList_buildTree(ProcessList* this, int pid, int level, int ind
|
||||
|
||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
||||
Process* process = (Process*) (Vector_get(this->processes, i));
|
||||
if (process->ppid == pid) {
|
||||
if (process->tgid == pid || (process->tgid == process->pid && process->ppid == pid)) {
|
||||
Process* process = (Process*) (Vector_take(this->processes, i));
|
||||
Vector_add(children, process);
|
||||
}
|
||||
@ -360,26 +362,34 @@ void ProcessList_sort(ProcessList* this) {
|
||||
if (!this->treeView) {
|
||||
Vector_sort(this->processes);
|
||||
} else {
|
||||
// Save settings
|
||||
int direction = this->direction;
|
||||
int sortKey = this->sortKey;
|
||||
// Sort by PID
|
||||
this->sortKey = PID;
|
||||
this->direction = 1;
|
||||
Vector_sort(this->processes);
|
||||
// Restore settings
|
||||
this->sortKey = sortKey;
|
||||
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));
|
||||
assert(init->pid == 1);
|
||||
init->indent = 0;
|
||||
Vector_add(this->processes2, init);
|
||||
// Recursively empty list
|
||||
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;
|
||||
this->processes = this->processes2;
|
||||
this->processes2 = t;
|
||||
@ -408,7 +418,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
|
||||
#ifdef DEBUG_PROC
|
||||
int num = ProcessList_read(this, location,
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu "
|
||||
"%c %u %u %u %u %d %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
||||
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
||||
@ -417,7 +427,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
&proc->tpgid, &proc->flags,
|
||||
&proc->minflt, &proc->cminflt, &proc->majflt, &proc->cmajflt,
|
||||
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
||||
&proc->priority, &proc->nice, &zero, &proc->itrealvalue,
|
||||
&proc->priority, &proc->nice, &proc->nlwp, &proc->itrealvalue,
|
||||
&proc->starttime, &proc->vsize, &proc->rss, &proc->rlim,
|
||||
&proc->startcode, &proc->endcode, &proc->startstack, &proc->kstkesp,
|
||||
&proc->kstkeip, &proc->signal, &proc->blocked, &proc->sigignore,
|
||||
@ -426,7 +436,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
#else
|
||||
long int uzero;
|
||||
int num = ProcessList_read(this, location,
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu "
|
||||
"%c %u %u %u %u %d %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
||||
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
||||
@ -435,7 +445,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
&proc->tpgid, &proc->flags,
|
||||
&zero, &zero, &zero, &zero,
|
||||
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
||||
&proc->priority, &proc->nice, &uzero, &uzero,
|
||||
&proc->priority, &proc->nice, &proc->nlwp, &uzero,
|
||||
&zero, &zero, &uzero, &zero,
|
||||
&zero, &zero, &zero, &zero,
|
||||
&zero, &zero, &zero, &zero,
|
||||
@ -454,10 +464,12 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
||||
char statusfilename[MAX_NAME+1];
|
||||
statusfilename[MAX_NAME] = '\0';
|
||||
/*
|
||||
|
||||
bool success = false;
|
||||
char buffer[256];
|
||||
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);
|
||||
FILE* status = ProcessList_fopen(this, statusfilename, "r");
|
||||
if (status) {
|
||||
@ -465,12 +477,11 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
||||
char* ok = fgets(buffer, 255, status);
|
||||
if (!ok)
|
||||
break;
|
||||
if (String_startsWith(buffer, "Uid:")) {
|
||||
int uid1, uid2, uid3, uid4;
|
||||
// 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 (String_startsWith(buffer, "Tgid:")) {
|
||||
int tgid;
|
||||
int ok = ProcessList_read(this, buffer, "Tgid:\t%d", &tgid);
|
||||
if (ok >= 1) {
|
||||
proc->st_uid = uid1;
|
||||
proc->tgid = tgid;
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
@ -478,8 +489,6 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
||||
}
|
||||
fclose(status);
|
||||
}
|
||||
if (!success) {
|
||||
*/
|
||||
snprintf(statusfilename, MAX_NAME, "%s/%s", dirname, name);
|
||||
struct stat sstat;
|
||||
int statok = stat(statusfilename, &sstat);
|
||||
@ -487,10 +496,6 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
||||
return false;
|
||||
proc->st_uid = sstat.st_uid;
|
||||
return true;
|
||||
/*
|
||||
} else
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
|
||||
void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, float period) {
|
||||
@ -521,10 +526,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
char subdirname[MAX_NAME+1];
|
||||
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
|
||||
|
||||
if (access(subdirname, X_OK) == 0) {
|
||||
ProcessList_processEntries(this, subdirname, pid, period);
|
||||
}
|
||||
}
|
||||
|
||||
FILE* status;
|
||||
char statusfilename[MAX_NAME+1];
|
||||
@ -555,7 +558,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
}
|
||||
int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d",
|
||||
&process->m_size, &process->m_resident, &process->m_share,
|
||||
&process->m_trs, &process->m_drs, &process->m_lrs,
|
||||
&process->m_trs, &process->m_lrs, &process->m_drs,
|
||||
&process->m_dt);
|
||||
|
||||
fclose(status);
|
||||
@ -581,6 +584,28 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
if(!existingProcess) {
|
||||
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);
|
||||
status = ProcessList_fopen(this, statusfilename, "r");
|
||||
if (!status) {
|
||||
@ -602,8 +627,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
process->percent_cpu = (process->utime + process->stime - lasttimes) /
|
||||
period * 100.0;
|
||||
|
||||
process->percent_mem = process->m_resident /
|
||||
(float)(this->usedMem - this->cachedMem - this->buffersMem) *
|
||||
process->percent_mem = (process->m_resident * PAGE_SIZE) /
|
||||
(float)(this->totalMem) *
|
||||
100.0;
|
||||
|
||||
this->totalTasks++;
|
||||
@ -633,7 +658,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
}
|
||||
|
||||
void ProcessList_scan(ProcessList* this) {
|
||||
unsigned long long int usertime, nicetime, systemtime, systemalltime, idletime, totaltime;
|
||||
unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime;
|
||||
unsigned long long int swapFree;
|
||||
|
||||
FILE* status;
|
||||
@ -693,14 +718,16 @@ void ProcessList_scan(ProcessList* this) {
|
||||
}
|
||||
// Fields existing on kernels >= 2.6
|
||||
// (and RHEL's patched kernel 2.4...)
|
||||
systemalltime = systemtime + ioWait + irq + softIrq + steal;
|
||||
totaltime = usertime + nicetime + systemalltime + idletime;
|
||||
idlealltime = idletime + ioWait;
|
||||
systemalltime = systemtime + irq + softIrq + steal;
|
||||
totaltime = usertime + nicetime + systemalltime + idlealltime;
|
||||
assert (usertime >= this->userTime[i]);
|
||||
assert (nicetime >= this->niceTime[i]);
|
||||
assert (systemtime >= this->systemTime[i]);
|
||||
assert (idletime >= this->idleTime[i]);
|
||||
assert (totaltime >= this->totalTime[i]);
|
||||
assert (systemalltime >= this->systemAllTime[i]);
|
||||
assert (idlealltime >= this->idleAllTime[i]);
|
||||
assert (ioWait >= this->ioWaitTime[i]);
|
||||
assert (irq >= this->irqTime[i]);
|
||||
assert (softIrq >= this->softIrqTime[i]);
|
||||
@ -709,6 +736,7 @@ void ProcessList_scan(ProcessList* this) {
|
||||
this->nicePeriod[i] = nicetime - this->niceTime[i];
|
||||
this->systemPeriod[i] = systemtime - this->systemTime[i];
|
||||
this->systemAllPeriod[i] = systemalltime - this->systemAllTime[i];
|
||||
this->idleAllPeriod[i] = idlealltime - this->idleAllTime[i];
|
||||
this->idlePeriod[i] = idletime - this->idleTime[i];
|
||||
this->ioWaitPeriod[i] = ioWait - this->ioWaitTime[i];
|
||||
this->irqPeriod[i] = irq - this->irqTime[i];
|
||||
@ -719,6 +747,7 @@ void ProcessList_scan(ProcessList* this) {
|
||||
this->niceTime[i] = nicetime;
|
||||
this->systemTime[i] = systemtime;
|
||||
this->systemAllTime[i] = systemalltime;
|
||||
this->idleAllTime[i] = idlealltime;
|
||||
this->idleTime[i] = idletime;
|
||||
this->ioWaitTime[i] = ioWait;
|
||||
this->irqTime[i] = irq;
|
||||
|
@ -39,11 +39,11 @@ in the source distribution for its full text.
|
||||
#endif
|
||||
|
||||
#ifndef PROCSTATFILE
|
||||
#define PROCSTATFILE "/proc/stat"
|
||||
#define PROCSTATFILE PROCDIR "/stat"
|
||||
#endif
|
||||
|
||||
#ifndef PROCMEMINFOFILE
|
||||
#define PROCMEMINFOFILE "/proc/meminfo"
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
@ -55,7 +55,7 @@ in the source distribution for its full text.
|
||||
#endif
|
||||
|
||||
#ifndef PER_PROCESSOR_FIELDS
|
||||
#define PER_PROCESSOR_FIELDS 20
|
||||
#define PER_PROCESSOR_FIELDS 22
|
||||
#endif
|
||||
|
||||
|
||||
@ -80,6 +80,7 @@ typedef struct ProcessList_ {
|
||||
unsigned long long int* userTime;
|
||||
unsigned long long int* systemTime;
|
||||
unsigned long long int* systemAllTime;
|
||||
unsigned long long int* idleAllTime;
|
||||
unsigned long long int* idleTime;
|
||||
unsigned long long int* niceTime;
|
||||
unsigned long long int* ioWaitTime;
|
||||
@ -90,6 +91,7 @@ typedef struct ProcessList_ {
|
||||
unsigned long long int* userPeriod;
|
||||
unsigned long long int* systemPeriod;
|
||||
unsigned long long int* systemAllPeriod;
|
||||
unsigned long long int* idleAllPeriod;
|
||||
unsigned long long int* idlePeriod;
|
||||
unsigned long long int* nicePeriod;
|
||||
unsigned long long int* ioWaitPeriod;
|
||||
@ -117,7 +119,7 @@ typedef struct ProcessList_ {
|
||||
bool treeView;
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool expandSystemTime;
|
||||
bool detailedCPUTime;
|
||||
#ifdef DEBUG_PROC
|
||||
FILE* traceFile;
|
||||
#endif
|
||||
|
18
RichString.c
18
RichString.c
@ -26,15 +26,6 @@ typedef struct RichString_ {
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
void RichString_write(RichString* this, int attrs, char* data) {
|
||||
RichString_init(this);
|
||||
RichString_append(this, attrs, data);
|
||||
}
|
||||
|
||||
inline void RichString_append(RichString* this, int attrs, char* data) {
|
||||
RichString_appendn(this, attrs, data, strlen(data));
|
||||
}
|
||||
|
||||
inline void RichString_appendn(RichString* this, int attrs, char* data, int len) {
|
||||
int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
|
||||
for (int i = this->len, j = 0; i < last; i++, j++)
|
||||
@ -43,6 +34,15 @@ inline void RichString_appendn(RichString* this, int attrs, char* data, int len)
|
||||
this->len = last;
|
||||
}
|
||||
|
||||
inline void RichString_append(RichString* this, int attrs, char* data) {
|
||||
RichString_appendn(this, attrs, data, strlen(data));
|
||||
}
|
||||
|
||||
void RichString_write(RichString* this, int attrs, char* data) {
|
||||
RichString_init(this);
|
||||
RichString_append(this, attrs, data);
|
||||
}
|
||||
|
||||
void RichString_setAttr(RichString *this, int attrs) {
|
||||
chtype* ch = this->chstr;
|
||||
for (int i = 0; i < this->len; i++) {
|
||||
|
@ -27,12 +27,12 @@ typedef struct RichString_ {
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#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);
|
||||
|
||||
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_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);
|
||||
|
||||
inline int ScreenManager_size(ScreenManager* this);
|
||||
extern int ScreenManager_size(ScreenManager* this);
|
||||
|
||||
void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size);
|
||||
|
||||
|
@ -140,7 +140,10 @@ bool Settings_read(Settings* this, char* fileName) {
|
||||
} else if (String_eq(option[0], "header_margin")) {
|
||||
this->header->margin = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "expand_system_time")) {
|
||||
this->pl->expandSystemTime = atoi(option[1]);
|
||||
// Compatibility option.
|
||||
this->pl->detailedCPUTime = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "detailed_cpu_time")) {
|
||||
this->pl->detailedCPUTime = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "delay")) {
|
||||
this->delay = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "color_scheme")) {
|
||||
@ -197,7 +200,7 @@ bool Settings_write(Settings* this) {
|
||||
fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes);
|
||||
fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView);
|
||||
fprintf(fd, "header_margin=%d\n", (int) this->header->margin);
|
||||
fprintf(fd, "expand_system_time=%d\n", (int) this->pl->expandSystemTime);
|
||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime);
|
||||
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
||||
fprintf(fd, "delay=%d\n", (int) this->delay);
|
||||
fprintf(fd, "left_meters=");
|
||||
@ -221,6 +224,7 @@ bool Settings_write(Settings* this) {
|
||||
fprintf(fd, "right_meter_modes=");
|
||||
for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++)
|
||||
fprintf(fd, "%d ", Header_readMeterMode(this->header, i, RIGHT_HEADER));
|
||||
fprintf(fd, "\n");
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
|
||||
((Object*)this)->delete = SignalsPanel_delete;
|
||||
|
||||
this->signals = Signal_getSignalTable();
|
||||
super->eventHandler = SignalsPanel_EventHandler;
|
||||
super->eventHandler = SignalsPanel_eventHandler;
|
||||
int sigCount = Signal_getSignalCount();
|
||||
for(int i = 0; i < sigCount; i++)
|
||||
Panel_set(super, i, (Object*) this->signals[i]);
|
||||
@ -51,7 +51,7 @@ void SignalsPanel_reset(SignalsPanel* this) {
|
||||
this->state = 0;
|
||||
}
|
||||
|
||||
HandlerResult SignalsPanel_EventHandler(Panel* super, int ch) {
|
||||
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
|
||||
SignalsPanel* this = (SignalsPanel*) super;
|
||||
|
||||
int size = Panel_getSize(super);
|
||||
|
@ -27,6 +27,6 @@ void SignalsPanel_delete(Object* object);
|
||||
|
||||
void SignalsPanel_reset(SignalsPanel* this);
|
||||
|
||||
HandlerResult SignalsPanel_EventHandler(Panel* super, int ch);
|
||||
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
#endif
|
||||
|
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))
|
||||
|
||||
inline void String_delete(char* s);
|
||||
extern void String_delete(char* s);
|
||||
|
||||
inline char* String_copy(char* orig);
|
||||
extern char* String_copy(char* orig);
|
||||
|
||||
char* String_cat(char* s1, char* s2);
|
||||
|
||||
@ -39,7 +39,7 @@ void String_printInt(int i);
|
||||
|
||||
void String_printPointer(void* p);
|
||||
|
||||
inline int String_eq(const char* s1, const char* s2);
|
||||
extern int String_eq(const char* s1, const char* s2);
|
||||
|
||||
char** String_split(char* s, char sep);
|
||||
|
||||
|
2
TODO
2
TODO
@ -5,6 +5,8 @@ BUGS:
|
||||
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=375219
|
||||
* add swap column for swap usage in MB
|
||||
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:
|
||||
|
||||
|
@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
char* UsersTable_getRef(UsersTable* this, int uid) {
|
||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
||||
char* name = (char*) (Hashtable_get(this->users, uid));
|
||||
if (name == NULL) {
|
||||
struct passwd* userData = getpwuid(uid);
|
||||
|
@ -28,10 +28,10 @@ UsersTable* UsersTable_new();
|
||||
|
||||
void UsersTable_delete(UsersTable* this);
|
||||
|
||||
char* UsersTable_getRef(UsersTable* this, int uid);
|
||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
||||
|
||||
inline int UsersTable_size(UsersTable* this);
|
||||
extern int UsersTable_size(UsersTable* this);
|
||||
|
||||
inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
||||
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
||||
|
||||
#endif
|
||||
|
6
Vector.h
6
Vector.h
@ -61,15 +61,15 @@ void Vector_moveDown(Vector* this, int index);
|
||||
|
||||
void Vector_set(Vector* this, int index, void* data_);
|
||||
|
||||
inline Object* Vector_get(Vector* this, int index);
|
||||
extern Object* Vector_get(Vector* this, int index);
|
||||
|
||||
inline int Vector_size(Vector* this);
|
||||
extern int Vector_size(Vector* this);
|
||||
|
||||
void Vector_merge(Vector* this, Vector* v2);
|
||||
|
||||
void Vector_add(Vector* this, void* data_);
|
||||
|
||||
inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
||||
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
||||
|
||||
void Vector_foreach(Vector* this, Vector_procedure f);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([htop],[0.6.5],[loderunner@users.sourceforge.net])
|
||||
AC_INIT([htop],[0.7],[loderunner@users.sourceforge.net])
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_SRCDIR([htop.c])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
@ -58,6 +58,11 @@ AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc fi
|
||||
fi,
|
||||
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/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.6.5" "Bartosz Fenski <fenio@o2.pl>" "Utils"
|
||||
.TH "htop" "1" "0.7" "Bartosz Fenski <fenio@o2.pl>" "Utils"
|
||||
.SH "NAME"
|
||||
htop \- interactive process viewer
|
||||
.SH "SYNTAX"
|
||||
@ -77,6 +77,9 @@ If none is tagged, sends to the currently selected process.
|
||||
.B F10, q
|
||||
Quit
|
||||
.TP
|
||||
.B a (on multiprocessor machines)
|
||||
Set CPU affinity: mark which CPUs a process is allowed to use.
|
||||
.TP
|
||||
.B u
|
||||
Show only processes owned by a specified user.
|
||||
.TP
|
||||
|
82
htop.c
82
htop.c
@ -25,6 +25,7 @@ in the source distribution for its full text.
|
||||
#include "CategoriesPanel.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "TraceScreen.h"
|
||||
#include "AffinityPanel.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
@ -62,13 +63,13 @@ void showHelp(ProcessList* pl) {
|
||||
mvaddstr(3, 0, "CPU usage bar: ");
|
||||
#define addattrstr(a,s) attrset(a);addstr(s)
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
if (pl->expandSystemTime) {
|
||||
if (pl->detailedCPUTime) {
|
||||
addattrstr(CRT_colors[CPU_NICE], "low"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_IOWAIT], "io-wait"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq");
|
||||
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_IOWAIT], "io-wait");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||
} else {
|
||||
addattrstr(CRT_colors[CPU_NICE], "low-priority"); addstr("/");
|
||||
@ -104,6 +105,9 @@ void showHelp(ProcessList* pl) {
|
||||
mvaddstr(15, 0, " F9 k: kill process/tagged processes P: sort by CPU%");
|
||||
mvaddstr(16, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%");
|
||||
mvaddstr(17, 0, " - ] F8: higher priority (root only) T: sort by TIME");
|
||||
if (pl->processorCount > 1)
|
||||
mvaddstr(18, 0, " a: set CPU affinity F4 I: invert sort order");
|
||||
else
|
||||
mvaddstr(18, 0, " F4 I: invert sort order");
|
||||
mvaddstr(19, 0, " F2 S: setup F6 >: select sort column");
|
||||
mvaddstr(20, 0, " F1 h: show this help screen");
|
||||
@ -120,6 +124,8 @@ void showHelp(ProcessList* pl) {
|
||||
mvaddstr(16, 0, " + [ F7"); mvaddstr(16,40, " M");
|
||||
mvaddstr(17, 0, " - ] F8"); mvaddstr(17,40, " T");
|
||||
mvaddstr(18,40, " F4 I");
|
||||
if (pl->processorCount > 1)
|
||||
mvaddstr(18, 0, " a:");
|
||||
mvaddstr(19, 0, " F2 S"); mvaddstr(19,40, " F6 >");
|
||||
mvaddstr(20, 0, " F1 h");
|
||||
mvaddstr(21, 0, " F10 q"); mvaddstr(21,40, " s");
|
||||
@ -169,7 +175,7 @@ static HandlerResult pickWithEnter(Panel* panel, int ch) {
|
||||
static Object* pickFromList(Panel* panel, Panel* list, int x, int y, char** keyLabels, FunctionBar* prevBar) {
|
||||
char* fuKeys[2] = {"Enter", "Esc"};
|
||||
int fuEvents[2] = {13, 27};
|
||||
if (!panel->eventHandler)
|
||||
if (!list->eventHandler)
|
||||
Panel_setEventHandler(list, pickWithEnter);
|
||||
ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, false);
|
||||
ScreenManager_add(scr, list, FunctionBar_new(2, keyLabels, fuKeys, fuEvents), x - 1);
|
||||
@ -208,32 +214,38 @@ int main(int argc, char** argv) {
|
||||
uid_t userId = 0;
|
||||
int sortKey = 0;
|
||||
|
||||
if (argc > 0) {
|
||||
if (String_eq(argv[1], "--help")) {
|
||||
int arg = 1;
|
||||
while (arg < argc) {
|
||||
if (String_eq(argv[arg], "--help")) {
|
||||
printHelpFlag();
|
||||
} else if (String_eq(argv[1], "--version")) {
|
||||
} else if (String_eq(argv[arg], "--version")) {
|
||||
printVersionFlag();
|
||||
} else if (String_eq(argv[1], "--sort-key")) {
|
||||
if (argc < 2) printHelpFlag();
|
||||
if (String_eq(argv[2], "help")) {
|
||||
} else if (String_eq(argv[arg], "--sort-key")) {
|
||||
if (arg == argc - 1) printHelpFlag();
|
||||
arg++;
|
||||
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(argv[2]);
|
||||
sortKey = ColumnsPanel_fieldNameToIndex(field);
|
||||
if (sortKey == -1) {
|
||||
fprintf(stderr, "Error: invalid column \"%s\".\n", argv[2]);
|
||||
fprintf(stderr, "Error: invalid column \"%s\".\n", field);
|
||||
exit(1);
|
||||
}
|
||||
} else if (String_eq(argv[1], "-d")) {
|
||||
if (argc < 2) printHelpFlag();
|
||||
sscanf(argv[2], "%d", &delay);
|
||||
} 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 > 100) delay = 100;
|
||||
} else if (String_eq(argv[1], "-u")) {
|
||||
if (argc < 2) printHelpFlag();
|
||||
setUserOnly(argv[2], &userOnly, &userId);
|
||||
} else if (String_eq(argv[arg], "-u")) {
|
||||
if (arg == argc - 1) printHelpFlag();
|
||||
arg++;
|
||||
setUserOnly(argv[arg], &userOnly, &userId);
|
||||
}
|
||||
arg++;
|
||||
}
|
||||
|
||||
if (access(PROCDIR, R_OK) != 0) {
|
||||
@ -312,7 +324,7 @@ int main(int argc, char** argv) {
|
||||
incSearchIndex = 0;
|
||||
incSearchBuffer[0] = 0;
|
||||
int currPos = Panel_getSelectedIndex(panel);
|
||||
int currPid = 0;
|
||||
unsigned int currPid = 0;
|
||||
int currScrollV = panel->scrollV;
|
||||
if (follow)
|
||||
currPid = ProcessList_get(pl, currPos)->pid;
|
||||
@ -406,7 +418,7 @@ int main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
if (isdigit((char)ch)) {
|
||||
int pid = ch-48 + acc;
|
||||
unsigned int pid = ch-48 + acc;
|
||||
for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++)
|
||||
Panel_setSelected(panel, i);
|
||||
acc = pid * 10;
|
||||
@ -586,6 +598,36 @@ int main(int argc, char** argv) {
|
||||
refreshTimeout = 0;
|
||||
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 'q':
|
||||
quit = 1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Version=0.6.5
|
||||
Version=0.7
|
||||
Name=Htop
|
||||
Type=Application
|
||||
Comment=Show System Processes
|
||||
|
3
htop.h
3
htop.h
@ -29,6 +29,7 @@ in the source distribution for its full text.
|
||||
#include "CategoriesPanel.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "TraceScreen.h"
|
||||
#include "AffinityPanel.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
@ -41,7 +42,7 @@ void printVersionFlag();
|
||||
|
||||
void printHelpFlag();
|
||||
|
||||
void showHelp();
|
||||
void showHelp(ProcessList* pl);
|
||||
|
||||
void addUserToList(int key, void* userCast, void* panelCast);
|
||||
|
||||
|
@ -21,6 +21,8 @@ class writer:
|
||||
self.file.write(text + "\n")
|
||||
out = writer(out)
|
||||
|
||||
print("Generating "+name+".h")
|
||||
|
||||
selfheader = '#include "' + name + '.h"'
|
||||
|
||||
out.write( "/* Do not edit this file. It was automatically generated. */" )
|
||||
@ -52,7 +54,7 @@ for line in file.readlines():
|
||||
elif equals != -1:
|
||||
out.write("extern " + line[:equals] + ";" )
|
||||
elif line[-1] == "{":
|
||||
out.write( line[:-2] + ";" )
|
||||
out.write( line[:-2].replace("inline", "extern") + ";" )
|
||||
state = SKIP
|
||||
else:
|
||||
out.write( line )
|
||||
|
Reference in New Issue
Block a user