23 Commits
0.7 ... 0.8

Author SHA1 Message Date
33fee7963a Tag release 0.8 in revision history. 2008-05-07 23:06:27 +00:00
6beb27d803 Prepare for release 0.8 2008-05-07 23:02:38 +00:00
ce3114079c Fix mouseclick handling in top bar 2008-05-07 23:02:23 +00:00
15ab0ad706 Let mouseclicks tick/untick checkboxes 2008-05-07 23:01:45 +00:00
23615d63a8 Make setup screen fully mouse-driveable 2008-04-23 07:24:27 +00:00
b09339d643 Enabling taskstats by default since they don't break
on systems that don't have them.
2008-03-16 00:31:31 +00:00
2338ad5820 Ability to change sort column with the mouse by
clicking column titles (click again to invert order).
Also, add a consolidated IO kbyte/s column.
2008-03-14 18:50:49 +00:00
fa6f919059 Add missing bits to build system, needed by the inclusion of PLPA.
Thanks to Bert Wesarg for the heads up.
2008-03-11 19:22:17 +00:00
da23c8c5a1 Clean up headers by using 'static' whenever possible.
Reduces resulting code size.
2008-03-09 08:58:38 +00:00
12f4f09e6e Add support for Linux per-process IO statistics,
enabled with the --enable-taskstats flag, which
requires a kernel compiled with taskstats support.
Thanks to Tobias Oetiker!
2008-03-09 08:02:22 +00:00
460608d6e2 Make column operation more comfortable. 2008-03-09 07:42:19 +00:00
8fa33dc336 Add Unicode support, enabled with the --enable-unicode
flag, which requires libncursesw.
Thanks to Sergej Pupykin!
2008-03-09 02:33:23 +00:00
fa87ff0251 Clean up htop's configure options. 2008-03-09 02:16:21 +00:00
93f091c47e BUGFIX: Fix display of CPU count for threaded processes.
When user threads are hidden, process now shows the
sum of processor usage for all processors. When user
threads are displayed, each thread shows its own
processor usage, including the root thread.
(thanks to Bert Wesarg for the report)
Also, add option to display thread colors differently.
2008-03-08 23:39:48 +00:00
52840406ac Make sure help screen is properly filled.
Make behavior of H key consistent.
2008-03-08 23:30:35 +00:00
4df76d127b Embed PLPA (Portable Linux Processor Affinity) in order to support
conflicting affinity API of different Linux kernel versions.
2008-03-05 09:46:47 +00:00
5ed2b85c84 Make clicks on leftmost panel in the Setup screen change setup pages,
like the keyboard navigation does. Fixes bug reported by Tero Keinanen.
https://sourceforge.net/tracker/index.php?func=detail&aid=1754735&group_id=108839&atid=651633
2008-03-05 06:54:30 +00:00
062433fe04 Time keeps passing by 2008-03-05 06:52:22 +00:00
657b0f5efc Time keeps passing by 2008-03-05 06:51:32 +00:00
37bb2fc5c7 Fix display of time with the "Black on White" theme. 2008-03-05 06:39:29 +00:00
cf7fdcd1d6 Experimental feature: beep on permission failures.
Update dates.
2007-12-17 05:57:28 +00:00
a839c3f2ca Adding affinity panel 2007-12-17 05:50:00 +00:00
807df03671 Avoid crashing when using many meters (thanks to David Cho for the report) 2007-11-26 22:06:25 +00:00
91 changed files with 4171 additions and 1136 deletions

View File

@ -7,6 +7,24 @@
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
HandlerResult result = IGNORED;
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
switch(ch) {
case KEY_MOUSE:
case ' ':
CheckItem_set(selected, ! (CheckItem_get(selected)) );
result = HANDLED;
break;
case 0x0a:
case 0x0d:
case KEY_ENTER:
result = BREAK_LOOP;
break;
}
return result;
}
Panel* AffinityPanel_new(int processorCount, unsigned long mask) { Panel* AffinityPanel_new(int processorCount, unsigned long mask) {
Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare); Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare);
this->eventHandler = AffinityPanel_eventHandler; this->eventHandler = AffinityPanel_eventHandler;
@ -29,20 +47,3 @@ unsigned long AffinityPanel_getAffinity(Panel* this) {
} }
return mask; 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;
}

View File

@ -14,6 +14,4 @@ Panel* AffinityPanel_new(int processorCount, unsigned long mask);
unsigned long AffinityPanel_getAffinity(Panel* this); unsigned long AffinityPanel_getAffinity(Panel* this);
HandlerResult AffinityPanel_eventHandler(Panel* this, int ch);
#endif #endif

View File

@ -22,6 +22,34 @@ typedef struct AvailableColumnsPanel_ {
}*/ }*/
static void AvailableColumnsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
Panel_done(super);
free(this);
}
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
char* text = ((ListItem*) Panel_getSelected(super))->value;
HandlerResult result = IGNORED;
switch(ch) {
case 13:
case KEY_ENTER:
case KEY_F(5):
{
int at = Panel_getSelectedIndex(this->columns);
Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
Panel_setSelected(this->columns, at+1);
ColumnsPanel_update(this->columns);
result = HANDLED;
break;
}
}
return result;
}
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) { AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel)); AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel));
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
@ -41,32 +69,3 @@ AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* colu
this->columns = columns; this->columns = columns;
return this; return this;
} }
void AvailableColumnsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
Panel_done(super);
free(this);
}
HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
char* text = ((ListItem*) Panel_getSelected(super))->value;
HandlerResult result = IGNORED;
switch(ch) {
case 13:
case KEY_ENTER:
case KEY_F(5):
{
int at = Panel_getSelectedIndex(this->columns) + 1;
if (at == Panel_getSize(this->columns))
at--;
Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
ColumnsPanel_update(this->columns);
result = HANDLED;
break;
}
}
return result;
}

View File

@ -25,8 +25,4 @@ typedef struct AvailableColumnsPanel_ {
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr); AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr);
void AvailableColumnsPanel_delete(Object* object);
HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch);
#endif #endif

View File

@ -23,41 +23,7 @@ typedef struct AvailableMetersPanel_ {
}*/ }*/
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) { static void AvailableMetersPanel_delete(Object* object) {
AvailableMetersPanel* this = (AvailableMetersPanel*) malloc(sizeof(AvailableMetersPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = AvailableMetersPanel_delete;
this->settings = settings;
this->leftPanel = leftMeters;
this->rightPanel = rightMeters;
this->scr = scr;
super->eventHandler = AvailableMetersPanel_EventHandler;
Panel_setHeader(super, "Available meters");
for (int i = 1; Meter_types[i]; i++) {
MeterType* type = Meter_types[i];
if (type != &CPUMeter) {
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
}
}
MeterType* type = &CPUMeter;
int processors = settings->pl->processorCount;
if (processors > 1) {
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
for (int i = 1; i <= processors; i++) {
char buffer[50];
sprintf(buffer, "%s %d", type->uiName, i);
Panel_add(super, (Object*) ListItem_new(buffer, i));
}
} else {
Panel_add(super, (Object*) ListItem_new("CPU", 1));
}
return this;
}
void AvailableMetersPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
AvailableMetersPanel* this = (AvailableMetersPanel*) object; AvailableMetersPanel* this = (AvailableMetersPanel*) object;
Panel_done(super); Panel_done(super);
@ -69,7 +35,7 @@ static inline void AvailableMetersPanel_addHeader(Header* header, Panel* panel,
Panel_add(panel, (Object*) Meter_toListItem(meter)); Panel_add(panel, (Object*) Meter_toListItem(meter));
} }
HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) { static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
AvailableMetersPanel* this = (AvailableMetersPanel*) super; AvailableMetersPanel* this = (AvailableMetersPanel*) super;
Header* header = this->settings->header; Header* header = this->settings->header;
@ -104,3 +70,37 @@ HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) {
} }
return result; return result;
} }
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) {
AvailableMetersPanel* this = (AvailableMetersPanel*) malloc(sizeof(AvailableMetersPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = AvailableMetersPanel_delete;
this->settings = settings;
this->leftPanel = leftMeters;
this->rightPanel = rightMeters;
this->scr = scr;
super->eventHandler = AvailableMetersPanel_eventHandler;
Panel_setHeader(super, "Available meters");
for (int i = 1; Meter_types[i]; i++) {
MeterType* type = Meter_types[i];
if (type != &CPUMeter) {
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
}
}
MeterType* type = &CPUMeter;
int processors = settings->pl->processorCount;
if (processors > 1) {
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
for (int i = 1; i <= processors; i++) {
char buffer[50];
sprintf(buffer, "%s %d", type->uiName, i);
Panel_add(super, (Object*) ListItem_new(buffer, i));
}
} else {
Panel_add(super, (Object*) ListItem_new("CPU", 1));
}
return this;
}

View File

@ -26,8 +26,4 @@ typedef struct AvailableMetersPanel_ {
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr); AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr);
void AvailableMetersPanel_delete(Object* object);
HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -22,33 +22,6 @@ int CPUMeter_attributes[] = {
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT
}; };
MeterType CPUMeter = {
.setValues = CPUMeter_setValues,
.display = CPUMeter_display,
.mode = BAR_METERMODE,
.items = 6,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "CPU",
.uiName = "CPU",
.caption = "CPU",
.init = CPUMeter_init
};
MeterType AllCPUsMeter = {
.mode = 0,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "AllCPUs",
.uiName = "All CPUs",
.caption = "CPU",
.draw = AllCPUsMeter_draw,
.init = AllCPUsMeter_init,
.setMode = AllCPUsMeter_setMode,
.done = AllCPUsMeter_done
};
#ifndef MIN #ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b))
#endif #endif
@ -56,7 +29,7 @@ MeterType AllCPUsMeter = {
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
#endif #endif
void CPUMeter_init(Meter* this) { static void CPUMeter_init(Meter* this) {
int processor = this->param; int processor = this->param;
if (this->pl->processorCount > 1) { if (this->pl->processorCount > 1) {
char caption[10]; char caption[10];
@ -67,7 +40,7 @@ void CPUMeter_init(Meter* this) {
Meter_setCaption(this, "Avg"); Meter_setCaption(this, "Avg");
} }
void CPUMeter_setValues(Meter* this, char* buffer, int size) { static 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];
@ -90,7 +63,7 @@ void CPUMeter_setValues(Meter* this, char* buffer, int size) {
snprintf(buffer, size, "%5.1f%%", cpu ); snprintf(buffer, size, "%5.1f%%", cpu );
} }
void CPUMeter_display(Object* cast, RichString* out) { static void CPUMeter_display(Object* cast, RichString* out) {
char buffer[50]; char buffer[50];
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
RichString_init(out); RichString_init(out);
@ -123,7 +96,7 @@ void CPUMeter_display(Object* cast, RichString* out) {
} }
} }
void AllCPUsMeter_init(Meter* this) { static void AllCPUsMeter_init(Meter* this) {
int processors = this->pl->processorCount; int processors = this->pl->processorCount;
this->drawBuffer = malloc(sizeof(Meter*) * processors); this->drawBuffer = malloc(sizeof(Meter*) * processors);
Meter** meters = (Meter**) this->drawBuffer; Meter** meters = (Meter**) this->drawBuffer;
@ -133,21 +106,21 @@ void AllCPUsMeter_init(Meter* this) {
this->mode = BAR_METERMODE; this->mode = BAR_METERMODE;
} }
void AllCPUsMeter_done(Meter* this) { static void AllCPUsMeter_done(Meter* this) {
int processors = this->pl->processorCount; int processors = this->pl->processorCount;
Meter** meters = (Meter**) this->drawBuffer; Meter** meters = (Meter**) this->drawBuffer;
for (int i = 0; i < processors; i++) for (int i = 0; i < processors; i++)
Meter_delete((Object*)meters[i]); Meter_delete((Object*)meters[i]);
} }
void AllCPUsMeter_setMode(Meter* this, int mode) { static void AllCPUsMeter_setMode(Meter* this, int mode) {
this->mode = mode; this->mode = mode;
int processors = this->pl->processorCount; int processors = this->pl->processorCount;
int h = Meter_modes[this->mode]->h; int h = Meter_modes[this->mode]->h;
this->h = h * processors; this->h = h * processors;
} }
void AllCPUsMeter_draw(Meter* this, int x, int y, int w) { static void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
int processors = this->pl->processorCount; int processors = this->pl->processorCount;
Meter** meters = (Meter**) this->drawBuffer; Meter** meters = (Meter**) this->drawBuffer;
for (int i = 0; i < processors; i++) { for (int i = 0; i < processors; i++) {
@ -156,3 +129,30 @@ void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
y += meters[i]->h; y += meters[i]->h;
} }
} }
MeterType CPUMeter = {
.setValues = CPUMeter_setValues,
.display = CPUMeter_display,
.mode = BAR_METERMODE,
.items = 6,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "CPU",
.uiName = "CPU",
.caption = "CPU",
.init = CPUMeter_init
};
MeterType AllCPUsMeter = {
.mode = 0,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "AllCPUs",
.uiName = "All CPUs",
.caption = "CPU",
.draw = AllCPUsMeter_draw,
.init = AllCPUsMeter_init,
.setMode = AllCPUsMeter_setMode,
.done = AllCPUsMeter_done
};

View File

@ -23,10 +23,6 @@ in the source distribution for its full text.
extern int CPUMeter_attributes[]; extern int CPUMeter_attributes[];
extern MeterType CPUMeter;
extern MeterType AllCPUsMeter;
#ifndef MIN #ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b))
#endif #endif
@ -34,18 +30,8 @@ extern MeterType AllCPUsMeter;
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
#endif #endif
void CPUMeter_init(Meter* this); extern MeterType CPUMeter;
void CPUMeter_setValues(Meter* this, char* buffer, int size); extern MeterType AllCPUsMeter;
void CPUMeter_display(Object* cast, RichString* out);
void AllCPUsMeter_init(Meter* this);
void AllCPUsMeter_done(Meter* this);
void AllCPUsMeter_setMode(Meter* this, int mode);
void AllCPUsMeter_draw(Meter* this, int x, int y, int w);
#endif #endif

48
CRT.c
View File

@ -68,6 +68,8 @@ typedef enum ColorElements_ {
PROCESS_BASENAME, PROCESS_BASENAME,
PROCESS_HIGH_PRIORITY, PROCESS_HIGH_PRIORITY,
PROCESS_LOW_PRIORITY, PROCESS_LOW_PRIORITY,
PROCESS_THREAD,
PROCESS_THREAD_BASENAME,
BAR_BORDER, BAR_BORDER,
BAR_SHADOW, BAR_SHADOW,
GRAPH_1, GRAPH_1,
@ -112,6 +114,17 @@ int CRT_colors[LAST_COLORELEMENT] = { 0 };
char* CRT_termType; char* CRT_termType;
static void CRT_handleSIGSEGV(int signal) {
CRT_done();
fprintf(stderr, "htop " VERSION " aborted. Please report bug at http://htop.sf.net\n");
exit(1);
}
static void CRT_handleSIGTERM(int signal) {
CRT_done();
exit(0);
}
// TODO: pass an instance of Settings instead. // TODO: pass an instance of Settings instead.
void CRT_init(int delay, int colorScheme) { void CRT_init(int delay, int colorScheme) {
@ -180,17 +193,6 @@ void CRT_enableDelay() {
halfdelay(CRT_delay); halfdelay(CRT_delay);
} }
void CRT_handleSIGSEGV(int signal) {
CRT_done();
fprintf(stderr, "htop " VERSION " aborted. Please report bug at http://htop.sf.net\n");
exit(1);
}
void CRT_handleSIGTERM(int signal) {
CRT_done();
exit(0);
}
void CRT_setColors(int colorScheme) { void CRT_setColors(int colorScheme) {
CRT_colorScheme = colorScheme; CRT_colorScheme = colorScheme;
if (colorScheme == COLORSCHEME_BLACKNIGHT) { if (colorScheme == COLORSCHEME_BLACKNIGHT) {
@ -210,8 +212,8 @@ void CRT_setColors(int colorScheme) {
CRT_colors[FUNCTION_KEY] = A_NORMAL; CRT_colors[FUNCTION_KEY] = A_NORMAL;
CRT_colors[PANEL_HEADER_FOCUS] = A_REVERSE; CRT_colors[PANEL_HEADER_FOCUS] = A_REVERSE;
CRT_colors[PANEL_HEADER_UNFOCUS] = A_REVERSE; CRT_colors[PANEL_HEADER_UNFOCUS] = A_REVERSE;
CRT_colors[PANEL_HIGHLIGHT_FOCUS] = A_REVERSE | A_BOLD; CRT_colors[PANEL_HIGHLIGHT_FOCUS] = A_REVERSE;
CRT_colors[PANEL_HIGHLIGHT_UNFOCUS] = A_REVERSE; CRT_colors[PANEL_HIGHLIGHT_UNFOCUS] = A_BOLD;
CRT_colors[FAILED_SEARCH] = A_REVERSE | A_BOLD; CRT_colors[FAILED_SEARCH] = A_REVERSE | A_BOLD;
CRT_colors[UPTIME] = A_BOLD; CRT_colors[UPTIME] = A_BOLD;
CRT_colors[LARGE_NUMBER] = A_BOLD; CRT_colors[LARGE_NUMBER] = A_BOLD;
@ -228,6 +230,8 @@ void CRT_setColors(int colorScheme) {
CRT_colors[PROCESS_R_STATE] = A_BOLD; CRT_colors[PROCESS_R_STATE] = A_BOLD;
CRT_colors[PROCESS_HIGH_PRIORITY] = A_BOLD; CRT_colors[PROCESS_HIGH_PRIORITY] = A_BOLD;
CRT_colors[PROCESS_LOW_PRIORITY] = A_DIM; CRT_colors[PROCESS_LOW_PRIORITY] = A_DIM;
CRT_colors[PROCESS_THREAD] = A_BOLD;
CRT_colors[PROCESS_THREAD_BASENAME] = A_REVERSE;
CRT_colors[BAR_BORDER] = A_BOLD; CRT_colors[BAR_BORDER] = A_BOLD;
CRT_colors[BAR_SHADOW] = A_DIM; CRT_colors[BAR_SHADOW] = A_DIM;
CRT_colors[SWAP] = A_BOLD; CRT_colors[SWAP] = A_BOLD;
@ -278,11 +282,13 @@ void CRT_setColors(int colorScheme) {
CRT_colors[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White); CRT_colors[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White);
CRT_colors[PROCESS_TAG] = ColorPair(White,Blue); CRT_colors[PROCESS_TAG] = ColorPair(White,Blue);
CRT_colors[PROCESS_MEGABYTES] = ColorPair(Blue,White); CRT_colors[PROCESS_MEGABYTES] = ColorPair(Blue,White);
CRT_colors[PROCESS_BASENAME] = ColorPair(Green,White); CRT_colors[PROCESS_BASENAME] = ColorPair(Blue,White);
CRT_colors[PROCESS_TREE] = ColorPair(Blue,White); CRT_colors[PROCESS_TREE] = ColorPair(Green,White);
CRT_colors[PROCESS_R_STATE] = ColorPair(Green,White); CRT_colors[PROCESS_R_STATE] = ColorPair(Green,White);
CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,White); CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,White);
CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,White); CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,White);
CRT_colors[PROCESS_THREAD] = ColorPair(Blue,White);
CRT_colors[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,White);
CRT_colors[BAR_BORDER] = ColorPair(Blue,White); CRT_colors[BAR_BORDER] = ColorPair(Blue,White);
CRT_colors[BAR_SHADOW] = ColorPair(Black,White); CRT_colors[BAR_SHADOW] = ColorPair(Black,White);
CRT_colors[SWAP] = ColorPair(Red,White); CRT_colors[SWAP] = ColorPair(Red,White);
@ -306,7 +312,7 @@ void CRT_setColors(int colorScheme) {
CRT_colors[CPU_NICE] = ColorPair(Cyan,White); CRT_colors[CPU_NICE] = ColorPair(Cyan,White);
CRT_colors[CPU_NORMAL] = ColorPair(Green,White); CRT_colors[CPU_NORMAL] = ColorPair(Green,White);
CRT_colors[CPU_KERNEL] = ColorPair(Red,White); CRT_colors[CPU_KERNEL] = ColorPair(Red,White);
CRT_colors[CLOCK] = ColorPair(White,White); CRT_colors[CLOCK] = ColorPair(Black,White);
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);
@ -338,6 +344,8 @@ void CRT_setColors(int colorScheme) {
CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Black); CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Black);
CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black); CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black);
CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Black); CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Black);
CRT_colors[PROCESS_THREAD] = ColorPair(Blue,Black);
CRT_colors[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black);
CRT_colors[BAR_BORDER] = ColorPair(Blue,Black); CRT_colors[BAR_BORDER] = ColorPair(Blue,Black);
CRT_colors[BAR_SHADOW] = ColorPair(Black,Black); CRT_colors[BAR_SHADOW] = ColorPair(Black,Black);
CRT_colors[SWAP] = ColorPair(Red,Black); CRT_colors[SWAP] = ColorPair(Red,Black);
@ -393,6 +401,8 @@ void CRT_setColors(int colorScheme) {
CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Blue); CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Blue);
CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Blue); CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Blue);
CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Blue); CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Blue);
CRT_colors[PROCESS_THREAD] = ColorPair(Green,Blue);
CRT_colors[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Blue);
CRT_colors[BAR_BORDER] = A_BOLD | ColorPair(Yellow,Blue); CRT_colors[BAR_BORDER] = A_BOLD | ColorPair(Yellow,Blue);
CRT_colors[BAR_SHADOW] = ColorPair(Cyan,Blue); CRT_colors[BAR_SHADOW] = ColorPair(Cyan,Blue);
CRT_colors[SWAP] = ColorPair(Red,Blue); CRT_colors[SWAP] = ColorPair(Red,Blue);
@ -445,6 +455,8 @@ void CRT_setColors(int colorScheme) {
CRT_colors[PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black); CRT_colors[PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black);
CRT_colors[PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black); CRT_colors[PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black);
CRT_colors[PROCESS_TREE] = ColorPair(Cyan,Black); CRT_colors[PROCESS_TREE] = ColorPair(Cyan,Black);
CRT_colors[PROCESS_THREAD] = ColorPair(Green,Black);
CRT_colors[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black);
CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Black); CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Black);
CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black); CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black);
CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Black); CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Black);
@ -471,7 +483,7 @@ void CRT_setColors(int colorScheme) {
CRT_colors[CPU_NICE] = ColorPair(Blue,Black); CRT_colors[CPU_NICE] = ColorPair(Blue,Black);
CRT_colors[CPU_NORMAL] = ColorPair(Green,Black); CRT_colors[CPU_NORMAL] = ColorPair(Green,Black);
CRT_colors[CPU_KERNEL] = ColorPair(Red,Black); CRT_colors[CPU_KERNEL] = ColorPair(Red,Black);
CRT_colors[CLOCK] = A_BOLD; CRT_colors[CLOCK] = ColorPair(Green,Black);
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);
@ -504,6 +516,8 @@ void CRT_setColors(int colorScheme) {
CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Black); CRT_colors[PROCESS_R_STATE] = ColorPair(Green,Black);
CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black); CRT_colors[PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black);
CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Black); CRT_colors[PROCESS_LOW_PRIORITY] = ColorPair(Red,Black);
CRT_colors[PROCESS_THREAD] = ColorPair(Green,Black);
CRT_colors[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black);
CRT_colors[BAR_BORDER] = A_BOLD; CRT_colors[BAR_BORDER] = A_BOLD;
CRT_colors[BAR_SHADOW] = A_BOLD | ColorPair(Black,Black); CRT_colors[BAR_SHADOW] = A_BOLD | ColorPair(Black,Black);
CRT_colors[SWAP] = ColorPair(Red,Black); CRT_colors[SWAP] = ColorPair(Red,Black);

6
CRT.h
View File

