mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 21:44:36 +03:00
Compare commits
185 Commits
3.0.0beta5
...
3.0.0rc1
Author | SHA1 | Date | |
---|---|---|---|
9a55efc8b5 | |||
31391b206c | |||
fed14a584d | |||
cca07e9bc9 | |||
9aa816873f | |||
0622be6ab3 | |||
54b6143cf6 | |||
5c5a599a2a | |||
e25ac8557d | |||
6b443c5da9 | |||
011125dab2 | |||
ab61ae3963 | |||
f4b0067339 | |||
1b8bed1294 | |||
a82fd262d7 | |||
cdff8aea2a | |||
b30c22d687 | |||
42c8e47cd6 | |||
0f76359e4e | |||
e833bf915f | |||
2be0992700 | |||
fb679dfb18 | |||
a7a5e356c2 | |||
dab4144f4a | |||
45ae6191c1 | |||
ed2b7791df | |||
78f4d064de | |||
e7d2f9383a | |||
97d700082c | |||
46ab1aa3bd | |||
500fb283e9 | |||
5228f5d47a | |||
74d547674d | |||
034e56b3c0 | |||
6310e5dc3a | |||
36ef4d4fb6 | |||
80ce69c44f | |||
6fbee8c1f4 | |||
00d333cc7b | |||
eef6bc447d | |||
f9625cacf0 | |||
e9947acfc6 | |||
5a17cee74d | |||
ed6f22a847 | |||
2f59798b3b | |||
9a70e43129 | |||
7ac1c709b7 | |||
579995c7c2 | |||
98e8da8bd3 | |||
7fbbf25afe | |||
e1f48c7c7c | |||
6cd1615863 | |||
c86ac5cf98 | |||
b3003f02fa | |||
dfd9279f87 | |||
b55f9320bc | |||
7fdd8d3732 | |||
f74cde982f | |||
832e77c754 | |||
8de04986cf | |||
1b4ed916b1 | |||
05c974f6cc | |||
6b5b8bab2c | |||
87c05ac136 | |||
ccf0e18414 | |||
88c9ebb8f7 | |||
37cc11253e | |||
63fbc3b517 | |||
dd33444f7e | |||
9ed47a213b | |||
12805f61d8 | |||
28840683cf | |||
18a60d668d | |||
1886117c72 | |||
a267003f2f | |||
613556faeb | |||
e450b58636 | |||
81b64691a7 | |||
909bb86f05 | |||
43728b37e7 | |||
1acfb0a752 | |||
1d5e6a27a0 | |||
9703a25d1b | |||
4b0600d8f8 | |||
7858ee6cee | |||
b0e24cd5a5 | |||
ff6914e4ad | |||
a88d2e313d | |||
fc8e9a2d3e | |||
070fe90461 | |||
a93edde1a2 | |||
92258e99e6 | |||
886eb68102 | |||
3512971084 | |||
01a1cc063f | |||
423414937b | |||
131a6c6e2b | |||
c3fadf6b69 | |||
fabe75685a | |||
078c2ddde5 | |||
fc0bf546c3 | |||
43875d94c9 | |||
08feb8585b | |||
da60309fc9 | |||
6f161e60e1 | |||
402e46bb82 | |||
90518bfc84 | |||
f49f545813 | |||
60e557868a | |||
79c939eb84 | |||
dc7d035238 | |||
6194c8dcc6 | |||
7c62db73fc | |||
a360a80d16 | |||
9139d29bbb | |||
536941fb23 | |||
ecfd6f685e | |||
f15d55c972 | |||
27fe307d22 | |||
9197adf57e | |||
41754e5632 | |||
8d7afb33e2 | |||
b7b4200f85 | |||
4cb58460e5 | |||
c39f710b52 | |||
c34be41e1c | |||
67e368914a | |||
bae27054e6 | |||
8d01ae2054 | |||
049af17be0 | |||
009837b56d | |||
bd1d719a61 | |||
ca1cce4ce7 | |||
c1fb585b6b | |||
d74b6dc8e0 | |||
060aa2b20f | |||
3d79c72e9a | |||
c005ffc3d7 | |||
48b807b0ff | |||
666e1e76b3 | |||
5f9e16b9da | |||
fd15ead51b | |||
103f1a497a | |||
08a9b051c5 | |||
e1e3791363 | |||
04cc193e3c | |||
5b38466eab | |||
34dff098c5 | |||
724aae60d1 | |||
e85b072ad0 | |||
7cfaa9dede | |||
db05ba6106 | |||
0505a7cfe1 | |||
cf04300d49 | |||
c53e384213 | |||
da4877f48c | |||
0969f83b21 | |||
155d7cbeee | |||
1ae7625c42 | |||
3c96467f7b | |||
7f40a3a5af | |||
45fad05b4a | |||
4ba06c51e5 | |||
fa18ac964c | |||
192e43c1ed | |||
75598c1389 | |||
c235b45cd6 | |||
0dbedf95a8 | |||
42c3a1fcb3 | |||
1cf8f429a5 | |||
23f96048c7 | |||
70bc51a387 | |||
442b0d2576 | |||
47cf1532b0 | |||
dc050e8088 | |||
aa3dc634dc | |||
5a75797f4d | |||
cda84fcddc | |||
69355234d0 | |||
cefbe499db | |||
76ef3682db | |||
4bd68809e4 | |||
a042cfece2 | |||
2e3c35d66d | |||
697f5bb9c1 |
@ -14,3 +14,4 @@ charset = utf-8
|
|||||||
[*.{c,h}]
|
[*.{c,h}]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 3
|
indent_size = 3
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
29
.github/workflows/ci.yml
vendored
Normal file
29
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-ubuntu-latest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
sudo apt-get install libncursesw5-dev
|
||||||
|
./autogen.sh
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
|
||||||
|
# build-macos-latest:
|
||||||
|
# runs-on: macos-latest
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v2
|
||||||
|
# - name: make
|
||||||
|
# run: |
|
||||||
|
# ./autogen.sh
|
||||||
|
# ./configure
|
||||||
|
# make
|
105
Action.c
105
Action.c
@ -26,7 +26,6 @@ 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>
|
||||||
@ -63,7 +62,7 @@ typedef struct State_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) {
|
||||||
Panel* panel = st->panel;
|
Panel* panel = st->panel;
|
||||||
Header* header = st->header;
|
Header* header = st->header;
|
||||||
Settings* settings = st->settings;
|
Settings* settings = st->settings;
|
||||||
@ -76,12 +75,12 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
|||||||
Panel* panelFocus;
|
Panel* panelFocus;
|
||||||
int ch;
|
int ch;
|
||||||
bool unfollow = false;
|
bool unfollow = false;
|
||||||
int pid = MainPanel_selectedPid((MainPanel*)panel);
|
int pid = followProcess ? MainPanel_selectedPid((MainPanel*)panel) : -1;
|
||||||
if (header->pl->following == -1) {
|
if (followProcess && header->pl->following == -1) {
|
||||||
header->pl->following = pid;
|
header->pl->following = pid;
|
||||||
unfollow = true;
|
unfollow = true;
|
||||||
}
|
}
|
||||||
ScreenManager_run(scr, &panelFocus, &ch, NULL);
|
ScreenManager_run(scr, &panelFocus, &ch);
|
||||||
if (unfollow) {
|
if (unfollow) {
|
||||||
header->pl->following = -1;
|
header->pl->following = -1;
|
||||||
}
|
}
|
||||||
@ -89,11 +88,16 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
|||||||
Panel_move(panel, 0, y);
|
Panel_move(panel, 0, y);
|
||||||
Panel_resize(panel, COLS, LINES-y-1);
|
Panel_resize(panel, COLS, LINES-y-1);
|
||||||
if (panelFocus == list && ch == 13) {
|
if (panelFocus == list && ch == 13) {
|
||||||
|
if (followProcess) {
|
||||||
Process* selected = (Process*)Panel_getSelected(panel);
|
Process* selected = (Process*)Panel_getSelected(panel);
|
||||||
if (selected && selected->pid == pid)
|
if (selected && selected->pid == pid)
|
||||||
return Panel_getSelected(list);
|
return Panel_getSelected(list);
|
||||||
else
|
else
|
||||||
beep();
|
beep();
|
||||||
|
} else {
|
||||||
|
return Panel_getSelected(list);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -107,7 +111,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, "Setup");
|
ScreenManager_run(scr, &panelFocus, &ch);
|
||||||
ScreenManager_delete(scr);
|
ScreenManager_delete(scr);
|
||||||
if (settings->changed) {
|
if (settings->changed) {
|
||||||
Header_writeBackToSettings(header);
|
Header_writeBackToSettings(header);
|
||||||
@ -172,10 +176,9 @@ static bool collapseIntoParent(Panel* panel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||||
ScreenSettings* ss = settings->ss;
|
settings->sortKey = sortKey;
|
||||||
ss->sortKey = sortKey;
|
settings->direction = 1;
|
||||||
ss->direction = 1;
|
settings->treeView = false;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,16 +186,15 @@ 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");
|
||||||
ScreenSettings* ss = st->settings->ss;
|
ProcessField* fields = st->settings->fields;
|
||||||
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] == ss->sortKey)
|
if (fields[i] == st->settings->sortKey)
|
||||||
Panel_setSelected(sortPanel, i);
|
Panel_setSelected(sortPanel, i);
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
|
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
|
||||||
if (field) {
|
if (field) {
|
||||||
reaction |= Action_setSortKey(st->settings, field->key);
|
reaction |= Action_setSortKey(st->settings, field->key);
|
||||||
}
|
}
|
||||||
@ -237,9 +239,8 @@ static Htop_Reaction actionToggleProgramPath(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionToggleTreeView(State* st) {
|
static Htop_Reaction actionToggleTreeView(State* st) {
|
||||||
ScreenSettings* ss = st->settings->ss;
|
st->settings->treeView = !st->settings->treeView;
|
||||||
ss->treeView = !ss->treeView;
|
if (st->settings->treeView) st->settings->direction = 1;
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -252,10 +253,21 @@ static Htop_Reaction actionIncFilter(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionIncSearch(State* st) {
|
static Htop_Reaction actionIncSearch(State* st) {
|
||||||
|
IncSet_reset(((MainPanel*)st->panel)->inc, INC_SEARCH);
|
||||||
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
||||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionIncNext(State* st) {
|
||||||
|
IncSet_next(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue);
|
||||||
|
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Htop_Reaction actionIncPrev(State* st) {
|
||||||
|
IncSet_prev(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue);
|
||||||
|
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||||
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionHigherPriority(State* st) {
|
static Htop_Reaction actionHigherPriority(State* st) {
|
||||||
bool changed = changePriority((MainPanel*)st->panel, -1);
|
bool changed = changePriority((MainPanel*)st->panel, -1);
|
||||||
return changed ? HTOP_REFRESH : HTOP_OK;
|
return changed ? HTOP_REFRESH : HTOP_OK;
|
||||||
@ -267,7 +279,7 @@ static Htop_Reaction actionLowerPriority(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionInvertSortOrder(State* st) {
|
static Htop_Reaction actionInvertSortOrder(State* st) {
|
||||||
ScreenSettings_invertSortOrder(st->settings->ss);
|
Settings_invertSortOrder(st->settings);
|
||||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
|
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +293,7 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
||||||
if (!st->settings->ss->treeView) {
|
if (!st->settings->treeView) {
|
||||||
return HTOP_OK;
|
return HTOP_OK;
|
||||||
}
|
}
|
||||||
bool changed = collapseIntoParent(st->panel);
|
bool changed = collapseIntoParent(st->panel);
|
||||||
@ -289,52 +301,13 @@ static Htop_Reaction actionCollapseIntoParent(State* st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||||
return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
return st->settings->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;
|
||||||
@ -348,7 +321,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
|||||||
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
|
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
|
||||||
Affinity_delete(affinity);
|
Affinity_delete(affinity);
|
||||||
|
|
||||||
void* set = Action_pickFromVector(st, affinityPanel, 15);
|
void* set = Action_pickFromVector(st, affinityPanel, 15, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL);
|
||||||
@ -362,7 +335,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
|||||||
|
|
||||||
static Htop_Reaction actionKill(State* st) {
|
static Htop_Reaction actionKill(State* st) {
|
||||||
Panel* signalsPanel = (Panel*) SignalsPanel_new();
|
Panel* signalsPanel = (Panel*) SignalsPanel_new();
|
||||||
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15);
|
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true);
|
||||||
if (sgn) {
|
if (sgn) {
|
||||||
if (sgn->key != 0) {
|
if (sgn->key != 0) {
|
||||||
Panel_setHeader(st->panel, "Sending...");
|
Panel_setHeader(st->panel, "Sending...");
|
||||||
@ -383,7 +356,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
|
|||||||
Vector_insertionSort(usersPanel->items);
|
Vector_insertionSort(usersPanel->items);
|
||||||
ListItem* allUsers = ListItem_new("All users", -1);
|
ListItem* allUsers = ListItem_new("All users", -1);
|
||||||
Panel_insert(usersPanel, 0, (Object*) allUsers);
|
Panel_insert(usersPanel, 0, (Object*) allUsers);
|
||||||
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20);
|
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false);
|
||||||
if (picked) {
|
if (picked) {
|
||||||
if (picked == allUsers) {
|
if (picked == allUsers) {
|
||||||
st->pl->userId = -1;
|
st->pl->userId = -1;
|
||||||
@ -506,7 +479,7 @@ static Htop_Reaction actionHelp(State* st) {
|
|||||||
if (settings->detailedCPUTime) {
|
if (settings->detailedCPUTime) {
|
||||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); 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_SYSTEM], "kernel"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
|
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
|
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
|
addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
|
||||||
@ -516,7 +489,7 @@ static Htop_Reaction actionHelp(State* st) {
|
|||||||
} else {
|
} else {
|
||||||
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_SYSTEM], "kernel"); addstr("/");
|
||||||
addattrstr(CRT_colors[CPU_GUEST], "virtualiz");
|
addattrstr(CRT_colors[CPU_GUEST], "virtualiz");
|
||||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||||
}
|
}
|
||||||
@ -602,6 +575,8 @@ void Action_setBindings(Htop_Action* keys) {
|
|||||||
keys['\\'] = actionIncFilter;
|
keys['\\'] = actionIncFilter;
|
||||||
keys[KEY_F(3)] = actionIncSearch;
|
keys[KEY_F(3)] = actionIncSearch;
|
||||||
keys['/'] = actionIncSearch;
|
keys['/'] = actionIncSearch;
|
||||||
|
keys['n'] = actionIncNext;
|
||||||
|
keys['N'] = actionIncPrev;
|
||||||
|
|
||||||
keys[']'] = actionHigherPriority;
|
keys[']'] = actionHigherPriority;
|
||||||
keys[KEY_F(7)] = actionHigherPriority;
|
keys[KEY_F(7)] = actionHigherPriority;
|
||||||
@ -639,7 +614,5 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
Action.h
12
Action.h
@ -39,22 +39,20 @@ typedef struct State_ {
|
|||||||
} State;
|
} State;
|
||||||
|
|
||||||
|
|
||||||
Object* Action_pickFromVector(State* st, Panel* list, int x);
|
extern Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
bool Action_setUserOnly(const char* userName, uid_t* userId);
|
extern bool Action_setUserOnly(const char* userName, uid_t* userId);
|
||||||
|
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
extern Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
Htop_Reaction Action_setScreenTab(Settings* settings, int x);
|
extern Htop_Reaction Action_follow(State* st);
|
||||||
|
|
||||||
Htop_Reaction Action_follow(State* st);
|
|
||||||
|
|
||||||
|
|
||||||
void Action_setBindings(Htop_Action* keys);
|
extern void Action_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Affinity.c
|
htop - Affinity.c
|
||||||
(C) 2004-2011 Hisham H. Muhammad
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -79,7 +80,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
|||||||
return affinity;
|
return affinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this) {
|
bool Affinity_set(Process* proc, Arg arg) {
|
||||||
|
Affinity *this = arg.v;
|
||||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||||
for (int i = 0; i < this->used; i++) {
|
for (int i = 0; i < this->used; i++) {
|
||||||
hwloc_bitmap_set(cpuset, this->cpus[i]);
|
hwloc_bitmap_set(cpuset, this->cpus[i]);
|
||||||
@ -103,7 +105,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
|||||||
return affinity;
|
return affinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this) {
|
bool Affinity_set(Process* proc, Arg arg) {
|
||||||
|
Affinity *this = arg.v;
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
CPU_ZERO(&cpuset);
|
CPU_ZERO(&cpuset);
|
||||||
for (int i = 0; i < this->used; i++) {
|
for (int i = 0; i < this->used; i++) {
|
||||||
|
15
Affinity.h
15
Affinity.h
@ -5,6 +5,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Affinity.h
|
htop - Affinity.h
|
||||||
(C) 2004-2011 Hisham H. Muhammad
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -29,23 +30,23 @@ typedef struct Affinity_ {
|
|||||||
} Affinity;
|
} Affinity;
|
||||||
|
|
||||||
|
|
||||||
Affinity* Affinity_new(ProcessList* pl);
|
extern Affinity* Affinity_new(ProcessList* pl);
|
||||||
|
|
||||||
void Affinity_delete(Affinity* this);
|
extern void Affinity_delete(Affinity* this);
|
||||||
|
|
||||||
void Affinity_add(Affinity* this, int id);
|
extern void Affinity_add(Affinity* this, int id);
|
||||||
|
|
||||||
#ifdef HAVE_LIBHWLOC
|
#ifdef HAVE_LIBHWLOC
|
||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
extern Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this);
|
extern bool Affinity_set(Process* proc, Arg arg);
|
||||||
|
|
||||||
#elif HAVE_LINUX_AFFINITY
|
#elif HAVE_LINUX_AFFINITY
|
||||||
|
|
||||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
extern Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||||
|
|
||||||
bool Affinity_set(Process* proc, Affinity* this);
|
extern bool Affinity_set(Process* proc, Arg arg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
extern PanelClass AffinityPanel_class;
|
extern PanelClass AffinityPanel_class;
|
||||||
|
|
||||||
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity);
|
extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity);
|
||||||
|
|
||||||
Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl);
|
extern Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,6 +19,6 @@ typedef struct AvailableColumnsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass AvailableColumnsPanel_class;
|
extern PanelClass AvailableColumnsPanel_class;
|
||||||
|
|
||||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns);
|
extern AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -127,7 +127,7 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
|
|||||||
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
||||||
for (int i = 1; i <= cpus; i++) {
|
for (int i = 1; i <= cpus; i++) {
|
||||||
char buffer[50];
|
char buffer[50];
|
||||||
xSnprintf(buffer, 50, "%s %d", type->uiName, i);
|
xSnprintf(buffer, 50, "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1));
|
||||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,6 +27,6 @@ typedef struct AvailableMetersPanel_ {
|
|||||||
|
|
||||||
extern PanelClass AvailableMetersPanel_class;
|
extern PanelClass AvailableMetersPanel_class;
|
||||||
|
|
||||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl);
|
extern AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
125
CPUMeter.c
125
CPUMeter.c
@ -28,13 +28,14 @@ typedef enum {
|
|||||||
CPU_METER_STEAL = 5,
|
CPU_METER_STEAL = 5,
|
||||||
CPU_METER_GUEST = 6,
|
CPU_METER_GUEST = 6,
|
||||||
CPU_METER_IOWAIT = 7,
|
CPU_METER_IOWAIT = 7,
|
||||||
CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
|
CPU_METER_FREQUENCY = 8,
|
||||||
|
CPU_METER_ITEMCOUNT = 9, // number of entries in this enum
|
||||||
} CPUMeterValues;
|
} CPUMeterValues;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
int CPUMeter_attributes[] = {
|
int CPUMeter_attributes[] = {
|
||||||
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT
|
CPU_NICE, CPU_NORMAL, CPU_SYSTEM, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
@ -63,7 +64,30 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
|
|||||||
}
|
}
|
||||||
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
|
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
|
||||||
double percent = Platform_setCPUValues(this, cpu);
|
double percent = Platform_setCPUValues(this, cpu);
|
||||||
|
if (this->pl->settings->showCPUFrequency) {
|
||||||
|
/* Initial frequency is in MHz. Emit it as GHz if it's larger than 1000MHz */
|
||||||
|
double cpuFrequency = this->values[CPU_METER_FREQUENCY];
|
||||||
|
char unit = 'M';
|
||||||
|
char cpuFrequencyBuffer[16];
|
||||||
|
if (cpuFrequency < 0) {
|
||||||
|
xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A");
|
||||||
|
} else {
|
||||||
|
if (cpuFrequency > 1000) {
|
||||||
|
cpuFrequency /= 1000;
|
||||||
|
unit = 'G';
|
||||||
|
}
|
||||||
|
xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.3f%cHz", cpuFrequency, unit);
|
||||||
|
}
|
||||||
|
if (this->pl->settings->showCPUUsage) {
|
||||||
|
xSnprintf(buffer, size, "%5.1f%% %s", percent, cpuFrequencyBuffer);
|
||||||
|
} else {
|
||||||
|
xSnprintf(buffer, size, "%s", cpuFrequencyBuffer);
|
||||||
|
}
|
||||||
|
} else if (this->pl->settings->showCPUUsage) {
|
||||||
xSnprintf(buffer, size, "%5.1f%%", percent);
|
xSnprintf(buffer, size, "%5.1f%%", percent);
|
||||||
|
} else if (size > 0) {
|
||||||
|
buffer[0] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CPUMeter_display(Object* cast, RichString* out) {
|
static void CPUMeter_display(Object* cast, RichString* out) {
|
||||||
@ -80,7 +104,7 @@ static void CPUMeter_display(Object* cast, RichString* out) {
|
|||||||
if (this->pl->settings->detailedCPUTime) {
|
if (this->pl->settings->detailedCPUTime) {
|
||||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
||||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
RichString_append(out, CRT_colors[CPU_SYSTEM], buffer);
|
||||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
||||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||||
@ -106,7 +130,7 @@ static void CPUMeter_display(Object* cast, RichString* out) {
|
|||||||
} else {
|
} else {
|
||||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
||||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
RichString_append(out, CRT_colors[CPU_SYSTEM], buffer);
|
||||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
||||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||||
@ -137,6 +161,15 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int MapClassnameToColumncount(Meter* this){
|
||||||
|
if (strchr(Meter_name(this), '4'))
|
||||||
|
return 4;
|
||||||
|
else if (strchr(Meter_name(this), '2'))
|
||||||
|
return 2;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void AllCPUsMeter_init(Meter* this) {
|
static void AllCPUsMeter_init(Meter* this) {
|
||||||
int cpus = this->pl->cpuCount;
|
int cpus = this->pl->cpuCount;
|
||||||
if (!this->drawData)
|
if (!this->drawData)
|
||||||
@ -152,10 +185,8 @@ static void AllCPUsMeter_init(Meter* this) {
|
|||||||
if (this->mode == 0)
|
if (this->mode == 0)
|
||||||
this->mode = BAR_METERMODE;
|
this->mode = BAR_METERMODE;
|
||||||
int h = Meter_modes[this->mode]->h;
|
int h = Meter_modes[this->mode]->h;
|
||||||
if (strchr(Meter_name(this), '2'))
|
int ncol = MapClassnameToColumncount(this);
|
||||||
this->h = h * ((count+1) / 2);
|
this->h = h * ((count + ncol - 1)/ ncol);
|
||||||
else
|
|
||||||
this->h = h * count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AllCPUsMeter_done(Meter* this) {
|
static void AllCPUsMeter_done(Meter* this) {
|
||||||
@ -175,10 +206,8 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) {
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Meter_setMode(meters[i], mode);
|
Meter_setMode(meters[i], mode);
|
||||||
}
|
}
|
||||||
if (strchr(Meter_name(this), '2'))
|
int ncol = MapClassnameToColumncount(this);
|
||||||
this->h = h * ((count+1) / 2);
|
this->h = h * ((count + ncol - 1)/ ncol);
|
||||||
else
|
|
||||||
this->h = h * count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
||||||
@ -209,6 +238,22 @@ static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){
|
||||||
|
Meter** meters = (Meter**) this->drawData;
|
||||||
|
int start, count;
|
||||||
|
AllCPUsMeter_getRange(this, &start, &count);
|
||||||
|
int ncol = MapClassnameToColumncount(this);
|
||||||
|
int colwidth = (w-ncol)/ncol + 1;
|
||||||
|
int diff = (w - (colwidth * ncol));
|
||||||
|
int nrows = (count + ncol - 1) / ncol;
|
||||||
|
for (int i = 0; i < count; i++){
|
||||||
|
int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer
|
||||||
|
int xpos = x + ((i / nrows) * colwidth) + d;
|
||||||
|
int ypos = y + ((i % nrows) * meters[0]->h);
|
||||||
|
meters[i]->draw(meters[i], xpos, ypos, colwidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MeterClass CPUMeter_class = {
|
MeterClass CPUMeter_class = {
|
||||||
.super = {
|
.super = {
|
||||||
.extends = Class(Meter),
|
.extends = Class(Meter),
|
||||||
@ -340,3 +385,59 @@ MeterClass RightCPUs2Meter_class = {
|
|||||||
.done = AllCPUsMeter_done
|
.done = AllCPUsMeter_done
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MeterClass AllCPUs4Meter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = CPUMeter_display
|
||||||
|
},
|
||||||
|
.defaultMode = CUSTOM_METERMODE,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = CPUMeter_attributes,
|
||||||
|
.name = "AllCPUs4",
|
||||||
|
.uiName = "CPUs (1&2&3&4/4)",
|
||||||
|
.description = "CPUs (1&2&3&4/4): all CPUs in 4 shorter columns",
|
||||||
|
.caption = "CPU",
|
||||||
|
.draw = MultiColCPUsMeter_draw,
|
||||||
|
.init = AllCPUsMeter_init,
|
||||||
|
.updateMode = AllCPUsMeter_updateMode,
|
||||||
|
.done = AllCPUsMeter_done
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass LeftCPUs4Meter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = CPUMeter_display
|
||||||
|
},
|
||||||
|
.defaultMode = CUSTOM_METERMODE,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = CPUMeter_attributes,
|
||||||
|
.name = "LeftCPUs4",
|
||||||
|
.uiName = "CPUs (1-4/8)",
|
||||||
|
.description = "CPUs (1-4/8): first half in 4 shorter columns",
|
||||||
|
.caption = "CPU",
|
||||||
|
.draw = MultiColCPUsMeter_draw,
|
||||||
|
.init = AllCPUsMeter_init,
|
||||||
|
.updateMode = AllCPUsMeter_updateMode,
|
||||||
|
.done = AllCPUsMeter_done
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass RightCPUs4Meter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = CPUMeter_display
|
||||||
|
},
|
||||||
|
.defaultMode = CUSTOM_METERMODE,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = CPUMeter_attributes,
|
||||||
|
.name = "RightCPUs4",
|
||||||
|
.uiName = "CPUs (5-8/8)",
|
||||||
|
.description = "CPUs (5-8/8): second half in 4 shorter columns",
|
||||||
|
.caption = "CPU",
|
||||||
|
.draw = MultiColCPUsMeter_draw,
|
||||||
|
.init = AllCPUsMeter_init,
|
||||||
|
.updateMode = AllCPUsMeter_updateMode,
|
||||||
|
.done = AllCPUsMeter_done
|
||||||
|
};
|
||||||
|
@ -20,7 +20,8 @@ typedef enum {
|
|||||||
CPU_METER_STEAL = 5,
|
CPU_METER_STEAL = 5,
|
||||||
CPU_METER_GUEST = 6,
|
CPU_METER_GUEST = 6,
|
||||||
CPU_METER_IOWAIT = 7,
|
CPU_METER_IOWAIT = 7,
|
||||||
CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
|
CPU_METER_FREQUENCY = 8,
|
||||||
|
CPU_METER_ITEMCOUNT = 9, // number of entries in this enum
|
||||||
} CPUMeterValues;
|
} CPUMeterValues;
|
||||||
|
|
||||||
|
|
||||||
@ -47,5 +48,10 @@ extern MeterClass LeftCPUs2Meter_class;
|
|||||||
|
|
||||||
extern MeterClass RightCPUs2Meter_class;
|
extern MeterClass RightCPUs2Meter_class;
|
||||||
|
|
||||||
|
extern MeterClass AllCPUs4Meter_class;
|
||||||
|
|
||||||
|
extern MeterClass LeftCPUs4Meter_class;
|
||||||
|
|
||||||
|
extern MeterClass RightCPUs4Meter_class;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
132
CRT.c
132
CRT.c
@ -42,7 +42,6 @@ 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
|
||||||
|
|
||||||
@ -123,23 +122,28 @@ typedef enum ColorElements_ {
|
|||||||
CPU_NICE,
|
CPU_NICE,
|
||||||
CPU_NICE_TEXT,
|
CPU_NICE_TEXT,
|
||||||
CPU_NORMAL,
|
CPU_NORMAL,
|
||||||
CPU_KERNEL,
|
CPU_SYSTEM,
|
||||||
CPU_IOWAIT,
|
CPU_IOWAIT,
|
||||||
CPU_IRQ,
|
CPU_IRQ,
|
||||||
CPU_SOFTIRQ,
|
CPU_SOFTIRQ,
|
||||||
CPU_STEAL,
|
CPU_STEAL,
|
||||||
CPU_GUEST,
|
CPU_GUEST,
|
||||||
PANEL_EDIT,
|
PRESSURE_STALL_TEN,
|
||||||
SCREENS_OTH_BORDER,
|
PRESSURE_STALL_SIXTY,
|
||||||
SCREENS_OTH_TEXT,
|
PRESSURE_STALL_THREEHUNDRED,
|
||||||
SCREENS_CUR_BORDER,
|
ZFS_MFU,
|
||||||
SCREENS_CUR_TEXT,
|
ZFS_MRU,
|
||||||
|
ZFS_ANON,
|
||||||
|
ZFS_HEADER,
|
||||||
|
ZFS_OTHER,
|
||||||
|
ZFS_COMPRESSED,
|
||||||
|
ZFS_RATIO,
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
extern void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn);
|
extern void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||||
|
|
||||||
@ -232,17 +236,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Blue,Black),
|
[CPU_NICE] = ColorPair(Blue,Black),
|
||||||
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[CPU_NORMAL] = ColorPair(Green,Black),
|
[CPU_NORMAL] = ColorPair(Green,Black),
|
||||||
[CPU_KERNEL] = ColorPair(Red,Black),
|
[CPU_SYSTEM] = ColorPair(Red,Black),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black),
|
[CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack,
|
||||||
[CPU_IRQ] = ColorPair(Yellow,Black),
|
[CPU_IRQ] = ColorPair(Yellow,Black),
|
||||||
[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),
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan,Black),
|
||||||
[SCREENS_OTH_BORDER] = ColorPair(Blue,Blue),
|
[PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan,Black),
|
||||||
[SCREENS_OTH_TEXT] = ColorPair(Black,Blue),
|
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Black),
|
||||||
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
[ZFS_MFU] = ColorPair(Blue,Black),
|
||||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
[ZFS_MRU] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_ANON] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_HEADER] = ColorPair(Cyan,Black),
|
||||||
|
[ZFS_OTHER] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Blue,Black),
|
||||||
|
[ZFS_RATIO] = ColorPair(Magenta,Black),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_MONOCHROME] = {
|
[COLORSCHEME_MONOCHROME] = {
|
||||||
[RESET_COLOR] = A_NORMAL,
|
[RESET_COLOR] = A_NORMAL,
|
||||||
@ -296,17 +305,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = A_NORMAL,
|
[CPU_NICE] = A_NORMAL,
|
||||||
[CPU_NICE_TEXT] = A_NORMAL,
|
[CPU_NICE_TEXT] = A_NORMAL,
|
||||||
[CPU_NORMAL] = A_BOLD,
|
[CPU_NORMAL] = A_BOLD,
|
||||||
[CPU_KERNEL] = A_BOLD,
|
[CPU_SYSTEM] = A_BOLD,
|
||||||
[CPU_IOWAIT] = A_NORMAL,
|
[CPU_IOWAIT] = A_NORMAL,
|
||||||
[CPU_IRQ] = A_BOLD,
|
[CPU_IRQ] = A_BOLD,
|
||||||
[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,
|
[PRESSURE_STALL_THREEHUNDRED] = A_DIM,
|
||||||
[SCREENS_OTH_BORDER] = A_DIM,
|
[PRESSURE_STALL_SIXTY] = A_NORMAL,
|
||||||
[SCREENS_OTH_TEXT] = A_DIM,
|
[PRESSURE_STALL_TEN] = A_BOLD,
|
||||||
[SCREENS_CUR_BORDER] = A_REVERSE,
|
[ZFS_MFU] = A_NORMAL,
|
||||||
[SCREENS_CUR_TEXT] = A_REVERSE,
|
[ZFS_MRU] = A_NORMAL,
|
||||||
|
[ZFS_ANON] = A_DIM,
|
||||||
|
[ZFS_HEADER] = A_BOLD,
|
||||||
|
[ZFS_OTHER] = A_DIM,
|
||||||
|
[ZFS_COMPRESSED] = A_BOLD,
|
||||||
|
[ZFS_RATIO] = A_BOLD,
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BLACKONWHITE] = {
|
[COLORSCHEME_BLACKONWHITE] = {
|
||||||
[RESET_COLOR] = ColorPair(Black,White),
|
[RESET_COLOR] = ColorPair(Black,White),
|
||||||
@ -360,17 +374,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Cyan,White),
|
[CPU_NICE] = ColorPair(Cyan,White),
|
||||||
[CPU_NICE_TEXT] = ColorPair(Cyan,White),
|
[CPU_NICE_TEXT] = ColorPair(Cyan,White),
|
||||||
[CPU_NORMAL] = ColorPair(Green,White),
|
[CPU_NORMAL] = ColorPair(Green,White),
|
||||||
[CPU_KERNEL] = ColorPair(Red,White),
|
[CPU_SYSTEM] = ColorPair(Red,White),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Black,White),
|
[CPU_IOWAIT] = A_BOLD | ColorPair(Black,White),
|
||||||
[CPU_IRQ] = ColorPair(Blue,White),
|
[CPU_IRQ] = ColorPair(Blue,White),
|
||||||
[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),
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,White),
|
||||||
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Black,White),
|
[PRESSURE_STALL_SIXTY] = ColorPair(Black,White),
|
||||||
[SCREENS_OTH_TEXT] = A_BOLD | ColorPair(Black,White),
|
[PRESSURE_STALL_TEN] = ColorPair(Black,White),
|
||||||
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
[ZFS_MFU] = ColorPair(Cyan,White),
|
||||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
[ZFS_MRU] = ColorPair(Yellow,White),
|
||||||
|
[ZFS_ANON] = ColorPair(Magenta,White),
|
||||||
|
[ZFS_HEADER] = ColorPair(Yellow,White),
|
||||||
|
[ZFS_OTHER] = ColorPair(Magenta,White),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Cyan,White),
|
||||||
|
[ZFS_RATIO] = ColorPair(Magenta,White),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_LIGHTTERMINAL] = {
|
[COLORSCHEME_LIGHTTERMINAL] = {
|
||||||
[RESET_COLOR] = ColorPair(Black,Black),
|
[RESET_COLOR] = ColorPair(Black,Black),
|
||||||
@ -424,17 +443,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Cyan,Black),
|
[CPU_NICE] = ColorPair(Cyan,Black),
|
||||||
[CPU_NICE_TEXT] = ColorPair(Cyan,Black),
|
[CPU_NICE_TEXT] = ColorPair(Cyan,Black),
|
||||||
[CPU_NORMAL] = ColorPair(Green,Black),
|
[CPU_NORMAL] = ColorPair(Green,Black),
|
||||||
[CPU_KERNEL] = ColorPair(Red,Black),
|
[CPU_SYSTEM] = ColorPair(Red,Black),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Black,Black),
|
[CPU_IOWAIT] = A_BOLD | ColorPair(Black,Black),
|
||||||
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[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),
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,Black),
|
||||||
[SCREENS_OTH_BORDER] = ColorPair(Blue,Black),
|
[PRESSURE_STALL_SIXTY] = ColorPair(Black,Black),
|
||||||
[SCREENS_OTH_TEXT] = ColorPair(Blue,Black),
|
[PRESSURE_STALL_TEN] = ColorPair(Black,Black),
|
||||||
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
[ZFS_MFU] = ColorPair(Cyan,Black),
|
||||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
[ZFS_MRU] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black),
|
||||||
|
[ZFS_HEADER] = ColorPair(Black,Black),
|
||||||
|
[ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Cyan,Black),
|
||||||
|
[ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_MIDNIGHT] = {
|
[COLORSCHEME_MIDNIGHT] = {
|
||||||
[RESET_COLOR] = ColorPair(White,Blue),
|
[RESET_COLOR] = ColorPair(White,Blue),
|
||||||
@ -488,17 +512,22 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue),
|
[CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue),
|
||||||
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue),
|
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue),
|
||||||
[CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue),
|
[CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue),
|
||||||
[CPU_KERNEL] = A_BOLD | ColorPair(Red,Blue),
|
[CPU_SYSTEM] = A_BOLD | ColorPair(Red,Blue),
|
||||||
[CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Blue),
|
[CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Blue),
|
||||||
[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue),
|
[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue),
|
||||||
[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),
|
[PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black,Blue),
|
||||||
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Yellow,Blue),
|
[PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White,Blue),
|
||||||
[SCREENS_OTH_TEXT] = ColorPair(Cyan,Blue),
|
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Blue),
|
||||||
[SCREENS_CUR_BORDER] = ColorPair(Cyan,Cyan),
|
[ZFS_MFU] = A_BOLD | ColorPair(White,Blue),
|
||||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Cyan),
|
[ZFS_MRU] = A_BOLD | ColorPair(Yellow,Blue),
|
||||||
|
[ZFS_ANON] = A_BOLD | ColorPair(Magenta,Blue),
|
||||||
|
[ZFS_HEADER] = A_BOLD | ColorPair(Yellow,Blue),
|
||||||
|
[ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue),
|
||||||
|
[ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue),
|
||||||
|
[ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue),
|
||||||
},
|
},
|
||||||
[COLORSCHEME_BLACKNIGHT] = {
|
[COLORSCHEME_BLACKNIGHT] = {
|
||||||
[RESET_COLOR] = ColorPair(Cyan,Black),
|
[RESET_COLOR] = ColorPair(Cyan,Black),
|
||||||
@ -552,21 +581,28 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||||||
[CPU_NICE] = ColorPair(Blue,Black),
|
[CPU_NICE] = ColorPair(Blue,Black),
|
||||||
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[CPU_NORMAL] = ColorPair(Green,Black),
|
[CPU_NORMAL] = ColorPair(Green,Black),
|
||||||
[CPU_KERNEL] = ColorPair(Red,Black),
|
[CPU_SYSTEM] = ColorPair(Red,Black),
|
||||||
[CPU_IOWAIT] = ColorPair(Yellow,Black),
|
[CPU_IOWAIT] = ColorPair(Yellow,Black),
|
||||||
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black),
|
||||||
[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),
|
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green,Black),
|
||||||
[SCREENS_OTH_BORDER] = ColorPair(White,Black),
|
[PRESSURE_STALL_SIXTY] = ColorPair(Green,Black),
|
||||||
[SCREENS_OTH_TEXT] = ColorPair(Cyan,Black),
|
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green,Black),
|
||||||
[SCREENS_CUR_BORDER] = A_BOLD | ColorPair(White,Black),
|
[ZFS_MFU] = ColorPair(Blue,Black),
|
||||||
[SCREENS_CUR_TEXT] = A_BOLD | ColorPair(Green,Black),
|
[ZFS_MRU] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_ANON] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_HEADER] = ColorPair(Yellow,Black),
|
||||||
|
[ZFS_OTHER] = ColorPair(Magenta,Black),
|
||||||
|
[ZFS_COMPRESSED] = ColorPair(Blue,Black),
|
||||||
|
[ZFS_RATIO] = ColorPair(Magenta,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;
|
||||||
@ -675,16 +711,12 @@ 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
|
||||||
|
48
CRT.h
48
CRT.h
@ -31,7 +31,6 @@ 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
|
||||||
|
|
||||||
@ -111,23 +110,28 @@ typedef enum ColorElements_ {
|
|||||||
CPU_NICE,
|
CPU_NICE,
|
||||||
CPU_NICE_TEXT,
|
CPU_NICE_TEXT,
|
||||||
CPU_NORMAL,
|
CPU_NORMAL,
|
||||||
CPU_KERNEL,
|
CPU_SYSTEM,
|
||||||
CPU_IOWAIT,
|
CPU_IOWAIT,
|
||||||
CPU_IRQ,
|
CPU_IRQ,
|
||||||
CPU_SOFTIRQ,
|
CPU_SOFTIRQ,
|
||||||
CPU_STEAL,
|
CPU_STEAL,
|
||||||
CPU_GUEST,
|
CPU_GUEST,
|
||||||
PANEL_EDIT,
|
PRESSURE_STALL_TEN,
|
||||||
SCREENS_OTH_BORDER,
|
PRESSURE_STALL_SIXTY,
|
||||||
SCREENS_OTH_TEXT,
|
PRESSURE_STALL_THREEHUNDRED,
|
||||||
SCREENS_CUR_BORDER,
|
ZFS_MFU,
|
||||||
SCREENS_CUR_TEXT,
|
ZFS_MRU,
|
||||||
|
ZFS_ANON,
|
||||||
|
ZFS_HEADER,
|
||||||
|
ZFS_OTHER,
|
||||||
|
ZFS_COMPRESSED,
|
||||||
|
ZFS_RATIO,
|
||||||
LAST_COLORELEMENT
|
LAST_COLORELEMENT
|
||||||
} ColorElements;
|
} ColorElements;
|
||||||
|
|
||||||
void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
extern void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn);
|
extern void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||||
|
|
||||||
@ -146,29 +150,31 @@ extern const char **CRT_treeStr;
|
|||||||
|
|
||||||
extern int CRT_delay;
|
extern int CRT_delay;
|
||||||
|
|
||||||
int* CRT_colors;
|
extern 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;
|
||||||
|
|
||||||
char* CRT_termType;
|
extern char* CRT_termType;
|
||||||
|
|
||||||
// TODO move color scheme to Settings, perhaps?
|
// TODO move color scheme to Settings, perhaps?
|
||||||
|
|
||||||
extern int CRT_colorScheme;
|
extern int CRT_colorScheme;
|
||||||
|
|
||||||
void *backtraceArray[128];
|
extern void *backtraceArray[128];
|
||||||
|
|
||||||
#if HAVE_SETUID_ENABLED
|
#if HAVE_SETUID_ENABLED
|
||||||
|
|
||||||
#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
|
#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
|
||||||
|
|
||||||
void CRT_dropPrivileges();
|
extern void CRT_dropPrivileges();
|
||||||
|
|
||||||
void CRT_restorePrivileges();
|
extern void CRT_restorePrivileges();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -183,18 +189,18 @@ void CRT_restorePrivileges();
|
|||||||
|
|
||||||
// TODO: pass an instance of Settings instead.
|
// TODO: pass an instance of Settings instead.
|
||||||
|
|
||||||
void CRT_init(int delay, int colorScheme);
|
extern void CRT_init(int delay, int colorScheme);
|
||||||
|
|
||||||
void CRT_done();
|
extern void CRT_done();
|
||||||
|
|
||||||
void CRT_fatalError(const char* note);
|
extern void CRT_fatalError(const char* note);
|
||||||
|
|
||||||
int CRT_readKey();
|
extern int CRT_readKey();
|
||||||
|
|
||||||
void CRT_disableDelay();
|
extern void CRT_disableDelay();
|
||||||
|
|
||||||
void CRT_enableDelay();
|
extern void CRT_enableDelay();
|
||||||
|
|
||||||
void CRT_setColors(int colorScheme);
|
extern void CRT_setColors(int colorScheme);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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 "ScreensPanel.h"
|
#include "ColumnsPanel.h"
|
||||||
#include "ColorsPanel.h"
|
#include "ColorsPanel.h"
|
||||||
#include "AvailableColumnsPanel.h"
|
#include "AvailableColumnsPanel.h"
|
||||||
|
|
||||||
@ -64,11 +64,9 @@ static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
|||||||
ScreenManager_add(this->scr, colors, -1);
|
ScreenManager_add(this->scr, colors, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CategoriesPanel_makeScreensPage(CategoriesPanel* this) {
|
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
||||||
Panel* screens = (Panel*) ScreensPanel_new(this->settings);
|
Panel* columns = (Panel*) ColumnsPanel_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);
|
||||||
}
|
}
|
||||||
@ -120,7 +118,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
|||||||
CategoriesPanel_makeColorsPage(this);
|
CategoriesPanel_makeColorsPage(this);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
CategoriesPanel_makeScreensPage(this);
|
CategoriesPanel_makeColumnsPage(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,10 +143,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, "Categories");
|
Panel_setHeader(super, "Setup");
|
||||||
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("Screens", 0));
|
Panel_add(super, (Object*) ListItem_new("Columns", 0));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ typedef struct CategoriesPanel_ {
|
|||||||
} CategoriesPanel;
|
} CategoriesPanel;
|
||||||
|
|
||||||
|
|
||||||
void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
|
extern void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
|
||||||
|
|
||||||
extern PanelClass CategoriesPanel_class;
|
extern PanelClass CategoriesPanel_class;
|
||||||
|
|
||||||
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl);
|
extern CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,12 +21,12 @@ typedef struct CheckItem_ {
|
|||||||
|
|
||||||
extern ObjectClass CheckItem_class;
|
extern ObjectClass CheckItem_class;
|
||||||
|
|
||||||
CheckItem* CheckItem_newByRef(char* text, bool* ref);
|
extern CheckItem* CheckItem_newByRef(char* text, bool* ref);
|
||||||
|
|
||||||
CheckItem* CheckItem_newByVal(char* text, bool value);
|
extern CheckItem* CheckItem_newByVal(char* text, bool value);
|
||||||
|
|
||||||
void CheckItem_set(CheckItem* this, bool value);
|
extern void CheckItem_set(CheckItem* this, bool value);
|
||||||
|
|
||||||
bool CheckItem_get(CheckItem* this);
|
extern bool CheckItem_get(CheckItem* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,6 +29,6 @@ typedef struct ColorsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass ColorsPanel_class;
|
extern PanelClass ColorsPanel_class;
|
||||||
|
|
||||||
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
|
extern ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,9 +22,8 @@ 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;
|
||||||
|
|
||||||
@ -124,31 +123,22 @@ PanelClass ColumnsPanel_class = {
|
|||||||
.eventHandler = ColumnsPanel_eventHandler
|
.eventHandler = ColumnsPanel_eventHandler
|
||||||
};
|
};
|
||||||
|
|
||||||
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss) {
|
ColumnsPanel* ColumnsPanel_new(Settings* settings) {
|
||||||
Panel* super = (Panel*) this;
|
|
||||||
Panel_prune(super);
|
|
||||||
ProcessField* fields = ss->fields;
|
|
||||||
for (; *fields; fields++) {
|
|
||||||
if (Process_fields[*fields].name) {
|
|
||||||
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);
|
ColumnsPanel* this = AllocThis(ColumnsPanel);
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
|
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
|
||||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||||
|
|
||||||
this->ss = ss;
|
this->settings = settings;
|
||||||
this->changed = changed;
|
|
||||||
this->moving = false;
|
this->moving = false;
|
||||||
Panel_setHeader(super, "Active Columns");
|
Panel_setHeader(super, "Active Columns");
|
||||||
|
|
||||||
ColumnsPanel_fill(this, ss);
|
ProcessField* fields = this->settings->fields;
|
||||||
|
for (; *fields; fields++) {
|
||||||
|
if (Process_fields[*fields].name) {
|
||||||
|
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,14 +154,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->changed) = true;
|
this->settings->changed = true;
|
||||||
this->ss->fields = xRealloc(this->ss->fields, sizeof(ProcessField) * (size+1));
|
this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1));
|
||||||
this->ss->flags = 0;
|
this->settings->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->ss->fields[i] = key;
|
this->settings->fields[i] = key;
|
||||||
this->ss->flags |= key < 1000 ? Process_fields[key].flags : 0;
|
this->settings->flags |= Process_fields[key].flags;
|
||||||
}
|
}
|
||||||
this->ss->fields[size] = 0;
|
this->settings->fields[size] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,22 +14,19 @@ 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;
|
||||||
|
|
||||||
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss);
|
extern ColumnsPanel* ColumnsPanel_new(Settings* settings);
|
||||||
|
|
||||||
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, bool* changed);
|
extern int ColumnsPanel_fieldNameToIndex(const char* name);
|
||||||
|
|
||||||
int ColumnsPanel_fieldNameToIndex(const char* name);
|
extern void ColumnsPanel_update(Panel* super);
|
||||||
|
|
||||||
void ColumnsPanel_update(Panel* super);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,6 +83,7 @@ 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)));
|
||||||
@ -96,6 +97,8 @@ 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)));
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU percentage numerically"), &(settings->showCPUUsage)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Also show CPU frequency"), &(settings->showCPUFrequency)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Enable the mouse"), &(settings->enableMouse)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ typedef struct DisplayOptionsPanel_ {
|
|||||||
|
|
||||||
extern PanelClass DisplayOptionsPanel_class;
|
extern PanelClass DisplayOptionsPanel_class;
|
||||||
|
|
||||||
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
|
extern DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,12 +11,12 @@ typedef struct EnvScreen_ {
|
|||||||
|
|
||||||
extern InfoScreenClass EnvScreen_class;
|
extern InfoScreenClass EnvScreen_class;
|
||||||
|
|
||||||
EnvScreen* EnvScreen_new(Process* process);
|
extern EnvScreen* EnvScreen_new(Process* process);
|
||||||
|
|
||||||
void EnvScreen_delete(Object* this);
|
extern void EnvScreen_delete(Object* this);
|
||||||
|
|
||||||
void EnvScreen_draw(InfoScreen* this);
|
extern void EnvScreen_draw(InfoScreen* this);
|
||||||
|
|
||||||
void EnvScreen_scan(InfoScreen* this);
|
extern void EnvScreen_scan(InfoScreen* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -96,12 +96,11 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FunctionBar_draw(const FunctionBar* this, char* buffer) {
|
void FunctionBar_draw(const FunctionBar* this, char* buffer) {
|
||||||
return FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
|
FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
void 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;
|
||||||
@ -116,10 +115,12 @@ int 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);
|
||||||
cursorX = x + strlen(buffer);
|
CRT_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) {
|
||||||
|
@ -22,18 +22,18 @@ typedef struct FunctionBar_ {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
|
extern FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
|
||||||
|
|
||||||
FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events);
|
extern FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events);
|
||||||
|
|
||||||
void FunctionBar_delete(FunctionBar* this);
|
extern void FunctionBar_delete(FunctionBar* this);
|
||||||
|
|
||||||
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
extern void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
||||||
|
|
||||||
int FunctionBar_draw(const FunctionBar* this, char* buffer);
|
extern void FunctionBar_draw(const FunctionBar* this, char* buffer);
|
||||||
|
|
||||||
int FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
extern void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
||||||
|
|
||||||
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
extern int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
12
Hashtable.h
12
Hashtable.h
@ -30,20 +30,20 @@ struct Hashtable_ {
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
int Hashtable_count(Hashtable* this);
|
extern int Hashtable_count(Hashtable* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Hashtable* Hashtable_new(int size, bool owner);
|
extern Hashtable* Hashtable_new(int size, bool owner);
|
||||||
|
|
||||||
void Hashtable_delete(Hashtable* this);
|
extern void Hashtable_delete(Hashtable* this);
|
||||||
|
|
||||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
extern void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
||||||
|
|
||||||
void* Hashtable_remove(Hashtable* this, unsigned int key);
|
extern void* Hashtable_remove(Hashtable* this, unsigned int key);
|
||||||
|
|
||||||
extern void* Hashtable_get(Hashtable* this, unsigned int key);
|
extern void* Hashtable_get(Hashtable* this, unsigned int key);
|
||||||
|
|
||||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
extern void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
9
Header.c
9
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->meterColumns[col];
|
MeterColumnSettings* colSettings = &this->settings->columns[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->meterColumns[col];
|
MeterColumnSettings* colSettings = &this->settings->columns[col];
|
||||||
|
|
||||||
String_freeArray(colSettings->names);
|
String_freeArray(colSettings->names);
|
||||||
free(colSettings->modes);
|
free(colSettings->modes);
|
||||||
@ -120,6 +120,8 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (paren)
|
||||||
|
*paren = '(';
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +213,6 @@ 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;
|
||||||
|
26
Header.h
26
Header.h
@ -31,30 +31,30 @@ typedef struct Header_ {
|
|||||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
extern Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
||||||
|
|
||||||
void Header_delete(Header* this);
|
extern void Header_delete(Header* this);
|
||||||
|
|
||||||
void Header_populateFromSettings(Header* this);
|
extern void Header_populateFromSettings(Header* this);
|
||||||
|
|
||||||
void Header_writeBackToSettings(const Header* this);
|
extern void Header_writeBackToSettings(const Header* this);
|
||||||
|
|
||||||
MeterModeId Header_addMeterByName(Header* this, char* name, int column);
|
extern MeterModeId Header_addMeterByName(Header* this, char* name, int column);
|
||||||
|
|
||||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
extern void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
||||||
|
|
||||||
Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column);
|
extern Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column);
|
||||||
|
|
||||||
int Header_size(Header* this, int column);
|
extern int Header_size(Header* this, int column);
|
||||||
|
|
||||||
char* Header_readMeterName(Header* this, int i, int column);
|
extern char* Header_readMeterName(Header* this, int i, int column);
|
||||||
|
|
||||||
MeterModeId Header_readMeterMode(Header* this, int i, int column);
|
extern MeterModeId Header_readMeterMode(Header* this, int i, int column);
|
||||||
|
|
||||||
void Header_reinit(Header* this);
|
extern void Header_reinit(Header* this);
|
||||||
|
|
||||||
void Header_draw(const Header* this);
|
extern void Header_draw(const Header* this);
|
||||||
|
|
||||||
int Header_calculateHeight(Header* this);
|
extern int Header_calculateHeight(Header* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
77
IncSet.c
77
IncSet.c
@ -38,7 +38,6 @@ 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;
|
||||||
@ -53,6 +52,10 @@ static void IncMode_reset(IncMode* mode) {
|
|||||||
mode->buffer[0] = 0;
|
mode->buffer[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IncSet_reset(IncSet* this, IncType type) {
|
||||||
|
IncMode_reset(&this->modes[type]);
|
||||||
|
}
|
||||||
|
|
||||||
static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
||||||
static const char* const searchKeys[] = {"F3", "Esc", " "};
|
static const char* const searchKeys[] = {"F3", "Esc", " "};
|
||||||
static int searchEvents[] = {KEY_F(3), 27, ERR};
|
static int searchEvents[] = {KEY_F(3), 27, ERR};
|
||||||
@ -116,33 +119,45 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool search(IncSet* this, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
static bool search(IncMode* mode, 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), this->active->buffer)) {
|
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||||
Panel_setSelected(panel, i);
|
Panel_setSelected(panel, i);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IncSet_drawBar(this, found ? CRT_colors[FUNCTION_BAR] : CRT_colors[FAILED_SEARCH]);
|
if (found)
|
||||||
|
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) {
|
static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
|
||||||
this->active = &(this->modes[type]);
|
int size = Panel_size(panel);
|
||||||
panel->currentBar = this->active->bar;
|
int here = Panel_getSelectedIndex(panel);
|
||||||
panel->cursorOn = true;
|
int i = here;
|
||||||
this->panel = panel;
|
for(;;) {
|
||||||
IncSet_drawBar(this, CRT_colors[FUNCTION_BAR]);
|
i+=step;
|
||||||
|
if (i == size) i = 0;
|
||||||
|
if (i == -1) i = size - 1;
|
||||||
|
if (i == here) return false;
|
||||||
|
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||||
|
Panel_setSelected(panel, i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IncSet_deactivate(IncSet* this, Panel* panel) {
|
bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||||
this->active = NULL;
|
return IncMode_find(&this->modes[type], panel, getPanelValue, 1);
|
||||||
Panel_setDefaultBar(panel);
|
}
|
||||||
panel->cursorOn = false;
|
|
||||||
FunctionBar_draw(this->defaultBar, NULL);
|
bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||||
|
return IncMode_find(&this->modes[type], panel, getPanelValue, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@ -154,17 +169,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||||||
bool doSearch = true;
|
bool doSearch = true;
|
||||||
if (ch == KEY_F(3)) {
|
if (ch == KEY_F(3)) {
|
||||||
if (size == 0) return true;
|
if (size == 0) return true;
|
||||||
int here = Panel_getSelectedIndex(panel);
|
IncMode_find(mode, panel, getPanelValue, 1);
|
||||||
int i = here;
|
|
||||||
for(;;) {
|
|
||||||
i++;
|
|
||||||
if (i == size) i = 0;
|
|
||||||
if (i == here) break;
|
|
||||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
|
||||||
Panel_setSelected(panel, i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doSearch = false;
|
doSearch = false;
|
||||||
} else if (ch < 255 && isprint((char)ch)) {
|
} else if (ch < 255 && isprint((char)ch)) {
|
||||||
if (mode->index < INCMODE_MAX) {
|
if (mode->index < INCMODE_MAX) {
|
||||||
@ -200,13 +205,17 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||||||
IncMode_reset(mode);
|
IncMode_reset(mode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (ch == 27) {
|
||||||
IncMode_reset(mode);
|
IncMode_reset(mode);
|
||||||
}
|
}
|
||||||
IncSet_deactivate(this, panel);
|
}
|
||||||
|
this->active = NULL;
|
||||||
|
Panel_setDefaultBar(panel);
|
||||||
|
FunctionBar_draw(this->defaultBar, NULL);
|
||||||
doSearch = false;
|
doSearch = false;
|
||||||
}
|
}
|
||||||
if (doSearch) {
|
if (doSearch) {
|
||||||
this->found = search(this, panel, getPanelValue);
|
this->found = search(mode, panel, getPanelValue);
|
||||||
}
|
}
|
||||||
if (filterChanged && lines) {
|
if (filterChanged && lines) {
|
||||||
updateWeakPanel(this, panel, lines);
|
updateWeakPanel(this, panel, lines);
|
||||||
@ -221,11 +230,15 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncSet_drawBar(IncSet* this, int attr) {
|
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||||
|
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) {
|
||||||
int cursorX = FunctionBar_drawAttr(this->active->bar, this->active->buffer, attr);
|
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||||
this->panel->cursorY = LINES - 1;
|
|
||||||
this->panel->cursorX = cursorX;
|
|
||||||
} else {
|
} else {
|
||||||
FunctionBar_draw(this->defaultBar, NULL);
|
FunctionBar_draw(this->defaultBar, NULL);
|
||||||
}
|
}
|
||||||
|
21
IncSet.h
21
IncSet.h
@ -33,7 +33,6 @@ 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;
|
||||||
@ -42,18 +41,24 @@ typedef struct IncSet_ {
|
|||||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||||
|
|
||||||
|
|
||||||
IncSet* IncSet_new(FunctionBar* bar);
|
extern void IncSet_reset(IncSet* this, IncType type);
|
||||||
|
|
||||||
void IncSet_delete(IncSet* this);
|
extern IncSet* IncSet_new(FunctionBar* bar);
|
||||||
|
|
||||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
extern void IncSet_delete(IncSet* this);
|
||||||
|
|
||||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
extern bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue);
|
||||||
|
|
||||||
const char* IncSet_getListItemValue(Panel* panel, int i);
|
extern bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue);
|
||||||
|
|
||||||
void IncSet_drawBar(IncSet* this, int attr);
|
extern bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
||||||
|
|
||||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
extern const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||||
|
|
||||||
|
extern void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||||
|
|
||||||
|
extern void IncSet_drawBar(IncSet* this);
|
||||||
|
|
||||||
|
extern int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
InfoScreen.c
14
InfoScreen.c
@ -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, CRT_colors[FUNCTION_BAR]);
|
IncSet_drawBar(this->inc);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,11 @@ void InfoScreen_run(InfoScreen* this) {
|
|||||||
|
|
||||||
Panel_draw(panel, true);
|
Panel_draw(panel, true);
|
||||||
|
|
||||||
int ch = Panel_getCh(panel);
|
if (this->inc->active) {
|
||||||
|
(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) {
|
||||||
@ -127,13 +131,15 @@ void InfoScreen_run(InfoScreen* this) {
|
|||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE) {
|
||||||
MEVENT mevent;
|
MEVENT mevent;
|
||||||
int ok = getmouse(&mevent);
|
int ok = getmouse(&mevent);
|
||||||
if (ok == OK)
|
if (ok == OK) {
|
||||||
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
||||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
||||||
ch = 0;
|
ch = 0;
|
||||||
} if (mevent.y == LINES - 1)
|
} else if (mevent.y == LINES - 1) {
|
||||||
ch = IncSet_synthesizeEvent(this->inc, mevent.x);
|
ch = IncSet_synthesizeEvent(this->inc, mevent.x);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this->inc->active) {
|
if (this->inc->active) {
|
||||||
IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines);
|
IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines);
|
||||||
|
12
InfoScreen.h
12
InfoScreen.h
@ -38,16 +38,16 @@ struct InfoScreen_ {
|
|||||||
Vector* lines;
|
Vector* lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader);
|
extern InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader);
|
||||||
|
|
||||||
InfoScreen* InfoScreen_done(InfoScreen* this);
|
extern InfoScreen* InfoScreen_done(InfoScreen* this);
|
||||||
|
|
||||||
void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...);
|
extern void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...);
|
||||||
|
|
||||||
void InfoScreen_addLine(InfoScreen* this, const char* line);
|
extern void InfoScreen_addLine(InfoScreen* this, const char* line);
|
||||||
|
|
||||||
void InfoScreen_appendLine(InfoScreen* this, const char* line);
|
extern void InfoScreen_appendLine(InfoScreen* this, const char* line);
|
||||||
|
|
||||||
void InfoScreen_run(InfoScreen* this);
|
extern void InfoScreen_run(InfoScreen* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
12
ListItem.c
12
ListItem.c
@ -27,13 +27,13 @@ typedef struct ListItem_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void ListItem_delete(Object* cast) {
|
static void ListItem_delete(Object* cast) {
|
||||||
ListItem* this = (ListItem*)cast;
|
ListItem* this = (ListItem*)cast;
|
||||||
free(this->value);
|
free(this->value);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListItem_display(Object* cast, RichString* out) {
|
static void ListItem_display(Object* cast, RichString* out) {
|
||||||
ListItem* const this = (ListItem*)cast;
|
ListItem* const this = (ListItem*)cast;
|
||||||
assert (this != NULL);
|
assert (this != NULL);
|
||||||
/*
|
/*
|
||||||
@ -59,15 +59,11 @@ ObjectClass ListItem_class = {
|
|||||||
.compare = ListItem_compare
|
.compare = ListItem_compare
|
||||||
};
|
};
|
||||||
|
|
||||||
void ListItem_init(ListItem* this, const char* value, int key) {
|
ListItem* ListItem_new(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
ListItem.h
14
ListItem.h
@ -19,21 +19,15 @@ 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);
|
extern ListItem* ListItem_new(const char* value, int key);
|
||||||
|
|
||||||
ListItem* ListItem_new(const char* value, int key);
|
extern void ListItem_append(ListItem* this, const char* text);
|
||||||
|
|
||||||
void ListItem_append(ListItem* this, const char* text);
|
extern const char* ListItem_getRef(ListItem* this);
|
||||||
|
|
||||||
const char* ListItem_getRef(ListItem* this);
|
extern long ListItem_compare(const void* cast1, const void* cast2);
|
||||||
|
|
||||||
long ListItem_compare(const void* cast1, const void* cast2);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
24
MainPanel.c
24
MainPanel.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - ColumnsPanel.c
|
htop - ColumnsPanel.c
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -25,11 +26,6 @@ typedef struct MainPanel_ {
|
|||||||
pid_t pidSearch;
|
pid_t pidSearch;
|
||||||
} MainPanel;
|
} MainPanel;
|
||||||
|
|
||||||
typedef union {
|
|
||||||
int i;
|
|
||||||
void* v;
|
|
||||||
} Arg;
|
|
||||||
|
|
||||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||||
|
|
||||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||||
@ -72,26 +68,20 @@ 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 == ss->sortKey) {
|
if (field == settings->sortKey) {
|
||||||
ScreenSettings_invertSortOrder(ss);
|
Settings_invertSortOrder(settings);
|
||||||
ss->treeView = false;
|
settings->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) {
|
||||||
@ -119,8 +109,8 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reaction & HTOP_REDRAW_BAR) {
|
if (reaction & HTOP_REDRAW_BAR) {
|
||||||
MainPanel_updateTreeFunctions(this, settings->ss->treeView);
|
MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
|
||||||
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
IncSet_drawBar(this->inc);
|
||||||
}
|
}
|
||||||
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));
|
||||||
|
22
MainPanel.h
22
MainPanel.h
@ -5,6 +5,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - ColumnsPanel.h
|
htop - ColumnsPanel.h
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -21,32 +22,27 @@ typedef struct MainPanel_ {
|
|||||||
pid_t pidSearch;
|
pid_t pidSearch;
|
||||||
} MainPanel;
|
} MainPanel;
|
||||||
|
|
||||||
typedef union {
|
|
||||||
int i;
|
|
||||||
void* v;
|
|
||||||
} Arg;
|
|
||||||
|
|
||||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||||
|
|
||||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||||
|
|
||||||
|
|
||||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
extern void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
||||||
|
|
||||||
void MainPanel_pidSearch(MainPanel* this, int ch);
|
extern void MainPanel_pidSearch(MainPanel* this, int ch);
|
||||||
|
|
||||||
int MainPanel_selectedPid(MainPanel* this);
|
extern int MainPanel_selectedPid(MainPanel* this);
|
||||||
|
|
||||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
extern const char* MainPanel_getValue(MainPanel* this, int i);
|
||||||
|
|
||||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged);
|
extern bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged);
|
||||||
|
|
||||||
extern PanelClass MainPanel_class;
|
extern PanelClass MainPanel_class;
|
||||||
|
|
||||||
MainPanel* MainPanel_new();
|
extern MainPanel* MainPanel_new();
|
||||||
|
|
||||||
void MainPanel_setState(MainPanel* this, State* state);
|
extern void MainPanel_setState(MainPanel* this, State* state);
|
||||||
|
|
||||||
void MainPanel_delete(Object* object);
|
extern void MainPanel_delete(Object* object);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
43
Makefile.am
43
Makefile.am
@ -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 ScreensPanel.c \
|
SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.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,7 +31,7 @@ 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 ScreensPanel.h \
|
ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.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
|
||||||
@ -49,15 +49,19 @@ linux_platform_headers = \
|
|||||||
linux/LinuxProcessList.h \
|
linux/LinuxProcessList.h \
|
||||||
linux/LinuxCRT.h \
|
linux/LinuxCRT.h \
|
||||||
linux/Battery.h \
|
linux/Battery.h \
|
||||||
linux/PerfCounter.h
|
linux/PressureStallMeter.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h
|
||||||
|
|
||||||
all_platform_headers += $(linux_platform_headers)
|
all_platform_headers += $(linux_platform_headers)
|
||||||
|
|
||||||
if HTOP_LINUX
|
if HTOP_LINUX
|
||||||
AM_CFLAGS += -rdynamic
|
AM_LDFLAGS += -rdynamic
|
||||||
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
||||||
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
||||||
linux/PerfCounter.c
|
linux/PressureStallMeter.c \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c
|
||||||
|
|
||||||
myhtopplatheaders = $(linux_platform_headers)
|
myhtopplatheaders = $(linux_platform_headers)
|
||||||
endif
|
endif
|
||||||
@ -70,13 +74,18 @@ freebsd_platform_headers = \
|
|||||||
freebsd/FreeBSDProcessList.h \
|
freebsd/FreeBSDProcessList.h \
|
||||||
freebsd/FreeBSDProcess.h \
|
freebsd/FreeBSDProcess.h \
|
||||||
freebsd/FreeBSDCRT.h \
|
freebsd/FreeBSDCRT.h \
|
||||||
freebsd/Battery.h
|
freebsd/Battery.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h \
|
||||||
|
zfs/openzfs_sysctl.h
|
||||||
|
|
||||||
all_platform_headers += $(freebsd_platform_headers)
|
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 \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c
|
||||||
|
|
||||||
myhtopplatheaders = $(freebsd_platform_headers)
|
myhtopplatheaders = $(freebsd_platform_headers)
|
||||||
endif
|
endif
|
||||||
@ -128,14 +137,19 @@ darwin_platform_headers = \
|
|||||||
darwin/DarwinProcess.h \
|
darwin/DarwinProcess.h \
|
||||||
darwin/DarwinProcessList.h \
|
darwin/DarwinProcessList.h \
|
||||||
darwin/DarwinCRT.h \
|
darwin/DarwinCRT.h \
|
||||||
darwin/Battery.h
|
darwin/Battery.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h \
|
||||||
|
zfs/openzfs_sysctl.h
|
||||||
|
|
||||||
all_platform_headers += $(darwin_platform_headers)
|
all_platform_headers += $(darwin_platform_headers)
|
||||||
|
|
||||||
if HTOP_DARWIN
|
if HTOP_DARWIN
|
||||||
AM_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 \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c zfs/openzfs_sysctl.c
|
||||||
|
|
||||||
myhtopplatheaders = $(darwin_platform_headers)
|
myhtopplatheaders = $(darwin_platform_headers)
|
||||||
endif
|
endif
|
||||||
@ -148,14 +162,18 @@ solaris_platform_headers = \
|
|||||||
solaris/SolarisProcess.h \
|
solaris/SolarisProcess.h \
|
||||||
solaris/SolarisProcessList.h \
|
solaris/SolarisProcessList.h \
|
||||||
solaris/SolarisCRT.h \
|
solaris/SolarisCRT.h \
|
||||||
solaris/Battery.h
|
solaris/Battery.h \
|
||||||
|
zfs/ZfsArcMeter.h \
|
||||||
|
zfs/ZfsCompressedArcMeter.h \
|
||||||
|
zfs/ZfsArcStats.h
|
||||||
|
|
||||||
all_platform_headers += $(solaris_platform_headers)
|
all_platform_headers += $(solaris_platform_headers)
|
||||||
|
|
||||||
if HTOP_SOLARIS
|
if HTOP_SOLARIS
|
||||||
myhtopplatsources = solaris/Platform.c \
|
myhtopplatsources = solaris/Platform.c \
|
||||||
solaris/SolarisProcess.c solaris/SolarisProcessList.c \
|
solaris/SolarisProcess.c solaris/SolarisProcessList.c \
|
||||||
solaris/SolarisCRT.c solaris/Battery.c
|
solaris/SolarisCRT.c solaris/Battery.c \
|
||||||
|
zfs/ZfsArcMeter.c zfs/ZfsCompressedArcMeter.c zfs/ZfsArcStats.c
|
||||||
|
|
||||||
myhtopplatheaders = $(solaris_platform_headers)
|
myhtopplatheaders = $(solaris_platform_headers)
|
||||||
endif
|
endif
|
||||||
@ -203,9 +221,6 @@ 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"
|
||||||
|
|
||||||
|
3
Meter.c
3
Meter.c
@ -523,6 +523,9 @@ MeterMode* Meter_modes[] = {
|
|||||||
|
|
||||||
static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
|
static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
(void) this; (void) buffer; (void) size;
|
(void) this; (void) buffer; (void) size;
|
||||||
|
if (size > 0) {
|
||||||
|
*buffer = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BlankMeter_display(Object* cast, RichString* out) {
|
static void BlankMeter_display(Object* cast, RichString* out) {
|
||||||
|
12
Meter.h
12
Meter.h
@ -109,17 +109,17 @@ typedef struct GraphData_ {
|
|||||||
|
|
||||||
extern MeterClass Meter_class;
|
extern MeterClass Meter_class;
|
||||||
|
|
||||||
Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
|
extern Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
|
||||||
|
|
||||||
int Meter_humanUnit(char* buffer, unsigned long int value, int size);
|
extern int Meter_humanUnit(char* buffer, unsigned long int value, int size);
|
||||||
|
|
||||||
void Meter_delete(Object* cast);
|
extern void Meter_delete(Object* cast);
|
||||||
|
|
||||||
void Meter_setCaption(Meter* this, const char* caption);
|
extern void Meter_setCaption(Meter* this, const char* caption);
|
||||||
|
|
||||||
void Meter_setMode(Meter* this, int modeIndex);
|
extern void Meter_setMode(Meter* this, int modeIndex);
|
||||||
|
|
||||||
ListItem* Meter_toListItem(Meter* this, bool moving);
|
extern ListItem* Meter_toListItem(Meter* this, bool moving);
|
||||||
|
|
||||||
/* ---------- TextMeterMode ---------- */
|
/* ---------- TextMeterMode ---------- */
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ struct MetersPanel_ {
|
|||||||
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
|
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
|
||||||
// considered "Ambiguous characters".
|
// considered "Ambiguous characters".
|
||||||
|
|
||||||
void MetersPanel_setMoving(MetersPanel* this, bool moving);
|
extern void MetersPanel_setMoving(MetersPanel* this, bool moving);
|
||||||
|
|
||||||
extern PanelClass MetersPanel_class;
|
extern PanelClass MetersPanel_class;
|
||||||
|
|
||||||
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);
|
extern MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
6
Object.c
6
Object.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Object.c
|
htop - Object.c
|
||||||
(C) 2004-2012 Hisham H. Muhammad
|
(C) 2004-2012 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -40,6 +41,11 @@ struct Object_ {
|
|||||||
ObjectClass* klass;
|
ObjectClass* klass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
int i;
|
||||||
|
void* v;
|
||||||
|
} Arg;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
ObjectClass Object_class = {
|
ObjectClass Object_class = {
|
||||||
|
8
Object.h
8
Object.h
@ -5,6 +5,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Object.h
|
htop - Object.h
|
||||||
(C) 2004-2012 Hisham H. Muhammad
|
(C) 2004-2012 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -41,12 +42,17 @@ struct Object_ {
|
|||||||
ObjectClass* klass;
|
ObjectClass* klass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
int i;
|
||||||
|
void* v;
|
||||||
|
} Arg;
|
||||||
|
|
||||||
|
|
||||||
extern ObjectClass Object_class;
|
extern ObjectClass Object_class;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
bool Object_isA(Object* o, const ObjectClass* klass);
|
extern bool Object_isA(Object* o, const ObjectClass* klass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -124,6 +124,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
|||||||
item->data[cmd] = xStrdup(line + 1);
|
item->data[cmd] = xStrdup(line + 1);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
fclose(fd);
|
||||||
int wstatus;
|
int wstatus;
|
||||||
if (waitpid(child, &wstatus, 0) == -1) {
|
if (waitpid(child, &wstatus, 0) == -1) {
|
||||||
pdata->error = 1;
|
pdata->error = 1;
|
||||||
|
@ -34,12 +34,12 @@ typedef struct OpenFilesScreen_ {
|
|||||||
|
|
||||||
extern InfoScreenClass OpenFilesScreen_class;
|
extern InfoScreenClass OpenFilesScreen_class;
|
||||||
|
|
||||||
OpenFilesScreen* OpenFilesScreen_new(Process* process);
|
extern OpenFilesScreen* OpenFilesScreen_new(Process* process);
|
||||||
|
|
||||||
void OpenFilesScreen_delete(Object* this);
|
extern void OpenFilesScreen_delete(Object* this);
|
||||||
|
|
||||||
void OpenFilesScreen_draw(InfoScreen* this);
|
extern void OpenFilesScreen_draw(InfoScreen* this);
|
||||||
|
|
||||||
void OpenFilesScreen_scan(InfoScreen* this);
|
extern void OpenFilesScreen_scan(InfoScreen* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
28
Panel.c
28
Panel.c
@ -40,12 +40,8 @@ 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);
|
||||||
|
|
||||||
@ -61,7 +57,6 @@ 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;
|
||||||
@ -71,7 +66,6 @@ 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;
|
||||||
@ -91,11 +85,6 @@ 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),
|
||||||
@ -123,8 +112,6 @@ 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;
|
||||||
@ -380,6 +367,7 @@ 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) {
|
||||||
@ -511,15 +499,3 @@ 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
59
Panel.h
59
Panel.h
@ -29,12 +29,8 @@ 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);
|
||||||
|
|
||||||
@ -50,7 +46,6 @@ 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;
|
||||||
@ -60,7 +55,6 @@ 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;
|
||||||
@ -79,59 +73,54 @@ 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);
|
extern Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
||||||
|
|
||||||
void Panel_delete(Object* cast);
|
extern void Panel_delete(Object* cast);
|
||||||
|
|
||||||
void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar);
|
extern void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar);
|
||||||
|
|
||||||
void Panel_done(Panel* this);
|
extern void Panel_done(Panel* this);
|
||||||
|
|
||||||
void Panel_setSelectionColor(Panel* this, int color);
|
extern void Panel_setSelectionColor(Panel* this, int color);
|
||||||
|
|
||||||
RichString* Panel_getHeader(Panel* this);
|
extern RichString* Panel_getHeader(Panel* this);
|
||||||
|
|
||||||
extern void Panel_setHeader(Panel* this, const char* header);
|
extern void Panel_setHeader(Panel* this, const char* header);
|
||||||
|
|
||||||
void Panel_move(Panel* this, int x, int y);
|
extern void Panel_move(Panel* this, int x, int y);
|
||||||
|
|
||||||
void Panel_resize(Panel* this, int w, int h);
|
extern void Panel_resize(Panel* this, int w, int h);
|
||||||
|
|
||||||
void Panel_prune(Panel* this);
|
extern void Panel_prune(Panel* this);
|
||||||
|
|
||||||
void Panel_add(Panel* this, Object* o);
|
extern void Panel_add(Panel* this, Object* o);
|
||||||
|
|
||||||
void Panel_insert(Panel* this, int i, Object* o);
|
extern void Panel_insert(Panel* this, int i, Object* o);
|
||||||
|
|
||||||
void Panel_set(Panel* this, int i, Object* o);
|
extern void Panel_set(Panel* this, int i, Object* o);
|
||||||
|
|
||||||
Object* Panel_get(Panel* this, int i);
|
extern Object* Panel_get(Panel* this, int i);
|
||||||
|
|
||||||
Object* Panel_remove(Panel* this, int i);
|
extern Object* Panel_remove(Panel* this, int i);
|
||||||
|
|
||||||
Object* Panel_getSelected(Panel* this);
|
extern Object* Panel_getSelected(Panel* this);
|
||||||
|
|
||||||
void Panel_moveSelectedUp(Panel* this);
|
extern void Panel_moveSelectedUp(Panel* this);
|
||||||
|
|
||||||
void Panel_moveSelectedDown(Panel* this);
|
extern void Panel_moveSelectedDown(Panel* this);
|
||||||
|
|
||||||
int Panel_getSelectedIndex(Panel* this);
|
extern int Panel_getSelectedIndex(Panel* this);
|
||||||
|
|
||||||
int Panel_size(Panel* this);
|
extern int Panel_size(Panel* this);
|
||||||
|
|
||||||
void Panel_setSelected(Panel* this, int selected);
|
extern void Panel_setSelected(Panel* this, int selected);
|
||||||
|
|
||||||
void Panel_draw(Panel* this, bool focus);
|
extern void Panel_draw(Panel* this, bool focus);
|
||||||
|
|
||||||
bool Panel_onKey(Panel* this, int key);
|
extern bool Panel_onKey(Panel* this, int key);
|
||||||
|
|
||||||
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
|
||||||
|
|
||||||
int Panel_getCh(Panel* this);
|
|
||||||
|
|
||||||
|
extern HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
110
Process.c
110
Process.c
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - Process.c
|
htop - Process.c
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -8,6 +9,8 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "RichString.h"
|
#include "RichString.h"
|
||||||
@ -30,8 +33,7 @@ in the source distribution for its full text.
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#ifdef MAJOR_IN_MKDEV
|
#ifdef MAJOR_IN_MKDEV
|
||||||
#include <sys/mkdev.h>
|
#include <sys/mkdev.h>
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
#elif defined(MAJOR_IN_SYSMACROS)
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -51,7 +53,6 @@ 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
|
||||||
|
|
||||||
@ -157,7 +158,7 @@ typedef struct ProcessFieldData_ {
|
|||||||
const char* name;
|
const char* name;
|
||||||
const char* title;
|
const char* title;
|
||||||
const char* description;
|
const char* description;
|
||||||
uint64_t flags;
|
int flags;
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
@ -192,10 +193,12 @@ static int Process_getuid = -1;
|
|||||||
#define ONE_K 1024L
|
#define ONE_K 1024L
|
||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
#define ONE_G (ONE_M * ONE_K)
|
#define ONE_G (ONE_M * ONE_K)
|
||||||
|
#define ONE_T ((long long)ONE_G * ONE_K)
|
||||||
|
|
||||||
#define ONE_DECIMAL_K 1000L
|
#define ONE_DECIMAL_K 1000L
|
||||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||||
|
#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K)
|
||||||
|
|
||||||
char Process_pidFormat[20] = "%7d ";
|
char Process_pidFormat[20] = "%7d ";
|
||||||
|
|
||||||
@ -229,7 +232,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
|||||||
if(number >= (10 * ONE_DECIMAL_M)) {
|
if(number >= (10 * ONE_DECIMAL_M)) {
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
if(number >= (100 * ONE_DECIMAL_G)) {
|
if(number >= (100 * ONE_DECIMAL_G)) {
|
||||||
len = snprintf(buffer, 10, "%4ldT ", number / ONE_G);
|
len = snprintf(buffer, 10, "%4luT ", number / ONE_G);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
} else if (number >= (1000 * ONE_DECIMAL_M)) {
|
} else if (number >= (1000 * ONE_DECIMAL_M)) {
|
||||||
@ -239,7 +242,7 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(number >= (100 * ONE_DECIMAL_M)) {
|
if(number >= (100 * ONE_DECIMAL_M)) {
|
||||||
len = snprintf(buffer, 10, "%4ldG ", number / ONE_M);
|
len = snprintf(buffer, 10, "%4luG ", number / ONE_M);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -247,11 +250,11 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
|||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
} else if (number >= 100000) {
|
} else if (number >= 100000) {
|
||||||
len = snprintf(buffer, 10, "%4ldM ", number / ONE_K);
|
len = snprintf(buffer, 10, "%4luM ", number / ONE_K);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer, len);
|
RichString_appendn(str, processMegabytesColor, buffer, len);
|
||||||
return;
|
return;
|
||||||
} else if (number >= 1000) {
|
} else if (number >= 1000) {
|
||||||
len = snprintf(buffer, 10, "%2ld", number/1000);
|
len = snprintf(buffer, 10, "%2lu", number/1000);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer, len);
|
RichString_appendn(str, processMegabytesColor, buffer, len);
|
||||||
number %= 1000;
|
number %= 1000;
|
||||||
len = snprintf(buffer, 10, "%03lu ", number);
|
len = snprintf(buffer, 10, "%03lu ", number);
|
||||||
@ -278,8 +281,15 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori
|
|||||||
if ((long long) number == -1LL) {
|
if ((long long) number == -1LL) {
|
||||||
int len = snprintf(buffer, 13, " no perm ");
|
int len = snprintf(buffer, 13, " no perm ");
|
||||||
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
|
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
|
||||||
} else if (number > 10000000000) {
|
} else if (number >= 100000LL * ONE_DECIMAL_T) {
|
||||||
xSnprintf(buffer, 13, "%11lld ", number / 1000);
|
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_G);
|
||||||
|
RichString_appendn(str, largeNumberColor, buffer, 12);
|
||||||
|
} else if (number >= 100LL * ONE_DECIMAL_T) {
|
||||||
|
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M);
|
||||||
|
RichString_appendn(str, largeNumberColor, buffer, 8);
|
||||||
|
RichString_appendn(str, processMegabytesColor, buffer+8, 4);
|
||||||
|
} else if (number >= 10LL * ONE_DECIMAL_G) {
|
||||||
|
xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, 5);
|
RichString_appendn(str, largeNumberColor, buffer, 5);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer+5, 3);
|
RichString_appendn(str, processMegabytesColor, buffer+5, 3);
|
||||||
RichString_appendn(str, processColor, buffer+8, 4);
|
RichString_appendn(str, processColor, buffer+8, 4);
|
||||||
@ -359,30 +369,18 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
|
|||||||
} else if (rate < ONE_K) {
|
} else if (rate < ONE_K) {
|
||||||
int len = snprintf(buffer, n, "%7.2f B/s ", rate);
|
int len = snprintf(buffer, n, "%7.2f B/s ", rate);
|
||||||
RichString_appendn(str, processColor, buffer, len);
|
RichString_appendn(str, processColor, buffer, len);
|
||||||
} else if (rate < ONE_K * ONE_K) {
|
} else if (rate < ONE_M) {
|
||||||
int len = snprintf(buffer, n, "%7.2f K/s ", rate / ONE_K);
|
int len = snprintf(buffer, n, "%7.2f K/s ", rate / ONE_K);
|
||||||
RichString_appendn(str, processColor, buffer, len);
|
RichString_appendn(str, processColor, buffer, len);
|
||||||
} else if (rate < ONE_K * ONE_K * ONE_K) {
|
} else if (rate < ONE_G) {
|
||||||
int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_K / ONE_K);
|
int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_M);
|
||||||
RichString_appendn(str, processMegabytesColor, buffer, len);
|
RichString_appendn(str, processMegabytesColor, buffer, len);
|
||||||
} else {
|
} else if (rate < ONE_T) {
|
||||||
int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_K / ONE_K / ONE_K);
|
int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_G);
|
||||||
RichString_appendn(str, largeNumberColor, buffer, len);
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
xSnprintf(buffer, n, "%4d ", (unsigned int)val);
|
int len = snprintf(buffer, n, "%7.2f T/s ", rate / ONE_T);
|
||||||
}
|
RichString_appendn(str, largeNumberColor, buffer, len);
|
||||||
} else {
|
|
||||||
*attr = CRT_colors[PROCESS_SHADOW];
|
|
||||||
xSnprintf(buffer, n, " N/A ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,15 +392,30 @@ 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: Process_printPercentage(this->percent_cpu, buffer, n, &attr); break;
|
case PERCENT_CPU: {
|
||||||
case PERCENT_MEM: Process_printPercentage(this->percent_mem, buffer, n, &attr); break;
|
if (this->percent_cpu > 999.9) {
|
||||||
|
xSnprintf(buffer, n, "%4u ", (unsigned int)this->percent_cpu);
|
||||||
|
} else if (this->percent_cpu > 99.9) {
|
||||||
|
xSnprintf(buffer, n, "%3u. ", (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];
|
||||||
}
|
}
|
||||||
ScreenSettings* ss = this->settings->ss;
|
if (!this->settings->treeView || this->indent == 0) {
|
||||||
if (!ss->treeView || this->indent == 0) {
|
|
||||||
Process_writeCommand(this, attr, baseattr, str);
|
Process_writeCommand(this, attr, baseattr, str);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -415,15 +428,20 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
if (indent & (1U << i))
|
if (indent & (1U << i))
|
||||||
maxIndent = i+1;
|
maxIndent = i+1;
|
||||||
for (int i = 0; i < maxIndent - 1; i++) {
|
for (int i = 0; i < maxIndent - 1; i++) {
|
||||||
int written;
|
int written, ret;
|
||||||
if (indent & (1 << i))
|
if (indent & (1 << i))
|
||||||
written = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
|
ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
|
||||||
else
|
else
|
||||||
written = snprintf(buf, n, " ");
|
ret = snprintf(buf, n, " ");
|
||||||
|
if (ret < 0 || ret >= n) {
|
||||||
|
written = n;
|
||||||
|
} else {
|
||||||
|
written = ret;
|
||||||
|
}
|
||||||
buf += written;
|
buf += written;
|
||||||
n -= written;
|
n -= written;
|
||||||
}
|
}
|
||||||
const char* draw = CRT_treeStr[lastItem ? (ss->direction == 1 ? TREE_STR_BEND : TREE_STR_TEND) : TREE_STR_RTEE];
|
const char* draw = CRT_treeStr[lastItem ? (this->settings->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);
|
||||||
@ -467,7 +485,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ST_UID: xSnprintf(buffer, n, "%4d ", this->st_uid); break;
|
case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break;
|
||||||
case TIME: Process_printTime(str, this->time); return;
|
case TIME: Process_printTime(str, this->time); return;
|
||||||
case TGID: xSnprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
case TGID: xSnprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
||||||
case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
||||||
@ -494,7 +512,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->ss->fields;
|
ProcessField* fields = this->settings->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]);
|
||||||
@ -545,14 +563,15 @@ bool Process_setPriority(Process* this, int priority) {
|
|||||||
return (err == 0);
|
return (err == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Process_changePriorityBy(Process* this, int delta) {
|
bool Process_changePriorityBy(Process* this, Arg delta) {
|
||||||
return Process_setPriority(this, this->nice + delta);
|
return Process_setPriority(this, this->nice + delta.i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, int sgn) {
|
bool Process_sendSignal(Process* this, Arg sgn) {
|
||||||
CRT_dropPrivileges();
|
CRT_dropPrivileges();
|
||||||
kill(this->pid, (int) sgn);
|
bool ok = (kill(this->pid, sgn.i) == 0);
|
||||||
CRT_restorePrivileges();
|
CRT_restorePrivileges();
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
long Process_pidCompare(const void* v1, const void* v2) {
|
long Process_pidCompare(const void* v1, const void* v2) {
|
||||||
@ -564,15 +583,14 @@ 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;
|
||||||
ScreenSettings* ss = settings->ss;
|
if (settings->direction == 1) {
|
||||||
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 (ss->sortKey) {
|
switch (settings->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:
|
||||||
|
41
Process.h
41
Process.h
@ -5,13 +5,13 @@
|
|||||||
/*
|
/*
|
||||||
htop - Process.h
|
htop - Process.h
|
||||||
(C) 2004-2015 Hisham H. Muhammad
|
(C) 2004-2015 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef MAJOR_IN_MKDEV
|
#ifdef MAJOR_IN_MKDEV
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
#elif defined(MAJOR_IN_SYSMACROS)
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
@ -29,7 +29,6 @@ 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
|
||||||
|
|
||||||
@ -135,7 +134,7 @@ typedef struct ProcessFieldData_ {
|
|||||||
const char* name;
|
const char* name;
|
||||||
const char* title;
|
const char* title;
|
||||||
const char* description;
|
const char* description;
|
||||||
uint64_t flags;
|
int flags;
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
@ -167,45 +166,45 @@ typedef struct ProcessClass_ {
|
|||||||
#define ONE_K 1024L
|
#define ONE_K 1024L
|
||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
#define ONE_G (ONE_M * ONE_K)
|
#define ONE_G (ONE_M * ONE_K)
|
||||||
|
#define ONE_T ((long long)ONE_G * ONE_K)
|
||||||
|
|
||||||
#define ONE_DECIMAL_K 1000L
|
#define ONE_DECIMAL_K 1000L
|
||||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||||
|
#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K)
|
||||||
|
|
||||||
extern char Process_pidFormat[20];
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
void Process_setupColumnWidths();
|
extern void Process_setupColumnWidths();
|
||||||
|
|
||||||
void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
extern void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
||||||
|
|
||||||
void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
extern void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
||||||
|
|
||||||
void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
extern void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
||||||
|
|
||||||
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
extern void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
||||||
|
|
||||||
void Process_printPercentage(float val, char* buffer, int n, int* attr);
|
extern void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
extern void Process_display(Object* cast, RichString* out);
|
||||||
|
|
||||||
void Process_display(Object* cast, RichString* out);
|
extern void Process_done(Process* this);
|
||||||
|
|
||||||
void Process_done(Process* this);
|
|
||||||
|
|
||||||
extern ProcessClass Process_class;
|
extern ProcessClass Process_class;
|
||||||
|
|
||||||
void Process_init(Process* this, struct Settings_* settings);
|
extern void Process_init(Process* this, struct Settings_* settings);
|
||||||
|
|
||||||
void Process_toggleTag(Process* this);
|
extern void Process_toggleTag(Process* this);
|
||||||
|
|
||||||
bool Process_setPriority(Process* this, int priority);
|
extern bool Process_setPriority(Process* this, int priority);
|
||||||
|
|
||||||
bool Process_changePriorityBy(Process* this, int delta);
|
extern bool Process_changePriorityBy(Process* this, Arg delta);
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, int sgn);
|
extern bool Process_sendSignal(Process* this, Arg sgn);
|
||||||
|
|
||||||
long Process_pidCompare(const void* v1, const void* v2);
|
extern long Process_pidCompare(const void* v1, const void* v2);
|
||||||
|
|
||||||
long Process_compare(const void* v1, const void* v2);
|
extern long Process_compare(const void* v1, const void* v2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -124,15 +124,14 @@ 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->ss->fields;
|
ProcessField* fields = this->settings->fields;
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
unsigned int key = fields[i];
|
const char* field = Process_fields[fields[i]].title;
|
||||||
const char* field = Process_fields[key].title;
|
|
||||||
if (!field) field = "- ";
|
if (!field) field = "- ";
|
||||||
int color = (!this->settings->ss->treeView && this->settings->ss->sortKey == key)
|
if (!this->settings->treeView && this->settings->sortKey == fields[i])
|
||||||
? CRT_colors[PANEL_SELECTION_FOCUS]
|
RichString_append(header, CRT_colors[PANEL_SELECTION_FOCUS], field);
|
||||||
: CRT_colors[PANEL_HEADER_FOCUS];
|
else
|
||||||
RichString_append(header, color, field);
|
RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,19 +200,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->ss->treeView) {
|
if (!this->settings->treeView) {
|
||||||
Vector_insertionSort(this->processes);
|
Vector_insertionSort(this->processes);
|
||||||
} else {
|
} else {
|
||||||
// Save settings
|
// Save settings
|
||||||
int direction = this->settings->ss->direction;
|
int direction = this->settings->direction;
|
||||||
int sortKey = this->settings->ss->sortKey;
|
int sortKey = this->settings->sortKey;
|
||||||
// Sort by PID
|
// Sort by PID
|
||||||
this->settings->ss->sortKey = PID;
|
this->settings->sortKey = PID;
|
||||||
this->settings->ss->direction = 1;
|
this->settings->direction = 1;
|
||||||
Vector_quickSort(this->processes);
|
Vector_quickSort(this->processes);
|
||||||
// Restore settings
|
// Restore settings
|
||||||
this->settings->ss->sortKey = sortKey;
|
this->settings->sortKey = sortKey;
|
||||||
this->settings->ss->direction = direction;
|
this->settings->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;
|
||||||
@ -272,7 +271,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->ss->fields;
|
ProcessField* fields = this->settings->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;
|
||||||
|
@ -71,32 +71,32 @@ void ProcessList_delete(ProcessList* pl);
|
|||||||
void ProcessList_goThroughEntries(ProcessList* pl);
|
void ProcessList_goThroughEntries(ProcessList* pl);
|
||||||
|
|
||||||
|
|
||||||
ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
extern ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||||
|
|
||||||
void ProcessList_done(ProcessList* this);
|
extern void ProcessList_done(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
extern void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
||||||
|
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header);
|
extern void ProcessList_printHeader(ProcessList* this, RichString* header);
|
||||||
|
|
||||||
void ProcessList_add(ProcessList* this, Process* p);
|
extern void ProcessList_add(ProcessList* this, Process* p);
|
||||||
|
|
||||||
void ProcessList_remove(ProcessList* this, Process* p);
|
extern void ProcessList_remove(ProcessList* this, Process* p);
|
||||||
|
|
||||||
Process* ProcessList_get(ProcessList* this, int idx);
|
extern Process* ProcessList_get(ProcessList* this, int idx);
|
||||||
|
|
||||||
int ProcessList_size(ProcessList* this);
|
extern int ProcessList_size(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_sort(ProcessList* this);
|
extern void ProcessList_sort(ProcessList* this);
|
||||||
|
|
||||||
ProcessField ProcessList_keyAt(ProcessList* this, int at);
|
extern ProcessField ProcessList_keyAt(ProcessList* this, int at);
|
||||||
|
|
||||||
void ProcessList_expandTree(ProcessList* this);
|
extern void ProcessList_expandTree(ProcessList* this);
|
||||||
|
|
||||||
void ProcessList_rebuildPanel(ProcessList* this);
|
extern void ProcessList_rebuildPanel(ProcessList* this);
|
||||||
|
|
||||||
Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor);
|
extern Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor);
|
||||||
|
|
||||||
void ProcessList_scan(ProcessList* this);
|
extern void ProcessList_scan(ProcessList* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
50
README
50
README
@ -1,46 +1,28 @@
|
|||||||
[](https://travis-ci.org/hishamhm/htop)
|

|
||||||
[](http://hisham.hm/htop/index.php?page=donate)
|
|
||||||
|
|
||||||
[htop](http://hisham.hm/htop/)
|
[](https://github.com/htop-dev/htop/actions)
|
||||||
====
|
[](https://scan.coverity.com/projects/21617)
|
||||||
|
[](https://groups.io/g/htop)
|
||||||
by Hisham Muhammad <hisham@gobolinux.org> (2004 - 2016)
|
[](https://webchat.freenode.net/#htop)
|
||||||
|
[](https://github.com/htop-dev/htop/releases/latest)
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
This is `htop`, an interactive process viewer.
|
`htop` is a cross-platform interactive process viewer.
|
||||||
It requires `ncurses`. It is developed primarily on Linux,
|
It requires `ncurses`.
|
||||||
but we also have code for running under FreeBSD and Mac OS X
|
|
||||||
(help and testing are wanted for these platforms!)
|
|
||||||
|
|
||||||
This software has evolved considerably over the years,
|
For more information and details on how to contribute to `htop`
|
||||||
and is reasonably complete, but there is always room for improvement.
|
visit [htop.dev](https://htop.dev).
|
||||||
|
|
||||||
Comparison between `htop` and classic `top`
|
Build instructions
|
||||||
-------------------------------------------
|
------------------
|
||||||
|
|
||||||
* In `htop` you can scroll the list vertically and horizontally
|
|
||||||
to see all processes and full command lines.
|
|
||||||
* In `top` you are subject to a delay for each unassigned
|
|
||||||
key you press (especially annoying when multi-key escape
|
|
||||||
sequences are triggered by accident).
|
|
||||||
* `htop` starts faster (`top` seems to collect data for a while
|
|
||||||
before displaying anything).
|
|
||||||
* In `htop` you don't need to type the process number to
|
|
||||||
kill a process, in `top` you do.
|
|
||||||
* In `htop` you don't need to type the process number or
|
|
||||||
the priority value to renice a process, in `top` you do.
|
|
||||||
* In `htop` you can kill multiple processes at once.
|
|
||||||
* `top` is older, hence, more tested.
|
|
||||||
|
|
||||||
Compilation instructions
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
This program is distributed as a standard autotools-based package.
|
This program is distributed as a standard autotools-based package.
|
||||||
See the [INSTALL](/INSTALL) file for detailed instructions.
|
For detailed instructions see the [INSTALL](/INSTALL) file, which
|
||||||
|
is created after `./autogen.sh` is run.
|
||||||
|
|
||||||
When compiling from a [release tarball](https://hisham.hm/htop/releases/), run:
|
When compiling from a [release tarball](https://github.com/htop-dev/htop/releases/), run:
|
||||||
|
|
||||||
./configure && make
|
./configure && make
|
||||||
|
|
||||||
@ -54,8 +36,6 @@ the path use `./configure --prefix=/some/path`.
|
|||||||
See the manual page (`man htop`) or the on-line help ('F1' or 'h'
|
See the manual page (`man htop`) or the on-line help ('F1' or 'h'
|
||||||
inside `htop`) for a list of supported key commands.
|
inside `htop`) for a list of supported key commands.
|
||||||
|
|
||||||
If not all keys work check your curses configuration.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
GNU General Public License, version 2 (GPL-2.0)
|
GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
16
RichString.h
16
RichString.h
@ -71,24 +71,24 @@ typedef struct RichString_ {
|
|||||||
|
|
||||||
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start);
|
extern int RichString_findChar(RichString* this, char c, int start);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
||||||
|
|
||||||
int RichString_findChar(RichString* this, char c, int start);
|
extern int RichString_findChar(RichString* this, char c, int start);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void RichString_prune(RichString* this);
|
extern void RichString_prune(RichString* this);
|
||||||
|
|
||||||
void RichString_setAttr(RichString* this, int attrs);
|
extern void RichString_setAttr(RichString* this, int attrs);
|
||||||
|
|
||||||
void RichString_append(RichString* this, int attrs, const char* data);
|
extern void RichString_append(RichString* this, int attrs, const char* data);
|
||||||
|
|
||||||
void RichString_appendn(RichString* this, int attrs, const char* data, int len);
|
extern void RichString_appendn(RichString* this, int attrs, const char* data, int len);
|
||||||
|
|
||||||
void RichString_write(RichString* this, int attrs, const char* data);
|
extern void RichString_write(RichString* this, int attrs, const char* data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
120
ScreenManager.c
120
ScreenManager.c
@ -13,7 +13,6 @@ 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>
|
||||||
|
|
||||||
@ -36,7 +35,6 @@ 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;
|
||||||
@ -73,46 +71,30 @@ 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 (idx > 0) {
|
if (this->panelCount > 0) {
|
||||||
Panel* last = (Panel*) Vector_get(this->panels, idx - 1);
|
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 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) {
|
||||||
size = COLS-this->x1+this->x2-lastX;
|
|
||||||
}
|
|
||||||
Panel_resize(item, size, height);
|
Panel_resize(item, size, height);
|
||||||
|
} else {
|
||||||
|
Panel_resize(item, COLS-this->x1+this->x2-lastX, 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_insert(this->panels, idx, item);
|
Vector_add(this->panels, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +131,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->ss->treeView) {
|
if (*sortTimeout == 0 || this->settings->treeView) {
|
||||||
ProcessList_sort(pl);
|
ProcessList_sort(pl);
|
||||||
*sortTimeout = 1;
|
*sortTimeout = 1;
|
||||||
}
|
}
|
||||||
@ -162,73 +144,27 @@ 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) {
|
const int nPanels = this->panelCount;
|
||||||
ScreenManager_drawScreenTabs(this);
|
|
||||||
}
|
|
||||||
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);
|
||||||
Panel_draw(panel, i == focus);
|
Panel_draw(panel, i == focus);
|
||||||
if (i < nPanels) {
|
|
||||||
if (this->orientation == HORIZONTAL) {
|
if (this->orientation == HORIZONTAL) {
|
||||||
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static Panel* setCurrentPanel(ScreenManager* this, int focus) {
|
static Panel* setCurrentPanel(Panel* panel) {
|
||||||
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, char* name) {
|
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
int focus = 0;
|
int focus = 0;
|
||||||
|
|
||||||
Panel* panelFocus = setCurrentPanel(this, focus);
|
Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||||
|
|
||||||
double oldTime = 0.0;
|
double oldTime = 0.0;
|
||||||
|
|
||||||
@ -241,8 +177,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, cha
|
|||||||
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) {
|
||||||
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
|
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
|
||||||
@ -253,10 +187,27 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
int prevCh = ch;
|
int prevCh = ch;
|
||||||
ch = Panel_getCh(panelFocus);
|
set_escdelay(25);
|
||||||
|
ch = getch();
|
||||||
|
|
||||||
|
if (this->settings->vimMode) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'h': ch = KEY_LEFT; break;
|
||||||
|
case 'j': ch = KEY_DOWN; break;
|
||||||
|
case 'k': ch = KEY_UP; break;
|
||||||
|
case 'l': ch = KEY_RIGHT; break;
|
||||||
|
case KEY_LEFT: ch = 'h'; break;
|
||||||
|
case KEY_DOWN: ch = 'j'; break;
|
||||||
|
case KEY_UP: ch = 'k'; break;
|
||||||
|
case KEY_RIGHT: ch = 'l'; break;
|
||||||
|
case 'K': ch = 'k'; break;
|
||||||
|
case 'J': ch = 'K'; break;
|
||||||
|
case 'L': ch = 'l'; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HandlerResult result = IGNORED;
|
HandlerResult result = IGNORED;
|
||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE && this->settings->enableMouse) {
|
||||||
ch = ERR;
|
ch = ERR;
|
||||||
MEVENT mevent;
|
MEVENT mevent;
|
||||||
int ok = getmouse(&mevent);
|
int ok = getmouse(&mevent);
|
||||||
@ -271,14 +222,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, cha
|
|||||||
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(this, i);
|
panelFocus = setCurrentPanel(panel);
|
||||||
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) {
|
||||||
@ -354,7 +302,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, cha
|
|||||||
tryLeft:
|
tryLeft:
|
||||||
if (focus > 0)
|
if (focus > 0)
|
||||||
focus--;
|
focus--;
|
||||||
panelFocus = setCurrentPanel(this, focus);
|
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||||
if (Panel_size(panelFocus) == 0 && focus > 0)
|
if (Panel_size(panelFocus) == 0 && focus > 0)
|
||||||
goto tryLeft;
|
goto tryLeft;
|
||||||
break;
|
break;
|
||||||
@ -369,7 +317,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, cha
|
|||||||
tryRight:
|
tryRight:
|
||||||
if (focus < this->panelCount - 1)
|
if (focus < this->panelCount - 1)
|
||||||
focus++;
|
focus++;
|
||||||
panelFocus = setCurrentPanel(this, focus);
|
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, 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,7 +27,6 @@ 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;
|
||||||
@ -36,20 +35,18 @@ typedef struct ScreenManager_ {
|
|||||||
} ScreenManager;
|
} ScreenManager;
|
||||||
|
|
||||||
|
|
||||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner);
|
extern ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner);
|
||||||
|
|
||||||
void ScreenManager_delete(ScreenManager* this);
|
extern void ScreenManager_delete(ScreenManager* this);
|
||||||
|
|
||||||
extern int ScreenManager_size(ScreenManager* this);
|
extern int ScreenManager_size(ScreenManager* this);
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
extern void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
||||||
|
|
||||||
void ScreenManager_insert(ScreenManager* this, Panel* item, int size, int idx);
|
extern Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
||||||
|
|
||||||
Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
extern 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);
|
extern 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
331
ScreensPanel.c
@ -1,331 +0,0 @@
|
|||||||
/*
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/* 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
|
|
334
Settings.c
334
Settings.c
@ -23,44 +23,31 @@ 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 meterColumns[2];
|
MeterColumnSettings columns[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 showCPUUsage;
|
||||||
|
bool showCPUFrequency;
|
||||||
|
bool treeView;
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool hideThreads;
|
bool hideThreads;
|
||||||
bool shadowOtherUsers;
|
bool shadowOtherUsers;
|
||||||
@ -73,7 +60,8 @@ typedef struct Settings_ {
|
|||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
bool screenTabs;
|
bool enableMouse;
|
||||||
|
bool vimMode;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
@ -84,82 +72,25 @@ 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);
|
||||||
for (unsigned int i = 0; i < (sizeof(this->meterColumns)/sizeof(MeterColumnSettings)); i++) {
|
free(this->fields);
|
||||||
String_freeArray(this->meterColumns[i].names);
|
for (unsigned int i = 0; i < (sizeof(this->columns)/sizeof(MeterColumnSettings)); i++) {
|
||||||
free(this->meterColumns[i].modes);
|
String_freeArray(this->columns[i].names);
|
||||||
}
|
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 side) {
|
static void Settings_readMeters(Settings* this, char* line, int column) {
|
||||||
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->meterColumns[side].names = ids;
|
this->columns[column].names = ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_readMeterModes(Settings* this, char* line, int side) {
|
static void Settings_readMeterModes(Settings* this, char* line, int column) {
|
||||||
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);
|
||||||
@ -168,13 +99,13 @@ static void Settings_readMeterModes(Settings* this, char* line, int side) {
|
|||||||
for (int i = 0; ids[i]; i++) {
|
for (int i = 0; ids[i]; i++) {
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
this->meterColumns[side].len = len;
|
this->columns[column].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->meterColumns[side].modes = modes;
|
this->columns[column].modes = modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_defaultMeters(Settings* this) {
|
static void Settings_defaultMeters(Settings* this) {
|
||||||
@ -183,62 +114,37 @@ 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->meterColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
|
this->columns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
|
||||||
this->meterColumns[i].modes = xCalloc(sizes[i], sizeof(int));
|
this->columns[i].modes = xCalloc(sizes[i], sizeof(int));
|
||||||
this->meterColumns[i].len = sizes[i];
|
this->columns[i].len = sizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (this->cpuCount > 8) {
|
if (this->cpuCount > 8) {
|
||||||
this->meterColumns[0].names[0] = xStrdup("LeftCPUs2");
|
this->columns[0].names[0] = xStrdup("LeftCPUs2");
|
||||||
this->meterColumns[0].modes[0] = BAR_METERMODE;
|
this->columns[0].modes[0] = BAR_METERMODE;
|
||||||
this->meterColumns[1].names[r] = xStrdup("RightCPUs2");
|
this->columns[1].names[r] = xStrdup("RightCPUs2");
|
||||||
this->meterColumns[1].modes[r++] = BAR_METERMODE;
|
this->columns[1].modes[r++] = BAR_METERMODE;
|
||||||
} else if (this->cpuCount > 4) {
|
} else if (this->cpuCount > 4) {
|
||||||
this->meterColumns[0].names[0] = xStrdup("LeftCPUs");
|
this->columns[0].names[0] = xStrdup("LeftCPUs");
|
||||||
this->meterColumns[0].modes[0] = BAR_METERMODE;
|
this->columns[0].modes[0] = BAR_METERMODE;
|
||||||
this->meterColumns[1].names[r] = xStrdup("RightCPUs");
|
this->columns[1].names[r] = xStrdup("RightCPUs");
|
||||||
this->meterColumns[1].modes[r++] = BAR_METERMODE;
|
this->columns[1].modes[r++] = BAR_METERMODE;
|
||||||
} else {
|
} else {
|
||||||
this->meterColumns[0].names[0] = xStrdup("AllCPUs");
|
this->columns[0].names[0] = xStrdup("AllCPUs");
|
||||||
this->meterColumns[0].modes[0] = BAR_METERMODE;
|
this->columns[0].modes[0] = BAR_METERMODE;
|
||||||
}
|
}
|
||||||
this->meterColumns[0].names[1] = xStrdup("Memory");
|
this->columns[0].names[1] = xStrdup("Memory");
|
||||||
this->meterColumns[0].modes[1] = BAR_METERMODE;
|
this->columns[0].modes[1] = BAR_METERMODE;
|
||||||
this->meterColumns[0].names[2] = xStrdup("Swap");
|
this->columns[0].names[2] = xStrdup("Swap");
|
||||||
this->meterColumns[0].modes[2] = BAR_METERMODE;
|
this->columns[0].modes[2] = BAR_METERMODE;
|
||||||
|
|
||||||
this->meterColumns[1].names[r] = xStrdup("Tasks");
|
this->columns[1].names[r] = xStrdup("Tasks");
|
||||||
this->meterColumns[1].modes[r++] = TEXT_METERMODE;
|
this->columns[1].modes[r++] = TEXT_METERMODE;
|
||||||
this->meterColumns[1].names[r] = xStrdup("LoadAverage");
|
this->columns[1].names[r] = xStrdup("LoadAverage");
|
||||||
this->meterColumns[1].modes[r++] = TEXT_METERMODE;
|
this->columns[1].modes[r++] = TEXT_METERMODE;
|
||||||
this->meterColumns[1].names[r] = xStrdup("Uptime");
|
this->columns[1].names[r] = xStrdup("Uptime");
|
||||||
this->meterColumns[1].modes[r++] = TEXT_METERMODE;
|
this->columns[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) {
|
||||||
@ -249,10 +155,11 @@ 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++) {
|
||||||
int idx = toFieldIndex(ids[i]);
|
// This "+1" is for compatibility with the older enum format.
|
||||||
if (idx != -1) {
|
int id = atoi(ids[i]) + 1;
|
||||||
fields[j] = idx;
|
if (id > 0 && Process_fields[id].name && id < Platform_numberOfFields) {
|
||||||
*flags |= Process_fields[idx].flags;
|
fields[j] = id;
|
||||||
|
*flags |= Process_fields[id].flags;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,30 +167,6 @@ 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;
|
||||||
|
|
||||||
@ -295,9 +178,6 @@ 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) {
|
||||||
@ -311,8 +191,15 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (String_eq(option[0], "fields")) {
|
if (String_eq(option[0], "fields")) {
|
||||||
readFields(legacyFields, &legacyFlags, option[1]);
|
readFields(this->fields, &(this->flags), option[1]);
|
||||||
legacyFieldsRead = true;
|
didReadFields = 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")) {
|
||||||
@ -333,8 +220,6 @@ 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]);
|
||||||
@ -342,6 +227,10 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
this->detailedCPUTime = atoi(option[1]);
|
this->detailedCPUTime = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "cpu_count_from_zero")) {
|
} else if (String_eq(option[0], "cpu_count_from_zero")) {
|
||||||
this->countCPUsFromZero = atoi(option[1]);
|
this->countCPUsFromZero = atoi(option[1]);
|
||||||
|
} else if (String_eq(option[0], "show_cpu_usage")) {
|
||||||
|
this->showCPUUsage = atoi(option[1]);
|
||||||
|
} else if (String_eq(option[0], "show_cpu_frequency")) {
|
||||||
|
this->showCPUFrequency = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "update_process_names")) {
|
} else if (String_eq(option[0], "update_process_names")) {
|
||||||
this->updateProcessNames = atoi(option[1]);
|
this->updateProcessNames = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "account_guest_in_cpu_meter")) {
|
} else if (String_eq(option[0], "account_guest_in_cpu_meter")) {
|
||||||
@ -351,6 +240,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
} else if (String_eq(option[0], "color_scheme")) {
|
} else if (String_eq(option[0], "color_scheme")) {
|
||||||
this->colorScheme = atoi(option[1]);
|
this->colorScheme = atoi(option[1]);
|
||||||
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
||||||
|
} else if (String_eq(option[0], "enable_mouse")) {
|
||||||
|
this->enableMouse = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "left_meters")) {
|
} else if (String_eq(option[0], "left_meters")) {
|
||||||
Settings_readMeters(this, option[1], 0);
|
Settings_readMeters(this, option[1], 0);
|
||||||
didReadMeters = true;
|
didReadMeters = true;
|
||||||
@ -363,62 +254,42 @@ 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) {
|
} else if (String_eq(option[0], "vim_mode")) {
|
||||||
Settings_newScreen(this, option[0] + 7, option[1]);
|
this->vimMode = atoi(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, bool byName) {
|
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
||||||
|
fprintf(fd, "%s=", name);
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
if (byName) {
|
|
||||||
fprintf(fd, "%s%s", sep, toFieldName(fields[i]));
|
|
||||||
} else {
|
|
||||||
// This "-1" is for compatibility with the older enum format.
|
// This "-1" is for compatibility with the older enum format.
|
||||||
fprintf(fd, "%s%d", sep, (int) fields[i]-1);
|
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 side) {
|
static void writeMeters(Settings* this, FILE* fd, int column) {
|
||||||
writeList(fd, this->meterColumns[side].names, this->meterColumns[side].len);
|
const char* sep = "";
|
||||||
|
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 side) {
|
static void writeMeterModes(Settings* this, FILE* fd, int column) {
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
for (int i = 0; i < this->meterColumns[side].len; i++) {
|
for (int i = 0; i < this->columns[column].len; i++) {
|
||||||
fprintf(fd, "%s%d", sep, this->meterColumns[side].modes[i]);
|
fprintf(fd, "%s%d", sep, this->columns[column].modes[i]);
|
||||||
sep = " ";
|
sep = " ";
|
||||||
}
|
}
|
||||||
fprintf(fd, "\n");
|
fprintf(fd, "\n");
|
||||||
@ -436,7 +307,10 @@ 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");
|
||||||
fprintf(fd, "fields="); writeFields(fd, this->screens[0]->fields, false);
|
writeFields(fd, this->fields, "fields");
|
||||||
|
// 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);
|
||||||
@ -446,35 +320,22 @@ 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, "show_cpu_usage=%d\n", (int) this->showCPUUsage);
|
||||||
|
fprintf(fd, "show_cpu_frequency=%d\n", (int) this->showCPUFrequency);
|
||||||
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
||||||
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter);
|
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter);
|
||||||
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
||||||
|
fprintf(fd, "enable_mouse=%d\n", (int) this->enableMouse);
|
||||||
fprintf(fd, "delay=%d\n", (int) this->delay);
|
fprintf(fd, "delay=%d\n", (int) this->delay);
|
||||||
fprintf(fd, "left_meters="); writeMeters(this, fd, 0);
|
fprintf(fd, "left_meters="); writeMeters(this, fd, 0);
|
||||||
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);
|
||||||
|
fprintf(fd, "vim_mode=%d\n", (int) this->vimMode);
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
@ -483,22 +344,34 @@ 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;
|
||||||
this->countCPUsFromZero = false;
|
this->countCPUsFromZero = false;
|
||||||
|
this->showCPUUsage = true;
|
||||||
|
this->showCPUFrequency = false;
|
||||||
this->updateProcessNames = false;
|
this->updateProcessNames = false;
|
||||||
this->cpuCount = cpuCount;
|
this->cpuCount = cpuCount;
|
||||||
this->showProgramPath = true;
|
this->showProgramPath = true;
|
||||||
this->highlightThreads = true;
|
this->highlightThreads = true;
|
||||||
|
|
||||||
this->screens = xCalloc(sizeof(ScreenSettings*), 1);
|
this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
||||||
this->nScreens = 0;
|
// TODO: turn 'fields' into a Vector,
|
||||||
|
// (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");
|
||||||
@ -535,6 +408,7 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
CRT_restorePrivileges();
|
CRT_restorePrivileges();
|
||||||
}
|
}
|
||||||
this->colorScheme = 0;
|
this->colorScheme = 0;
|
||||||
|
this->enableMouse = true;
|
||||||
this->changed = false;
|
this->changed = false;
|
||||||
this->delay = DEFAULT_DELAY;
|
this->delay = DEFAULT_DELAY;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
@ -559,21 +433,15 @@ 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 ScreenSettings_invertSortOrder(ScreenSettings* this) {
|
void Settings_invertSortOrder(Settings* this) {
|
||||||
if (this->direction == 1)
|
if (this->direction == 1)
|
||||||
this->direction = -1;
|
this->direction = -1;
|
||||||
else
|
else
|
||||||
|
46
Settings.h
46
Settings.h
@ -14,44 +14,31 @@ 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 meterColumns[2];
|
MeterColumnSettings columns[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 showCPUUsage;
|
||||||
|
bool showCPUFrequency;
|
||||||
|
bool treeView;
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool hideThreads;
|
bool hideThreads;
|
||||||
bool shadowOtherUsers;
|
bool shadowOtherUsers;
|
||||||
@ -64,7 +51,8 @@ typedef struct Settings_ {
|
|||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
bool screenTabs;
|
bool enableMouse;
|
||||||
|
bool vimMode;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
@ -74,18 +62,12 @@ typedef struct Settings_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
extern void Settings_delete(Settings* this);
|
||||||
|
|
||||||
*/
|
extern bool Settings_write(Settings* this);
|
||||||
|
|
||||||
void Settings_delete(Settings* this);
|
extern Settings* Settings_new(int cpuCount);
|
||||||
|
|
||||||
ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char* line);
|
extern void Settings_invertSortOrder(Settings* this);
|
||||||
|
|
||||||
bool Settings_write(Settings* this);
|
|
||||||
|
|
||||||
Settings* Settings_new(int cpuCount);
|
|
||||||
|
|
||||||
void ScreenSettings_invertSortOrder(ScreenSettings* this);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,6 +16,6 @@ typedef struct SignalItem_ {
|
|||||||
} SignalItem;
|
} SignalItem;
|
||||||
|
|
||||||
|
|
||||||
Panel* SignalsPanel_new();
|
extern Panel* SignalsPanel_new();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,11 +27,12 @@ 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) {
|
||||||
size_t l1 = strlen(s1);
|
int l1 = strlen(s1);
|
||||||
size_t l2 = strlen(s2);
|
int l2 = strlen(s2);
|
||||||
char* out = xMalloc(l1 + l2 + 1);
|
char* out = xMalloc(l1 + l2 + 1);
|
||||||
strncpy(out, s1, l1);
|
memcpy(out, s1, l1);
|
||||||
strncpy(out + l1, s2, l2 + 1);
|
memcpy(out+l1, s2, l2+1);
|
||||||
|
out[l1 + l2] = '\0';
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +40,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++;
|
||||||
}
|
}
|
||||||
size_t len = strlen(in);
|
int 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 +81,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') {
|
||||||
size_t size = strlen(s);
|
int 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;
|
||||||
|
@ -19,18 +19,18 @@ in the source distribution for its full text.
|
|||||||
* at compile time (e.g. when they are immutable string literals). :)
|
* at compile time (e.g. when they are immutable string literals). :)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char* String_cat(const char* s1, const char* s2);
|
extern char* String_cat(const char* s1, const char* s2);
|
||||||
|
|
||||||
char* String_trim(const char* in);
|
extern char* String_trim(const char* in);
|
||||||
|
|
||||||
extern int String_eq(const char* s1, const char* s2);
|
extern int String_eq(const char* s1, const char* s2);
|
||||||
|
|
||||||
char** String_split(const char* s, char sep, int* n);
|
extern char** String_split(const char* s, char sep, int* n);
|
||||||
|
|
||||||
void String_freeArray(char** s);
|
extern void String_freeArray(char** s);
|
||||||
|
|
||||||
char* String_getToken(const char* line, const unsigned short int numMatch);
|
extern char* String_getToken(const char* line, const unsigned short int numMatch);
|
||||||
|
|
||||||
char* String_readLine(FILE* fd);
|
extern char* String_readLine(FILE* fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,7 +15,7 @@ in the source distribution for its full text.
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
int TasksMeter_attributes[] = {
|
int TasksMeter_attributes[] = {
|
||||||
CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING
|
CPU_SYSTEM, PROCESS_THREAD, PROCESS, TASKS_RUNNING
|
||||||
};
|
};
|
||||||
|
|
||||||
static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
|
static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||||
|
@ -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, CRT_colors[FUNCTION_BAR]);
|
IncSet_drawBar(this->inc);
|
||||||
}
|
}
|
||||||
|
|
||||||
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", "-s", "512", "-p", buffer, NULL);
|
execlp("strace", "strace", "-T", "-tt", "-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));
|
||||||
|
@ -25,16 +25,16 @@ typedef struct TraceScreen_ {
|
|||||||
|
|
||||||
extern InfoScreenClass TraceScreen_class;
|
extern InfoScreenClass TraceScreen_class;
|
||||||
|
|
||||||
TraceScreen* TraceScreen_new(Process* process);
|
extern TraceScreen* TraceScreen_new(Process* process);
|
||||||
|
|
||||||
void TraceScreen_delete(Object* cast);
|
extern void TraceScreen_delete(Object* cast);
|
||||||
|
|
||||||
void TraceScreen_draw(InfoScreen* this);
|
extern void TraceScreen_draw(InfoScreen* this);
|
||||||
|
|
||||||
bool TraceScreen_forkTracer(TraceScreen* this);
|
extern bool TraceScreen_forkTracer(TraceScreen* this);
|
||||||
|
|
||||||
void TraceScreen_updateTrace(InfoScreen* super);
|
extern void TraceScreen_updateTrace(InfoScreen* super);
|
||||||
|
|
||||||
bool TraceScreen_onKey(InfoScreen* super, int ch);
|
extern bool TraceScreen_onKey(InfoScreen* super, int ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,11 +15,11 @@ typedef struct UsersTable_ {
|
|||||||
Hashtable* users;
|
Hashtable* users;
|
||||||
} UsersTable;
|
} UsersTable;
|
||||||
|
|
||||||
UsersTable* UsersTable_new();
|
extern UsersTable* UsersTable_new();
|
||||||
|
|
||||||
void UsersTable_delete(UsersTable* this);
|
extern void UsersTable_delete(UsersTable* this);
|
||||||
|
|
||||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
extern char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
||||||
|
|
||||||
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
||||||
|
|
||||||
|
26
Vector.h
26
Vector.h
@ -27,38 +27,38 @@ typedef struct Vector_ {
|
|||||||
} Vector;
|
} Vector;
|
||||||
|
|
||||||
|
|
||||||
Vector* Vector_new(ObjectClass* type, bool owner, int size);
|
extern Vector* Vector_new(ObjectClass* type, bool owner, int size);
|
||||||
|
|
||||||
void Vector_delete(Vector* this);
|
extern void Vector_delete(Vector* this);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
int Vector_count(Vector* this);
|
extern int Vector_count(Vector* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Vector_prune(Vector* this);
|
extern void Vector_prune(Vector* this);
|
||||||
|
|
||||||
// If I were to use only one sorting algorithm for both cases, it would probably be this one:
|
// If I were to use only one sorting algorithm for both cases, it would probably be this one:
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Vector_quickSort(Vector* this);
|
extern void Vector_quickSort(Vector* this);
|
||||||
|
|
||||||
void Vector_insertionSort(Vector* this);
|
extern void Vector_insertionSort(Vector* this);
|
||||||
|
|
||||||
void Vector_insert(Vector* this, int idx, void* data_);
|
extern void Vector_insert(Vector* this, int idx, void* data_);
|
||||||
|
|
||||||
Object* Vector_take(Vector* this, int idx);
|
extern Object* Vector_take(Vector* this, int idx);
|
||||||
|
|
||||||
Object* Vector_remove(Vector* this, int idx);
|
extern Object* Vector_remove(Vector* this, int idx);
|
||||||
|
|
||||||
void Vector_moveUp(Vector* this, int idx);
|
extern void Vector_moveUp(Vector* this, int idx);
|
||||||
|
|
||||||
void Vector_moveDown(Vector* this, int idx);
|
extern void Vector_moveDown(Vector* this, int idx);
|
||||||
|
|
||||||
void Vector_set(Vector* this, int idx, void* data_);
|
extern void Vector_set(Vector* this, int idx, void* data_);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ extern int Vector_size(Vector* this);
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Vector_add(Vector* this, void* data_);
|
extern void Vector_add(Vector* this, void* data_);
|
||||||
|
|
||||||
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
||||||
|
|
||||||
|
10
XAlloc.h
10
XAlloc.h
@ -11,11 +11,11 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void* xMalloc(size_t size);
|
extern void* xMalloc(size_t size);
|
||||||
|
|
||||||
void* xCalloc(size_t nmemb, size_t size);
|
extern void* xCalloc(size_t nmemb, size_t size);
|
||||||
|
|
||||||
void* xRealloc(void* ptr, size_t size);
|
extern void* xRealloc(void* ptr, size_t size);
|
||||||
|
|
||||||
#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
|
#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
|
||||||
|
|
||||||
@ -32,9 +32,9 @@ void* xRealloc(void* ptr, size_t size);
|
|||||||
#endif
|
#endif
|
||||||
#if (__has_attribute(nonnull) || \
|
#if (__has_attribute(nonnull) || \
|
||||||
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
|
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
|
||||||
char* xStrdup_(const char* str) __attribute__((nonnull));
|
extern char* xStrdup_(const char* str) __attribute__((nonnull));
|
||||||
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
||||||
|
|
||||||
char* xStrdup_(const char* str);
|
extern char* xStrdup_(const char* str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
61
configure.ac
61
configure.ac
@ -2,10 +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],[3.0.0beta5],[hisham@gobolinux.org])
|
AC_INIT([htop],[3.0.0],[htop@groups.io])
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
AC_CONFIG_SRCDIR([htop.c])
|
AC_CONFIG_SRCDIR([htop.c])
|
||||||
AC_CONFIG_AUX_DIR([.])
|
AC_CONFIG_AUX_DIR([.])
|
||||||
@ -69,7 +66,7 @@ dnl glibc 2.25 deprecates 'major' and 'minor' in <sys/types.h> and requires to
|
|||||||
dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
|
dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
|
||||||
dnl been updated in Autoconf 2.69, so use a workaround:
|
dnl been updated in Autoconf 2.69, so use a workaround:
|
||||||
m4_version_prereq([2.70], [],
|
m4_version_prereq([2.70], [],
|
||||||
[if test "x$ac_cv_header_sys_mkdev_h" = xno; then
|
[if test "x$ac_cv_header_sys_mkdev_h" != xyes; then
|
||||||
AC_CHECK_HEADER(sys/sysmacros.h, [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
|
AC_CHECK_HEADER(sys/sysmacros.h, [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
|
||||||
[Define to 1 if `major', `minor', and `makedev' are declared in <sys/sysmacros.h>.])])
|
[Define to 1 if `major', `minor', and `makedev' are declared in <sys/sysmacros.h>.])])
|
||||||
fi])
|
fi])
|
||||||
@ -245,10 +242,6 @@ if test "$my_htop_platform" = "solaris"; then
|
|||||||
AC_CHECK_LIB([kstat], [kstat_open], [], [missing_libraries="$missing_libraries libkstat"])
|
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([proc], [Pgrab_error], [], [missing_libraries="$missing_libraries libproc"])
|
||||||
AC_CHECK_LIB([malloc], [free], [], [missing_libraries="$missing_libraries libmalloc"])
|
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
|
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")
|
||||||
@ -285,53 +278,7 @@ 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")
|
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable Linux delay accounting])],, enable_delayacct="no")
|
||||||
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")
|
|
||||||
if test "x$enable_delayacct" = xyes
|
if test "x$enable_delayacct" = xyes
|
||||||
then
|
then
|
||||||
m4_ifdef([PKG_PROG_PKG_CONFIG], [
|
m4_ifdef([PKG_PROG_PKG_CONFIG], [
|
||||||
@ -358,7 +305,7 @@ if test ! -z "$missing_headers"; then
|
|||||||
AC_MSG_ERROR([missing headers: $missing_headers])
|
AC_MSG_ERROR([missing headers: $missing_headers])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-$year Hisham Muhammad", [Copyright message.])
|
AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-2018 Hisham Muhammad", [Copyright message.])
|
||||||
|
|
||||||
# We're done, let's go!
|
# We're done, let's go!
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
@ -9,6 +9,8 @@ in the source distribution for its full text.
|
|||||||
#include "DarwinProcess.h"
|
#include "DarwinProcess.h"
|
||||||
#include "DarwinProcessList.h"
|
#include "DarwinProcessList.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
#include "zfs/openzfs_sysctl.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -21,8 +23,40 @@ in the source distribution for its full text.
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
struct kern {
|
||||||
|
short int version[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
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_));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
*/
|
||||||
|
int CompareKernelVersion(short int major, short int minor, short int component) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
@ -36,42 +70,12 @@ typedef struct DarwinProcessList_ {
|
|||||||
uint64_t kernel_threads;
|
uint64_t kernel_threads;
|
||||||
uint64_t user_threads;
|
uint64_t user_threads;
|
||||||
uint64_t global_diff;
|
uint64_t global_diff;
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
} DarwinProcessList;
|
} 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;
|
||||||
|
|
||||||
@ -85,10 +89,9 @@ void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t);
|
mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t);
|
||||||
@ -133,8 +136,8 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
|||||||
return processes;
|
return processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||||
|
size_t len;
|
||||||
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
||||||
|
|
||||||
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
||||||
@ -147,6 +150,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
|||||||
/* Initialize the VM statistics */
|
/* Initialize the VM statistics */
|
||||||
ProcessList_getVMStats(&this->vm_stats);
|
ProcessList_getVMStats(&this->vm_stats);
|
||||||
|
|
||||||
|
/* Initialize the ZFS kstats, if zfs.kext loaded */
|
||||||
|
openzfs_sysctl_init(&this->zfs);
|
||||||
|
openzfs_sysctl_updateArcStats(&this->zfs);
|
||||||
|
|
||||||
this->super.kernelThreads = 0;
|
this->super.kernelThreads = 0;
|
||||||
this->super.userlandThreads = 0;
|
this->super.userlandThreads = 0;
|
||||||
this->super.totalTasks = 0;
|
this->super.totalTasks = 0;
|
||||||
@ -175,6 +182,7 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
|||||||
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);
|
||||||
|
openzfs_sysctl_updateArcStats(&dpl->zfs);
|
||||||
|
|
||||||
/* Get the time difference */
|
/* Get the time difference */
|
||||||
dpl->global_diff = 0;
|
dpl->global_diff = 0;
|
||||||
@ -206,7 +214,7 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
|||||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||||
|
|
||||||
// Disabled for High Sierra due to bug in macOS High Sierra
|
// Disabled for High Sierra due to bug in macOS High Sierra
|
||||||
bool isScanThreadSupported = ! ( compareKernelVersion(17, 0, 0) >= 0 && compareKernelVersion(17, 5, 0) < 0);
|
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);
|
||||||
|
|
||||||
if (isScanThreadSupported){
|
if (isScanThreadSupported){
|
||||||
DarwinProcess_scanThreads(proc);
|
DarwinProcess_scanThreads(proc);
|
||||||
|
@ -9,7 +9,19 @@ Released under the GNU GPL, see the COPYING file
|
|||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct kern;
|
||||||
|
|
||||||
|
void GetKernelVersion(struct kern *k);
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
*/
|
||||||
|
int CompareKernelVersion(short int major, short int minor, short int component);
|
||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
@ -23,8 +35,9 @@ typedef struct DarwinProcessList_ {
|
|||||||
uint64_t kernel_threads;
|
uint64_t kernel_threads;
|
||||||
uint64_t user_threads;
|
uint64_t user_threads;
|
||||||
uint64_t global_diff;
|
uint64_t global_diff;
|
||||||
} DarwinProcessList;
|
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
|
} DarwinProcessList;
|
||||||
|
|
||||||
|
|
||||||
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
||||||
|
@ -15,6 +15,8 @@ in the source distribution for its full text.
|
|||||||
#include "ClockMeter.h"
|
#include "ClockMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
|
#include "zfs/ZfsArcMeter.h"
|
||||||
|
#include "zfs/ZfsCompressedArcMeter.h"
|
||||||
#include "DarwinProcessList.h"
|
#include "DarwinProcessList.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -25,26 +27,13 @@ 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
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
{
|
|
||||||
.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 },
|
||||||
@ -110,7 +99,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, },
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
MeterClass* Platform_meterTypes[] = {
|
MeterClass* Platform_meterTypes[] = {
|
||||||
@ -130,6 +119,8 @@ MeterClass* Platform_meterTypes[] = {
|
|||||||
&RightCPUsMeter_class,
|
&RightCPUsMeter_class,
|
||||||
&LeftCPUs2Meter_class,
|
&LeftCPUs2Meter_class,
|
||||||
&RightCPUs2Meter_class,
|
&RightCPUs2Meter_class,
|
||||||
|
&ZfsArcMeter_class,
|
||||||
|
&ZfsCompressedArcMeter_class,
|
||||||
&BlankMeter_class,
|
&BlankMeter_class,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
@ -230,6 +221,8 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
|
|||||||
/* Convert to percent and return */
|
/* Convert to percent and return */
|
||||||
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
||||||
|
|
||||||
|
mtr->values[CPU_METER_FREQUENCY] = -1;
|
||||||
|
|
||||||
return CLAMP(total, 0.0, 100.0);
|
return CLAMP(total, 0.0, 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,6 +247,18 @@ void Platform_setSwapValues(Meter* mtr) {
|
|||||||
mtr->values[0] = swapused.xsu_used / 1024;
|
mtr->values[0] = swapused.xsu_used / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this) {
|
||||||
|
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsArcMeter_readStats(this, &(dpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this) {
|
||||||
|
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsCompressedArcMeter_readStats(this, &(dpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid) {
|
char* Platform_getProcessEnv(pid_t pid) {
|
||||||
char* env = NULL;
|
char* env = NULL;
|
||||||
|
|
||||||
|
@ -16,18 +16,11 @@ 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 ScreenDefaults Platform_defaultScreens[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern const SignalItem Platform_signals[];
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
@ -55,6 +48,10 @@ void Platform_setMemoryValues(Meter* mtr);
|
|||||||
|
|
||||||
void Platform_setSwapValues(Meter* mtr);
|
void Platform_setSwapValues(Meter* mtr);
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this);
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this);
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid);
|
char* Platform_getProcessEnv(pid_t pid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -121,7 +121,7 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField
|
|||||||
case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break;
|
case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break;
|
||||||
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
||||||
case JAIL:{
|
case JAIL:{
|
||||||
xSnprintf(buffer, n, "%-11s ", fp->jname); break;
|
xSnprintf(buffer, n, "%-11s ", fp->jname);
|
||||||
if (buffer[11] != '\0') {
|
if (buffer[11] != '\0') {
|
||||||
buffer[11] = ' ';
|
buffer[11] = ' ';
|
||||||
buffer[12] = '\0';
|
buffer[12] = '\0';
|
||||||
@ -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->ss->direction == 1) {
|
if (settings->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->ss->sortKey) {
|
switch ((int) settings->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,15 +40,7 @@ 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[] = {
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
{
|
|
||||||
.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;
|
||||||
|
|
||||||
@ -187,6 +179,9 @@ double Platform_setCPUValues(Meter* this, int cpu) {
|
|||||||
|
|
||||||
percent = CLAMP(percent, 0.0, 100.0);
|
percent = CLAMP(percent, 0.0, 100.0);
|
||||||
if (isnan(percent)) percent = 0.0;
|
if (isnan(percent)) percent = 0.0;
|
||||||
|
|
||||||
|
v[CPU_METER_FREQUENCY] = -1;
|
||||||
|
|
||||||
return percent;
|
return percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,7 @@ 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 ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel
|
|||||||
// add FreeBSD-specific fields here
|
// add FreeBSD-specific fields here
|
||||||
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
||||||
case JAIL:{
|
case JAIL:{
|
||||||
xSnprintf(buffer, n, "%-11s ", fp->jname); break;
|
xSnprintf(buffer, n, "%-11s ", fp->jname);
|
||||||
if (buffer[11] != '\0') {
|
if (buffer[11] != '\0') {
|
||||||
buffer[11] = ' ';
|
buffer[11] = ' ';
|
||||||
buffer[12] = '\0';
|
buffer[12] = '\0';
|
||||||
@ -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->ss->direction == 1) {
|
if (settings->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->ss->sortKey) {
|
switch ((int) settings->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);
|
||||||
|
@ -8,6 +8,8 @@ in the source distribution for its full text.
|
|||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
#include "FreeBSDProcessList.h"
|
#include "FreeBSDProcessList.h"
|
||||||
#include "FreeBSDProcess.h"
|
#include "FreeBSDProcess.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
#include "zfs/openzfs_sysctl.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -18,9 +20,12 @@ in the source distribution for its full text.
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/jail.h>
|
#include <sys/jail.h>
|
||||||
@ -45,14 +50,12 @@ typedef struct FreeBSDProcessList_ {
|
|||||||
ProcessList super;
|
ProcessList super;
|
||||||
kvm_t* kd;
|
kvm_t* kd;
|
||||||
|
|
||||||
int zfsArcEnabled;
|
|
||||||
|
|
||||||
unsigned long long int memWire;
|
unsigned long long int memWire;
|
||||||
unsigned long long int memActive;
|
unsigned long long int memActive;
|
||||||
unsigned long long int memInactive;
|
unsigned long long int memInactive;
|
||||||
unsigned long long int memFree;
|
unsigned long long int memFree;
|
||||||
unsigned long long int memZfsArc;
|
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
|
|
||||||
CPUData* cpus;
|
CPUData* cpus;
|
||||||
|
|
||||||
@ -80,8 +83,6 @@ static int MIB_vm_stats_vm_v_free_count[4];
|
|||||||
|
|
||||||
static int MIB_vfs_bufspace[2];
|
static int MIB_vfs_bufspace[2];
|
||||||
|
|
||||||
static int MIB_kstat_zfs_misc_arcstats_size[5];
|
|
||||||
|
|
||||||
static int MIB_kern_cp_time[2];
|
static int MIB_kern_cp_time[2];
|
||||||
static int MIB_kern_cp_times[2];
|
static int MIB_kern_cp_times[2];
|
||||||
static int kernelFScale;
|
static int kernelFScale;
|
||||||
@ -118,15 +119,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
|||||||
|
|
||||||
len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len);
|
len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len);
|
||||||
|
|
||||||
len = sizeof(fpl->memZfsArc);
|
openzfs_sysctl_init(&fpl->zfs);
|
||||||
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &fpl->memZfsArc, &len,
|
openzfs_sysctl_updateArcStats(&fpl->zfs);
|
||||||
NULL, 0) == 0 && fpl->memZfsArc != 0) {
|
|
||||||
sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
|
|
||||||
fpl->zfsArcEnabled = 1;
|
|
||||||
} else {
|
|
||||||
fpl->zfsArcEnabled = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int smp = 0;
|
int smp = 0;
|
||||||
len = sizeof(smp);
|
len = sizeof(smp);
|
||||||
@ -296,37 +290,57 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
|||||||
//
|
//
|
||||||
// htop_used = active + (wired - arc)
|
// htop_used = active + (wired - arc)
|
||||||
// htop_cache = buffers + cache + arc
|
// htop_cache = buffers + cache + arc
|
||||||
size_t len = sizeof(pl->totalMem);
|
u_long totalMem;
|
||||||
|
u_int memActive, memWire, cachedMem;
|
||||||
|
long buffersMem;
|
||||||
|
uint64_t memZfsArc;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
//disabled for now, as it is always smaller than phycal amount of memory...
|
//disabled for now, as it is always smaller than phycal amount of memory...
|
||||||
//...to avoid "where is my memory?" questions
|
//...to avoid "where is my memory?" questions
|
||||||
//sysctl(MIB_vm_stats_vm_v_page_count, 4, &(pl->totalMem), &len, NULL, 0);
|
//sysctl(MIB_vm_stats_vm_v_page_count, 4, &(pl->totalMem), &len, NULL, 0);
|
||||||
//pl->totalMem *= pageSizeKb;
|
//pl->totalMem *= pageSizeKb;
|
||||||
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0);
|
len = sizeof(totalMem);
|
||||||
pl->totalMem /= 1024;
|
sysctl(MIB_hw_physmem, 2, &(totalMem), &len, NULL, 0);
|
||||||
|
totalMem /= 1024;
|
||||||
|
pl->totalMem = totalMem;
|
||||||
|
|
||||||
sysctl(MIB_vm_stats_vm_v_active_count, 4, &(fpl->memActive), &len, NULL, 0);
|
len = sizeof(memActive);
|
||||||
fpl->memActive *= pageSizeKb;
|
sysctl(MIB_vm_stats_vm_v_active_count, 4, &(memActive), &len, NULL, 0);
|
||||||
|
memActive *= pageSizeKb;
|
||||||
|
fpl->memActive = memActive;
|
||||||
|
|
||||||
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(fpl->memWire), &len, NULL, 0);
|
len = sizeof(memWire);
|
||||||
fpl->memWire *= pageSizeKb;
|
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(memWire), &len, NULL, 0);
|
||||||
|
memWire *= pageSizeKb;
|
||||||
|
fpl->memWire = memWire;
|
||||||
|
|
||||||
sysctl(MIB_vfs_bufspace, 2, &(pl->buffersMem), &len, NULL, 0);
|
len = sizeof(buffersMem);
|
||||||
pl->buffersMem /= 1024;
|
sysctl(MIB_vfs_bufspace, 2, &(buffersMem), &len, NULL, 0);
|
||||||
|
buffersMem /= 1024;
|
||||||
|
pl->buffersMem = buffersMem;
|
||||||
|
|
||||||
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0);
|
len = sizeof(cachedMem);
|
||||||
pl->cachedMem *= pageSizeKb;
|
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(cachedMem), &len, NULL, 0);
|
||||||
|
cachedMem *= pageSizeKb;
|
||||||
|
pl->cachedMem = cachedMem;
|
||||||
|
|
||||||
if (fpl->zfsArcEnabled) {
|
if (fpl->zfsArcEnabled) {
|
||||||
len = sizeof(fpl->memZfsArc);
|
len = sizeof(memZfsArc);
|
||||||
sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(fpl->memZfsArc), &len , NULL, 0);
|
sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(memZfsArc), &len , NULL, 0);
|
||||||
fpl->memZfsArc /= 1024;
|
memZfsArc /= 1024;
|
||||||
|
fpl->memZfsArc = memZfsArc;
|
||||||
fpl->memWire -= fpl->memZfsArc;
|
fpl->memWire -= fpl->memZfsArc;
|
||||||
pl->cachedMem += fpl->memZfsArc;
|
pl->cachedMem += fpl->memZfsArc;
|
||||||
// maybe when we learn how to make custom memory meter
|
// maybe when we learn how to make custom memory meter
|
||||||
// we could do custom arc breakdown?
|
// we could do custom arc breakdown?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fpl->zfs.enabled) {
|
||||||
|
fpl->memWire -= fpl->zfs.size;
|
||||||
|
pl->cachedMem += fpl->zfs.size;
|
||||||
|
}
|
||||||
|
|
||||||
pl->usedMem = fpl->memActive + fpl->memWire;
|
pl->usedMem = fpl->memActive + fpl->memWire;
|
||||||
|
|
||||||
//currently unused, same as with arc, custom meter perhaps
|
//currently unused, same as with arc, custom meter perhaps
|
||||||
@ -422,6 +436,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
|||||||
bool hideKernelThreads = settings->hideKernelThreads;
|
bool hideKernelThreads = settings->hideKernelThreads;
|
||||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||||
|
|
||||||
|
openzfs_sysctl_updateArcStats(&fpl->zfs);
|
||||||
FreeBSDProcessList_scanMemoryInfo(this);
|
FreeBSDProcessList_scanMemoryInfo(this);
|
||||||
FreeBSDProcessList_scanCPUTime(this);
|
FreeBSDProcessList_scanCPUTime(this);
|
||||||
|
|
||||||
@ -429,10 +444,14 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count);
|
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count);
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
struct kinfo_proc* kproc = &kprocs[i];
|
struct kinfo_proc* kproc = &kprocs[i];
|
||||||
bool preExisting = false;
|
bool preExisting = false;
|
||||||
bool isIdleProcess = false;
|
bool isIdleProcess = false;
|
||||||
|
struct tm date;
|
||||||
Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new);
|
Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new);
|
||||||
FreeBSDProcess* fp = (FreeBSDProcess*) proc;
|
FreeBSDProcess* fp = (FreeBSDProcess*) proc;
|
||||||
|
|
||||||
@ -523,6 +542,9 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
|||||||
this->kernelThreads++;
|
this->kernelThreads++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(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);
|
||||||
|
|
||||||
this->totalTasks++;
|
this->totalTasks++;
|
||||||
if (proc->state == 'R')
|
if (proc->state == 'R')
|
||||||
this->runningTasks++;
|
this->runningTasks++;
|
||||||
|
@ -10,6 +10,8 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/jail.h>
|
#include <sys/jail.h>
|
||||||
@ -34,14 +36,12 @@ typedef struct FreeBSDProcessList_ {
|
|||||||
ProcessList super;
|
ProcessList super;
|
||||||
kvm_t* kd;
|
kvm_t* kd;
|
||||||
|
|
||||||
int zfsArcEnabled;
|
|
||||||
|
|
||||||
unsigned long long int memWire;
|
unsigned long long int memWire;
|
||||||
unsigned long long int memActive;
|
unsigned long long int memActive;
|
||||||
unsigned long long int memInactive;
|
unsigned long long int memInactive;
|
||||||
unsigned long long int memFree;
|
unsigned long long int memFree;
|
||||||
unsigned long long int memZfsArc;
|
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
|
|
||||||
CPUData* cpus;
|
CPUData* cpus;
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ in the source distribution for its full text.
|
|||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
#include "ClockMeter.h"
|
#include "ClockMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
|
#include "zfs/ZfsArcMeter.h"
|
||||||
|
#include "zfs/ZfsCompressedArcMeter.h"
|
||||||
#include "FreeBSDProcess.h"
|
#include "FreeBSDProcess.h"
|
||||||
#include "FreeBSDProcessList.h"
|
#include "FreeBSDProcessList.h"
|
||||||
|
|
||||||
@ -39,16 +41,6 @@ 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;
|
||||||
@ -114,6 +106,8 @@ MeterClass* Platform_meterTypes[] = {
|
|||||||
&LeftCPUs2Meter_class,
|
&LeftCPUs2Meter_class,
|
||||||
&RightCPUs2Meter_class,
|
&RightCPUs2Meter_class,
|
||||||
&BlankMeter_class,
|
&BlankMeter_class,
|
||||||
|
&ZfsArcMeter_class,
|
||||||
|
&ZfsCompressedArcMeter_class,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -188,6 +182,9 @@ double Platform_setCPUValues(Meter* this, int cpu) {
|
|||||||
|
|
||||||
percent = CLAMP(percent, 0.0, 100.0);
|
percent = CLAMP(percent, 0.0, 100.0);
|
||||||
if (isnan(percent)) percent = 0.0;
|
if (isnan(percent)) percent = 0.0;
|
||||||
|
|
||||||
|
v[CPU_METER_FREQUENCY] = -1;
|
||||||
|
|
||||||
return percent;
|
return percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +204,18 @@ void Platform_setSwapValues(Meter* this) {
|
|||||||
this->values[0] = pl->usedSwap;
|
this->values[0] = pl->usedSwap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this) {
|
||||||
|
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsArcMeter_readStats(this, &(fpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this) {
|
||||||
|
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsCompressedArcMeter_readStats(this, &(fpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
void Platform_setTasksValues(Meter* this) {
|
void Platform_setTasksValues(Meter* this) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,6 @@ 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;
|
||||||
@ -48,6 +44,10 @@ void Platform_setMemoryValues(Meter* this);
|
|||||||
|
|
||||||
void Platform_setSwapValues(Meter* this);
|
void Platform_setSwapValues(Meter* this);
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this);
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this);
|
||||||
|
|
||||||
void Platform_setTasksValues(Meter* this);
|
void Platform_setTasksValues(Meter* this);
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid);
|
char* Platform_getProcessEnv(pid_t pid);
|
||||||
|
91
htop.1.in
91
htop.1.in
@ -1,17 +1,22 @@
|
|||||||
.TH "HTOP" "1" "2015" "@PACKAGE_STRING@" "Utils"
|
.TH "HTOP" "1" "2020" "@PACKAGE_STRING@" "User Commands"
|
||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
htop \- interactive process viewer
|
htop \- interactive process viewer
|
||||||
.SH "SYNOPSIS"
|
.SH "SYNOPSIS"
|
||||||
.LP
|
.LP
|
||||||
.B htop [\fI\-dChustv\fR]
|
.B htop
|
||||||
|
.RB [ \-dChpustv ]
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
.LP
|
.LP
|
||||||
Htop is a free (GPL) ncurses-based process viewer for Linux.
|
.B htop
|
||||||
|
is a cross-platform ncurses-based process viewer.
|
||||||
.LP
|
.LP
|
||||||
It is similar to top, but allows you to scroll vertically and horizontally,
|
It is similar to
|
||||||
so you can see all the processes running on the system, along with their full
|
.BR top ,
|
||||||
command lines, as well as viewing them as a process tree, selecting multiple
|
but allows you to scroll vertically and horizontally, and interact using
|
||||||
processes and acting on them all at once.
|
a pointing device (mouse).
|
||||||
|
You can observe all processes running on the system, along with their
|
||||||
|
command line arguments, as well as view them in a tree format, select
|
||||||
|
multiple processes and acting on them all at once.
|
||||||
.LP
|
.LP
|
||||||
Tasks related to processes (killing, renicing) can be done without
|
Tasks related to processes (killing, renicing) can be done without
|
||||||
entering their PIDs.
|
entering their PIDs.
|
||||||
@ -22,10 +27,14 @@ Mandatory arguments to long options are mandatory for short options too.
|
|||||||
.LP
|
.LP
|
||||||
.TP
|
.TP
|
||||||
\fB\-d \-\-delay=DELAY\fR
|
\fB\-d \-\-delay=DELAY\fR
|
||||||
Delay between updates, in tenths of seconds
|
Delay between updates, in tenths of seconds. If the delay value is
|
||||||
|
less than 1 it is increased to 1, i.e. 1/10 second. If the delay value
|
||||||
|
is greater than 100, it is decreased to 100, i.e. 10 seconds.
|
||||||
.TP
|
.TP
|
||||||
\fB\-C \-\-no-color \-\-no-colour\fR
|
\fB\-C \-\-no-color \-\-no-colour\fR
|
||||||
Start htop in monochrome mode
|
Start
|
||||||
|
.B htop
|
||||||
|
in monochrome mode
|
||||||
.TP
|
.TP
|
||||||
\fB\-h \-\-help
|
\fB\-h \-\-help
|
||||||
Display a help message and exit
|
Display a help message and exit
|
||||||
@ -44,11 +53,10 @@ Output version information and exit
|
|||||||
.TP
|
.TP
|
||||||
\fB\-t \-\-tree
|
\fB\-t \-\-tree
|
||||||
Show processes in tree view
|
Show processes in tree view
|
||||||
.PP
|
|
||||||
.br
|
|
||||||
.SH "INTERACTIVE COMMANDS"
|
.SH "INTERACTIVE COMMANDS"
|
||||||
.LP
|
.LP
|
||||||
The following commands are supported while in htop:
|
The following commands are supported while in
|
||||||
|
.BR htop :
|
||||||
.LP
|
.LP
|
||||||
.TP 5
|
.TP 5
|
||||||
.B Up, Alt-k
|
.B Up, Alt-k
|
||||||
@ -194,14 +202,17 @@ Refresh: redraw screen and recalculate values.
|
|||||||
.B Numbers
|
.B Numbers
|
||||||
PID search: type in process ID and the selection highlight will be moved to it.
|
PID search: type in process ID and the selection highlight will be moved to it.
|
||||||
.PD
|
.PD
|
||||||
|
|
||||||
.SH "COLUMNS"
|
.SH "COLUMNS"
|
||||||
.LP
|
.LP
|
||||||
The following columns can display data about each process. A value of '\-' in
|
The following columns can display data about each process. A value of '\-' in
|
||||||
all the rows indicates that a column is unsupported on your system, or
|
all the rows indicates that a column is unsupported on your system, or
|
||||||
currently unimplemented in htop. The names below are the ones used in the
|
currently unimplemented in
|
||||||
|
.BR htop .
|
||||||
|
The names below are the ones used in the
|
||||||
"Available Columns" section of the setup screen. If a different name is
|
"Available Columns" section of the setup screen. If a different name is
|
||||||
shown in htop's main screen, it is shown below in parenthesis.
|
shown in
|
||||||
|
.BR htop 's
|
||||||
|
main screen, it is shown below in parenthesis.
|
||||||
.LP
|
.LP
|
||||||
.TP 5
|
.TP 5
|
||||||
.B Command
|
.B Command
|
||||||
@ -389,36 +400,44 @@ The percentage of time spent swapping in pages. Requires CAP_NET_ADMIN.
|
|||||||
.TP
|
.TP
|
||||||
.B All other flags
|
.B All other flags
|
||||||
Currently unsupported (always displays '-').
|
Currently unsupported (always displays '-').
|
||||||
|
|
||||||
.SH "CONFIG FILE"
|
.SH "CONFIG FILE"
|
||||||
.LP
|
.LP
|
||||||
By default htop reads its configuration from the XDG-compliant path
|
By default
|
||||||
~/.config/htop/htoprc -- the configuration file is overwritten by htop's
|
.B htop
|
||||||
in-program Setup configuration, so it should not be hand-edited. If no
|
reads its configuration from the XDG-compliant path
|
||||||
user configuration exists htop tries to read the system-wide configuration
|
.IR ~/.config/htop/htoprc .
|
||||||
from @sysconfdir@/htoprc and as a last resort, falls back to its
|
The configuration file is overwritten by
|
||||||
hard coded defaults.
|
.BR htop 's
|
||||||
|
in-program Setup configuration, so it should not be hand-edited.
|
||||||
|
If no user configuration exists
|
||||||
|
.B htop
|
||||||
|
tries to read the system-wide configuration from
|
||||||
|
.I @sysconfdir@/htoprc
|
||||||
|
and as a last resort, falls back to its hard coded defaults.
|
||||||
.LP
|
.LP
|
||||||
You may override the location of the configuration file using the $HTOPRC
|
You may override the location of the configuration file using the $HTOPRC
|
||||||
environment variable (so you can have multiple configurations for different
|
environment variable (so you can have multiple configurations for different
|
||||||
machines that share the same home directory, for example).
|
machines that share the same home directory, for example).
|
||||||
|
|
||||||
.SH "MEMORY SIZES"
|
.SH "MEMORY SIZES"
|
||||||
.LP
|
.LP
|
||||||
Memory sizes in htop are displayed as they are in tools from the GNU Coreutils
|
Memory sizes in
|
||||||
(when ran with the --human-readable option). This means that sizes are printed
|
.B htop
|
||||||
in powers of 1024. (e.g., 1023M = 1072693248 Bytes)
|
are displayed in a human-readable form.
|
||||||
|
Sizes are printed in powers of 1024. (e.g., 1023M = 1072693248 Bytes)
|
||||||
.LP
|
.LP
|
||||||
The decision to use this convention was made in order to conserve screen space
|
The decision to use this convention was made in order to conserve screen
|
||||||
and make memory size representations consistent throughout htop.
|
space and make memory size representations consistent throughout
|
||||||
|
.BR htop .
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
proc(5), top(1), free(1), ps(1), uptime(1), limits.conf(5)
|
.BR proc (5),
|
||||||
|
.BR top (1),
|
||||||
|
.BR free (1),
|
||||||
|
.BR ps (1),
|
||||||
|
.BR uptime (1)
|
||||||
|
and
|
||||||
|
.BR limits.conf (5).
|
||||||
.SH "AUTHORS"
|
.SH "AUTHORS"
|
||||||
.LP
|
.LP
|
||||||
htop is developed by Hisham Muhammad <hisham@gobolinux.org>.
|
.B htop
|
||||||
.LP
|
was originally developed by Hisham Muhammad.
|
||||||
This man page was written by Bartosz Fenski <fenio@o2.pl> for the Debian
|
Nowadays it is maintained by the community at <htop@groups.io>.
|
||||||
GNU/Linux distribution (but it may be used by others). It was updated by Hisham
|
|
||||||
Muhammad, and later by Vincent Launchbury, who wrote the 'Columns' section.
|
|
||||||
|
41
htop.c
41
htop.c
@ -39,11 +39,12 @@ static void printHelpFlag() {
|
|||||||
fputs("htop " VERSION " - " COPYRIGHT "\n"
|
fputs("htop " VERSION " - " COPYRIGHT "\n"
|
||||||
"Released under the GNU GPL.\n\n"
|
"Released under the GNU GPL.\n\n"
|
||||||
"-C --no-color Use a monochrome color scheme\n"
|
"-C --no-color Use a monochrome color scheme\n"
|
||||||
|
"-m --no-mouse Disable the mouse\n"
|
||||||
"-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"
|
"-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 for a given user (or $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"
|
||||||
"\n"
|
"\n"
|
||||||
@ -62,6 +63,7 @@ typedef struct CommandLineSettings_ {
|
|||||||
int sortKey;
|
int sortKey;
|
||||||
int delay;
|
int delay;
|
||||||
bool useColors;
|
bool useColors;
|
||||||
|
bool enableMouse;
|
||||||
bool treeView;
|
bool treeView;
|
||||||
} CommandLineSettings;
|
} CommandLineSettings;
|
||||||
|
|
||||||
@ -73,6 +75,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
.sortKey = 0,
|
.sortKey = 0,
|
||||||
.delay = -1,
|
.delay = -1,
|
||||||
.useColors = true,
|
.useColors = true,
|
||||||
|
.enableMouse = true,
|
||||||
.treeView = false,
|
.treeView = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,18 +85,18 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{"delay", required_argument, 0, 'd'},
|
{"delay", required_argument, 0, 'd'},
|
||||||
{"sort-key", required_argument, 0, 's'},
|
{"sort-key", required_argument, 0, 's'},
|
||||||
{"user", required_argument, 0, 'u'},
|
{"user", optional_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'},
|
||||||
|
{"no-mouse", no_argument, 0, 'm'},
|
||||||
{"tree", no_argument, 0, 't'},
|
{"tree", no_argument, 0, 't'},
|
||||||
{"pid", required_argument, 0, 'p'},
|
{"pid", required_argument, 0, 'p'},
|
||||||
{"io", no_argument, 0, 'i'},
|
|
||||||
{0,0,0,0}
|
{0,0,0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int opt, opti=0;
|
int opt, opti=0;
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:i", long_opts, &opti))) {
|
while ((opt = getopt_long(argc, argv, "hvmCs:td:u::p:", long_opts, &opti))) {
|
||||||
if (opt == EOF) break;
|
if (opt == EOF) break;
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -113,6 +116,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
flags.sortKey = ColumnsPanel_fieldNameToIndex(optarg);
|
flags.sortKey = ColumnsPanel_fieldNameToIndex(optarg);
|
||||||
if (flags.sortKey == -1) {
|
if (flags.sortKey == -1) {
|
||||||
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
|
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -121,16 +125,31 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
if (flags.delay > 100) flags.delay = 100;
|
if (flags.delay > 100) flags.delay = 100;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
|
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
|
if (!optarg && optind < argc && argv[optind] != NULL &&
|
||||||
|
(argv[optind][0] != '\0' && argv[optind][0] != '-')) {
|
||||||
|
optarg = argv[optind++];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!optarg) {
|
||||||
|
optarg = getenv("USER");
|
||||||
|
flags.userId = geteuid();
|
||||||
|
}
|
||||||
|
|
||||||
if (!Action_setUserOnly(optarg, &(flags.userId))) {
|
if (!Action_setUserOnly(optarg, &(flags.userId))) {
|
||||||
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
|
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
flags.useColors = false;
|
flags.useColors = false;
|
||||||
break;
|
break;
|
||||||
|
case 'm':
|
||||||
|
flags.enableMouse = false;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
flags.treeView = true;
|
flags.treeView = true;
|
||||||
break;
|
break;
|
||||||
@ -204,20 +223,22 @@ 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.enableMouse)
|
||||||
|
settings->enableMouse = false;
|
||||||
if (flags.treeView)
|
if (flags.treeView)
|
||||||
settings->screens[0]->treeView = true;
|
settings->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->screens[0]->treeView);
|
MainPanel_updateTreeFunctions(panel, settings->treeView);
|
||||||
|
|
||||||
if (flags.sortKey > 0) {
|
if (flags.sortKey > 0) {
|
||||||
settings->screens[0]->sortKey = flags.sortKey;
|
settings->sortKey = flags.sortKey;
|
||||||
settings->screens[0]->treeView = false;
|
settings->treeView = false;
|
||||||
settings->screens[0]->direction = 1;
|
settings->direction = 1;
|
||||||
}
|
}
|
||||||
ProcessList_printHeader(pl, Panel_getHeader((Panel*)panel));
|
ProcessList_printHeader(pl, Panel_getHeader((Panel*)panel));
|
||||||
|
|
||||||
@ -237,7 +258,7 @@ int main(int argc, char** argv) {
|
|||||||
millisleep(75);
|
millisleep(75);
|
||||||
ProcessList_scan(pl);
|
ProcessList_scan(pl);
|
||||||
|
|
||||||
ScreenManager_run(scr, NULL, NULL, NULL);
|
ScreenManager_run(scr, NULL, NULL);
|
||||||
|
|
||||||
attron(CRT_colors[RESET_COLOR]);
|
attron(CRT_colors[RESET_COLOR]);
|
||||||
mvhline(LINES-1, 0, ' ', COLS);
|
mvhline(LINES-1, 0, ' ', COLS);
|
||||||
|
@ -4,6 +4,7 @@ Version=1.0
|
|||||||
Name=Htop
|
Name=Htop
|
||||||
GenericName=Process Viewer
|
GenericName=Process Viewer
|
||||||
GenericName[ca]=Visualitzador de processos
|
GenericName[ca]=Visualitzador de processos
|
||||||
|
GenericName[da]=Procesfremviser
|
||||||
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
|
||||||
@ -32,6 +33,7 @@ GenericName[zh_CN]=进程查看器
|
|||||||
GenericName[zh_TW]=行程檢視器
|
GenericName[zh_TW]=行程檢視器
|
||||||
Comment=Show System Processes
|
Comment=Show System Processes
|
||||||
Comment[ca]=Visualitzeu els processos del sistema
|
Comment[ca]=Visualitzeu els processos del sistema
|
||||||
|
Comment[da]=Vis systemprocesser
|
||||||
Comment[de]=Systemprozesse anzeigen
|
Comment[de]=Systemprozesse anzeigen
|
||||||
Comment[en_GB]=Show System Processes
|
Comment[en_GB]=Show System Processes
|
||||||
Comment[es]=Mostrar procesos del sistema
|
Comment[es]=Mostrar procesos del sistema
|
||||||
|
2
htop.h
2
htop.h
@ -14,6 +14,6 @@ in the source distribution for its full text.
|
|||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv);
|
extern int main(int argc, char** argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -193,8 +193,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
|||||||
char* entryName = (char *) dirEntry->d_name;
|
char* entryName = (char *) dirEntry->d_name;
|
||||||
const char filePath[50];
|
const char filePath[50];
|
||||||
|
|
||||||
if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') {
|
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName);
|
||||||
|
int fd = open(filePath, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char type[8];
|
||||||
|
ssize_t typelen = xread(fd, type, 7);
|
||||||
|
close(fd);
|
||||||
|
if (typelen < 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') {
|
||||||
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName);
|
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName);
|
||||||
int fd = open(filePath, O_RDONLY);
|
int fd = open(filePath, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
@ -29,6 +29,6 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat
|
|||||||
// READ FROM /sys
|
// READ FROM /sys
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
extern void Battery_getData(double* level, ACPresence* isOnAC);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,9 +13,9 @@ in the source distribution for its full text.
|
|||||||
#include "IOPriority.h"
|
#include "IOPriority.h"
|
||||||
#include "ListItem.h"
|
#include "ListItem.h"
|
||||||
|
|
||||||
Panel* IOPriorityPanel_new(IOPriority currPrio);
|
extern Panel* IOPriorityPanel_new(IOPriority currPrio);
|
||||||
|
|
||||||
IOPriority IOPriorityPanel_getIOPriority(Panel* this);
|
extern IOPriority IOPriorityPanel_getIOPriority(Panel* this);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,6 @@ in the source distribution for its full text.
|
|||||||
#ifdef HAVE_EXECINFO_H
|
#ifdef HAVE_EXECINFO_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn);
|
extern void CRT_handleSIGSEGV(int sgn);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
htop - LinuxProcess.c
|
htop - LinuxProcess.c
|
||||||
(C) 2014 Hisham H. Muhammad
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
@ -19,24 +20,12 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
|
||||||
#include "PerfCounter.h"
|
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100
|
||||||
|
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200
|
||||||
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100L
|
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
|
||||||
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200L
|
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
|
||||||
#define PROCESS_FLAG_LINUX_VSERVER 0x0400L
|
#define PROCESS_FLAG_LINUX_OOM 0x1000
|
||||||
#define PROCESS_FLAG_LINUX_CGROUP 0x0800L
|
#define PROCESS_FLAG_LINUX_SMAPS 0x2000
|
||||||
#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,
|
||||||
@ -100,18 +89,10 @@ typedef enum LinuxProcessFields {
|
|||||||
PERCENT_IO_DELAY = 117,
|
PERCENT_IO_DELAY = 117,
|
||||||
PERCENT_SWAP_DELAY = 118,
|
PERCENT_SWAP_DELAY = 118,
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PERFCOUNTERS
|
M_PSS = 119,
|
||||||
IPC = 119,
|
M_SWAP = 120,
|
||||||
MCYCLE = 120,
|
M_PSSWP = 121,
|
||||||
MINSTR = 121,
|
LAST_PROCESSFIELD = 122,
|
||||||
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"
|
||||||
@ -127,6 +108,9 @@ typedef struct LinuxProcess_ {
|
|||||||
unsigned long long int cutime;
|
unsigned long long int cutime;
|
||||||
unsigned long long int cstime;
|
unsigned long long int cstime;
|
||||||
long m_share;
|
long m_share;
|
||||||
|
long m_pss;
|
||||||
|
long m_swap;
|
||||||
|
long m_psswp;
|
||||||
long m_trs;
|
long m_trs;
|
||||||
long m_drs;
|
long m_drs;
|
||||||
long m_lrs;
|
long m_lrs;
|
||||||
@ -166,25 +150,6 @@ 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
|
||||||
@ -197,7 +162,8 @@ typedef struct LinuxProcess_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
long long btime; /* semi-global */
|
/* semi-global */
|
||||||
|
long long btime;
|
||||||
|
|
||||||
ProcessFieldData Process_fields[] = {
|
ProcessFieldData Process_fields[] = {
|
||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
@ -278,21 +244,13 @@ 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 = "CPD% ", .description = "CPU delay %", .flags = 0, },
|
[PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPUD% ", .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 = "SWD% ", .description = "Swapin delay %", .flags = 0, },
|
[PERCENT_SWAP_DELAY] = { .name = "PERCENT_SWAP_DELAY", .title = "SWAPD% ", .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
|
||||||
|
[M_PSS] = { .name = "M_PSS", .title = " PSS ", .description = "proportional set size, same as M_RESIDENT but each page is divided by the number of processes sharing it.", .flags = PROCESS_FLAG_LINUX_SMAPS, },
|
||||||
|
[M_SWAP] = { .name = "M_SWAP", .title = " SWAP ", .description = "Size of the process's swapped pages", .flags = PROCESS_FLAG_LINUX_SMAPS, },
|
||||||
|
[M_PSSWP] = { .name = "M_PSSWP", .title = " PSSWP ", .description = "shows proportional swap share of this mapping, Unlike \"Swap\", this does not take into account swapped out page of underlying shmem objects.", .flags = PROCESS_FLAG_LINUX_SMAPS, },
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -332,10 +290,6 @@ 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);
|
||||||
@ -361,51 +315,22 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) {
|
|||||||
return ioprio;
|
return ioprio;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) {
|
bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio) {
|
||||||
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
|
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
|
||||||
#ifdef SYS_ioprio_set
|
#ifdef SYS_ioprio_set
|
||||||
syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio);
|
syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio.i);
|
||||||
#endif
|
#endif
|
||||||
return (LinuxProcess_updateIOPriority(this) == ioprio);
|
return (LinuxProcess_updateIOPriority(this) == ioprio.i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_DELAYACCT || HAVE_PERFCOUNTERS
|
#ifdef HAVE_DELAYACCT
|
||||||
|
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) {
|
||||||
static char* perfFmt[] = {
|
if (delay_percent == -1LL) {
|
||||||
"%6.2f ",
|
xSnprintf(buffer, n, " N/A ");
|
||||||
NULL,
|
|
||||||
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 {
|
} else {
|
||||||
xSnprintf(buffer, n, perfNA[len]);
|
xSnprintf(buffer, n, "%4.1f ", delay_percent);
|
||||||
*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) {
|
||||||
@ -431,6 +356,9 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
|||||||
case M_LRS: Process_humanNumber(str, lp->m_lrs * PAGE_SIZE_KB, coloring); return;
|
case M_LRS: Process_humanNumber(str, lp->m_lrs * PAGE_SIZE_KB, coloring); return;
|
||||||
case M_TRS: Process_humanNumber(str, lp->m_trs * PAGE_SIZE_KB, coloring); return;
|
case M_TRS: Process_humanNumber(str, lp->m_trs * PAGE_SIZE_KB, coloring); return;
|
||||||
case M_SHARE: Process_humanNumber(str, lp->m_share * PAGE_SIZE_KB, coloring); return;
|
case M_SHARE: Process_humanNumber(str, lp->m_share * PAGE_SIZE_KB, coloring); return;
|
||||||
|
case M_PSS: Process_humanNumber(str, lp->m_pss, coloring); return;
|
||||||
|
case M_SWAP: Process_humanNumber(str, lp->m_swap, coloring); return;
|
||||||
|
case M_PSSWP: Process_humanNumber(str, lp->m_psswp, coloring); return;
|
||||||
case UTIME: Process_printTime(str, lp->utime); return;
|
case UTIME: Process_printTime(str, lp->utime); return;
|
||||||
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;
|
||||||
@ -489,20 +417,9 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
case PERCENT_CPU_DELAY: Process_printPercentage(lp->cpu_delay_percent, buffer, n, &attr); break;
|
case PERCENT_CPU_DELAY: LinuxProcess_printDelay(lp->cpu_delay_percent, buffer, n); break;
|
||||||
case PERCENT_IO_DELAY: Process_printPercentage(lp->blkio_delay_percent, buffer, n, &attr); break;
|
case PERCENT_IO_DELAY: LinuxProcess_printDelay(lp->blkio_delay_percent, buffer, n); break;
|
||||||
case PERCENT_SWAP_DELAY: Process_printPercentage(lp->swapin_delay_percent, buffer, n, &attr); break;
|
case PERCENT_SWAP_DELAY: LinuxProcess_printDelay(lp->swapin_delay_percent, buffer, n); 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);
|
||||||
@ -511,12 +428,10 @@ 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->ss->direction == 1) {
|
if (settings->direction == 1) {
|
||||||
p1 = (LinuxProcess*)v1;
|
p1 = (LinuxProcess*)v1;
|
||||||
p2 = (LinuxProcess*)v2;
|
p2 = (LinuxProcess*)v2;
|
||||||
} else {
|
} else {
|
||||||
@ -524,11 +439,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
|||||||
p1 = (LinuxProcess*)v2;
|
p1 = (LinuxProcess*)v2;
|
||||||
}
|
}
|
||||||
long long diff;
|
long long diff;
|
||||||
switch ((int)settings->ss->sortKey) {
|
switch ((int)settings->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:
|
||||||
@ -539,6 +450,12 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
|||||||
return (p2->m_trs - p1->m_trs);
|
return (p2->m_trs - p1->m_trs);
|
||||||
case M_SHARE:
|
case M_SHARE:
|
||||||
return (p2->m_share - p1->m_share);
|
return (p2->m_share - p1->m_share);
|
||||||
|
case M_PSS:
|
||||||
|
return (p2->m_pss - p1->m_pss);
|
||||||
|
case M_SWAP:
|
||||||
|
return (p2->m_swap - p1->m_swap);
|
||||||
|
case M_PSSWP:
|
||||||
|
return (p2->m_psswp - p1->m_psswp);
|
||||||
case UTIME: diff = p2->utime - p1->utime; goto test_diff;
|
case UTIME: diff = p2->utime - p1->utime; goto test_diff;
|
||||||
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;
|
||||||
@ -578,20 +495,12 @@ 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: COMPARE_FIELD(cpu_delay_percent);
|
case PERCENT_CPU_DELAY:
|
||||||
case PERCENT_IO_DELAY: COMPARE_FIELD(blkio_delay_percent);
|
return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1);
|
||||||
case PERCENT_SWAP_DELAY: COMPARE_FIELD(swapin_delay_percent);
|
case PERCENT_IO_DELAY:
|
||||||
#endif
|
return (p2->blkio_delay_percent > p1->blkio_delay_percent ? 1 : -1);
|
||||||
#ifdef HAVE_PERFCOUNTERS
|
case PERCENT_SWAP_DELAY:
|
||||||
case PERCENT_MISS: COMPARE_FIELD(pMiss);
|
return (p2->swapin_delay_percent > p1->swapin_delay_percent ? 1 : -1);
|
||||||
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);
|
||||||
@ -605,3 +514,4 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,29 +5,18 @@
|
|||||||
/*
|
/*
|
||||||
htop - LinuxProcess.h
|
htop - LinuxProcess.h
|
||||||
(C) 2014 Hisham H. Muhammad
|
(C) 2014 Hisham H. Muhammad
|
||||||
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "PerfCounter.h"
|
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100
|
||||||
|
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200
|
||||||
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100L
|
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
|
||||||
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200L
|
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
|
||||||
#define PROCESS_FLAG_LINUX_VSERVER 0x0400L
|
#define PROCESS_FLAG_LINUX_OOM 0x1000
|
||||||
#define PROCESS_FLAG_LINUX_CGROUP 0x0800L
|
#define PROCESS_FLAG_LINUX_SMAPS 0x2000
|
||||||
#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,
|
||||||
@ -91,18 +80,10 @@ typedef enum LinuxProcessFields {
|
|||||||
PERCENT_IO_DELAY = 117,
|
PERCENT_IO_DELAY = 117,
|
||||||
PERCENT_SWAP_DELAY = 118,
|
PERCENT_SWAP_DELAY = 118,
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PERFCOUNTERS
|
M_PSS = 119,
|
||||||
IPC = 119,
|
M_SWAP = 120,
|
||||||
MCYCLE = 120,
|
M_PSSWP = 121,
|
||||||
MINSTR = 121,
|
LAST_PROCESSFIELD = 122,
|
||||||
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"
|
||||||
@ -118,6 +99,9 @@ typedef struct LinuxProcess_ {
|
|||||||
unsigned long long int cutime;
|
unsigned long long int cutime;
|
||||||
unsigned long long int cstime;
|
unsigned long long int cstime;
|
||||||
long m_share;
|
long m_share;
|
||||||
|
long m_pss;
|
||||||
|
long m_swap;
|
||||||
|
long m_psswp;
|
||||||
long m_trs;
|
long m_trs;
|
||||||
long m_drs;
|
long m_drs;
|
||||||
long m_lrs;
|
long m_lrs;
|
||||||
@ -157,25 +141,6 @@ 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
|
||||||
@ -187,7 +152,8 @@ typedef struct LinuxProcess_ {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
long long btime; /* semi-global */
|
/* semi-global */
|
||||||
|
extern long long btime;
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
@ -195,9 +161,9 @@ extern ProcessPidColumn Process_pidColumns[];
|
|||||||
|
|
||||||
extern ProcessClass LinuxProcess_class;
|
extern ProcessClass LinuxProcess_class;
|
||||||
|
|
||||||
LinuxProcess* LinuxProcess_new(Settings* settings);
|
extern LinuxProcess* LinuxProcess_new(Settings* settings);
|
||||||
|
|
||||||
void Process_delete(Object* cast);
|
extern void Process_delete(Object* cast);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[1] Note that before kernel 2.6.26 a process that has not asked for
|
[1] Note that before kernel 2.6.26 a process that has not asked for
|
||||||
@ -209,20 +175,19 @@ extern io_priority;
|
|||||||
*/
|
*/
|
||||||
#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority)
|
#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority)
|
||||||
|
|
||||||
IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
|
extern IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
|
||||||
|
|
||||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio);
|
extern bool LinuxProcess_setIOPriority(LinuxProcess* this, Arg ioprio);
|
||||||
|
|
||||||
#if HAVE_DELAYACCT || HAVE_PERFCOUNTERS
|
|
||||||
|
|
||||||
|
#ifdef HAVE_DELAYACCT
|
||||||
|
extern void LinuxProcess_printDelay(float delay_percent, char* buffer, int n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field);
|
extern void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
|
|
||||||
#define COMPARE_FIELD(_f) return (p2->_f > p1->_f ? 1 : -1)
|
extern long LinuxProcess_compare(const void* v1, const void* v2);
|
||||||
|
|
||||||
long LinuxProcess_compare(const void* v1, const void* v2);
|
extern bool Process_isThread(Process* this);
|
||||||
|
|
||||||
bool Process_isThread(Process* this);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,8 +28,7 @@ in the source distribution for its full text.
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#ifdef MAJOR_IN_MKDEV
|
#ifdef MAJOR_IN_MKDEV
|
||||||
#include <sys/mkdev.h>
|
#include <sys/mkdev.h>
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
#elif defined(MAJOR_IN_SYSMACROS)
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -46,6 +45,7 @@ in the source distribution for its full text.
|
|||||||
/*{
|
/*{
|
||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
|
||||||
extern long long btime;
|
extern long long btime;
|
||||||
|
|
||||||
@ -75,6 +75,8 @@ typedef struct CPUData_ {
|
|||||||
unsigned long long int softIrqPeriod;
|
unsigned long long int softIrqPeriod;
|
||||||
unsigned long long int stealPeriod;
|
unsigned long long int stealPeriod;
|
||||||
unsigned long long int guestPeriod;
|
unsigned long long int guestPeriod;
|
||||||
|
|
||||||
|
double frequency;
|
||||||
} CPUData;
|
} CPUData;
|
||||||
|
|
||||||
typedef struct TtyDriver_ {
|
typedef struct TtyDriver_ {
|
||||||
@ -89,17 +91,24 @@ typedef struct LinuxProcessList_ {
|
|||||||
|
|
||||||
CPUData* cpus;
|
CPUData* cpus;
|
||||||
TtyDriver* ttyDrivers;
|
TtyDriver* ttyDrivers;
|
||||||
|
bool haveSmapsRollup;
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
struct nl_sock *netlink_socket;
|
struct nl_sock *netlink_socket;
|
||||||
int netlink_family;
|
int netlink_family;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
} LinuxProcessList;
|
} LinuxProcessList;
|
||||||
|
|
||||||
#ifndef PROCDIR
|
#ifndef PROCDIR
|
||||||
#define PROCDIR "/proc"
|
#define PROCDIR "/proc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PROCCPUINFOFILE
|
||||||
|
#define PROCCPUINFOFILE PROCDIR "/cpuinfo"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PROCSTATFILE
|
#ifndef PROCSTATFILE
|
||||||
#define PROCSTATFILE PROCDIR "/stat"
|
#define PROCSTATFILE PROCDIR "/stat"
|
||||||
#endif
|
#endif
|
||||||
@ -108,6 +117,10 @@ typedef struct LinuxProcessList_ {
|
|||||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PROCARCSTATSFILE
|
||||||
|
#define PROCARCSTATSFILE PROCDIR "/spl/kstat/zfs/arcstats"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PROCTTYDRIVERSFILE
|
#ifndef PROCTTYDRIVERSFILE
|
||||||
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
|
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
|
||||||
#endif
|
#endif
|
||||||
@ -240,8 +253,17 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
|||||||
LinuxProcessList_initNetlinkSocket(this);
|
LinuxProcessList_initNetlinkSocket(this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Check for /proc/*/smaps_rollup availability (improves smaps parsing speed, Linux 4.14+)
|
||||||
|
FILE* file = fopen(PROCDIR "/self/smaps_rollup", "r");
|
||||||
|
if(file != NULL) {
|
||||||
|
this->haveSmapsRollup = true;
|
||||||
|
fclose(file);
|
||||||
|
} else {
|
||||||
|
this->haveSmapsRollup = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Update CPU count:
|
// Update CPU count:
|
||||||
FILE* file = fopen(PROCSTATFILE, "r");
|
file = fopen(PROCSTATFILE, "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
CRT_fatalError("Cannot open " PROCSTATFILE);
|
CRT_fatalError("Cannot open " PROCSTATFILE);
|
||||||
}
|
}
|
||||||
@ -486,6 +508,62 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* di
|
|||||||
return (errno == 0);
|
return (errno == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* dirname, const char* name, bool haveSmapsRollup) {
|
||||||
|
//http://elixir.free-electrons.com/linux/v4.10/source/fs/proc/task_mmu.c#L719
|
||||||
|
//kernel will return data in chunks of size PAGE_SIZE or less.
|
||||||
|
|
||||||
|
char buffer[PAGE_SIZE];// 4k
|
||||||
|
char *start,*end;
|
||||||
|
ssize_t nread=0;
|
||||||
|
int tmp=0;
|
||||||
|
if(haveSmapsRollup) {// only available in Linux 4.14+
|
||||||
|
snprintf(buffer, PAGE_SIZE-1, "%s/%s/smaps_rollup", dirname, name);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, PAGE_SIZE-1, "%s/%s/smaps", dirname, name);
|
||||||
|
}
|
||||||
|
int fd = open(buffer, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
process->m_pss = 0;
|
||||||
|
process->m_swap = 0;
|
||||||
|
process->m_psswp = 0;
|
||||||
|
|
||||||
|
while ( ( nread = read(fd,buffer, sizeof(buffer)) ) > 0 ){
|
||||||
|
start = (char *)&buffer;
|
||||||
|
end = start + nread;
|
||||||
|
do{//parse 4k block
|
||||||
|
|
||||||
|
if( (tmp = (end - start)) > 0 &&
|
||||||
|
(start = memmem(start,tmp,"\nPss:",5)) != NULL )
|
||||||
|
{
|
||||||
|
process->m_pss += strtol(start+5, &start, 10);
|
||||||
|
start += 3;//now we must be at the end of line "Pss: 0 kB"
|
||||||
|
}else
|
||||||
|
break; //read next 4k block
|
||||||
|
|
||||||
|
if( (tmp = (end - start)) > 0 &&
|
||||||
|
(start = memmem(start,tmp,"\nSwap:",6)) != NULL )
|
||||||
|
{
|
||||||
|
process->m_swap += strtol(start+6, &start, 10);
|
||||||
|
start += 3;
|
||||||
|
}else
|
||||||
|
break;
|
||||||
|
|
||||||
|
if( (tmp = (end - start)) > 0 &&
|
||||||
|
(start = memmem(start,tmp,"\nSwapPss:",9)) != NULL )
|
||||||
|
{
|
||||||
|
process->m_psswp += strtol(start+9, &start, 10);
|
||||||
|
start += 3;
|
||||||
|
}else
|
||||||
|
break;
|
||||||
|
|
||||||
|
}while(1);
|
||||||
|
}//while read
|
||||||
|
close(fd);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_OPENVZ
|
#ifdef HAVE_OPENVZ
|
||||||
|
|
||||||
static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) {
|
static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) {
|
||||||
@ -656,9 +734,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 = -1;
|
process->swapin_delay_percent = -1LL;
|
||||||
process->blkio_delay_percent = -1;
|
process->blkio_delay_percent = -1LL;
|
||||||
process->cpu_delay_percent = -1;
|
process->cpu_delay_percent = -1LL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,77 +747,6 @@ 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);
|
||||||
@ -763,7 +770,11 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
|||||||
int tokenEnd = 0;
|
int tokenEnd = 0;
|
||||||
int lastChar = 0;
|
int lastChar = 0;
|
||||||
if (amtRead == 0) {
|
if (amtRead == 0) {
|
||||||
|
if (process->state == 'Z') {
|
||||||
|
process->basenameOffset = 0;
|
||||||
|
} else {
|
||||||
((LinuxProcess*)process)->isKernelThread = true;
|
((LinuxProcess*)process)->isKernelThread = true;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (amtRead < 0) {
|
} else if (amtRead < 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -835,7 +846,6 @@ 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;
|
|
||||||
|
|
||||||
#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;
|
||||||
@ -880,13 +890,28 @@ 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 (ss->flags & PROCESS_FLAG_IO)
|
if (settings->flags & PROCESS_FLAG_IO)
|
||||||
LinuxProcessList_readIoFile(lp, dirname, name, now);
|
LinuxProcessList_readIoFile(lp, dirname, name, now);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (! LinuxProcessList_readStatmFile(lp, dirname, name))
|
if (! LinuxProcessList_readStatmFile(lp, dirname, name))
|
||||||
goto errorReadingProcess;
|
goto errorReadingProcess;
|
||||||
|
|
||||||
|
if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)){
|
||||||
|
if (!parent){
|
||||||
|
// Read smaps file of each process only every second pass to improve performance
|
||||||
|
static int smaps_flag = 0;
|
||||||
|
if ((pid & 1) == smaps_flag){
|
||||||
|
LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup);
|
||||||
|
}
|
||||||
|
if (pid == 1) {
|
||||||
|
smaps_flag = !smaps_flag;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lp->m_pss = ((LinuxProcess*)parent)->m_pss;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
|
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
|
||||||
|
|
||||||
char command[MAX_NAME+1];
|
char command[MAX_NAME+1];
|
||||||
@ -899,7 +924,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 (ss->flags & PROCESS_FLAG_LINUX_IOPRIO)
|
if (settings->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);
|
||||||
@ -914,13 +939,13 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
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 (ss->flags & PROCESS_FLAG_LINUX_OPENVZ) {
|
if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) {
|
||||||
LinuxProcessList_readOpenVZData(lp, dirname, name);
|
LinuxProcessList_readOpenVZData(lp, dirname, name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_VSERVER
|
#ifdef HAVE_VSERVER
|
||||||
if (ss->flags & PROCESS_FLAG_LINUX_VSERVER) {
|
if (settings->flags & PROCESS_FLAG_LINUX_VSERVER) {
|
||||||
LinuxProcessList_readVServerData(lp, dirname, name);
|
LinuxProcessList_readVServerData(lp, dirname, name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -943,18 +968,13 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
if (ss->flags & PROCESS_FLAG_LINUX_CGROUP)
|
if (settings->flags & PROCESS_FLAG_LINUX_CGROUP)
|
||||||
LinuxProcessList_readCGroupFile(lp, dirname, name);
|
LinuxProcessList_readCGroupFile(lp, dirname, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ss->flags & PROCESS_FLAG_LINUX_OOM)
|
if (settings->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);
|
||||||
@ -1004,30 +1024,30 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
|
|||||||
char buffer[128];
|
char buffer[128];
|
||||||
while (fgets(buffer, 128, file)) {
|
while (fgets(buffer, 128, file)) {
|
||||||
|
|
||||||
#define tryRead(label, variable) (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %32llu kB", variable))
|
#define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %32llu kB", variable)) { break; } } while(0)
|
||||||
switch (buffer[0]) {
|
switch (buffer[0]) {
|
||||||
case 'M':
|
case 'M':
|
||||||
if (tryRead("MemTotal:", &this->totalMem)) {}
|
tryRead("MemTotal:", &this->totalMem);
|
||||||
else if (tryRead("MemFree:", &this->freeMem)) {}
|
tryRead("MemFree:", &this->freeMem);
|
||||||
else if (tryRead("MemShared:", &this->sharedMem)) {}
|
tryRead("MemShared:", &this->sharedMem);
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
if (tryRead("Buffers:", &this->buffersMem)) {}
|
tryRead("Buffers:", &this->buffersMem);
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
if (tryRead("Cached:", &this->cachedMem)) {}
|
tryRead("Cached:", &this->cachedMem);
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
switch (buffer[1]) {
|
switch (buffer[1]) {
|
||||||
case 'w':
|
case 'w':
|
||||||
if (tryRead("SwapTotal:", &this->totalSwap)) {}
|
tryRead("SwapTotal:", &this->totalSwap);
|
||||||
else if (tryRead("SwapFree:", &swapFree)) {}
|
tryRead("SwapFree:", &swapFree);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
if (tryRead("Shmem:", &shmem)) {}
|
tryRead("Shmem:", &shmem);
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
if (tryRead("SReclaimable:", &sreclaimable)) {}
|
tryRead("SReclaimable:", &sreclaimable);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1041,6 +1061,68 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) {
|
||||||
|
unsigned long long int dbufSize;
|
||||||
|
unsigned long long int dnodeSize;
|
||||||
|
unsigned long long int bonusSize;
|
||||||
|
|
||||||
|
FILE* file = fopen(PROCARCSTATSFILE, "r");
|
||||||
|
if (file == NULL) {
|
||||||
|
lpl->zfs.enabled = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char buffer[128];
|
||||||
|
while (fgets(buffer, 128, file)) {
|
||||||
|
#define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0)
|
||||||
|
#define tryReadFlag(label, variable, flag) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { flag = 1; break; } else { flag = 0; } } while(0)
|
||||||
|
switch (buffer[0]) {
|
||||||
|
case 'c':
|
||||||
|
tryRead("c_max", &lpl->zfs.max);
|
||||||
|
tryReadFlag("compressed_size", &lpl->zfs.compressed, lpl->zfs.isCompressed);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
tryRead("uncompressed_size", &lpl->zfs.uncompressed);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
tryRead("size", &lpl->zfs.size);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
tryRead("hdr_size", &lpl->zfs.header);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
tryRead("dbuf_size", &dbufSize);
|
||||||
|
tryRead("dnode_size", &dnodeSize);
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
tryRead("bonus_size", &bonusSize);
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
tryRead("anon_size", &lpl->zfs.anon);
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
tryRead("mfu_size", &lpl->zfs.MFU);
|
||||||
|
tryRead("mru_size", &lpl->zfs.MRU);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#undef tryRead
|
||||||
|
#undef tryReadFlag
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
lpl->zfs.enabled = (lpl->zfs.size > 0 ? 1 : 0);
|
||||||
|
lpl->zfs.size /= 1024;
|
||||||
|
lpl->zfs.max /= 1024;
|
||||||
|
lpl->zfs.MFU /= 1024;
|
||||||
|
lpl->zfs.MRU /= 1024;
|
||||||
|
lpl->zfs.anon /= 1024;
|
||||||
|
lpl->zfs.header /= 1024;
|
||||||
|
lpl->zfs.other = (dbufSize + dnodeSize + bonusSize) / 1024;
|
||||||
|
if ( lpl->zfs.isCompressed ) {
|
||||||
|
lpl->zfs.compressed /= 1024;
|
||||||
|
lpl->zfs.uncompressed /= 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||||
|
|
||||||
FILE* file = fopen(PROCSTATFILE, "r");
|
FILE* file = fopen(PROCSTATFILE, "r");
|
||||||
@ -1105,18 +1187,87 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
|||||||
cpuData->stealTime = steal;
|
cpuData->stealTime = steal;
|
||||||
cpuData->guestTime = virtalltime;
|
cpuData->guestTime = virtalltime;
|
||||||
cpuData->totalTime = totaltime;
|
cpuData->totalTime = totaltime;
|
||||||
|
|
||||||
}
|
}
|
||||||
double period = (double)this->cpus[0].totalPeriod / cpus;
|
double period = (double)this->cpus[0].totalPeriod / cpus;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return period;
|
return period;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) {
|
||||||
|
ProcessList* pl = (ProcessList*) this;
|
||||||
|
Settings* settings = pl->settings;
|
||||||
|
|
||||||
|
int cpus = this->super.cpuCount;
|
||||||
|
assert(cpus > 0);
|
||||||
|
|
||||||
|
for (int i = 0; i <= cpus; i++) {
|
||||||
|
CPUData* cpuData = &(this->cpus[i]);
|
||||||
|
cpuData->frequency = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int numCPUsWithFrequency = 0;
|
||||||
|
double totalFrequency = 0;
|
||||||
|
|
||||||
|
if (settings->showCPUFrequency) {
|
||||||
|
FILE* file = fopen(PROCCPUINFOFILE, "r");
|
||||||
|
if (file == NULL) {
|
||||||
|
CRT_fatalError("Cannot open " PROCCPUINFOFILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cpuid = -1;
|
||||||
|
double frequency;
|
||||||
|
while (!feof(file)) {
|
||||||
|
char buffer[PROC_LINE_LENGTH];
|
||||||
|
char *ok = fgets(buffer, PROC_LINE_LENGTH, file);
|
||||||
|
if (!ok) break;
|
||||||
|
|
||||||
|
if (
|
||||||
|
(sscanf(buffer, "processor : %d", &cpuid) == 1) ||
|
||||||
|
(sscanf(buffer, "processor: %d", &cpuid) == 1)
|
||||||
|
) {
|
||||||
|
if (cpuid < 0 || cpuid > (cpus - 1)) {
|
||||||
|
char buffer[64];
|
||||||
|
xSnprintf(buffer, sizeof(buffer), PROCCPUINFOFILE " contains out-of-range CPU number %d", cpuid);
|
||||||
|
CRT_fatalError(buffer);
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
(sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) ||
|
||||||
|
(sscanf(buffer, "cpu MHz: %lf", &frequency) == 1)
|
||||||
|
) {
|
||||||
|
if (cpuid < 0) {
|
||||||
|
CRT_fatalError(PROCCPUINFOFILE " is malformed: cpu MHz line without corresponding processor line");
|
||||||
|
}
|
||||||
|
|
||||||
|
int cpu = cpuid + 1;
|
||||||
|
CPUData* cpuData = &(this->cpus[cpu]);
|
||||||
|
cpuData->frequency = frequency;
|
||||||
|
numCPUsWithFrequency++;
|
||||||
|
totalFrequency += frequency;
|
||||||
|
} else if (buffer[0] == '\n') {
|
||||||
|
cpuid = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
if (numCPUsWithFrequency > 0) {
|
||||||
|
this->cpus[0].frequency = totalFrequency / numCPUsWithFrequency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double period = (double)this->cpus[0].totalPeriod / cpus;
|
||||||
|
return period;
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* super) {
|
void ProcessList_goThroughEntries(ProcessList* super) {
|
||||||
LinuxProcessList* this = (LinuxProcessList*) super;
|
LinuxProcessList* this = (LinuxProcessList*) super;
|
||||||
|
|
||||||
LinuxProcessList_scanMemoryInfo(super);
|
LinuxProcessList_scanMemoryInfo(super);
|
||||||
|
LinuxProcessList_scanZfsArcstats(this);
|
||||||
double period = LinuxProcessList_scanCPUTime(this);
|
double period = LinuxProcessList_scanCPUTime(this);
|
||||||
|
|
||||||
|
LinuxProcessList_scanCPUFrequency(this);
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
LinuxProcessList_recurseProcTree(this, PROCDIR, NULL, period, tv);
|
LinuxProcessList_recurseProcTree(this, PROCDIR, NULL, period, tv);
|
||||||
|
@ -10,8 +10,7 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef MAJOR_IN_MKDEV
|
#ifdef MAJOR_IN_MKDEV
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
#elif defined(MAJOR_IN_SYSMACROS)
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
@ -19,6 +18,7 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "zfs/ZfsArcStats.h"
|
||||||
|
|
||||||
extern long long btime;
|
extern long long btime;
|
||||||
|
|
||||||
@ -48,6 +48,8 @@ typedef struct CPUData_ {
|
|||||||
unsigned long long int softIrqPeriod;
|
unsigned long long int softIrqPeriod;
|
||||||
unsigned long long int stealPeriod;
|
unsigned long long int stealPeriod;
|
||||||
unsigned long long int guestPeriod;
|
unsigned long long int guestPeriod;
|
||||||
|
|
||||||
|
double frequency;
|
||||||
} CPUData;
|
} CPUData;
|
||||||
|
|
||||||
typedef struct TtyDriver_ {
|
typedef struct TtyDriver_ {
|
||||||
@ -62,17 +64,24 @@ typedef struct LinuxProcessList_ {
|
|||||||
|
|
||||||
CPUData* cpus;
|
CPUData* cpus;
|
||||||
TtyDriver* ttyDrivers;
|
TtyDriver* ttyDrivers;
|
||||||
|
bool haveSmapsRollup;
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
struct nl_sock *netlink_socket;
|
struct nl_sock *netlink_socket;
|
||||||
int netlink_family;
|
int netlink_family;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ZfsArcStats zfs;
|
||||||
} LinuxProcessList;
|
} LinuxProcessList;
|
||||||
|
|
||||||
#ifndef PROCDIR
|
#ifndef PROCDIR
|
||||||
#define PROCDIR "/proc"
|
#define PROCDIR "/proc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PROCCPUINFOFILE
|
||||||
|
#define PROCCPUINFOFILE PROCDIR "/cpuinfo"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PROCSTATFILE
|
#ifndef PROCSTATFILE
|
||||||
#define PROCSTATFILE PROCDIR "/stat"
|
#define PROCSTATFILE PROCDIR "/stat"
|
||||||
#endif
|
#endif
|
||||||
@ -81,6 +90,10 @@ typedef struct LinuxProcessList_ {
|
|||||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PROCARCSTATSFILE
|
||||||
|
#define PROCARCSTATSFILE PROCDIR "/spl/kstat/zfs/arcstats"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PROCTTYDRIVERSFILE
|
#ifndef PROCTTYDRIVERSFILE
|
||||||
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
|
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
|
||||||
#endif
|
#endif
|
||||||
@ -98,9 +111,9 @@ typedef struct LinuxProcessList_ {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
extern ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||||
|
|
||||||
void ProcessList_delete(ProcessList* pl);
|
extern void ProcessList_delete(ProcessList* pl);
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
@ -123,54 +136,6 @@ void ProcessList_delete(ProcessList* pl);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_PERFCOUNTERS
|
extern void ProcessList_goThroughEntries(ProcessList* super);
|
||||||
|
|
||||||
#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);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/* 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
|
|
@ -19,10 +19,12 @@ in the source distribution for its full text.
|
|||||||
#include "TasksMeter.h"
|
#include "TasksMeter.h"
|
||||||
#include "LoadAverageMeter.h"
|
#include "LoadAverageMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
|
#include "PressureStallMeter.h"
|
||||||
#include "ClockMeter.h"
|
#include "ClockMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
|
#include "zfs/ZfsArcMeter.h"
|
||||||
|
#include "zfs/ZfsCompressedArcMeter.h"
|
||||||
#include "LinuxProcess.h"
|
#include "LinuxProcess.h"
|
||||||
#include "CRT.h"
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -36,13 +38,16 @@ 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[] = {
|
||||||
@ -82,31 +87,6 @@ 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) {
|
||||||
@ -116,7 +96,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
|||||||
if (!p) return HTOP_OK;
|
if (!p) return HTOP_OK;
|
||||||
IOPriority ioprio = p->ioPriority;
|
IOPriority ioprio = p->ioPriority;
|
||||||
Panel* ioprioPanel = IOPriorityPanel_new(ioprio);
|
Panel* ioprioPanel = IOPriorityPanel_new(ioprio);
|
||||||
void* set = Action_pickFromVector(st, ioprioPanel, 21);
|
void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
|
||||||
if (set) {
|
if (set) {
|
||||||
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL);
|
||||||
@ -144,11 +124,21 @@ MeterClass* Platform_meterTypes[] = {
|
|||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
|
&AllCPUs4Meter_class,
|
||||||
&LeftCPUsMeter_class,
|
&LeftCPUsMeter_class,
|
||||||
&RightCPUsMeter_class,
|
&RightCPUsMeter_class,
|
||||||
&LeftCPUs2Meter_class,
|
&LeftCPUs2Meter_class,
|
||||||
&RightCPUs2Meter_class,
|
&RightCPUs2Meter_class,
|
||||||
|
&LeftCPUs4Meter_class,
|
||||||
|
&RightCPUs4Meter_class,
|
||||||
&BlankMeter_class,
|
&BlankMeter_class,
|
||||||
|
&PressureStallCPUSomeMeter_class,
|
||||||
|
&PressureStallIOSomeMeter_class,
|
||||||
|
&PressureStallIOFullMeter_class,
|
||||||
|
&PressureStallMemorySomeMeter_class,
|
||||||
|
&PressureStallMemoryFullMeter_class,
|
||||||
|
&ZfsArcMeter_class,
|
||||||
|
&ZfsCompressedArcMeter_class,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -215,6 +205,9 @@ double Platform_setCPUValues(Meter* this, int cpu) {
|
|||||||
}
|
}
|
||||||
percent = CLAMP(percent, 0.0, 100.0);
|
percent = CLAMP(percent, 0.0, 100.0);
|
||||||
if (isnan(percent)) percent = 0.0;
|
if (isnan(percent)) percent = 0.0;
|
||||||
|
|
||||||
|
v[CPU_METER_FREQUENCY] = cpuData->frequency;
|
||||||
|
|
||||||
return percent;
|
return percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,6 +229,17 @@ void Platform_setSwapValues(Meter* this) {
|
|||||||
this->values[0] = pl->usedSwap;
|
this->values[0] = pl->usedSwap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsArcValues(Meter* this) {
|
||||||
|
LinuxProcessList* lpl = (LinuxProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsArcMeter_readStats(this, &(lpl->zfs));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform_setZfsCompressedArcValues(Meter* this) {
|
||||||
|
LinuxProcessList* lpl = (LinuxProcessList*) this->pl;
|
||||||
|
|
||||||
|
ZfsCompressedArcMeter_readStats(this, &(lpl->zfs));
|
||||||
|
}
|
||||||
char* Platform_getProcessEnv(pid_t pid) {
|
char* Platform_getProcessEnv(pid_t pid) {
|
||||||
char procname[32+1];
|
char procname[32+1];
|
||||||
xSnprintf(procname, 32, "/proc/%d/environ", pid);
|
xSnprintf(procname, 32, "/proc/%d/environ", pid);
|
||||||
@ -260,3 +264,21 @@ char* Platform_getProcessEnv(pid_t pid) {
|
|||||||
}
|
}
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) {
|
||||||
|
*ten = *sixty = *threehundred = 0;
|
||||||
|
char procname[128+1];
|
||||||
|
xSnprintf(procname, 128, PROCDIR "/pressure/%s", file);
|
||||||
|
FILE *fd = fopen(procname, "r");
|
||||||
|
if (!fd) {
|
||||||
|
*ten = *sixty = *threehundred = NAN;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int total = fscanf(fd, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
|
||||||
|
if (!some) {
|
||||||
|
total = fscanf(fd, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred);
|
||||||
|
}
|
||||||
|
(void) total;
|
||||||
|
assert(total == 3);
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
@ -14,38 +14,40 @@ 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);
|
extern void Platform_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
extern MeterClass* Platform_meterTypes[];
|
extern MeterClass* Platform_meterTypes[];
|
||||||
|
|
||||||
int Platform_getUptime();
|
extern int Platform_getUptime();
|
||||||
|
|
||||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
extern void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||||
|
|
||||||
int Platform_getMaxPid();
|
extern int Platform_getMaxPid();
|
||||||
|
|
||||||
double Platform_setCPUValues(Meter* this, int cpu);
|
extern double Platform_setCPUValues(Meter* this, int cpu);
|
||||||
|
|
||||||
void Platform_setMemoryValues(Meter* this);
|
extern void Platform_setMemoryValues(Meter* this);
|
||||||
|
|
||||||
void Platform_setSwapValues(Meter* this);
|
extern void Platform_setSwapValues(Meter* this);
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid);
|
extern void Platform_setZfsArcValues(Meter* this);
|
||||||
|
|
||||||
|
extern void Platform_setZfsCompressedArcValues(Meter* this);
|
||||||
|
extern char* Platform_getProcessEnv(pid_t pid);
|
||||||
|
|
||||||
|
extern void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
133
linux/PressureStallMeter.c
Normal file
133
linux/PressureStallMeter.c
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
htop - PressureStallMeter.c
|
||||||
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
(C) 2019 Ran Benita
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PressureStallMeter.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
#include "CRT.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*{
|
||||||
|
#include "Meter.h"
|
||||||
|
}*/
|
||||||
|
|
||||||
|
static int PressureStallMeter_attributes[] = {
|
||||||
|
PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED
|
||||||
|
};
|
||||||
|
|
||||||
|
static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||||
|
const char *file;
|
||||||
|
if (strstr(Meter_name(this), "CPU")) {
|
||||||
|
file = "cpu";
|
||||||
|
} else if (strstr(Meter_name(this), "IO")) {
|
||||||
|
file = "io";
|
||||||
|
} else {
|
||||||
|
file = "memory";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool some;
|
||||||
|
if (strstr(Meter_name(this), "Some")) {
|
||||||
|
some = true;
|
||||||
|
} else {
|
||||||
|
some = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
|
||||||
|
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PressureStallMeter_display(Object* cast, RichString* out) {
|
||||||
|
Meter* this = (Meter*)cast;
|
||||||
|
char buffer[20];
|
||||||
|
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
|
||||||
|
RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
|
||||||
|
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[1]);
|
||||||
|
RichString_append(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer);
|
||||||
|
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[2]);
|
||||||
|
RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
MeterClass PressureStallCPUSomeMeter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = PressureStallMeter_display,
|
||||||
|
},
|
||||||
|
.updateValues = PressureStallMeter_updateValues,
|
||||||
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 3,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = PressureStallMeter_attributes,
|
||||||
|
.name = "PressureStallCPUSome",
|
||||||
|
.uiName = "Pressure Stall Information, some CPU",
|
||||||
|
.caption = "Some CPU pressure: "
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass PressureStallIOSomeMeter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = PressureStallMeter_display,
|
||||||
|
},
|
||||||
|
.updateValues = PressureStallMeter_updateValues,
|
||||||
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 3,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = PressureStallMeter_attributes,
|
||||||
|
.name = "PressureStallIOSome",
|
||||||
|
.uiName = "Pressure Stall Information, some IO",
|
||||||
|
.caption = "Some IO pressure: "
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass PressureStallIOFullMeter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = PressureStallMeter_display,
|
||||||
|
},
|
||||||
|
.updateValues = PressureStallMeter_updateValues,
|
||||||
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 3,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = PressureStallMeter_attributes,
|
||||||
|
.name = "PressureStallIOFull",
|
||||||
|
.uiName = "Pressure Stall Information, full IO",
|
||||||
|
.caption = "Full IO pressure: "
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass PressureStallMemorySomeMeter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = PressureStallMeter_display,
|
||||||
|
},
|
||||||
|
.updateValues = PressureStallMeter_updateValues,
|
||||||
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 3,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = PressureStallMeter_attributes,
|
||||||
|
.name = "PressureStallMemorySome",
|
||||||
|
.uiName = "Pressure Stall Information, some memory",
|
||||||
|
.caption = "Some Mem pressure: "
|
||||||
|
};
|
||||||
|
|
||||||
|
MeterClass PressureStallMemoryFullMeter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete,
|
||||||
|
.display = PressureStallMeter_display,
|
||||||
|
},
|
||||||
|
.updateValues = PressureStallMeter_updateValues,
|
||||||
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 3,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = PressureStallMeter_attributes,
|
||||||
|
.name = "PressureStallMemoryFull",
|
||||||
|
.uiName = "Pressure Stall Information, full memory",
|
||||||
|
.caption = "Full Mem pressure: "
|
||||||
|
};
|
25
linux/PressureStallMeter.h
Normal file
25
linux/PressureStallMeter.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* Do not edit this file. It was automatically generated. */
|
||||||
|
|
||||||
|
#ifndef HEADER_PressureStallMeter
|
||||||
|
#define HEADER_PressureStallMeter
|
||||||
|
/*
|
||||||
|
htop - PressureStallMeter.h
|
||||||
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
|
(C) 2019 Ran Benita
|
||||||
|
Released under the GNU GPL, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Meter.h"
|
||||||
|
|
||||||
|
extern MeterClass PressureStallCPUSomeMeter_class;
|
||||||
|
|
||||||
|
extern MeterClass PressureStallIOSomeMeter_class;
|
||||||
|
|
||||||
|
extern MeterClass PressureStallIOFullMeter_class;
|
||||||
|
|
||||||
|
extern MeterClass PressureStallMemorySomeMeter_class;
|
||||||
|
|
||||||
|
extern MeterClass PressureStallMemoryFullMeter_class;
|
||||||
|
|
||||||
|
#endif
|
@ -10,6 +10,7 @@ in the source distribution for its full text.
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/sensors.h>
|
#include <sys/sensors.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
|
static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
|
||||||
for (int devn = 0;; devn++) {
|
for (int devn = 0;; devn++) {
|
||||||
|
@ -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->ss->direction == 1) {
|
if (settings->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->ss->sortKey) {
|
switch (settings->sortKey) {
|
||||||
// add OpenBSD-specific fields here
|
// add OpenBSD-specific fields here
|
||||||
default:
|
default:
|
||||||
return Process_compare(v1, v2);
|
return Process_compare(v1, v2);
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user