mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 13:34:35 +03:00
Compare commits
87 Commits
3.1.2
...
3.0.0beta5
Author | SHA1 | Date | |
---|---|---|---|
a4f4ef5b63 | |||
8c43218aa0 | |||
e77a16f4ae | |||
a49853543e | |||
28a5859fe8 | |||
0939e5cb41 | |||
e1c2dc56fd | |||
e9f95da559 | |||
5a0a4e1adb | |||
f3b47c46e6 | |||
34b147e14e | |||
03e0a73d5b | |||
794419e6c5 | |||
7ec5312974 | |||
af92f0b8d6 | |||
22e9d09723 | |||
fda1475a10 | |||
ebf3cff1ac | |||
7bbb3600fc | |||
4092c90bc3 | |||
7742e17cc0 | |||
2dffee8de9 | |||
791aae87c4 | |||
505fa6b517 | |||
f94c54eb5a | |||
9710ce6c08 | |||
f78f658eed | |||
b8bfe60d2b | |||
5c6d7cca3e | |||
6fe06fb7e5 | |||
657836a2ae | |||
63e1417b8c | |||
9b4bdfcb3e | |||
7a71f9cf32 | |||
c91b0938d5 | |||
4f934c977d | |||
d1696b5d5d | |||
beb47cbb12 | |||
677cac9fab | |||
6790e004cd | |||
8677162836 | |||
475798e8ab | |||
7689c5c3b7 | |||
c2ab3ac422 | |||
61bb649e0a | |||
b8ec1c0337 | |||
499af738e7 | |||
416ef48a62 | |||
b9e0da9200 | |||
509303323f | |||
421a31d6f1 | |||
d4c4c02b97 | |||
1ef20d1f14 | |||
1ab5afa1fe | |||
00d1fb019a | |||
dd175b6881 | |||
7ad9701a12 | |||
881fe9631a | |||
0de77c7075 | |||
0f71db9d82 | |||
da4010783e | |||
3f7622a302 | |||
df5d81a881 | |||
6c2b3b546d | |||
f48f5a10ca | |||
1aa23925c9 | |||
2e1f56d934 | |||
6ee99566cd | |||
dc6bb069f0 | |||
0169577019 | |||
0e38be9ee7 | |||
8e6c1e1bac | |||
709619800f | |||
a72439c9b7 | |||
61e94c1b5b | |||
b9f5892593 | |||
267d03b6d8 | |||
3b819daf82 | |||
d9f8cdf0a6 | |||
59982a188c | |||
0800424fe6 | |||
b4a8f048d1 | |||
2df1f61d77 | |||
e6c98b6e8e | |||
b815e4c7a3 | |||
4791050cea | |||
1edcfad874 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ htop
|
|||||||
.deps/
|
.deps/
|
||||||
Makefile
|
Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
|
INSTALL
|
||||||
aclocal.m4
|
aclocal.m4
|
||||||
autom4te.cache/
|
autom4te.cache/
|
||||||
compile
|
compile
|
||||||
|
93
Action.c
93
Action.c
@ -26,6 +26,7 @@ in the source distribution for its full text.
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -80,7 +81,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
|||||||
header->pl->following = pid;
|
header->pl->following = pid;
|
||||||
unfollow = true;
|
unfollow = true;
|
||||||
}
|
}
|
||||||
ScreenManager_run(scr, &panelFocus, &ch);
|
ScreenManager_run(scr, &panelFocus, &ch, NULL);
|
||||||
if (unfollow) {
|
if (unfollow) {
|
||||||
header->pl->following = -1;
|
header->pl->following = -1;
|
||||||
}
|
}
|
||||||
@ -106,7 +107,7 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis
|
|||||||
CategoriesPanel_makeMetersPage(panelCategories);
|
CategoriesPanel_makeMetersPage(panelCategories);
|
||||||
Panel* panelFocus;
|
Panel* panelFocus;
|
||||||
int ch;
|
int ch;
|
||||||
ScreenManager_run(scr, &panelFocus, &ch);
|
ScreenManager_run(scr, &panelFocus, &ch, "Setup");
|
||||||
ScreenManager_delete(scr);
|
ScreenManager_delete(scr);
|
||||||
if (settings->changed) {
|
if (settings->changed) {
|
||||||
Header_writeBackToSettings(header);
|
Header_writeBackToSettings(header);
|
||||||
@ -155,10 +156,26 @@ static bool expandCollapse(Panel* panel) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool collapseIntoParent(Panel* panel) {
|
||||||
|
Process* p = (Process*) Panel_getSelected(panel);
|
||||||
|
if (!p) return false;
|
||||||
|
pid_t ppid = Process_getParentPid(p);
|
||||||
|
for (int i = 0; i < Panel_size(panel); i++) {
|
||||||
|
Process* q = (Process*) Panel_get(panel, i);
|
||||||
|
if (q->pid == ppid) {
|
||||||
|
q->showChildren = false;
|
||||||
|
Panel_setSelected(panel, i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||||
settings->sortKey = sortKey;
|
ScreenSettings* ss = settings->ss;
|
||||||
settings->direction = 1;
|
ss->sortKey = sortKey;
|
||||||
settings->treeView = false;
|
ss->direction = 1;
|
||||||
|
ss->treeView = false;
|
||||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,11 +183,12 @@ static Htop_Reaction sortBy(State* st) {
|
|||||||
Htop_Reaction reaction = HTOP_OK;
|
Htop_Reaction reaction = HTOP_OK;
|
||||||
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_newEnterEsc("Sort ", "Cancel "));
|
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_newEnterEsc("Sort ", "Cancel "));
|
||||||
Panel_setHeader(sortPanel, "Sort by");
|
Panel_setHeader(sortPanel, "Sort by");
|
||||||
ProcessField* fields = st->settings->fields;
|
ScreenSettings* ss = st->settings->ss;
|
||||||
|
ProcessField* fields = ss->fields;
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
char* name = String_trim(Process_fields[fields[i]].name);
|
char* name = String_trim(Process_fields[fields[i]].name);
|
||||||
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
||||||
if (fields[i] == st->settings->sortKey)
|
if (fields[i] == ss->sortKey)
|
||||||
Panel_setSelected(sortPanel, i);
|
Panel_setSelected(sortPanel, i);
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
@ -219,8 +237,9 @@ static Htop_Reaction actionToggleProgramPath(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionToggleTreeView(State* st) {
|
static Htop_Reaction actionToggleTreeView(State* st) {
|
||||||
st->settings->treeView = !st->settings->treeView;
|
ScreenSettings* ss = st->settings->ss;
|
||||||
if (st->settings->treeView) st->settings->direction = 1;
|
ss->treeView = !ss->treeView;
|
||||||
|
if (ss->treeView) ss->direction = 1;
|
||||||
ProcessList_expandTree(st->pl);
|
ProcessList_expandTree(st->pl);
|
||||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||||
}
|
}
|
||||||
@ -248,7 +267,7 @@ static Htop_Reaction actionLowerPriority(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionInvertSortOrder(State* st) {
|
static Htop_Reaction actionInvertSortOrder(State* st) {
|
||||||
Settings_invertSortOrder(st->settings);
|
ScreenSettings_invertSortOrder(st->settings->ss);
|
||||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
|
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,14 +280,61 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
|
|||||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
||||||
|
if (!st->settings->ss->treeView) {
|
||||||
|
return HTOP_OK;
|
||||||
|
}
|
||||||
|
bool changed = collapseIntoParent(st->panel);
|
||||||
|
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||||
return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionQuit() {
|
static Htop_Reaction actionQuit() {
|
||||||
return HTOP_QUIT;
|
return HTOP_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionNextScreen(State* st) {
|
||||||
|
Settings* settings = st->settings;
|
||||||
|
settings->ssIndex++;
|
||||||
|
if (settings->ssIndex == settings->nScreens) {
|
||||||
|
settings->ssIndex = 0;
|
||||||
|
}
|
||||||
|
settings->ss = settings->screens[settings->ssIndex];
|
||||||
|
return HTOP_REFRESH;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionPrevScreen(State* st) {
|
||||||
|
Settings* settings = st->settings;
|
||||||
|
if (settings->ssIndex == 0) {
|
||||||
|
settings->ssIndex = settings->nScreens - 1;
|
||||||
|
} else {
|
||||||
|
settings->ssIndex--;
|
||||||
|
}
|
||||||
|
settings->ss = settings->screens[settings->ssIndex];
|
||||||
|
return HTOP_REFRESH;
|
||||||
|
}
|
||||||
|
|
||||||
|
Htop_Reaction Action_setScreenTab(Settings* settings, int x) {
|
||||||
|
int s = 2;
|
||||||
|
for (unsigned int i = 0; i < settings->nScreens; i++) {
|
||||||
|
if (x < s) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const char* name = settings->screens[i]->name;
|
||||||
|
int len = strlen(name);
|
||||||
|
if (x <= s + len + 1) {
|
||||||
|
settings->ssIndex = i;
|
||||||
|
settings->ss = settings->screens[i];
|
||||||
|
return HTOP_REFRESH;
|
||||||
|
}
|
||||||
|
s += len + 3;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionSetAffinity(State* st) {
|
static Htop_Reaction actionSetAffinity(State* st) {
|
||||||
if (st->pl->cpuCount == 1)
|
if (st->pl->cpuCount == 1)
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
@ -451,7 +517,7 @@ static Htop_Reaction actionHelp(State* st) {
|
|||||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
|
addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
|
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_STEAL], "virtualiz");
|
addattrstr(CRT_colors[CPU_GUEST], "virtualiz");
|
||||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||||
}
|
}
|
||||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||||
@ -557,6 +623,7 @@ void Action_setBindings(Htop_Action* keys) {
|
|||||||
keys['+'] = actionExpandOrCollapse;
|
keys['+'] = actionExpandOrCollapse;
|
||||||
keys['='] = actionExpandOrCollapse;
|
keys['='] = actionExpandOrCollapse;
|
||||||
keys['-'] = actionExpandOrCollapse;
|
keys['-'] = actionExpandOrCollapse;
|
||||||
|
keys['\177'] = actionCollapseIntoParent;
|
||||||
keys['u'] = actionFilterByUser;
|
keys['u'] = actionFilterByUser;
|
||||||
keys['F'] = Action_follow;
|
keys['F'] = Action_follow;
|
||||||
keys['S'] = actionSetup;
|
keys['S'] = actionSetup;
|
||||||
@ -572,5 +639,7 @@ void Action_setBindings(Htop_Action* keys) {
|
|||||||
keys['U'] = actionUntagAll;
|
keys['U'] = actionUntagAll;
|
||||||
keys['c'] = actionTagAllChildren;
|
keys['c'] = actionTagAllChildren;
|
||||||
keys['e'] = actionShowEnvScreen;
|
keys['e'] = actionShowEnvScreen;
|
||||||
|
keys['\t'] = actionNextScreen;
|
||||||
|
keys[KEY_SHIFT_TAB] = actionPrevScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
Action.h
2
Action.h
@ -49,6 +49,8 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
|||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
|
Htop_Reaction Action_setScreenTab(Settings* settings, int x);
|
||||||
|
|
||||||
Htop_Reaction Action_follow(State* st);
|
Htop_Reaction Action_follow(State* st);
|
||||||
|
|
||||||
|
|
||||||
|
42
CRT.c
42
CRT.c
@ -42,6 +42,7 @@ in the source distribution for its full text.
|
|||||||
#define KEY_WHEELUP KEY_F(20)
|
#define KEY_WHEELUP KEY_F(20)
|
||||||
#define KEY_WHEELDOWN KEY_F(21)
|
#define KEY_WHEELDOWN KEY_F(21)
|
||||||
#define KEY_RECLICK KEY_F(22)
|
#define KEY_RECLICK KEY_F(22)
|
||||||
|
#define KEY_SHIFT_TAB KEY_F(23)
|
||||||
|
|
||||||
//#link curses
|
//#link curses
|
||||||
|
|
||||||
@ -128,6 +129,11 @@ typedef enum ColorElements_ {
|
|||||||
CPU_SOFTIRQ,
|
CPU_SOFTIRQ,
|
||||||
CPU_STEAL,
|
CPU_STEAL,
|
||||||
CPU_GUEST,
|
CPU_GUEST,
|
||||||
|
PANEL_EDIT,
|
||||||
|
SCREENS_OTH_BORDER,
|
||||||
|
SCREENS_OTH_TEXT,
|
||||||
|
SCREENS_CUR_BORDER,
|
||||||
|
SCREENS_CUR_TEXT,
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
@ -232,6 +238,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_SOFTIRQ] = ColorPair(Magenta,Black),
|
[CPU_SOFTIRQ] = ColorPair(Magenta,Black),
|
||||||
[CPU_STEAL] = ColorPair(Cyan,Black),
|
[CPU_STEAL] = ColorPair(Cyan,Black),
|
||||||
[CPU_GUEST] = ColorPair(Cyan,Black),
|
[CPU_GUEST] = ColorPair(Cyan,Black),
|
||||||
|
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||||
|
[SCREENS_OTH_BORDER] = ColorPair(Blue,Blue),
|
||||||
|
[SCREENS_OTH_TEXT] = ColorPair(Black,Blue),
|
||||||
|
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
||||||
|
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_MONOCHROME] = {
|
[COLORSCHEME_MONOCHROME] = {
|
||||||
[RESET_COLOR] = A_NORMAL,
|
[RESET_COLOR] = A_NORMAL,
|
||||||
@ -291,6 +302,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_SOFTIRQ] = A_BOLD,
|
[CPU_SOFTIRQ] = A_BOLD,
|
||||||
[CPU_STEAL] = A_REVERSE,
|
[CPU_STEAL] = A_REVERSE,
|
||||||
[CPU_GUEST] = A_REVERSE,
|
[CPU_GUEST] = A_REVERSE,
|
||||||
|
[PANEL_EDIT] = A_BOLD,
|
||||||
|
[SCREENS_OTH_BORDER] = A_DIM,
|
||||||
|
[SCREENS_OTH_TEXT] = A_DIM,
|
||||||
|
[SCREENS_CUR_BORDER] = A_REVERSE,
|
||||||
|
[SCREENS_CUR_TEXT] = A_REVERSE,
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BLACKONWHITE] = {
|
[COLORSCHEME_BLACKONWHITE] = {
|
||||||
[RESET_COLOR] = ColorPair(Black,White),
|
[RESET_COLOR] = ColorPair(Black,White),
|
||||||
@ -350,6 +366,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_SOFTIRQ] = ColorPair(Blue,White),
|
[CPU_SOFTIRQ] = ColorPair(Blue,White),
|
||||||
[CPU_STEAL] = ColorPair(Cyan,White),
|
[CPU_STEAL] = ColorPair(Cyan,White),
|
||||||
[CPU_GUEST] = ColorPair(Cyan,White),
|
[CPU_GUEST] = ColorPair(Cyan,White),
|
||||||
|
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||||
|
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Black,White),
|
||||||
|
[SCREENS_OTH_TEXT] = A_BOLD | ColorPair(Black,White),
|
||||||
|
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
||||||
|
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_LIGHTTERMINAL] = {
|
[COLORSCHEME_LIGHTTERMINAL] = {
|
||||||
[RESET_COLOR] = ColorPair(Black,Black),
|
[RESET_COLOR] = ColorPair(Black,Black),
|
||||||
@ -409,6 +430,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
||||||
[CPU_STEAL] = ColorPair(Black,Black),
|
[CPU_STEAL] = ColorPair(Black,Black),
|
||||||
[CPU_GUEST] = ColorPair(Black,Black),
|
[CPU_GUEST] = ColorPair(Black,Black),
|
||||||
|
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||||
|
[SCREENS_OTH_BORDER] = ColorPair(Blue,Black),
|
||||||
|
[SCREENS_OTH_TEXT] = ColorPair(Blue,Black),
|
||||||
|
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
||||||
|
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_MIDNIGHT] = {
|
[COLORSCHEME_MIDNIGHT] = {
|
||||||
[RESET_COLOR] = ColorPair(White,Blue),
|
[RESET_COLOR] = ColorPair(White,Blue),
|
||||||
@ -468,6 +494,11 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_SOFTIRQ] = ColorPair(Black,Blue),
|
[CPU_SOFTIRQ] = ColorPair(Black,Blue),
|
||||||
[CPU_STEAL] = ColorPair(White,Blue),
|
[CPU_STEAL] = ColorPair(White,Blue),
|
||||||
[CPU_GUEST] = ColorPair(White,Blue),
|
[CPU_GUEST] = ColorPair(White,Blue),
|
||||||
|
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||||
|
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Yellow,Blue),
|
||||||
|
[SCREENS_OTH_TEXT] = ColorPair(Cyan,Blue),
|
||||||
|
[SCREENS_CUR_BORDER] = ColorPair(Cyan,Cyan),
|
||||||
|
[SCREENS_CUR_TEXT] = ColorPair(Black,Cyan),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BLACKNIGHT] = {
|
[COLORSCHEME_BLACKNIGHT] = {
|
||||||
[RESET_COLOR] = ColorPair(Cyan,Black),
|
[RESET_COLOR] = ColorPair(Cyan,Black),
|
||||||
@ -527,12 +558,15 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
[CPU_SOFTIRQ] = ColorPair(Blue,Black),
|
||||||
[CPU_STEAL] = ColorPair(Cyan,Black),
|
[CPU_STEAL] = ColorPair(Cyan,Black),
|
||||||
[CPU_GUEST] = ColorPair(Cyan,Black),
|
[CPU_GUEST] = ColorPair(Cyan,Black),
|
||||||
|
[PANEL_EDIT] = ColorPair(White,Cyan),
|
||||||
|
[SCREENS_OTH_BORDER] = ColorPair(White,Black),
|
||||||
|
[SCREENS_OTH_TEXT] = ColorPair(Cyan,Black),
|
||||||
|
[SCREENS_CUR_BORDER] = A_BOLD | ColorPair(White,Black),
|
||||||
|
[SCREENS_CUR_TEXT] = A_BOLD | ColorPair(Green,Black),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
|
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
|
||||||
};
|
};
|
||||||
|
|
||||||
int CRT_cursorX = 0;
|
|
||||||
|
|
||||||
int CRT_scrollHAmount = 5;
|
int CRT_scrollHAmount = 5;
|
||||||
|
|
||||||
int CRT_scrollWheelVAmount = 10;
|
int CRT_scrollWheelVAmount = 10;
|
||||||
@ -641,12 +675,16 @@ void CRT_init(int delay, int colorScheme) {
|
|||||||
define_key("\033[13~", KEY_F(3));
|
define_key("\033[13~", KEY_F(3));
|
||||||
define_key("\033[14~", KEY_F(4));
|
define_key("\033[14~", KEY_F(4));
|
||||||
define_key("\033[17;2~", KEY_F(18));
|
define_key("\033[17;2~", KEY_F(18));
|
||||||
|
define_key("\033[Z", KEY_SHIFT_TAB);
|
||||||
char sequence[3] = "\033a";
|
char sequence[3] = "\033a";
|
||||||
for (char c = 'a'; c <= 'z'; c++) {
|
for (char c = 'a'; c <= 'z'; c++) {
|
||||||
sequence[1] = c;
|
sequence[1] = c;
|
||||||
define_key(sequence, KEY_ALT('A' + (c - 'a')));
|
define_key(sequence, KEY_ALT('A' + (c - 'a')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (String_startsWith(CRT_termType, "rxvt")) {
|
||||||
|
define_key("\033[Z", KEY_SHIFT_TAB);
|
||||||
|
}
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
signal(11, CRT_handleSIGSEGV);
|
signal(11, CRT_handleSIGSEGV);
|
||||||
#endif
|
#endif
|
||||||
|
8
CRT.h
8
CRT.h
@ -31,6 +31,7 @@ in the source distribution for its full text.
|
|||||||
#define KEY_WHEELUP KEY_F(20)
|
#define KEY_WHEELUP KEY_F(20)
|
||||||
#define KEY_WHEELDOWN KEY_F(21)
|
#define KEY_WHEELDOWN KEY_F(21)
|
||||||
#define KEY_RECLICK KEY_F(22)
|
#define KEY_RECLICK KEY_F(22)
|
||||||
|
#define KEY_SHIFT_TAB KEY_F(23)
|
||||||
|
|
||||||
//#link curses
|
//#link curses
|
||||||
|
|
||||||
@ -116,6 +117,11 @@ typedef enum ColorElements_ {
|
|||||||
CPU_SOFTIRQ,
|
CPU_SOFTIRQ,
|
||||||
CPU_STEAL,
|
CPU_STEAL,
|
||||||
CPU_GUEST,
|
CPU_GUEST,
|
||||||
|
PANEL_EDIT,
|
||||||
|
SCREENS_OTH_BORDER,
|
||||||
|
SCREENS_OTH_TEXT,
|
||||||
|
SCREENS_CUR_BORDER,
|
||||||
|
SCREENS_CUR_TEXT,
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
@ -144,8 +150,6 @@ int* CRT_colors;
|
|||||||
|
|
||||||
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
|
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
|
||||||
|
|
||||||
extern int CRT_cursorX;
|
|
||||||
|
|
||||||
extern int CRT_scrollHAmount;
|
extern int CRT_scrollHAmount;
|
||||||
|
|
||||||
extern int CRT_scrollWheelVAmount;
|
extern int CRT_scrollWheelVAmount;
|
||||||
|
@ -10,7 +10,7 @@ in the source distribution for its full text.
|
|||||||
#include "AvailableMetersPanel.h"
|
#include "AvailableMetersPanel.h"
|
||||||
#include "MetersPanel.h"
|
#include "MetersPanel.h"
|
||||||
#include "DisplayOptionsPanel.h"
|
#include "DisplayOptionsPanel.h"
|
||||||
#include "ColumnsPanel.h"
|
#include "ScreensPanel.h"
|
||||||
#include "ColorsPanel.h"
|
#include "ColorsPanel.h"
|
||||||
#include "AvailableColumnsPanel.h"
|
#include "AvailableColumnsPanel.h"
|
||||||
|
|
||||||
@ -64,9 +64,11 @@ static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
|||||||
ScreenManager_add(this->scr, colors, -1);
|
ScreenManager_add(this->scr, colors, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
static void CategoriesPanel_makeScreensPage(CategoriesPanel* this) {
|
||||||
Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
|
Panel* screens = (Panel*) ScreensPanel_new(this->settings);
|
||||||
|
Panel* columns = (Panel*) ((ScreensPanel*)screens)->columns;
|
||||||
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
|
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
|
||||||
|
ScreenManager_add(this->scr, screens, 20);
|
||||||
ScreenManager_add(this->scr, columns, 20);
|
ScreenManager_add(this->scr, columns, 20);
|
||||||
ScreenManager_add(this->scr, availableColumns, -1);
|
ScreenManager_add(this->scr, availableColumns, -1);
|
||||||
}
|
}
|
||||||
@ -118,7 +120,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
|||||||
CategoriesPanel_makeColorsPage(this);
|
CategoriesPanel_makeColorsPage(this);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
CategoriesPanel_makeColumnsPage(this);
|
CategoriesPanel_makeScreensPage(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,10 +145,10 @@ CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Hea
|
|||||||
this->settings = settings;
|
this->settings = settings;
|
||||||
this->header = header;
|
this->header = header;
|
||||||
this->pl = pl;
|
this->pl = pl;
|
||||||
Panel_setHeader(super, "Setup");
|
Panel_setHeader(super, "Categories");
|
||||||
Panel_add(super, (Object*) ListItem_new("Meters", 0));
|
Panel_add(super, (Object*) ListItem_new("Meters", 0));
|
||||||
Panel_add(super, (Object*) ListItem_new("Display options", 0));
|
Panel_add(super, (Object*) ListItem_new("Display options", 0));
|
||||||
Panel_add(super, (Object*) ListItem_new("Colors", 0));
|
Panel_add(super, (Object*) ListItem_new("Colors", 0));
|
||||||
Panel_add(super, (Object*) ListItem_new("Columns", 0));
|
Panel_add(super, (Object*) ListItem_new("Screens", 0));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
31
ChangeLog
31
ChangeLog
@ -1,21 +1,38 @@
|
|||||||
What's new in version 2.1.1
|
What's new in version 2.2.0
|
||||||
|
|
||||||
|
* Solaris/Illumos/OpenIndiana support
|
||||||
|
(thanks to Guy M. Broome)
|
||||||
|
* -t/--tree flag for starting in tree-view mode
|
||||||
|
(thanks to Daniel Flanagan)
|
||||||
|
* macOS: detects High Sierra version to avoid OS bug
|
||||||
|
(thanks to Pierre Malhaire)
|
||||||
|
* OpenBSD: read battery data
|
||||||
|
(thanks to @nerd972)
|
||||||
|
* Various automake and build improvements
|
||||||
|
(thanks to Kang-Che Sung)
|
||||||
* Check for pkg-config when building with --enable-delayacct
|
* Check for pkg-config when building with --enable-delayacct
|
||||||
(thanks to @florian2833z for the report)
|
(thanks to @florian2833z for the report)
|
||||||
|
* Avoid some bashisms in configure script
|
||||||
|
(thanks to Jesin)
|
||||||
* Use CFLAGS from ncurses*-config if present
|
* Use CFLAGS from ncurses*-config if present
|
||||||
(thanks to Michael Klein)
|
(thanks to Michael Klein)
|
||||||
* Fix build failure in Glibc 2.28
|
* Header generator supports non-UTF-8 environments
|
||||||
(thanks to Kang-Che Sung)
|
(thanks to @volkov-am)
|
||||||
|
* Linux: changed detection of kernel threads
|
||||||
|
* Collapse current subtree pressing Backspace
|
||||||
* BUGFIX: fix behavior of SYSCR column
|
* BUGFIX: fix behavior of SYSCR column
|
||||||
(thanks to Marc Kleine-Budde)
|
(thanks to Marc Kleine-Budde)
|
||||||
* BUGFIX: preserve LDFLAGS when building
|
* BUGFIX: obtain exit code of lsof correctly
|
||||||
(thanks to Lance Frederickson for the report)
|
(thanks to @wangqr)
|
||||||
* BUGFIX: fix issue with small terminals
|
|
||||||
(thanks to Daniel Elf for the report)
|
|
||||||
* BUGFIX: fix crash with particular keycodes
|
* BUGFIX: fix crash with particular keycodes
|
||||||
(thanks to Wellington Torrejais da Silva for the report)
|
(thanks to Wellington Torrejais da Silva for the report)
|
||||||
|
* BUGFIX: fix issue with small terminals
|
||||||
|
(thanks to Daniel Elf for the report)
|
||||||
* BUGFIX: fix terminal color issues
|
* BUGFIX: fix terminal color issues
|
||||||
(thanks to Kang-Che Sung for the report)
|
(thanks to Kang-Che Sung for the report)
|
||||||
|
* BUGFIX: preserve LDFLAGS when building
|
||||||
|
(thanks to Lance Frederickson for the report)
|
||||||
|
* BUGFIX: fixed overflow for systems with >= 100 signals
|
||||||
|
|
||||||
What's new in version 2.1.0
|
What's new in version 2.1.0
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
typedef struct ColumnsPanel_ {
|
typedef struct ColumnsPanel_ {
|
||||||
Panel super;
|
Panel super;
|
||||||
|
ScreenSettings* ss;
|
||||||
|
bool* changed;
|
||||||
|
|
||||||
Settings* settings;
|
|
||||||
bool moving;
|
bool moving;
|
||||||
} ColumnsPanel;
|
} ColumnsPanel;
|
||||||
|
|
||||||
@ -123,22 +124,31 @@ PanelClass ColumnsPanel_class = {
|
|||||||
.eventHandler = ColumnsPanel_eventHandler
|
.eventHandler = ColumnsPanel_eventHandler
|
||||||
};
|
};
|
||||||
|
|
||||||
ColumnsPanel* ColumnsPanel_new(Settings* settings) {
|
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss) {
|
||||||
ColumnsPanel* this = AllocThis(ColumnsPanel);
|
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
|
Panel_prune(super);
|
||||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
ProcessField* fields = ss->fields;
|
||||||
|
|
||||||
this->settings = settings;
|
|
||||||
this->moving = false;
|
|
||||||
Panel_setHeader(super, "Active Columns");
|
|
||||||
|
|
||||||
ProcessField* fields = this->settings->fields;
|
|
||||||
for (; *fields; fields++) {
|
for (; *fields; fields++) {
|
||||||
if (Process_fields[*fields].name) {
|
if (Process_fields[*fields].name) {
|
||||||
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
|
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->ss = ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, bool* changed) {
|
||||||
|
ColumnsPanel* this = AllocThis(ColumnsPanel);
|
||||||
|
Panel* super = (Panel*) this;
|
||||||
|
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
|
||||||
|
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||||
|
|
||||||
|
this->ss = ss;
|
||||||
|
this->changed = changed;
|
||||||
|
this->moving = false;
|
||||||
|
Panel_setHeader(super, "Active Columns");
|
||||||
|
|
||||||
|
ColumnsPanel_fill(this, ss);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,14 +164,14 @@ int ColumnsPanel_fieldNameToIndex(const char* name) {
|
|||||||
void ColumnsPanel_update(Panel* super) {
|
void ColumnsPanel_update(Panel* super) {
|
||||||
ColumnsPanel* this = (ColumnsPanel*) super;
|
ColumnsPanel* this = (ColumnsPanel*) super;
|
||||||
int size = Panel_size(super);
|
int size = Panel_size(super);
|
||||||
this->settings->changed = true;
|
*(this->changed) = true;
|
||||||
this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1));
|
this->ss->fields = xRealloc(this->ss->fields, sizeof(ProcessField) * (size+1));
|
||||||
this->settings->flags = 0;
|
this->ss->flags = 0;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
int key = ((ListItem*) Panel_get(super, i))->key;
|
int key = ((ListItem*) Panel_get(super, i))->key;
|
||||||
this->settings->fields[i] = key;
|
this->ss->fields[i] = key;
|
||||||
this->settings->flags |= Process_fields[key].flags;
|
this->ss->flags |= key < 1000 ? Process_fields[key].flags : 0;
|
||||||
}
|
}
|
||||||
this->settings->fields[size] = 0;
|
this->ss->fields[size] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,15 +14,18 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
typedef struct ColumnsPanel_ {
|
typedef struct ColumnsPanel_ {
|
||||||
Panel super;
|
Panel super;
|
||||||
|
ScreenSettings* ss;
|
||||||
|
bool* changed;
|
||||||
|
|
||||||
Settings* settings;
|
|
||||||
bool moving;
|
bool moving;
|
||||||
} ColumnsPanel;
|
} ColumnsPanel;
|
||||||
|
|
||||||
|
|
||||||
extern PanelClass ColumnsPanel_class;
|
extern PanelClass ColumnsPanel_class;
|
||||||
|
|
||||||
ColumnsPanel* ColumnsPanel_new(Settings* settings);
|
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss);
|
||||||
|
|
||||||
|
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, bool* changed);
|
||||||
|
|
||||||
int ColumnsPanel_fieldNameToIndex(const char* name);
|
int ColumnsPanel_fieldNameToIndex(const char* name);
|
||||||
|
|
||||||
|
@ -83,7 +83,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
|||||||
this->scr = scr;
|
this->scr = scr;
|
||||||
|
|
||||||
Panel_setHeader(super, "Display options");
|
Panel_setHeader(super, "Display options");
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Tree view"), &(settings->treeView)));
|
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Shadow other users' processes"), &(settings->shadowOtherUsers)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Shadow other users' processes"), &(settings->shadowOtherUsers)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide kernel threads"), &(settings->hideKernelThreads)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide kernel threads"), &(settings->hideKernelThreads)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide userland process threads"), &(settings->hideUserlandThreads)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide userland process threads"), &(settings->hideUserlandThreads)));
|
||||||
@ -97,5 +96,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
|||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show tabs for screens"), &(settings->screenTabs)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -96,11 +96,12 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionBar_draw(const FunctionBar* this, char* buffer) {
|
int FunctionBar_draw(const FunctionBar* this, char* buffer) {
|
||||||
FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
|
return FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
int FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
||||||
|
int cursorX = 0;
|
||||||
attrset(CRT_colors[FUNCTION_BAR]);
|
attrset(CRT_colors[FUNCTION_BAR]);
|
||||||
mvhline(LINES-1, 0, ' ', COLS);
|
mvhline(LINES-1, 0, ' ', COLS);
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -115,12 +116,10 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
|||||||
if (buffer) {
|
if (buffer) {
|
||||||
attrset(attr);
|
attrset(attr);
|
||||||
mvaddstr(LINES-1, x, buffer);
|
mvaddstr(LINES-1, x, buffer);
|
||||||
CRT_cursorX = x + strlen(buffer);
|
cursorX = x + strlen(buffer);
|
||||||
curs_set(1);
|
|
||||||
} else {
|
|
||||||
curs_set(0);
|
|
||||||
}
|
}
|
||||||
attrset(CRT_colors[RESET_COLOR]);
|
attrset(CRT_colors[RESET_COLOR]);
|
||||||
|
return cursorX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
|
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
|
||||||
|
@ -30,9 +30,9 @@ void FunctionBar_delete(FunctionBar* this);
|
|||||||
|
|
||||||
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
||||||
|
|
||||||
void FunctionBar_draw(const FunctionBar* this, char* buffer);
|
int FunctionBar_draw(const FunctionBar* this, char* buffer);
|
||||||
|
|
||||||
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
int FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
||||||
|
|
||||||
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
||||||
|
|
||||||
|
7
Header.c
7
Header.c
@ -62,7 +62,7 @@ void Header_delete(Header* this) {
|
|||||||
|
|
||||||
void Header_populateFromSettings(Header* this) {
|
void Header_populateFromSettings(Header* this) {
|
||||||
Header_forEachColumn(this, col) {
|
Header_forEachColumn(this, col) {
|
||||||
MeterColumnSettings* colSettings = &this->settings->columns[col];
|
MeterColumnSettings* colSettings = &this->settings->meterColumns[col];
|
||||||
for (int i = 0; i < colSettings->len; i++) {
|
for (int i = 0; i < colSettings->len; i++) {
|
||||||
Header_addMeterByName(this, colSettings->names[i], col);
|
Header_addMeterByName(this, colSettings->names[i], col);
|
||||||
if (colSettings->modes[i] != 0) {
|
if (colSettings->modes[i] != 0) {
|
||||||
@ -75,7 +75,7 @@ void Header_populateFromSettings(Header* this) {
|
|||||||
|
|
||||||
void Header_writeBackToSettings(const Header* this) {
|
void Header_writeBackToSettings(const Header* this) {
|
||||||
Header_forEachColumn(this, col) {
|
Header_forEachColumn(this, col) {
|
||||||
MeterColumnSettings* colSettings = &this->settings->columns[col];
|
MeterColumnSettings* colSettings = &this->settings->meterColumns[col];
|
||||||
|
|
||||||
String_freeArray(colSettings->names);
|
String_freeArray(colSettings->names);
|
||||||
free(colSettings->modes);
|
free(colSettings->modes);
|
||||||
@ -211,6 +211,9 @@ int Header_calculateHeight(Header* this) {
|
|||||||
}
|
}
|
||||||
maxHeight = MAX(maxHeight, height);
|
maxHeight = MAX(maxHeight, height);
|
||||||
}
|
}
|
||||||
|
if (this->settings->screenTabs) {
|
||||||
|
maxHeight++;
|
||||||
|
}
|
||||||
this->height = maxHeight;
|
this->height = maxHeight;
|
||||||
this->pad = pad;
|
this->pad = pad;
|
||||||
return maxHeight;
|
return maxHeight;
|
||||||
|
370
INSTALL
370
INSTALL
@ -1,370 +0,0 @@
|
|||||||
Installation Instructions
|
|
||||||
*************************
|
|
||||||
|
|
||||||
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
|
|
||||||
Inc.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved. This file is offered as-is,
|
|
||||||
without warranty of any kind.
|
|
||||||
|
|
||||||
Basic Installation
|
|
||||||
==================
|
|
||||||
|
|
||||||
Briefly, the shell command `./configure && make && make install'
|
|
||||||
should configure, build, and install this package. The following
|
|
||||||
more-detailed instructions are generic; see the `README' file for
|
|
||||||
instructions specific to this package. Some packages provide this
|
|
||||||
`INSTALL' file but do not implement all of the features documented
|
|
||||||
below. The lack of an optional feature in a given package is not
|
|
||||||
necessarily a bug. More recommendations for GNU packages can be found
|
|
||||||
in *note Makefile Conventions: (standards)Makefile Conventions.
|
|
||||||
|
|
||||||
The `configure' shell script attempts to guess correct values for
|
|
||||||
various system-dependent variables used during compilation. It uses
|
|
||||||
those values to create a `Makefile' in each directory of the package.
|
|
||||||
It may also create one or more `.h' files containing system-dependent
|
|
||||||
definitions. Finally, it creates a shell script `config.status' that
|
|
||||||
you can run in the future to recreate the current configuration, and a
|
|
||||||
file `config.log' containing compiler output (useful mainly for
|
|
||||||
debugging `configure').
|
|
||||||
|
|
||||||
It can also use an optional file (typically called `config.cache'
|
|
||||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
|
||||||
the results of its tests to speed up reconfiguring. Caching is
|
|
||||||
disabled by default to prevent problems with accidental use of stale
|
|
||||||
cache files.
|
|
||||||
|
|
||||||
If you need to do unusual things to compile the package, please try
|
|
||||||
to figure out how `configure' could check whether to do them, and mail
|
|
||||||
diffs or instructions to the address given in the `README' so they can
|
|
||||||
be considered for the next release. If you are using the cache, and at
|
|
||||||
some point `config.cache' contains results you don't want to keep, you
|
|
||||||
may remove or edit it.
|
|
||||||
|
|
||||||
The file `configure.ac' (or `configure.in') is used to create
|
|
||||||
`configure' by a program called `autoconf'. You need `configure.ac' if
|
|
||||||
you want to change it or regenerate `configure' using a newer version
|
|
||||||
of `autoconf'.
|
|
||||||
|
|
||||||
The simplest way to compile this package is:
|
|
||||||
|
|
||||||
1. `cd' to the directory containing the package's source code and type
|
|
||||||
`./configure' to configure the package for your system.
|
|
||||||
|
|
||||||
Running `configure' might take a while. While running, it prints
|
|
||||||
some messages telling which features it is checking for.
|
|
||||||
|
|
||||||
2. Type `make' to compile the package.
|
|
||||||
|
|
||||||
3. Optionally, type `make check' to run any self-tests that come with
|
|
||||||
the package, generally using the just-built uninstalled binaries.
|
|
||||||
|
|
||||||
4. Type `make install' to install the programs and any data files and
|
|
||||||
documentation. When installing into a prefix owned by root, it is
|
|
||||||
recommended that the package be configured and built as a regular
|
|
||||||
user, and only the `make install' phase executed with root
|
|
||||||
privileges.
|
|
||||||
|
|
||||||
5. Optionally, type `make installcheck' to repeat any self-tests, but
|
|
||||||
this time using the binaries in their final installed location.
|
|
||||||
This target does not install anything. Running this target as a
|
|
||||||
regular user, particularly if the prior `make install' required
|
|
||||||
root privileges, verifies that the installation completed
|
|
||||||
correctly.
|
|
||||||
|
|
||||||
6. You can remove the program binaries and object files from the
|
|
||||||
source code directory by typing `make clean'. To also remove the
|
|
||||||
files that `configure' created (so you can compile the package for
|
|
||||||
a different kind of computer), type `make distclean'. There is
|
|
||||||
also a `make maintainer-clean' target, but that is intended mainly
|
|
||||||
for the package's developers. If you use it, you may have to get
|
|
||||||
all sorts of other programs in order to regenerate files that came
|
|
||||||
with the distribution.
|
|
||||||
|
|
||||||
7. Often, you can also type `make uninstall' to remove the installed
|
|
||||||
files again. In practice, not all packages have tested that
|
|
||||||
uninstallation works correctly, even though it is required by the
|
|
||||||
GNU Coding Standards.
|
|
||||||
|
|
||||||
8. Some packages, particularly those that use Automake, provide `make
|
|
||||||
distcheck', which can by used by developers to test that all other
|
|
||||||
targets like `make install' and `make uninstall' work correctly.
|
|
||||||
This target is generally not run by end users.
|
|
||||||
|
|
||||||
Compilers and Options
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Some systems require unusual options for compilation or linking that
|
|
||||||
the `configure' script does not know about. Run `./configure --help'
|
|
||||||
for details on some of the pertinent environment variables.
|
|
||||||
|
|
||||||
You can give `configure' initial values for configuration parameters
|
|
||||||
by setting variables in the command line or in the environment. Here
|
|
||||||
is an example:
|
|
||||||
|
|
||||||
./configure CC=c99 CFLAGS=-g LIBS=-lposix
|
|
||||||
|
|
||||||
*Note Defining Variables::, for more details.
|
|
||||||
|
|
||||||
Compiling For Multiple Architectures
|
|
||||||
====================================
|
|
||||||
|
|
||||||
You can compile the package for more than one kind of computer at the
|
|
||||||
same time, by placing the object files for each architecture in their
|
|
||||||
own directory. To do this, you can use GNU `make'. `cd' to the
|
|
||||||
directory where you want the object files and executables to go and run
|
|
||||||
the `configure' script. `configure' automatically checks for the
|
|
||||||
source code in the directory that `configure' is in and in `..'. This
|
|
||||||
is known as a "VPATH" build.
|
|
||||||
|
|
||||||
With a non-GNU `make', it is safer to compile the package for one
|
|
||||||
architecture at a time in the source code directory. After you have
|
|
||||||
installed the package for one architecture, use `make distclean' before
|
|
||||||
reconfiguring for another architecture.
|
|
||||||
|
|
||||||
On MacOS X 10.5 and later systems, you can create libraries and
|
|
||||||
executables that work on multiple system types--known as "fat" or
|
|
||||||
"universal" binaries--by specifying multiple `-arch' options to the
|
|
||||||
compiler but only a single `-arch' option to the preprocessor. Like
|
|
||||||
this:
|
|
||||||
|
|
||||||
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
|
|
||||||
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
|
|
||||||
CPP="gcc -E" CXXCPP="g++ -E"
|
|
||||||
|
|
||||||
This is not guaranteed to produce working output in all cases, you
|
|
||||||
may have to build one architecture at a time and combine the results
|
|
||||||
using the `lipo' tool if you have problems.
|
|
||||||
|
|
||||||
Installation Names
|
|
||||||
==================
|
|
||||||
|
|
||||||
By default, `make install' installs the package's commands under
|
|
||||||
`/usr/local/bin', include files under `/usr/local/include', etc. You
|
|
||||||
can specify an installation prefix other than `/usr/local' by giving
|
|
||||||
`configure' the option `--prefix=PREFIX', where PREFIX must be an
|
|
||||||
absolute file name.
|
|
||||||
|
|
||||||
You can specify separate installation prefixes for
|
|
||||||
architecture-specific files and architecture-independent files. If you
|
|
||||||
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
|
|
||||||
PREFIX as the prefix for installing programs and libraries.
|
|
||||||
Documentation and other data files still use the regular prefix.
|
|
||||||
|
|
||||||
In addition, if you use an unusual directory layout you can give
|
|
||||||
options like `--bindir=DIR' to specify different values for particular
|
|
||||||
kinds of files. Run `configure --help' for a list of the directories
|
|
||||||
you can set and what kinds of files go in them. In general, the
|
|
||||||
default for these options is expressed in terms of `${prefix}', so that
|
|
||||||
specifying just `--prefix' will affect all of the other directory
|
|
||||||
specifications that were not explicitly provided.
|
|
||||||
|
|
||||||
The most portable way to affect installation locations is to pass the
|
|
||||||
correct locations to `configure'; however, many packages provide one or
|
|
||||||
both of the following shortcuts of passing variable assignments to the
|
|
||||||
`make install' command line to change installation locations without
|
|
||||||
having to reconfigure or recompile.
|
|
||||||
|
|
||||||
The first method involves providing an override variable for each
|
|
||||||
affected directory. For example, `make install
|
|
||||||
prefix=/alternate/directory' will choose an alternate location for all
|
|
||||||
directory configuration variables that were expressed in terms of
|
|
||||||
`${prefix}'. Any directories that were specified during `configure',
|
|
||||||
but not in terms of `${prefix}', must each be overridden at install
|
|
||||||
time for the entire installation to be relocated. The approach of
|
|
||||||
makefile variable overrides for each directory variable is required by
|
|
||||||
the GNU Coding Standards, and ideally causes no recompilation.
|
|
||||||
However, some platforms have known limitations with the semantics of
|
|
||||||
shared libraries that end up requiring recompilation when using this
|
|
||||||
method, particularly noticeable in packages that use GNU Libtool.
|
|
||||||
|
|
||||||
The second method involves providing the `DESTDIR' variable. For
|
|
||||||
example, `make install DESTDIR=/alternate/directory' will prepend
|
|
||||||
`/alternate/directory' before all installation names. The approach of
|
|
||||||
`DESTDIR' overrides is not required by the GNU Coding Standards, and
|
|
||||||
does not work on platforms that have drive letters. On the other hand,
|
|
||||||
it does better at avoiding recompilation issues, and works well even
|
|
||||||
when some directory options were not specified in terms of `${prefix}'
|
|
||||||
at `configure' time.
|
|
||||||
|
|
||||||
Optional Features
|
|
||||||
=================
|
|
||||||
|
|
||||||
If the package supports it, you can cause programs to be installed
|
|
||||||
with an extra prefix or suffix on their names by giving `configure' the
|
|
||||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
|
||||||
|
|
||||||
Some packages pay attention to `--enable-FEATURE' options to
|
|
||||||
`configure', where FEATURE indicates an optional part of the package.
|
|
||||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
|
||||||
is something like `gnu-as' or `x' (for the X Window System). The
|
|
||||||
`README' should mention any `--enable-' and `--with-' options that the
|
|
||||||
package recognizes.
|
|
||||||
|
|
||||||
For packages that use the X Window System, `configure' can usually
|
|
||||||
find the X include and library files automatically, but if it doesn't,
|
|
||||||
you can use the `configure' options `--x-includes=DIR' and
|
|
||||||
`--x-libraries=DIR' to specify their locations.
|
|
||||||
|
|
||||||
Some packages offer the ability to configure how verbose the
|
|
||||||
execution of `make' will be. For these packages, running `./configure
|
|
||||||
--enable-silent-rules' sets the default to minimal output, which can be
|
|
||||||
overridden with `make V=1'; while running `./configure
|
|
||||||
--disable-silent-rules' sets the default to verbose, which can be
|
|
||||||
overridden with `make V=0'.
|
|
||||||
|
|
||||||
Particular systems
|
|
||||||
==================
|
|
||||||
|
|
||||||
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
|
|
||||||
CC is not installed, it is recommended to use the following options in
|
|
||||||
order to use an ANSI C compiler:
|
|
||||||
|
|
||||||
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
|
|
||||||
|
|
||||||
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
|
|
||||||
|
|
||||||
HP-UX `make' updates targets which have the same time stamps as
|
|
||||||
their prerequisites, which makes it generally unusable when shipped
|
|
||||||
generated files such as `configure' are involved. Use GNU `make'
|
|
||||||
instead.
|
|
||||||
|
|
||||||
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
|
|
||||||
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
|
|
||||||
a workaround. If GNU CC is not installed, it is therefore recommended
|
|
||||||
to try
|
|
||||||
|
|
||||||
./configure CC="cc"
|
|
||||||
|
|
||||||
and if that doesn't work, try
|
|
||||||
|
|
||||||
./configure CC="cc -nodtk"
|
|
||||||
|
|
||||||
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
|
|
||||||
directory contains several dysfunctional programs; working variants of
|
|
||||||
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
|
|
||||||
in your `PATH', put it _after_ `/usr/bin'.
|
|
||||||
|
|
||||||
On Haiku, software installed for all users goes in `/boot/common',
|
|
||||||
not `/usr/local'. It is recommended to use the following options:
|
|
||||||
|
|
||||||
./configure --prefix=/boot/common
|
|
||||||
|
|
||||||
Specifying the System Type
|
|
||||||
==========================
|
|
||||||
|
|
||||||
There may be some features `configure' cannot figure out
|
|
||||||
automatically, but needs to determine by the type of machine the package
|
|
||||||
will run on. Usually, assuming the package is built to be run on the
|
|
||||||
_same_ architectures, `configure' can figure that out, but if it prints
|
|
||||||
a message saying it cannot guess the machine type, give it the
|
|
||||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
|
||||||
type, such as `sun4', or a canonical name which has the form:
|
|
||||||
|
|
||||||
CPU-COMPANY-SYSTEM
|
|
||||||
|
|
||||||
where SYSTEM can have one of these forms:
|
|
||||||
|
|
||||||
OS
|
|
||||||
KERNEL-OS
|
|
||||||
|
|
||||||
See the file `config.sub' for the possible values of each field. If
|
|
||||||
`config.sub' isn't included in this package, then this package doesn't
|
|
||||||
need to know the machine type.
|
|
||||||
|
|
||||||
If you are _building_ compiler tools for cross-compiling, you should
|
|
||||||
use the option `--target=TYPE' to select the type of system they will
|
|
||||||
produce code for.
|
|
||||||
|
|
||||||
If you want to _use_ a cross compiler, that generates code for a
|
|
||||||
platform different from the build platform, you should specify the
|
|
||||||
"host" platform (i.e., that on which the generated programs will
|
|
||||||
eventually be run) with `--host=TYPE'.
|
|
||||||
|
|
||||||
Sharing Defaults
|
|
||||||
================
|
|
||||||
|
|
||||||
If you want to set default values for `configure' scripts to share,
|
|
||||||
you can create a site shell script called `config.site' that gives
|
|
||||||
default values for variables like `CC', `cache_file', and `prefix'.
|
|
||||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
|
||||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
|
||||||
`CONFIG_SITE' environment variable to the location of the site script.
|
|
||||||
A warning: not all `configure' scripts look for a site script.
|
|
||||||
|
|
||||||
Defining Variables
|
|
||||||
==================
|
|
||||||
|
|
||||||
Variables not defined in a site shell script can be set in the
|
|
||||||
environment passed to `configure'. However, some packages may run
|
|
||||||
configure again during the build, and the customized values of these
|
|
||||||
variables may be lost. In order to avoid this problem, you should set
|
|
||||||
them in the `configure' command line, using `VAR=value'. For example:
|
|
||||||
|
|
||||||
./configure CC=/usr/local2/bin/gcc
|
|
||||||
|
|
||||||
causes the specified `gcc' to be used as the C compiler (unless it is
|
|
||||||
overridden in the site shell script).
|
|
||||||
|
|
||||||
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
|
|
||||||
an Autoconf limitation. Until the limitation is lifted, you can use
|
|
||||||
this workaround:
|
|
||||||
|
|
||||||
CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
|
|
||||||
|
|
||||||
`configure' Invocation
|
|
||||||
======================
|
|
||||||
|
|
||||||
`configure' recognizes the following options to control how it
|
|
||||||
operates.
|
|
||||||
|
|
||||||
`--help'
|
|
||||||
`-h'
|
|
||||||
Print a summary of all of the options to `configure', and exit.
|
|
||||||
|
|
||||||
`--help=short'
|
|
||||||
`--help=recursive'
|
|
||||||
Print a summary of the options unique to this package's
|
|
||||||
`configure', and exit. The `short' variant lists options used
|
|
||||||
only in the top level, while the `recursive' variant lists options
|
|
||||||
also present in any nested packages.
|
|
||||||
|
|
||||||
`--version'
|
|
||||||
`-V'
|
|
||||||
Print the version of Autoconf used to generate the `configure'
|
|
||||||
script, and exit.
|
|
||||||
|
|
||||||
`--cache-file=FILE'
|
|
||||||
Enable the cache: use and save the results of the tests in FILE,
|
|
||||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
|
||||||
disable caching.
|
|
||||||
|
|
||||||
`--config-cache'
|
|
||||||
`-C'
|
|
||||||
Alias for `--cache-file=config.cache'.
|
|
||||||
|
|
||||||
`--quiet'
|
|
||||||
`--silent'
|
|
||||||
`-q'
|
|
||||||
Do not print messages saying which checks are being made. To
|
|
||||||
suppress all normal output, redirect it to `/dev/null' (any error
|
|
||||||
messages will still be shown).
|
|
||||||
|
|
||||||
`--srcdir=DIR'
|
|
||||||
Look for the package's source code in directory DIR. Usually
|
|
||||||
`configure' can determine that directory automatically.
|
|
||||||
|
|
||||||
`--prefix=DIR'
|
|
||||||
Use DIR as the installation prefix. *note Installation Names::
|
|
||||||
for more details, including other options available for fine-tuning
|
|
||||||
the installation locations.
|
|
||||||
|
|
||||||
`--no-create'
|
|
||||||
`-n'
|
|
||||||
Run the configure checks, but stop before creating any output
|
|
||||||
files.
|
|
||||||
|
|
||||||
`configure' also accepts some other, not widely useful, options. Run
|
|
||||||
`configure --help' for more details.
|
|
43
IncSet.c
43
IncSet.c
@ -38,6 +38,7 @@ typedef struct IncMode_ {
|
|||||||
typedef struct IncSet_ {
|
typedef struct IncSet_ {
|
||||||
IncMode modes[2];
|
IncMode modes[2];
|
||||||
IncMode* active;
|
IncMode* active;
|
||||||
|
Panel* panel;
|
||||||
FunctionBar* defaultBar;
|
FunctionBar* defaultBar;
|
||||||
bool filtering;
|
bool filtering;
|
||||||
bool found;
|
bool found;
|
||||||
@ -115,23 +116,35 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
static bool search(IncSet* this, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||||
int size = Panel_size(panel);
|
int size = Panel_size(panel);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
if (String_contains_i(getPanelValue(panel, i), this->active->buffer)) {
|
||||||
Panel_setSelected(panel, i);
|
Panel_setSelected(panel, i);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found)
|
IncSet_drawBar(this, found ? CRT_colors[FUNCTION_BAR] : CRT_colors[FAILED_SEARCH]);
|
||||||
FunctionBar_draw(mode->bar, mode->buffer);
|
|
||||||
else
|
|
||||||
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||||
|
this->active = &(this->modes[type]);
|
||||||
|
panel->currentBar = this->active->bar;
|
||||||
|
panel->cursorOn = true;
|
||||||
|
this->panel = panel;
|
||||||
|
IncSet_drawBar(this, CRT_colors[FUNCTION_BAR]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void IncSet_deactivate(IncSet* this, Panel* panel) {
|
||||||
|
this->active = NULL;
|
||||||
|
Panel_setDefaultBar(panel);
|
||||||
|
panel->cursorOn = false;
|
||||||
|
FunctionBar_draw(this->defaultBar, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
||||||
if (ch == ERR)
|
if (ch == ERR)
|
||||||
return true;
|
return true;
|
||||||
@ -189,13 +202,11 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||||||
} else {
|
} else {
|
||||||
IncMode_reset(mode);
|
IncMode_reset(mode);
|
||||||
}
|
}
|
||||||
this->active = NULL;
|
IncSet_deactivate(this, panel);
|
||||||
Panel_setDefaultBar(panel);
|
|
||||||
FunctionBar_draw(this->defaultBar, NULL);
|
|
||||||
doSearch = false;
|
doSearch = false;
|
||||||
}
|
}
|
||||||
if (doSearch) {
|
if (doSearch) {
|
||||||
this->found = search(mode, panel, getPanelValue);
|
this->found = search(this, panel, getPanelValue);
|
||||||
}
|
}
|
||||||
if (filterChanged && lines) {
|
if (filterChanged && lines) {
|
||||||
updateWeakPanel(this, panel, lines);
|
updateWeakPanel(this, panel, lines);
|
||||||
@ -210,15 +221,11 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
void IncSet_drawBar(IncSet* this, int attr) {
|
||||||
this->active = &(this->modes[type]);
|
|
||||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
|
||||||
panel->currentBar = this->active->bar;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IncSet_drawBar(IncSet* this) {
|
|
||||||
if (this->active) {
|
if (this->active) {
|
||||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
int cursorX = FunctionBar_drawAttr(this->active->bar, this->active->buffer, attr);
|
||||||
|
this->panel->cursorY = LINES - 1;
|
||||||
|
this->panel->cursorX = cursorX;
|
||||||
} else {
|
} else {
|
||||||
FunctionBar_draw(this->defaultBar, NULL);
|
FunctionBar_draw(this->defaultBar, NULL);
|
||||||
}
|
}
|
||||||
|
7
IncSet.h
7
IncSet.h
@ -33,6 +33,7 @@ typedef struct IncMode_ {
|
|||||||
typedef struct IncSet_ {
|
typedef struct IncSet_ {
|
||||||
IncMode modes[2];
|
IncMode modes[2];
|
||||||
IncMode* active;
|
IncMode* active;
|
||||||
|
Panel* panel;
|
||||||
FunctionBar* defaultBar;
|
FunctionBar* defaultBar;
|
||||||
bool filtering;
|
bool filtering;
|
||||||
bool found;
|
bool found;
|
||||||
@ -45,13 +46,13 @@ IncSet* IncSet_new(FunctionBar* bar);
|
|||||||
|
|
||||||
void IncSet_delete(IncSet* this);
|
void IncSet_delete(IncSet* this);
|
||||||
|
|
||||||
|
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||||
|
|
||||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
||||||
|
|
||||||
const char* IncSet_getListItemValue(Panel* panel, int i);
|
const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||||
|
|
||||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
void IncSet_drawBar(IncSet* this, int attr);
|
||||||
|
|
||||||
void IncSet_drawBar(IncSet* this);
|
|
||||||
|
|
||||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) {
|
|||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
this->display->needsRedraw = true;
|
this->display->needsRedraw = true;
|
||||||
Panel_draw(this->display, true);
|
Panel_draw(this->display, true);
|
||||||
IncSet_drawBar(this->inc);
|
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,11 +115,7 @@ void InfoScreen_run(InfoScreen* this) {
|
|||||||
|
|
||||||
Panel_draw(panel, true);
|
Panel_draw(panel, true);
|
||||||
|
|
||||||
if (this->inc->active) {
|
int ch = Panel_getCh(panel);
|
||||||
(void) move(LINES-1, CRT_cursorX);
|
|
||||||
}
|
|
||||||
set_escdelay(25);
|
|
||||||
int ch = getch();
|
|
||||||
|
|
||||||
if (ch == ERR) {
|
if (ch == ERR) {
|
||||||
if (As_InfoScreen(this)->onErr) {
|
if (As_InfoScreen(this)->onErr) {
|
||||||
|
12
ListItem.c
12
ListItem.c
@ -27,13 +27,13 @@ typedef struct ListItem_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static void ListItem_delete(Object* cast) {
|
void ListItem_delete(Object* cast) {
|
||||||
ListItem* this = (ListItem*)cast;
|
ListItem* this = (ListItem*)cast;
|
||||||
free(this->value);
|
free(this->value);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ListItem_display(Object* cast, RichString* out) {
|
void ListItem_display(Object* cast, RichString* out) {
|
||||||
ListItem* const this = (ListItem*)cast;
|
ListItem* const this = (ListItem*)cast;
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
/*
|
/*
|
||||||
@ -59,11 +59,15 @@ ObjectClass ListItem_class = {
|
|||||||
.compare = ListItem_compare
|
.compare = ListItem_compare
|
||||||
};
|
};
|
||||||
|
|
||||||
ListItem* ListItem_new(const char* value, int key) {
|
void ListItem_init(ListItem* this, const char* value, int key) {
|
||||||
ListItem* this = AllocThis(ListItem);
|
|
||||||
this->value = xStrdup(value);
|
this->value = xStrdup(value);
|
||||||
this->key = key;
|
this->key = key;
|
||||||
this->moving = false;
|
this->moving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ListItem* ListItem_new(const char* value, int key) {
|
||||||
|
ListItem* this = AllocThis(ListItem);
|
||||||
|
ListItem_init(this, value, key);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,14 @@ typedef struct ListItem_ {
|
|||||||
} ListItem;
|
} ListItem;
|
||||||
|
|
||||||
|
|
||||||
|
void ListItem_delete(Object* cast);
|
||||||
|
|
||||||
|
void ListItem_display(Object* cast, RichString* out);
|
||||||
|
|
||||||
extern ObjectClass ListItem_class;
|
extern ObjectClass ListItem_class;
|
||||||
|
|
||||||
|
void ListItem_init(ListItem* this, const char* value, int key);
|
||||||
|
|
||||||
ListItem* ListItem_new(const char* value, int key);
|
ListItem* ListItem_new(const char* value, int key);
|
||||||
|
|
||||||
void ListItem_append(ListItem* this, const char* text);
|
void ListItem_append(ListItem* this, const char* text);
|
||||||
|
18
MainPanel.c
18
MainPanel.c
@ -72,20 +72,26 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
|||||||
|
|
||||||
Htop_Reaction reaction = HTOP_OK;
|
Htop_Reaction reaction = HTOP_OK;
|
||||||
|
|
||||||
|
Settings* settings = this->state->settings;
|
||||||
|
ScreenSettings* ss = settings->ss;
|
||||||
|
|
||||||
if (EVENT_IS_HEADER_CLICK(ch)) {
|
if (EVENT_IS_HEADER_CLICK(ch)) {
|
||||||
int x = EVENT_HEADER_CLICK_GET_X(ch);
|
int x = EVENT_HEADER_CLICK_GET_X(ch);
|
||||||
ProcessList* pl = this->state->pl;
|
ProcessList* pl = this->state->pl;
|
||||||
Settings* settings = this->state->settings;
|
|
||||||
int hx = super->scrollH + x + 1;
|
int hx = super->scrollH + x + 1;
|
||||||
ProcessField field = ProcessList_keyAt(pl, hx);
|
ProcessField field = ProcessList_keyAt(pl, hx);
|
||||||
if (field == settings->sortKey) {
|
if (field == ss->sortKey) {
|
||||||
Settings_invertSortOrder(settings);
|
ScreenSettings_invertSortOrder(ss);
|
||||||
settings->treeView = false;
|
ss->treeView = false;
|
||||||
} else {
|
} else {
|
||||||
reaction |= Action_setSortKey(settings, field);
|
reaction |= Action_setSortKey(settings, field);
|
||||||
}
|
}
|
||||||
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
|
} else if (EVENT_IS_SCREEN_TAB_CLICK(ch)) {
|
||||||
|
int x = EVENT_SCREEN_TAB_GET_X(ch);
|
||||||
|
reaction |= Action_setScreenTab(settings, x);
|
||||||
|
result = HANDLED;
|
||||||
} else if (ch != ERR && this->inc->active) {
|
} else if (ch != ERR && this->inc->active) {
|
||||||
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
||||||
if (filterChanged) {
|
if (filterChanged) {
|
||||||
@ -113,8 +119,8 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reaction & HTOP_REDRAW_BAR) {
|
if (reaction & HTOP_REDRAW_BAR) {
|
||||||
MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
|
MainPanel_updateTreeFunctions(this, settings->ss->treeView);
|
||||||
IncSet_drawBar(this->inc);
|
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||||
}
|
}
|
||||||
if (reaction & HTOP_UPDATE_PANELHDR) {
|
if (reaction & HTOP_UPDATE_PANELHDR) {
|
||||||
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
|
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
|
||||||
|
156
Makefile.am
156
Makefile.am
@ -12,8 +12,8 @@ applications_DATA = htop.desktop
|
|||||||
pixmapdir = $(datadir)/pixmaps
|
pixmapdir = $(datadir)/pixmaps
|
||||||
pixmap_DATA = htop.png
|
pixmap_DATA = htop.png
|
||||||
|
|
||||||
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
AM_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
||||||
htop_LDFLAGS =
|
AM_LDFLAGS =
|
||||||
AM_CPPFLAGS = -DNDEBUG
|
AM_CPPFLAGS = -DNDEBUG
|
||||||
|
|
||||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||||
@ -21,7 +21,7 @@ ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c MainPanel.c \
|
|||||||
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
|
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
|
||||||
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
|
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
|
||||||
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
|
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
|
||||||
SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \
|
SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c ScreensPanel.c \
|
||||||
TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
|
TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
|
||||||
HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \
|
HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \
|
||||||
InfoScreen.c XAlloc.c
|
InfoScreen.c XAlloc.c
|
||||||
@ -31,69 +31,169 @@ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
|
|||||||
CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \
|
CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \
|
||||||
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
|
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
|
||||||
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
|
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
|
||||||
ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \
|
ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h ScreensPanel.h \
|
||||||
TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \
|
TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \
|
||||||
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
||||||
EnvScreen.h InfoScreen.h XAlloc.h
|
EnvScreen.h InfoScreen.h XAlloc.h
|
||||||
|
|
||||||
if HTOP_LINUX
|
all_platform_headers =
|
||||||
htop_CFLAGS += -rdynamic
|
|
||||||
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
|
||||||
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c
|
|
||||||
|
|
||||||
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
|
# Linux
|
||||||
linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h
|
# -----
|
||||||
|
|
||||||
|
linux_platform_headers = \
|
||||||
|
linux/Platform.h \
|
||||||
|
linux/IOPriorityPanel.h \
|
||||||
|
linux/IOPriority.h \
|
||||||
|
linux/LinuxProcess.h \
|
||||||
|
linux/LinuxProcessList.h \
|
||||||
|
linux/LinuxCRT.h \
|
||||||
|
linux/Battery.h \
|
||||||
|
linux/PerfCounter.h
|
||||||
|
|
||||||
|
all_platform_headers += $(linux_platform_headers)
|
||||||
|
|
||||||
|
if HTOP_LINUX
|
||||||
|
AM_CFLAGS += -rdynamic
|
||||||
|
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
||||||
|
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
||||||
|
linux/PerfCounter.c
|
||||||
|
|
||||||
|
myhtopplatheaders = $(linux_platform_headers)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# FreeBSD
|
||||||
|
# -------
|
||||||
|
|
||||||
|
freebsd_platform_headers = \
|
||||||
|
freebsd/Platform.h \
|
||||||
|
freebsd/FreeBSDProcessList.h \
|
||||||
|
freebsd/FreeBSDProcess.h \
|
||||||
|
freebsd/FreeBSDCRT.h \
|
||||||
|
freebsd/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(freebsd_platform_headers)
|
||||||
|
|
||||||
if HTOP_FREEBSD
|
if HTOP_FREEBSD
|
||||||
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
||||||
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
|
myhtopplatheaders = $(freebsd_platform_headers)
|
||||||
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# DragonFlyBSD
|
||||||
|
# ------------
|
||||||
|
|
||||||
|
dragonflybsd_platform_headers = \
|
||||||
|
dragonflybsd/Platform.h \
|
||||||
|
dragonflybsd/DragonFlyBSDProcessList.h \
|
||||||
|
dragonflybsd/DragonFlyBSDProcess.h \
|
||||||
|
dragonflybsd/DragonFlyBSDCRT.h \
|
||||||
|
dragonflybsd/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(dragonflybsd_platform_headers)
|
||||||
|
|
||||||
if HTOP_DRAGONFLYBSD
|
if HTOP_DRAGONFLYBSD
|
||||||
htop_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
AM_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
||||||
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
||||||
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = dragonflybsd/Platform.h dragonflybsd/DragonFlyBSDProcessList.h \
|
myhtopplatheaders = $(dragonflybsd_platform_headers)
|
||||||
dragonflybsd/DragonFlyBSDProcess.h dragonflybsd/DragonFlyBSDCRT.h dragonflybsd/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# OpenBSD
|
||||||
|
# -------
|
||||||
|
|
||||||
|
openbsd_platform_headers = \
|
||||||
|
openbsd/Platform.h \
|
||||||
|
openbsd/OpenBSDProcessList.h \
|
||||||
|
openbsd/OpenBSDProcess.h \
|
||||||
|
openbsd/OpenBSDCRT.h \
|
||||||
|
openbsd/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(openbsd_platform_headers)
|
||||||
|
|
||||||
if HTOP_OPENBSD
|
if HTOP_OPENBSD
|
||||||
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
||||||
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = openbsd/Platform.h openbsd/OpenBSDProcessList.h \
|
myhtopplatheaders = $(openbsd_platform_headers)
|
||||||
openbsd/OpenBSDProcess.h openbsd/OpenBSDCRT.h openbsd/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Darwin
|
||||||
|
# ------
|
||||||
|
|
||||||
|
darwin_platform_headers = \
|
||||||
|
darwin/Platform.h \
|
||||||
|
darwin/DarwinProcess.h \
|
||||||
|
darwin/DarwinProcessList.h \
|
||||||
|
darwin/DarwinCRT.h \
|
||||||
|
darwin/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(darwin_platform_headers)
|
||||||
|
|
||||||
if HTOP_DARWIN
|
if HTOP_DARWIN
|
||||||
htop_LDFLAGS += -framework IOKit -framework CoreFoundation
|
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||||
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
||||||
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = darwin/Platform.h darwin/DarwinProcess.h \
|
myhtopplatheaders = $(darwin_platform_headers)
|
||||||
darwin/DarwinProcessList.h darwin/DarwinCRT.h darwin/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Solaris
|
||||||
|
# -------
|
||||||
|
|
||||||
|
solaris_platform_headers = \
|
||||||
|
solaris/Platform.h \
|
||||||
|
solaris/SolarisProcess.h \
|
||||||
|
solaris/SolarisProcessList.h \
|
||||||
|
solaris/SolarisCRT.h \
|
||||||
|
solaris/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(solaris_platform_headers)
|
||||||
|
|
||||||
|
if HTOP_SOLARIS
|
||||||
|
myhtopplatsources = solaris/Platform.c \
|
||||||
|
solaris/SolarisProcess.c solaris/SolarisProcessList.c \
|
||||||
|
solaris/SolarisCRT.c solaris/Battery.c
|
||||||
|
|
||||||
|
myhtopplatheaders = $(solaris_platform_headers)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Unsupported
|
||||||
|
# -----------
|
||||||
|
|
||||||
|
unsupported_platform_headers = \
|
||||||
|
unsupported/Platform.h \
|
||||||
|
unsupported/UnsupportedProcess.h \
|
||||||
|
unsupported/UnsupportedProcessList.h \
|
||||||
|
unsupported/UnsupportedCRT.h \
|
||||||
|
unsupported/Battery.h
|
||||||
|
|
||||||
|
all_platform_headers += $(unsupported_platform_headers)
|
||||||
|
|
||||||
if HTOP_UNSUPPORTED
|
if HTOP_UNSUPPORTED
|
||||||
myhtopplatsources = unsupported/Platform.c \
|
myhtopplatsources = unsupported/Platform.c \
|
||||||
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
||||||
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = unsupported/Platform.h \
|
myhtopplatheaders = $(unsupported_platform_headers)
|
||||||
unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \
|
|
||||||
unsupported/UnsupportedCRT.h unsupported/Battery.h
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# ----
|
||||||
|
|
||||||
SUFFIXES = .h
|
SUFFIXES = .h
|
||||||
|
|
||||||
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
||||||
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
||||||
|
|
||||||
|
.PHONY: htop-headers clean-htop-headers
|
||||||
|
|
||||||
|
htop-headers: $(myhtopheaders) $(all_platform_headers)
|
||||||
|
|
||||||
|
clean-htop-headers:
|
||||||
|
-rm -f $(myhtopheaders) $(all_platform_headers)
|
||||||
|
|
||||||
target:
|
target:
|
||||||
echo $(htop_SOURCES)
|
echo $(htop_SOURCES)
|
||||||
|
|
||||||
@ -103,6 +203,9 @@ profile:
|
|||||||
debug:
|
debug:
|
||||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG"
|
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG"
|
||||||
|
|
||||||
|
symbols:
|
||||||
|
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DNDEBUG"
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov"
|
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov"
|
||||||
|
|
||||||
@ -112,6 +215,13 @@ coverage:
|
|||||||
cppcheck:
|
cppcheck:
|
||||||
cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS
|
cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS
|
||||||
|
|
||||||
|
dist-hook: $(top_distdir)/configure
|
||||||
|
@if grep 'pkg_m4_absent' '$(top_distdir)/configure'; then \
|
||||||
|
echo 'configure is generated without pkg.m4. Please supply pkg.m4 and run ./autogen.sh to rebuild the configure script.'>&2; \
|
||||||
|
(exit 1); \
|
||||||
|
else :; \
|
||||||
|
fi
|
||||||
|
|
||||||
.PHONY: lcov
|
.PHONY: lcov
|
||||||
|
|
||||||
lcov:
|
lcov:
|
||||||
|
@ -76,16 +76,35 @@ void OpenFilesScreen_draw(InfoScreen* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||||
char command[1025];
|
char buffer[1025];
|
||||||
xSnprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
xSnprintf(buffer, 1024, "%d", pid);
|
||||||
FILE* fd = popen(command, "r");
|
|
||||||
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
||||||
OpenFiles_FileData* fdata = NULL;
|
OpenFiles_FileData* fdata = NULL;
|
||||||
OpenFiles_Data* item = &(pdata->data);
|
OpenFiles_Data* item = &(pdata->data);
|
||||||
if (!fd) {
|
int fdpair[2];
|
||||||
pdata->error = 127;
|
if (pipe(fdpair) == -1) {
|
||||||
|
pdata->error = 1;
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
|
pid_t child = fork();
|
||||||
|
if (child == -1) {
|
||||||
|
pdata->error = 1;
|
||||||
|
return pdata;
|
||||||
|
}
|
||||||
|
if (child == 0) {
|
||||||
|
close(fdpair[0]);
|
||||||
|
dup2(fdpair[1], STDOUT_FILENO);
|
||||||
|
close(fdpair[1]);
|
||||||
|
int fdnull = open("/dev/null", O_WRONLY);
|
||||||
|
if (fdnull < 0)
|
||||||
|
exit(1);
|
||||||
|
dup2(fdnull, STDERR_FILENO);
|
||||||
|
close(fdnull);
|
||||||
|
execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL);
|
||||||
|
exit(127);
|
||||||
|
}
|
||||||
|
close(fdpair[1]);
|
||||||
|
FILE* fd = fdopen(fdpair[0], "r");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char* line = String_readLine(fd);
|
char* line = String_readLine(fd);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
@ -105,7 +124,15 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
|||||||
item->data[cmd] = xStrdup(line + 1);
|
item->data[cmd] = xStrdup(line + 1);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
pdata->error = pclose(fd);
|
int wstatus;
|
||||||
|
if (waitpid(child, &wstatus, 0) == -1) {
|
||||||
|
pdata->error = 1;
|
||||||
|
return pdata;
|
||||||
|
}
|
||||||
|
if (!WIFEXITED(wstatus))
|
||||||
|
pdata->error = 1;
|
||||||
|
else
|
||||||
|
pdata->error = WEXITSTATUS(wstatus);
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
Panel.c
28
Panel.c
@ -40,8 +40,12 @@ typedef enum HandlerResult_ {
|
|||||||
#define EVENT_SET_SELECTED -1
|
#define EVENT_SET_SELECTED -1
|
||||||
|
|
||||||
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
||||||
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000)
|
|
||||||
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
||||||
|
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ < -9000)
|
||||||
|
|
||||||
|
#define EVENT_SCREEN_TAB_CLICK(x_) (-20000 + x_)
|
||||||
|
#define EVENT_SCREEN_TAB_GET_X(ev_) (ev_ + 20000)
|
||||||
|
#define EVENT_IS_SCREEN_TAB_CLICK(ev_) (ev_ >= -20000 && ev_ < -10000)
|
||||||
|
|
||||||
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
||||||
|
|
||||||
@ -57,6 +61,7 @@ typedef struct PanelClass_ {
|
|||||||
struct Panel_ {
|
struct Panel_ {
|
||||||
Object super;
|
Object super;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
|
int cursorX, cursorY;
|
||||||
WINDOW* window;
|
WINDOW* window;
|
||||||
Vector* items;
|
Vector* items;
|
||||||
int selected;
|
int selected;
|
||||||
@ -66,6 +71,7 @@ struct Panel_ {
|
|||||||
int scrollV;
|
int scrollV;
|
||||||
short scrollH;
|
short scrollH;
|
||||||
bool needsRedraw;
|
bool needsRedraw;
|
||||||
|
bool cursorOn;
|
||||||
FunctionBar* currentBar;
|
FunctionBar* currentBar;
|
||||||
FunctionBar* defaultBar;
|
FunctionBar* defaultBar;
|
||||||
RichString header;
|
RichString header;
|
||||||
@ -85,6 +91,11 @@ struct Panel_ {
|
|||||||
|
|
||||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||||
|
|
||||||
|
void Panel_setCursorToSelection(Panel* this) {
|
||||||
|
this->cursorY = this->y + this->selected - this->scrollV + 1;
|
||||||
|
this->cursorX = this->x + this->selectedLen - this->scrollH;
|
||||||
|
}
|
||||||
|
|
||||||
PanelClass Panel_class = {
|
PanelClass Panel_class = {
|
||||||
.super = {
|
.super = {
|
||||||
.extends = Class(Object),
|
.extends = Class(Object),
|
||||||
@ -112,6 +123,8 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
|
|||||||
this->y = y;
|
this->y = y;
|
||||||
this->w = w;
|
this->w = w;
|
||||||
this->h = h;
|
this->h = h;
|
||||||
|
this->cursorX = 0;
|
||||||
|
this->cursorY = 0;
|
||||||
this->eventHandlerState = NULL;
|
this->eventHandlerState = NULL;
|
||||||
this->items = Vector_new(type, owner, DEFAULT_SIZE);
|
this->items = Vector_new(type, owner, DEFAULT_SIZE);
|
||||||
this->scrollV = 0;
|
this->scrollV = 0;
|
||||||
@ -367,7 +380,6 @@ void Panel_draw(Panel* this, bool focus) {
|
|||||||
RichString_end(old);
|
RichString_end(old);
|
||||||
}
|
}
|
||||||
this->oldSelected = this->selected;
|
this->oldSelected = this->selected;
|
||||||
move(0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Panel_onKey(Panel* this, int key) {
|
bool Panel_onKey(Panel* this, int key) {
|
||||||
@ -499,3 +511,15 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
|||||||
}
|
}
|
||||||
return IGNORED;
|
return IGNORED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Panel_getCh(Panel* this) {
|
||||||
|
if (this->cursorOn) {
|
||||||
|
move(this->cursorY, this->cursorX);
|
||||||
|
curs_set(1);
|
||||||
|
} else {
|
||||||
|
curs_set(0);
|
||||||
|
}
|
||||||
|
set_escdelay(25);
|
||||||
|
return getch();
|
||||||
|
}
|
||||||
|
|
||||||
|
13
Panel.h
13
Panel.h
@ -29,8 +29,12 @@ typedef enum HandlerResult_ {
|
|||||||
#define EVENT_SET_SELECTED -1
|
#define EVENT_SET_SELECTED -1
|
||||||
|
|
||||||
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
||||||
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000)
|
|
||||||
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
||||||
|
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ < -9000)
|
||||||
|
|
||||||
|
#define EVENT_SCREEN_TAB_CLICK(x_) (-20000 + x_)
|
||||||
|
#define EVENT_SCREEN_TAB_GET_X(ev_) (ev_ + 20000)
|
||||||
|
#define EVENT_IS_SCREEN_TAB_CLICK(ev_) (ev_ >= -20000 && ev_ < -10000)
|
||||||
|
|
||||||
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
||||||
|
|
||||||
@ -46,6 +50,7 @@ typedef struct PanelClass_ {
|
|||||||
struct Panel_ {
|
struct Panel_ {
|
||||||
Object super;
|
Object super;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
|
int cursorX, cursorY;
|
||||||
WINDOW* window;
|
WINDOW* window;
|
||||||
Vector* items;
|
Vector* items;
|
||||||
int selected;
|
int selected;
|
||||||
@ -55,6 +60,7 @@ struct Panel_ {
|
|||||||
int scrollV;
|
int scrollV;
|
||||||
short scrollH;
|
short scrollH;
|
||||||
bool needsRedraw;
|
bool needsRedraw;
|
||||||
|
bool cursorOn;
|
||||||
FunctionBar* currentBar;
|
FunctionBar* currentBar;
|
||||||
FunctionBar* defaultBar;
|
FunctionBar* defaultBar;
|
||||||
RichString header;
|
RichString header;
|
||||||
@ -73,6 +79,8 @@ struct Panel_ {
|
|||||||
|
|
||||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||||
|
|
||||||
|
void Panel_setCursorToSelection(Panel* this);
|
||||||
|
|
||||||
extern PanelClass Panel_class;
|
extern PanelClass Panel_class;
|
||||||
|
|
||||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
||||||
@ -123,4 +131,7 @@ bool Panel_onKey(Panel* this, int key);
|
|||||||
|
|
||||||
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
||||||
|
|
||||||
|
int Panel_getCh(Panel* this);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
52
Process.c
52
Process.c
@ -51,6 +51,7 @@ in the source distribution for its full text.
|
|||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#define PROCESS_FLAG_IO 0x0001
|
#define PROCESS_FLAG_IO 0x0001
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ typedef struct ProcessFieldData_ {
|
|||||||
const char* name;
|
const char* name;
|
||||||
const char* title;
|
const char* title;
|
||||||
const char* description;
|
const char* description;
|
||||||
int flags;
|
uint64_t flags;
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
@ -178,6 +179,8 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||||
|
|
||||||
|
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
||||||
|
|
||||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||||
|
|
||||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||||
@ -368,6 +371,21 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Process_printPercentage(float val, char* buffer, int n, int* attr) {
|
||||||
|
if (val >= 0) {
|
||||||
|
if (val < 100) {
|
||||||
|
xSnprintf(buffer, n, "%4.1f ", val);
|
||||||
|
} else if (val < 1000) {
|
||||||
|
xSnprintf(buffer, n, "%3d. ", (unsigned int)val);
|
||||||
|
} else {
|
||||||
|
xSnprintf(buffer, n, "%4d ", (unsigned int)val);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*attr = CRT_colors[PROCESS_SHADOW];
|
||||||
|
xSnprintf(buffer, n, " N/A ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||||
char buffer[256]; buffer[255] = '\0';
|
char buffer[256]; buffer[255] = '\0';
|
||||||
int attr = CRT_colors[DEFAULT_COLOR];
|
int attr = CRT_colors[DEFAULT_COLOR];
|
||||||
@ -376,30 +394,15 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
bool coloring = this->settings->highlightMegabytes;
|
bool coloring = this->settings->highlightMegabytes;
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case PERCENT_CPU: {
|
case PERCENT_CPU: Process_printPercentage(this->percent_cpu, buffer, n, &attr); break;
|
||||||
if (this->percent_cpu > 999.9) {
|
case PERCENT_MEM: Process_printPercentage(this->percent_mem, buffer, n, &attr); break;
|
||||||
xSnprintf(buffer, n, "%4d ", (unsigned int)this->percent_cpu);
|
|
||||||
} else if (this->percent_cpu > 99.9) {
|
|
||||||
xSnprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu);
|
|
||||||
} else {
|
|
||||||
xSnprintf(buffer, n, "%4.1f ", this->percent_cpu);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PERCENT_MEM: {
|
|
||||||
if (this->percent_mem > 99.9) {
|
|
||||||
xSnprintf(buffer, n, "100. ");
|
|
||||||
} else {
|
|
||||||
xSnprintf(buffer, n, "%4.1f ", this->percent_mem);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COMM: {
|
case COMM: {
|
||||||
if (this->settings->highlightThreads && Process_isThread(this)) {
|
if (this->settings->highlightThreads && Process_isThread(this)) {
|
||||||
attr = CRT_colors[PROCESS_THREAD];
|
attr = CRT_colors[PROCESS_THREAD];
|
||||||
baseattr = CRT_colors[PROCESS_THREAD_BASENAME];
|
baseattr = CRT_colors[PROCESS_THREAD_BASENAME];
|
||||||
}
|
}
|
||||||
if (!this->settings->treeView || this->indent == 0) {
|
ScreenSettings* ss = this->settings->ss;
|
||||||
|
if (!ss->treeView || this->indent == 0) {
|
||||||
Process_writeCommand(this, attr, baseattr, str);
|
Process_writeCommand(this, attr, baseattr, str);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +423,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
buf += written;
|
buf += written;
|
||||||
n -= written;
|
n -= written;
|
||||||
}
|
}
|
||||||
const char* draw = CRT_treeStr[lastItem ? (this->settings->direction == 1 ? TREE_STR_BEND : TREE_STR_TEND) : TREE_STR_RTEE];
|
const char* draw = CRT_treeStr[lastItem ? (ss->direction == 1 ? TREE_STR_BEND : TREE_STR_TEND) : TREE_STR_RTEE];
|
||||||
xSnprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] );
|
xSnprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] );
|
||||||
RichString_append(str, CRT_colors[PROCESS_TREE], buffer);
|
RichString_append(str, CRT_colors[PROCESS_TREE], buffer);
|
||||||
Process_writeCommand(this, attr, baseattr, str);
|
Process_writeCommand(this, attr, baseattr, str);
|
||||||
@ -491,7 +494,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
|
|
||||||
void Process_display(Object* cast, RichString* out) {
|
void Process_display(Object* cast, RichString* out) {
|
||||||
Process* this = (Process*) cast;
|
Process* this = (Process*) cast;
|
||||||
ProcessField* fields = this->settings->fields;
|
ProcessField* fields = this->settings->ss->fields;
|
||||||
RichString_prune(out);
|
RichString_prune(out);
|
||||||
for (int i = 0; fields[i]; i++)
|
for (int i = 0; fields[i]; i++)
|
||||||
As_Process(this)->writeField(this, out, fields[i]);
|
As_Process(this)->writeField(this, out, fields[i]);
|
||||||
@ -561,14 +564,15 @@ long Process_pidCompare(const void* v1, const void* v2) {
|
|||||||
long Process_compare(const void* v1, const void* v2) {
|
long Process_compare(const void* v1, const void* v2) {
|
||||||
Process *p1, *p2;
|
Process *p1, *p2;
|
||||||
Settings *settings = ((Process*)v1)->settings;
|
Settings *settings = ((Process*)v1)->settings;
|
||||||
if (settings->direction == 1) {
|
ScreenSettings* ss = settings->ss;
|
||||||
|
if (ss->direction == 1) {
|
||||||
p1 = (Process*)v1;
|
p1 = (Process*)v1;
|
||||||
p2 = (Process*)v2;
|
p2 = (Process*)v2;
|
||||||
} else {
|
} else {
|
||||||
p2 = (Process*)v1;
|
p2 = (Process*)v1;
|
||||||
p1 = (Process*)v2;
|
p1 = (Process*)v2;
|
||||||
}
|
}
|
||||||
switch (settings->sortKey) {
|
switch (ss->sortKey) {
|
||||||
case PERCENT_CPU:
|
case PERCENT_CPU:
|
||||||
return (p2->percent_cpu > p1->percent_cpu ? 1 : -1);
|
return (p2->percent_cpu > p1->percent_cpu ? 1 : -1);
|
||||||
case PERCENT_MEM:
|
case PERCENT_MEM:
|
||||||
|
@ -29,6 +29,7 @@ in the source distribution for its full text.
|
|||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#define PROCESS_FLAG_IO 0x0001
|
#define PROCESS_FLAG_IO 0x0001
|
||||||
|
|
||||||
@ -134,7 +135,7 @@ typedef struct ProcessFieldData_ {
|
|||||||
const char* name;
|
const char* name;
|
||||||
const char* title;
|
const char* title;
|
||||||
const char* description;
|
const char* description;
|
||||||
int flags;
|
uint64_t flags;
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
@ -156,6 +157,8 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||||
|
|
||||||
|
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
||||||
|
|
||||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||||
|
|
||||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||||
@ -181,6 +184,8 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
|||||||
|
|
||||||
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
||||||
|
|
||||||
|
void Process_printPercentage(float val, char* buffer, int n, int* attr);
|
||||||
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
|
|
||||||
void Process_display(Object* cast, RichString* out);
|
void Process_display(Object* cast, RichString* out);
|
||||||
|
@ -124,14 +124,15 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
|
|||||||
|
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
||||||
RichString_prune(header);
|
RichString_prune(header);
|
||||||
ProcessField* fields = this->settings->fields;
|
ProcessField* fields = this->settings->ss->fields;
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
const char* field = Process_fields[fields[i]].title;
|
unsigned int key = fields[i];
|
||||||
|
const char* field = Process_fields[key].title;
|
||||||
if (!field) field = "- ";
|
if (!field) field = "- ";
|
||||||
if (!this->settings->treeView && this->settings->sortKey == fields[i])
|
int color = (!this->settings->ss->treeView && this->settings->ss->sortKey == key)
|
||||||
RichString_append(header, CRT_colors[PANEL_SELECTION_FOCUS], field);
|
? CRT_colors[PANEL_SELECTION_FOCUS]
|
||||||
else
|
: CRT_colors[PANEL_HEADER_FOCUS];
|
||||||
RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field);
|
RichString_append(header, color, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,19 +201,19 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_sort(ProcessList* this) {
|
void ProcessList_sort(ProcessList* this) {
|
||||||
if (!this->settings->treeView) {
|
if (!this->settings->ss->treeView) {
|
||||||
Vector_insertionSort(this->processes);
|
Vector_insertionSort(this->processes);
|
||||||
} else {
|
} else {
|
||||||
// Save settings
|
// Save settings
|
||||||
int direction = this->settings->direction;
|
int direction = this->settings->ss->direction;
|
||||||
int sortKey = this->settings->sortKey;
|
int sortKey = this->settings->ss->sortKey;
|
||||||
// Sort by PID
|
// Sort by PID
|
||||||
this->settings->sortKey = PID;
|
this->settings->ss->sortKey = PID;
|
||||||
this->settings->direction = 1;
|
this->settings->ss->direction = 1;
|
||||||
Vector_quickSort(this->processes);
|
Vector_quickSort(this->processes);
|
||||||
// Restore settings
|
// Restore settings
|
||||||
this->settings->sortKey = sortKey;
|
this->settings->ss->sortKey = sortKey;
|
||||||
this->settings->direction = direction;
|
this->settings->ss->direction = direction;
|
||||||
int vsize = Vector_size(this->processes);
|
int vsize = Vector_size(this->processes);
|
||||||
// Find all processes whose parent is not visible
|
// Find all processes whose parent is not visible
|
||||||
int size;
|
int size;
|
||||||
@ -228,7 +229,7 @@ void ProcessList_sort(ProcessList* this) {
|
|||||||
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pid_t ppid = process->tgid == process->pid ? process->ppid : process->tgid;
|
pid_t ppid = Process_getParentPid(process);
|
||||||
// Bisect the process vector to find parent
|
// Bisect the process vector to find parent
|
||||||
int l = 0, r = size;
|
int l = 0, r = size;
|
||||||
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
||||||
@ -271,7 +272,7 @@ void ProcessList_sort(ProcessList* this) {
|
|||||||
|
|
||||||
ProcessField ProcessList_keyAt(ProcessList* this, int at) {
|
ProcessField ProcessList_keyAt(ProcessList* this, int at) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
ProcessField* fields = this->settings->fields;
|
ProcessField* fields = this->settings->ss->fields;
|
||||||
ProcessField field;
|
ProcessField field;
|
||||||
for (int i = 0; (field = fields[i]); i++) {
|
for (int i = 0; (field = fields[i]); i++) {
|
||||||
const char* title = Process_fields[field].title;
|
const char* title = Process_fields[field].title;
|
||||||
|
@ -13,6 +13,7 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ typedef struct ScreenManager_ {
|
|||||||
int y2;
|
int y2;
|
||||||
Orientation orientation;
|
Orientation orientation;
|
||||||
Vector* panels;
|
Vector* panels;
|
||||||
|
const char* name;
|
||||||
int panelCount;
|
int panelCount;
|
||||||
const Header* header;
|
const Header* header;
|
||||||
const Settings* settings;
|
const Settings* settings;
|
||||||
@ -71,30 +73,46 @@ inline int ScreenManager_size(ScreenManager* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
||||||
|
ScreenManager_insert(this, item, size, Vector_size(this->panels));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenManager_insert(ScreenManager* this, Panel* item, int size, int idx) {
|
||||||
if (this->orientation == HORIZONTAL) {
|
if (this->orientation == HORIZONTAL) {
|
||||||
int lastX = 0;
|
int lastX = 0;
|
||||||
if (this->panelCount > 0) {
|
if (idx > 0) {
|
||||||
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1);
|
Panel* last = (Panel*) Vector_get(this->panels, idx - 1);
|
||||||
lastX = last->x + last->w + 1;
|
lastX = last->x + last->w + 1;
|
||||||
}
|
}
|
||||||
int height = LINES - this->y1 + this->y2;
|
int height = LINES - this->y1 + this->y2;
|
||||||
if (size > 0) {
|
if (size <= 0) {
|
||||||
Panel_resize(item, size, height);
|
size = COLS-this->x1+this->x2-lastX;
|
||||||
} else {
|
|
||||||
Panel_resize(item, COLS-this->x1+this->x2-lastX, height);
|
|
||||||
}
|
}
|
||||||
|
Panel_resize(item, size, height);
|
||||||
Panel_move(item, lastX, this->y1);
|
Panel_move(item, lastX, this->y1);
|
||||||
|
if (idx < this->panelCount) {
|
||||||
|
for (int i = idx + 1; i <= this->panelCount; i++) {
|
||||||
|
Panel* p = (Panel*) Vector_get(this->panels, i);
|
||||||
|
Panel_move(p, p->x + size, p->y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: VERTICAL
|
// TODO: VERTICAL
|
||||||
Vector_add(this->panels, item);
|
Vector_insert(this->panels, idx, item);
|
||||||
item->needsRedraw = true;
|
item->needsRedraw = true;
|
||||||
this->panelCount++;
|
this->panelCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Panel* ScreenManager_remove(ScreenManager* this, int idx) {
|
Panel* ScreenManager_remove(ScreenManager* this, int idx) {
|
||||||
assert(this->panelCount > idx);
|
assert(this->panelCount > idx);
|
||||||
|
int w = ((Panel*) Vector_get(this->panels, idx))->w;
|
||||||
Panel* panel = (Panel*) Vector_remove(this->panels, idx);
|
Panel* panel = (Panel*) Vector_remove(this->panels, idx);
|
||||||
this->panelCount--;
|
this->panelCount--;
|
||||||
|
if (idx < this->panelCount) {
|
||||||
|
for (int i = idx; i < this->panelCount; i++) {
|
||||||
|
Panel* p = (Panel*) Vector_get(this->panels, i);
|
||||||
|
Panel_move(p, p->x - w, p->y);
|
||||||
|
}
|
||||||
|
}
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +149,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
|
|||||||
if (*rescan) {
|
if (*rescan) {
|
||||||
*oldTime = newTime;
|
*oldTime = newTime;
|
||||||
ProcessList_scan(pl);
|
ProcessList_scan(pl);
|
||||||
if (*sortTimeout == 0 || this->settings->treeView) {
|
if (*sortTimeout == 0 || this->settings->ss->treeView) {
|
||||||
ProcessList_sort(pl);
|
ProcessList_sort(pl);
|
||||||
*sortTimeout = 1;
|
*sortTimeout = 1;
|
||||||
}
|
}
|
||||||
@ -144,7 +162,50 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
|
|||||||
*rescan = false;
|
*rescan = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool drawTab(int* y, int* x, int l, const char* name, bool cur) {
|
||||||
|
attrset(CRT_colors[cur ? SCREENS_CUR_BORDER : SCREENS_OTH_BORDER]);
|
||||||
|
mvaddch(*y, *x, '[');
|
||||||
|
(*x)++;
|
||||||
|
if (*x >= l) return false;
|
||||||
|
int nameLen = strlen(name);
|
||||||
|
int n = MIN(l - *x, nameLen);
|
||||||
|
attrset(CRT_colors[cur ? SCREENS_CUR_TEXT : SCREENS_OTH_TEXT]);
|
||||||
|
mvaddnstr(*y, *x, name, n);
|
||||||
|
*x += n;
|
||||||
|
if (*x >= l) return false;
|
||||||
|
attrset(CRT_colors[cur ? SCREENS_CUR_BORDER : SCREENS_OTH_BORDER]);
|
||||||
|
mvaddch(*y, *x, ']');
|
||||||
|
*x += 2;
|
||||||
|
if (*x >= l) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ScreenManager_drawScreenTabs(ScreenManager* this) {
|
||||||
|
ScreenSettings** screens = this->settings->screens;
|
||||||
|
int cur = this->settings->ssIndex;
|
||||||
|
int l = COLS;
|
||||||
|
Panel* panel = (Panel*) Vector_get(this->panels, 0);
|
||||||
|
int y = panel->y - 1;
|
||||||
|
int x = 2;
|
||||||
|
|
||||||
|
if (this->name) {
|
||||||
|
drawTab(&y, &x, l, this->name, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int s = 0; screens[s]; s++) {
|
||||||
|
bool ok = drawTab(&y, &x, l, screens[s]->name, s == cur);
|
||||||
|
if (!ok) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrset(CRT_colors[RESET_COLOR]);
|
||||||
|
}
|
||||||
|
|
||||||
static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
||||||
|
if (this->settings->screenTabs) {
|
||||||
|
ScreenManager_drawScreenTabs(this);
|
||||||
|
}
|
||||||
int nPanels = this->panelCount;
|
int nPanels = this->panelCount;
|
||||||
for (int i = 0; i < nPanels; i++) {
|
for (int i = 0; i < nPanels; i++) {
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||||
@ -157,16 +218,17 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Panel* setCurrentPanel(Panel* panel) {
|
static Panel* setCurrentPanel(ScreenManager* this, int focus) {
|
||||||
|
Panel* panel = (Panel*) Vector_get(this->panels, focus);
|
||||||
FunctionBar_draw(panel->currentBar, NULL);
|
FunctionBar_draw(panel->currentBar, NULL);
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, char* name) {
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
int focus = 0;
|
int focus = 0;
|
||||||
|
|
||||||
Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
Panel* panelFocus = setCurrentPanel(this, focus);
|
||||||
|
|
||||||
double oldTime = 0.0;
|
double oldTime = 0.0;
|
||||||
|
|
||||||
@ -178,6 +240,8 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
bool rescan = false;
|
bool rescan = false;
|
||||||
int sortTimeout = 0;
|
int sortTimeout = 0;
|
||||||
int resetSortTimeout = 5;
|
int resetSortTimeout = 5;
|
||||||
|
|
||||||
|
this->name = name;
|
||||||
|
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
if (this->header) {
|
if (this->header) {
|
||||||
@ -189,8 +253,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int prevCh = ch;
|
int prevCh = ch;
|
||||||
set_escdelay(25);
|
ch = Panel_getCh(panelFocus);
|
||||||
ch = getch();
|
|
||||||
|
|
||||||
HandlerResult result = IGNORED;
|
HandlerResult result = IGNORED;
|
||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE) {
|
||||||
@ -208,11 +271,14 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
if (mevent.y == panel->y) {
|
if (mevent.y == panel->y) {
|
||||||
ch = EVENT_HEADER_CLICK(mevent.x - panel->x);
|
ch = EVENT_HEADER_CLICK(mevent.x - panel->x);
|
||||||
break;
|
break;
|
||||||
|
} else if (this->settings->screenTabs && mevent.y == panel->y - 1) {
|
||||||
|
ch = EVENT_SCREEN_TAB_CLICK(mevent.x);
|
||||||
|
break;
|
||||||
} else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) {
|
} else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) {
|
||||||
ch = KEY_MOUSE;
|
ch = KEY_MOUSE;
|
||||||
if (panel == panelFocus || this->allowFocusChange) {
|
if (panel == panelFocus || this->allowFocusChange) {
|
||||||
focus = i;
|
focus = i;
|
||||||
panelFocus = setCurrentPanel(panel);
|
panelFocus = setCurrentPanel(this, i);
|
||||||
Object* oldSelection = Panel_getSelected(panel);
|
Object* oldSelection = Panel_getSelected(panel);
|
||||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||||
if (Panel_getSelected(panel) == oldSelection) {
|
if (Panel_getSelected(panel) == oldSelection) {
|
||||||
@ -288,7 +354,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
tryLeft:
|
tryLeft:
|
||||||
if (focus > 0)
|
if (focus > 0)
|
||||||
focus--;
|
focus--;
|
||||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
panelFocus = setCurrentPanel(this, focus);
|
||||||
if (Panel_size(panelFocus) == 0 && focus > 0)
|
if (Panel_size(panelFocus) == 0 && focus > 0)
|
||||||
goto tryLeft;
|
goto tryLeft;
|
||||||
break;
|
break;
|
||||||
@ -303,7 +369,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||||||
tryRight:
|
tryRight:
|
||||||
if (focus < this->panelCount - 1)
|
if (focus < this->panelCount - 1)
|
||||||
focus++;
|
focus++;
|
||||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
panelFocus = setCurrentPanel(this, focus);
|
||||||
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
|
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
|
||||||
goto tryRight;
|
goto tryRight;
|
||||||
break;
|
break;
|
||||||
|
@ -27,6 +27,7 @@ typedef struct ScreenManager_ {
|
|||||||
int y2;
|
int y2;
|
||||||
Orientation orientation;
|
Orientation orientation;
|
||||||
Vector* panels;
|
Vector* panels;
|
||||||
|
const char* name;
|
||||||
int panelCount;
|
int panelCount;
|
||||||
const Header* header;
|
const Header* header;
|
||||||
const Settings* settings;
|
const Settings* settings;
|
||||||
@ -43,10 +44,12 @@ extern int ScreenManager_size(ScreenManager* this);
|
|||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
||||||
|
|
||||||
|
void ScreenManager_insert(ScreenManager* this, Panel* item, int size, int idx);
|
||||||
|
|
||||||
Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
||||||
|
|
||||||
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, char* name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
331
ScreensPanel.c
Normal file
331
ScreensPanel.c
Normal file
@ -0,0 +1,331 @@
|
|||||||
|
/*
|
||||||
|
htop - ScreensPanel.c
|
||||||
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ScreensPanel.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
#include "StringUtils.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*{
|
||||||
|
#include "Panel.h"
|
||||||
|
#include "ScreenManager.h"
|
||||||
|
#include "ColumnsPanel.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "ListItem.h"
|
||||||
|
|
||||||
|
#ifndef SCREEN_NAME_LEN
|
||||||
|
#define SCREEN_NAME_LEN 20
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct ScreensPanel_ {
|
||||||
|
Panel super;
|
||||||
|
|
||||||
|
ScreenManager* scr;
|
||||||
|
Settings* settings;
|
||||||
|
ColumnsPanel* columns;
|
||||||
|
char buffer[SCREEN_NAME_LEN + 1];
|
||||||
|
char* saved;
|
||||||
|
int cursor;
|
||||||
|
bool moving;
|
||||||
|
bool renaming;
|
||||||
|
} ScreensPanel;
|
||||||
|
|
||||||
|
typedef struct ScreenListItem_ {
|
||||||
|
ListItem super;
|
||||||
|
ScreenSettings* ss;
|
||||||
|
} ScreenListItem;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
ObjectClass ScreenListItem_class = {
|
||||||
|
.extends = Class(ListItem),
|
||||||
|
.display = ListItem_display,
|
||||||
|
.delete = ListItem_delete,
|
||||||
|
.compare = ListItem_compare
|
||||||
|
};
|
||||||
|
|
||||||
|
ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss) {
|
||||||
|
ScreenListItem* this = AllocThis(ScreenListItem);
|
||||||
|
ListItem_init((ListItem*)this, value, 0);
|
||||||
|
this->ss = ss;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* const ScreensFunctions[] = {" ", "Rename", " ", " ", "New ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||||
|
|
||||||
|
static void ScreensPanel_delete(Object* object) {
|
||||||
|
Panel* super = (Panel*) object;
|
||||||
|
ScreensPanel* this = (ScreensPanel*) object;
|
||||||
|
Panel_done(super);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HandlerResult ScreensPanel_eventHandlerRenaming(Panel* super, int ch) {
|
||||||
|
ScreensPanel* const this = (ScreensPanel*) super;
|
||||||
|
|
||||||
|
//ListItem* item = (ListItem*)Panel_getSelected(super);
|
||||||
|
if (ch >= 32 && ch < 127 && ch != 61 && ch != 22) {
|
||||||
|
if (this->cursor < SCREEN_NAME_LEN - 1) {
|
||||||
|
this->buffer[this->cursor] = ch;
|
||||||
|
this->cursor++;
|
||||||
|
super->selectedLen = strlen(this->buffer);
|
||||||
|
Panel_setCursorToSelection(super);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch(ch) {
|
||||||
|
case 127:
|
||||||
|
case KEY_BACKSPACE:
|
||||||
|
{
|
||||||
|
if (this->cursor > 0) {
|
||||||
|
this->cursor--;
|
||||||
|
this->buffer[this->cursor] = '\0';
|
||||||
|
super->selectedLen = strlen(this->buffer);
|
||||||
|
Panel_setCursorToSelection(super);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0x0a:
|
||||||
|
case 0x0d:
|
||||||
|
case KEY_ENTER:
|
||||||
|
{
|
||||||
|
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||||
|
free(this->saved);
|
||||||
|
item->value = xStrdup(this->buffer);
|
||||||
|
this->renaming = false;
|
||||||
|
super->cursorOn = false;
|
||||||
|
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||||
|
ScreensPanel_update(super);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 27: // Esc
|
||||||
|
{
|
||||||
|
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||||
|
item->value = this->saved;
|
||||||
|
this->renaming = false;
|
||||||
|
super->cursorOn = false;
|
||||||
|
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void startRenaming(Panel* super) {
|
||||||
|
ScreensPanel* const this = (ScreensPanel*) super;
|
||||||
|
|
||||||
|
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||||
|
this->renaming = true;
|
||||||
|
super->cursorOn = true;
|
||||||
|
char* name = item->value;
|
||||||
|
this->saved = name;
|
||||||
|
strncpy(this->buffer, name, SCREEN_NAME_LEN);
|
||||||
|
this->buffer[SCREEN_NAME_LEN] = '\0';
|
||||||
|
this->cursor = strlen(this->buffer);
|
||||||
|
item->value = this->buffer;
|
||||||
|
Panel_setSelectionColor(super, CRT_colors[PANEL_EDIT]);
|
||||||
|
super->selectedLen = strlen(this->buffer);
|
||||||
|
Panel_setCursorToSelection(super);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rebuildSettingsArray(Panel* super) {
|
||||||
|
ScreensPanel* const this = (ScreensPanel*) super;
|
||||||
|
|
||||||
|
int n = Panel_size(super);
|
||||||
|
free(this->settings->screens);
|
||||||
|
this->settings->screens = xMalloc(sizeof(ScreenSettings*) * (n + 1));
|
||||||
|
this->settings->screens[n] = NULL;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
ScreenListItem* item = (ScreenListItem*) Panel_get(super, i);
|
||||||
|
this->settings->screens[i] = item->ss;
|
||||||
|
}
|
||||||
|
this->settings->nScreens = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addNewScreen(Panel* super) {
|
||||||
|
ScreensPanel* const this = (ScreensPanel*) super;
|
||||||
|
|
||||||
|
char* name = "New";
|
||||||
|
ScreenSettings* ss = Settings_newScreen(this->settings, name, "PID Command");
|
||||||
|
ScreenListItem* item = ScreenListItem_new(name, ss);
|
||||||
|
int idx = Panel_getSelectedIndex(super);
|
||||||
|
Panel_insert(super, idx + 1, (Object*) item);
|
||||||
|
Panel_setSelected(super, idx + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
|
||||||
|
ScreensPanel* const this = (ScreensPanel*) super;
|
||||||
|
|
||||||
|
int selected = Panel_getSelectedIndex(super);
|
||||||
|
ScreenListItem* oldFocus = (ScreenListItem*) Panel_getSelected(super);
|
||||||
|
bool shouldRebuildArray = false;
|
||||||
|
HandlerResult result = IGNORED;
|
||||||
|
switch(ch) {
|
||||||
|
case 0x0a:
|
||||||
|
case 0x0d:
|
||||||
|
case KEY_ENTER:
|
||||||
|
case KEY_MOUSE:
|
||||||
|
case KEY_RECLICK:
|
||||||
|
{
|
||||||
|
this->moving = !(this->moving);
|
||||||
|
Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||||
|
((ListItem*)Panel_getSelected(super))->moving = this->moving;
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EVENT_SET_SELECTED:
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
case KEY_NPAGE:
|
||||||
|
case KEY_PPAGE:
|
||||||
|
case KEY_HOME:
|
||||||
|
case KEY_END: {
|
||||||
|
Panel_onKey(super, ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KEY_F(2):
|
||||||
|
case KEY_CTRL('R'):
|
||||||
|
{
|
||||||
|
startRenaming(super);
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KEY_F(5):
|
||||||
|
case KEY_CTRL('N'):
|
||||||
|
{
|
||||||
|
addNewScreen(super);
|
||||||
|
startRenaming(super);
|
||||||
|
shouldRebuildArray = true;
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KEY_UP:
|
||||||
|
{
|
||||||
|
if (!this->moving) {
|
||||||
|
Panel_onKey(super, ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* else fallthrough */
|
||||||
|
}
|
||||||
|
case KEY_F(7):
|
||||||
|
case '[':
|
||||||
|
case '-':
|
||||||
|
{
|
||||||
|
Panel_moveSelectedUp(super);
|
||||||
|
shouldRebuildArray = true;
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KEY_DOWN:
|
||||||
|
{
|
||||||
|
if (!this->moving) {
|
||||||
|
Panel_onKey(super, ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* else fallthrough */
|
||||||
|
}
|
||||||
|
case KEY_F(8):
|
||||||
|
case ']':
|
||||||
|
case '+':
|
||||||
|
{
|
||||||
|
Panel_moveSelectedDown(super);
|
||||||
|
shouldRebuildArray = true;
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KEY_F(9):
|
||||||
|
//case KEY_DC:
|
||||||
|
{
|
||||||
|
if (Panel_size(super) > 1) {
|
||||||
|
Panel_remove(super, selected);
|
||||||
|
}
|
||||||
|
shouldRebuildArray = true;
|
||||||
|
result = HANDLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (ch < 255 && isalpha(ch))
|
||||||
|
result = Panel_selectByTyping(super, ch);
|
||||||
|
if (result == BREAK_LOOP)
|
||||||
|
result = IGNORED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ScreenListItem* newFocus = (ScreenListItem*) Panel_getSelected(super);
|
||||||
|
if (oldFocus != newFocus) {
|
||||||
|
ColumnsPanel_fill(this->columns, newFocus->ss);
|
||||||
|
result = HANDLED;
|
||||||
|
}
|
||||||
|
if (shouldRebuildArray) {
|
||||||
|
rebuildSettingsArray(super);
|
||||||
|
}
|
||||||
|
if (result == HANDLED)
|
||||||
|
ScreensPanel_update(super);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HandlerResult ScreensPanel_eventHandler(Panel* super, int ch) {
|
||||||
|
ScreensPanel* const this = (ScreensPanel*) super;
|
||||||
|
|
||||||
|
if (this->renaming) {
|
||||||
|
return ScreensPanel_eventHandlerRenaming(super, ch);
|
||||||
|
} else {
|
||||||
|
return ScreensPanel_eventHandlerNormal(super, ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PanelClass ScreensPanel_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Panel),
|
||||||
|
.delete = ScreensPanel_delete
|
||||||
|
},
|
||||||
|
.eventHandler = ScreensPanel_eventHandler
|
||||||
|
};
|
||||||
|
|
||||||
|
ScreensPanel* ScreensPanel_new(Settings* settings) {
|
||||||
|
ScreensPanel* this = AllocThis(ScreensPanel);
|
||||||
|
Panel* super = (Panel*) this;
|
||||||
|
FunctionBar* fuBar = FunctionBar_new(ScreensFunctions, NULL, NULL);
|
||||||
|
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||||
|
|
||||||
|
this->settings = settings;
|
||||||
|
this->columns = ColumnsPanel_new(settings->screens[0], &(settings->changed));
|
||||||
|
this->moving = false;
|
||||||
|
this->renaming = false;
|
||||||
|
super->cursorOn = false;
|
||||||
|
this->cursor = 0;
|
||||||
|
Panel_setHeader(super, "Screens");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < settings->nScreens; i++) {
|
||||||
|
ScreenSettings* ss = settings->screens[i];
|
||||||
|
char* name = ss->name;
|
||||||
|
Panel_add(super, (Object*) ScreenListItem_new(name, ss));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreensPanel_update(Panel* super) {
|
||||||
|
ScreensPanel* this = (ScreensPanel*) super;
|
||||||
|
int size = Panel_size(super);
|
||||||
|
this->settings->changed = true;
|
||||||
|
this->settings->screens = xRealloc(this->settings->screens, sizeof(char*) * (size+1));
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
ScreenListItem* item = (ScreenListItem*) Panel_get(super, i);
|
||||||
|
ScreenSettings* ss = item->ss;
|
||||||
|
free(ss->name);
|
||||||
|
this->settings->screens[i] = ss;
|
||||||
|
ss->name = xStrdup(((ListItem*) item)->value);
|
||||||
|
}
|
||||||
|
this->settings->screens[size] = NULL;
|
||||||
|
}
|
51
ScreensPanel.h
Normal file
51
ScreensPanel.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_ScreensPanel
|
||||||
|
#define HEADER_ScreensPanel
|
||||||
|
/*
|
||||||
|
htop - ScreensPanel.h
|
||||||
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Panel.h"
|
||||||
|
#include "ScreenManager.h"
|
||||||
|
#include "ColumnsPanel.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "ListItem.h"
|
||||||
|
|
||||||
|
#ifndef SCREEN_NAME_LEN
|
||||||
|
#define SCREEN_NAME_LEN 20
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct ScreensPanel_ {
|
||||||
|
Panel super;
|
||||||
|
|
||||||
|
ScreenManager* scr;
|
||||||
|
Settings* settings;
|
||||||
|
ColumnsPanel* columns;
|
||||||
|
char buffer[SCREEN_NAME_LEN + 1];
|
||||||
|
char* saved;
|
||||||
|
int cursor;
|
||||||
|
bool moving;
|
||||||
|
bool renaming;
|
||||||
|
} ScreensPanel;
|
||||||
|
|
||||||
|
typedef struct ScreenListItem_ {
|
||||||
|
ListItem super;
|
||||||
|
ScreenSettings* ss;
|
||||||
|
} ScreenListItem;
|
||||||
|
|
||||||
|
|
||||||
|
extern ObjectClass ScreenListItem_class;
|
||||||
|
|
||||||
|
ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss);
|
||||||
|
|
||||||
|
extern PanelClass ScreensPanel_class;
|
||||||
|
|
||||||
|
ScreensPanel* ScreensPanel_new(Settings* settings);
|
||||||
|
|
||||||
|
void ScreensPanel_update(Panel* super);
|
||||||
|
|
||||||
|
#endif
|
319
Settings.c
319
Settings.c
@ -23,29 +23,44 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* name;
|
||||||
|
const char* columns;
|
||||||
|
const char* sortKey;
|
||||||
|
} ScreenDefaults;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
char** names;
|
char** names;
|
||||||
int* modes;
|
int* modes;
|
||||||
} MeterColumnSettings;
|
} MeterColumnSettings;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* name;
|
||||||
|
ProcessField* fields;
|
||||||
|
int flags;
|
||||||
|
int direction;
|
||||||
|
ProcessField sortKey;
|
||||||
|
bool treeView;
|
||||||
|
} ScreenSettings;
|
||||||
|
|
||||||
typedef struct Settings_ {
|
typedef struct Settings_ {
|
||||||
char* filename;
|
char* filename;
|
||||||
|
|
||||||
MeterColumnSettings columns[2];
|
MeterColumnSettings meterColumns[2];
|
||||||
|
|
||||||
|
ScreenSettings** screens;
|
||||||
|
unsigned int nScreens;
|
||||||
|
unsigned int ssIndex;
|
||||||
|
ScreenSettings* ss;
|
||||||
|
|
||||||
ProcessField* fields;
|
|
||||||
int flags;
|
|
||||||
int colorScheme;
|
int colorScheme;
|
||||||
int delay;
|
int delay;
|
||||||
|
|
||||||
int cpuCount;
|
int cpuCount;
|
||||||
int direction;
|
|
||||||
ProcessField sortKey;
|
|
||||||
|
|
||||||
bool countCPUsFromZero;
|
bool countCPUsFromZero;
|
||||||
bool detailedCPUTime;
|
bool detailedCPUTime;
|
||||||
bool treeView;
|
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool hideThreads;
|
bool hideThreads;
|
||||||
bool shadowOtherUsers;
|
bool shadowOtherUsers;
|
||||||
@ -58,6 +73,7 @@ typedef struct Settings_ {
|
|||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
|
bool screenTabs;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
@ -68,25 +84,82 @@ typedef struct Settings_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
static void writeList(FILE* fd, char** list, int len) {
|
||||||
|
const char* sep = "";
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
fprintf(fd, "%s%s", sep, list[i]);
|
||||||
|
sep = " ";
|
||||||
|
}
|
||||||
|
fprintf(fd, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
static char** readQuotedList(char* line) {
|
||||||
|
int n = 0;
|
||||||
|
char** list = xCalloc(sizeof(char*), 1);
|
||||||
|
int start = 0;
|
||||||
|
for (;;) {
|
||||||
|
while (line[start] && line[start] == ' ') {
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
if (line[start] != '"') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
start++;
|
||||||
|
int close = start;
|
||||||
|
while (line[close] && line[close] != '"') {
|
||||||
|
close++;
|
||||||
|
}
|
||||||
|
int len = close - start;
|
||||||
|
char* item = xMalloc(len + 1);
|
||||||
|
strncpy(item, line + start, len);
|
||||||
|
item[len] = '\0';
|
||||||
|
list[n] = item;
|
||||||
|
n++;
|
||||||
|
list = xRealloc(list, sizeof(char*) * (n + 1));
|
||||||
|
start = close + 1;
|
||||||
|
}
|
||||||
|
list[n] = NULL;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void writeQuotedList(FILE* fd, char** list) {
|
||||||
|
const char* sep = "";
|
||||||
|
for (int i = 0; list[i]; i++) {
|
||||||
|
fprintf(fd, "%s\"%s\"", sep, list[i]);
|
||||||
|
sep = " ";
|
||||||
|
}
|
||||||
|
fprintf(fd, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
void Settings_delete(Settings* this) {
|
void Settings_delete(Settings* this) {
|
||||||
free(this->filename);
|
free(this->filename);
|
||||||
free(this->fields);
|
for (unsigned int i = 0; i < (sizeof(this->meterColumns)/sizeof(MeterColumnSettings)); i++) {
|
||||||
for (unsigned int i = 0; i < (sizeof(this->columns)/sizeof(MeterColumnSettings)); i++) {
|
String_freeArray(this->meterColumns[i].names);
|
||||||
String_freeArray(this->columns[i].names);
|
free(this->meterColumns[i].modes);
|
||||||
free(this->columns[i].modes);
|
}
|
||||||
|
if (this->screens) {
|
||||||
|
for (unsigned int i = 0; this->screens[i]; i++) {
|
||||||
|
free(this->screens[i]->name);
|
||||||
|
free(this->screens[i]->fields);
|
||||||
|
}
|
||||||
|
free(this->screens);
|
||||||
}
|
}
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_readMeters(Settings* this, char* line, int column) {
|
static void Settings_readMeters(Settings* this, char* line, int side) {
|
||||||
char* trim = String_trim(line);
|
char* trim = String_trim(line);
|
||||||
int nIds;
|
int nIds;
|
||||||
char** ids = String_split(trim, ' ', &nIds);
|
char** ids = String_split(trim, ' ', &nIds);
|
||||||
free(trim);
|
free(trim);
|
||||||
this->columns[column].names = ids;
|
this->meterColumns[side].names = ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_readMeterModes(Settings* this, char* line, int column) {
|
static void Settings_readMeterModes(Settings* this, char* line, int side) {
|
||||||
char* trim = String_trim(line);
|
char* trim = String_trim(line);
|
||||||
int nIds;
|
int nIds;
|
||||||
char** ids = String_split(trim, ' ', &nIds);
|
char** ids = String_split(trim, ' ', &nIds);
|
||||||
@ -95,13 +168,13 @@ static void Settings_readMeterModes(Settings* this, char* line, int column) {
|
|||||||
for (int i = 0; ids[i]; i++) {
|
for (int i = 0; ids[i]; i++) {
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
this->columns[column].len = len;
|
this->meterColumns[side].len = len;
|
||||||
int* modes = xCalloc(len, sizeof(int));
|
int* modes = xCalloc(len, sizeof(int));
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
modes[i] = atoi(ids[i]);
|
modes[i] = atoi(ids[i]);
|
||||||
}
|
}
|
||||||
String_freeArray(ids);
|
String_freeArray(ids);
|
||||||
this->columns[column].modes = modes;
|
this->meterColumns[side].modes = modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_defaultMeters(Settings* this) {
|
static void Settings_defaultMeters(Settings* this) {
|
||||||
@ -110,37 +183,62 @@ static void Settings_defaultMeters(Settings* this) {
|
|||||||
sizes[1]++;
|
sizes[1]++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
this->columns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
|
this->meterColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
|
||||||
this->columns[i].modes = xCalloc(sizes[i], sizeof(int));
|
this->meterColumns[i].modes = xCalloc(sizes[i], sizeof(int));
|
||||||
this->columns[i].len = sizes[i];
|
this->meterColumns[i].len = sizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (this->cpuCount > 8) {
|
if (this->cpuCount > 8) {
|
||||||
this->columns[0].names[0] = xStrdup("LeftCPUs2");
|
this->meterColumns[0].names[0] = xStrdup("LeftCPUs2");
|
||||||
this->columns[0].modes[0] = BAR_METERMODE;
|
this->meterColumns[0].modes[0] = BAR_METERMODE;
|
||||||
this->columns[1].names[r] = xStrdup("RightCPUs2");
|
this->meterColumns[1].names[r] = xStrdup("RightCPUs2");
|
||||||
this->columns[1].modes[r++] = BAR_METERMODE;
|
this->meterColumns[1].modes[r++] = BAR_METERMODE;
|
||||||
} else if (this->cpuCount > 4) {
|
} else if (this->cpuCount > 4) {
|
||||||
this->columns[0].names[0] = xStrdup("LeftCPUs");
|
this->meterColumns[0].names[0] = xStrdup("LeftCPUs");
|
||||||
this->columns[0].modes[0] = BAR_METERMODE;
|
this->meterColumns[0].modes[0] = BAR_METERMODE;
|
||||||
this->columns[1].names[r] = xStrdup("RightCPUs");
|
this->meterColumns[1].names[r] = xStrdup("RightCPUs");
|
||||||
this->columns[1].modes[r++] = BAR_METERMODE;
|
this->meterColumns[1].modes[r++] = BAR_METERMODE;
|
||||||
} else {
|
} else {
|
||||||
this->columns[0].names[0] = xStrdup("AllCPUs");
|
this->meterColumns[0].names[0] = xStrdup("AllCPUs");
|
||||||
this->columns[0].modes[0] = BAR_METERMODE;
|
this->meterColumns[0].modes[0] = BAR_METERMODE;
|
||||||
}
|
}
|
||||||
this->columns[0].names[1] = xStrdup("Memory");
|
this->meterColumns[0].names[1] = xStrdup("Memory");
|
||||||
this->columns[0].modes[1] = BAR_METERMODE;
|
this->meterColumns[0].modes[1] = BAR_METERMODE;
|
||||||
this->columns[0].names[2] = xStrdup("Swap");
|
this->meterColumns[0].names[2] = xStrdup("Swap");
|
||||||
this->columns[0].modes[2] = BAR_METERMODE;
|
this->meterColumns[0].modes[2] = BAR_METERMODE;
|
||||||
|
|
||||||
this->columns[1].names[r] = xStrdup("Tasks");
|
this->meterColumns[1].names[r] = xStrdup("Tasks");
|
||||||
this->columns[1].modes[r++] = TEXT_METERMODE;
|
this->meterColumns[1].modes[r++] = TEXT_METERMODE;
|
||||||
this->columns[1].names[r] = xStrdup("LoadAverage");
|
this->meterColumns[1].names[r] = xStrdup("LoadAverage");
|
||||||
this->columns[1].modes[r++] = TEXT_METERMODE;
|
this->meterColumns[1].modes[r++] = TEXT_METERMODE;
|
||||||
this->columns[1].names[r] = xStrdup("Uptime");
|
this->meterColumns[1].names[r] = xStrdup("Uptime");
|
||||||
this->columns[1].modes[r++] = TEXT_METERMODE;
|
this->meterColumns[1].modes[r++] = TEXT_METERMODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* toFieldName(int i) {
|
||||||
|
if (i < 0 || i > LAST_PROCESSFIELD) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return Process_fields[i].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int toFieldIndex(const char* str) {
|
||||||
|
if (isdigit(str[0])) {
|
||||||
|
// This "+1" is for compatibility with the older enum format.
|
||||||
|
int id = atoi(str) + 1;
|
||||||
|
if (id < Platform_numberOfFields && toFieldName(id)) {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int p = 1; p < LAST_PROCESSFIELD; p++) {
|
||||||
|
const char* pName = toFieldName(p);
|
||||||
|
if (pName && strcmp(pName, str) == 0) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readFields(ProcessField* fields, int* flags, const char* line) {
|
static void readFields(ProcessField* fields, int* flags, const char* line) {
|
||||||
@ -151,11 +249,10 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
|
|||||||
int i, j;
|
int i, j;
|
||||||
*flags = 0;
|
*flags = 0;
|
||||||
for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) {
|
for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) {
|
||||||
// This "+1" is for compatibility with the older enum format.
|
int idx = toFieldIndex(ids[i]);
|
||||||
int id = atoi(ids[i]) + 1;
|
if (idx != -1) {
|
||||||
if (id > 0 && Process_fields[id].name && id < Platform_numberOfFields) {
|
fields[j] = idx;
|
||||||
fields[j] = id;
|
*flags |= Process_fields[idx].flags;
|
||||||
*flags |= Process_fields[id].flags;
|
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +260,30 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
|
|||||||
String_freeArray(ids);
|
String_freeArray(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char* line) {
|
||||||
|
ScreenSettings* ss = xCalloc(sizeof(ScreenSettings), 1);
|
||||||
|
ss->name = xStrdup(name);
|
||||||
|
ss->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
||||||
|
ss->flags = 0;
|
||||||
|
ss->direction = 1;
|
||||||
|
ss->treeView = 0;
|
||||||
|
readFields(ss->fields, &(ss->flags), line);
|
||||||
|
ss->sortKey = ss->fields[0];
|
||||||
|
this->screens[this->nScreens] = ss;
|
||||||
|
this->nScreens++;
|
||||||
|
this->screens = xRealloc(this->screens, sizeof(ScreenSettings*) * (this->nScreens + 1));
|
||||||
|
this->screens[this->nScreens] = NULL;
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Settings_defaultScreens(Settings* this) {
|
||||||
|
for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++) {
|
||||||
|
ScreenDefaults* defaults = &Platform_defaultScreens[i];
|
||||||
|
Settings_newScreen(this, defaults->name, defaults->columns);
|
||||||
|
this->screens[i]->sortKey = toFieldIndex(defaults->sortKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool Settings_read(Settings* this, const char* fileName) {
|
static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
FILE* fd;
|
FILE* fd;
|
||||||
|
|
||||||
@ -174,6 +295,9 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
|
|
||||||
bool didReadMeters = false;
|
bool didReadMeters = false;
|
||||||
bool didReadFields = false;
|
bool didReadFields = false;
|
||||||
|
ProcessField* legacyFields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
||||||
|
int legacyFlags;
|
||||||
|
bool legacyFieldsRead = false;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char* line = String_readLine(fd);
|
char* line = String_readLine(fd);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
@ -187,15 +311,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (String_eq(option[0], "fields")) {
|
if (String_eq(option[0], "fields")) {
|
||||||
readFields(this->fields, &(this->flags), option[1]);
|
readFields(legacyFields, &legacyFlags, option[1]);
|
||||||
didReadFields = true;
|
legacyFieldsRead = true;
|
||||||
} else if (String_eq(option[0], "sort_key")) {
|
|
||||||
// This "+1" is for compatibility with the older enum format.
|
|
||||||
this->sortKey = atoi(option[1]) + 1;
|
|
||||||
} else if (String_eq(option[0], "sort_direction")) {
|
|
||||||
this->direction = atoi(option[1]);
|
|
||||||
} else if (String_eq(option[0], "tree_view")) {
|
|
||||||
this->treeView = atoi(option[1]);
|
|
||||||
} else if (String_eq(option[0], "hide_threads")) {
|
} else if (String_eq(option[0], "hide_threads")) {
|
||||||
this->hideThreads = atoi(option[1]);
|
this->hideThreads = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
||||||
@ -216,6 +333,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
this->highlightThreads = atoi(option[1]);
|
this->highlightThreads = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "header_margin")) {
|
} else if (String_eq(option[0], "header_margin")) {
|
||||||
this->headerMargin = atoi(option[1]);
|
this->headerMargin = atoi(option[1]);
|
||||||
|
} else if (String_eq(option[0], "screen_tabs")) {
|
||||||
|
this->screenTabs = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "expand_system_time")) {
|
} else if (String_eq(option[0], "expand_system_time")) {
|
||||||
// Compatibility option.
|
// Compatibility option.
|
||||||
this->detailedCPUTime = atoi(option[1]);
|
this->detailedCPUTime = atoi(option[1]);
|
||||||
@ -244,40 +363,62 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
} else if (String_eq(option[0], "right_meter_modes")) {
|
} else if (String_eq(option[0], "right_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 1);
|
Settings_readMeterModes(this, option[1], 1);
|
||||||
didReadMeters = true;
|
didReadMeters = true;
|
||||||
|
} else if (strncmp(option[0], "screen:", 7) == 0) {
|
||||||
|
Settings_newScreen(this, option[0] + 7, option[1]);
|
||||||
|
didReadFields = true;
|
||||||
|
} else if (String_eq(option[0], ".tree_view")) {
|
||||||
|
if (this->nScreens > 0) {
|
||||||
|
this->screens[this->nScreens - 1]->treeView = atoi(option[1]);
|
||||||
|
}
|
||||||
|
} else if (String_eq(option[0], ".sort_direction")) {
|
||||||
|
if (this->nScreens > 0) {
|
||||||
|
this->screens[this->nScreens - 1]->direction = atoi(option[1]);
|
||||||
|
}
|
||||||
|
} else if (String_eq(option[0], ".sort_key")) {
|
||||||
|
if (this->nScreens > 0) {
|
||||||
|
this->screens[this->nScreens - 1]->sortKey = toFieldIndex(option[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String_freeArray(option);
|
String_freeArray(option);
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
if (this->nScreens == 0) {
|
||||||
|
Settings_defaultScreens(this);
|
||||||
|
if (legacyFieldsRead) {
|
||||||
|
didReadFields = true;
|
||||||
|
free(this->screens[0]->fields);
|
||||||
|
this->screens[0]->fields = legacyFields;
|
||||||
|
this->screens[0]->flags = legacyFlags;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!didReadMeters) {
|
if (!didReadMeters) {
|
||||||
Settings_defaultMeters(this);
|
Settings_defaultMeters(this);
|
||||||
}
|
}
|
||||||
return didReadFields;
|
return didReadFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
static void writeFields(FILE* fd, ProcessField* fields, bool byName) {
|
||||||
fprintf(fd, "%s=", name);
|
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
// This "-1" is for compatibility with the older enum format.
|
if (byName) {
|
||||||
fprintf(fd, "%s%d", sep, (int) fields[i]-1);
|
fprintf(fd, "%s%s", sep, toFieldName(fields[i]));
|
||||||
|
} else {
|
||||||
|
// This " - 1" is for compatibility with the older enum format.
|
||||||
|
fprintf(fd, "%s%d", sep, (int) fields[i] - 1);
|
||||||
|
}
|
||||||
sep = " ";
|
sep = " ";
|
||||||
}
|
}
|
||||||
fprintf(fd, "\n");
|
fprintf(fd, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeMeters(Settings* this, FILE* fd, int column) {
|
static void writeMeters(Settings* this, FILE* fd, int side) {
|
||||||
const char* sep = "";
|
writeList(fd, this->meterColumns[side].names, this->meterColumns[side].len);
|
||||||
for (int i = 0; i < this->columns[column].len; i++) {
|
|
||||||
fprintf(fd, "%s%s", sep, this->columns[column].names[i]);
|
|
||||||
sep = " ";
|
|
||||||
}
|
|
||||||
fprintf(fd, "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeMeterModes(Settings* this, FILE* fd, int column) {
|
static void writeMeterModes(Settings* this, FILE* fd, int side) {
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for (int i = 0; i < this->columns[column].len; i++) {
|
for (int i = 0; i < this->meterColumns[side].len; i++) {
|
||||||
fprintf(fd, "%s%d", sep, this->columns[column].modes[i]);
|
fprintf(fd, "%s%d", sep, this->meterColumns[side].modes[i]);
|
||||||
sep = " ";
|
sep = " ";
|
||||||
}
|
}
|
||||||
fprintf(fd, "\n");
|
fprintf(fd, "\n");
|
||||||
@ -295,10 +436,7 @@ bool Settings_write(Settings* this) {
|
|||||||
}
|
}
|
||||||
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
||||||
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
||||||
writeFields(fd, this->fields, "fields");
|
fprintf(fd, "fields="); writeFields(fd, this->screens[0]->fields, false);
|
||||||
// This "-1" is for compatibility with the older enum format.
|
|
||||||
fprintf(fd, "sort_key=%d\n", (int) this->sortKey-1);
|
|
||||||
fprintf(fd, "sort_direction=%d\n", (int) this->direction);
|
|
||||||
fprintf(fd, "hide_threads=%d\n", (int) this->hideThreads);
|
fprintf(fd, "hide_threads=%d\n", (int) this->hideThreads);
|
||||||
fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads);
|
fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads);
|
||||||
fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads);
|
fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads);
|
||||||
@ -308,8 +446,8 @@ bool Settings_write(Settings* this) {
|
|||||||
fprintf(fd, "highlight_base_name=%d\n", (int) this->highlightBaseName);
|
fprintf(fd, "highlight_base_name=%d\n", (int) this->highlightBaseName);
|
||||||
fprintf(fd, "highlight_megabytes=%d\n", (int) this->highlightMegabytes);
|
fprintf(fd, "highlight_megabytes=%d\n", (int) this->highlightMegabytes);
|
||||||
fprintf(fd, "highlight_threads=%d\n", (int) this->highlightThreads);
|
fprintf(fd, "highlight_threads=%d\n", (int) this->highlightThreads);
|
||||||
fprintf(fd, "tree_view=%d\n", (int) this->treeView);
|
|
||||||
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
||||||
|
fprintf(fd, "screen_tabs=%d\n", (int) this->screenTabs);
|
||||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
||||||
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero);
|
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero);
|
||||||
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
||||||
@ -320,6 +458,23 @@ bool Settings_write(Settings* this) {
|
|||||||
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
||||||
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
||||||
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
||||||
|
|
||||||
|
// Legacy compatibility with older versions of htop
|
||||||
|
fprintf(fd, "tree_view=%d\n", (int) this->screens[0]->treeView);
|
||||||
|
// This "-1" is for compatibility with the older enum format.
|
||||||
|
fprintf(fd, "sort_key=%d\n", (int) this->screens[0]->sortKey-1);
|
||||||
|
fprintf(fd, "sort_direction=%d\n", (int) this->screens[0]->direction);
|
||||||
|
|
||||||
|
if (this->screens && this->screens[0]) {
|
||||||
|
for (unsigned int i = 0; i < this->nScreens; i++) {
|
||||||
|
ScreenSettings* ss = this->screens[i];
|
||||||
|
fprintf(fd, "screen:%s=", ss->name);
|
||||||
|
writeFields(fd, ss->fields, true);
|
||||||
|
fprintf(fd, ".tree_view=%d\n", (int) ss->treeView);
|
||||||
|
fprintf(fd, ".sort_key=%s\n", toFieldName(ss->sortKey));
|
||||||
|
fprintf(fd, ".sort_direction=%d\n", (int) ss->direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -328,14 +483,11 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
|
|
||||||
Settings* this = xCalloc(1, sizeof(Settings));
|
Settings* this = xCalloc(1, sizeof(Settings));
|
||||||
|
|
||||||
this->sortKey = PERCENT_CPU;
|
|
||||||
this->direction = 1;
|
|
||||||
this->hideThreads = false;
|
this->hideThreads = false;
|
||||||
this->shadowOtherUsers = false;
|
this->shadowOtherUsers = false;
|
||||||
this->showThreadNames = false;
|
this->showThreadNames = false;
|
||||||
this->hideKernelThreads = false;
|
this->hideKernelThreads = false;
|
||||||
this->hideUserlandThreads = false;
|
this->hideUserlandThreads = false;
|
||||||
this->treeView = false;
|
|
||||||
this->highlightBaseName = false;
|
this->highlightBaseName = false;
|
||||||
this->highlightMegabytes = false;
|
this->highlightMegabytes = false;
|
||||||
this->detailedCPUTime = false;
|
this->detailedCPUTime = false;
|
||||||
@ -345,15 +497,8 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
this->showProgramPath = true;
|
this->showProgramPath = true;
|
||||||
this->highlightThreads = true;
|
this->highlightThreads = true;
|
||||||
|
|
||||||
this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
this->screens = xCalloc(sizeof(ScreenSettings*), 1);
|
||||||
// TODO: turn 'fields' into a Vector,
|
this->nScreens = 0;
|
||||||
// (and ProcessFields into proper objects).
|
|
||||||
this->flags = 0;
|
|
||||||
ProcessField* defaults = Platform_defaultFields;
|
|
||||||
for (int i = 0; defaults[i]; i++) {
|
|
||||||
this->fields[i] = defaults[i];
|
|
||||||
this->flags |= Process_fields[defaults[i]].flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* legacyDotfile = NULL;
|
char* legacyDotfile = NULL;
|
||||||
char* rcfile = getenv("HTOPRC");
|
char* rcfile = getenv("HTOPRC");
|
||||||
@ -414,15 +559,21 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
}
|
}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
Settings_defaultMeters(this);
|
Settings_defaultMeters(this);
|
||||||
|
Settings_defaultScreens(this);
|
||||||
this->hideKernelThreads = true;
|
this->hideKernelThreads = true;
|
||||||
this->highlightMegabytes = true;
|
this->highlightMegabytes = true;
|
||||||
this->highlightThreads = true;
|
this->highlightThreads = true;
|
||||||
this->headerMargin = true;
|
this->headerMargin = true;
|
||||||
|
this->screenTabs = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->ssIndex = 0;
|
||||||
|
this->ss = this->screens[this->ssIndex];
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings_invertSortOrder(Settings* this) {
|
void ScreenSettings_invertSortOrder(ScreenSettings* this) {
|
||||||
if (this->direction == 1)
|
if (this->direction == 1)
|
||||||
this->direction = -1;
|
this->direction = -1;
|
||||||
else
|
else
|
||||||
|
36
Settings.h
36
Settings.h
@ -14,29 +14,44 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* name;
|
||||||
|
const char* columns;
|
||||||
|
const char* sortKey;
|
||||||
|
} ScreenDefaults;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
char** names;
|
char** names;
|
||||||
int* modes;
|
int* modes;
|
||||||
} MeterColumnSettings;
|
} MeterColumnSettings;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* name;
|
||||||
|
ProcessField* fields;
|
||||||
|
int flags;
|
||||||
|
int direction;
|
||||||
|
ProcessField sortKey;
|
||||||
|
bool treeView;
|
||||||
|
} ScreenSettings;
|
||||||
|
|
||||||
typedef struct Settings_ {
|
typedef struct Settings_ {
|
||||||
char* filename;
|
char* filename;
|
||||||
|
|
||||||
MeterColumnSettings columns[2];
|
MeterColumnSettings meterColumns[2];
|
||||||
|
|
||||||
|
ScreenSettings** screens;
|
||||||
|
unsigned int nScreens;
|
||||||
|
unsigned int ssIndex;
|
||||||
|
ScreenSettings* ss;
|
||||||
|
|
||||||
ProcessField* fields;
|
|
||||||
int flags;
|
|
||||||
int colorScheme;
|
int colorScheme;
|
||||||
int delay;
|
int delay;
|
||||||
|
|
||||||
int cpuCount;
|
int cpuCount;
|
||||||
int direction;
|
|
||||||
ProcessField sortKey;
|
|
||||||
|
|
||||||
bool countCPUsFromZero;
|
bool countCPUsFromZero;
|
||||||
bool detailedCPUTime;
|
bool detailedCPUTime;
|
||||||
bool treeView;
|
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool hideThreads;
|
bool hideThreads;
|
||||||
bool shadowOtherUsers;
|
bool shadowOtherUsers;
|
||||||
@ -49,6 +64,7 @@ typedef struct Settings_ {
|
|||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
|
bool screenTabs;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
@ -58,12 +74,18 @@ typedef struct Settings_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
void Settings_delete(Settings* this);
|
void Settings_delete(Settings* this);
|
||||||
|
|
||||||
|
ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char* line);
|
||||||
|
|
||||||
bool Settings_write(Settings* this);
|
bool Settings_write(Settings* this);
|
||||||
|
|
||||||
Settings* Settings_new(int cpuCount);
|
Settings* Settings_new(int cpuCount);
|
||||||
|
|
||||||
void Settings_invertSortOrder(Settings* this);
|
void ScreenSettings_invertSortOrder(ScreenSettings* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,10 +41,10 @@ Panel* SignalsPanel_new() {
|
|||||||
}
|
}
|
||||||
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
||||||
if (SIGRTMAX - SIGRTMIN <= 100) {
|
if (SIGRTMAX - SIGRTMIN <= 100) {
|
||||||
static char buf[15];
|
static char buf[16];
|
||||||
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
||||||
int n = sig - SIGRTMIN;
|
int n = sig - SIGRTMIN;
|
||||||
xSnprintf(buf, 15, "%2d SIGRTMIN%-+3d", sig, n);
|
xSnprintf(buf, 16, "%2d SIGRTMIN%-+3d", sig, n);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
buf[11] = '\0';
|
buf[11] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
char* String_cat(const char* s1, const char* s2) {
|
char* String_cat(const char* s1, const char* s2) {
|
||||||
int l1 = strlen(s1);
|
size_t l1 = strlen(s1);
|
||||||
int l2 = strlen(s2);
|
size_t l2 = strlen(s2);
|
||||||
char* out = xMalloc(l1 + l2 + 1);
|
char* out = xMalloc(l1 + l2 + 1);
|
||||||
strncpy(out, s1, l1);
|
strncpy(out, s1, l1);
|
||||||
strncpy(out+l1, s2, l2+1);
|
strncpy(out + l1, s2, l2 + 1);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ char* String_trim(const char* in) {
|
|||||||
while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') {
|
while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') {
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
int len = strlen(in);
|
size_t len = strlen(in);
|
||||||
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
|
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ char** String_split(const char* s, char sep, int* n) {
|
|||||||
s += size + 1;
|
s += size + 1;
|
||||||
}
|
}
|
||||||
if (s[0] != '\0') {
|
if (s[0] != '\0') {
|
||||||
int size = strlen(s);
|
size_t size = strlen(s);
|
||||||
char* token = xMalloc(size + 1);
|
char* token = xMalloc(size + 1);
|
||||||
strncpy(token, s, size + 1);
|
strncpy(token, s, size + 1);
|
||||||
out[ctr] = token;
|
out[ctr] = token;
|
||||||
|
@ -86,7 +86,7 @@ void TraceScreen_draw(InfoScreen* this) {
|
|||||||
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);
|
||||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||||
IncSet_drawBar(this->inc);
|
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TraceScreen_forkTracer(TraceScreen* this) {
|
bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||||
@ -101,7 +101,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
|
|||||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||||
if (ok != -1) {
|
if (ok != -1) {
|
||||||
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
|
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
|
||||||
execlp("strace", "strace", "-p", buffer, NULL);
|
execlp("strace", "strace", "-s", "512", "-p", buffer, NULL);
|
||||||
}
|
}
|
||||||
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
||||||
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
||||||
|
80
configure.ac
80
configure.ac
@ -2,7 +2,7 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ(2.65)
|
AC_PREREQ(2.65)
|
||||||
AC_INIT([htop],[2.1.0],[hisham@gobolinux.org])
|
AC_INIT([htop],[3.0.0beta5],[hisham@gobolinux.org])
|
||||||
|
|
||||||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
||||||
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
||||||
@ -43,6 +43,9 @@ dragonfly*)
|
|||||||
darwin*)
|
darwin*)
|
||||||
my_htop_platform=darwin
|
my_htop_platform=darwin
|
||||||
;;
|
;;
|
||||||
|
solaris*)
|
||||||
|
my_htop_platform=solaris
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
my_htop_platform=unsupported
|
my_htop_platform=unsupported
|
||||||
;;
|
;;
|
||||||
@ -238,6 +241,16 @@ if test "$my_htop_platform" = "openbsd"; then
|
|||||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "$my_htop_platform" = "solaris"; then
|
||||||
|
AC_CHECK_LIB([kstat], [kstat_open], [], [missing_libraries="$missing_libraries libkstat"])
|
||||||
|
AC_CHECK_LIB([proc], [Pgrab_error], [], [missing_libraries="$missing_libraries libproc"])
|
||||||
|
AC_CHECK_LIB([malloc], [free], [], [missing_libraries="$missing_libraries libmalloc"])
|
||||||
|
AC_CHECK_HEADERS([err.h],[:],[
|
||||||
|
missing_headers="$missing_headers err.h"
|
||||||
|
AC_MSG_ERROR([You appear to be on Solaris 10, or very early Solaris Express, which are currently unsupported.])
|
||||||
|
])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
||||||
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||||
AC_MSG_CHECKING([for usable sched_setaffinity])
|
AC_MSG_CHECKING([for usable sched_setaffinity])
|
||||||
@ -272,15 +285,67 @@ then
|
|||||||
AC_DEFINE(HAVE_SETUID_ENABLED, 1, [Define if setuid support should be enabled.])
|
AC_DEFINE(HAVE_SETUID_ENABLED, 1, [Define if setuid support should be enabled.])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(perfcounters, [AS_HELP_STRING([--enable-perfcounters], [enable hardware performance counters])],, enable_perfcounters="yes")
|
||||||
|
if test "x$enable_perfcounters" = "xyes" -a "$my_htop_platform" = "linux"
|
||||||
|
then
|
||||||
|
AC_DEFINE(HAVE_PERFCOUNTERS, 1, [Define if hardware performance counter support should be enabled.])
|
||||||
|
|
||||||
|
AC_CHECK_HEADERS([linux/perf_counter.h], [have_perf_counter=yes],
|
||||||
|
[have_perf_counter=no])
|
||||||
|
|
||||||
|
AC_CHECK_HEADERS([linux/perf_event.h], [have_perf_event=yes],
|
||||||
|
[have_perf_event=no])
|
||||||
|
|
||||||
|
if test "x${have_perf_counter}" = xno -a "x${have_perf_event}" = xno; then
|
||||||
|
os=`uname -s -r`
|
||||||
|
AC_MSG_FAILURE([
|
||||||
|
------------------------------------------------------------
|
||||||
|
Could not locate linux/perf_count.h or linux/perf_event.h.
|
||||||
|
Are performance counters supported on this machine?
|
||||||
|
Linux 2.6.31+ is required.
|
||||||
|
uname reports: ${os}
|
||||||
|
------------------------------------------------------------])
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for hardware architecture
|
||||||
|
no_target=yes
|
||||||
|
AC_MSG_CHECKING([hardware])
|
||||||
|
hw=`uname -m`
|
||||||
|
case $hw in
|
||||||
|
x86_64 | i386 | i686 ) :
|
||||||
|
AC_MSG_RESULT([x86])
|
||||||
|
AC_DEFINE([TARGET_X86], [1], [Define to 1 if the target is x86.])
|
||||||
|
no_target=no
|
||||||
|
;;
|
||||||
|
unknown ) :
|
||||||
|
AC_MSG_RESULT([unknown])
|
||||||
|
AC_MSG_WARN([Could not detect architecture])
|
||||||
|
;;
|
||||||
|
* ) :
|
||||||
|
AC_MSG_RESULT([$hw])
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test x$no_target = xyes; then
|
||||||
|
AC_DEFINE([NOTARGET], [1], [Define to 1 when no specific target is supported.])
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable linux delay accounting])],, enable_delayacct="no")
|
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable linux delay accounting])],, enable_delayacct="no")
|
||||||
if test "x$enable_delayacct" = xyes
|
if test "x$enable_delayacct" = xyes
|
||||||
then
|
then
|
||||||
PKG_PROG_PKG_CONFIG()
|
m4_ifdef([PKG_PROG_PKG_CONFIG], [
|
||||||
PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [missing_libraries="$missing_libraries libnl-3"])
|
PKG_PROG_PKG_CONFIG()
|
||||||
PKG_CHECK_MODULES(LIBNL3GENL, libnl-genl-3.0, [], [missing_libraries="$missing_libraries libnl-genl-3"])
|
PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [missing_libraries="$missing_libraries libnl-3"])
|
||||||
CFLAGS="$CFLAGS $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
PKG_CHECK_MODULES(LIBNL3GENL, libnl-genl-3.0, [], [missing_libraries="$missing_libraries libnl-genl-3"])
|
||||||
LIBS="$LIBS $LIBNL3_LIBS $LIBNL3GENL_LIBS"
|
CFLAGS="$CFLAGS $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
||||||
AC_DEFINE(HAVE_DELAYACCT, 1, [Define if delay accounting support should be enabled.])
|
LIBS="$LIBS $LIBNL3_LIBS $LIBNL3GENL_LIBS"
|
||||||
|
AC_DEFINE(HAVE_DELAYACCT, 1, [Define if delay accounting support should be enabled.])
|
||||||
|
], [
|
||||||
|
pkg_m4_absent=1
|
||||||
|
m4_warning([configure is generated without pkg.m4. 'make dist' target will be disabled.])
|
||||||
|
AC_MSG_ERROR([htop on Linux requires pkg-config for checking delayacct requirements. Please install pkg-config and run ./autogen.sh to rebuild the configure script.])
|
||||||
|
])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -302,6 +367,7 @@ AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
|||||||
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
||||||
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
||||||
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
||||||
|
AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
|
||||||
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
||||||
AC_SUBST(my_htop_platform)
|
AC_SUBST(my_htop_platform)
|
||||||
AC_CONFIG_FILES([Makefile htop.1])
|
AC_CONFIG_FILES([Makefile htop.1])
|
||||||
|
@ -18,6 +18,8 @@ in the source distribution for its full text.
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <utmpx.h>
|
#include <utmpx.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
@ -38,19 +40,51 @@ typedef struct DarwinProcessList_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
typedef struct kern {
|
||||||
|
short int version[3];
|
||||||
|
} kern_;
|
||||||
|
|
||||||
|
static void getKernelVersion(struct kern *k) {
|
||||||
|
static short int version_[3] = {0};
|
||||||
|
if (!version_[0]) {
|
||||||
|
// just in case it fails someday
|
||||||
|
version_[0] = version_[1] = version_[2] = -1;
|
||||||
|
char str[256] = {0};
|
||||||
|
size_t size = sizeof(str);
|
||||||
|
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
|
||||||
|
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
|
||||||
|
}
|
||||||
|
memcpy(k->version, version_, sizeof(version_));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int compareKernelVersion(short int major, short int minor, short int component) {
|
||||||
|
/*
|
||||||
|
compare the given os version with the one installed returns:
|
||||||
|
0 if equals the installed version
|
||||||
|
positive value if less than the installed version
|
||||||
|
negative value if more than the installed version
|
||||||
|
*/
|
||||||
|
struct kern k;
|
||||||
|
getKernelVersion(&k);
|
||||||
|
if ( k.version[0] != major) return k.version[0] - major;
|
||||||
|
if ( k.version[1] != minor) return k.version[1] - minor;
|
||||||
|
if ( k.version[2] != component) return k.version[2] - component;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||||
|
|
||||||
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||||
CRT_fatalError("Unable to retrieve host info\n");
|
CRT_fatalError("Unable to retrieve host info\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
if(NULL != p && NULL != *p) {
|
if (NULL != p && NULL != *p) {
|
||||||
if(0 != munmap(*p, vm_page_size)) {
|
if (0 != munmap(*p, vm_page_size)) {
|
||||||
CRT_fatalError("Unable to free old CPU load information\n");
|
CRT_fatalError("Unable to free old CPU load information\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = NULL;
|
*p = NULL;
|
||||||
@ -61,7 +95,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
|||||||
unsigned cpu_count;
|
unsigned cpu_count;
|
||||||
|
|
||||||
// TODO Improving the accuracy of the load counts woule help a lot.
|
// TODO Improving the accuracy of the load counts woule help a lot.
|
||||||
if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
||||||
CRT_fatalError("Unable to retrieve CPU info\n");
|
CRT_fatalError("Unable to retrieve CPU info\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +103,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_getVMStats(vm_statistics_t p) {
|
void ProcessList_getVMStats(vm_statistics_t p) {
|
||||||
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
||||||
|
|
||||||
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
||||||
CRT_fatalError("Unable to retrieve VM statistics\n");
|
CRT_fatalError("Unable to retrieve VM statistics\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
||||||
@ -127,61 +161,65 @@ void ProcessList_delete(ProcessList* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* super) {
|
void ProcessList_goThroughEntries(ProcessList* super) {
|
||||||
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
||||||
bool preExisting = true;
|
bool preExisting = true;
|
||||||
struct kinfo_proc *ps;
|
struct kinfo_proc *ps;
|
||||||
size_t count;
|
size_t count;
|
||||||
DarwinProcess *proc;
|
DarwinProcess *proc;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL); /* Start processing time */
|
gettimeofday(&tv, NULL); /* Start processing time */
|
||||||
|
|
||||||
/* Update the global data (CPU times and VM stats) */
|
/* Update the global data (CPU times and VM stats) */
|
||||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||||
dpl->prev_load = dpl->curr_load;
|
dpl->prev_load = dpl->curr_load;
|
||||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||||
ProcessList_getVMStats(&dpl->vm_stats);
|
ProcessList_getVMStats(&dpl->vm_stats);
|
||||||
|
|
||||||
/* Get the time difference */
|
/* Get the time difference */
|
||||||
dpl->global_diff = 0;
|
dpl->global_diff = 0;
|
||||||
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||||
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the thread counts */
|
/* Clear the thread counts */
|
||||||
super->kernelThreads = 0;
|
super->kernelThreads = 0;
|
||||||
super->userlandThreads = 0;
|
super->userlandThreads = 0;
|
||||||
super->totalTasks = 0;
|
super->totalTasks = 0;
|
||||||
super->runningTasks = 0;
|
super->runningTasks = 0;
|
||||||
|
|
||||||
/* We use kinfo_procs for initial data since :
|
/* We use kinfo_procs for initial data since :
|
||||||
*
|
*
|
||||||
* 1) They always succeed.
|
* 1) They always succeed.
|
||||||
* 2) The contain the basic information.
|
* 2) The contain the basic information.
|
||||||
*
|
*
|
||||||
* We attempt to fill-in additional information with libproc.
|
* We attempt to fill-in additional information with libproc.
|
||||||
*/
|
*/
|
||||||
ps = ProcessList_getKInfoProcs(&count);
|
ps = ProcessList_getKInfoProcs(&count);
|
||||||
|
|
||||||
for(size_t i = 0; i < count; ++i) {
|
for(size_t i = 0; i < count; ++i) {
|
||||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||||
|
|
||||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||||
|
|
||||||
// Disabled due to bug in macOS High Sierra
|
|
||||||
// DarwinProcess_scanThreads(proc);
|
|
||||||
|
|
||||||
super->totalTasks += 1;
|
// Disabled for High Sierra due to bug in macOS High Sierra
|
||||||
|
bool isScanThreadSupported = ! ( compareKernelVersion(17, 0, 0) >= 0 && compareKernelVersion(17, 5, 0) < 0);
|
||||||
|
|
||||||
if(!preExisting) {
|
if (isScanThreadSupported){
|
||||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
DarwinProcess_scanThreads(proc);
|
||||||
|
}
|
||||||
|
|
||||||
ProcessList_add(super, &proc->super);
|
super->totalTasks += 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(ps);
|
if (!preExisting) {
|
||||||
|
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||||
|
|
||||||
|
ProcessList_add(super, &proc->super);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ps);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ typedef struct DarwinProcessList_ {
|
|||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
||||||
|
|
||||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
||||||
|
@ -25,13 +25,26 @@ in the source distribution for its full text.
|
|||||||
#include "CPUMeter.h"
|
#include "CPUMeter.h"
|
||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "DarwinProcess.h"
|
#include "DarwinProcess.h"
|
||||||
|
|
||||||
|
typedef enum DarwinProcessFields {
|
||||||
|
LAST_PROCESSFIELD = 100,
|
||||||
|
} DarwinProcessField;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Main",
|
||||||
|
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
const SignalItem Platform_signals[] = {
|
const SignalItem Platform_signals[] = {
|
||||||
{ .name = " 0 Cancel", .number = 0 },
|
{ .name = " 0 Cancel", .number = 0 },
|
||||||
@ -97,7 +110,7 @@ ProcessFieldData Process_fields[] = {
|
|||||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||||
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||||
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||||
[100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
MeterClass* Platform_meterTypes[] = {
|
MeterClass* Platform_meterTypes[] = {
|
||||||
|
@ -16,11 +16,18 @@ in the source distribution for its full text.
|
|||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "DarwinProcess.h"
|
#include "DarwinProcess.h"
|
||||||
|
|
||||||
|
typedef enum DarwinProcessFields {
|
||||||
|
LAST_PROCESSFIELD = 100,
|
||||||
|
} DarwinProcessField;
|
||||||
|
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
extern const SignalItem Platform_signals[];
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
|
@ -138,14 +138,14 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField
|
|||||||
long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
|
long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
|
||||||
DragonFlyBSDProcess *p1, *p2;
|
DragonFlyBSDProcess *p1, *p2;
|
||||||
Settings *settings = ((Process*)v1)->settings;
|
Settings *settings = ((Process*)v1)->settings;
|
||||||
if (settings->direction == 1) {
|
if (settings->ss->direction == 1) {
|
||||||
p1 = (DragonFlyBSDProcess*)v1;
|
p1 = (DragonFlyBSDProcess*)v1;
|
||||||
p2 = (DragonFlyBSDProcess*)v2;
|
p2 = (DragonFlyBSDProcess*)v2;
|
||||||
} else {
|
} else {
|
||||||
p2 = (DragonFlyBSDProcess*)v1;
|
p2 = (DragonFlyBSDProcess*)v1;
|
||||||
p1 = (DragonFlyBSDProcess*)v2;
|
p1 = (DragonFlyBSDProcess*)v2;
|
||||||
}
|
}
|
||||||
switch ((int) settings->sortKey) {
|
switch ((int) settings->ss->sortKey) {
|
||||||
// add Platform-specific fields here
|
// add Platform-specific fields here
|
||||||
case JID:
|
case JID:
|
||||||
return (p1->jid - p2->jid);
|
return (p1->jid - p2->jid);
|
||||||
|
@ -40,7 +40,15 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Main",
|
||||||
|
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
|
@ -21,7 +21,9 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
|
@ -136,14 +136,14 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel
|
|||||||
long FreeBSDProcess_compare(const void* v1, const void* v2) {
|
long FreeBSDProcess_compare(const void* v1, const void* v2) {
|
||||||
FreeBSDProcess *p1, *p2;
|
FreeBSDProcess *p1, *p2;
|
||||||
Settings *settings = ((Process*)v1)->settings;
|
Settings *settings = ((Process*)v1)->settings;
|
||||||
if (settings->direction == 1) {
|
if (settings->ss->direction == 1) {
|
||||||
p1 = (FreeBSDProcess*)v1;
|
p1 = (FreeBSDProcess*)v1;
|
||||||
p2 = (FreeBSDProcess*)v2;
|
p2 = (FreeBSDProcess*)v2;
|
||||||
} else {
|
} else {
|
||||||
p2 = (FreeBSDProcess*)v1;
|
p2 = (FreeBSDProcess*)v1;
|
||||||
p1 = (FreeBSDProcess*)v2;
|
p1 = (FreeBSDProcess*)v2;
|
||||||
}
|
}
|
||||||
switch ((int) settings->sortKey) {
|
switch ((int) settings->ss->sortKey) {
|
||||||
// add FreeBSD-specific fields here
|
// add FreeBSD-specific fields here
|
||||||
case JID:
|
case JID:
|
||||||
return (p1->jid - p2->jid);
|
return (p1->jid - p2->jid);
|
||||||
|
@ -39,6 +39,16 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Main",
|
||||||
|
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
@ -20,6 +20,10 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
12
htop.1.in
12
htop.1.in
@ -3,7 +3,7 @@
|
|||||||
htop \- interactive process viewer
|
htop \- interactive process viewer
|
||||||
.SH "SYNOPSIS"
|
.SH "SYNOPSIS"
|
||||||
.LP
|
.LP
|
||||||
.B htop [\fI\-dChusv\fR]
|
.B htop [\fI\-dChustv\fR]
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
.LP
|
.LP
|
||||||
Htop is a free (GPL) ncurses-based process viewer for Linux.
|
Htop is a free (GPL) ncurses-based process viewer for Linux.
|
||||||
@ -41,6 +41,9 @@ Show only the processes of a given user
|
|||||||
.TP
|
.TP
|
||||||
\fB\-v \-\-version
|
\fB\-v \-\-version
|
||||||
Output version information and exit
|
Output version information and exit
|
||||||
|
.TP
|
||||||
|
\fB\-t \-\-tree
|
||||||
|
Show processes in tree view
|
||||||
.PP
|
.PP
|
||||||
.br
|
.br
|
||||||
.SH "INTERACTIVE COMMANDS"
|
.SH "INTERACTIVE COMMANDS"
|
||||||
@ -82,8 +85,13 @@ Tag or untag a process. Commands that can operate on multiple processes,
|
|||||||
like "kill", will then apply over the list of tagged processes, instead
|
like "kill", will then apply over the list of tagged processes, instead
|
||||||
of the currently highlighted one.
|
of the currently highlighted one.
|
||||||
.TP
|
.TP
|
||||||
|
.B c
|
||||||
|
Tag the current process and its children. Commands that can operate on multiple
|
||||||
|
processes, like "kill", will then apply over the list of tagged processes,
|
||||||
|
instead of the currently highlighted one.
|
||||||
|
.TP
|
||||||
.B U
|
.B U
|
||||||
Untag all processes (remove all tags added with the Space key).
|
Untag all processes (remove all tags added with the Space or c keys).
|
||||||
.TP
|
.TP
|
||||||
.B s
|
.B s
|
||||||
Trace process system calls: if strace(1) is installed, pressing this key
|
Trace process system calls: if strace(1) is installed, pressing this key
|
||||||
|
21
htop.c
21
htop.c
@ -42,6 +42,7 @@ static void printHelpFlag() {
|
|||||||
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
||||||
"-h --help Print this help screen\n"
|
"-h --help Print this help screen\n"
|
||||||
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
|
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
|
||||||
|
"-t --tree Show the tree view by default\n"
|
||||||
"-u --user=USERNAME Show only processes of a given user\n"
|
"-u --user=USERNAME Show only processes of a given user\n"
|
||||||
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
|
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
|
||||||
"-v --version Print version info\n"
|
"-v --version Print version info\n"
|
||||||
@ -61,6 +62,7 @@ typedef struct CommandLineSettings_ {
|
|||||||
int sortKey;
|
int sortKey;
|
||||||
int delay;
|
int delay;
|
||||||
bool useColors;
|
bool useColors;
|
||||||
|
bool treeView;
|
||||||
} CommandLineSettings;
|
} CommandLineSettings;
|
||||||
|
|
||||||
static CommandLineSettings parseArguments(int argc, char** argv) {
|
static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||||
@ -71,6 +73,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
.sortKey = 0,
|
.sortKey = 0,
|
||||||
.delay = -1,
|
.delay = -1,
|
||||||
.useColors = true,
|
.useColors = true,
|
||||||
|
.treeView = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct option long_opts[] =
|
static struct option long_opts[] =
|
||||||
@ -82,6 +85,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
{"user", required_argument, 0, 'u'},
|
{"user", required_argument, 0, 'u'},
|
||||||
{"no-color", no_argument, 0, 'C'},
|
{"no-color", no_argument, 0, 'C'},
|
||||||
{"no-colour",no_argument, 0, 'C'},
|
{"no-colour",no_argument, 0, 'C'},
|
||||||
|
{"tree", no_argument, 0, 't'},
|
||||||
{"pid", required_argument, 0, 'p'},
|
{"pid", required_argument, 0, 'p'},
|
||||||
{"io", no_argument, 0, 'i'},
|
{"io", no_argument, 0, 'i'},
|
||||||
{0,0,0,0}
|
{0,0,0,0}
|
||||||
@ -89,7 +93,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
|
|
||||||
int opt, opti=0;
|
int opt, opti=0;
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((opt = getopt_long(argc, argv, "hvCs:d:u:p:i", long_opts, &opti))) {
|
while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:i", long_opts, &opti))) {
|
||||||
if (opt == EOF) break;
|
if (opt == EOF) break;
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -127,6 +131,9 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
case 'C':
|
case 'C':
|
||||||
flags.useColors = false;
|
flags.useColors = false;
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
flags.treeView = true;
|
||||||
|
break;
|
||||||
case 'p': {
|
case 'p': {
|
||||||
char* argCopy = xStrdup(optarg);
|
char* argCopy = xStrdup(optarg);
|
||||||
char* saveptr;
|
char* saveptr;
|
||||||
@ -197,18 +204,20 @@ int main(int argc, char** argv) {
|
|||||||
settings->delay = flags.delay;
|
settings->delay = flags.delay;
|
||||||
if (!flags.useColors)
|
if (!flags.useColors)
|
||||||
settings->colorScheme = COLORSCHEME_MONOCHROME;
|
settings->colorScheme = COLORSCHEME_MONOCHROME;
|
||||||
|
if (flags.treeView)
|
||||||
|
settings->screens[0]->treeView = true;
|
||||||
|
|
||||||
CRT_init(settings->delay, settings->colorScheme);
|
CRT_init(settings->delay, settings->colorScheme);
|
||||||
|
|
||||||
MainPanel* panel = MainPanel_new();
|
MainPanel* panel = MainPanel_new();
|
||||||
ProcessList_setPanel(pl, (Panel*) panel);
|
ProcessList_setPanel(pl, (Panel*) panel);
|
||||||
|
|
||||||
MainPanel_updateTreeFunctions(panel, settings->treeView);
|
MainPanel_updateTreeFunctions(panel, settings->screens[0]->treeView);
|
||||||
|
|
||||||
if (flags.sortKey > 0) {
|
if (flags.sortKey > 0) {
|
||||||
settings->sortKey = flags.sortKey;
|
settings->screens[0]->sortKey = flags.sortKey;
|
||||||
settings->treeView = false;
|
settings->screens[0]->treeView = false;
|
||||||
settings->direction = 1;
|
settings->screens[0]->direction = 1;
|
||||||
}
|
}
|
||||||
ProcessList_printHeader(pl, Panel_getHeader((Panel*)panel));
|
ProcessList_printHeader(pl, Panel_getHeader((Panel*)panel));
|
||||||
|
|
||||||
@ -228,7 +237,7 @@ int main(int argc, char** argv) {
|
|||||||
millisleep(75);
|
millisleep(75);
|
||||||
ProcessList_scan(pl);
|
ProcessList_scan(pl);
|
||||||
|
|
||||||
ScreenManager_run(scr, NULL, NULL);
|
ScreenManager_run(scr, NULL, NULL, NULL);
|
||||||
|
|
||||||
attron(CRT_colors[RESET_COLOR]);
|
attron(CRT_colors[RESET_COLOR]);
|
||||||
mvhline(LINES-1, 0, ' ', COLS);
|
mvhline(LINES-1, 0, ' ', COLS);
|
||||||
|
70
htop.desktop
70
htop.desktop
@ -1,41 +1,9 @@
|
|||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
Version=1.0
|
Version=1.0
|
||||||
Name=Htop
|
Name=Htop
|
||||||
Type=Application
|
|
||||||
Comment=Show System Processes
|
|
||||||
Comment[ca]=Mostra els processos del sistema
|
|
||||||
Comment[de]=Systemprozesse anzeigen
|
|
||||||
Comment[en_GB]=Show System Processes
|
|
||||||
Comment[es]=Mostrar procesos del sistema
|
|
||||||
Comment[fi]=Katsele järjestelmän prosesseja
|
|
||||||
Comment[fr]=Affiche les processus système
|
|
||||||
Comment[gl]=Mostrar os procesos do sistema.
|
|
||||||
Comment[it]=Mostra processi di sistema
|
|
||||||
Comment[ko]=시스템 프로세스 보기
|
|
||||||
Comment[nb]=Vis systemprosesser
|
|
||||||
Comment[nl]=Systeemprocessen tonen
|
|
||||||
Comment[nn]=Vis systemprosessar
|
|
||||||
Comment[pl]=Pokaż procesy systemowe
|
|
||||||
Comment[pt]=Mostrar os Processos do Sistema
|
|
||||||
Comment[pt_BR]=Mostra os processos do sistema
|
|
||||||
Comment[ru]=Просмотр списка процессов в системе
|
|
||||||
Comment[sk]=Zobraziť systémové procesy
|
|
||||||
Comment[sl]=Prikaz sistemskih opravil
|
|
||||||
Comment[sr]=Приказ системских процеса
|
|
||||||
Comment[sr@ijekavian]=Приказ системских процеса
|
|
||||||
Comment[sr@ijekavianlatin]=Prikaz sistemskih procesa
|
|
||||||
Comment[sr@latin]=Prikaz sistemskih procesa
|
|
||||||
Comment[sv]=Visa systemprocesser
|
|
||||||
Comment[tr]=Sistem Süreçlerini Göster
|
|
||||||
Comment[uk]=Перегляд системних процесів
|
|
||||||
Comment[zh_CN]=显示系统进程
|
|
||||||
Comment[zh_TW]=顯示系統行程
|
|
||||||
Terminal=true
|
|
||||||
Exec=htop
|
|
||||||
Icon=htop
|
|
||||||
Categories=ConsoleOnly;System;
|
|
||||||
GenericName=Process Viewer
|
GenericName=Process Viewer
|
||||||
GenericName[ca]=Visor de processos
|
GenericName[ca]=Visualitzador de processos
|
||||||
GenericName[de]=Prozessanzeige
|
GenericName[de]=Prozessanzeige
|
||||||
GenericName[en_GB]=Process Viewer
|
GenericName[en_GB]=Process Viewer
|
||||||
GenericName[es]=Visor de procesos
|
GenericName[es]=Visor de procesos
|
||||||
@ -53,13 +21,45 @@ GenericName[pt_BR]=Visualizador de processos
|
|||||||
GenericName[ru]=Монитор процессов
|
GenericName[ru]=Монитор процессов
|
||||||
GenericName[sk]=Prehliadač procesov
|
GenericName[sk]=Prehliadač procesov
|
||||||
GenericName[sl]=Pregledovalnik opravil
|
GenericName[sl]=Pregledovalnik opravil
|
||||||
GenericName[sr]=Приказивач процеса
|
|
||||||
GenericName[sr@ijekavian]=Приказивач процеса
|
GenericName[sr@ijekavian]=Приказивач процеса
|
||||||
GenericName[sr@ijekavianlatin]=Prikazivač procesa
|
GenericName[sr@ijekavianlatin]=Prikazivač procesa
|
||||||
GenericName[sr@latin]=Prikazivač procesa
|
GenericName[sr@latin]=Prikazivač procesa
|
||||||
|
GenericName[sr]=Приказивач процеса
|
||||||
GenericName[sv]=Processvisning
|
GenericName[sv]=Processvisning
|
||||||
GenericName[tr]=Süreç Görüntüleyici
|
GenericName[tr]=Süreç Görüntüleyici
|
||||||
GenericName[uk]=Перегляд процесів
|
GenericName[uk]=Перегляд процесів
|
||||||
GenericName[zh_CN]=进程查看器
|
GenericName[zh_CN]=进程查看器
|
||||||
GenericName[zh_TW]=行程檢視器
|
GenericName[zh_TW]=行程檢視器
|
||||||
|
Comment=Show System Processes
|
||||||
|
Comment[ca]=Visualitzeu els processos del sistema
|
||||||
|
Comment[de]=Systemprozesse anzeigen
|
||||||
|
Comment[en_GB]=Show System Processes
|
||||||
|
Comment[es]=Mostrar procesos del sistema
|
||||||
|
Comment[fi]=Katsele järjestelmän prosesseja
|
||||||
|
Comment[fr]=Affiche les processus système
|
||||||
|
Comment[gl]=Mostrar os procesos do sistema.
|
||||||
|
Comment[it]=Mostra processi di sistema
|
||||||
|
Comment[ko]=시스템 프로세스 보기
|
||||||
|
Comment[nb]=Vis systemprosesser
|
||||||
|
Comment[nl]=Systeemprocessen tonen
|
||||||
|
Comment[nn]=Vis systemprosessar
|
||||||
|
Comment[pl]=Pokaż procesy systemowe
|
||||||
|
Comment[pt]=Mostrar os Processos do Sistema
|
||||||
|
Comment[pt_BR]=Mostra os processos do sistema
|
||||||
|
Comment[ru]=Просмотр списка процессов в системе
|
||||||
|
Comment[sk]=Zobraziť systémové procesy
|
||||||
|
Comment[sl]=Prikaz sistemskih opravil
|
||||||
|
Comment[sr@ijekavian]=Приказ системских процеса
|
||||||
|
Comment[sr@ijekavianlatin]=Prikaz sistemskih procesa
|
||||||
|
Comment[sr@latin]=Prikaz sistemskih procesa
|
||||||
|
Comment[sr]=Приказ системских процеса
|
||||||
|
Comment[sv]=Visa systemprocesser
|
||||||
|
Comment[tr]=Sistem Süreçlerini Göster
|
||||||
|
Comment[uk]=Перегляд системних процесів
|
||||||
|
Comment[zh_CN]=显示系统进程
|
||||||
|
Comment[zh_TW]=顯示系統行程
|
||||||
|
Icon=htop
|
||||||
|
Exec=htop
|
||||||
|
Terminal=true
|
||||||
|
Categories=System;Monitor;ConsoleOnly;
|
||||||
Keywords=system;process;task
|
Keywords=system;process;task
|
||||||
|
@ -15,14 +15,28 @@ in the source distribution for its full text.
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
|
||||||
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100
|
#include "PerfCounter.h"
|
||||||
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200
|
|
||||||
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
|
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100L
|
||||||
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
|
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200L
|
||||||
#define PROCESS_FLAG_LINUX_OOM 0x1000
|
#define PROCESS_FLAG_LINUX_VSERVER 0x0400L
|
||||||
|
#define PROCESS_FLAG_LINUX_CGROUP 0x0800L
|
||||||
|
#define PROCESS_FLAG_LINUX_OOM 0x1000L
|
||||||
|
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC 0xff0000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_CYCLE 0x10000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_INSN 0x20000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_MISS 0x40000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_BMISS 0x80000L
|
||||||
|
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DR 0x100000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DW 0x200000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DRM 0x400000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DWM 0x800000L
|
||||||
|
|
||||||
typedef enum UnsupportedProcessFields {
|
typedef enum UnsupportedProcessFields {
|
||||||
FLAGS = 9,
|
FLAGS = 9,
|
||||||
@ -86,13 +100,25 @@ typedef enum LinuxProcessFields {
|
|||||||
PERCENT_IO_DELAY = 117,
|
PERCENT_IO_DELAY = 117,
|
||||||
PERCENT_SWAP_DELAY = 118,
|
PERCENT_SWAP_DELAY = 118,
|
||||||
#endif
|
#endif
|
||||||
LAST_PROCESSFIELD = 119,
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
IPC = 119,
|
||||||
|
MCYCLE = 120,
|
||||||
|
MINSTR = 121,
|
||||||
|
PERCENT_MISS = 122,
|
||||||
|
PERCENT_BMISS = 123,
|
||||||
|
L1DREADS = 124,
|
||||||
|
L1DRMISSES = 125,
|
||||||
|
L1DWRITES = 126,
|
||||||
|
L1DWMISSES = 127,
|
||||||
|
#endif
|
||||||
|
LAST_PROCESSFIELD = 128,
|
||||||
} LinuxProcessField;
|
} LinuxProcessField;
|
||||||
|
|
||||||
#include "IOPriority.h"
|
#include "IOPriority.h"
|
||||||
|
|
||||||
typedef struct LinuxProcess_ {
|
typedef struct LinuxProcess_ {
|
||||||
Process super;
|
Process super;
|
||||||
|
bool isKernelThread;
|
||||||
IOPriority ioPriority;
|
IOPriority ioPriority;
|
||||||
unsigned long int cminflt;
|
unsigned long int cminflt;
|
||||||
unsigned long int cmajflt;
|
unsigned long int cmajflt;
|
||||||
@ -105,6 +131,7 @@ typedef struct LinuxProcess_ {
|
|||||||
long m_drs;
|
long m_drs;
|
||||||
long m_lrs;
|
long m_lrs;
|
||||||
long m_dt;
|
long m_dt;
|
||||||
|
unsigned long long starttime;
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
unsigned long long io_rchar;
|
unsigned long long io_rchar;
|
||||||
unsigned long long io_wchar;
|
unsigned long long io_wchar;
|
||||||
@ -139,10 +166,29 @@ typedef struct LinuxProcess_ {
|
|||||||
float blkio_delay_percent;
|
float blkio_delay_percent;
|
||||||
float swapin_delay_percent;
|
float swapin_delay_percent;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
PerfCounter* cycleCounter;
|
||||||
|
PerfCounter* insnCounter;
|
||||||
|
PerfCounter* missCounter;
|
||||||
|
PerfCounter* brCounter;
|
||||||
|
PerfCounter* l1drCounter;
|
||||||
|
PerfCounter* l1drmCounter;
|
||||||
|
PerfCounter* l1dwCounter;
|
||||||
|
PerfCounter* l1dwmCounter;
|
||||||
|
float ipc;
|
||||||
|
float mcycle;
|
||||||
|
float minstr;
|
||||||
|
float pMiss;
|
||||||
|
float pBMiss;
|
||||||
|
float l1dr;
|
||||||
|
float l1drm;
|
||||||
|
float l1dw;
|
||||||
|
float l1dwm;
|
||||||
|
#endif
|
||||||
} LinuxProcess;
|
} LinuxProcess;
|
||||||
|
|
||||||
#ifndef Process_isKernelThread
|
#ifndef Process_isKernelThread
|
||||||
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Process_isUserlandThread
|
#ifndef Process_isUserlandThread
|
||||||
@ -151,6 +197,8 @@ typedef struct LinuxProcess_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
long long btime; /* semi-global */
|
||||||
|
|
||||||
ProcessFieldData Process_fields[] = {
|
ProcessFieldData Process_fields[] = {
|
||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||||
@ -230,9 +278,20 @@ ProcessFieldData Process_fields[] = {
|
|||||||
[OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, },
|
[OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, },
|
||||||
[IO_PRIORITY] = { .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, },
|
[IO_PRIORITY] = { .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, },
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
[PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPUD% ", .description = "CPU delay %", .flags = 0, },
|
[PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPD% ", .description = "CPU delay %", .flags = 0, },
|
||||||
[PERCENT_IO_DELAY] = { .name = "PERCENT_IO_DELAY", .title = "IOD% ", .description = "Block I/O delay %", .flags = 0, },
|
[PERCENT_IO_DELAY] = { .name = "PERCENT_IO_DELAY", .title = "IOD% ", .description = "Block I/O delay %", .flags = 0, },
|
||||||
[PERCENT_SWAP_DELAY] = { .name = "PERCENT_SWAP_DELAY", .title = "SWAPD% ", .description = "Swapin delay %", .flags = 0, },
|
[PERCENT_SWAP_DELAY] = { .name = "PERCENT_SWAP_DELAY", .title = "SWD% ", .description = "Swapin delay %", .flags = 0, },
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
[IPC] = { .name = "IPC", .title = " IPC ", .description = "Executed instructions per cycle", .flags = PROCESS_FLAG_LINUX_HPC_CYCLE | PROCESS_FLAG_LINUX_HPC_INSN, },
|
||||||
|
[MCYCLE] = { .name = "MCYCLE", .title = " Mcycle ", .description = "Cycles (millions)", .flags = PROCESS_FLAG_LINUX_HPC_CYCLE, },
|
||||||
|
[MINSTR] = { .name = "MINSTR", .title = " Minstr ", .description = "Instructions (millions)", .flags = PROCESS_FLAG_LINUX_HPC_INSN, },
|
||||||
|
[PERCENT_MISS] = { .name = "PERCENT_MISS", .title = "MIS% ", .description = "Cache misses per 100 instructions", .flags = PROCESS_FLAG_LINUX_HPC_MISS | PROCESS_FLAG_LINUX_HPC_INSN, },
|
||||||
|
[PERCENT_BMISS] = { .name = "PERCENT_BMISS", .title = "BrM% ", .description = "Branch misprediction per 100 instructions", .flags = PROCESS_FLAG_LINUX_HPC_BMISS | PROCESS_FLAG_LINUX_HPC_INSN, },
|
||||||
|
[L1DREADS] = { .name = "L1DREADS", .title = " L1Dread ", .description = "L1 data cache: reads (thousands)", .flags = PROCESS_FLAG_LINUX_HPC_L1DR, },
|
||||||
|
[L1DRMISSES] = { .name = "L1DRMISSES", .title = " R miss ", .description = "L1 data cache: reads misses (thousands)", .flags = PROCESS_FLAG_LINUX_HPC_L1DRM, },
|
||||||
|
[L1DWRITES] = { .name = "L1DWRITES", .title = " L1Dwrite ", .description = "L1D data cache: writes (thousands)", .flags = PROCESS_FLAG_LINUX_HPC_L1DW, },
|
||||||
|
[L1DWMISSES] = { .name = "L1DWMISSES", .title = " W miss ", .description = "L1D data cache: write misses (thousands)", .flags = PROCESS_FLAG_LINUX_HPC_L1DWM, },
|
||||||
#endif
|
#endif
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
@ -273,6 +332,10 @@ void Process_delete(Object* cast) {
|
|||||||
Process_done((Process*)cast);
|
Process_done((Process*)cast);
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
free(this->cgroup);
|
free(this->cgroup);
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
PerfCounter_delete(this->cycleCounter);
|
||||||
|
PerfCounter_delete(this->insnCounter);
|
||||||
#endif
|
#endif
|
||||||
free(this->ttyDevice);
|
free(this->ttyDevice);
|
||||||
free(this);
|
free(this);
|
||||||
@ -306,14 +369,43 @@ bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) {
|
|||||||
return (LinuxProcess_updateIOPriority(this) == ioprio);
|
return (LinuxProcess_updateIOPriority(this) == ioprio);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#if HAVE_DELAYACCT || HAVE_PERFCOUNTERS
|
||||||
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) {
|
|
||||||
if (delay_percent == -1LL) {
|
static char* perfFmt[] = {
|
||||||
xSnprintf(buffer, n, " N/A ");
|
"%6.2f ",
|
||||||
} else {
|
NULL,
|
||||||
xSnprintf(buffer, n, "%4.1f ", delay_percent);
|
NULL,
|
||||||
}
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
"%6.1f ",
|
||||||
|
"%7.1f ",
|
||||||
|
"%8.2f ",
|
||||||
|
"%9.1f ",
|
||||||
|
};
|
||||||
|
|
||||||
|
static char* perfNA[] = {
|
||||||
|
" N/A ",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
" N/A ",
|
||||||
|
" N/A ",
|
||||||
|
" N/A ",
|
||||||
|
" N/A ",
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void LinuxProcess_printPerfCounter(float val, int len, char* buffer, int n, int* attr) {
|
||||||
|
if (val != -1) {
|
||||||
|
xSnprintf(buffer, n, perfFmt[len], val);
|
||||||
|
} else {
|
||||||
|
xSnprintf(buffer, n, perfNA[len]);
|
||||||
|
*attr = CRT_colors[PROCESS_SHADOW];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||||
@ -343,6 +435,13 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
|||||||
case STIME: Process_printTime(str, lp->stime); return;
|
case STIME: Process_printTime(str, lp->stime); return;
|
||||||
case CUTIME: Process_printTime(str, lp->cutime); return;
|
case CUTIME: Process_printTime(str, lp->cutime); return;
|
||||||
case CSTIME: Process_printTime(str, lp->cstime); return;
|
case CSTIME: Process_printTime(str, lp->cstime); return;
|
||||||
|
case STARTTIME: {
|
||||||
|
struct tm date;
|
||||||
|
time_t starttimewall = btime + (lp->starttime / sysconf(_SC_CLK_TCK));
|
||||||
|
(void) localtime_r(&starttimewall, &date);
|
||||||
|
strftime(buffer, n, ((starttimewall > time(NULL) - 86400) ? "%R " : "%b%d "), &date);
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
case RCHAR: Process_colorNumber(str, lp->io_rchar, coloring); return;
|
case RCHAR: Process_colorNumber(str, lp->io_rchar, coloring); return;
|
||||||
case WCHAR: Process_colorNumber(str, lp->io_wchar, coloring); return;
|
case WCHAR: Process_colorNumber(str, lp->io_wchar, coloring); return;
|
||||||
@ -390,9 +489,20 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
case PERCENT_CPU_DELAY: LinuxProcess_printDelay(lp->cpu_delay_percent, buffer, n); break;
|
case PERCENT_CPU_DELAY: Process_printPercentage(lp->cpu_delay_percent, buffer, n, &attr); break;
|
||||||
case PERCENT_IO_DELAY: LinuxProcess_printDelay(lp->blkio_delay_percent, buffer, n); break;
|
case PERCENT_IO_DELAY: Process_printPercentage(lp->blkio_delay_percent, buffer, n, &attr); break;
|
||||||
case PERCENT_SWAP_DELAY: LinuxProcess_printDelay(lp->swapin_delay_percent, buffer, n); break;
|
case PERCENT_SWAP_DELAY: Process_printPercentage(lp->swapin_delay_percent, buffer, n, &attr); break;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
case PERCENT_MISS: Process_printPercentage(lp->pMiss, buffer, n, &attr); break;
|
||||||
|
case PERCENT_BMISS: Process_printPercentage(lp->pBMiss, buffer, n, &attr); break;
|
||||||
|
case IPC: LinuxProcess_printPerfCounter(lp->ipc, 0, buffer, n, &attr); break;
|
||||||
|
case MCYCLE: LinuxProcess_printPerfCounter(lp->mcycle, 8, buffer, n, &attr); break;
|
||||||
|
case MINSTR: LinuxProcess_printPerfCounter(lp->minstr, 8, buffer, n, &attr); break;
|
||||||
|
case L1DREADS: LinuxProcess_printPerfCounter(lp->l1dr, 9, buffer, n, &attr); break;
|
||||||
|
case L1DRMISSES: LinuxProcess_printPerfCounter(lp->l1drm, 9, buffer, n, &attr); break;
|
||||||
|
case L1DWRITES: LinuxProcess_printPerfCounter(lp->l1dw, 9, buffer, n, &attr); break;
|
||||||
|
case L1DWMISSES: LinuxProcess_printPerfCounter(lp->l1dwm, 9, buffer, n, &attr); break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
Process_writeField((Process*)this, str, field);
|
Process_writeField((Process*)this, str, field);
|
||||||
@ -401,10 +511,12 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
|||||||
RichString_append(str, attr, buffer);
|
RichString_append(str, attr, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define COMPARE_FIELD(_f) return (p2->_f > p1->_f ? 1 : -1)
|
||||||
|
|
||||||
long LinuxProcess_compare(const void* v1, const void* v2) {
|
long LinuxProcess_compare(const void* v1, const void* v2) {
|
||||||
LinuxProcess *p1, *p2;
|
LinuxProcess *p1, *p2;
|
||||||
Settings *settings = ((Process*)v1)->settings;
|
Settings *settings = ((Process*)v1)->settings;
|
||||||
if (settings->direction == 1) {
|
if (settings->ss->direction == 1) {
|
||||||
p1 = (LinuxProcess*)v1;
|
p1 = (LinuxProcess*)v1;
|
||||||
p2 = (LinuxProcess*)v2;
|
p2 = (LinuxProcess*)v2;
|
||||||
} else {
|
} else {
|
||||||
@ -412,7 +524,11 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
|||||||
p1 = (LinuxProcess*)v2;
|
p1 = (LinuxProcess*)v2;
|
||||||
}
|
}
|
||||||
long long diff;
|
long long diff;
|
||||||
switch ((int)settings->sortKey) {
|
switch ((int)settings->ss->sortKey) {
|
||||||
|
case CMAJFLT:
|
||||||
|
return (p2->cmajflt - p1->cmajflt);
|
||||||
|
case CMINFLT:
|
||||||
|
return (p2->cminflt - p1->cminflt);
|
||||||
case M_DRS:
|
case M_DRS:
|
||||||
return (p2->m_drs - p1->m_drs);
|
return (p2->m_drs - p1->m_drs);
|
||||||
case M_DT:
|
case M_DT:
|
||||||
@ -427,6 +543,12 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
|||||||
case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff;
|
case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff;
|
||||||
case STIME: diff = p2->stime - p1->stime; goto test_diff;
|
case STIME: diff = p2->stime - p1->stime; goto test_diff;
|
||||||
case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff;
|
case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff;
|
||||||
|
case STARTTIME: {
|
||||||
|
if (p1->starttime == p2->starttime)
|
||||||
|
return (p1->super.pid - p2->super.pid);
|
||||||
|
else
|
||||||
|
return (p1->starttime - p2->starttime);
|
||||||
|
}
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
case RCHAR: diff = p2->io_rchar - p1->io_rchar; goto test_diff;
|
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 WCHAR: diff = p2->io_wchar - p1->io_wchar; goto test_diff;
|
||||||
@ -456,12 +578,20 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
|||||||
case OOM:
|
case OOM:
|
||||||
return (p2->oom - p1->oom);
|
return (p2->oom - p1->oom);
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
case PERCENT_CPU_DELAY:
|
case PERCENT_CPU_DELAY: COMPARE_FIELD(cpu_delay_percent);
|
||||||
return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1);
|
case PERCENT_IO_DELAY: COMPARE_FIELD(blkio_delay_percent);
|
||||||
case PERCENT_IO_DELAY:
|
case PERCENT_SWAP_DELAY: COMPARE_FIELD(swapin_delay_percent);
|
||||||
return (p2->blkio_delay_percent > p1->blkio_delay_percent ? 1 : -1);
|
#endif
|
||||||
case PERCENT_SWAP_DELAY:
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
return (p2->swapin_delay_percent > p1->swapin_delay_percent ? 1 : -1);
|
case PERCENT_MISS: COMPARE_FIELD(pMiss);
|
||||||
|
case PERCENT_BMISS: COMPARE_FIELD(pBMiss);
|
||||||
|
case IPC: COMPARE_FIELD(ipc);
|
||||||
|
case MCYCLE: COMPARE_FIELD(mcycle);
|
||||||
|
case MINSTR: COMPARE_FIELD(minstr);
|
||||||
|
case L1DREADS: COMPARE_FIELD(l1dr);
|
||||||
|
case L1DRMISSES: COMPARE_FIELD(l1drm);
|
||||||
|
case L1DWRITES: COMPARE_FIELD(l1dw);
|
||||||
|
case L1DWMISSES: COMPARE_FIELD(l1dwm);
|
||||||
#endif
|
#endif
|
||||||
case IO_PRIORITY:
|
case IO_PRIORITY:
|
||||||
return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2);
|
return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2);
|
||||||
@ -475,4 +605,3 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
|||||||
bool Process_isThread(Process* this) {
|
bool Process_isThread(Process* this) {
|
||||||
return (Process_isUserlandThread(this) || Process_isKernelThread(this));
|
return (Process_isUserlandThread(this) || Process_isKernelThread(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,11 +10,24 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100
|
#include "PerfCounter.h"
|
||||||
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200
|
|
||||||
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
|
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100L
|
||||||
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
|
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200L
|
||||||
#define PROCESS_FLAG_LINUX_OOM 0x1000
|
#define PROCESS_FLAG_LINUX_VSERVER 0x0400L
|
||||||
|
#define PROCESS_FLAG_LINUX_CGROUP 0x0800L
|
||||||
|
#define PROCESS_FLAG_LINUX_OOM 0x1000L
|
||||||
|
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC 0xff0000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_CYCLE 0x10000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_INSN 0x20000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_MISS 0x40000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_BMISS 0x80000L
|
||||||
|
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DR 0x100000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DW 0x200000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DRM 0x400000L
|
||||||
|
#define PROCESS_FLAG_LINUX_HPC_L1DWM 0x800000L
|
||||||
|
|
||||||
typedef enum UnsupportedProcessFields {
|
typedef enum UnsupportedProcessFields {
|
||||||
FLAGS = 9,
|
FLAGS = 9,
|
||||||
@ -78,13 +91,25 @@ typedef enum LinuxProcessFields {
|
|||||||
PERCENT_IO_DELAY = 117,
|
PERCENT_IO_DELAY = 117,
|
||||||
PERCENT_SWAP_DELAY = 118,
|
PERCENT_SWAP_DELAY = 118,
|
||||||
#endif
|
#endif
|
||||||
LAST_PROCESSFIELD = 119,
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
IPC = 119,
|
||||||
|
MCYCLE = 120,
|
||||||
|
MINSTR = 121,
|
||||||
|
PERCENT_MISS = 122,
|
||||||
|
PERCENT_BMISS = 123,
|
||||||
|
L1DREADS = 124,
|
||||||
|
L1DRMISSES = 125,
|
||||||
|
L1DWRITES = 126,
|
||||||
|
L1DWMISSES = 127,
|
||||||
|
#endif
|
||||||
|
LAST_PROCESSFIELD = 128,
|
||||||
} LinuxProcessField;
|
} LinuxProcessField;
|
||||||
|
|
||||||
#include "IOPriority.h"
|
#include "IOPriority.h"
|
||||||
|
|
||||||
typedef struct LinuxProcess_ {
|
typedef struct LinuxProcess_ {
|
||||||
Process super;
|
Process super;
|
||||||
|
bool isKernelThread;
|
||||||
IOPriority ioPriority;
|
IOPriority ioPriority;
|
||||||
unsigned long int cminflt;
|
unsigned long int cminflt;
|
||||||
unsigned long int cmajflt;
|
unsigned long int cmajflt;
|
||||||
@ -97,6 +122,7 @@ typedef struct LinuxProcess_ {
|
|||||||
long m_drs;
|
long m_drs;
|
||||||
long m_lrs;
|
long m_lrs;
|
||||||
long m_dt;
|
long m_dt;
|
||||||
|
unsigned long long starttime;
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
unsigned long long io_rchar;
|
unsigned long long io_rchar;
|
||||||
unsigned long long io_wchar;
|
unsigned long long io_wchar;
|
||||||
@ -131,10 +157,29 @@ typedef struct LinuxProcess_ {
|
|||||||
float blkio_delay_percent;
|
float blkio_delay_percent;
|
||||||
float swapin_delay_percent;
|
float swapin_delay_percent;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
PerfCounter* cycleCounter;
|
||||||
|
PerfCounter* insnCounter;
|
||||||
|
PerfCounter* missCounter;
|
||||||
|
PerfCounter* brCounter;
|
||||||
|
PerfCounter* l1drCounter;
|
||||||
|
PerfCounter* l1drmCounter;
|
||||||
|
PerfCounter* l1dwCounter;
|
||||||
|
PerfCounter* l1dwmCounter;
|
||||||
|
float ipc;
|
||||||
|
float mcycle;
|
||||||
|
float minstr;
|
||||||
|
float pMiss;
|
||||||
|
float pBMiss;
|
||||||
|
float l1dr;
|
||||||
|
float l1drm;
|
||||||
|
float l1dw;
|
||||||
|
float l1dwm;
|
||||||
|
#endif
|
||||||
} LinuxProcess;
|
} LinuxProcess;
|
||||||
|
|
||||||
#ifndef Process_isKernelThread
|
#ifndef Process_isKernelThread
|
||||||
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Process_isUserlandThread
|
#ifndef Process_isUserlandThread
|
||||||
@ -142,6 +187,8 @@ typedef struct LinuxProcess_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
long long btime; /* semi-global */
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
extern ProcessPidColumn Process_pidColumns[];
|
extern ProcessPidColumn Process_pidColumns[];
|
||||||
@ -166,15 +213,16 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
|
|||||||
|
|
||||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio);
|
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio);
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#if HAVE_DELAYACCT || HAVE_PERFCOUNTERS
|
||||||
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field);
|
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
|
|
||||||
|
#define COMPARE_FIELD(_f) return (p2->_f > p1->_f ? 1 : -1)
|
||||||
|
|
||||||
long LinuxProcess_compare(const void* v1, const void* v2);
|
long LinuxProcess_compare(const void* v1, const void* v2);
|
||||||
|
|
||||||
bool Process_isThread(Process* this);
|
bool Process_isThread(Process* this);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,6 +47,8 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
|
||||||
|
extern long long btime;
|
||||||
|
|
||||||
typedef struct CPUData_ {
|
typedef struct CPUData_ {
|
||||||
unsigned long long int totalTime;
|
unsigned long long int totalTime;
|
||||||
unsigned long long int userTime;
|
unsigned long long int userTime;
|
||||||
@ -111,7 +113,7 @@ typedef struct LinuxProcessList_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PROC_LINE_LENGTH
|
#ifndef PROC_LINE_LENGTH
|
||||||
#define PROC_LINE_LENGTH 512
|
#define PROC_LINE_LENGTH 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
@ -230,8 +232,8 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) {
|
|||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||||
LinuxProcessList* this = xCalloc(1, sizeof(LinuxProcessList));
|
LinuxProcessList* this = xCalloc(1, sizeof(LinuxProcessList));
|
||||||
ProcessList* pl = &(this->super);
|
ProcessList* pl = &(this->super);
|
||||||
|
|
||||||
ProcessList_init(pl, Class(LinuxProcess), usersTable, pidWhiteList, userId);
|
ProcessList_init(pl, Class(LinuxProcess), usersTable, pidWhiteList, userId);
|
||||||
|
|
||||||
LinuxProcessList_initTtyDrivers(this);
|
LinuxProcessList_initTtyDrivers(this);
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
@ -243,13 +245,19 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
|||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
CRT_fatalError("Cannot open " PROCSTATFILE);
|
CRT_fatalError("Cannot open " PROCSTATFILE);
|
||||||
}
|
}
|
||||||
char buffer[PROC_LINE_LENGTH + 1];
|
int cpus = 0;
|
||||||
int cpus = -1;
|
|
||||||
do {
|
do {
|
||||||
cpus++;
|
char buffer[PROC_LINE_LENGTH + 1];
|
||||||
char * s = fgets(buffer, PROC_LINE_LENGTH, file);
|
if (fgets(buffer, PROC_LINE_LENGTH + 1, file) == NULL) {
|
||||||
(void) s;
|
CRT_fatalError("No btime in " PROCSTATFILE);
|
||||||
} while (String_startsWith(buffer, "cpu"));
|
} else if (String_startsWith(buffer, "cpu")) {
|
||||||
|
cpus++;
|
||||||
|
} else if (String_startsWith(buffer, "btime ")) {
|
||||||
|
sscanf(buffer, "btime %lld\n", &btime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while(true);
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
pl->cpuCount = MAX(cpus - 1, 1);
|
pl->cpuCount = MAX(cpus - 1, 1);
|
||||||
@ -259,7 +267,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
|||||||
this->cpus[i].totalTime = 1;
|
this->cpus[i].totalTime = 1;
|
||||||
this->cpus[i].totalPeriod = 1;
|
this->cpus[i].totalPeriod = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pl;
|
return pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +362,10 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
|
|||||||
location += 1;
|
location += 1;
|
||||||
process->nlwp = strtol(location, &location, 10);
|
process->nlwp = strtol(location, &location, 10);
|
||||||
location += 1;
|
location += 1;
|
||||||
for (int i=0; i<17; i++) location = strchr(location, ' ')+1;
|
location = strchr(location, ' ')+1;
|
||||||
|
lp->starttime = strtoll(location, &location, 10);
|
||||||
|
location += 1;
|
||||||
|
for (int i=0; i<15; i++) location = strchr(location, ' ')+1;
|
||||||
process->exit_signal = strtol(location, &location, 10);
|
process->exit_signal = strtol(location, &location, 10);
|
||||||
location += 1;
|
location += 1;
|
||||||
assert(location != NULL);
|
assert(location != NULL);
|
||||||
@ -367,7 +377,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool LinuxProcessList_statProcessDir(Process* process, const char* dirname, char* name, time_t curTime) {
|
static bool LinuxProcessList_statProcessDir(Process* process, const char* dirname, char* name) {
|
||||||
char filename[MAX_NAME+1];
|
char filename[MAX_NAME+1];
|
||||||
filename[MAX_NAME] = '\0';
|
filename[MAX_NAME] = '\0';
|
||||||
|
|
||||||
@ -377,13 +387,6 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam
|
|||||||
if (statok == -1)
|
if (statok == -1)
|
||||||
return false;
|
return false;
|
||||||
process->st_uid = sstat.st_uid;
|
process->st_uid = sstat.st_uid;
|
||||||
|
|
||||||
struct tm date;
|
|
||||||
time_t ctime = sstat.st_ctime;
|
|
||||||
process->starttime_ctime = ctime;
|
|
||||||
(void) localtime_r((time_t*) &ctime, &date);
|
|
||||||
strftime(process->starttime_show, 7, ((ctime > curTime - 86400) ? "%R " : "%b%d "), &date);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,9 +656,9 @@ static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nl_send_sync(this->netlink_socket, msg) < 0) {
|
if (nl_send_sync(this->netlink_socket, msg) < 0) {
|
||||||
process->swapin_delay_percent = -1LL;
|
process->swapin_delay_percent = -1;
|
||||||
process->blkio_delay_percent = -1LL;
|
process->blkio_delay_percent = -1;
|
||||||
process->cpu_delay_percent = -1LL;
|
process->cpu_delay_percent = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,6 +669,77 @@ static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProc
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
|
||||||
|
#define READ_COUNTER(_b, _var, _flag, _type, _config) \
|
||||||
|
bool _b ## Ok = false; \
|
||||||
|
uint64_t _b ## Delta = 0; \
|
||||||
|
if (flags & _flag && lp->super.show) { \
|
||||||
|
if (!_var) { \
|
||||||
|
_var = PerfCounter_new(lp->super.pid, _type, _config); \
|
||||||
|
_b ## Ok = PerfCounter_read(_var); \
|
||||||
|
_b ## Delta = 0; \
|
||||||
|
} else { \
|
||||||
|
_b ## Ok = PerfCounter_read(_var); \
|
||||||
|
_b ## Delta = PerfCounter_delta(_var); \
|
||||||
|
} \
|
||||||
|
if (_b ## Ok) { \
|
||||||
|
} \
|
||||||
|
} else { \
|
||||||
|
if (_var) { \
|
||||||
|
PerfCounter_delete(_var); \
|
||||||
|
_var = NULL; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SET_IF(_ok, _var, _exp) \
|
||||||
|
if (_ok) { \
|
||||||
|
_var = _exp; \
|
||||||
|
} else { \
|
||||||
|
_var = -1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SET_IFNZ(_ok, _z, _var, _exp) \
|
||||||
|
if (_ok) { \
|
||||||
|
if (_z > 0) { \
|
||||||
|
_var = _exp; \
|
||||||
|
} else { \
|
||||||
|
_var = 0; \
|
||||||
|
} \
|
||||||
|
} else { \
|
||||||
|
_var = -1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define L1DR (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_READ << 8) | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16))
|
||||||
|
#define L1DRM (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_READ << 8) | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16))
|
||||||
|
#define L1DW (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16))
|
||||||
|
#define L1DWM (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16))
|
||||||
|
|
||||||
|
static void LinuxProcessList_readPerfCounters(LinuxProcess* lp, uint64_t flags) {
|
||||||
|
|
||||||
|
READ_COUNTER(c, lp->cycleCounter, PROCESS_FLAG_LINUX_HPC_CYCLE, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES);
|
||||||
|
READ_COUNTER(i, lp->insnCounter, PROCESS_FLAG_LINUX_HPC_INSN, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS);
|
||||||
|
READ_COUNTER(m, lp->missCounter, PROCESS_FLAG_LINUX_HPC_MISS, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES);
|
||||||
|
READ_COUNTER(b, lp->brCounter, PROCESS_FLAG_LINUX_HPC_BMISS, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES);
|
||||||
|
|
||||||
|
READ_COUNTER(r, lp->l1drCounter, PROCESS_FLAG_LINUX_HPC_L1DR, PERF_TYPE_HW_CACHE, L1DR);
|
||||||
|
READ_COUNTER(R, lp->l1drmCounter, PROCESS_FLAG_LINUX_HPC_L1DRM, PERF_TYPE_HW_CACHE, L1DRM);
|
||||||
|
READ_COUNTER(w, lp->l1dwCounter, PROCESS_FLAG_LINUX_HPC_L1DW, PERF_TYPE_HW_CACHE, L1DW);
|
||||||
|
READ_COUNTER(W, lp->l1dwmCounter, PROCESS_FLAG_LINUX_HPC_L1DWM, PERF_TYPE_HW_CACHE, L1DWM);
|
||||||
|
|
||||||
|
SET_IF(cOk, lp->mcycle, (double)cDelta / 1000000);
|
||||||
|
SET_IF(iOk, lp->minstr, (double)iDelta / 1000000);
|
||||||
|
SET_IFNZ(cOk && iOk, cDelta, lp->ipc, (double)iDelta / cDelta);
|
||||||
|
SET_IFNZ(mOk && iOk, iDelta, lp->pMiss, 100 * ((double)mDelta / iDelta));
|
||||||
|
SET_IFNZ(bOk && iOk, iDelta, lp->pBMiss, 100 * ((double)bDelta / iDelta));
|
||||||
|
SET_IF(rOk, lp->l1dr, (double)rDelta / 1000);
|
||||||
|
SET_IF(ROk, lp->l1drm, (double)RDelta / 1000);
|
||||||
|
SET_IF(wOk, lp->l1dw, (double)wDelta / 1000);
|
||||||
|
SET_IF(WOk, lp->l1dwm, (double)WDelta / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static void setCommand(Process* process, const char* command, int len) {
|
static void setCommand(Process* process, const char* command, int len) {
|
||||||
if (process->comm && process->commLen >= len) {
|
if (process->comm && process->commLen >= len) {
|
||||||
strncpy(process->comm, command, len + 1);
|
strncpy(process->comm, command, len + 1);
|
||||||
@ -677,9 +751,6 @@ static void setCommand(Process* process, const char* command, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
||||||
if (Process_isKernelThread(process))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
char filename[MAX_NAME+1];
|
char filename[MAX_NAME+1];
|
||||||
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = open(filename, O_RDONLY);
|
||||||
@ -691,7 +762,10 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
|||||||
close(fd);
|
close(fd);
|
||||||
int tokenEnd = 0;
|
int tokenEnd = 0;
|
||||||
int lastChar = 0;
|
int lastChar = 0;
|
||||||
if (amtRead <= 0) {
|
if (amtRead == 0) {
|
||||||
|
((LinuxProcess*)process)->isKernelThread = true;
|
||||||
|
return true;
|
||||||
|
} else if (amtRead < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < amtRead; i++) {
|
for (int i = 0; i < amtRead; i++) {
|
||||||
@ -709,7 +783,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
|||||||
}
|
}
|
||||||
command[lastChar + 1] = '\0';
|
command[lastChar + 1] = '\0';
|
||||||
process->basenameOffset = tokenEnd;
|
process->basenameOffset = tokenEnd;
|
||||||
setCommand(process, command, lastChar);
|
setCommand(process, command, lastChar + 1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -761,8 +835,8 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
Settings* settings = pl->settings;
|
Settings* settings = pl->settings;
|
||||||
|
ScreenSettings* ss = settings->ss;
|
||||||
|
|
||||||
time_t curTime = tv.tv_sec;
|
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL;
|
unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL;
|
||||||
#endif
|
#endif
|
||||||
@ -806,7 +880,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
LinuxProcessList_recurseProcTree(this, subdirname, proc, period, tv);
|
LinuxProcessList_recurseProcTree(this, subdirname, proc, period, tv);
|
||||||
|
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
if (settings->flags & PROCESS_FLAG_IO)
|
if (ss->flags & PROCESS_FLAG_IO)
|
||||||
LinuxProcessList_readIoFile(lp, dirname, name, now);
|
LinuxProcessList_readIoFile(lp, dirname, name, now);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -825,7 +899,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
free(lp->ttyDevice);
|
free(lp->ttyDevice);
|
||||||
lp->ttyDevice = LinuxProcessList_updateTtyDevice(this->ttyDrivers, proc->tty_nr);
|
lp->ttyDevice = LinuxProcessList_updateTtyDevice(this->ttyDrivers, proc->tty_nr);
|
||||||
}
|
}
|
||||||
if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO)
|
if (ss->flags & PROCESS_FLAG_LINUX_IOPRIO)
|
||||||
LinuxProcess_updateIOPriority(lp);
|
LinuxProcess_updateIOPriority(lp);
|
||||||
float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0;
|
float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0;
|
||||||
proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0);
|
proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0);
|
||||||
@ -834,19 +908,19 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
|
|
||||||
if(!preExisting) {
|
if(!preExisting) {
|
||||||
|
|
||||||
if (! LinuxProcessList_statProcessDir(proc, dirname, name, curTime))
|
if (! LinuxProcessList_statProcessDir(proc, dirname, name))
|
||||||
goto errorReadingProcess;
|
goto errorReadingProcess;
|
||||||
|
|
||||||
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
||||||
|
|
||||||
#ifdef HAVE_OPENVZ
|
#ifdef HAVE_OPENVZ
|
||||||
if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) {
|
if (ss->flags & PROCESS_FLAG_LINUX_OPENVZ) {
|
||||||
LinuxProcessList_readOpenVZData(lp, dirname, name);
|
LinuxProcessList_readOpenVZData(lp, dirname, name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_VSERVER
|
#ifdef HAVE_VSERVER
|
||||||
if (settings->flags & PROCESS_FLAG_LINUX_VSERVER) {
|
if (ss->flags & PROCESS_FLAG_LINUX_VSERVER) {
|
||||||
LinuxProcessList_readVServerData(lp, dirname, name);
|
LinuxProcessList_readVServerData(lp, dirname, name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -869,13 +943,18 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
if (settings->flags & PROCESS_FLAG_LINUX_CGROUP)
|
if (ss->flags & PROCESS_FLAG_LINUX_CGROUP)
|
||||||
LinuxProcessList_readCGroupFile(lp, dirname, name);
|
LinuxProcessList_readCGroupFile(lp, dirname, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (settings->flags & PROCESS_FLAG_LINUX_OOM)
|
if (ss->flags & PROCESS_FLAG_LINUX_OOM)
|
||||||
LinuxProcessList_readOomData(lp, dirname, name);
|
LinuxProcessList_readOomData(lp, dirname, name);
|
||||||
|
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
if (ss->flags & PROCESS_FLAG_LINUX_HPC)
|
||||||
|
LinuxProcessList_readPerfCounters(lp, ss->flags);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (proc->state == 'Z' && (proc->basenameOffset == 0)) {
|
if (proc->state == 'Z' && (proc->basenameOffset == 0)) {
|
||||||
proc->basenameOffset = -1;
|
proc->basenameOffset = -1;
|
||||||
setCommand(proc, command, commLen);
|
setCommand(proc, command, commLen);
|
||||||
|
@ -20,6 +20,8 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
|
||||||
|
extern long long btime;
|
||||||
|
|
||||||
typedef struct CPUData_ {
|
typedef struct CPUData_ {
|
||||||
unsigned long long int totalTime;
|
unsigned long long int totalTime;
|
||||||
unsigned long long int userTime;
|
unsigned long long int userTime;
|
||||||
@ -84,7 +86,7 @@ typedef struct LinuxProcessList_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PROC_LINE_LENGTH
|
#ifndef PROC_LINE_LENGTH
|
||||||
#define PROC_LINE_LENGTH 512
|
#define PROC_LINE_LENGTH 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -121,6 +123,54 @@ void ProcessList_delete(ProcessList* pl);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PERFCOUNTERS
|
||||||
|
|
||||||
|
#define READ_COUNTER(_b, _var, _flag, _type, _config) \
|
||||||
|
bool _b ## Ok = false; \
|
||||||
|
uint64_t _b ## Delta = 0; \
|
||||||
|
if (flags & _flag && lp->super.show) { \
|
||||||
|
if (!_var) { \
|
||||||
|
_var = PerfCounter_new(lp->super.pid, _type, _config); \
|
||||||
|
_b ## Ok = PerfCounter_read(_var); \
|
||||||
|
_b ## Delta = 0; \
|
||||||
|
} else { \
|
||||||
|
_b ## Ok = PerfCounter_read(_var); \
|
||||||
|
_b ## Delta = PerfCounter_delta(_var); \
|
||||||
|
} \
|
||||||
|
if (_b ## Ok) { \
|
||||||
|
} \
|
||||||
|
} else { \
|
||||||
|
if (_var) { \
|
||||||
|
PerfCounter_delete(_var); \
|
||||||
|
_var = NULL; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SET_IF(_ok, _var, _exp) \
|
||||||
|
if (_ok) { \
|
||||||
|
_var = _exp; \
|
||||||
|
} else { \
|
||||||
|
_var = -1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SET_IFNZ(_ok, _z, _var, _exp) \
|
||||||
|
if (_ok) { \
|
||||||
|
if (_z > 0) { \
|
||||||
|
_var = _exp; \
|
||||||
|
} else { \
|
||||||
|
_var = 0; \
|
||||||
|
} \
|
||||||
|
} else { \
|
||||||
|
_var = -1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define L1DR (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_READ << 8) | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16))
|
||||||
|
#define L1DRM (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_READ << 8) | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16))
|
||||||
|
#define L1DW (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16))
|
||||||
|
#define L1DWM (PERF_COUNT_HW_CACHE_L1D | (PERF_COUNT_HW_CACHE_OP_WRITE << 8) | (PERF_COUNT_HW_CACHE_RESULT_MISS << 16))
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* super);
|
void ProcessList_goThroughEntries(ProcessList* super);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
135
linux/PerfCounter.c
Normal file
135
linux/PerfCounter.c
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* This file is based on tiptop.
|
||||||
|
* by Erven ROHOU
|
||||||
|
* Copyright (c) 2011, 2012, 2014 Inria
|
||||||
|
* License: GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PerfCounter.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "XAlloc.h"
|
||||||
|
|
||||||
|
/*{
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <asm/unistd.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
// The sys_perf_counter_open syscall and header files changed names
|
||||||
|
// between Linux 2.6.31 and 2.6.32. Do the mangling here.
|
||||||
|
#ifdef HAVE_LINUX_PERF_COUNTER_H
|
||||||
|
#include <linux/perf_counter.h>
|
||||||
|
#define STRUCT_NAME perf_counter_attr
|
||||||
|
#define SYSCALL_NUM __NR_perf_counter_open
|
||||||
|
|
||||||
|
#elif HAVE_LINUX_PERF_EVENT_H
|
||||||
|
#include <linux/perf_event.h>
|
||||||
|
#define STRUCT_NAME perf_event_attr
|
||||||
|
#define SYSCALL_NUM __NR_perf_event_open
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error Sorry, performance counters not supported on this system.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct PerfCounter_ {
|
||||||
|
struct STRUCT_NAME events;
|
||||||
|
pid_t pid;
|
||||||
|
int fd;
|
||||||
|
uint64_t prevValue;
|
||||||
|
uint64_t value;
|
||||||
|
} PerfCounter;
|
||||||
|
|
||||||
|
#define PerfCounter_delta(pc_) ((pc_)->value - (pc_)->prevValue)
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
int PerfCounter_openFds = 0;
|
||||||
|
static int PerfCounter_fdLimit = -1;
|
||||||
|
|
||||||
|
static void PerfCounter_initFdLimit() {
|
||||||
|
char name[100] = { 0 }; /* needs to fit the name /proc/xxxx/limits */
|
||||||
|
snprintf(name, sizeof(name) - 1, "/proc/%d/limits", getpid());
|
||||||
|
FILE* f = fopen(name, "r");
|
||||||
|
if (f) {
|
||||||
|
char line[100];
|
||||||
|
while (fgets(line, 100, f)) {
|
||||||
|
int n = sscanf(line, "Max open files %d", &PerfCounter_fdLimit);
|
||||||
|
if (n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
PerfCounter_fdLimit -= 20; /* keep some slack */
|
||||||
|
if (PerfCounter_fdLimit == 0) { /* something went wrong */
|
||||||
|
PerfCounter_fdLimit = 200; /* reasonable default? */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static long perf_event_open(struct STRUCT_NAME *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags) {
|
||||||
|
int ret = syscall(SYSCALL_NUM, hw_event, pid, cpu, group_fd, flags);
|
||||||
|
#if defined(__x86_64__) || defined(__i386__)
|
||||||
|
if (ret < 0 && ret > -4096) {
|
||||||
|
errno = -ret;
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
PerfCounter* PerfCounter_new(pid_t pid, uint32_t type, uint64_t config) {
|
||||||
|
if (PerfCounter_fdLimit == -1) {
|
||||||
|
PerfCounter_initFdLimit();
|
||||||
|
}
|
||||||
|
PerfCounter* this = xCalloc(sizeof(PerfCounter), 1);
|
||||||
|
this->pid = pid;
|
||||||
|
this->events.disabled = 0;
|
||||||
|
this->events.pinned = 1;
|
||||||
|
this->events.exclude_hv = 1;
|
||||||
|
this->events.exclude_kernel = 1;
|
||||||
|
this->events.type = type;
|
||||||
|
this->events.config = config;
|
||||||
|
if (PerfCounter_openFds < PerfCounter_fdLimit) {
|
||||||
|
this->fd = perf_event_open(&this->events, pid, -1, -1, 0);
|
||||||
|
} else {
|
||||||
|
this->fd = -1;
|
||||||
|
}
|
||||||
|
if (this->fd != -1) {
|
||||||
|
PerfCounter_openFds++;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerfCounter_delete(PerfCounter* this) {
|
||||||
|
if (!this) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this->fd != -1) {
|
||||||
|
PerfCounter_openFds--;
|
||||||
|
}
|
||||||
|
close(this->fd);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PerfCounter_read(PerfCounter* this) {
|
||||||
|
if (this->fd == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint64_t value;
|
||||||
|
int r = read(this->fd, &value, sizeof(value));
|
||||||
|
if (r != sizeof(value)) {
|
||||||
|
close(this->fd);
|
||||||
|
this->fd = perf_event_open(&this->events, this->pid, -1, -1, 0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this->prevValue = this->value;
|
||||||
|
this->value = value;
|
||||||
|
return true;
|
||||||
|
}
|
54
linux/PerfCounter.h
Normal file
54
linux/PerfCounter.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_PerfCounter
|
||||||
|
#define HEADER_PerfCounter
|
||||||
|
/*
|
||||||
|
* This file is based on tiptop.
|
||||||
|
* by Erven ROHOU
|
||||||
|
* Copyright (c) 2011, 2012, 2014 Inria
|
||||||
|
* License: GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <asm/unistd.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
// The sys_perf_counter_open syscall and header files changed names
|
||||||
|
// between Linux 2.6.31 and 2.6.32. Do the mangling here.
|
||||||
|
#ifdef HAVE_LINUX_PERF_COUNTER_H
|
||||||
|
#include <linux/perf_counter.h>
|
||||||
|
#define STRUCT_NAME perf_counter_attr
|
||||||
|
#define SYSCALL_NUM __NR_perf_counter_open
|
||||||
|
|
||||||
|
#elif HAVE_LINUX_PERF_EVENT_H
|
||||||
|
#include <linux/perf_event.h>
|
||||||
|
#define STRUCT_NAME perf_event_attr
|
||||||
|
#define SYSCALL_NUM __NR_perf_event_open
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error Sorry, performance counters not supported on this system.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct PerfCounter_ {
|
||||||
|
struct STRUCT_NAME events;
|
||||||
|
pid_t pid;
|
||||||
|
int fd;
|
||||||
|
uint64_t prevValue;
|
||||||
|
uint64_t value;
|
||||||
|
} PerfCounter;
|
||||||
|
|
||||||
|
#define PerfCounter_delta(pc_) ((pc_)->value - (pc_)->prevValue)
|
||||||
|
|
||||||
|
|
||||||
|
extern int PerfCounter_openFds;
|
||||||
|
PerfCounter* PerfCounter_new(pid_t pid, uint32_t type, uint64_t config);
|
||||||
|
|
||||||
|
void PerfCounter_delete(PerfCounter* this);
|
||||||
|
|
||||||
|
bool PerfCounter_read(PerfCounter* this);
|
||||||
|
|
||||||
|
#endif
|
@ -22,6 +22,7 @@ in the source distribution for its full text.
|
|||||||
#include "ClockMeter.h"
|
#include "ClockMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
#include "LinuxProcess.h"
|
#include "LinuxProcess.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -35,16 +36,13 @@ in the source distribution for its full text.
|
|||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "LinuxProcess.h"
|
#include "LinuxProcess.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
|
#include "Settings.h"
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
|
||||||
|
|
||||||
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
|
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
const SignalItem Platform_signals[] = {
|
const SignalItem Platform_signals[] = {
|
||||||
@ -84,6 +82,31 @@ const SignalItem Platform_signals[] = {
|
|||||||
{ .name = "31 SIGSYS", .number = 31 },
|
{ .name = "31 SIGSYS", .number = 31 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Main",
|
||||||
|
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "I/O",
|
||||||
|
.columns = "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command",
|
||||||
|
.sortKey = "IO_RATE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "Perf Counters",
|
||||||
|
.columns = "PID USER PERCENT_CPU PROCESSOR MCYCLE MINSTR IPC PERCENT_MISS PERCENT_BMISS Command",
|
||||||
|
.sortKey = "MCYCLE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "L1 Data Cache",
|
||||||
|
.columns = "PID USER PERCENT_CPU L1DREADS L1DRMISSES L1DWRITES L1DWMISSES Command",
|
||||||
|
.sortKey = "L1DREADS",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||||
|
|
||||||
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||||
|
@ -14,17 +14,20 @@ in the source distribution for its full text.
|
|||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "LinuxProcess.h"
|
#include "LinuxProcess.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
extern const SignalItem Platform_signals[];
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfSignals;
|
extern const unsigned int Platform_numberOfSignals;
|
||||||
|
|
||||||
void Platform_setBindings(Htop_Action* keys);
|
void Platform_setBindings(Htop_Action* keys);
|
||||||
|
@ -7,10 +7,65 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/sensors.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
|
||||||
// TODO
|
for (int devn = 0;; devn++) {
|
||||||
*level = -1;
|
mib[2] = devn;
|
||||||
*isOnAC = AC_ERROR;
|
if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) {
|
||||||
|
if (errno == ENXIO)
|
||||||
|
continue;
|
||||||
|
if (errno == ENOENT)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(name, snsrdev->xname) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||||
|
static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
||||||
|
struct sensor s;
|
||||||
|
size_t slen = sizeof(struct sensor);
|
||||||
|
struct sensordev snsrdev;
|
||||||
|
size_t sdlen = sizeof(struct sensordev);
|
||||||
|
|
||||||
|
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
|
||||||
|
|
||||||
|
*level = -1;
|
||||||
|
if (found) {
|
||||||
|
/* last full capacity */
|
||||||
|
mib[3] = 7;
|
||||||
|
mib[4] = 0;
|
||||||
|
double last_full_capacity = 0;
|
||||||
|
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||||
|
last_full_capacity = s.value;
|
||||||
|
}
|
||||||
|
if (last_full_capacity > 0) {
|
||||||
|
/* remaining capacity */
|
||||||
|
mib[3] = 7;
|
||||||
|
mib[4] = 3;
|
||||||
|
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||||
|
double charge = s.value;
|
||||||
|
*level = 100*(charge / last_full_capacity);
|
||||||
|
if (charge >= last_full_capacity) {
|
||||||
|
*level = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
found = findDevice("acpiac0", mib, &snsrdev, &sdlen);
|
||||||
|
|
||||||
|
*isOnAC = AC_ERROR;
|
||||||
|
if (found) {
|
||||||
|
mib[3] = 9;
|
||||||
|
mib[4] = 0;
|
||||||
|
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||||
|
*isOnAC = s.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,5 +12,4 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -215,14 +215,14 @@ void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel
|
|||||||
long OpenBSDProcess_compare(const void* v1, const void* v2) {
|
long OpenBSDProcess_compare(const void* v1, const void* v2) {
|
||||||
OpenBSDProcess *p1, *p2;
|
OpenBSDProcess *p1, *p2;
|
||||||
Settings *settings = ((Process*)v1)->settings;
|
Settings *settings = ((Process*)v1)->settings;
|
||||||
if (settings->direction == 1) {
|
if (settings->ss->direction == 1) {
|
||||||
p1 = (OpenBSDProcess*)v1;
|
p1 = (OpenBSDProcess*)v1;
|
||||||
p2 = (OpenBSDProcess*)v2;
|
p2 = (OpenBSDProcess*)v2;
|
||||||
} else {
|
} else {
|
||||||
p2 = (OpenBSDProcess*)v1;
|
p2 = (OpenBSDProcess*)v1;
|
||||||
p1 = (OpenBSDProcess*)v2;
|
p1 = (OpenBSDProcess*)v2;
|
||||||
}
|
}
|
||||||
switch (settings->sortKey) {
|
switch (settings->ss->sortKey) {
|
||||||
// add OpenBSD-specific fields here
|
// add OpenBSD-specific fields here
|
||||||
default:
|
default:
|
||||||
return Process_compare(v1, v2);
|
return Process_compare(v1, v2);
|
||||||
|
@ -223,6 +223,8 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
|||||||
bool preExisting;
|
bool preExisting;
|
||||||
Process* proc;
|
Process* proc;
|
||||||
OpenBSDProcess* fp;
|
OpenBSDProcess* fp;
|
||||||
|
struct tm date;
|
||||||
|
struct timeval tv;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -232,6 +234,8 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
|||||||
struct kinfo_proc* kprocs = kvm_getprocs(opl->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
|
struct kinfo_proc* kprocs = kvm_getprocs(opl->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
|
||||||
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
|
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
kproc = &kprocs[i];
|
kproc = &kprocs[i];
|
||||||
|
|
||||||
@ -254,6 +258,8 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
|||||||
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
|
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
|
||||||
ProcessList_add((ProcessList*)this, proc);
|
ProcessList_add((ProcessList*)this, proc);
|
||||||
proc->comm = OpenBSDProcessList_readProcessName(opl->kd, kproc, &proc->basenameOffset);
|
proc->comm = OpenBSDProcessList_readProcessName(opl->kd, kproc, &proc->basenameOffset);
|
||||||
|
(void) localtime_r((time_t*) &kproc->p_ustart_sec, &date);
|
||||||
|
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date);
|
||||||
} else {
|
} else {
|
||||||
if (settings->updateProcessNames) {
|
if (settings->updateProcessNames) {
|
||||||
free(proc->comm);
|
free(proc->comm);
|
||||||
|
@ -23,6 +23,7 @@ in the source distribution for its full text.
|
|||||||
#include <sys/sched.h>
|
#include <sys/sched.h>
|
||||||
#include <uvm/uvmexp.h>
|
#include <uvm/uvmexp.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
#include <sys/swap.h>
|
#include <sys/swap.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -34,6 +35,9 @@ in the source distribution for its full text.
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <kvm.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "Action.h"
|
#include "Action.h"
|
||||||
@ -92,7 +96,15 @@ static int percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_
|
|||||||
return (total_change);
|
return (total_change);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Main",
|
||||||
|
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
@ -294,6 +306,48 @@ void Platform_setTasksValues(Meter* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid) {
|
char* Platform_getProcessEnv(pid_t pid) {
|
||||||
// TODO
|
char errbuf[_POSIX2_LINE_MAX];
|
||||||
return NULL;
|
char *env;
|
||||||
|
char **ptr;
|
||||||
|
int count;
|
||||||
|
kvm_t *kt;
|
||||||
|
struct kinfo_proc *kproc;
|
||||||
|
size_t capacity = 4096, size = 0;
|
||||||
|
|
||||||
|
if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid,
|
||||||
|
sizeof(struct kinfo_proc), &count)) == NULL) {\
|
||||||
|
(void) kvm_close(kt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ptr = kvm_getenvv(kt, kproc, 0)) == NULL) {
|
||||||
|
(void) kvm_close(kt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
env = xMalloc(capacity);
|
||||||
|
for (char **p = ptr; *p; p++) {
|
||||||
|
size_t len = strlen(*p) + 1;
|
||||||
|
|
||||||
|
if (size + len > capacity) {
|
||||||
|
capacity *= 2;
|
||||||
|
env = xRealloc(env, capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcpy(env + size, *p, len);
|
||||||
|
size += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < 2 || env[size - 1] || env[size - 2]) {
|
||||||
|
if (size + 2 < capacity)
|
||||||
|
env = xRealloc(env, capacity + 2);
|
||||||
|
env[size] = 0;
|
||||||
|
env[size+1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void) kvm_close(kt);
|
||||||
|
return env;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,9 @@ extern ProcessFieldData Process_fields[];
|
|||||||
* The routine assumes modulo arithmetic. This function is especially
|
* The routine assumes modulo arithmetic. This function is especially
|
||||||
* useful on BSD machines for calculating cpu state percentages.
|
* useful on BSD machines for calculating cpu state percentages.
|
||||||
*/
|
*/
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os, sys, string
|
import os, sys, string, io
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from StringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
from io import StringIO
|
||||||
from StringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
ANY=1
|
ANY=1
|
||||||
COPY=2
|
COPY=2
|
||||||
SKIP=3
|
SKIP=3
|
||||||
SKIPONE=4
|
SKIPONE=4
|
||||||
|
COPYDEFINE=5
|
||||||
|
|
||||||
state = ANY
|
state = ANY
|
||||||
static = 0
|
static = 0
|
||||||
|
|
||||||
file = open(sys.argv[1])
|
file = io.open(sys.argv[1], "r", encoding="utf-8")
|
||||||
name = sys.argv[1][:-2]
|
name = sys.argv[1][:-2]
|
||||||
|
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
@ -49,7 +47,11 @@ for line in file.readlines():
|
|||||||
elif len(line) > 1:
|
elif len(line) > 1:
|
||||||
static = 0
|
static = 0
|
||||||
equals = line.find(" = ")
|
equals = line.find(" = ")
|
||||||
if line[-3:] == "= {":
|
if line[:7] == "#define":
|
||||||
|
if line[-1:] == "\\":
|
||||||
|
state = COPYDEFINE
|
||||||
|
out.write( line + "\n")
|
||||||
|
elif line[-3:] == "= {":
|
||||||
out.write( "extern " + line[:-4] + ";\n" )
|
out.write( "extern " + line[:-4] + ";\n" )
|
||||||
state = SKIP
|
state = SKIP
|
||||||
elif equals != -1:
|
elif equals != -1:
|
||||||
@ -60,7 +62,7 @@ for line in file.readlines():
|
|||||||
out.write( line[:-2].replace("inline", "extern") + ";\n" )
|
out.write( line[:-2].replace("inline", "extern") + ";\n" )
|
||||||
state = SKIP
|
state = SKIP
|
||||||
else:
|
else:
|
||||||
out.write( line + "\n")
|
out.write( line + "\n" )
|
||||||
is_blank = False
|
is_blank = False
|
||||||
elif line == "":
|
elif line == "":
|
||||||
if not is_blank:
|
if not is_blank:
|
||||||
@ -69,6 +71,11 @@ for line in file.readlines():
|
|||||||
else:
|
else:
|
||||||
out.write( line + "\n")
|
out.write( line + "\n")
|
||||||
is_blank = False
|
is_blank = False
|
||||||
|
elif state == COPYDEFINE:
|
||||||
|
is_blank = False
|
||||||
|
out.write( line + "\n")
|
||||||
|
if line[-1:] != "\\":
|
||||||
|
state = ANY
|
||||||
elif state == COPY:
|
elif state == COPY:
|
||||||
is_blank = False
|
is_blank = False
|
||||||
if line == "}*/":
|
if line == "}*/":
|
||||||
@ -94,12 +101,12 @@ out.write( "#endif\n" )
|
|||||||
# This prevents a lot of recompilation during development
|
# This prevents a lot of recompilation during development
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
try:
|
try:
|
||||||
with open(name + ".h", "r") as orig:
|
with io.open(name + ".h", "r", encoding="utf-8") as orig:
|
||||||
origcontents = orig.readlines()
|
origcontents = orig.readlines()
|
||||||
except:
|
except:
|
||||||
origcontents = ""
|
origcontents = ""
|
||||||
if origcontents != out.readlines():
|
if origcontents != out.readlines():
|
||||||
with open(name + ".h", "w") as new:
|
with io.open(name + ".h", "w", encoding="utf-8") as new:
|
||||||
print("Writing "+name+".h")
|
print("Writing "+name+".h")
|
||||||
new.write(out.getvalue())
|
new.write(out.getvalue())
|
||||||
out.close()
|
out.close()
|
||||||
|
8
solaris/Battery.c
Normal file
8
solaris/Battery.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
#include "BatteryMeter.h"
|
||||||
|
|
||||||
|
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||||
|
*level = -1;
|
||||||
|
*isOnAC = AC_ERROR;
|
||||||
|
}
|
||||||
|
|
9
solaris/Battery.h
Normal file
9
solaris/Battery.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_Battery
|
||||||
|
#define HEADER_Battery
|
||||||
|
|
||||||
|
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
266
solaris/Platform.c
Normal file
266
solaris/Platform.c
Normal file
@ -0,0 +1,266 @@
|
|||||||
|
/*
|
||||||
|
htop - solaris/Platform.c
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2015 David C. Hunt
|
||||||
|
(C) 2017,2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Platform.h"
|
||||||
|
#include "Meter.h"
|
||||||
|
#include "CPUMeter.h"
|
||||||
|
#include "MemoryMeter.h"
|
||||||
|
#include "SwapMeter.h"
|
||||||
|
#include "TasksMeter.h"
|
||||||
|
#include "LoadAverageMeter.h"
|
||||||
|
#include "ClockMeter.h"
|
||||||
|
#include "HostnameMeter.h"
|
||||||
|
#include "UptimeMeter.h"
|
||||||
|
#include "SolarisProcess.h"
|
||||||
|
#include "SolarisProcessList.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <utmpx.h>
|
||||||
|
#include <sys/loadavg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <kstat.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <sys/var.h>
|
||||||
|
|
||||||
|
/*{
|
||||||
|
#include "Action.h"
|
||||||
|
#include "BatteryMeter.h"
|
||||||
|
#include "SignalsPanel.h"
|
||||||
|
#include "SolarisProcess.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/mkdev.h>
|
||||||
|
#include <sys/proc.h>
|
||||||
|
#include <libproc.h>
|
||||||
|
|
||||||
|
#define kill(pid, signal) kill(pid / 1024, signal)
|
||||||
|
|
||||||
|
extern ProcessFieldData Process_fields[];
|
||||||
|
typedef struct var kvar_t;
|
||||||
|
|
||||||
|
typedef struct envAccum_ {
|
||||||
|
size_t capacity;
|
||||||
|
size_t size;
|
||||||
|
size_t bytes;
|
||||||
|
char *env;
|
||||||
|
} envAccum;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
double plat_loadavg[3] = {0};
|
||||||
|
|
||||||
|
const SignalItem Platform_signals[] = {
|
||||||
|
{ .name = " 0 Cancel", .number = 0 },
|
||||||
|
{ .name = " 1 SIGHUP", .number = 1 },
|
||||||
|
{ .name = " 2 SIGINT", .number = 2 },
|
||||||
|
{ .name = " 3 SIGQUIT", .number = 3 },
|
||||||
|
{ .name = " 4 SIGILL", .number = 4 },
|
||||||
|
{ .name = " 5 SIGTRAP", .number = 5 },
|
||||||
|
{ .name = " 6 SIGABRT/IOT", .number = 6 },
|
||||||
|
{ .name = " 7 SIGEMT", .number = 7 },
|
||||||
|
{ .name = " 8 SIGFPE", .number = 8 },
|
||||||
|
{ .name = " 9 SIGKILL", .number = 9 },
|
||||||
|
{ .name = "10 SIGBUS", .number = 10 },
|
||||||
|
{ .name = "11 SIGSEGV", .number = 11 },
|
||||||
|
{ .name = "12 SIGSYS", .number = 12 },
|
||||||
|
{ .name = "13 SIGPIPE", .number = 13 },
|
||||||
|
{ .name = "14 SIGALRM", .number = 14 },
|
||||||
|
{ .name = "15 SIGTERM", .number = 15 },
|
||||||
|
{ .name = "16 SIGUSR1", .number = 16 },
|
||||||
|
{ .name = "17 SIGUSR2", .number = 17 },
|
||||||
|
{ .name = "18 SIGCHLD/CLD", .number = 18 },
|
||||||
|
{ .name = "19 SIGPWR", .number = 19 },
|
||||||
|
{ .name = "20 SIGWINCH", .number = 20 },
|
||||||
|
{ .name = "21 SIGURG", .number = 21 },
|
||||||
|
{ .name = "22 SIGPOLL/IO", .number = 22 },
|
||||||
|
{ .name = "23 SIGSTOP", .number = 23 },
|
||||||
|
{ .name = "24 SIGTSTP", .number = 24 },
|
||||||
|
{ .name = "25 SIGCONT", .number = 25 },
|
||||||
|
{ .name = "26 SIGTTIN", .number = 26 },
|
||||||
|
{ .name = "27 SIGTTOU", .number = 27 },
|
||||||
|
{ .name = "28 SIGVTALRM", .number = 28 },
|
||||||
|
{ .name = "29 SIGPROF", .number = 29 },
|
||||||
|
{ .name = "30 SIGXCPU", .number = 30 },
|
||||||
|
{ .name = "31 SIGXFSZ", .number = 31 },
|
||||||
|
{ .name = "32 SIGWAITING", .number = 32 },
|
||||||
|
{ .name = "33 SIGLWP", .number = 33 },
|
||||||
|
{ .name = "34 SIGFREEZE", .number = 34 },
|
||||||
|
{ .name = "35 SIGTHAW", .number = 35 },
|
||||||
|
{ .name = "36 SIGCANCEL", .number = 36 },
|
||||||
|
{ .name = "37 SIGLOST", .number = 37 },
|
||||||
|
{ .name = "38 SIGXRES", .number = 38 },
|
||||||
|
{ .name = "39 SIGJVM1", .number = 39 },
|
||||||
|
{ .name = "40 SIGJVM2", .number = 40 },
|
||||||
|
{ .name = "41 SIGINFO", .number = 41 },
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||||
|
|
||||||
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Default",
|
||||||
|
.columns = "PID LWPID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
|
MeterClass* Platform_meterTypes[] = {
|
||||||
|
&CPUMeter_class,
|
||||||
|
&ClockMeter_class,
|
||||||
|
&LoadAverageMeter_class,
|
||||||
|
&LoadMeter_class,
|
||||||
|
&MemoryMeter_class,
|
||||||
|
&SwapMeter_class,
|
||||||
|
&TasksMeter_class,
|
||||||
|
&BatteryMeter_class,
|
||||||
|
&HostnameMeter_class,
|
||||||
|
&UptimeMeter_class,
|
||||||
|
&AllCPUsMeter_class,
|
||||||
|
&AllCPUs2Meter_class,
|
||||||
|
&LeftCPUsMeter_class,
|
||||||
|
&RightCPUsMeter_class,
|
||||||
|
&LeftCPUs2Meter_class,
|
||||||
|
&RightCPUs2Meter_class,
|
||||||
|
&BlankMeter_class,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
void Platform_setBindings(Htop_Action* keys) {
|
||||||
|
(void) keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
|
int Platform_getUptime() {
|
||||||
|
int boot_time = 0;
|
||||||
|
int curr_time = time(NULL);
|
||||||
|
struct utmpx * ent;
|
||||||
|
|
||||||
|
while (( ent = getutxent() )) {
|
||||||
|
if ( !strcmp("system boot", ent->ut_line )) {
|
||||||
|
boot_time = ent->ut_tv.tv_sec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endutxent();
|
||||||
|
|
||||||
|
return (curr_time-boot_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||||
|
getloadavg( plat_loadavg, 3 );
|
||||||
|
*one = plat_loadavg[LOADAVG_1MIN];
|
||||||
|
*five = plat_loadavg[LOADAVG_5MIN];
|
||||||
|
*fifteen = plat_loadavg[LOADAVG_15MIN];
|
||||||
|
}
|
||||||
|
|
||||||
|
int Platform_getMaxPid() {
|
||||||
|
kstat_ctl_t *kc = NULL;
|
||||||
|
kstat_t *kshandle = NULL;
|
||||||
|
kvar_t *ksvar = NULL;
|
||||||
|
int vproc = 32778; // Reasonable Solaris default
|
||||||
|
kc = kstat_open();
|
||||||
|
if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); }
|
||||||
|
if (kshandle != NULL) { kstat_read(kc,kshandle,NULL); }
|
||||||
|
ksvar = kshandle->ks_data;
|
||||||
|
if (ksvar->v_proc > 0 ) {
|
||||||
|
vproc = ksvar->v_proc;
|
||||||
|
}
|
||||||
|
if (kc != NULL) { kstat_close(kc); }
|
||||||
|
return vproc;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Platform_setCPUValues(Meter* this, int cpu) {
|
||||||
|
SolarisProcessList* spl = (SolarisProcessList*) this->pl;
|
||||||
|
int cpus = this->pl->cpuCount;
|
||||||
|
CPUData* cpuData = NULL;
|
||||||
|
|
||||||
|
if (cpus == 1) {
|
||||||
|
// single CPU box has everything in spl->cpus[0]
|
||||||
|
cpuData = &(spl->cpus[0]);
|
||||||
|
} else {
|
||||||
|
cpuData = &(spl->cpus[cpu]);
|
||||||
|
}
|
||||||
|
|
||||||
|
double percent;
|
||||||
|
double* v = this->values;
|
||||||
|
|
||||||
|
v[CPU_METER_NICE] = cpuData->nicePercent;
|
||||||
|
v[CPU_METER_NORMAL] = cpuData->userPercent;
|
||||||
|
if (this->pl->settings->detailedCPUTime) {
|
||||||
|
v[CPU_METER_KERNEL] = cpuData->systemPercent;
|
||||||
|
v[CPU_METER_IRQ] = cpuData->irqPercent;
|
||||||
|
Meter_setItems(this, 4);
|
||||||
|
percent = v[0]+v[1]+v[2]+v[3];
|
||||||
|
} else {
|
||||||
|
v[2] = cpuData->systemAllPercent;
|
||||||
|
Meter_setItems(this, 3);
|
||||||
|
percent = v[0]+v[1]+v[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
percent = CLAMP(percent, 0.0, 100.0);
|
||||||
|
if (isnan(percent)) percent = 0.0;
|
||||||
|
return percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_setMemoryValues(Meter* this) {
|
||||||
|
ProcessList* pl = (ProcessList*) this->pl;
|
||||||
|
this->total = pl->totalMem;
|
||||||
|
this->values[0] = pl->usedMem;
|
||||||
|
this->values[1] = pl->buffersMem;
|
||||||
|
this->values[2] = pl->cachedMem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_setSwapValues(Meter* this) {
|
||||||
|
ProcessList* pl = (ProcessList*) this->pl;
|
||||||
|
this->total = pl->totalSwap;
|
||||||
|
this->values[0] = pl->usedSwap;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) {
|
||||||
|
envAccum *accump = accum;
|
||||||
|
(void) Phandle;
|
||||||
|
(void) addr;
|
||||||
|
size_t thissz = strlen(str);
|
||||||
|
if ((thissz + 2) > (accump->capacity - accump->size))
|
||||||
|
accump->env = xRealloc(accump->env, accump->capacity *= 2);
|
||||||
|
if ((thissz + 2) > (accump->capacity - accump->size))
|
||||||
|
return 1;
|
||||||
|
strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size));
|
||||||
|
strncpy( accump->env + accump->size + thissz + 1, "\n", 1);
|
||||||
|
accump->size = accump->size + thissz + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* Platform_getProcessEnv(pid_t pid) {
|
||||||
|
envAccum envBuilder;
|
||||||
|
pid_t realpid = pid / 1024;
|
||||||
|
int graberr;
|
||||||
|
struct ps_prochandle *Phandle;
|
||||||
|
|
||||||
|
if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL)
|
||||||
|
return "Unable to read process environment.";
|
||||||
|
|
||||||
|
envBuilder.capacity = 4096;
|
||||||
|
envBuilder.size = 0;
|
||||||
|
envBuilder.env = xMalloc(envBuilder.capacity);
|
||||||
|
|
||||||
|
(void) Penv_iter(Phandle,Platform_buildenv,&envBuilder);
|
||||||
|
|
||||||
|
Prelease(Phandle, 0);
|
||||||
|
|
||||||
|
strncpy( envBuilder.env + envBuilder.size, "\0", 1);
|
||||||
|
return envBuilder.env;
|
||||||
|
}
|
68
solaris/Platform.h
Normal file
68
solaris/Platform.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_Platform
|
||||||
|
#define HEADER_Platform
|
||||||
|
/*
|
||||||
|
htop - solaris/Platform.h
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2015 David C. Hunt
|
||||||
|
(C) 2017,2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Action.h"
|
||||||
|
#include "BatteryMeter.h"
|
||||||
|
#include "SignalsPanel.h"
|
||||||
|
#include "SolarisProcess.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/mkdev.h>
|
||||||
|
#include <sys/proc.h>
|
||||||
|
#include <libproc.h>
|
||||||
|
|
||||||
|
#define kill(pid, signal) kill(pid / 1024, signal)
|
||||||
|
|
||||||
|
extern ProcessFieldData Process_fields[];
|
||||||
|
typedef struct var kvar_t;
|
||||||
|
|
||||||
|
typedef struct envAccum_ {
|
||||||
|
size_t capacity;
|
||||||
|
size_t size;
|
||||||
|
size_t bytes;
|
||||||
|
char *env;
|
||||||
|
} envAccum;
|
||||||
|
|
||||||
|
|
||||||
|
extern double plat_loadavg[3];
|
||||||
|
|
||||||
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfSignals;
|
||||||
|
|
||||||
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
|
extern MeterClass* Platform_meterTypes[];
|
||||||
|
|
||||||
|
void Platform_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
|
int Platform_getUptime();
|
||||||
|
|
||||||
|
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||||
|
|
||||||
|
int Platform_getMaxPid();
|
||||||
|
|
||||||
|
double Platform_setCPUValues(Meter* this, int cpu);
|
||||||
|
|
||||||
|
void Platform_setMemoryValues(Meter* this);
|
||||||
|
|
||||||
|
void Platform_setSwapValues(Meter* this);
|
||||||
|
|
||||||
|
char* Platform_getProcessEnv(pid_t pid);
|
||||||
|
|
||||||
|
#endif
|
32
solaris/SolarisCRT.c
Normal file
32
solaris/SolarisCRT.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
htop - SolarisCRT.c
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void CRT_handleSIGSEGV(int sgn) {
|
||||||
|
(void) sgn;
|
||||||
|
CRT_done();
|
||||||
|
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||||
|
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||||
|
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||||
|
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||||
|
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||||
|
fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump");
|
||||||
|
fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report.");
|
||||||
|
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||||
|
#endif
|
||||||
|
abort();
|
||||||
|
}
|
18
solaris/SolarisCRT.h
Normal file
18
solaris/SolarisCRT.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_SolarisCRT
|
||||||
|
#define HEADER_SolarisCRT
|
||||||
|
/*
|
||||||
|
htop - SolarisCRT.h
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
|
#endif
|
214
solaris/SolarisProcess.c
Normal file
214
solaris/SolarisProcess.c
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
/*
|
||||||
|
htop - SolarisProcess.c
|
||||||
|
(C) 2015 Hisham H. Muhammad
|
||||||
|
(C) 2017,2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Process.h"
|
||||||
|
#include "ProcessList.h"
|
||||||
|
#include "SolarisProcess.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
|
/*{
|
||||||
|
#include "Settings.h"
|
||||||
|
#include <zone.h>
|
||||||
|
#include <sys/proc.h>
|
||||||
|
#include <libproc.h>
|
||||||
|
|
||||||
|
typedef enum SolarisProcessFields {
|
||||||
|
// Add platform-specific fields here, with ids >= 100
|
||||||
|
ZONEID = 100,
|
||||||
|
ZONE = 101,
|
||||||
|
PROJID = 102,
|
||||||
|
TASKID = 103,
|
||||||
|
POOLID = 104,
|
||||||
|
CONTID = 105,
|
||||||
|
LWPID = 106,
|
||||||
|
LAST_PROCESSFIELD = 107,
|
||||||
|
} SolarisProcessField;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct SolarisProcess_ {
|
||||||
|
Process super;
|
||||||
|
int kernel;
|
||||||
|
zoneid_t zoneid;
|
||||||
|
char* zname;
|
||||||
|
taskid_t taskid;
|
||||||
|
projid_t projid;
|
||||||
|
poolid_t poolid;
|
||||||
|
ctid_t contid;
|
||||||
|
bool is_lwp;
|
||||||
|
pid_t realpid;
|
||||||
|
pid_t realppid;
|
||||||
|
pid_t lwpid;
|
||||||
|
} SolarisProcess;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef Process_isKernelThread
|
||||||
|
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef Process_isUserlandThread
|
||||||
|
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
ProcessClass SolarisProcess_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Process),
|
||||||
|
.display = Process_display,
|
||||||
|
.delete = Process_delete,
|
||||||
|
.compare = SolarisProcess_compare
|
||||||
|
},
|
||||||
|
.writeField = (Process_WriteField) SolarisProcess_writeField,
|
||||||
|
};
|
||||||
|
|
||||||
|
ProcessFieldData Process_fields[] = {
|
||||||
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
|
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||||
|
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
||||||
|
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, O onproc, Z zombie, T stopped, W waiting)", .flags = 0, },
|
||||||
|
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||||
|
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||||
|
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||||
|
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||||
|
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||||
|
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||||
|
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||||
|
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
|
||||||
|
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
|
||||||
|
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
|
||||||
|
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
||||||
|
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
||||||
|
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||||
|
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||||
|
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||||
|
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||||
|
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||||
|
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||||
|
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||||
|
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||||
|
[ZONEID] = { .name = "ZONEID", .title = " ZONEID ", .description = "Zone ID", .flags = 0, },
|
||||||
|
[ZONE] = { .name = "ZONE", .title = "ZONE ", .description = "Zone name", .flags = 0, },
|
||||||
|
[PROJID] = { .name = "PROJID", .title = " PRJID ", .description = "Project ID", .flags = 0, },
|
||||||
|
[TASKID] = { .name = "TASKID", .title = " TSKID ", .description = "Task ID", .flags = 0, },
|
||||||
|
[POOLID] = { .name = "POOLID", .title = " POLID ", .description = "Pool ID", .flags = 0, },
|
||||||
|
[CONTID] = { .name = "CONTID", .title = " CNTID ", .description = "Contract ID", .flags = 0, },
|
||||||
|
[LWPID] = { .name = "LWPID", .title = " LWPID ", .description = "LWP ID", .flags = 0, },
|
||||||
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
|
};
|
||||||
|
|
||||||
|
ProcessPidColumn Process_pidColumns[] = {
|
||||||
|
{ .id = ZONEID, .label = "ZONEID" },
|
||||||
|
{ .id = TASKID, .label = "TSKID" },
|
||||||
|
{ .id = PROJID, .label = "PRJID" },
|
||||||
|
{ .id = POOLID, .label = "POLID" },
|
||||||
|
{ .id = CONTID, .label = "CNTID" },
|
||||||
|
{ .id = PID, .label = "PID" },
|
||||||
|
{ .id = PPID, .label = "PPID" },
|
||||||
|
{ .id = LWPID, .label = "LWPID" },
|
||||||
|
{ .id = TPGID, .label = "TPGID" },
|
||||||
|
{ .id = TGID, .label = "TGID" },
|
||||||
|
{ .id = PGRP, .label = "PGRP" },
|
||||||
|
{ .id = SESSION, .label = "SID" },
|
||||||
|
{ .id = 0, .label = NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
SolarisProcess* SolarisProcess_new(Settings* settings) {
|
||||||
|
SolarisProcess* this = xCalloc(1, sizeof(SolarisProcess));
|
||||||
|
Object_setClass(this, Class(SolarisProcess));
|
||||||
|
Process_init(&this->super, settings);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Process_delete(Object* cast) {
|
||||||
|
SolarisProcess* sp = (SolarisProcess*) cast;
|
||||||
|
Process_done((Process*)cast);
|
||||||
|
free(sp->zname);
|
||||||
|
free(sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||||
|
SolarisProcess* sp = (SolarisProcess*) this;
|
||||||
|
char buffer[256]; buffer[255] = '\0';
|
||||||
|
int attr = CRT_colors[DEFAULT_COLOR];
|
||||||
|
int n = sizeof(buffer) - 1;
|
||||||
|
switch ((int) field) {
|
||||||
|
// add Solaris-specific fields here
|
||||||
|
case ZONEID: xSnprintf(buffer, n, Process_pidFormat, sp->zoneid); break;
|
||||||
|
case PROJID: xSnprintf(buffer, n, Process_pidFormat, sp->projid); break;
|
||||||
|
case TASKID: xSnprintf(buffer, n, Process_pidFormat, sp->taskid); break;
|
||||||
|
case POOLID: xSnprintf(buffer, n, Process_pidFormat, sp->poolid); break;
|
||||||
|
case CONTID: xSnprintf(buffer, n, Process_pidFormat, sp->contid); break;
|
||||||
|
case ZONE:{
|
||||||
|
xSnprintf(buffer, n, "%-*s ", ZONENAME_MAX/4, sp->zname); break;
|
||||||
|
if (buffer[ZONENAME_MAX/4] != '\0') {
|
||||||
|
buffer[ZONENAME_MAX/4] = ' ';
|
||||||
|
buffer[(ZONENAME_MAX/4)+1] = '\0';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PID: xSnprintf(buffer, n, Process_pidFormat, sp->realpid); break;
|
||||||
|
case PPID: xSnprintf(buffer, n, Process_pidFormat, sp->realppid); break;
|
||||||
|
case LWPID: xSnprintf(buffer, n, Process_pidFormat, sp->lwpid); break;
|
||||||
|
default:
|
||||||
|
Process_writeField(this, str, field);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RichString_append(str, attr, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
long SolarisProcess_compare(const void* v1, const void* v2) {
|
||||||
|
SolarisProcess *p1, *p2;
|
||||||
|
Settings* settings = ((Process*)v1)->settings;
|
||||||
|
if (settings->ss->direction == 1) {
|
||||||
|
p1 = (SolarisProcess*)v1;
|
||||||
|
p2 = (SolarisProcess*)v2;
|
||||||
|
} else {
|
||||||
|
p2 = (SolarisProcess*)v1;
|
||||||
|
p1 = (SolarisProcess*)v2;
|
||||||
|
}
|
||||||
|
switch ((int) settings->ss->sortKey) {
|
||||||
|
case ZONEID:
|
||||||
|
return (p1->zoneid - p2->zoneid);
|
||||||
|
case PROJID:
|
||||||
|
return (p1->projid - p2->projid);
|
||||||
|
case TASKID:
|
||||||
|
return (p1->taskid - p2->taskid);
|
||||||
|
case POOLID:
|
||||||
|
return (p1->poolid - p2->poolid);
|
||||||
|
case CONTID:
|
||||||
|
return (p1->contid - p2->contid);
|
||||||
|
case ZONE:
|
||||||
|
return strcmp(p1->zname ? p1->zname : "global", p2->zname ? p2->zname : "global");
|
||||||
|
case PID:
|
||||||
|
return (p1->realpid - p2->realpid);
|
||||||
|
case PPID:
|
||||||
|
return (p1->realppid - p2->realppid);
|
||||||
|
case LWPID:
|
||||||
|
return (p1->lwpid - p2->lwpid);
|
||||||
|
default:
|
||||||
|
return Process_compare(v1, v2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Process_isThread(Process* this) {
|
||||||
|
SolarisProcess* fp = (SolarisProcess*) this;
|
||||||
|
|
||||||
|
if (fp->kernel == 1 ) {
|
||||||
|
return 1;
|
||||||
|
} else if (fp->is_lwp) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
72
solaris/SolarisProcess.h
Normal file
72
solaris/SolarisProcess.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_SolarisProcess
|
||||||
|
#define HEADER_SolarisProcess
|
||||||
|
/*
|
||||||
|
htop - SolarisProcess.h
|
||||||
|
(C) 2015 Hisham H. Muhammad
|
||||||
|
(C) 2017,2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Settings.h"
|
||||||
|
#include <zone.h>
|
||||||
|
#include <sys/proc.h>
|
||||||
|
#include <libproc.h>
|
||||||
|
|
||||||
|
typedef enum SolarisProcessFields {
|
||||||
|
// Add platform-specific fields here, with ids >= 100
|
||||||
|
ZONEID = 100,
|
||||||
|
ZONE = 101,
|
||||||
|
PROJID = 102,
|
||||||
|
TASKID = 103,
|
||||||
|
POOLID = 104,
|
||||||
|
CONTID = 105,
|
||||||
|
LWPID = 106,
|
||||||
|
LAST_PROCESSFIELD = 107,
|
||||||
|
} SolarisProcessField;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct SolarisProcess_ {
|
||||||
|
Process super;
|
||||||
|
int kernel;
|
||||||
|
zoneid_t zoneid;
|
||||||
|
char* zname;
|
||||||
|
taskid_t taskid;
|
||||||
|
projid_t projid;
|
||||||
|
poolid_t poolid;
|
||||||
|
ctid_t contid;
|
||||||
|
bool is_lwp;
|
||||||
|
pid_t realpid;
|
||||||
|
pid_t realppid;
|
||||||
|
pid_t lwpid;
|
||||||
|
} SolarisProcess;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef Process_isKernelThread
|
||||||
|
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef Process_isUserlandThread
|
||||||
|
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
extern ProcessClass SolarisProcess_class;
|
||||||
|
|
||||||
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
|
extern ProcessPidColumn Process_pidColumns[];
|
||||||
|
|
||||||
|
SolarisProcess* SolarisProcess_new(Settings* settings);
|
||||||
|
|
||||||
|
void Process_delete(Object* cast);
|
||||||
|
|
||||||
|
void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
|
|
||||||
|
long SolarisProcess_compare(const void* v1, const void* v2);
|
||||||
|
|
||||||
|
bool Process_isThread(Process* this);
|
||||||
|
|
||||||
|
#endif
|
373
solaris/SolarisProcessList.c
Normal file
373
solaris/SolarisProcessList.c
Normal file
@ -0,0 +1,373 @@
|
|||||||
|
/*
|
||||||
|
htop - SolarisProcessList.c
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2017,2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ProcessList.h"
|
||||||
|
#include "SolarisProcess.h"
|
||||||
|
#include "SolarisProcessList.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/user.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <procfs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#define MAXCMDLINE 255
|
||||||
|
|
||||||
|
/*{
|
||||||
|
|
||||||
|
#include <kstat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/sysconf.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
#include <sys/swap.h>
|
||||||
|
|
||||||
|
#define ZONE_ERRMSGLEN 1024
|
||||||
|
char zone_errmsg[ZONE_ERRMSGLEN];
|
||||||
|
|
||||||
|
typedef struct CPUData_ {
|
||||||
|
double userPercent;
|
||||||
|
double nicePercent;
|
||||||
|
double systemPercent;
|
||||||
|
double irqPercent;
|
||||||
|
double idlePercent;
|
||||||
|
double systemAllPercent;
|
||||||
|
uint64_t luser;
|
||||||
|
uint64_t lkrnl;
|
||||||
|
uint64_t lintr;
|
||||||
|
uint64_t lidle;
|
||||||
|
} CPUData;
|
||||||
|
|
||||||
|
typedef struct SolarisProcessList_ {
|
||||||
|
ProcessList super;
|
||||||
|
kstat_ctl_t* kd;
|
||||||
|
CPUData* cpus;
|
||||||
|
} SolarisProcessList;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
|
||||||
|
char* zname;
|
||||||
|
if ( sproc->zoneid == 0 ) {
|
||||||
|
zname = xStrdup("global ");
|
||||||
|
} else if ( kd == NULL ) {
|
||||||
|
zname = xStrdup("unknown ");
|
||||||
|
} else {
|
||||||
|
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
|
||||||
|
zname = xStrdup(ks->ks_name);
|
||||||
|
}
|
||||||
|
return zname;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||||
|
SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList));
|
||||||
|
ProcessList* pl = (ProcessList*) spl;
|
||||||
|
ProcessList_init(pl, Class(SolarisProcess), usersTable, pidWhiteList, userId);
|
||||||
|
|
||||||
|
spl->kd = kstat_open();
|
||||||
|
|
||||||
|
pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
|
||||||
|
if (pl->cpuCount == 1 ) {
|
||||||
|
spl->cpus = xRealloc(spl->cpus, sizeof(CPUData));
|
||||||
|
} else {
|
||||||
|
spl->cpus = xRealloc(spl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
|
||||||
|
}
|
||||||
|
|
||||||
|
return pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
|
||||||
|
const SolarisProcessList* spl = (SolarisProcessList*) pl;
|
||||||
|
int cpus = pl->cpuCount;
|
||||||
|
kstat_t *cpuinfo = NULL;
|
||||||
|
int kchain = 0;
|
||||||
|
kstat_named_t *idletime = NULL;
|
||||||
|
kstat_named_t *intrtime = NULL;
|
||||||
|
kstat_named_t *krnltime = NULL;
|
||||||
|
kstat_named_t *usertime = NULL;
|
||||||
|
double idlebuf = 0;
|
||||||
|
double intrbuf = 0;
|
||||||
|
double krnlbuf = 0;
|
||||||
|
double userbuf = 0;
|
||||||
|
uint64_t totaltime = 0;
|
||||||
|
int arrskip = 0;
|
||||||
|
|
||||||
|
assert(cpus > 0);
|
||||||
|
|
||||||
|
if (cpus > 1) {
|
||||||
|
// Store values for the stats loop one extra element up in the array
|
||||||
|
// to leave room for the average to be calculated afterwards
|
||||||
|
arrskip++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate per-CPU statistics first
|
||||||
|
for (int i = 0; i < cpus; i++) {
|
||||||
|
if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); }
|
||||||
|
if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); }
|
||||||
|
if (kchain != -1 ) {
|
||||||
|
idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle");
|
||||||
|
intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr");
|
||||||
|
krnltime = kstat_data_lookup(cpuinfo,"cpu_nsec_kernel");
|
||||||
|
usertime = kstat_data_lookup(cpuinfo,"cpu_nsec_user");
|
||||||
|
}
|
||||||
|
|
||||||
|
assert( (idletime != NULL) && (intrtime != NULL)
|
||||||
|
&& (krnltime != NULL) && (usertime != NULL) );
|
||||||
|
|
||||||
|
CPUData* cpuData = &(spl->cpus[i+arrskip]);
|
||||||
|
totaltime = (idletime->value.ui64 - cpuData->lidle)
|
||||||
|
+ (intrtime->value.ui64 - cpuData->lintr)
|
||||||
|
+ (krnltime->value.ui64 - cpuData->lkrnl)
|
||||||
|
+ (usertime->value.ui64 - cpuData->luser);
|
||||||
|
// Calculate percentages of deltas since last reading
|
||||||
|
cpuData->userPercent = ((usertime->value.ui64 - cpuData->luser) / (double)totaltime) * 100.0;
|
||||||
|
cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
|
||||||
|
cpuData->systemPercent = ((krnltime->value.ui64 - cpuData->lkrnl) / (double)totaltime) * 100.0;
|
||||||
|
cpuData->irqPercent = ((intrtime->value.ui64 - cpuData->lintr) / (double)totaltime) * 100.0;
|
||||||
|
cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
|
||||||
|
cpuData->idlePercent = ((idletime->value.ui64 - cpuData->lidle) / (double)totaltime) * 100.0;
|
||||||
|
// Store current values to use for the next round of deltas
|
||||||
|
cpuData->luser = usertime->value.ui64;
|
||||||
|
cpuData->lkrnl = krnltime->value.ui64;
|
||||||
|
cpuData->lintr = intrtime->value.ui64;
|
||||||
|
cpuData->lidle = idletime->value.ui64;
|
||||||
|
// Accumulate the current percentages into buffers for later average calculation
|
||||||
|
if (cpus > 1) {
|
||||||
|
userbuf += cpuData->userPercent;
|
||||||
|
krnlbuf += cpuData->systemPercent;
|
||||||
|
intrbuf += cpuData->irqPercent;
|
||||||
|
idlebuf += cpuData->idlePercent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpus > 1) {
|
||||||
|
CPUData* cpuData = &(spl->cpus[0]);
|
||||||
|
cpuData->userPercent = userbuf / cpus;
|
||||||
|
cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
|
||||||
|
cpuData->systemPercent = krnlbuf / cpus;
|
||||||
|
cpuData->irqPercent = intrbuf / cpus;
|
||||||
|
cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
|
||||||
|
cpuData->idlePercent = idlebuf / cpus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||||
|
SolarisProcessList* spl = (SolarisProcessList*) pl;
|
||||||
|
kstat_t *meminfo = NULL;
|
||||||
|
int ksrphyserr = -1;
|
||||||
|
kstat_named_t *totalmem_pgs = NULL;
|
||||||
|
kstat_named_t *lockedmem_pgs = NULL;
|
||||||
|
kstat_named_t *pages = NULL;
|
||||||
|
struct swaptable *sl = NULL;
|
||||||
|
struct swapent *swapdev = NULL;
|
||||||
|
uint64_t totalswap = 0;
|
||||||
|
uint64_t totalfree = 0;
|
||||||
|
int nswap = 0;
|
||||||
|
char *spath = NULL;
|
||||||
|
char *spathbase = NULL;
|
||||||
|
|
||||||
|
// Part 1 - physical memory
|
||||||
|
if (spl->kd != NULL) { meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); }
|
||||||
|
if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); }
|
||||||
|
if (ksrphyserr != -1) {
|
||||||
|
totalmem_pgs = kstat_data_lookup( meminfo, "physmem" );
|
||||||
|
lockedmem_pgs = kstat_data_lookup( meminfo, "pageslocked" );
|
||||||
|
pages = kstat_data_lookup( meminfo, "pagestotal" );
|
||||||
|
|
||||||
|
pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB;
|
||||||
|
pl->usedMem = lockedmem_pgs->value.ui64 * PAGE_SIZE_KB;
|
||||||
|
// Not sure how to implement this on Solaris - suggestions welcome!
|
||||||
|
pl->cachedMem = 0;
|
||||||
|
// Not really "buffers" but the best Solaris analogue that I can find to
|
||||||
|
// "memory in use but not by programs or the kernel itself"
|
||||||
|
pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * PAGE_SIZE_KB;
|
||||||
|
} else {
|
||||||
|
// Fall back to basic sysconf if kstat isn't working
|
||||||
|
pl->totalMem = sysconf(_SC_PHYS_PAGES) * PAGE_SIZE;
|
||||||
|
pl->buffersMem = 0;
|
||||||
|
pl->cachedMem = 0;
|
||||||
|
pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Part 2 - swap
|
||||||
|
nswap = swapctl(SC_GETNSWP, NULL);
|
||||||
|
if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); }
|
||||||
|
if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); }
|
||||||
|
if (spathbase != NULL) {
|
||||||
|
spath = spathbase;
|
||||||
|
swapdev = sl->swt_ent;
|
||||||
|
for (int i = 0; i < nswap; i++, swapdev++) {
|
||||||
|
swapdev->ste_path = spath;
|
||||||
|
spath += MAXPATHLEN;
|
||||||
|
}
|
||||||
|
sl->swt_n = nswap;
|
||||||
|
}
|
||||||
|
nswap = swapctl(SC_LIST, sl);
|
||||||
|
if (nswap > 0) {
|
||||||
|
swapdev = sl->swt_ent;
|
||||||
|
for (int i = 0; i < nswap; i++, swapdev++) {
|
||||||
|
totalswap += swapdev->ste_pages;
|
||||||
|
totalfree += swapdev->ste_free;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(spathbase);
|
||||||
|
free(sl);
|
||||||
|
pl->totalSwap = totalswap * PAGE_SIZE_KB;
|
||||||
|
pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessList_delete(ProcessList* pl) {
|
||||||
|
SolarisProcessList* spl = (SolarisProcessList*) pl;
|
||||||
|
ProcessList_done(pl);
|
||||||
|
free(spl->cpus);
|
||||||
|
if (spl->kd) kstat_close(spl->kd);
|
||||||
|
free(spl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* NOTE: the following is a callback function of type proc_walk_f
|
||||||
|
* and MUST conform to the appropriate definition in order
|
||||||
|
* to work. See libproc(3LIB) on a Solaris or Illumos
|
||||||
|
* system for more info.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) {
|
||||||
|
struct timeval tv;
|
||||||
|
struct tm date;
|
||||||
|
bool preExisting;
|
||||||
|
pid_t getpid;
|
||||||
|
|
||||||
|
// Setup process list
|
||||||
|
ProcessList *pl = (ProcessList*) listptr;
|
||||||
|
SolarisProcessList *spl = (SolarisProcessList*) listptr;
|
||||||
|
|
||||||
|
id_t lwpid_real = _lwpsinfo->pr_lwpid;
|
||||||
|
if (lwpid_real > 1023) return 0;
|
||||||
|
pid_t lwpid = (_psinfo->pr_pid * 1024) + lwpid_real;
|
||||||
|
bool onMasterLWP = (_lwpsinfo->pr_lwpid == _psinfo->pr_lwp.pr_lwpid);
|
||||||
|
if (onMasterLWP) {
|
||||||
|
getpid = _psinfo->pr_pid * 1024;
|
||||||
|
} else {
|
||||||
|
getpid = lwpid;
|
||||||
|
}
|
||||||
|
Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new);
|
||||||
|
SolarisProcess *sproc = (SolarisProcess*) proc;
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
|
// Common code pass 1
|
||||||
|
proc->show = false;
|
||||||
|
sproc->taskid = _psinfo->pr_taskid;
|
||||||
|
sproc->projid = _psinfo->pr_projid;
|
||||||
|
sproc->poolid = _psinfo->pr_poolid;
|
||||||
|
sproc->contid = _psinfo->pr_contract;
|
||||||
|
proc->priority = _lwpsinfo->pr_pri;
|
||||||
|
proc->nice = _lwpsinfo->pr_nice;
|
||||||
|
proc->processor = _lwpsinfo->pr_onpro;
|
||||||
|
proc->state = _lwpsinfo->pr_sname;
|
||||||
|
// NOTE: This 'percentage' is a 16-bit BINARY FRACTIONS where 1.0 = 0x8000
|
||||||
|
// Source: https://docs.oracle.com/cd/E19253-01/816-5174/proc-4/index.html
|
||||||
|
// (accessed on 18 November 2017)
|
||||||
|
proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem/(double)32768)*(double)100.0;
|
||||||
|
proc->st_uid = _psinfo->pr_euid;
|
||||||
|
proc->pgrp = _psinfo->pr_pgid;
|
||||||
|
proc->nlwp = _psinfo->pr_nlwp;
|
||||||
|
proc->tty_nr = _psinfo->pr_ttydev;
|
||||||
|
proc->m_resident = _psinfo->pr_rssize/PAGE_SIZE_KB;
|
||||||
|
proc->m_size = _psinfo->pr_size/PAGE_SIZE_KB;
|
||||||
|
|
||||||
|
if (!preExisting) {
|
||||||
|
sproc->realpid = _psinfo->pr_pid;
|
||||||
|
sproc->lwpid = lwpid_real;
|
||||||
|
sproc->zoneid = _psinfo->pr_zoneid;
|
||||||
|
sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
|
||||||
|
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
||||||
|
proc->comm = xStrdup(_psinfo->pr_fname);
|
||||||
|
proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
// End common code pass 1
|
||||||
|
|
||||||
|
if (onMasterLWP) { // Are we on the representative LWP?
|
||||||
|
proc->ppid = (_psinfo->pr_ppid * 1024);
|
||||||
|
proc->tgid = (_psinfo->pr_ppid * 1024);
|
||||||
|
sproc->realppid = _psinfo->pr_ppid;
|
||||||
|
// See note above (in common section) about this BINARY FRACTION
|
||||||
|
proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0;
|
||||||
|
proc->time = _psinfo->pr_time.tv_sec;
|
||||||
|
if(!preExisting) { // Tasks done only for NEW processes
|
||||||
|
sproc->is_lwp = false;
|
||||||
|
proc->starttime_ctime = _psinfo->pr_start.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update proc and thread counts based on settings
|
||||||
|
if (sproc->kernel && !pl->settings->hideKernelThreads) {
|
||||||
|
pl->kernelThreads += proc->nlwp;
|
||||||
|
pl->totalTasks += proc->nlwp+1;
|
||||||
|
if (proc->state == 'O') pl->runningTasks++;
|
||||||
|
} else if (!sproc->kernel) {
|
||||||
|
if (proc->state == 'O') pl->runningTasks++;
|
||||||
|
if (pl->settings->hideUserlandThreads) {
|
||||||
|
pl->totalTasks++;
|
||||||
|
} else {
|
||||||
|
pl->userlandThreads += proc->nlwp;
|
||||||
|
pl->totalTasks += proc->nlwp+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proc->show = !(pl->settings->hideKernelThreads && sproc->kernel);
|
||||||
|
} else { // We are not in the master LWP, so jump to the LWP handling code
|
||||||
|
proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0;
|
||||||
|
proc->time = _lwpsinfo->pr_time.tv_sec;
|
||||||
|
if (!preExisting) { // Tasks done only for NEW LWPs
|
||||||
|
sproc->is_lwp = true;
|
||||||
|
proc->basenameOffset = -1;
|
||||||
|
proc->ppid = _psinfo->pr_pid * 1024;
|
||||||
|
proc->tgid = _psinfo->pr_pid * 1024;
|
||||||
|
sproc->realppid = _psinfo->pr_pid;
|
||||||
|
proc->starttime_ctime = _lwpsinfo->pr_start.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top-level process only gets this for the representative LWP
|
||||||
|
if (sproc->kernel && !pl->settings->hideKernelThreads) proc->show = true;
|
||||||
|
if (!sproc->kernel && !pl->settings->hideUserlandThreads) proc->show = true;
|
||||||
|
} // Top-level LWP or subordinate LWP
|
||||||
|
|
||||||
|
// Common code pass 2
|
||||||
|
|
||||||
|
if (!preExisting) {
|
||||||
|
if ((sproc->realppid <= 0) && !(sproc->realpid <= 1)) {
|
||||||
|
sproc->kernel = true;
|
||||||
|
} else {
|
||||||
|
sproc->kernel = false;
|
||||||
|
}
|
||||||
|
(void) localtime_r((time_t*) &proc->starttime_ctime, &date);
|
||||||
|
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date);
|
||||||
|
ProcessList_add(pl, proc);
|
||||||
|
}
|
||||||
|
proc->updated = true;
|
||||||
|
|
||||||
|
// End common code pass 2
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessList_goThroughEntries(ProcessList* this) {
|
||||||
|
SolarisProcessList_scanCPUTime(this);
|
||||||
|
SolarisProcessList_scanMemoryInfo(this);
|
||||||
|
this->kernelThreads = 1;
|
||||||
|
proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP);
|
||||||
|
}
|
||||||
|
|
64
solaris/SolarisProcessList.h
Normal file
64
solaris/SolarisProcessList.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_SolarisProcessList
|
||||||
|
#define HEADER_SolarisProcessList
|
||||||
|
/*
|
||||||
|
htop - SolarisProcessList.h
|
||||||
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2017,2018 Guy M. Broome
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAXCMDLINE 255
|
||||||
|
|
||||||
|
|
||||||
|
#include <kstat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/sysconf.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
#include <sys/swap.h>
|
||||||
|
|
||||||
|
#define ZONE_ERRMSGLEN 1024
|
||||||
|
char zone_errmsg[ZONE_ERRMSGLEN];
|
||||||
|
|
||||||
|
typedef struct CPUData_ {
|
||||||
|
double userPercent;
|
||||||
|
double nicePercent;
|
||||||
|
double systemPercent;
|
||||||
|
double irqPercent;
|
||||||
|
double idlePercent;
|
||||||
|
double systemAllPercent;
|
||||||
|
uint64_t luser;
|
||||||
|
uint64_t lkrnl;
|
||||||
|
uint64_t lintr;
|
||||||
|
uint64_t lidle;
|
||||||
|
} CPUData;
|
||||||
|
|
||||||
|
typedef struct SolarisProcessList_ {
|
||||||
|
ProcessList super;
|
||||||
|
kstat_ctl_t* kd;
|
||||||
|
CPUData* cpus;
|
||||||
|
} SolarisProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc);
|
||||||
|
|
||||||
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||||
|
|
||||||
|
void ProcessList_delete(ProcessList* pl);
|
||||||
|
|
||||||
|
/* NOTE: the following is a callback function of type proc_walk_f
|
||||||
|
* and MUST conform to the appropriate definition in order
|
||||||
|
* to work. See libproc(3LIB) on a Solaris or Illumos
|
||||||
|
* system for more info.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr);
|
||||||
|
|
||||||
|
void ProcessList_goThroughEntries(ProcessList* this);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -29,7 +29,15 @@ const SignalItem Platform_signals[] = {
|
|||||||
|
|
||||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ScreenDefaults Platform_defaultScreens[] = {
|
||||||
|
{
|
||||||
|
.name = "Main",
|
||||||
|
.columns = "PID LWPID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||||
|
.sortKey = "PERCENT_CPU",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||||
|
|
||||||
ProcessFieldData Process_fields[] = {
|
ProcessFieldData Process_fields[] = {
|
||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
|
@ -19,7 +19,9 @@ extern const SignalItem Platform_signals[];
|
|||||||
|
|
||||||
extern const unsigned int Platform_numberOfSignals;
|
extern const unsigned int Platform_numberOfSignals;
|
||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ScreenDefaults Platform_defaultScreens[];
|
||||||
|
|
||||||
|
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user