@ -70,6 +70,8 @@ typedef enum ColorElements_ {
PROCESS_BASENAME, PROCESS_BASENAME,
PROCESS_HIGH_PRIORITY, PROCESS_HIGH_PRIORITY,
PROCESS_LOW_PRIORITY, PROCESS_LOW_PRIORITY,
PROCESS_THREAD,
PROCESS_THREAD_BASENAME,
BAR_BORDER, BAR_BORDER,
BAR_SHADOW, BAR_SHADOW,
GRAPH_1, GRAPH_1,
@ -125,10 +127,6 @@ void CRT_disableDelay();
void CRT_enableDelay(); void CRT_enableDelay();
void CRT_handleSIGSEGV(int signal);
void CRT_handleSIGTERM(int signal);
void CRT_setColors(int colorScheme); void CRT_setColors(int colorScheme);
#endif #endif

View File

@ -35,6 +35,87 @@ static char* ColorsFunctions[10] = {" ", " ", " ", " ", "
static char* AvailableColumnsFunctions[10] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done "}; static char* AvailableColumnsFunctions[10] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done "};
static void CategoriesPanel_delete(Object* object) {
Panel* super = (Panel*) object;
CategoriesPanel* this = (CategoriesPanel*) object;
Panel_done(super);
free(this);
}
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, leftMeters, rightMeters, this->scr);
ScreenManager_add(this->scr, leftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, rightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, availableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1);
}
static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
ScreenManager_add(this->scr, displayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1);
}
static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
ScreenManager_add(this->scr, colors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1);
}
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
Panel* columns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, columns, this->scr);
ScreenManager_add(this->scr, columns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, availableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1);
}
static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
CategoriesPanel* this = (CategoriesPanel*) super;
HandlerResult result = IGNORED;
int selected = Panel_getSelectedIndex(super);
switch (ch) {
case EVENT_SETSELECTED:
result = HANDLED;
break;
case KEY_UP:
case KEY_DOWN:
case KEY_NPAGE:
case KEY_PPAGE:
case KEY_HOME:
case KEY_END: {
int previous = selected;
Panel_onKey(super, ch);
selected = Panel_getSelectedIndex(super);
if (previous != selected)
result = HANDLED;
break;
}
}
if (result == HANDLED) {
int size = ScreenManager_size(this->scr);
for (int i = 1; i < size; i++)
ScreenManager_remove(this->scr, 1);
switch (selected) {
case 0:
CategoriesPanel_makeMetersPage(this);
break;
case 1:
CategoriesPanel_makeDisplayOptionsPage(this);
break;
case 2:
CategoriesPanel_makeColorsPage(this);
break;
case 3:
CategoriesPanel_makeColumnsPage(this);
break;
}
}
return result;
}
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) { CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
CategoriesPanel* this = (CategoriesPanel*) malloc(sizeof(CategoriesPanel)); CategoriesPanel* this = (CategoriesPanel*) malloc(sizeof(CategoriesPanel));
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
@ -51,78 +132,3 @@ CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
Panel_add(super, (Object*) ListItem_new("Columns", 0)); Panel_add(super, (Object*) ListItem_new("Columns", 0));
return this; return this;
} }
void CategoriesPanel_delete(Object* object) {
Panel* super = (Panel*) object;
CategoriesPanel* this = (CategoriesPanel*) object;
Panel_done(super);
free(this);
}
HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
CategoriesPanel* this = (CategoriesPanel*) super;
HandlerResult result = IGNORED;
int previous = Panel_getSelectedIndex(super);
switch (ch) {
case KEY_UP:
case KEY_DOWN:
case KEY_NPAGE:
case KEY_PPAGE:
case KEY_HOME:
case KEY_END: {
Panel_onKey(super, ch);
int selected = Panel_getSelectedIndex(super);
if (previous != selected) {
int size = ScreenManager_size(this->scr);
for (int i = 1; i < size; i++)
ScreenManager_remove(this->scr, 1);
switch (selected) {
case 0:
CategoriesPanel_makeMetersPage(this);
break;
case 1:
CategoriesPanel_makeDisplayOptionsPage(this);
break;
case 2:
CategoriesPanel_makeColorsPage(this);
break;
case 3:
CategoriesPanel_makeColumnsPage(this);
break;
}
}
result = HANDLED;
}
}
return result;
}
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, leftMeters, rightMeters, this->scr);
ScreenManager_add(this->scr, leftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, rightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, availableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1);
}
void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
ScreenManager_add(this->scr, displayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1);
}
void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
ScreenManager_add(this->scr, colors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1);
}
void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
Panel* columns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, columns, this->scr);
ScreenManager_add(this->scr, columns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20);
ScreenManager_add(this->scr, availableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1);
}

View File

@ -24,18 +24,8 @@ typedef struct CategoriesPanel_ {
} CategoriesPanel; } CategoriesPanel;
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr);
void CategoriesPanel_delete(Object* object);
HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch);
void CategoriesPanel_makeMetersPage(CategoriesPanel* this); void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this); CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr);
void CategoriesPanel_makeColorsPage(CategoriesPanel* this);
void CategoriesPanel_makeColumnsPage(CategoriesPanel* this);
#endif #endif

View File

@ -1,4 +1,24 @@
What's new in version 0.8
* Ability to change sort column with the mouse by
clicking column titles (click again to invert order)
* Add support for Linux per-process IO statistics,
enabled with the --enable-taskstats flag, which
requires a kernel compiled with taskstats support.
(thanks to Tobias Oetiker)
* Add Unicode support, enabled with the --enable-unicode
flag, which requires libncursesw.
(thanks to Sergej Pupykin)
* BUGFIX: Fix display of CPU count for threaded processes.
When user threads are hidden, process now shows the
sum of processor usage for all processors. When user
threads are displayed, each thread shows its own
processor usage, including the root thread.
(thanks to Bert Wesarg for the report)
* BUGFIX: avoid crashing when using many meters
(thanks to David Cho for the report)
What's new in version 0.7 What's new in version 0.7
* CPU affinity configuration ('a' key) * CPU affinity configuration ('a' key)

View File

@ -28,6 +28,26 @@ char* CHECKITEM_CLASS = "CheckItem";
#define CHECKITEM_CLASS NULL #define CHECKITEM_CLASS NULL
#endif #endif
static void CheckItem_delete(Object* cast) {
CheckItem* this = (CheckItem*)cast;
assert (this != NULL);
free(this->text);
free(this);
}
static void CheckItem_display(Object* cast, RichString* out) {
CheckItem* this = (CheckItem*)cast;
assert (this != NULL);
RichString_write(out, CRT_colors[CHECK_BOX], "[");
if (CheckItem_get(this))
RichString_append(out, CRT_colors[CHECK_MARK], "x");
else
RichString_append(out, CRT_colors[CHECK_MARK], " ");
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
}
CheckItem* CheckItem_new(char* text, bool* ref, bool value) { CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
CheckItem* this = malloc(sizeof(CheckItem)); CheckItem* this = malloc(sizeof(CheckItem));
Object_setClass(this, CHECKITEM_CLASS); Object_setClass(this, CHECKITEM_CLASS);
@ -39,14 +59,6 @@ CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
return this; return this;
} }
void CheckItem_delete(Object* cast) {
CheckItem* this = (CheckItem*)cast;
assert (this != NULL);
free(this->text);
free(this);
}
void CheckItem_set(CheckItem* this, bool value) { void CheckItem_set(CheckItem* this, bool value) {
if (this->ref) if (this->ref)
*(this->ref) = value; *(this->ref) = value;
@ -60,15 +72,3 @@ bool CheckItem_get(CheckItem* this) {
else else
return this->value; 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 (CheckItem_get(this))
RichString_append(out, CRT_colors[CHECK_MARK], "x");
else
RichString_append(out, CRT_colors[CHECK_MARK], " ");
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
}

View File

@ -31,12 +31,8 @@ extern char* CHECKITEM_CLASS;
CheckItem* CheckItem_new(char* text, bool* ref, bool value); CheckItem* CheckItem_new(char* text, bool* ref, bool value);
void CheckItem_delete(Object* cast);
void CheckItem_set(CheckItem* this, bool value); void CheckItem_set(CheckItem* this, bool value);
bool CheckItem_get(CheckItem* this); bool CheckItem_get(CheckItem* this);
void CheckItem_display(Object* cast, RichString* out);
#endif #endif

View File

@ -16,6 +16,13 @@ int ClockMeter_attributes[] = {
CLOCK CLOCK
}; };
static void ClockMeter_setValues(Meter* this, char* buffer, int size) {
time_t t = time(NULL);
struct tm *lt = localtime(&t);
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
strftime(buffer, size, "%H:%M:%S", lt);
}
MeterType ClockMeter = { MeterType ClockMeter = {
.setValues = ClockMeter_setValues, .setValues = ClockMeter_setValues,
.display = NULL, .display = NULL,
@ -27,10 +34,3 @@ MeterType ClockMeter = {
.uiName = "Clock", .uiName = "Clock",
.caption = "Time: ", .caption = "Time: ",
}; };
void ClockMeter_setValues(Meter* this, char* buffer, int size) {
time_t t = time(NULL);
struct tm *lt = localtime(&t);
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
strftime(buffer, size, "%H:%M:%S", lt);
}

View File

@ -19,6 +19,4 @@ extern int ClockMeter_attributes[];
extern MeterType ClockMeter; extern MeterType ClockMeter;
void ClockMeter_setValues(Meter* this, char* buffer, int size);
#endif #endif

View File

@ -37,32 +37,14 @@ static char* ColorSchemes[] = {
NULL NULL
}; };
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { static void ColorsPanel_delete(Object* object) {
ColorsPanel* this = (ColorsPanel*) malloc(sizeof(ColorsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = ColorsPanel_delete;
this->settings = settings;
this->scr = scr;
super->eventHandler = ColorsPanel_EventHandler;
Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemes[i] != NULL; i++) {
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
}
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
return this;
}
void ColorsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
ColorsPanel* this = (ColorsPanel*) object; ColorsPanel* this = (ColorsPanel*) object;
Panel_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) { static HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
ColorsPanel* this = (ColorsPanel*) super; ColorsPanel* this = (ColorsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
@ -72,6 +54,7 @@ HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
case 0x0a: case 0x0a:
case 0x0d: case 0x0d:
case KEY_ENTER: case KEY_ENTER:
case KEY_MOUSE:
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); CheckItem_set((CheckItem*)Panel_get(super, i), false);
@ -93,3 +76,20 @@ HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
return result; return result;
} }
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
ColorsPanel* this = (ColorsPanel*) malloc(sizeof(ColorsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = ColorsPanel_delete;
this->settings = settings;
this->scr = scr;
super->eventHandler = ColorsPanel_EventHandler;
Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemes[i] != NULL; i++) {
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
}
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
return this;
}

View File

@ -30,9 +30,4 @@ typedef struct ColorsPanel_ {
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
void ColorsPanel_delete(Object* object);
HandlerResult ColorsPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -19,57 +19,14 @@ typedef struct ColumnsPanel_ {
}*/ }*/
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) { static void ColumnsPanel_delete(Object* object) {
ColumnsPanel* this = (ColumnsPanel*) malloc(sizeof(ColumnsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = ColumnsPanel_delete;
this->settings = settings;
this->scr = scr;
super->eventHandler = ColumnsPanel_eventHandler;
Panel_setHeader(super, "Active Columns");
ProcessField* fields = this->settings->pl->fields;
for (; *fields; fields++) {
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0));
}
return this;
}
void ColumnsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
ColumnsPanel* this = (ColumnsPanel*) object; ColumnsPanel* this = (ColumnsPanel*) object;
Panel_done(super); Panel_done(super);
free(this); free(this);
} }
int ColumnsPanel_fieldNameToIndex(const char* name) { static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
if (String_eq(name, Process_fieldNames[j])) {
return j;
}
}
return 0;
}
void ColumnsPanel_update(Panel* super) {
ColumnsPanel* this = (ColumnsPanel*) super;
int size = Panel_getSize(super);
this->settings->changed = true;
// FIXME: this is crappily inefficient
free(this->settings->pl->fields);
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
for (int i = 0; i < size; i++) {
char* text = ((ListItem*) Panel_get(super, i))->value;
int j = ColumnsPanel_fieldNameToIndex(text);
if (j > 0)
this->settings->pl->fields[i] = j;
}
this->settings->pl->fields[size] = 0;
}
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
int selected = Panel_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
@ -108,3 +65,47 @@ HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
ColumnsPanel_update(super); ColumnsPanel_update(super);
return result; return result;
} }
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) {
ColumnsPanel* this = (ColumnsPanel*) malloc(sizeof(ColumnsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = ColumnsPanel_delete;
this->settings = settings;
this->scr = scr;
super->eventHandler = ColumnsPanel_eventHandler;
Panel_setHeader(super, "Active Columns");
ProcessField* fields = this->settings->pl->fields;
for (; *fields; fields++) {
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0));
}
return 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) {
ColumnsPanel* this = (ColumnsPanel*) super;
int size = Panel_getSize(super);
this->settings->changed = true;
// FIXME: this is crappily inefficient
free(this->settings->pl->fields);
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
for (int i = 0; i < size; i++) {
char* text = ((ListItem*) Panel_get(super, i))->value;
int j = ColumnsPanel_fieldNameToIndex(text);
if (j > 0)
this->settings->pl->fields[i] = j;
}
this->settings->pl->fields[size] = 0;
}

View File

@ -22,12 +22,9 @@ typedef struct ColumnsPanel_ {
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr); ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr);
void ColumnsPanel_delete(Object* object);
int ColumnsPanel_fieldNameToIndex(const char* name); int ColumnsPanel_fieldNameToIndex(const char* name);
void ColumnsPanel_update(Panel* super); void ColumnsPanel_update(Panel* super);
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch);
#endif #endif

View File

@ -20,36 +20,14 @@ typedef struct DisplayOptionsPanel_ {
}*/ }*/
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) { static void DisplayOptionsPanel_delete(Object* object) {
DisplayOptionsPanel* this = (DisplayOptionsPanel*) malloc(sizeof(DisplayOptionsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = DisplayOptionsPanel_delete;
this->settings = settings;
this->scr = scr;
super->eventHandler = DisplayOptionsPanel_eventHandler;
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("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;
}
void DisplayOptionsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object; DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
Panel_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
@ -59,6 +37,7 @@ HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
case 0x0a: case 0x0a:
case 0x0d: case 0x0d:
case KEY_ENTER: case KEY_ENTER:
case KEY_MOUSE:
case ' ': case ' ':
CheckItem_set(selected, ! (CheckItem_get(selected)) ); CheckItem_set(selected, ! (CheckItem_get(selected)) );
result = HANDLED; result = HANDLED;
@ -74,3 +53,25 @@ HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
return result; return result;
} }
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
DisplayOptionsPanel* this = (DisplayOptionsPanel*) malloc(sizeof(DisplayOptionsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = DisplayOptionsPanel_delete;
this->settings = settings;
this->scr = scr;
super->eventHandler = DisplayOptionsPanel_eventHandler;
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("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("Display threads in a different color"), &(settings->pl->highlightThreads), 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;
}

View File

@ -23,9 +23,4 @@ typedef struct DisplayOptionsPanel_ {
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
void DisplayOptionsPanel_delete(Object* object);
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch);
#endif #endif

View File

@ -34,7 +34,7 @@ struct Hashtable_ {
#ifdef DEBUG #ifdef DEBUG
bool Hashtable_isConsistent(Hashtable* this) { static bool Hashtable_isConsistent(Hashtable* this) {
int items = 0; int items = 0;
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
HashtableItem* bucket = this->buckets[i]; HashtableItem* bucket = this->buckets[i];
@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) {
#endif #endif
HashtableItem* HashtableItem_new(unsigned int key, void* value) { static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
HashtableItem* this; HashtableItem* this;
this = (HashtableItem*) malloc(sizeof(HashtableItem)); this = (HashtableItem*) malloc(sizeof(HashtableItem));
@ -99,11 +99,6 @@ void Hashtable_delete(Hashtable* this) {
free(this); free(this);
} }
inline int Hashtable_size(Hashtable* this) {
assert(Hashtable_isConsistent(this));
return this->items;
}
void Hashtable_put(Hashtable* this, unsigned int key, void* value) { void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
unsigned int index = key % this->size; unsigned int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]); HashtableItem** bucketPtr = &(this->buckets[index]);

View File

@ -35,20 +35,14 @@ struct Hashtable_ {
#ifdef DEBUG #ifdef DEBUG
bool Hashtable_isConsistent(Hashtable* this);
int Hashtable_count(Hashtable* this); int Hashtable_count(Hashtable* this);
#endif #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);
void Hashtable_put(Hashtable* this, unsigned int key, void* value); void Hashtable_put(Hashtable* this, unsigned int key, void* value);
void* Hashtable_remove(Hashtable* this, unsigned int key); void* Hashtable_remove(Hashtable* this, unsigned int key);

View File

@ -73,6 +73,8 @@ void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) {
? this->leftMeters ? this->leftMeters
: this->rightMeters; : this->rightMeters;
if (i >= Vector_size(meters))
return;
Meter* meter = (Meter*) Vector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
Meter_setMode(meter, mode); Meter_setMode(meter, mode);
} }

View File

@ -29,6 +29,21 @@ char* LISTITEM_CLASS = "ListItem";
#define LISTITEM_CLASS NULL #define LISTITEM_CLASS NULL
#endif #endif
static void ListItem_delete(Object* cast) {
ListItem* this = (ListItem*)cast;
free(this->value);
free(this);
}
static void ListItem_display(Object* cast, RichString* out) {
ListItem* this = (ListItem*)cast;
assert (this != NULL);
int len = strlen(this->value)+1;
char buffer[len+1];
snprintf(buffer, len, "%s", this->value);
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
}
ListItem* ListItem_new(char* value, int key) { ListItem* ListItem_new(char* value, int key) {
ListItem* this = malloc(sizeof(ListItem)); ListItem* this = malloc(sizeof(ListItem));
Object_setClass(this, LISTITEM_CLASS); Object_setClass(this, LISTITEM_CLASS);
@ -46,21 +61,6 @@ void ListItem_append(ListItem* this, char* text) {
this->value = buf; this->value = buf;
} }
void ListItem_delete(Object* cast) {
ListItem* this = (ListItem*)cast;
free(this->value);
free(this);
}
void ListItem_display(Object* cast, RichString* out) {
ListItem* this = (ListItem*)cast;
assert (this != NULL);
int len = strlen(this->value)+1;
char buffer[len+1];
snprintf(buffer, len, "%s", this->value);
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
}
const char* ListItem_getRef(ListItem* this) { const char* ListItem_getRef(ListItem* this) {
return this->value; return this->value;
} }

View File

@ -34,10 +34,6 @@ ListItem* ListItem_new(char* value, int key);
void ListItem_append(ListItem* this, char* text); void ListItem_append(ListItem* this, char* text);
void ListItem_delete(Object* cast);
void ListItem_display(Object* cast, RichString* out);
const char* ListItem_getRef(ListItem* this); const char* ListItem_getRef(ListItem* this);
int ListItem_compare(const void* cast1, const void* cast2); int ListItem_compare(const void* cast1, const void* cast2);

View File

@ -16,6 +16,52 @@ int LoadAverageMeter_attributes[] = {
LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE
}; };
int LoadMeter_attributes[] = { LOAD };
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
int activeProcs, totalProcs, lastProc;
FILE *fd = fopen(PROCDIR "/loadavg", "r");
int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
&activeProcs, &totalProcs, &lastProc);
(void) read;
assert(read == 6);
fclose(fd);
}
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
}
static void LoadAverageMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
char buffer[20];
RichString_init(out);
sprintf(buffer, "%.2f ", this->values[2]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
sprintf(buffer, "%.2f ", this->values[1]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
sprintf(buffer, "%.2f ", this->values[0]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
}
static void LoadMeter_setValues(Meter* this, char* buffer, int size) {
double five, fifteen;
LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
if (this->values[0] > this->total) {
this->total = this->values[0];
}
snprintf(buffer, size, "%.2f", this->values[0]);
}
static void LoadMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
char buffer[20];
RichString_init(out);
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
RichString_append(out, CRT_colors[LOAD], buffer);
}
MeterType LoadAverageMeter = { MeterType LoadAverageMeter = {
.setValues = LoadAverageMeter_setValues, .setValues = LoadAverageMeter_setValues,
.display = LoadAverageMeter_display, .display = LoadAverageMeter_display,
@ -28,8 +74,6 @@ MeterType LoadAverageMeter = {
.caption = "Load average: " .caption = "Load average: "
}; };
int LoadMeter_attributes[] = { LOAD };
MeterType LoadMeter = { MeterType LoadMeter = {
.setValues = LoadMeter_setValues, .setValues = LoadMeter_setValues,
.display = LoadMeter_display, .display = LoadMeter_display,
@ -41,47 +85,3 @@ MeterType LoadMeter = {
.uiName = "Load", .uiName = "Load",
.caption = "Load: " .caption = "Load: "
}; };
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
int activeProcs, totalProcs, lastProc;
FILE *fd = fopen(PROCDIR "/loadavg", "r");
int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
&activeProcs, &totalProcs, &lastProc);
(void) read;
assert(read == 6);
fclose(fd);
}
void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
}
void LoadAverageMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
char buffer[20];
RichString_init(out);
sprintf(buffer, "%.2f ", this->values[2]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
sprintf(buffer, "%.2f ", this->values[1]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
sprintf(buffer, "%.2f ", this->values[0]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
}
void LoadMeter_setValues(Meter* this, char* buffer, int size) {
double five, fifteen;
LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
if (this->values[0] > this->total) {
this->total = this->values[0];
}
snprintf(buffer, size, "%.2f", this->values[0]);
}
void LoadMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
char buffer[20];
RichString_init(out);
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
RichString_append(out, CRT_colors[LOAD], buffer);
}

View File

@ -17,18 +17,10 @@ in the source distribution for its full text.
extern int LoadAverageMeter_attributes[]; extern int LoadAverageMeter_attributes[];
extern MeterType LoadAverageMeter;
extern int LoadMeter_attributes[]; extern int LoadMeter_attributes[];
extern MeterType LoadAverageMeter;
extern MeterType LoadMeter; extern MeterType LoadMeter;
void LoadAverageMeter_setValues(Meter* this, char* buffer, int size);
void LoadAverageMeter_display(Object* cast, RichString* out);
void LoadMeter_setValues(Meter* this, char* buffer, int size);
void LoadMeter_display(Object* cast, RichString* out);
#endif #endif

View File

@ -1,4 +1,6 @@
SUBDIRS = plpa-1.1
bin_PROGRAMS = htop bin_PROGRAMS = htop
dist_man_MANS = htop.1 dist_man_MANS = htop.1
EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \ EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \
@ -8,7 +10,7 @@ applications_DATA = htop.desktop
pixmapdir = $(datadir)/pixmaps pixmapdir = $(datadir)/pixmaps
pixmap_DATA = htop.png pixmap_DATA = htop.png
AM_CFLAGS = -pedantic -Wall -std=c99 htop_CFLAGS = -pedantic -Wall -std=c99 -D_XOPEN_SOURCE_EXTENDED
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
@ -32,6 +34,7 @@ SUFFIXES = .h
BUILT_SOURCES = $(myhtopheaders) BUILT_SOURCES = $(myhtopheaders)
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h
htop_LDADD = $(top_builddir)/plpa-1.1/src/libplpa_included.la
profile: profile:
$(MAKE) all CFLAGS="-pg -O2" $(MAKE) all CFLAGS="-pg -O2"

View File

@ -23,19 +23,7 @@ int MemoryMeter_attributes[] = {
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
}; };
MeterType MemoryMeter = { static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
.setValues = MemoryMeter_setValues,
.display = MemoryMeter_display,
.mode = BAR_METERMODE,
.items = 3,
.total = 100.0,
.attributes = MemoryMeter_attributes,
"Memory",
"Memory",
"Mem"
};
void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
long int usedMem = this->pl->usedMem; long int usedMem = this->pl->usedMem;
long int buffersMem = this->pl->buffersMem; long int buffersMem = this->pl->buffersMem;
long int cachedMem = this->pl->cachedMem; long int cachedMem = this->pl->cachedMem;
@ -47,7 +35,7 @@ void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024); snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024);
} }
void MemoryMeter_display(Object* cast, RichString* out) { static void MemoryMeter_display(Object* cast, RichString* out) {
char buffer[50]; char buffer[50];
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
int div = 1024; char* format = "%ldM "; int div = 1024; char* format = "%ldM ";
@ -69,3 +57,15 @@ void MemoryMeter_display(Object* cast, RichString* out) {
RichString_append(out, CRT_colors[METER_TEXT], "cache:"); RichString_append(out, CRT_colors[METER_TEXT], "cache:");
RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); RichString_append(out, CRT_colors[MEMORY_CACHE], buffer);
} }
MeterType MemoryMeter = {
.setValues = MemoryMeter_setValues,
.display = MemoryMeter_display,
.mode = BAR_METERMODE,
.items = 3,
.total = 100.0,
.attributes = MemoryMeter_attributes,
"Memory",
"Memory",
"Mem"
};

View File

@ -26,8 +26,4 @@ extern int MemoryMeter_attributes[];
extern MeterType MemoryMeter; extern MeterType MemoryMeter;
void MemoryMeter_setValues(Meter* this, char* buffer, int size);
void MemoryMeter_display(Object* cast, RichString* out);
#endif #endif

91
Meter.c
View File

@ -18,6 +18,7 @@ in the source distribution for its full text.
#include "ListItem.h" #include "ListItem.h"
#include "String.h" #include "String.h"
#include "ProcessList.h" #include "ProcessList.h"
#include "RichString.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
@ -123,45 +124,6 @@ MeterType* Meter_types[] = {
NULL NULL
}; };
static MeterMode BarMeterMode = {
.uiName = "Bar",
.h = 1,
.draw = BarMeterMode_draw,
};
static MeterMode TextMeterMode = {
.uiName = "Text",
.h = 1,
.draw = TextMeterMode_draw,
};
#ifdef USE_FUNKY_MODES
static MeterMode GraphMeterMode = {
.uiName = "Graph",
.h = 3,
.draw = GraphMeterMode_draw,
};
static MeterMode LEDMeterMode = {
.uiName = "LED",
.h = 3,
.draw = LEDMeterMode_draw,
};
#endif
MeterMode* Meter_modes[] = {
NULL,
&BarMeterMode,
&TextMeterMode,
#ifdef USE_FUNKY_MODES
&GraphMeterMode,
&LEDMeterMode,
#endif
NULL
};
static RichString Meter_stringBuffer; static RichString Meter_stringBuffer;
Meter* Meter_new(ProcessList* pl, int param, MeterType* type) { Meter* Meter_new(ProcessList* pl, int param, MeterType* type) {
@ -253,7 +215,7 @@ ListItem* Meter_toListItem(Meter* this) {
/* ---------- TextMeterMode ---------- */ /* ---------- TextMeterMode ---------- */
void TextMeterMode_draw(Meter* this, int x, int y, int w) { static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
MeterType* type = this->type; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, METER_BUFFER_LEN - 1);
@ -266,14 +228,14 @@ void TextMeterMode_draw(Meter* this, int x, int y, int w) {
Meter_displayToStringBuffer(this, buffer); Meter_displayToStringBuffer(this, buffer);
mvhline(y, x, ' ', CRT_colors[DEFAULT_COLOR]); mvhline(y, x, ' ', CRT_colors[DEFAULT_COLOR]);
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
mvaddchstr(y, x, Meter_stringBuffer.chstr); RichString_printVal(Meter_stringBuffer, y, x);
} }
/* ---------- BarMeterMode ---------- */ /* ---------- BarMeterMode ---------- */
static char BarMeterMode_characters[] = "|#*@$%&"; static char BarMeterMode_characters[] = "|#*@$%&";
void BarMeterMode_draw(Meter* this, int x, int y, int w) { static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
MeterType* type = this->type; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, METER_BUFFER_LEN - 1);
@ -361,7 +323,7 @@ static int GraphMeterMode_colors[21] = {
static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_"; static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_";
void GraphMeterMode_draw(Meter* this, int x, int y, int w) { static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (!this->drawBuffer) this->drawBuffer = calloc(sizeof(double), METER_BUFFER_LEN); if (!this->drawBuffer) this->drawBuffer = calloc(sizeof(double), METER_BUFFER_LEN);
double* drawBuffer = (double*) this->drawBuffer; double* drawBuffer = (double*) this->drawBuffer;
@ -407,7 +369,7 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) {
mvaddstr(y+i, x, LEDMeterMode_digits[i][n]); mvaddstr(y+i, x, LEDMeterMode_digits[i][n]);
} }
void LEDMeterMode_draw(Meter* this, int x, int y, int w) { static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
MeterType* type = this->type; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, METER_BUFFER_LEN - 1);
@ -418,7 +380,7 @@ void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
mvaddstr(y+2, x, this->caption); mvaddstr(y+2, x, this->caption);
int xx = x + strlen(this->caption); int xx = x + strlen(this->caption);
for (int i = 0; i < Meter_stringBuffer.len; i++) { for (int i = 0; i < Meter_stringBuffer.len; i++) {
char c = Meter_stringBuffer.chstr[i]; char c = RichString_getCharVal(Meter_stringBuffer, i);
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
LEDMeterMode_drawDigit(xx, y, c-48); LEDMeterMode_drawDigit(xx, y, c-48);
xx += 4; xx += 4;
@ -431,3 +393,42 @@ void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
} }
#endif #endif
static MeterMode BarMeterMode = {
.uiName = "Bar",
.h = 1,
.draw = BarMeterMode_draw,
};
static MeterMode TextMeterMode = {
.uiName = "Text",
.h = 1,
.draw = TextMeterMode_draw,
};
#ifdef USE_FUNKY_MODES
static MeterMode GraphMeterMode = {
.uiName = "Graph",
.h = 3,
.draw = GraphMeterMode_draw,
};
static MeterMode LEDMeterMode = {
.uiName = "LED",
.h = 3,
.draw = LEDMeterMode_draw,
};
#endif
MeterMode* Meter_modes[] = {
NULL,
&BarMeterMode,
&TextMeterMode,
#ifdef USE_FUNKY_MODES
&GraphMeterMode,
&LEDMeterMode,
#endif
NULL
};

19
Meter.h
View File

@ -21,6 +21,7 @@ in the source distribution for its full text.
#include "ListItem.h" #include "ListItem.h"
#include "String.h" #include "String.h"
#include "ProcessList.h" #include "ProcessList.h"
#include "RichString.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
@ -113,12 +114,6 @@ extern char* METER_CLASS;
extern MeterType* Meter_types[]; extern MeterType* Meter_types[];
#ifdef USE_FUNKY_MODES
#endif
extern MeterMode* Meter_modes[];
Meter* Meter_new(ProcessList* pl, int param, MeterType* type); Meter* Meter_new(ProcessList* pl, int param, MeterType* type);
void Meter_delete(Object* cast); void Meter_delete(Object* cast);
@ -131,24 +126,22 @@ ListItem* Meter_toListItem(Meter* this);
/* ---------- TextMeterMode ---------- */ /* ---------- TextMeterMode ---------- */
void TextMeterMode_draw(Meter* this, int x, int y, int w);
/* ---------- BarMeterMode ---------- */ /* ---------- BarMeterMode ---------- */
void BarMeterMode_draw(Meter* this, int x, int y, int w);
#ifdef USE_FUNKY_MODES #ifdef USE_FUNKY_MODES
/* ---------- GraphMeterMode ---------- */ /* ---------- GraphMeterMode ---------- */
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0) #define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0)
void GraphMeterMode_draw(Meter* this, int x, int y, int w);
/* ---------- LEDMeterMode ---------- */ /* ---------- LEDMeterMode ---------- */
void LEDMeterMode_draw(Meter* this, int x, int y, int w); #endif
#ifdef USE_FUNKY_MODES
#endif #endif
extern MeterMode* Meter_modes[];
#endif #endif

View File

@ -20,32 +20,14 @@ typedef struct MetersPanel_ {
}*/ }*/
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) { static void MetersPanel_delete(Object* object) {
MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = MetersPanel_delete;
this->settings = settings;
this->meters = meters;
this->scr = scr;
super->eventHandler = MetersPanel_EventHandler;
Panel_setHeader(super, header);
for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i);
Panel_add(super, (Object*) Meter_toListItem(meter));
}
return this;
}
void MetersPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
MetersPanel* this = (MetersPanel*) object; MetersPanel* this = (MetersPanel*) object;
Panel_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult MetersPanel_EventHandler(Panel* super, int ch) { static HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
MetersPanel* this = (MetersPanel*) super; MetersPanel* this = (MetersPanel*) super;
int selected = Panel_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
@ -103,3 +85,21 @@ HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
} }
return result; return result;
} }
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) {
MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = MetersPanel_delete;
this->settings = settings;
this->meters = meters;
this->scr = scr;
super->eventHandler = MetersPanel_EventHandler;
Panel_setHeader(super, header);
for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i);
Panel_add(super, (Object*) Meter_toListItem(meter));
}
return this;
}

View File

@ -23,8 +23,4 @@ typedef struct MetersPanel_ {
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr); MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr);
void MetersPanel_delete(Object* object);
HandlerResult MetersPanel_EventHandler(Panel* super, int ch);
#endif #endif

View File

@ -48,7 +48,7 @@ void Object_setClass(void* this, char* class) {
((Object*)this)->class = class; ((Object*)this)->class = class;
} }
void Object_display(Object* this, RichString* out) { static void Object_display(Object* this, RichString* out) {
char objAddress[50]; char objAddress[50];
sprintf(objAddress, "%s @ %p", this->class, (void*) this); sprintf(objAddress, "%s @ %p", this->class, (void*) this);
RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress); RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress);

View File

@ -47,8 +47,6 @@ extern char* OBJECT_CLASS;
void Object_setClass(void* this, char* class); void Object_setClass(void* this, char* class);
void Object_display(Object* this, RichString* out);
#endif #endif
#endif #endif

19
Panel.c
View File

@ -31,6 +31,8 @@ typedef enum HandlerResult_ {
BREAK_LOOP BREAK_LOOP
} HandlerResult; } HandlerResult;
#define EVENT_SETSELECTED -1
typedef HandlerResult(*Panel_EventHandler)(Panel*, int); typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
struct Panel_ { struct Panel_ {
@ -222,6 +224,9 @@ void Panel_setSelected(Panel* this, int selected) {
selected = MAX(0, MIN(Vector_size(this->items) - 1, selected)); selected = MAX(0, MIN(Vector_size(this->items) - 1, selected));
this->selected = selected; this->selected = selected;
if (this->eventHandler) {
this->eventHandler(this, EVENT_SETSELECTED);
}
} }
void Panel_draw(Panel* this, bool focus) { void Panel_draw(Panel* this, bool focus) {
@ -260,8 +265,8 @@ void Panel_draw(Panel* this, bool focus) {
attrset(attr); attrset(attr);
mvhline(y, x, ' ', this->w); mvhline(y, x, ' ', this->w);
if (scrollH < this->header.len) { if (scrollH < this->header.len) {
mvaddchnstr(y, x, this->header.chstr + scrollH, RichString_printoffnVal(this->header, y, x, scrollH,
MIN(this->header.len - scrollH, this->w)); MIN(this->header.len - scrollH, this->w));
} }
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
y++; y++;
@ -284,12 +289,12 @@ void Panel_draw(Panel* this, bool focus) {
RichString_setAttr(&itemRef, highlight); RichString_setAttr(&itemRef, highlight);
mvhline(y + j, x+0, ' ', this->w); mvhline(y + j, x+0, ' ', this->w);
if (amt > 0) if (amt > 0)
mvaddchnstr(y+j, x+0, itemRef.chstr + scrollH, amt); RichString_printoffnVal(itemRef, y+j, x+0, scrollH, amt);
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
} else { } else {
mvhline(y+j, x+0, ' ', this->w); mvhline(y+j, x+0, ' ', this->w);
if (amt > 0) if (amt > 0)
mvaddchnstr(y+j, x+0, itemRef.chstr + scrollH, amt); RichString_printoffnVal(itemRef, y+j, x+0, scrollH, amt);
} }
} }
for (int i = y + (last - first); i < y + this->h; i++) for (int i = y + (last - first); i < y + this->h; i++)
@ -307,12 +312,14 @@ void Panel_draw(Panel* this, bool focus) {
newObj->display(newObj, &newRef); newObj->display(newObj, &newRef);
mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w); mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w);
if (scrollH < oldRef.len) if (scrollH < oldRef.len)
mvaddchnstr(y+ this->oldSelected - this->scrollV, x+0, oldRef.chstr + this->scrollH, MIN(oldRef.len - scrollH, this->w)); RichString_printoffnVal(oldRef, y+this->oldSelected - this->scrollV, x,
this->scrollH, MIN(oldRef.len - scrollH, this->w));
attrset(highlight); attrset(highlight);
mvhline(y+this->selected - this->scrollV, x+0, ' ', this->w); mvhline(y+this->selected - this->scrollV, x+0, ' ', this->w);
RichString_setAttr(&newRef, highlight); RichString_setAttr(&newRef, highlight);
if (scrollH < newRef.len) if (scrollH < newRef.len)
mvaddchnstr(y+this->selected - this->scrollV, x+0, newRef.chstr + this->scrollH, MIN(newRef.len - scrollH, this->w)); RichString_printoffnVal(newRef, y+this->selected - this->scrollV, x,
this->scrollH, MIN(newRef.len - scrollH, this->w));
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
} }
this->oldSelected = this->selected; this->oldSelected = this->selected;

View File

@ -33,6 +33,8 @@ typedef enum HandlerResult_ {
BREAK_LOOP BREAK_LOOP
} HandlerResult; } HandlerResult;
#define EVENT_SETSELECTED -1
typedef HandlerResult(*Panel_EventHandler)(Panel*, int); typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
struct Panel_ { struct Panel_ {

339
Process.c
View File

@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "CRT.h" #include "CRT.h"
#include "String.h" #include "String.h"
#include "Process.h" #include "Process.h"
#include "RichString.h"
#include "debug.h" #include "debug.h"
@ -27,6 +28,8 @@ in the source distribution for its full text.
#include <pwd.h> #include <pwd.h>
#include <sched.h> #include <sched.h>
#include <plpa.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 #ifndef PAGE_SIZE
@ -42,10 +45,13 @@ 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, NLWP, TGID,
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
VEID, VPID, VEID, VPID,
#endif #endif
#ifdef HAVE_TASKSTATS
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
#endif
LAST_PROCESSFIELD LAST_PROCESSFIELD
} ProcessField; } ProcessField;
@ -118,6 +124,19 @@ typedef struct Process_ {
unsigned int veid; unsigned int veid;
unsigned int vpid; unsigned int vpid;
#endif #endif
#ifdef HAVE_TASKSTATS
unsigned long long io_rchar;
unsigned long long io_wchar;
unsigned long long io_syscr;
unsigned long long io_syscw;
unsigned long long io_read_bytes;
unsigned long long io_write_bytes;
unsigned long long io_cancelled_write_bytes;
double io_rate_read_bps;
unsigned long long io_rate_read_time;
double io_rate_write_bps;
unsigned long long io_rate_write_time;
#endif
} Process; } Process;
}*/ }*/
@ -129,86 +148,44 @@ 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", "NLWP", "TGID",
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
"VEID", "VPID", "VEID", "VPID",
#endif
#ifdef HAVE_TASKSTATS
"RCHAR", "WCHAR", "SYSCR", "SYSCW", "RBYTES", "WBYTES", "CNCLWB",
"IO_READ_RATE", "IO_WRITE_RATE", "IO_RATE",
#endif #endif
"*** report bug! ***" "*** report bug! ***"
}; };
char *Process_fieldTitles[] = {
"", " PID ", "Command ", "S ", " PPID ", " PGRP ", " SESN ",
" TTY ", "TPGID ", "- ", "- ", "- ", "- ", "- ",
" UTIME+ ", " STIME+ ", "- ", "- ", "PRI ", " NI ", "- ",
"- ", "- ", "- ", "- ", "- ", "- ", "- ",
"- ", "- ", "- ", "- ", "- ", "- ", "- ",
"- ", "- ", "- ", "CPU ", " VIRT ", " RES ", " SHR ",
" CODE ", " DATA ", " LIB ", " DIRTY ", " UID ", "CPU% ", "MEM% ",
"USER ", " TIME+ ", "NLWP ", " TGID ",
#ifdef HAVE_OPENVZ
" VEID ", " VPID ",
#endif
#ifdef HAVE_TASKSTATS
" RD_CHAR ", " WR_CHAR ", " RD_SYSC ", " WR_SYSC ", " IO_RD ", " IO_WR ", " IO_CANCEL ",
" IORR ", " IOWR ", " IO ",
#endif
};
static int Process_getuid = -1; static int Process_getuid = -1;
Process* Process_new(struct ProcessList_ *pl) {
Process* this = malloc(sizeof(Process));
Object_setClass(this, PROCESS_CLASS);
((Object*)this)->display = Process_display;
((Object*)this)->delete = Process_delete;
this->pid = 0;
this->pl = pl;
this->tag = false;
this->updated = false;
this->utime = 0;
this->stime = 0;
this->comm = NULL;
this->indent = 0;
if (Process_getuid == -1) Process_getuid = getuid();
return this;
}
Process* Process_clone(Process* this) {
Process* clone = malloc(sizeof(Process));
memcpy(clone, this, sizeof(Process));
this->comm = NULL;
this->pid = 0;
return clone;
}
void Process_delete(Object* cast) {
Process* this = (Process*) cast;
assert (this != NULL);
if (this->comm) free(this->comm);
free(this);
}
void Process_display(Object* cast, RichString* out) {
Process* this = (Process*) cast;
ProcessField* fields = this->pl->fields;
RichString_init(out);
for (int i = 0; fields[i]; i++)
Process_writeField(this, out, fields[i]);
if (this->pl->shadowOtherUsers && this->st_uid != Process_getuid)
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
if (this->tag == true)
RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
assert(out->len > 0);
}
void Process_toggleTag(Process* this) {
this->tag = this->tag == true ? false : true;
}
void Process_setPriority(Process* this, int priority) {
int old_prio = getpriority(PRIO_PROCESS, this->pid);
int err = setpriority(PRIO_PROCESS, this->pid, priority);
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
this->nice = 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);
}
#define ONE_K 1024 #define ONE_K 1024
#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)
@ -261,30 +238,43 @@ static void Process_printTime(RichString* str, unsigned long t) {
RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer); RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer);
} }
static inline void Process_writeCommand(Process* this, int attr, RichString* str) { static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) {
int start = str->len;
RichString_append(str, attr, this->comm);
if (this->pl->highlightBaseName) { if (this->pl->highlightBaseName) {
char* firstSpace = strchr(this->comm, ' '); int finish = str->len - 1;
if (firstSpace) { int space = RichString_findChar(str, ' ', start);
char* slash = firstSpace; if (space != -1)
while (slash > this->comm && *slash != '/') finish = space - 1;
slash--; for (;;) {
if (slash > this->comm) { int slash = RichString_findChar(str, '/', start);
slash++; if (slash == -1 || slash > finish)
RichString_appendn(str, attr, this->comm, slash - this->comm); break;
} start = slash + 1;
RichString_appendn(str, CRT_colors[PROCESS_BASENAME], slash, firstSpace - slash);
RichString_append(str, attr, firstSpace);
} else {
RichString_append(str, CRT_colors[PROCESS_BASENAME], this->comm);
} }
} else { RichString_setAttrn(str, baseattr, start, finish);
RichString_append(str, attr, this->comm);
} }
} }
void Process_writeField(Process* this, RichString* str, ProcessField field) { static inline void Process_outputRate(Process* this, RichString* str, int attr, char* buffer, int n, double rate) {
rate = rate / 1024;
if (rate < 0.01)
snprintf(buffer, n, " 0 ");
else if (rate <= 10)
snprintf(buffer, n, "%5.2f ", rate);
else if (rate <= 100)
snprintf(buffer, n, "%5.1f ", rate);
else {
Process_printLargeNumber(this, str, rate);
return;
}
RichString_append(str, attr, buffer);
}
static void Process_writeField(Process* this, RichString* str, ProcessField field) {
char buffer[PROCESS_COMM_LEN]; char buffer[PROCESS_COMM_LEN];
int attr = CRT_colors[DEFAULT_COLOR]; int attr = CRT_colors[DEFAULT_COLOR];
int baseattr = CRT_colors[PROCESS_BASENAME];
int n = PROCESS_COMM_LEN; int n = PROCESS_COMM_LEN;
switch (field) { switch (field) {
@ -298,8 +288,12 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
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 NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
case COMM: { case COMM: {
if (this->pl->highlightThreads && (this->pid != this->tgid || this->m_size == 0)) {
attr = CRT_colors[PROCESS_THREAD];
baseattr = CRT_colors[PROCESS_THREAD_BASENAME];
}
if (!this->pl->treeView || this->indent == 0) { if (!this->pl->treeView || this->indent == 0) {
Process_writeCommand(this, attr, str); Process_writeCommand(this, attr, baseattr, str);
return; return;
} else { } else {
char* buf = buffer; char* buf = buffer;
@ -320,7 +314,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
else else
snprintf(buf, n, " ,- "); snprintf(buf, n, " ,- ");
RichString_append(str, CRT_colors[PROCESS_TREE], buffer); RichString_append(str, CRT_colors[PROCESS_TREE], buffer);
Process_writeCommand(this, attr, str); Process_writeCommand(this, attr, baseattr, str);
return; return;
} }
} }
@ -373,8 +367,10 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
case CSTIME: Process_printTime(str, this->cstime); return; case CSTIME: Process_printTime(str, this->cstime); return;
case TIME: Process_printTime(str, this->utime + this->stime); return; case TIME: Process_printTime(str, this->utime + this->stime); return;
case PERCENT_CPU: { case PERCENT_CPU: {
if (this->percent_cpu > 99.9) { if (this->percent_cpu > 999.9) {
snprintf(buffer, n, "100. "); snprintf(buffer, n, "%4d ", (unsigned int)this->percent_cpu);
} else if (this->percent_cpu > 99.9) {
snprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu);
} else { } else {
snprintf(buffer, n, "%4.1f ", this->percent_cpu); snprintf(buffer, n, "%4.1f ", this->percent_cpu);
} }
@ -392,11 +388,108 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
case VEID: snprintf(buffer, n, "%5u ", this->veid); break; case VEID: snprintf(buffer, n, "%5u ", this->veid); break;
case VPID: snprintf(buffer, n, "%5u ", this->vpid); break; case VPID: snprintf(buffer, n, "%5u ", this->vpid); break;
#endif #endif
#ifdef HAVE_TASKSTATS
case RCHAR: snprintf(buffer, n, "%10llu ", this->io_rchar); break;
case WCHAR: snprintf(buffer, n, "%10llu ", this->io_wchar); break;
case SYSCR: snprintf(buffer, n, "%10llu ", this->io_syscr); break;
case SYSCW: snprintf(buffer, n, "%10llu ", this->io_syscw); break;
case RBYTES: snprintf(buffer, n, "%10llu ", this->io_read_bytes); break;
case WBYTES: snprintf(buffer, n, "%10llu ", this->io_write_bytes); break;
case CNCLWB: snprintf(buffer, n, "%10llu ", this->io_cancelled_write_bytes); break;
case IO_READ_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_read_bps); return;
case IO_WRITE_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_write_bps); return;
case IO_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_read_bps + this->io_rate_write_bps); return;
#endif
default: default:
snprintf(buffer, n, "- "); snprintf(buffer, n, "- ");
} }
RichString_append(str, attr, buffer); RichString_append(str, attr, buffer);
return; }
static void Process_display(Object* cast, RichString* out) {
Process* this = (Process*) cast;
ProcessField* fields = this->pl->fields;
RichString_init(out);
for (int i = 0; fields[i]; i++)
Process_writeField(this, out, fields[i]);
if (this->pl->shadowOtherUsers && this->st_uid != Process_getuid)
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
if (this->tag == true)
RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
assert(out->len > 0);
}
void Process_delete(Object* cast) {
Process* this = (Process*) cast;
assert (this != NULL);
if (this->comm) free(this->comm);
free(this);
}
Process* Process_new(struct ProcessList_ *pl) {
Process* this = calloc(sizeof(Process), 1);
Object_setClass(this, PROCESS_CLASS);
((Object*)this)->display = Process_display;
((Object*)this)->delete = Process_delete;
this->pid = 0;
this->pl = pl;
this->tag = false;
this->updated = false;
this->utime = 0;
this->stime = 0;
this->comm = NULL;
this->indent = 0;
if (Process_getuid == -1) Process_getuid = getuid();
return this;
}
Process* Process_clone(Process* this) {
Process* clone = malloc(sizeof(Process));
#if HAVE_TASKSTATS
this->io_rchar = 0;
this->io_wchar = 0;
this->io_syscr = 0;
this->io_syscw = 0;
this->io_read_bytes = 0;
this->io_rate_read_bps = 0;
this->io_rate_read_time = 0;
this->io_write_bytes = 0;
this->io_rate_write_bps = 0;
this->io_rate_write_time = 0;
this->io_cancelled_write_bytes = 0;
#endif
memcpy(clone, this, sizeof(Process));
this->comm = NULL;
this->pid = 0;
return clone;
}
void Process_toggleTag(Process* this) {
this->tag = this->tag == true ? false : true;
}
bool Process_setPriority(Process* this, int priority) {
int old_prio = getpriority(PRIO_PROCESS, this->pid);
int err = setpriority(PRIO_PROCESS, this->pid, priority);
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
this->nice = priority;
}
return (err == 0);
}
unsigned long Process_getAffinity(Process* this) {
unsigned long mask = 0;
plpa_sched_getaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask);
return mask;
}
bool Process_setAffinity(Process* this, unsigned long mask) {
return (plpa_sched_setaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask) == 0);
}
void Process_sendSignal(Process* this, int signal) {
kill(this->pid, signal);
} }
int Process_pidCompare(const void* v1, const void* v2) { int Process_pidCompare(const void* v1, const void* v2) {
@ -415,6 +508,7 @@ int Process_compare(const void* v1, const void* v2) {
p2 = (Process*)v1; p2 = (Process*)v1;
p1 = (Process*)v2; p1 = (Process*)v2;
} }
long long diff;
switch (pl->sortKey) { switch (pl->sortKey) {
case PID: case PID:
return (p1->pid - p2->pid); return (p1->pid - p2->pid);
@ -462,45 +556,22 @@ int Process_compare(const void* v1, const void* v2) {
case VPID: case VPID:
return (p1->vpid - p2->vpid); return (p1->vpid - p2->vpid);
#endif #endif
#ifdef HAVE_TASKSTATS
case RCHAR: diff = p2->io_rchar - p1->io_rchar; goto test_diff;
case WCHAR: diff = p2->io_wchar - p1->io_wchar; goto test_diff;
case SYSCR: diff = p2->io_syscr - p1->io_syscr; goto test_diff;
case SYSCW: diff = p2->io_syscw - p1->io_syscw; goto test_diff;
case RBYTES: diff = p2->io_read_bytes - p1->io_read_bytes; goto test_diff;
case WBYTES: diff = p2->io_write_bytes - p1->io_write_bytes; goto test_diff;
case CNCLWB: diff = p2->io_cancelled_write_bytes - p1->io_cancelled_write_bytes; goto test_diff;
case IO_READ_RATE: diff = p2->io_rate_read_bps - p1->io_rate_read_bps; goto test_diff;
case IO_WRITE_RATE: diff = p2->io_rate_write_bps - p1->io_rate_write_bps; goto test_diff;
case IO_RATE: diff = (p2->io_rate_read_bps + p2->io_rate_write_bps) - (p1->io_rate_read_bps + p1->io_rate_write_bps); goto test_diff;
#endif
default: default:
return (p1->pid - p2->pid); return (p1->pid - p2->pid);
} }
test_diff:
} return (diff > 0) ? 1 : (diff < 0 ? -1 : 0);
char* Process_printField(ProcessField field) {
switch (field) {
case PID: return " PID ";
case PPID: return " PPID ";
case PGRP: return " PGRP ";
case SESSION: return " SESN ";
case TTY_NR: return " TTY ";
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 ";
case ST_UID: return " UID ";
case USER: return "USER ";
case UTIME: return " UTIME+ ";
case STIME: return " STIME+ ";
case TIME: return " TIME+ ";
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 "- ";
}
} }

View File

@ -14,6 +14,7 @@ in the source distribution for its full text.
#include "Object.h" #include "Object.h"
#include "CRT.h" #include "CRT.h"
#include "String.h" #include "String.h"
#include "RichString.h"
#include "debug.h" #include "debug.h"
@ -30,6 +31,8 @@ in the source distribution for its full text.
#include <pwd.h> #include <pwd.h>
#include <sched.h> #include <sched.h>
#include <plpa.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 #ifndef PAGE_SIZE
@ -48,6 +51,9 @@ typedef enum ProcessField_ {
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
VEID, VPID, VEID, VPID,
#endif #endif
#ifdef HAVE_TASKSTATS
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
#endif
LAST_PROCESSFIELD LAST_PROCESSFIELD
} ProcessField; } ProcessField;
@ -120,6 +126,19 @@ typedef struct Process_ {
unsigned int veid; unsigned int veid;
unsigned int vpid; unsigned int vpid;
#endif #endif
#ifdef HAVE_TASKSTATS
unsigned long long io_rchar;
unsigned long long io_wchar;
unsigned long long io_syscr;
unsigned long long io_syscw;
unsigned long long io_read_bytes;
unsigned long long io_write_bytes;
unsigned long long io_cancelled_write_bytes;
double io_rate_read_bps;
unsigned long long io_rate_read_time;
double io_rate_write_bps;
unsigned long long io_rate_write_time;
#endif
} Process; } Process;
@ -131,34 +150,30 @@ extern char* PROCESS_CLASS;
extern char *Process_fieldNames[]; extern char *Process_fieldNames[];
Process* Process_new(struct ProcessList_ *pl); extern char *Process_fieldTitles[];
Process* Process_clone(Process* this);
void Process_delete(Object* cast);
void Process_display(Object* cast, RichString* out);
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 #define ONE_K 1024
#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)
void Process_writeField(Process* this, RichString* str, ProcessField field); void Process_delete(Object* cast);
Process* Process_new(struct ProcessList_ *pl);
Process* Process_clone(Process* this);
void Process_toggleTag(Process* this);
bool Process_setPriority(Process* this, int priority);
unsigned long Process_getAffinity(Process* this);
bool Process_setAffinity(Process* this, unsigned long mask);
void Process_sendSignal(Process* this, int signal);
int Process_pidCompare(const void* v1, const void* v2); int Process_pidCompare(const void* v1, const void* v2);
int Process_compare(const void* v1, const void* v2); int Process_compare(const void* v1, const void* v2);
char* Process_printField(ProcessField field);
#endif #endif

View File

@ -119,6 +119,7 @@ typedef struct ProcessList_ {
bool treeView; bool treeView;
bool highlightBaseName; bool highlightBaseName;
bool highlightMegabytes; bool highlightMegabytes;
bool highlightThreads;
bool detailedCPUTime; bool detailedCPUTime;
#ifdef DEBUG_PROC #ifdef DEBUG_PROC
FILE* traceFile; FILE* traceFile;
@ -282,10 +283,10 @@ void ProcessList_invertSortOrder(ProcessList* this) {
RichString ProcessList_printHeader(ProcessList* this) { RichString ProcessList_printHeader(ProcessList* this) {
RichString out; RichString out;
RichString_init(&out); RichString_initVal(out);
ProcessField* fields = this->fields; ProcessField* fields = this->fields;
for (int i = 0; fields[i]; i++) { for (int i = 0; fields[i]; i++) {
char* field = Process_printField(fields[i]); char* field = Process_fieldTitles[fields[i]];
if (this->sortKey == fields[i]) if (this->sortKey == fields[i])
RichString_append(&out, CRT_colors[PANEL_HIGHLIGHT_FOCUS], field); RichString_append(&out, CRT_colors[PANEL_HIGHLIGHT_FOCUS], field);
else else
@ -294,12 +295,7 @@ RichString ProcessList_printHeader(ProcessList* this) {
return out; return out;
} }
static void ProcessList_add(ProcessList* this, Process* p) {
void ProcessList_prune(ProcessList* this) {
Vector_prune(this->processes);
}
void ProcessList_add(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1); assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
assert(Hashtable_get(this->processTable, p->pid) == NULL); assert(Hashtable_get(this->processTable, p->pid) == NULL);
Vector_add(this->processes, p); Vector_add(this->processes, p);
@ -309,7 +305,7 @@ void ProcessList_add(ProcessList* this, Process* p) {
assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
} }
void ProcessList_remove(ProcessList* this, Process* p) { static void ProcessList_remove(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
assert(Hashtable_get(this->processTable, p->pid) != NULL); assert(Hashtable_get(this->processTable, p->pid) != NULL);
Process* pp = Hashtable_remove(this->processTable, p->pid); Process* pp = Hashtable_remove(this->processTable, p->pid);
@ -461,34 +457,10 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
return 1; return 1;
} }
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) { static 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;
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) {
while (!feof(status)) {
char* ok = fgets(buffer, 255, status);
if (!ok)
break;
if (String_startsWith(buffer, "Tgid:")) {
int tgid;
int ok = ProcessList_read(this, buffer, "Tgid:\t%d", &tgid);
if (ok >= 1) {
proc->tgid = tgid;
success = true;
}
break;
}
}
fclose(status);
}
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);
@ -498,13 +470,59 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
return true; return true;
} }
void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, float period) { #ifdef HAVE_TASKSTATS
static void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, char* name) {
char iofilename[MAX_NAME+1];
iofilename[MAX_NAME] = '\0';
snprintf(iofilename, MAX_NAME, "%s/%s/io", dirname, name);
FILE* io = ProcessList_fopen(this, iofilename, "r");
if (io) {
char buffer[256];
buffer[255] = '\0';
struct timeval tv;
gettimeofday(&tv,NULL);
unsigned long long now = tv.tv_sec*1000+tv.tv_usec/1000;
unsigned long long last_read = proc->io_read_bytes;
unsigned long long last_write = proc->io_write_bytes;
while (!feof(io)) {
char* ok = fgets(buffer, 255, io);
if (!ok)
break;
if (ProcessList_read(this, buffer, "rchar: %llu", &proc->io_rchar)) continue;
if (ProcessList_read(this, buffer, "wchar: %llu", &proc->io_wchar)) continue;
if (ProcessList_read(this, buffer, "syscr: %llu", &proc->io_syscr)) continue;
if (ProcessList_read(this, buffer, "syscw: %llu", &proc->io_syscw)) continue;
if (ProcessList_read(this, buffer, "read_bytes: %llu", &proc->io_read_bytes)) {
proc->io_rate_read_bps =
((double)(proc->io_read_bytes - last_read))/(((double)(now - proc->io_rate_read_time))/1000);
proc->io_rate_read_time = now;
continue;
}
if (ProcessList_read(this, buffer, "write_bytes: %llu", &proc->io_write_bytes)) {
proc->io_rate_write_bps =
((double)(proc->io_write_bytes - last_write))/(((double)(now - proc->io_rate_write_time))/1000);
proc->io_rate_write_time = now;
continue;
}
ProcessList_read(this, buffer, "cancelled_write_bytes: %llu", &proc->io_cancelled_write_bytes);
}
fclose(io);
}
}
#endif
static bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* parent, float period) {
DIR* dir; DIR* dir;
struct dirent* entry; struct dirent* entry;
Process* prototype = this->prototype; Process* prototype = this->prototype;
dir = opendir(dirname); dir = opendir(dirname);
if (!dir) return; if (!dir) return false;
int processors = this->processorCount;
bool showUserlandThreads = !this->hideUserlandThreads;
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
char* name = entry->d_name; char* name = entry->d_name;
int pid; int pid;
@ -521,34 +539,49 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
isThread = true; isThread = true;
} }
if (pid > 0 && pid != parent) { if (pid > 0) {
if (!this->hideUserlandThreads) {
char subdirname[MAX_NAME+1];
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
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 = NULL;
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); assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1);
process = existingProcess; process = existingProcess;
assert(process->pid == pid); assert(process->pid == pid);
} else { } else {
process = prototype; if (parent && parent->pid == pid) {
assert(process->comm == NULL); process = parent;
process->pid = pid; } else {
process = prototype;
assert(process->comm == NULL);
process->pid = pid;
}
}
if (parent) {
process->tgid = parent->pid;
}
#ifdef HAVE_TASKSTATS
ProcessList_readIoFile(this, process, dirname, name);
#endif
if (showUserlandThreads && (!parent || pid != parent->pid)) {
char subdirname[MAX_NAME+1];
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
if (ProcessList_processEntries(this, subdirname, process, period))
continue;
}
process->updated = true;
if (!existingProcess)
if (! ProcessList_readStatusFile(this, process, dirname, name)) if (! ProcessList_readStatusFile(this, process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
}
process->updated = true;
snprintf(statusfilename, MAX_NAME, "%s/%s/statm", dirname, name); snprintf(statusfilename, MAX_NAME, "%s/%s/statm", dirname, name);
status = ProcessList_fopen(this, statusfilename, "r"); status = ProcessList_fopen(this, statusfilename, "r");
@ -573,13 +606,14 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
snprintf(statusfilename, MAX_NAME, "%s/%s/stat", dirname, name); snprintf(statusfilename, MAX_NAME, "%s/%s/stat", dirname, name);
status = ProcessList_fopen(this, statusfilename, "r"); status = ProcessList_fopen(this, statusfilename, "r");
if (status == NULL) if (status == NULL)
goto errorReadingProcess; goto errorReadingProcess;
int success = ProcessList_readStatFile(this, process, status, command); int success = ProcessList_readStatFile(this, process, status, command);
fclose(status); fclose(status);
if(!success) if(!success) {
goto errorReadingProcess; goto errorReadingProcess;
}
if(!existingProcess) { if(!existingProcess) {
process->user = UsersTable_getRef(this->usersTable, process->st_uid); process->user = UsersTable_getRef(this->usersTable, process->st_uid);
@ -624,8 +658,9 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
fclose(status); fclose(status);
} }
process->percent_cpu = (process->utime + process->stime - lasttimes) / int percent_cpu = (process->utime + process->stime - lasttimes) /
period * 100.0; period * 100.0;
process->percent_cpu = MAX(MIN(percent_cpu, processors*100.0), 0.0);
process->percent_mem = (process->m_resident * PAGE_SIZE) / process->percent_mem = (process->m_resident * PAGE_SIZE) /
(float)(this->totalMem) * (float)(this->totalMem) *
@ -637,7 +672,8 @@ 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;
@ -655,6 +691,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
} }
} }
closedir(dir); closedir(dir);
return true;
} }
void ProcessList_scan(ProcessList* this) { void ProcessList_scan(ProcessList* this) {
@ -665,6 +702,7 @@ void ProcessList_scan(ProcessList* this) {
char buffer[128]; char buffer[128];
status = ProcessList_fopen(this, PROCMEMINFOFILE, "r"); status = ProcessList_fopen(this, PROCMEMINFOFILE, "r");
assert(status != NULL); assert(status != NULL);
int processors = this->processorCount;
while (!feof(status)) { while (!feof(status)) {
fgets(buffer, 128, status); fgets(buffer, 128, status);
@ -701,7 +739,7 @@ void ProcessList_scan(ProcessList* this) {
status = ProcessList_fopen(this, PROCSTATFILE, "r"); status = ProcessList_fopen(this, PROCSTATFILE, "r");
assert(status != NULL); assert(status != NULL);
for (int i = 0; i <= this->processorCount; i++) { for (int i = 0; i <= processors; i++) {
char buffer[256]; char buffer[256];
int cpuid; int cpuid;
unsigned long long int ioWait, irq, softIrq, steal; unsigned long long int ioWait, irq, softIrq, steal;
@ -755,7 +793,7 @@ void ProcessList_scan(ProcessList* this) {
this->stealTime[i] = steal; 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] / processors;
fclose(status); fclose(status);
// mark all process as "dirty" // mark all process as "dirty"
@ -766,8 +804,8 @@ void ProcessList_scan(ProcessList* this) {
this->totalTasks = 0; this->totalTasks = 0;
this->runningTasks = 0; this->runningTasks = 0;
ProcessList_processEntries(this, PROCDIR, 0, period); ProcessList_processEntries(this, PROCDIR, NULL, period);
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i); Process* p = (Process*) Vector_get(this->processes, i);
@ -778,3 +816,17 @@ void ProcessList_scan(ProcessList* this) {
} }
} }
ProcessField ProcessList_keyAt(ProcessList* this, int at) {
int x = 0;
ProcessField* fields = this->fields;
ProcessField field;
for (int i = 0; (field = fields[i]); i++) {
int len = strlen(Process_fieldTitles[field]);
if (at >= x && at <= x + len) {
return field;
}
x += len;
}
return COMM;
}

View File

@ -119,6 +119,7 @@ typedef struct ProcessList_ {
bool treeView; bool treeView;
bool highlightBaseName; bool highlightBaseName;
bool highlightMegabytes; bool highlightMegabytes;
bool highlightThreads;
bool detailedCPUTime; bool detailedCPUTime;
#ifdef DEBUG_PROC #ifdef DEBUG_PROC
FILE* traceFile; FILE* traceFile;
@ -149,23 +150,18 @@ void ProcessList_invertSortOrder(ProcessList* this);
RichString ProcessList_printHeader(ProcessList* this); RichString ProcessList_printHeader(ProcessList* this);
void ProcessList_prune(ProcessList* this);
void ProcessList_add(ProcessList* this, Process* p);
void ProcessList_remove(ProcessList* this, Process* p);
Process* ProcessList_get(ProcessList* this, int index); Process* ProcessList_get(ProcessList* this, int index);
int ProcessList_size(ProcessList* this); int ProcessList_size(ProcessList* this);
void ProcessList_sort(ProcessList* this); void ProcessList_sort(ProcessList* this);
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name); #ifdef HAVE_TASKSTATS
void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, float period); #endif
void ProcessList_scan(ProcessList* this); void ProcessList_scan(ProcessList* this);
ProcessField ProcessList_keyAt(ProcessList* this, int at);
#endif #endif

View File

@ -1,12 +1,20 @@
#include "RichString.h" #include "RichString.h"
#ifndef CONFIG_H
#define CONFIG_H
#include "config.h"
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <curses.h> #include <curses.h>
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#ifdef HAVE_LIBNCURSESW
#include <wchar.h>
#endif
#define RICHSTRING_MAXLEN 300 #define RICHSTRING_MAXLEN 300
@ -15,9 +23,23 @@
#define RichString_init(this) (this)->len = 0 #define RichString_init(this) (this)->len = 0
#define RichString_initVal(this) (this).len = 0 #define RichString_initVal(this) (this).len = 0
#ifdef HAVE_LIBNCURSESW
#define RichString_printVal(this, y, x) mvadd_wchstr(y, x, this.chstr)
#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, this.chstr + off, n)
#define RichString_getCharVal(this, i) (this.chstr[i].chars[0] & 255)
#else
#define RichString_printVal(this, y, x) mvaddchstr(y, x, this.chstr)
#define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, this.chstr + off, n)
#define RichString_getCharVal(this, i) (this.chstr[i])
#endif
typedef struct RichString_ { typedef struct RichString_ {
int len; int len;
#ifdef HAVE_LIBNCURSESW
cchar_t chstr[RICHSTRING_MAXLEN+1];
#else
chtype chstr[RICHSTRING_MAXLEN+1]; chtype chstr[RICHSTRING_MAXLEN+1];
#endif
} RichString; } RichString;
}*/ }*/
@ -26,14 +48,76 @@ 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) { #ifdef HAVE_LIBNCURSESW
inline void RichString_appendn(RichString* this, int attrs, char* data_c, int len) {
wchar_t data[RICHSTRING_MAXLEN];
len = mbstowcs(data, data_c, RICHSTRING_MAXLEN);
if (len<0)
return;
int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
for (int i = this->len, j = 0; i < last; i++, j++) {
memset(&this->chstr[i], 0, sizeof(this->chstr[i]));
this->chstr[i].chars[0] = data[j];
this->chstr[i].attr = attrs;
}
this->chstr[last].chars[0] = 0;
this->len = last;
}
inline void RichString_setAttrn(RichString *this, int attrs, int start, int finish) {
cchar_t* ch = this->chstr + start;
for (int i = start; i <= finish; i++) {
ch->attr = attrs;
ch++;
}
}
int RichString_findChar(RichString *this, char c, int start) {
wchar_t wc = btowc(c);
cchar_t* ch = this->chstr + start;
for (int i = start; i < this->len; i++) {
if (ch->chars[0] == wc)
return i;
ch++;
}
return -1;
}
#else
inline void RichString_appendn(RichString* this, int attrs, char* data_c, int len) {
int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len); int last = MIN(RICHSTRING_MAXLEN - 1, len + this->len);
for (int i = this->len, j = 0; i < last; i++, j++) for (int i = this->len, j = 0; i < last; i++, j++)
this->chstr[i] = data[j] | attrs; this->chstr[i] = data_c[j] | attrs;
this->chstr[last] = 0; this->chstr[last] = 0;
this->len = last; this->len = last;
} }
void RichString_setAttrn(RichString *this, int attrs, int start, int finish) {
chtype* ch = this->chstr + start;
for (int i = start; i <= finish; i++) {
*ch = (*ch & 0xff) | attrs;
ch++;
}
}
int RichString_findChar(RichString *this, char c, int start) {
chtype* ch = this->chstr + start;
for (int i = start; i < this->len; i++) {
if ((*ch & 0xff) == c)
return i;
ch++;
}
return -1;
}
#endif
void RichString_setAttr(RichString *this, int attrs) {
RichString_setAttrn(this, attrs, 0, this->len - 1);
}
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));
} }
@ -43,22 +127,6 @@ void RichString_write(RichString* this, int attrs, char* data) {
RichString_append(this, attrs, data); RichString_append(this, attrs, data);
} }
void RichString_setAttr(RichString *this, int attrs) {
chtype* ch = this->chstr;
for (int i = 0; i < this->len; i++) {
*ch = (*ch & 0xff) | attrs;
ch++;
}
}
void RichString_applyAttr(RichString *this, int attrs) {
chtype* ch = this->chstr;
for (int i = 0; i < this->len; i++) {
*ch |= attrs;
ch++;
}
}
RichString RichString_quickString(int attrs, char* data) { RichString RichString_quickString(int attrs, char* data) {
RichString str; RichString str;
RichString_initVal(str); RichString_initVal(str);

View File

@ -4,12 +4,20 @@
#define HEADER_RichString #define HEADER_RichString
#ifndef CONFIG_H
#define CONFIG_H
#include "config.h"
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <curses.h> #include <curses.h>
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#ifdef HAVE_LIBNCURSESW
#include <wchar.h>
#endif
#define RICHSTRING_MAXLEN 300 #define RICHSTRING_MAXLEN 300
@ -17,9 +25,23 @@
#define RichString_init(this) (this)->len = 0 #define RichString_init(this) (this)->len = 0
#define RichString_initVal(this) (this).len = 0 #define RichString_initVal(this) (this).len = 0
#ifdef HAVE_LIBNCURSESW
#define RichString_printVal(this, y, x) mvadd_wchstr(y, x, this.chstr)
#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, this.chstr + off, n)
#define RichString_getCharVal(this, i) (this.chstr[i].chars[0] & 255)
#else
#define RichString_printVal(this, y, x) mvaddchstr(y, x, this.chstr)
#define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, this.chstr + off, n)
#define RichString_getCharVal(this, i) (this.chstr[i])
#endif
typedef struct RichString_ { typedef struct RichString_ {
int len; int len;
#ifdef HAVE_LIBNCURSESW
cchar_t chstr[RICHSTRING_MAXLEN+1];
#else
chtype chstr[RICHSTRING_MAXLEN+1]; chtype chstr[RICHSTRING_MAXLEN+1];
#endif
} RichString; } RichString;
@ -27,16 +49,30 @@ 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); #ifdef HAVE_LIBNCURSESW
extern void RichString_appendn(RichString* this, int attrs, char* data_c, int len);
extern void RichString_setAttrn(RichString *this, int attrs, int start, int finish);
int RichString_findChar(RichString *this, char c, int start);
#else
extern void RichString_appendn(RichString* this, int attrs, char* data_c, int len);
void RichString_setAttrn(RichString *this, int attrs, int start, int finish);
int RichString_findChar(RichString *this, char c, int start);
#endif
void RichString_setAttr(RichString *this, int attrs);
extern void RichString_append(RichString* this, int attrs, char* data); 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);
void RichString_setAttr(RichString *this, int attrs);
void RichString_applyAttr(RichString *this, int attrs);
RichString RichString_quickString(int attrs, char* data); RichString RichString_quickString(int attrs, char* data);
#endif #endif

View File

@ -98,12 +98,6 @@ Panel* ScreenManager_remove(ScreenManager* this, int index) {
return panel; return panel;
} }
void ScreenManager_setFunctionBar(ScreenManager* this, FunctionBar* fuBar) {
if (this->owner && this->fuBar)
FunctionBar_delete((Object*)this->fuBar);
this->fuBar = fuBar;
}
void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
this->x1 = x1; this->x1 = x1;
this->y1 = y1; this->y1 = y1;
@ -150,7 +144,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
ch = getch(); ch = getch();
bool loop = false;
if (ch == KEY_MOUSE) { if (ch == KEY_MOUSE) {
MEVENT mevent; MEVENT mevent;
int ok = getmouse(&mevent); int ok = getmouse(&mevent);
@ -165,14 +158,12 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
focus = i; focus = i;
panelFocus = panel; panelFocus = panel;
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
loop = true;
break; break;
} }
} }
} }
} }
} }
if (loop) continue;
if (panelFocus->eventHandler) { if (panelFocus->eventHandler) {
HandlerResult result = panelFocus->eventHandler(panelFocus, ch); HandlerResult result = panelFocus->eventHandler(panelFocus, ch);

View File

@ -49,8 +49,6 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
Panel* ScreenManager_remove(ScreenManager* this, int index); Panel* ScreenManager_remove(ScreenManager* this, int index);
void ScreenManager_setFunctionBar(ScreenManager* this, FunctionBar* fuBar);
void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2);
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey);

View File

@ -27,39 +27,6 @@ typedef struct Settings_ {
}*/ }*/
Settings* Settings_new(ProcessList* pl, Header* header) {
Settings* this = malloc(sizeof(Settings));
this->pl = pl;
this->header = header;
char* home;
char* rcfile;
home = getenv("HOME_ETC");
if (!home) home = getenv("HOME");
if (!home) home = "";
rcfile = getenv("HOMERC");
if (!rcfile)
this->userSettings = String_cat(home, "/.htoprc");
else
this->userSettings = String_copy(rcfile);
this->colorScheme = 0;
this->changed = false;
this->delay = DEFAULT_DELAY;
bool ok = Settings_read(this, this->userSettings);
if (!ok) {
this->changed = true;
// TODO: how to get SYSCONFDIR correctly through Autoconf?
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
ok = Settings_read(this, systemSettings);
free(systemSettings);
if (!ok) {
Header_defaultMeters(this->header);
pl->hideKernelThreads = true;
pl->highlightMegabytes = true;
}
}
return this;
}
void Settings_delete(Settings* this) { void Settings_delete(Settings* this) {
free(this->userSettings); free(this->userSettings);
free(this); free(this);
@ -88,7 +55,7 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side)
String_freeArray(ids); String_freeArray(ids);
} }
bool Settings_read(Settings* this, char* fileName) { static bool Settings_read(Settings* this, char* fileName) {
// TODO: implement File object and make // TODO: implement File object and make
// file I/O object-oriented. // file I/O object-oriented.
FILE* fd; FILE* fd;
@ -96,7 +63,7 @@ bool Settings_read(Settings* this, char* fileName) {
if (fd == NULL) { if (fd == NULL) {
return false; return false;
} }
const int maxLine = 512; const int maxLine = 65535;
char buffer[maxLine]; char buffer[maxLine];
bool readMeters = false; bool readMeters = false;
while (!feof(fd)) { while (!feof(fd)) {
@ -137,6 +104,8 @@ bool Settings_read(Settings* this, char* fileName) {
this->pl->highlightBaseName = atoi(option[1]); this->pl->highlightBaseName = atoi(option[1]);
} else if (String_eq(option[0], "highlight_megabytes")) { } else if (String_eq(option[0], "highlight_megabytes")) {
this->pl->highlightMegabytes = atoi(option[1]); this->pl->highlightMegabytes = atoi(option[1]);
} else if (String_eq(option[0], "highlight_threads")) {
this->pl->highlightThreads = 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")) { } else if (String_eq(option[0], "expand_system_time")) {
@ -198,6 +167,7 @@ bool Settings_write(Settings* this) {
fprintf(fd, "shadow_other_users=%d\n", (int) this->pl->shadowOtherUsers); fprintf(fd, "shadow_other_users=%d\n", (int) this->pl->shadowOtherUsers);
fprintf(fd, "highlight_base_name=%d\n", (int) this->pl->highlightBaseName); fprintf(fd, "highlight_base_name=%d\n", (int) this->pl->highlightBaseName);
fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes); fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes);
fprintf(fd, "highlight_threads=%d\n", (int) this->pl->highlightThreads);
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, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime);
@ -228,3 +198,37 @@ bool Settings_write(Settings* this) {
fclose(fd); fclose(fd);
return true; return true;
} }
Settings* Settings_new(ProcessList* pl, Header* header) {
Settings* this = malloc(sizeof(Settings));
this->pl = pl;
this->header = header;
char* home;
char* rcfile;
home = getenv("HOME_ETC");
if (!home) home = getenv("HOME");
if (!home) home = "";
rcfile = getenv("HOMERC");
if (!rcfile)
this->userSettings = String_cat(home, "/.htoprc");
else
this->userSettings = String_copy(rcfile);
this->colorScheme = 0;
this->changed = false;
this->delay = DEFAULT_DELAY;
bool ok = Settings_read(this, this->userSettings);
if (!ok) {
this->changed = true;
// TODO: how to get SYSCONFDIR correctly through Autoconf?
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
ok = Settings_read(this, systemSettings);
free(systemSettings);
if (!ok) {
Header_defaultMeters(this->header);
pl->hideKernelThreads = true;
pl->highlightMegabytes = true;
pl->highlightThreads = false;
}
}
return this;
}

View File

@ -28,12 +28,10 @@ typedef struct Settings_ {
} Settings; } Settings;
Settings* Settings_new(ProcessList* pl, Header* header);
void Settings_delete(Settings* this); void Settings_delete(Settings* this);
bool Settings_read(Settings* this, char* fileName);
bool Settings_write(Settings* this); bool Settings_write(Settings* this);
Settings* Settings_new(ProcessList* pl, Header* header);
#endif #endif

View File

@ -31,7 +31,23 @@ char* SIGNAL_CLASS = "Signal";
#define SIGNAL_CLASS NULL #define SIGNAL_CLASS NULL
#endif #endif
Signal* Signal_new(char* name, int number) { static void Signal_delete(Object* cast) {
Signal* this = (Signal*)cast;
assert (this != NULL);
// names are string constants, so we're not deleting them.
free(this);
}
static void Signal_display(Object* cast, RichString* out) {
Signal* this = (Signal*)cast;
assert (this != NULL);
char buffer[31];
snprintf(buffer, 30, "%2d %s", this->number, this->name);
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
}
static Signal* Signal_new(char* name, int number) {
Signal* this = malloc(sizeof(Signal)); Signal* this = malloc(sizeof(Signal));
Object_setClass(this, SIGNAL_CLASS); Object_setClass(this, SIGNAL_CLASS);
((Object*)this)->display = Signal_display; ((Object*)this)->display = Signal_display;
@ -41,22 +57,6 @@ Signal* Signal_new(char* name, int number) {
return this; return this;
} }
void Signal_delete(Object* cast) {
Signal* this = (Signal*)cast;
assert (this != NULL);
// names are string constants, so we're not deleting them.
free(this);
}
void Signal_display(Object* cast, RichString* out) {
Signal* this = (Signal*)cast;
assert (this != NULL);
char buffer[31];
snprintf(buffer, 30, "%2d %s", this->number, this->name);
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
}
int Signal_getSignalCount() { int Signal_getSignalCount() {
return SIGNAL_COUNT; return SIGNAL_COUNT;
} }

View File

@ -32,12 +32,6 @@ extern char* SIGNAL_CLASS;
#define SIGNAL_CLASS NULL #define SIGNAL_CLASS NULL
#endif #endif
Signal* Signal_new(char* name, int number);
void Signal_delete(Object* cast);
void Signal_display(Object* cast, RichString* out);
int Signal_getSignalCount(); int Signal_getSignalCount();
Signal** Signal_getSignalTable(); Signal** Signal_getSignalTable();

View File

@ -20,38 +20,7 @@ typedef struct SignalsPanel_ {
}*/ }*/
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) { static HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
Panel* super = (Panel*) this;
Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
((Object*)this)->delete = SignalsPanel_delete;
this->signals = Signal_getSignalTable();
super->eventHandler = SignalsPanel_eventHandler;
int sigCount = Signal_getSignalCount();
for(int i = 0; i < sigCount; i++)
Panel_set(super, i, (Object*) this->signals[i]);
SignalsPanel_reset(this);
return this;
}
void SignalsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
SignalsPanel* this = (SignalsPanel*) object;
Panel_done(super);
free(this->signals);
free(this);
}
void SignalsPanel_reset(SignalsPanel* this) {
Panel* super = (Panel*) this;
Panel_setHeader(super, "Send signal:");
Panel_setSelected(super, 16); // 16th item is SIGTERM
this->state = 0;
}
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);
@ -75,3 +44,34 @@ HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
} }
return IGNORED; return IGNORED;
} }
static void SignalsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
SignalsPanel* this = (SignalsPanel*) object;
Panel_done(super);
free(this->signals);
free(this);
}
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
Panel* super = (Panel*) this;
Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
((Object*)this)->delete = SignalsPanel_delete;
this->signals = Signal_getSignalTable();
super->eventHandler = SignalsPanel_eventHandler;
int sigCount = Signal_getSignalCount();
for(int i = 0; i < sigCount; i++)
Panel_set(super, i, (Object*) this->signals[i]);
SignalsPanel_reset(this);
return this;
}
void SignalsPanel_reset(SignalsPanel* this) {
Panel* super = (Panel*) this;
Panel_setHeader(super, "Send signal:");
Panel_setSelected(super, 16); // 16th item is SIGTERM
this->state = 0;
}

View File

@ -23,10 +23,6 @@ typedef struct SignalsPanel_ {
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h); SignalsPanel* SignalsPanel_new(int x, int y, int w, int h);
void SignalsPanel_delete(Object* object);
void SignalsPanel_reset(SignalsPanel* this); void SignalsPanel_reset(SignalsPanel* this);
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch);
#endif #endif

View File

@ -18,10 +18,6 @@ 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))
}*/ }*/
inline void String_delete(char* s) {
free(s);
}
inline char* String_copy(char* orig) { inline char* String_copy(char* orig) {
return strdup(orig); return strdup(orig);
} }
@ -49,53 +45,6 @@ char* String_trim(char* in) {
return out; return out;
} }
char* String_copyUpTo(char* orig, char upTo) {
int len;
int origLen = strlen(orig);
char* at = strchr(orig, upTo);
if (at != NULL)
len = at - orig;
else
len = origLen;
char* copy = (char*) malloc(len+1);
strncpy(copy, orig, len);
copy[len] = '\0';
return copy;
}
char* String_sub(char* orig, int from, int to) {
char* copy;
int len;
len = strlen(orig);
if (to > len)
to = len;
if (from > len)
to = len;
len = to-from+1;
copy = (char*) malloc(len+1);
strncpy(copy, orig+from, len);
copy[len] = '\0';
return copy;
}
void String_println(char* s) {
printf("%s\n", s);
}
void String_print(char* s) {
printf("%s", s);
}
void String_printInt(int i) {
printf("%i", i);
}
void String_printPointer(void* p) {
printf("%p", p);
}
inline int String_eq(const char* s1, const char* s2) { inline int String_eq(const char* s1, const char* s2) {
if (s1 == NULL || s2 == NULL) { if (s1 == NULL || s2 == NULL) {
if (s1 == NULL && s2 == NULL) if (s1 == NULL && s2 == NULL)
@ -144,10 +93,6 @@ void String_freeArray(char** s) {
free(s); free(s);
} }
int String_startsWith_i(char* s, char* match) {
return (strncasecmp(s, match, strlen(match)) == 0);
}
int String_contains_i(char* s, char* match) { int String_contains_i(char* s, char* match) {
int lens = strlen(s); int lens = strlen(s);
int lenmatch = strlen(match); int lenmatch = strlen(match);

View File

@ -19,34 +19,18 @@ 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);
extern char* String_copy(char* orig); extern char* String_copy(char* orig);
char* String_cat(char* s1, char* s2); char* String_cat(char* s1, char* s2);
char* String_trim(char* in); char* String_trim(char* in);
char* String_copyUpTo(char* orig, char upTo);
char* String_sub(char* orig, int from, int to);
void String_println(char* s);
void String_print(char* s);
void String_printInt(int i);
void String_printPointer(void* p);
extern 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); char** String_split(char* s, char sep);
void String_freeArray(char** s); void String_freeArray(char** s);
int String_startsWith_i(char* s, char* match);
int String_contains_i(char* s, char* match); int String_contains_i(char* s, char* match);
#endif #endif

View File

@ -23,26 +23,14 @@ int SwapMeter_attributes[] = {
SWAP SWAP
}; };
MeterType SwapMeter = { static void SwapMeter_setValues(Meter* this, char* buffer, int len) {
.setValues = SwapMeter_setValues,
.display = SwapMeter_display,
.mode = BAR_METERMODE,
.items = 1,
.total = 100.0,
.attributes = SwapMeter_attributes,
.name = "Swap",
.uiName = "Swap",
.caption = "Swp"
};
void SwapMeter_setValues(Meter* this, char* buffer, int len) {
long int usedSwap = this->pl->usedSwap; long int usedSwap = this->pl->usedSwap;
this->total = this->pl->totalSwap; this->total = this->pl->totalSwap;
this->values[0] = usedSwap; this->values[0] = usedSwap;
snprintf(buffer, len, "%ld/%ldMB", (long int) usedSwap / 1024, (long int) this->total / 1024); snprintf(buffer, len, "%ld/%ldMB", (long int) usedSwap / 1024, (long int) this->total / 1024);
} }
void SwapMeter_display(Object* cast, RichString* out) { static void SwapMeter_display(Object* cast, RichString* out) {
char buffer[50]; char buffer[50];
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
long int swap = (long int) this->values[0]; long int swap = (long int) this->values[0];
@ -54,3 +42,15 @@ void SwapMeter_display(Object* cast, RichString* out) {
RichString_append(out, CRT_colors[METER_TEXT], "used:"); RichString_append(out, CRT_colors[METER_TEXT], "used:");
RichString_append(out, CRT_colors[METER_VALUE], buffer); RichString_append(out, CRT_colors[METER_VALUE], buffer);
} }
MeterType SwapMeter = {
.setValues = SwapMeter_setValues,
.display = SwapMeter_display,
.mode = BAR_METERMODE,
.items = 1,
.total = 100.0,
.attributes = SwapMeter_attributes,
.name = "Swap",
.uiName = "Swap",
.caption = "Swp"
};

View File

@ -26,8 +26,4 @@ extern int SwapMeter_attributes[];
extern MeterType SwapMeter; extern MeterType SwapMeter;
void SwapMeter_setValues(Meter* this, char* buffer, int len);
void SwapMeter_display(Object* cast, RichString* out);
#endif #endif

View File

@ -18,6 +18,24 @@ int TasksMeter_attributes[] = {
TASKS_RUNNING TASKS_RUNNING
}; };
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
this->total = this->pl->totalTasks;
this->values[0] = this->pl->runningTasks;
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
}
static void TasksMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
RichString_init(out);
char buffer[20];
sprintf(buffer, "%d", (int)this->total);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " total, ");
sprintf(buffer, "%d", (int)this->values[0]);
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " running");
}
MeterType TasksMeter = { MeterType TasksMeter = {
.setValues = TasksMeter_setValues, .setValues = TasksMeter_setValues,
.display = TasksMeter_display, .display = TasksMeter_display,
@ -29,21 +47,3 @@ MeterType TasksMeter = {
.uiName = "Task counter", .uiName = "Task counter",
.caption = "Tasks: " .caption = "Tasks: "
}; };
void TasksMeter_setValues(Meter* this, char* buffer, int len) {
this->total = this->pl->totalTasks;
this->values[0] = this->pl->runningTasks;
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
}
void TasksMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast;
RichString_init(out);
char buffer[20];
sprintf(buffer, "%d", (int)this->total);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " total, ");
sprintf(buffer, "%d", (int)this->values[0]);
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " running");
}

View File

@ -21,8 +21,4 @@ extern int TasksMeter_attributes[];
extern MeterType TasksMeter; extern MeterType TasksMeter;
void TasksMeter_setValues(Meter* this, char* buffer, int len);
void TasksMeter_display(Object* cast, RichString* out);
#endif #endif

View File

@ -53,7 +53,7 @@ void TraceScreen_delete(TraceScreen* this) {
free(this); free(this);
} }
void TraceScreen_draw(TraceScreen* this) { static void TraceScreen_draw(TraceScreen* this) {
attrset(CRT_colors[PANEL_HEADER_FOCUS]); attrset(CRT_colors[PANEL_HEADER_FOCUS]);
mvhline(0, 0, ' ', COLS); mvhline(0, 0, ' ', COLS);
mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm); mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm);

View File

@ -37,8 +37,6 @@ TraceScreen* TraceScreen_new(Process* process);
void TraceScreen_delete(TraceScreen* this); void TraceScreen_delete(TraceScreen* this);
void TraceScreen_draw(TraceScreen* this);
void TraceScreen_run(TraceScreen* this); void TraceScreen_run(TraceScreen* this);
#endif #endif

View File

@ -18,19 +18,7 @@ int UptimeMeter_attributes[] = {
UPTIME UPTIME
}; };
MeterType UptimeMeter = { static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
.setValues = UptimeMeter_setValues,
.display = NULL,
.mode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = UptimeMeter_attributes,
.name = "Uptime",
.uiName = "Uptime",
.caption = "Uptime: "
};
void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
double uptime; double uptime;
FILE* fd = fopen(PROCDIR "/uptime", "r"); FILE* fd = fopen(PROCDIR "/uptime", "r");
fscanf(fd, "%lf", &uptime); fscanf(fd, "%lf", &uptime);
@ -56,3 +44,15 @@ void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
} }
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds); snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
} }
MeterType UptimeMeter = {
.setValues = UptimeMeter_setValues,
.display = NULL,
.mode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = UptimeMeter_attributes,
.name = "Uptime",
.uiName = "Uptime",
.caption = "Uptime: "
};

View File

@ -21,6 +21,4 @@ extern int UptimeMeter_attributes[];
extern MeterType UptimeMeter; extern MeterType UptimeMeter;
void UptimeMeter_setValues(Meter* this, char* buffer, int len);
#endif #endif

View File

@ -47,10 +47,6 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
return name; return name;
} }
inline int UsersTable_size(UsersTable* this) {
return (Hashtable_size(this->users));
}
inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData) { inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData) {
Hashtable_foreach(this->users, f, userData); Hashtable_foreach(this->users, f, userData);
} }

View File

@ -30,8 +30,6 @@ void UsersTable_delete(UsersTable* this);
char* UsersTable_getRef(UsersTable* this, unsigned int uid); char* UsersTable_getRef(UsersTable* this, unsigned int uid);
extern int UsersTable_size(UsersTable* this);
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData); extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
#endif #endif

View File

@ -218,7 +218,9 @@ inline int Vector_size(Vector* this) {
return this->items; return this->items;
} }
void Vector_merge(Vector* this, Vector* v2) { /*
static void Vector_merge(Vector* this, Vector* v2) {
int i; int i;
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
@ -229,6 +231,8 @@ void Vector_merge(Vector* this, Vector* v2) {
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
*/
void Vector_add(Vector* this, void* data_) { 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_;
@ -252,7 +256,9 @@ inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) {
return -1; return -1;
} }
void Vector_foreach(Vector* this, Vector_procedure f) { /*
static void Vector_foreach(Vector* this, Vector_procedure f) {
int i; int i;
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
@ -260,3 +266,5 @@ void Vector_foreach(Vector* this, Vector_procedure f) {
f(this->array[i]); f(this->array[i]);
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
} }
*/

View File

@ -65,12 +65,16 @@ extern Object* Vector_get(Vector* this, int index);
extern 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_); void Vector_add(Vector* this, void* data_);
extern 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); /*
*/
#endif #endif

1
acinclude.m4 Normal file
View File

@ -0,0 +1 @@
m4_include(plpa-1.1/plpa.m4)

View File

@ -3,6 +3,7 @@
aclocal aclocal
autoconf autoconf
autoheader autoheader
libtoolize --copy
automake --add-missing --copy automake --add-missing --copy

View File

@ -2,16 +2,20 @@
# 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.8],[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])
# Checks for programs. # Checks for programs.
AC_PROG_CC AC_PROG_CC
AM_PROG_CC_C_O
AM_DISABLE_SHARED
AM_ENABLE_STATIC
AC_PROG_LIBTOOL
# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB([ncurses], [refresh], [], [missing_libraries="$missing_libraries libncurses"])
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
@ -43,11 +47,13 @@ AC_TYPE_SIGNAL
AC_FUNC_STAT AC_FUNC_STAT
AC_CHECK_FUNCS([memmove strncasecmp strstr strdup]) AC_CHECK_FUNCS([memmove strncasecmp strstr strdup])
save_cflags="${CFLAGS}"
CFLAGS="${CFLAGS} -std=c99" CFLAGS="${CFLAGS} -std=c99"
AC_MSG_CHECKING([whether gcc -std=c99 option works]) AC_MSG_CHECKING([whether gcc -std=c99 option works])
AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [char *a; a = strdup("foo"); int i = 0; i++; // C99], AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [char *a; a = strdup("foo"); int i = 0; i++; // C99],
AC_MSG_RESULT([yes]), AC_MSG_RESULT([yes]),
AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.])) AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.]))
CFLAGS="$save_cflags"
PROCDIR=/proc PROCDIR=/proc
AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc).], AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc).],
@ -60,11 +66,29 @@ AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc fi
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no") AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
if test "x$enable_openvz" = xyes; then if test "x$enable_openvz" = xyes; then
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.]) AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
fi
AC_ARG_ENABLE(taskstats, [AC_HELP_STRING([--enable-taskstats], [enable per-task IO Stats (taskstats kernel sup required)])], ,enable_taskstats="yes")
if test "x$enable_taskstats" = xyes; then
AC_DEFINE(HAVE_TASKSTATS, 1, [Define if taskstats support enabled.])
fi
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="no")
if test "x$enable_unicode" = xyes; then
AC_CHECK_LIB([ncursesw], [refresh], [], [missing_libraries="$missing_libraries libncursesw"])
else
AC_CHECK_LIB([ncurses], [refresh], [], [missing_libraries="$missing_libraries libncurses"])
fi 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.))
PLPA_INCLUDED(plpa-1.1)
PLPA_INIT(plpa_happy=yes, plpa_happy=no)
if test "x$plpa_happy" = xno; then
AC_MSG_ERROR([Failed to initialize PLPA.])
fi
AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([Makefile])
AC_OUTPUT AC_OUTPUT

2
htop.1
View File

@ -1,4 +1,4 @@
.TH "htop" "1" "0.7" "Bartosz Fenski <fenio@o2.pl>" "Utils" .TH "htop" "1" "0.8" "Bartosz Fenski <fenio@o2.pl>" "Utils"
.SH "NAME" .SH "NAME"
htop \- interactive process viewer htop \- interactive process viewer
.SH "SYNTAX" .SH "SYNTAX"

127
htop.c
View File

@ -1,6 +1,6 @@
/* /*
htop - htop.c htop - htop.c
(C) 2004-2006 Hisham H. Muhammad (C) 2004-2008 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
@ -11,6 +11,7 @@ in the source distribution for its full text.
#include <sys/param.h> #include <sys/param.h>
#include <ctype.h> #include <ctype.h>
#include <stdbool.h> #include <stdbool.h>
#include <locale.h>
#include "ProcessList.h" #include "ProcessList.h"
#include "CRT.h" #include "CRT.h"
@ -34,16 +35,16 @@ in the source distribution for its full text.
#define INCSEARCH_MAX 40 #define INCSEARCH_MAX 40
void printVersionFlag() { static void printVersionFlag() {
clear(); clear();
printf("htop " VERSION " - (C) 2004-2006 Hisham Muhammad.\n"); printf("htop " VERSION " - (C) 2004-2008 Hisham Muhammad.\n");
printf("Released under the GNU GPL.\n\n"); printf("Released under the GNU GPL.\n\n");
exit(0); exit(0);
} }
void printHelpFlag() { static void printHelpFlag() {
clear(); clear();
printf("htop " VERSION " - (C) 2004-2006 Hisham Muhammad.\n"); printf("htop " VERSION " - (C) 2004-2008 Hisham Muhammad.\n");
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");
@ -53,10 +54,14 @@ void printHelpFlag() {
exit(0); exit(0);
} }
void showHelp(ProcessList* pl) { static void showHelp(ProcessList* pl) {
clear(); clear();
attrset(CRT_colors[HELP_BOLD]); attrset(CRT_colors[HELP_BOLD]);
mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2006 Hisham Muhammad.");
for (int i = 0; i < LINES-1; i++)
mvhline(i, 0, ' ', COLS);
mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2008 Hisham Muhammad.");
mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info."); mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info.");
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
@ -139,10 +144,12 @@ void showHelp(ProcessList* pl) {
clear(); clear();
} }
static char* CategoriesFunctions[10] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done "};
static void Setup_run(Settings* settings, int headerHeight) { static void Setup_run(Settings* settings, int headerHeight) {
ScreenManager* scr = ScreenManager_new(0, headerHeight, 0, -1, HORIZONTAL, true); ScreenManager* scr = ScreenManager_new(0, headerHeight, 0, -1, HORIZONTAL, true);
CategoriesPanel* panelCategories = CategoriesPanel_new(settings, scr); CategoriesPanel* panelCategories = CategoriesPanel_new(settings, scr);
ScreenManager_add(scr, (Panel*) panelCategories, NULL, 16); ScreenManager_add(scr, (Panel*) panelCategories, FunctionBar_new(10, CategoriesFunctions, NULL, NULL), 16);
CategoriesPanel_makeMetersPage(panelCategories); CategoriesPanel_makeMetersPage(panelCategories);
Panel* panelFocus; Panel* panelFocus;
int ch; int ch;
@ -151,18 +158,21 @@ static void Setup_run(Settings* settings, int headerHeight) {
} }
static bool changePriority(Panel* panel, int delta) { static bool changePriority(Panel* panel, int delta) {
bool ok = true;
bool anyTagged = false; bool anyTagged = false;
for (int i = 0; i < Panel_getSize(panel); i++) { for (int i = 0; i < Panel_getSize(panel); i++) {
Process* p = (Process*) Panel_get(panel, i); Process* p = (Process*) Panel_get(panel, i);
if (p->tag) { if (p->tag) {
Process_setPriority(p, p->nice + delta); ok = Process_setPriority(p, p->nice + delta) && ok;
anyTagged = true; anyTagged = true;
} }
} }
if (!anyTagged) { if (!anyTagged) {
Process* p = (Process*) Panel_getSelected(panel); Process* p = (Process*) Panel_getSelected(panel);
Process_setPriority(p, p->nice + delta); ok = Process_setPriority(p, p->nice + delta) && ok;
} }
if (!ok)
beep();
return anyTagged; return anyTagged;
} }
@ -193,13 +203,13 @@ static Object* pickFromList(Panel* panel, Panel* list, int x, int y, char** keyL
return NULL; return NULL;
} }
void addUserToList(int key, void* userCast, void* panelCast) { static void addUserToList(int key, void* userCast, void* panelCast) {
char* user = (char*) userCast; char* user = (char*) userCast;
Panel* panel = (Panel*) panelCast; Panel* panel = (Panel*) panelCast;
Panel_add(panel, (Object*) ListItem_new(user, key)); Panel_add(panel, (Object*) ListItem_new(user, key));
} }
void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) { static void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
struct passwd* user = getpwnam(userName); struct passwd* user = getpwnam(userName);
if (user) { if (user) {
*userOnly = true; *userOnly = true;
@ -207,6 +217,14 @@ void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
} }
} }
static inline void setSortKey(ProcessList* pl, ProcessField sortKey, Panel* panel, Settings* settings) {
pl->sortKey = sortKey;
pl->direction = 1;
pl->treeView = false;
settings->changed = true;
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
int delay = -1; int delay = -1;
@ -214,6 +232,12 @@ int main(int argc, char** argv) {
uid_t userId = 0; uid_t userId = 0;
int sortKey = 0; int sortKey = 0;
char *lc_ctype = getenv("LC_CTYPE");
if(lc_ctype != NULL)
setlocale(LC_CTYPE, lc_ctype);
else
setlocale(LC_CTYPE, getenv("LC_ALL"));
int arg = 1; int arg = 1;
while (arg < argc) { while (arg < argc) {
if (String_eq(argv[arg], "--help")) { if (String_eq(argv[arg], "--help")) {
@ -274,10 +298,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
@ -287,6 +307,11 @@ int main(int argc, char** argv) {
CRT_init(settings->delay, settings->colorScheme); CRT_init(settings->delay, settings->colorScheme);
panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false, NULL); panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false, NULL);
if (sortKey > 0) {
pl->sortKey = sortKey;
pl->treeView = false;
pl->direction = 1;
}
Panel_setRichHeader(panel, ProcessList_printHeader(pl)); Panel_setRichHeader(panel, ProcessList_printHeader(pl));
char* searchFunctions[3] = {"Next ", "Exit ", " Search: "}; char* searchFunctions[3] = {"Next ", "Exit ", " Search: "};
@ -433,7 +458,18 @@ int main(int argc, char** argv) {
MEVENT mevent; MEVENT mevent;
int ok = getmouse(&mevent); int ok = getmouse(&mevent);
if (ok == OK) { if (ok == OK) {
if (mevent.y >= panel->y + 1 && mevent.y < LINES - 1) { if (mevent.y == panel->y) {
int x = panel->scrollH + mevent.x + 1;
ProcessField field = ProcessList_keyAt(pl, x);
if (field == pl->sortKey) {
ProcessList_invertSortOrder(pl);
pl->treeView = false;
} else {
setSortKey(pl, field, panel, settings);
}
refreshTimeout = 0;
continue;
} else if (mevent.y >= panel->y + 1 && mevent.y < LINES - 1) {
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
doRefresh = false; doRefresh = false;
refreshTimeout = resetRefreshTimeout; refreshTimeout = resetRefreshTimeout;
@ -460,19 +496,13 @@ int main(int argc, char** argv) {
case 'M': case 'M':
{ {
refreshTimeout = 0; refreshTimeout = 0;
pl->sortKey = PERCENT_MEM; setSortKey(pl, PERCENT_MEM, panel, settings);
pl->treeView = false;
settings->changed = true;
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
break; break;
} }
case 'T': case 'T':
{ {
refreshTimeout = 0; refreshTimeout = 0;
pl->sortKey = TIME; setSortKey(pl, TIME, panel, settings);
pl->treeView = false;
settings->changed = true;
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
break; break;
} }
case 'U': case 'U':
@ -487,10 +517,7 @@ int main(int argc, char** argv) {
case 'P': case 'P':
{ {
refreshTimeout = 0; refreshTimeout = 0;
pl->sortKey = PERCENT_CPU; setSortKey(pl, PERCENT_CPU, panel, settings);
pl->treeView = false;
settings->changed = true;
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
break; break;
} }
case KEY_F(1): case KEY_F(1):
@ -608,20 +635,25 @@ int main(int argc, char** argv) {
Panel* affinityPanel = AffinityPanel_new(pl->processorCount, curr); Panel* affinityPanel = AffinityPanel_new(pl->processorCount, curr);
char* fuFunctions[2] = {"Toggle ", "Done "}; char* fuFunctions[2] = {"Set ", "Cancel "};
pickFromList(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar); void* set = pickFromList(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar);
unsigned long new = AffinityPanel_getAffinity(affinityPanel); if (set) {
bool anyTagged = false; unsigned long new = AffinityPanel_getAffinity(affinityPanel);
for (int i = 0; i < Panel_getSize(panel); i++) { bool anyTagged = false;
Process* p = (Process*) Panel_get(panel, i); bool ok = true;
if (p->tag) { for (int i = 0; i < Panel_getSize(panel); i++) {
Process_setAffinity(p, new); Process* p = (Process*) Panel_get(panel, i);
anyTagged = true; if (p->tag) {
ok = Process_setAffinity(p, new) && ok;
anyTagged = true;
}
} }
} if (!anyTagged) {
if (!anyTagged) { Process* p = (Process*) Panel_getSelected(panel);
Process* p = (Process*) Panel_getSelected(panel); ok = Process_setAffinity(p, new) && ok;
Process_setAffinity(p, new); }
if (!ok)
beep();
} }
((Object*)affinityPanel)->delete((Object*)affinityPanel); ((Object*)affinityPanel)->delete((Object*)affinityPanel);
Panel_setRichHeader(panel, ProcessList_printHeader(pl)); Panel_setRichHeader(panel, ProcessList_printHeader(pl));
@ -644,7 +676,7 @@ int main(int argc, char** argv) {
char* fuFunctions[2] = {"Sort ", "Cancel "}; char* fuFunctions[2] = {"Sort ", "Cancel "};
ProcessField* fields = pl->fields; ProcessField* fields = pl->fields;
for (int i = 0; fields[i]; i++) { for (int i = 0; fields[i]; i++) {
char* name = String_trim(Process_printField(fields[i])); char* name = String_trim(Process_fieldTitles[fields[i]]);
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i])); Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
if (fields[i] == pl->sortKey) if (fields[i] == pl->sortKey)
Panel_setSelected(sortPanel, i); Panel_setSelected(sortPanel, i);
@ -652,12 +684,12 @@ int main(int argc, char** argv) {
} }
ListItem* field = (ListItem*) pickFromList(panel, sortPanel, 15, headerHeight, fuFunctions, defaultBar); ListItem* field = (ListItem*) pickFromList(panel, sortPanel, 15, headerHeight, fuFunctions, defaultBar);
if (field) { if (field) {
pl->treeView = false;
settings->changed = true; settings->changed = true;
pl->sortKey = field->key; setSortKey(pl, field->key, panel, settings);
} else {
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
} }
((Object*)sortPanel)->delete((Object*)sortPanel); ((Object*)sortPanel)->delete((Object*)sortPanel);
Panel_setRichHeader(panel, ProcessList_printHeader(pl));
refreshTimeout = 0; refreshTimeout = 0;
break; break;
} }
@ -697,7 +729,8 @@ int main(int argc, char** argv) {
break; break;
case 'H': case 'H':
refreshTimeout = 0; refreshTimeout = 0;
pl->hideThreads = !pl->hideThreads; pl->hideUserlandThreads = !pl->hideUserlandThreads;
pl->hideThreads = pl->hideUserlandThreads;
settings->changed = true; settings->changed = true;
break; break;
case 'K': case 'K':

13
htop.h
View File

@ -4,7 +4,7 @@
#define HEADER_htop #define HEADER_htop
/* /*
htop - htop.h htop - htop.h
(C) 2004-2006 Hisham H. Muhammad (C) 2004-2008 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
@ -15,6 +15,7 @@ in the source distribution for its full text.
#include <sys/param.h> #include <sys/param.h>
#include <ctype.h> #include <ctype.h>
#include <stdbool.h> #include <stdbool.h>
#include <locale.h>
#include "ProcessList.h" #include "ProcessList.h"
#include "CRT.h" #include "CRT.h"
@ -38,16 +39,6 @@ in the source distribution for its full text.
#define INCSEARCH_MAX 40 #define INCSEARCH_MAX 40
void printVersionFlag();
void printHelpFlag();
void showHelp(ProcessList* pl);
void addUserToList(int key, void* userCast, void* panelCast);
void setUserOnly(const char* userName, bool* userOnly, uid_t* userId);
int main(int argc, char** argv); int main(int argc, char** argv);
#endif #endif

13
plpa-1.1/AUTHORS Normal file
View File

@ -0,0 +1,13 @@
PLPA Authors
============
The IDs in parenthesis are those used in Subversion commit notices.
Current Authors
---------------
Indiana University:
- Jeff Squyres (jsquyres)
Lawrence Berkeley National Lab:
- Paul Hargrove (phargrov)

57
plpa-1.1/LICENSE Normal file
View File

@ -0,0 +1,57 @@
Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
University Research and Technology
Corporation. All rights reserved.
Copyright (c) 2004-2005 The Regents of the University of California.
All rights reserved.
Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
Portions copyright:
Copyright (c) 2004-2005 The University of Tennessee and The University
of Tennessee Research Foundation. All rights
reserved.
Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
University of Stuttgart. All rights reserved.
Copyright (c) 2006, 2007 Advanced Micro Devices, Inc.
All rights reserved.
$COPYRIGHT$
Additional copyrights may follow
$HEADER$
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer listed
in this license in the documentation and/or other materials
provided with the distribution.
- Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
The copyright holders provide no reassurances that the source code
provided does not infringe any patent, copyright, or any other
intellectual property rights of third parties. The copyright holders
disclaim any liability to any recipient for claims brought against
recipient by any third party for infringement of that parties
intellectual property rights.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

17
plpa-1.1/Makefile.am Normal file
View File

@ -0,0 +1,17 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
SUBDIRS = src
DIST_SUBDIRS = $(SUBDIRS)
EXTRA_DIST = README VERSION LICENSE AUTHORS plpa.m4

499
plpa-1.1/Makefile.in Normal file
View File

@ -0,0 +1,499 @@
# Makefile.in generated by automake 1.10 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = plpa-1.1
DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
AUTHORS
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/plpa-1.1/plpa.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h \
$(top_builddir)/plpa-1.1/src/plpa_config.h \
$(top_builddir)/plpa-1.1/src/plpa.h
CONFIG_CLEAN_FILES =
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-dvi-recursive install-exec-recursive \
install-html-recursive install-info-recursive \
install-pdf-recursive install-ps-recursive install-recursive \
installcheck-recursive installdirs-recursive pdf-recursive \
ps-recursive uninstall-recursive
RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
distclean-recursive maintainer-clean-recursive
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = src
DIST_SUBDIRS = $(SUBDIRS)
EXTRA_DIST = README VERSION LICENSE AUTHORS plpa.m4
all: all-recursive
.SUFFIXES:
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu plpa-1.1/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu plpa-1.1/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
*=* | --[!k]*);; \
*k*) failcom='fail=yes';; \
esac; \
done; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| eval $$failcom; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
$(RECURSIVE_CLEAN_TARGETS):
@failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
*=* | --[!k]*);; \
*k*) failcom='fail=yes';; \
esac; \
done; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| eval $$failcom; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
include_option=--etags-include; \
empty_fix=.; \
else \
include_option=--include; \
empty_fix=; \
fi; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test ! -f $$subdir/TAGS || \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d "$(distdir)/$$subdir" \
|| $(MKDIR_P) "$(distdir)/$$subdir" \
|| exit 1; \
distdir=`$(am__cd) $(distdir) && pwd`; \
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$$top_distdir" \
distdir="$$distdir/$$subdir" \
am__remove_distdir=: \
am__skip_length_check=: \
distdir) \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-recursive
all-am: Makefile
installdirs: installdirs-recursive
installdirs-am:
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-recursive
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-recursive
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-tags
dvi: dvi-recursive
dvi-am:
html: html-recursive
info: info-recursive
info-am:
install-data-am:
install-dvi: install-dvi-recursive
install-exec-am:
install-html: install-html-recursive
install-info: install-info-recursive
install-man:
install-pdf: install-pdf-recursive
install-ps: install-ps-recursive
installcheck-am:
maintainer-clean: maintainer-clean-recursive
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-recursive
pdf-am:
ps: ps-recursive
ps-am:
uninstall-am:
.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \
install-strip
.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
all all-am check check-am clean clean-generic clean-libtool \
ctags ctags-recursive distclean distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs installdirs-am maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-generic \
mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
uninstall uninstall-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

29
plpa-1.1/README Normal file
View File

@ -0,0 +1,29 @@
This is a stripped-down version of the PLPA 1.1 package, adapted to
be embedded in the htop code base. For the full PLPA package, go to
http://www.open-mpi.org/projects/plpa/. Copyright notice for PLPA
follows below.
-- Hisham Muhammad, htop author. March 2008.
===========================================================================
This is the Portable Linux Processor Affinity (PLPA) package
(pronounced "pli-pa"). It is intended for developers who wish to use
Linux processor affinity via the sched_setaffinity() and
sched_getaffinity() library calls, but don't want to wade through the
morass of 3 different APIs that have been offered through the life of
these calls in various Linux distributions and glibc versions.
Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
University Research and Technology
Corporation. All rights reserved.
Copyright (c) 2004-2005 The Regents of the University of California.
All rights reserved.
Copyright (c) 2006-2008 Cisco Systems, Inc. All rights reserved.
$COPYRIGHT$
See LICENSE file for a rollup of all copyright notices.
$HEADER$
===========================================================================

36
plpa-1.1/VERSION Normal file
View File

@ -0,0 +1,36 @@
# This is the VERSION file for PLPA, describing the precise version of
# PLPA in this distribution. The various components of the version
# number below are combined to form a single version number string.
# major, minor, and release are generally combined in the form
# <major>.<minor>.<release>. If release is zero, then it is omitted.
major=1
minor=1
release=0
# greek is used for alpha or beta release tags. If it is non-empty,
# it will be appended to the version number. It does not have to be
# numeric. Common examples include a1 (alpha release 1), b1 (beta
# release 1), sc2005 (Super Computing 2005 release). The only
# requirement is that it must be entirely printable ASCII characters
# and have no white space.
greek=
# If want_svn=1, then the SVN r number will be included in the overall
# PLPA version number in some form.
want_svn=0
# If svn_r=-1, then the SVN r numbere will be obtained dynamically at
# run time, either 1) via the "svnversion" command (if this is a
# Subversion checkout) in the form "r<svn_r>", or b) with the date (if
# this is not a Subversion checkout, and the svnversion command cannot
# be used) in the form of "svn<date>". Alternatively, if svn_r is not
# -1, the value of svn_r will be directly appended to the version
# string. This happens during "make dist", for example: if the
# distribution tarball is being made from an SVN checkout, the value
# of svn_r in this file is replaced with the output of "svnversion".
svn_r=r147:149

274
plpa-1.1/plpa.m4 Normal file
View File

@ -0,0 +1,274 @@
# -*- shell-script -*-
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2006-2008 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Main PLPA m4 macro, to be invoked by the user
#
# Expects two paramters:
# 1. What to do upon success
# 2. What to do upon failure
#
AC_DEFUN([PLPA_INIT],[
AC_REQUIRE([_PLPA_INTERNAL_SETUP])
AC_REQUIRE([AC_PROG_CC])
# Check for syscall()
AC_CHECK_FUNC([syscall], [happy=1], [happy=0])
# Look for syscall.h
if test "$happy" = 1; then
AC_CHECK_HEADER([sys/syscall.h], [happy=1], [happy=0])
fi
# Look for unistd.h
if test "$happy" = 1; then
AC_CHECK_HEADER([unistd.h], [happy=1], [happy=0])
fi
# Check for __NR_sched_setaffinity
if test "$happy" = 1; then
AC_MSG_CHECKING([for __NR_sched_setaffinity])
if test "$plpa_emulate" = "yes"; then
AC_MSG_RESULT([emulated])
AC_DEFINE([__NR_sched_setaffinity], [0], [Emulated value])
else
AC_TRY_COMPILE([#include <syscall.h>
#include <unistd.h>], [#ifndef __NR_sched_setaffinity
#error __NR_sched_setaffinity_not found!
#endif
int i = 1;],
[AC_MSG_RESULT([yes])
happy=1],
[AC_MSG_RESULT([no])
happy=0])
fi
fi
# Check for __NR_sched_getaffinity (probably overkill, but what
# the heck?)
if test "$happy" = 1; then
AC_MSG_CHECKING([for __NR_sched_getaffinity])
if test "$plpa_emulate" = "yes"; then
AC_MSG_RESULT([emulated])
AC_DEFINE([__NR_sched_getaffinity], [0], [Emulated value])
else
AC_TRY_COMPILE([#include <syscall.h>
#include <unistd.h>], [#ifndef __NR_sched_getaffinity
#error __NR_sched_getaffinity_not found!
#endif
int i = 1;],
[AC_MSG_RESULT([yes])
happy=1],
[AC_MSG_RESULT([no])
happy=0])
fi
fi
# If all was good, do the real init
AS_IF([test "$happy" = "1"],
[_PLPA_INIT($1, $2)],
[$2])
PLPA_DO_AM_CONDITIONALS
AC_CONFIG_FILES(
plpa_config_prefix[/Makefile]
plpa_config_prefix[/src/Makefile]
)
# Cleanup
unset happy
])dnl
#-----------------------------------------------------------------------
# Build PLPA as a standalone package
AC_DEFUN([PLPA_STANDALONE],[
m4_define([plpa_config_prefix],[.])
AC_REQUIRE([_PLPA_INTERNAL_SETUP])
plpa_mode=standalone
])dnl
#-----------------------------------------------------------------------
# Build PLPA as an included package
AC_DEFUN([PLPA_INCLUDED],[
m4_define([plpa_config_prefix],[$1])
AC_REQUIRE([_PLPA_INTERNAL_SETUP])
plpa_mode=included
PLPA_DISABLE_EXECUTABLES
])dnl
#-----------------------------------------------------------------------
dnl JMS: No fortran bindings yet
dnl # Set whether the fortran bindings will be built or not
dnl AC_DEFUN([PLPA_FORTRAN],[
dnl AC_REQUIRE([_PLPA_INTERNAL_SETUP])
dnl
dnl # Need [] around entire following line to escape m4 properly
dnl [plpa_tmp=`echo $1 | tr '[:upper:]' '[:lower:]'`]
dnl if test "$1" = "0" -o "$1" = "n"; then
dnl plpa_fortran=no
dnl elif test "$1" = "1" -o "$1" = "y"; then
dnl plpa_fortran=yes
dnl else
dnl AC_MSG_WARN([Did not understand PLPA_FORTRAN argument ($1) -- ignored])
dnl fi
dnl ])dnl
#-----------------------------------------------------------------------
# Disable building the executables
AC_DEFUN([PLPA_DISABLE_EXECUTABLES],[
AC_REQUIRE([_PLPA_INTERNAL_SETUP])
plpa_executables=no
])dnl
#-----------------------------------------------------------------------
# Specify the symbol prefix
AC_DEFUN([PLPA_SET_SYMBOL_PREFIX],[
AC_REQUIRE([_PLPA_INTERNAL_SETUP])
plpa_symbol_prefix_value=$1
])dnl
#-----------------------------------------------------------------------
# Internals
AC_DEFUN([_PLPA_INTERNAL_SETUP],[
AC_ARG_ENABLE([plpa_emulate],
AC_HELP_STRING([--enable-plpa-emulate],
[Emulate __NR_sched_setaffinity and __NR_sched_getaffinity, to allow building on non-Linux systems (for testing)]))
if test "$enable_plpa_emulate" = "yes"; then
plpa_emulate=yes
else
plpa_emulate=no
fi
dnl Hisham Muhammad: don't expose flags to htop's configure
dnl
dnl # Included mode, or standalone?
dnl AC_ARG_ENABLE([included-mode],
dnl AC_HELP_STRING([--enable-included-mode],
dnl [Using --enable-included-mode puts the PLPA into "included" mode. The default is --disable-included-mode, meaning that the PLPA is in "standalone" mode.]))
dnl if test "$enable_included_mode" = "yes"; then
plpa_mode=included
dnl else
dnl plpa_mode=standalone
dnl fi
dnl JMS: No fortran bindings yet
dnl # Fortran bindings, or no?
dnl AC_ARG_ENABLE([fortran],
dnl AC_HELP_STRING([--disable-fortran],
dnl [Using --disable-fortran disables building the Fortran PLPA API bindings]))
dnl if test "$enable_fortran" = "yes" -o "$enable_fortran" = ""; then
dnl plpa_fortran=yes
dnl else
dnl plpa_fortran=no
dnl fi
dnl Hisham Muhammad: don't expose flags to htop's configure
dnl
dnl # Build and install the executables or no?
dnl AC_ARG_ENABLE([executables],
dnl AC_HELP_STRING([--disable-executables],
dnl [Using --disable-executables disables building and installing the PLPA executables]))
dnl if test "$enable_executables" = "yes" -o "$enable_executables" = ""; then
dnl plpa_executables=yes
dnl else
plpa_executables=no
dnl fi
dnl Hisham Muhammad: don't expose flags to htop's configure
dnl
dnl # Change the symbol prefix?
dnl AC_ARG_WITH([plpa-symbol-prefix],
dnl AC_HELP_STRING([--with-plpa-symbol-prefix=STRING],
dnl [STRING can be any valid C symbol name. It will be prefixed to all public PLPA symbols. Default: "plpa_"]))
dnl if test "$with_plpa_symbol_prefix" = ""; then
plpa_symbol_prefix_value=plpa_
dnl else
dnl plpa_symbol_prefix_value=$with_plpa_symbol_prefix
dnl fi
])dnl
#-----------------------------------------------------------------------
# Internals for PLPA_INIT
AC_DEFUN([_PLPA_INIT],[
AC_REQUIRE([_PLPA_INTERNAL_SETUP])
# Are we building as standalone or included?
AC_MSG_CHECKING([for PLPA building mode])
AC_MSG_RESULT([$plpa_mode])
# We need to set a path for header, etc files depending on whether
# we're standalone or included. this is taken care of by PLPA_INCLUDED.
AC_MSG_CHECKING([for PLPA config prefix])
AC_MSG_RESULT(plpa_config_prefix)
# Note that plpa_config.h *MUST* be listed first so that it
# becomes the "main" config header file. Any AM_CONFIG_HEADERs
# after that (plpa.h) will only have selective #defines replaced,
# not the entire file.
AM_CONFIG_HEADER(plpa_config_prefix[/src/plpa_config.h])
AM_CONFIG_HEADER(plpa_config_prefix[/src/plpa.h])
# What prefix are we using?
AC_MSG_CHECKING([for PLPA symbol prefix])
AC_DEFINE_UNQUOTED(PLPA_SYM_PREFIX, [$plpa_symbol_prefix_value],
[The PLPA symbol prefix])
# Ensure to [] escape the whole next line so that we can get the
# proper tr tokens
[plpa_symbol_prefix_value_caps="`echo $plpa_symbol_prefix_value | tr '[:lower:]' '[:upper:]'`"]
AC_DEFINE_UNQUOTED(PLPA_SYM_PREFIX_CAPS, [$plpa_symbol_prefix_value_caps],
[The PLPA symbol prefix in all caps])
AC_MSG_RESULT([$plpa_symbol_prefix_value])
dnl JMS: No fortran bindings yet
dnl # Check for fortran
dnl AC_MSG_CHECKING([whether to build PLPA Fortran API])
dnl AC_MSG_RESULT([$plpa_fortran])
# Check whether to build the exectuables or not
AC_MSG_CHECKING([whether to build PLPA executables])
AC_MSG_RESULT([$plpa_executables])
# If we're building executables, we need some things for plpa-taskset
if test "$plpa_executables" = "yes"; then
AC_C_INLINE
fi
# Success
$1
])dnl
#-----------------------------------------------------------------------
# This must be a standalone routine so that it can be called both by
# PLPA_INIT and an external caller (if PLPA_INIT is not invoked).
AC_DEFUN([PLPA_DO_AM_CONDITIONALS],[
if test "$plpa_did_am_conditionals" != "yes"; then
AM_CONDITIONAL([PLPA_BUILD_STANDALONE], [test "$plpa_mode" = "standalone"])
dnl JMS: No fortran bindings yet
dnl AM_CONDITIONAL(PLPA_BUILD_FORTRAN, [test "$plpa_fortran" = "yes"])
AM_CONDITIONAL(PLPA_BUILD_EXECUTABLES, [test "$plpa_executables" = "yes"])
fi
plpa_did_am_conditionals=yes
])dnl

49
plpa-1.1/src/Makefile.am Normal file
View File

@ -0,0 +1,49 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2006-2007 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Defaults
lib_LTLIBRARIES =
noinst_LTLIBRARIES =
nodist_include_HEADERS =
nodist_noinst_HEADERS =
# Note that this file is generated by configure, so we don't want to
# ship it in the tarball. Hence the "nodist_" prefixes to the HEADERS
# macros, below.
public_headers = plpa.h
# See which mode we're building in
if PLPA_BUILD_STANDALONE
lib_LTLIBRARIES += libplpa.la
nodist_include_HEADERS += $(public_headers)
else
noinst_LTLIBRARIES += libplpa_included.la
nodist_noinst_HEADERS += $(public_headers)
endif
# The sources
plpa_sources = \
plpa_internal.h \
plpa_api_probe.c \
plpa_dispatch.c \
plpa_runtime.c \
plpa_map.c
libplpa_la_SOURCES = $(plpa_sources)
libplpa_included_la_SOURCES = $(plpa_sources)

579
plpa-1.1/src/Makefile.in Normal file
View File

@ -0,0 +1,579 @@
# Makefile.in generated by automake 1.10 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2006-2007 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
# See which mode we're building in
@PLPA_BUILD_STANDALONE_TRUE@am__append_1 = libplpa.la
@PLPA_BUILD_STANDALONE_TRUE@am__append_2 = $(public_headers)
@PLPA_BUILD_STANDALONE_FALSE@am__append_3 = libplpa_included.la
@PLPA_BUILD_STANDALONE_FALSE@am__append_4 = $(public_headers)
subdir = plpa-1.1/src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/plpa.h.in $(srcdir)/plpa_config.h.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/plpa-1.1/plpa.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h plpa_config.h plpa.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
libplpa_la_LIBADD =
am__objects_1 = plpa_api_probe.lo plpa_dispatch.lo plpa_runtime.lo \
plpa_map.lo
am_libplpa_la_OBJECTS = $(am__objects_1)
libplpa_la_OBJECTS = $(am_libplpa_la_OBJECTS)
@PLPA_BUILD_STANDALONE_TRUE@am_libplpa_la_rpath = -rpath $(libdir)
libplpa_included_la_LIBADD =
am_libplpa_included_la_OBJECTS = $(am__objects_1)
libplpa_included_la_OBJECTS = $(am_libplpa_included_la_OBJECTS)
@PLPA_BUILD_STANDALONE_FALSE@am_libplpa_included_la_rpath =
DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libplpa_la_SOURCES) $(libplpa_included_la_SOURCES)
DIST_SOURCES = $(libplpa_la_SOURCES) $(libplpa_included_la_SOURCES)
nodist_includeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(nodist_include_HEADERS) $(nodist_noinst_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
# Defaults
lib_LTLIBRARIES = $(am__append_1)
noinst_LTLIBRARIES = $(am__append_3)
nodist_include_HEADERS = $(am__append_2)
nodist_noinst_HEADERS = $(am__append_4)
# Note that this file is generated by configure, so we don't want to
# ship it in the tarball. Hence the "nodist_" prefixes to the HEADERS
# macros, below.
public_headers = plpa.h
# The sources
plpa_sources = \
plpa_internal.h \
plpa_api_probe.c \
plpa_dispatch.c \
plpa_runtime.c \
plpa_map.c
libplpa_la_SOURCES = $(plpa_sources)
libplpa_included_la_SOURCES = $(plpa_sources)
all: plpa_config.h plpa.h
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu plpa-1.1/src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu plpa-1.1/src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
plpa_config.h: stamp-h2
@if test ! -f $@; then \
rm -f stamp-h2; \
$(MAKE) $(AM_MAKEFLAGS) stamp-h2; \
else :; fi
stamp-h2: $(srcdir)/plpa_config.h.in $(top_builddir)/config.status
@rm -f stamp-h2
cd $(top_builddir) && $(SHELL) ./config.status plpa-1.1/src/plpa_config.h
$(srcdir)/plpa_config.h.in: $(am__configure_deps)
cd $(top_srcdir) && $(AUTOHEADER)
rm -f stamp-h2
touch $@
plpa.h: stamp-h3
@if test ! -f $@; then \
rm -f stamp-h3; \
$(MAKE) $(AM_MAKEFLAGS) stamp-h3; \
else :; fi
stamp-h3: $(srcdir)/plpa.h.in $(top_builddir)/config.status
@rm -f stamp-h3
cd $(top_builddir) && $(SHELL) ./config.status plpa-1.1/src/plpa.h
distclean-hdr:
-rm -f plpa_config.h stamp-h2 plpa.h stamp-h3
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
p=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
clean-noinstLTLIBRARIES:
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
@list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libplpa.la: $(libplpa_la_OBJECTS) $(libplpa_la_DEPENDENCIES)
$(LINK) $(am_libplpa_la_rpath) $(libplpa_la_OBJECTS) $(libplpa_la_LIBADD) $(LIBS)
libplpa_included.la: $(libplpa_included_la_OBJECTS) $(libplpa_included_la_DEPENDENCIES)
$(LINK) $(am_libplpa_included_la_rpath) $(libplpa_included_la_OBJECTS) $(libplpa_included_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plpa_api_probe.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plpa_dispatch.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plpa_map.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plpa_runtime.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-nodist_includeHEADERS: $(nodist_include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
@list='$(nodist_include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(nodist_includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
$(nodist_includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
done
uninstall-nodist_includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(nodist_include_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
rm -f "$(DESTDIR)$(includedir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) plpa_config.h.in plpa.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) plpa_config.h.in plpa.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) plpa_config.h.in plpa.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) plpa_config.h.in plpa.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS) plpa_config.h plpa.h
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
clean-noinstLTLIBRARIES mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-hdr distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-nodist_includeHEADERS
install-dvi: install-dvi-am
install-exec-am: install-libLTLIBRARIES
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-libLTLIBRARIES uninstall-nodist_includeHEADERS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libLTLIBRARIES clean-libtool clean-noinstLTLIBRARIES \
ctags distclean distclean-compile distclean-generic \
distclean-hdr distclean-libtool distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \
install-data install-data-am install-dvi install-dvi-am \
install-exec install-exec-am install-html install-html-am \
install-info install-info-am install-libLTLIBRARIES \
install-man install-nodist_includeHEADERS install-pdf \
install-pdf-am install-ps install-ps-am install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-libLTLIBRARIES \
uninstall-nodist_includeHEADERS
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

214
plpa-1.1/src/plpa.h.in Normal file
View File

@ -0,0 +1,214 @@
/* -*- c -*-
*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2008 Cisco, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/*
* Some notes about the declarations and definitions in this file:
*
* This file is a mix of internal and public declarations.
* Applications are warned against using the internal types; they are
* subject to change with no warning.
*
* The PLPA_NAME() and PLPA_NAME_CAPS() macros are used for prefixing
* the PLPA type names, enum names, and symbol names when embedding
* PLPA. When not embedding, the default prefix is "plpa_" (or
* "PLPA_" when using PLPA_NAME_CAPS()). Hence, if you see a
* declaration like this:
*
* int PLPA_NAME(foo)(void);
*
* It's a function named plpa_foo() that returns an int and takes no
* arguments when building PLPA as a standalone library. It's a
* function with a different prefix than "plpa_" when the
* --enable-included-mode and --with-plpa-symbol-prefix options are
* supplied to PLPA's configure script.
*/
#ifndef PLPA_H
#define PLPA_H
/* Absolutely must not include <sched.h> here or it will generate
conflicts. */
/* For memset() */
#include <string.h>
/* For pid_t and size_t */
#include <sys/types.h>
/***************************************************************************
* Internal types
***************************************************************************/
/* If we're building PLPA itself, <plpa_config.h> will have already
been included. But <plpa_config.h> is a private header file; it is
not installed into $includedir. Hence, applications including
<plpa.h> will not have included <plpa_config.h> (this is by
design). So include just enough information here to allow us to
continue. */
#ifndef PLPA_CONFIG_H
/* The PLPA symbol prefix */
#define PLPA_SYM_PREFIX plpa_
/* The PLPA symbol prefix in all caps */
#define PLPA_SYM_PREFIX_CAPS PLPA_
#endif
/* Preprocessors are fun -- the double inderection is unfortunately
necessary. */
#define PLPA_MUNGE_NAME(a, b) PLPA_MUNGE_NAME2(a, b)
#define PLPA_MUNGE_NAME2(a, b) a ## b
#define PLPA_NAME(name) PLPA_MUNGE_NAME(PLPA_SYM_PREFIX, name)
#define PLPA_NAME_CAPS(name) PLPA_MUNGE_NAME(PLPA_SYM_PREFIX_CAPS, name)
/***************************************************************************
* Public type
***************************************************************************/
/* Values that can be returned from plpa_api_probe() */
typedef enum {
/* Sentinel value */
PLPA_NAME_CAPS(PROBE_UNSET),
/* sched_setaffinity syscall available */
PLPA_NAME_CAPS(PROBE_OK),
/* syscall unavailable/unimplemented */
PLPA_NAME_CAPS(PROBE_NOT_SUPPORTED),
/* we experienced some strange failure that the user should report */
PLPA_NAME_CAPS(PROBE_UNKNOWN)
} PLPA_NAME(api_type_t);
/***************************************************************************
* Internal types
***************************************************************************/
/* Internal PLPA bitmask type. This type should not be used by
external applications! */
typedef unsigned long int PLPA_NAME(bitmask_t);
#define PLPA_BITMASK_T_NUM_BITS (sizeof(PLPA_NAME(bitmask_t)) * 8)
#define PLPA_BITMASK_CPU_MAX 1024
#define PLPA_BITMASK_NUM_ELEMENTS (PLPA_BITMASK_CPU_MAX / PLPA_BITMASK_T_NUM_BITS)
/***************************************************************************
* Public type
***************************************************************************/
/* Public type for the PLPA cpu set. */
typedef struct { PLPA_NAME(bitmask_t) bitmask[PLPA_BITMASK_NUM_ELEMENTS]; } PLPA_NAME(cpu_set_t);
/***************************************************************************
* Internal macros
***************************************************************************/
/* Internal macro for identifying the byte in a bitmask array. This
macro should not be used by external applications! */
#define PLPA_CPU_BYTE(num) ((num) / PLPA_BITMASK_T_NUM_BITS)
/* Internal macro for identifying the bit in a bitmask array. This
macro should not be used by external applications! */
#define PLPA_CPU_BIT(num) ((num) % PLPA_BITMASK_T_NUM_BITS)
/***************************************************************************
* Public macros
***************************************************************************/
/* Public macro to zero out a PLPA cpu set (analogous to the FD_ZERO()
macro; see select(2)). */
#define PLPA_CPU_ZERO(cpuset) \
memset((cpuset), 0, sizeof(PLPA_NAME(cpu_set_t)))
/* Public macro to set a bit in a PLPA cpu set (analogous to the
FD_SET() macro; see select(2)). */
#define PLPA_CPU_SET(num, cpuset) \
(cpuset)->bitmask[PLPA_CPU_BYTE(num)] |= ((PLPA_NAME(bitmask_t))1 << PLPA_CPU_BIT(num))
/* Public macro to clear a bit in a PLPA cpu set (analogous to the
FD_CLR() macro; see select(2)). */
#define PLPA_CPU_CLR(num, cpuset) \
(cpuset)->bitmask[PLPA_CPU_BYTE(num)] &= ~((PLPA_NAME(bitmask_t))1 << PLPA_CPU_BIT(num))
/* Public macro to test if a bit is set in a PLPA cpu set (analogous
to the FD_ISSET() macro; see select(2)). */
#define PLPA_CPU_ISSET(num, cpuset) \
(0 != (((cpuset)->bitmask[PLPA_CPU_BYTE(num)]) & ((PLPA_NAME(bitmask_t))1 << PLPA_CPU_BIT(num))))
/***************************************************************************
* Public functions
***************************************************************************/
/* Setup PLPA internals. This function is optional; it will be
automatically invoked by all the other API functions if you do not
invoke it explicitly. Returns 0 upon success. */
int PLPA_NAME(init)(void);
/* Check what API is on this machine. If api_type returns
PLPA_PROBE_OK, then PLPA can function properly on this machine.
Returns 0 upon success. */
int PLPA_NAME(api_probe)(PLPA_NAME(api_type_t) *api_type);
/* Set processor affinity. Use the PLPA_CPU_* macros to set the
cpuset value. The same rules and restrictions about pid apply as
they do for the sched_setaffinity(2) system call. Returns 0 upon
success. */
int PLPA_NAME(sched_setaffinity)(pid_t pid, size_t cpusetsize,
const PLPA_NAME(cpu_set_t) *cpuset);
/* Get processor affinity. Use the PLPA_CPU_* macros to analyze the
returned value of cpuset. The same rules and restrictions about
pid apply as they do for the sched_getaffinity(2) system call.
Returns 0 upon success. */
int PLPA_NAME(sched_getaffinity)(pid_t pid, size_t cpusetsize,
PLPA_NAME(cpu_set_t) *cpuset);
/* Return whether topology information is available (i.e.,
plpa_map_to_*, plpa_max_*). The topology functions will be
available if supported == 1 and the function returns 0. */
int PLPA_NAME(have_topology_information)(int *supported);
/* Map (socket,core) tuple to virtual processor ID. processor_id is
then suitable for use with the PLPA_CPU_* macros, probably leading
to a call to plpa_sched_setaffinity(). Returns 0 upon success. */
int PLPA_NAME(map_to_processor_id)(int socket, int core, int *processor_id);
/* Map processor_id to (socket,core) tuple. The processor_id input is
usually obtained from the return from the plpa_sched_getaffinity()
call, using PLPA_CPU_ISSET to find individual bits in the map that
were set/unset. plpa_map_to_socket_core() can map the bit indexes
to a socket/core tuple. Returns 0 upon success. */
int PLPA_NAME(map_to_socket_core)(int processor_id, int *socket, int *core);
/* Return the max processor ID. Returns both the number of processors
(cores) in a system and the maximum Linux virtual processor ID
(because it may be higher than the number of processors if there
are "holes" in the available Linux virtual processor IDs). Returns
0 upon success. */
int PLPA_NAME(get_processor_info)(int *num_processors, int *max_processor_id);
/* Returns both the number of sockets in the system and the maximum
socket ID number (in case there are "holes" in the list of available
socket IDs). Returns 0 upon sucess. */
int PLPA_NAME(get_socket_info)(int *num_sockets, int *max_socket_id);
/* Return both the number of cores and the max code ID for a given
socket (in case there are "holes" in the list of available core
IDs). Returns 0 upon success. */
int PLPA_NAME(get_core_info)(int socket, int *num_cores, int *max_core_id);
/* Shut down PLPA. This function releases resources used by the PLPA.
It should be the last PLPA function invoked, or can be used to
forcibly cause PLPA to dump its topology cache and re-analyze the
underlying system the next time another PLPA function is called.
Specifically: it is safe to call plpa_init() (or any other PLPA
function) again after plpa_finalized(). Returns 0 upon success. */
int PLPA_NAME(finalize)(void);
#endif /* PLPA_H */

View File

@ -0,0 +1,90 @@
/* -*- c -*-
*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2008 Cisco, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "plpa_config.h"
#include "plpa.h"
#include "plpa_internal.h"
#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>
/* Cache, just to make things a little more efficient */
static PLPA_NAME(api_type_t) cache = PLPA_NAME_CAPS(PROBE_UNSET);
/* The len value we find - not in public header, but used by the lib */
size_t PLPA_NAME(len) = 0;
int PLPA_NAME(api_probe_init)(void)
{
PLPA_NAME(cpu_set_t) mask;
int rc;
size_t len;
for (len = sizeof(mask); len != 0; len >>= 1) {
rc = syscall(__NR_sched_getaffinity, 0, len, &mask);
if (rc >= 0) {
/* OK, kernel is happy with a get(). Validate w/ a set(). */
/* Note that kernel may have told us the "proper" size */
size_t tmp = (0 != rc) ? ((size_t) rc) : len;
/* Pass mask=NULL, expect errno==EFAULT if tmp was OK
as a length */
rc = syscall(__NR_sched_setaffinity, 0, tmp, NULL);
if ((rc < 0) && (errno == EFAULT)) {
cache = PLPA_NAME_CAPS(PROBE_OK);
PLPA_NAME(len) = tmp;
rc = 0;
break;
}
}
if (errno == ENOSYS) {
break; /* No point in looping */
}
}
if (rc >= 0) {
/* OK */
} else if (errno == ENOSYS) {
/* Kernel returns ENOSYS because there is no support for
processor affinity */
cache = PLPA_NAME_CAPS(PROBE_NOT_SUPPORTED);
} else {
/* Unknown! */
cache = PLPA_NAME_CAPS(PROBE_UNKNOWN);
}
return 0;
}
int PLPA_NAME(api_probe)(PLPA_NAME(api_type_t) *api_type)
{
int ret;
/* Check to see that we're initialized */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == api_type) {
return EINVAL;
}
/* All done */
*api_type = cache;
return 0;
}

View File

@ -0,0 +1,112 @@
/* ./src/libplpa/plpa_config.h.in. Generated from configure.ac by autoheader. */
/* -*- c -*-
*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef PLPA_CONFIG_H
#define PLPA_CONFIG_H
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#undef NO_MINUS_C_MINUS_O
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Whether we're in debugging mode or not */
#undef PLPA_DEBUG
/* Major version of PLPA */
#undef PLPA_MAJOR_VERSION
/* Minor version of PLPA */
#undef PLPA_MINOR_VERSION
/* Release version of PLPA */
#undef PLPA_RELEASE_VERSION
/* The PLPA symbol prefix */
#undef PLPA_SYM_PREFIX
/* The PLPA symbol prefix in all caps */
#undef PLPA_SYM_PREFIX_CAPS
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
`char[]'. */
#undef YYTEXT_POINTER
/* Emulated value */
#undef __NR_sched_getaffinity
/* Emulated value */
#undef __NR_sched_setaffinity
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#undef inline
#endif
#endif /* PLPA_CONFIG_H */

View File

@ -0,0 +1,201 @@
/* -*- c -*-
*
* Copyright (c) 2004-2006 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "plpa_config.h"
#include "plpa.h"
#include "plpa_internal.h"
#include <errno.h>
#include <sys/syscall.h>
#include <unistd.h>
/**
* Call the kernel's setaffinity, massaging the user's input
* parameters as necessary
*/
int PLPA_NAME(sched_setaffinity)(pid_t pid, size_t cpusetsize,
const PLPA_NAME(cpu_set_t) *cpuset)
{
int ret;
size_t i;
PLPA_NAME(cpu_set_t) tmp;
PLPA_NAME(api_type_t) api;
/* Check to see that we're initialized */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == cpuset) {
return EINVAL;
}
/* Probe the API type */
if (0 != (ret = PLPA_NAME(api_probe)(&api))) {
return ret;
}
switch (api) {
case PLPA_NAME_CAPS(PROBE_OK):
/* This shouldn't happen, but check anyway */
if (cpusetsize > sizeof(*cpuset)) {
return EINVAL;
}
/* If the user-supplied bitmask is smaller than what the
kernel wants, zero out a temporary buffer of the size that
the kernel wants and copy the user-supplied bitmask to the
lower part of the temporary buffer. This could be done
more efficiently, but we're looking for clarity/simplicity
of code here -- this is not intended to be
performance-critical. */
if (cpusetsize < PLPA_NAME(len)) {
memset(&tmp, 0, sizeof(tmp));
for (i = 0; i < cpusetsize * 8; ++i) {
if (PLPA_CPU_ISSET(i, cpuset)) {
PLPA_CPU_SET(i, &tmp);
}
}
}
/* If the user-supplied bitmask is larger than what the kernel
will accept, scan it and see if there are any set bits in
the part larger than what the kernel will accept. If so,
return EINVAL. Otherwise, copy the part that the kernel
will accept into a temporary and use that. Again,
efficinency is not the issue of this code -- clarity is. */
else if (cpusetsize > PLPA_NAME(len)) {
for (i = PLPA_NAME(len) * 8; i < cpusetsize * 8; ++i) {
if (PLPA_CPU_ISSET(i, cpuset)) {
return EINVAL;
}
}
/* No upper-level bits are set, so now copy over the bits
that the kernel will look at */
memset(&tmp, 0, sizeof(tmp));
for (i = 0; i < PLPA_NAME(len) * 8; ++i) {
if (PLPA_CPU_ISSET(i, cpuset)) {
PLPA_CPU_SET(i, &tmp);
}
}
}
/* Otherwise, the user supplied a buffer that is exactly the
right size. Just for clarity of code, copy the user's
buffer into the temporary and use that. */
else {
memcpy(&tmp, cpuset, cpusetsize);
}
/* Now do the syscall */
ret = syscall(__NR_sched_setaffinity, pid, PLPA_NAME(len), &tmp);
/* Return 0 upon success. According to
http://www.open-mpi.org/community/lists/plpa-users/2006/02/0016.php,
all the kernel implementations return >= 0 upon success. */
if (ret >= 0) {
return 0;
} else {
return ret;
}
break;
case PLPA_NAME_CAPS(PROBE_NOT_SUPPORTED):
/* Process affinity not supported here */
return ENOSYS;
break;
default:
/* Something went wrong */
/* JMS: would be good to have something other than EINVAL here
-- suggestions? */
return EINVAL;
break;
}
}
/**
* Call the kernel's getaffinity, massaging the user's input
* parameters as necessary
*/
int PLPA_NAME(sched_getaffinity)(pid_t pid, size_t cpusetsize,
PLPA_NAME(cpu_set_t) *cpuset)
{
int ret;
PLPA_NAME(api_type_t) api;
/* Check to see that we're initialized */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == cpuset) {
return EINVAL;
}
/* Probe the API type */
if (0 != (ret = PLPA_NAME(api_probe)(&api))) {
return ret;
}
switch (api) {
case PLPA_NAME_CAPS(PROBE_OK):
/* This shouldn't happen, but check anyway */
if (PLPA_NAME(len) > sizeof(*cpuset)) {
return EINVAL;
}
/* If the user supplied a buffer that is too small, then don't
even bother */
if (cpusetsize < PLPA_NAME(len)) {
return EINVAL;
}
/* Now we know that the user's buffer is >= the size required
by the kernel. If it's >, then zero it out so that the
bits at the top are cleared (since they won't be set by the
kernel) */
if (cpusetsize > PLPA_NAME(len)) {
memset(cpuset, 0, cpusetsize);
}
/* Now do the syscall */
ret = syscall(__NR_sched_getaffinity, pid, PLPA_NAME(len), cpuset);
/* Return 0 upon success. According to
http://www.open-mpi.org/community/lists/plpa-users/2006/02/0016.php,
all the kernel implementations return >= 0 upon success. */
if (ret >= 0) {
return 0;
} else {
return ret;
}
break;
case PLPA_NAME_CAPS(PROBE_NOT_SUPPORTED):
/* Process affinity not supported here */
return ENOSYS;
break;
default:
/* Something went wrong */
return EINVAL;
break;
}
}

View File

@ -0,0 +1,36 @@
/* -*- c -*-
*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef PLPA_INTERNAL_H
#define PLPA_INTERNAL_H
#include <plpa.h>
/* Have we initialized yet? */
extern int PLPA_NAME(initialized);
/* Cached size of the affinity buffers that the kernel expects */
extern size_t PLPA_NAME(len);
/* Setup topology information */
int PLPA_NAME(map_init)(void);
/* Setup API type */
int PLPA_NAME(api_probe_init)(void);
/* Free all mapping memory */
void PLPA_NAME(map_finalize)(void);
#endif /* PLPA_INTERNAL_H */

602
plpa-1.1/src/plpa_map.c Normal file
View File

@ -0,0 +1,602 @@
/*
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
*
* Portions of this file originally contributed by Advanced Micro
* Devices, Inc. See notice below.
*/
/* ============================================================
License Agreement
Copyright (c) 2006, 2007 Advanced Micro Devices, Inc.
All rights reserved.
Redistribution and use in any form of this material and any product
thereof including software in source or binary forms, along with any
related documentation, with or without modification ("this material"),
is permitted provided that the following conditions are met:
+ Redistributions of source code of any software must retain the above
copyright notice and all terms of this license as part of the code.
+ Redistributions in binary form of any software must reproduce the
above copyright notice and all terms of this license in any related
documentation and/or other materials.
+ Neither the names nor trademarks of Advanced Micro Devices, Inc. or
any copyright holders or contributors may be used to endorse or
promote products derived from this material without specific prior
written permission.
+ Notice about U.S. Government restricted rights: This material is
provided with "RESTRICTED RIGHTS." Use, duplication or disclosure by
the U.S. Government is subject to the full extent of restrictions set
forth in FAR52.227 and DFARS252.227 et seq., or any successor or
applicable regulations. Use of this material by the U.S. Government
constitutes acknowledgment of the proprietary rights of Advanced Micro
Devices, Inc.
and any copyright holders and contributors.
+ In no event shall anyone redistributing or accessing or using this
material commence or participate in any arbitration or legal action
relating to this material against Advanced Micro Devices, Inc. or any
copyright holders or contributors. The foregoing shall survive any
expiration or termination of this license or any agreement or access
or use related to this material.
+ ANY BREACH OF ANY TERM OF THIS LICENSE SHALL RESULT IN THE IMMEDIATE
REVOCATION OF ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL.
THIS MATERIAL IS PROVIDED BY ADVANCED MICRO DEVICES, INC. AND ANY
COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" IN ITS CURRENT CONDITION
AND WITHOUT ANY REPRESENTATIONS, GUARANTEE, OR WARRANTY OF ANY KIND OR
IN ANY WAY RELATED TO SUPPORT, INDEMNITY, ERROR FREE OR UNINTERRUPTED
OPERATION, OR THAT IT IS FREE FROM DEFECTS OR VIRUSES. ALL
OBLIGATIONS ARE HEREBY DISCLAIMED - WHETHER EXPRESS, IMPLIED, OR
STATUTORY - INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, ACCURACY,
COMPLETENESS, OPERABILITY, QUALITY OF SERVICE, OR NON-INFRINGEMENT. IN
NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, PUNITIVE, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, REVENUE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED OR BASED ON ANY THEORY OF LIABILITY ARISING IN ANY WAY RELATED
TO THIS MATERIAL, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE ENTIRE AND AGGREGATE LIABILITY OF ADVANCED MICRO DEVICES, INC. AND
ANY COPYRIGHT HOLDERS AND CONTRIBUTORS SHALL NOT EXCEED TEN DOLLARS
(US $10.00). ANYONE REDISTRIBUTING OR ACCESSING OR USING THIS MATERIAL
ACCEPTS THIS ALLOCATION OF RISK AND AGREES TO RELEASE ADVANCED MICRO
DEVICES, INC. AND ANY COPYRIGHT HOLDERS AND CONTRIBUTORS FROM ANY AND
ALL LIABILITIES, OBLIGATIONS, CLAIMS, OR DEMANDS IN EXCESS OF TEN
DOLLARS (US $10.00). THE FOREGOING ARE ESSENTIAL TERMS OF THIS LICENSE
AND, IF ANY OF THESE TERMS ARE CONSTRUED AS UNENFORCEABLE, FAIL IN
ESSENTIAL PURPOSE, OR BECOME VOID OR DETRIMENTAL TO ADVANCED MICRO
DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR CONTRIBUTORS FOR ANY REASON,
THEN ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL SHALL
TERMINATE IMMEDIATELY. MOREOVER, THE FOREGOING SHALL SURVIVE ANY
EXPIRATION OR TERMINATION OF THIS LICENSE OR ANY AGREEMENT OR ACCESS
OR USE RELATED TO THIS MATERIAL.
NOTICE IS HEREBY PROVIDED, AND BY REDISTRIBUTING OR ACCESSING OR USING
THIS MATERIAL SUCH NOTICE IS ACKNOWLEDGED, THAT THIS MATERIAL MAY BE
SUBJECT TO RESTRICTIONS UNDER THE LAWS AND REGULATIONS OF THE UNITED
STATES OR OTHER COUNTRIES, WHICH INCLUDE BUT ARE NOT LIMITED TO, U.S.
EXPORT CONTROL LAWS SUCH AS THE EXPORT ADMINISTRATION REGULATIONS AND
NATIONAL SECURITY CONTROLS AS DEFINED THEREUNDER, AS WELL AS STATE
DEPARTMENT CONTROLS UNDER THE U.S. MUNITIONS LIST. THIS MATERIAL MAY
NOT BE USED, RELEASED, TRANSFERRED, IMPORTED, EXPORTED AND/OR RE-
EXPORTED IN ANY MANNER PROHIBITED UNDER ANY APPLICABLE LAWS, INCLUDING
U.S. EXPORT CONTROL LAWS REGARDING SPECIFICALLY DESIGNATED PERSONS,
COUNTRIES AND NATIONALS OF COUNTRIES SUBJECT TO NATIONAL SECURITY
CONTROLS.
MOREOVER,
THE FOREGOING SHALL SURVIVE ANY EXPIRATION OR TERMINATION OF ANY
LICENSE OR AGREEMENT OR ACCESS OR USE RELATED TO THIS MATERIAL.
This license forms the entire agreement regarding the subject matter
hereof and supersedes all proposals and prior discussions and writings
between the parties with respect thereto. This license does not affect
any ownership, rights, title, or interest in, or relating to, this
material. No terms of this license can be modified or waived, and no
breach of this license can be excused, unless done so in a writing
signed by all affected parties. Each term of this license is
separately enforceable. If any term of this license is determined to
be or becomes unenforceable or illegal, such term shall be reformed to
the minimum extent necessary in order for this license to remain in
effect in accordance with its terms as modified by such reformation.
This license shall be governed by and construed in accordance with the
laws of the State of Texas without regard to rules on conflicts of law
of any state or jurisdiction or the United Nations Convention on the
International Sale of Goods. All disputes arising out of this license
shall be subject to the jurisdiction of the federal and state courts
in Austin, Texas, and all defenses are hereby waived concerning
personal jurisdiction and venue of these courts.
============================================================ */
#include "plpa_config.h"
#include "plpa.h"
#include "plpa_internal.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
typedef struct tuple_t_ {
int processor_id, socket, core;
} tuple_t;
static int supported = 0;
static int num_processors = -1;
static int max_processor_num = -1;
static int num_sockets = -1;
static int max_socket_id = -1;
static int *max_core_id = NULL;
static int *num_cores = NULL;
static int max_core_id_overall = -1;
static tuple_t *map_processor_id_to_tuple = NULL;
static tuple_t ***map_tuple_to_processor_id = NULL;
static void clear_cache(void)
{
if (NULL != max_core_id) {
free(max_core_id);
max_core_id = NULL;
}
if (NULL != num_cores) {
free(num_cores);
num_cores = NULL;
}
if (NULL != map_processor_id_to_tuple) {
free(map_processor_id_to_tuple);
map_processor_id_to_tuple = NULL;
}
if (NULL != map_tuple_to_processor_id) {
if (NULL != map_tuple_to_processor_id[0]) {
free(map_tuple_to_processor_id[0]);
map_tuple_to_processor_id = NULL;
}
free(map_tuple_to_processor_id);
map_tuple_to_processor_id = NULL;
}
num_processors = max_processor_num = -1;
num_sockets = max_socket_id = -1;
max_core_id_overall = -1;
}
static void load_cache(const char *sysfs_mount)
{
int i, j, k, invalid_entry, fd;
char path[PATH_MAX], buf[8];
PLPA_NAME(cpu_set_t) *cores_on_sockets;
int found;
/* Check for the parent directory */
sprintf(path, "%s/devices/system/cpu", sysfs_mount);
if (access(path, R_OK|X_OK)) {
return;
}
/* Go through and find the max processor ID */
for (num_processors = max_processor_num = i = 0;
i < PLPA_BITMASK_CPU_MAX; ++i) {
sprintf(path, "%s/devices/system/cpu/cpu%d", sysfs_mount, i);
if (0 != access(path, (R_OK | X_OK))) {
max_processor_num = i - 1;
break;
}
++num_processors;
}
/* If we found no processors, then we have no topology info */
if (0 == num_processors) {
clear_cache();
return;
}
/* Malloc space for the first map (processor ID -> tuple).
Include enough space for one invalid entry. */
map_processor_id_to_tuple = malloc(sizeof(tuple_t) *
(max_processor_num + 2));
if (NULL == map_processor_id_to_tuple) {
return;
}
for (i = 0; i <= max_processor_num; ++i) {
map_processor_id_to_tuple[i].processor_id = i;
map_processor_id_to_tuple[i].socket = -1;
map_processor_id_to_tuple[i].core = -1;
}
/* Set the invalid entry */
invalid_entry = i;
map_processor_id_to_tuple[invalid_entry].processor_id = -1;
map_processor_id_to_tuple[invalid_entry].socket = -1;
map_processor_id_to_tuple[invalid_entry].core = -1;
/* Build a cached map of (socket,core) tuples */
for (found = 0, i = 0; i <= max_processor_num; ++i) {
sprintf(path, "%s/devices/system/cpu/cpu%d/topology/core_id",
sysfs_mount, i);
fd = open(path, O_RDONLY);
if ( fd < 0 ) {
continue;
}
if ( read(fd, buf, 7) <= 0 ) {
continue;
}
sscanf(buf, "%d", &(map_processor_id_to_tuple[i].core));
close(fd);
sprintf(path,
"%s/devices/system/cpu/cpu%d/topology/physical_package_id",
sysfs_mount, i);
fd = open(path, O_RDONLY);
if ( fd < 0 ) {
continue;
}
if ( read(fd, buf, 7) <= 0 ) {
continue;
}
sscanf(buf, "%d", &(map_processor_id_to_tuple[i].socket));
close(fd);
found = 1;
/* Keep a running tab on the max socket number */
if (map_processor_id_to_tuple[i].socket > max_socket_id) {
max_socket_id = map_processor_id_to_tuple[i].socket;
}
}
/* Now that we know the max number of sockets, allocate some
arrays */
max_core_id = malloc(sizeof(int) * (max_socket_id + 1));
if (NULL == max_core_id) {
clear_cache();
return;
}
num_cores = malloc(sizeof(int) * (max_socket_id + 1));
if (NULL == num_cores) {
clear_cache();
return;
}
for (i = 0; i <= max_socket_id; ++i) {
num_cores[i] = -1;
max_core_id[i] = -1;
}
/* Find the max core number on each socket */
for (i = 0; i <= max_processor_num; ++i) {
if (map_processor_id_to_tuple[i].core >
max_core_id[map_processor_id_to_tuple[i].socket]) {
max_core_id[map_processor_id_to_tuple[i].socket] =
map_processor_id_to_tuple[i].core;
}
if (max_core_id[map_processor_id_to_tuple[i].socket] >
max_core_id_overall) {
max_core_id_overall =
max_core_id[map_processor_id_to_tuple[i].socket];
}
}
/* If we didn't find any core_id/physical_package_id's, then we
don't have the topology info */
if (!found) {
clear_cache();
return;
}
/* Go through and count the number of unique sockets found. It
may not be the same as max_socket_id because there may be
"holes" -- e.g., sockets 0 and 3 are used, but sockets 1 and 2
are empty. */
for (j = i = 0; i <= max_socket_id; ++i) {
if (max_core_id[i] >= 0) {
++j;
}
}
if (j > 0) {
num_sockets = j;
}
/* Count how many cores are available on each socket. This may
not be the same as max_core_id[socket_num] if there are
"holes". I don't know if holes can happen (i.e., if specific
cores can be taken offline), but what the heck... */
cores_on_sockets = malloc(sizeof(PLPA_NAME(cpu_set_t)) *
(max_socket_id + 1));
if (NULL == cores_on_sockets) {
clear_cache();
return;
}
for (i = 0; i <= max_socket_id; ++i) {
PLPA_CPU_ZERO(&(cores_on_sockets[i]));
}
for (i = 0; i <= max_processor_num; ++i) {
if (map_processor_id_to_tuple[i].socket >= 0) {
PLPA_CPU_SET(map_processor_id_to_tuple[i].core,
&(cores_on_sockets[map_processor_id_to_tuple[i].socket]));
}
}
for (i = 0; i <= max_socket_id; ++i) {
int count = 0;
for (j = 0; j < PLPA_BITMASK_CPU_MAX; ++j) {
if (PLPA_CPU_ISSET(j, &(cores_on_sockets[i]))) {
++count;
}
}
if (count > 0) {
num_cores[i] = count;
}
}
/* Now go through and build the map in the other direction:
(socket,core) => processor_id. This map simply points to
entries in the other map (i.e., it's by reference instead of by
value). */
map_tuple_to_processor_id = malloc(sizeof(tuple_t **) *
(max_socket_id + 1));
if (NULL == map_tuple_to_processor_id) {
clear_cache();
return;
}
map_tuple_to_processor_id[0] = malloc(sizeof(tuple_t *) *
((max_socket_id + 1) *
(max_core_id_overall + 1)));
if (NULL == map_tuple_to_processor_id[0]) {
clear_cache();
return;
}
/* Set pointers for 2nd dimension */
for (i = 1; i <= max_socket_id; ++i) {
map_tuple_to_processor_id[i] =
map_tuple_to_processor_id[i - 1] + max_core_id_overall + 1;
}
/* Compute map */
for (i = 0; i <= max_socket_id; ++i) {
for (j = 0; j <= max_core_id_overall; ++j) {
/* Default to the invalid entry in the other map, meaning
that this (socket,core) combination doesn't exist
(e.g., the core number does not exist in this socket,
although it does exist in other sockets). */
map_tuple_to_processor_id[i][j] =
&map_processor_id_to_tuple[invalid_entry];
/* See if this (socket,core) tuple exists in the other
map. If so, set this entry to point to it (overriding
the invalid entry default). */
for (k = 0; k <= max_processor_num; ++k) {
if (map_processor_id_to_tuple[k].socket == i &&
map_processor_id_to_tuple[k].core == j) {
map_tuple_to_processor_id[i][j] =
&map_processor_id_to_tuple[k];
#if defined(PLPA_DEBUG) && PLPA_DEBUG
printf("Creating map: (socket %d, core %d) -> ID %d\n",
i, j, k);
#endif
break;
}
}
}
}
supported = 1;
}
/* Internal function to setup the mapping data. Guaranteed to be
calling during PLPA_NAME(init), so we don't have to worry about
thread safety here. */
int PLPA_NAME(map_init)(void)
{
const char *sysfs_mount = "/sys";
char *temp;
temp = getenv("PLPA_SYSFS_MOUNT");
if (temp) {
sysfs_mount = temp;
}
load_cache(sysfs_mount);
return 0;
}
/* Internal function to cleanup allocated memory. Only called by one
thread (during PLPA_NAME(finalize), so don't need to worry about
thread safety here. */
void PLPA_NAME(map_finalize)(void)
{
clear_cache();
}
/* Return whether this kernel supports topology information or not */
int PLPA_NAME(have_topology_information)(int *supported_arg)
{
int ret;
/* Initialize if not already done so */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == supported_arg) {
return EINVAL;
}
*supported_arg = supported;
return 0;
}
int PLPA_NAME(map_to_processor_id)(int socket, int core, int *processor_id)
{
int ret;
/* Initialize if not already done so */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == processor_id) {
return EINVAL;
}
/* If this system doesn't support mapping, sorry Charlie */
if (!supported) {
return ENOSYS;
}
/* Check for some invalid entries */
if (socket < 0 || socket > max_socket_id ||
core < 0 || core > max_core_id_overall) {
return ENOENT;
}
/* If the mapping returns -1, then this is a non-existent
socket/core combo (even though they fall within the max socket
/ max core overall values) */
ret = map_tuple_to_processor_id[socket][core]->processor_id;
if (-1 == ret) {
return ENOENT;
}
/* Ok, all should be good -- return the mapping */
*processor_id = ret;
return 0;
}
int PLPA_NAME(map_to_socket_core)(int processor_id, int *socket, int *core)
{
int ret;
/* Initialize if not already done so */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == socket || NULL == core) {
return EINVAL;
}
/* If this system doesn't support mapping, sorry Charlie */
if (!supported) {
return ENOSYS;
}
/* Check for some invalid entries */
if (processor_id < 0 || processor_id > max_processor_num) {
return ENOENT;
}
ret = map_processor_id_to_tuple[processor_id].socket;
if (-1 == ret) {
return ENOENT;
}
/* Ok, all should be good -- return the mapping */
*socket = ret;
*core = map_processor_id_to_tuple[processor_id].core;
return 0;
}
int PLPA_NAME(get_processor_info)(int *num_processors_arg,
int *max_processor_num_arg)
{
int ret;
/* Initialize if not already done so */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == max_processor_num_arg || NULL == num_processors_arg) {
return EINVAL;
}
/* If this system doesn't support mapping, sorry Charlie */
if (!supported) {
return ENOSYS;
}
/* All done */
*num_processors_arg = num_processors;
*max_processor_num_arg = max_processor_num;
return 0;
}
/* Return the max socket number */
int PLPA_NAME(get_socket_info)(int *num_sockets_arg, int *max_socket_id_arg)
{
int ret;
/* Initialize if not already done so */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == max_socket_id_arg || NULL == num_sockets_arg) {
return EINVAL;
}
/* If this system doesn't support mapping, sorry Charlie */
if (!supported) {
return ENOSYS;
}
/* All done */
*num_sockets_arg = num_sockets;
*max_socket_id_arg = max_socket_id;
return 0;
}
/* Return the number of cores in a socket and the max core ID number */
int PLPA_NAME(get_core_info)(int socket, int *num_cores_arg,
int *max_core_id_arg)
{
int ret;
/* Initialize if not already done so */
if (!PLPA_NAME(initialized)) {
if (0 != (ret = PLPA_NAME(init)())) {
return ret;
}
}
/* Check for bozo arguments */
if (NULL == max_core_id_arg || NULL == num_cores_arg) {
return EINVAL;
}
/* If this system doesn't support mapping, sorry Charlie */
if (!supported) {
return ENOSYS;
}
/* Check for some invalid entries */
if (socket < 0 || socket > max_socket_id || -1 == max_core_id[socket]) {
return ENOENT;
}
ret = num_cores[socket];
if (-1 == ret) {
return ENOENT;
}
/* All done */
*num_cores_arg = ret;
*max_core_id_arg = max_core_id[socket];
return 0;
}

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
*/
#include "plpa_config.h"
#include "plpa.h"
#include "plpa_internal.h"
#include <errno.h>
#include <pthread.h>
/* Global variables */
int PLPA_NAME(initialized) = 0;
/* Local variables */
static int refcount = 0;
static pthread_mutex_t mutex;
/* Central clearing point for all parts of PLPA that need to be
initialized. It is erroneous to call this function by more than
one thread simultaneously. */
int PLPA_NAME(init)(void)
{
int ret;
/* If we're already initialized, simply increase the refcount */
if (PLPA_NAME(initialized)) {
pthread_mutex_lock(&mutex);
++refcount;
pthread_mutex_unlock(&mutex);
return 0;
}
/* Otherwise, initialize all the sybsystems */
if (0 != (ret = pthread_mutex_init(&mutex, NULL)) ||
0 != (ret = PLPA_NAME(api_probe_init)()) ||
0 != (ret = PLPA_NAME(map_init)())) {
return ret;
}
PLPA_NAME(initialized) = 1;
refcount = 1;
return 0;
}
/* Central clearing point for all parts of PLPA that need to be
shutdown. */
int PLPA_NAME(finalize)(void)
{
int val;
/* If we're not initialized, return an error */
if (!PLPA_NAME(initialized)) {
return ENOENT;
}
/* Decrement and check the refcount. If it's nonzero, then simply
return success. */
pthread_mutex_lock(&mutex);
val = --refcount;
pthread_mutex_unlock(&mutex);
if (0 != val) {
return 0;
}
/* Ok, we're the last one. Cleanup. */
PLPA_NAME(map_finalize)();
pthread_mutex_destroy(&mutex);
PLPA_NAME(initialized) = 0;
return 0;
}