mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 21:44:36 +03:00
Compare commits
293 Commits
Author | SHA1 | Date | |
---|---|---|---|
4e6ec4a087 | |||
abaec509e6 | |||
f156dfecd5 | |||
2999fff88e | |||
2613db4b0d | |||
9eed30949b | |||
ce50095323 | |||
17e28d5264 | |||
da97d2625a | |||
7694dbc821 | |||
c0a9e92eea | |||
491c6f1044 | |||
98cbdc6dca | |||
9ed9d73ab5 | |||
999801464a | |||
0e29174211 | |||
efe09a5e39 | |||
038f2ae777 | |||
0af08bcfc9 | |||
e053446cbd | |||
3d8fa0b926 | |||
d73cc70566 | |||
37e01cbe33 | |||
d22667725a | |||
ef4cbae5ea | |||
44091705db | |||
87793b8555 | |||
fe7f238e2c | |||
c24681a078 | |||
2da8f71209 | |||
51228b6239 | |||
33973f7e40 | |||
79db69c48d | |||
9fc72c1e9c | |||
db93268968 | |||
4f1269cc9f | |||
0388b30077 | |||
4b8b61fe18 | |||
fae7ff6f03 | |||
e07fce7014 | |||
e08eec813c | |||
549fcb6bb8 | |||
08166b27b1 | |||
0d53245cf9 | |||
c7413fd677 | |||
8f0475cd73 | |||
a155fd0f8b | |||
549543f8e4 | |||
10b541b5e4 | |||
73f08debe0 | |||
8b98d3effb | |||
7e66ee1d28 | |||
a7a6571d14 | |||
cde72dd0b0 | |||
cb61865bb9 | |||
c144bf9ae5 | |||
ae518e20b7 | |||
cdf3f3c50b | |||
1f2f4fe891 | |||
ec809b7f71 | |||
b83ce85d89 | |||
ee1bf2f917 | |||
afc4a9d657 | |||
3f3691886a | |||
99aa906bc5 | |||
df955c8991 | |||
6a7b3fdc7d | |||
72c56691ec | |||
4ccad46045 | |||
7039abe109 | |||
2b7504b522 | |||
8b927ba596 | |||
0ffd772d28 | |||
64fb7181ee | |||
ba4c67942c | |||
3f0c172a60 | |||
7c43e02591 | |||
c6f946edd2 | |||
a2ca7583a9 | |||
469ae7a0bd | |||
c4239335b9 | |||
23b56193d7 | |||
edf319e53d | |||
b6c0667eae | |||
3ba695293c | |||
6133cac721 | |||
da653f8148 | |||
d35db47c9a | |||
978a7c894f | |||
79a6f6cb5b | |||
deb05fe7c2 | |||
82d34deaf1 | |||
fa3e0d06c2 | |||
82dce5cf8e | |||
8d987864e4 | |||
58b42e4cac | |||
2477a5a018 | |||
1a403eb7eb | |||
a3a7958721 | |||
4aeb146ce8 | |||
8c99683b04 | |||
265a7b8a50 | |||
939685dff9 | |||
3e1a27a981 | |||
9512fd7930 | |||
4a664c0df8 | |||
d0d9f202c5 | |||
a0ad0697a8 | |||
a133ffd829 | |||
fde1243443 | |||
6eab39c0ab | |||
2c3a64ac9c | |||
442c1596f6 | |||
f782f821f7 | |||
5b78ad2d53 | |||
1ef8c0e12f | |||
6fcb1994c8 | |||
5bc988ad6d | |||
6e9a5e9e49 | |||
14f428a172 | |||
6388033e10 | |||
b45eaf2fe1 | |||
230dc9c3c1 | |||
d084a80023 | |||
5c8670717a | |||
bc08c7dc2a | |||
1e94b92226 | |||
63fafb4844 | |||
c85e5bbf5c | |||
c9e0bd2002 | |||
df1914f429 | |||
3cfdf66d9a | |||
fa9f260f63 | |||
1da78b5818 | |||
2ae1906479 | |||
0e58784224 | |||
4ef5e4296e | |||
ba3a1df806 | |||
b672e60886 | |||
cd6457ef88 | |||
31fe29c5a7 | |||
cc2547fcf0 | |||
72ba20fa5f | |||
ff4f44b22a | |||
a38f48481e | |||
61c9fe44a3 | |||
ff0ea41c86 | |||
43e9be5a8f | |||
d73783d6db | |||
89b7c4c9f9 | |||
78aefc2a99 | |||
697c502b7e | |||
171aa0faaa | |||
ddfacb8694 | |||
5beef3e737 | |||
27a18830d5 | |||
b98a4f8d56 | |||
55e073a455 | |||
915b558bbe | |||
550100327b | |||
9dc964bb42 | |||
ea4282784d | |||
1c3c149d20 | |||
42c0493021 | |||
1284ab4835 | |||
07496eafb0 | |||
e7a8d14cbd | |||
21cb1c4d59 | |||
e64269df2c | |||
d8dfbbd37c | |||
afa3fe4af1 | |||
2ef70ad7f6 | |||
2977414d54 | |||
696f79fe50 | |||
4374a267be | |||
3e70de64b3 | |||
3f9f52fd29 | |||
dfa62506b7 | |||
731b4003a2 | |||
30c5004cbb | |||
9d3a1d4981 | |||
60cfa2edce | |||
604744f68d | |||
13fe58f54a | |||
e785693ef9 | |||
4cf74de1f1 | |||
0a5890d332 | |||
2128edfba2 | |||
d1c833fe95 | |||
868b0b3574 | |||
04871a2d04 | |||
b7248f6cb8 | |||
74afca7bc1 | |||
2a13e15ad0 | |||
8ac8542b6e | |||
f75a8bc3a1 | |||
d520199e62 | |||
9d8d87e1d5 | |||
57c1538887 | |||
9eb52d5932 | |||
970885edc3 | |||
ae1816e563 | |||
53732ab0bb | |||
8932efece9 | |||
d23627fda9 | |||
4c846921a6 | |||
c5e789db1b | |||
eb94c4f9c9 | |||
8361c6c1ae | |||
07f934ccfb | |||
6f751d5929 | |||
e26a2cf431 | |||
d527bc9132 | |||
dadcb87ad0 | |||
754c0d6bb9 | |||
9f4a4faab9 | |||
a710deeaa7 | |||
466d6f99e2 | |||
1601931bbf | |||
41f9c0ab77 | |||
e28d022716 | |||
d5ac75a5c7 | |||
2ba7d5ff36 | |||
3d99c306b9 | |||
3d3474b3fc | |||
94ad111391 | |||
976fa3b121 | |||
61227793de | |||
e6ded48d1a | |||
87c992739b | |||
29e1fcfa05 | |||
29983ff83a | |||
36b7f57200 | |||
c5fe142256 | |||
691b7dd5af | |||
ad0f9c58bf | |||
a8d0f2a7fe | |||
e6596cbd69 | |||
40c9f89971 | |||
09ad8067f4 | |||
bda3ee2b81 | |||
bdb015ffa3 | |||
80a515abcc | |||
5000cefc13 | |||
bf7d98e7ac | |||
c096712b8d | |||
be82448bd5 | |||
68c00b9cdb | |||
3c8d586a1c | |||
3869c43393 | |||
fcca4c2f2d | |||
dd88510dcd | |||
43ffdb0eda | |||
bf395e10c5 | |||
8f259bc5e1 | |||
38e6136b82 | |||
589b0733d9 | |||
c9b58c7fbe | |||
ca06e68037 | |||
a516e0852e | |||
3f805cf347 | |||
556d7c03e8 | |||
0925c54caa | |||
d0f5b61aa5 | |||
284f8c5e0b | |||
11b65a2861 | |||
b85b718e69 | |||
7891cdc552 | |||
b9fdf1c2a1 | |||
2844429f15 | |||
3834f2a68f | |||
343c2e58be | |||
fd2c4f5ddd | |||
7f95ed8528 | |||
9579d9b7aa | |||
0580dbb202 | |||
c0c2bb98a2 | |||
9b30870eec | |||
25c945e2ef | |||
f94934472f | |||
becd33795c | |||
74f99e3693 | |||
e1f4645bd1 | |||
0afd0fe572 | |||
ff336b652c | |||
58a59c11f4 | |||
3f806368e0 | |||
4855d92469 | |||
b81bb9038c | |||
1f2f567ca1 | |||
393330239e | |||
d2c34259b4 | |||
858ad8029d |
51
.github/workflows/build_release.yml
vendored
Normal file
51
.github/workflows/build_release.yml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
name: Build Source Release
|
||||
|
||||
# Trigger whenever a release is created
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- created
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: archive
|
||||
id: archive
|
||||
run: |
|
||||
VERSION=${{ github.event.release.tag_name }}
|
||||
PKGNAME="htop-$VERSION"
|
||||
SHASUM=$PKGNAME.tar.xz.sha256
|
||||
autoreconf -i
|
||||
mkdir -p /tmp/$PKGNAME
|
||||
mv * /tmp/$PKGNAME
|
||||
mv /tmp/$PKGNAME .
|
||||
TARBALL=$PKGNAME.tar.xz
|
||||
tar cJf $TARBALL $PKGNAME
|
||||
sha256sum $TARBALL > $SHASUM
|
||||
echo "::set-output name=tarball::$TARBALL"
|
||||
echo "::set-output name=shasum::$SHASUM"
|
||||
- name: upload tarball
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./${{ steps.archive.outputs.tarball }}
|
||||
asset_name: ${{ steps.archive.outputs.tarball }}
|
||||
asset_content_type: application/gzip
|
||||
|
||||
- name: upload shasum
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./${{ steps.archive.outputs.shasum }}
|
||||
asset_name: ${{ steps.archive.outputs.shasum }}
|
||||
asset_content_type: text/plain
|
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -113,6 +113,10 @@ jobs:
|
||||
build-ubuntu-latest-pcp:
|
||||
# Turns out 'ubuntu-latest' can be older than 20.04, we want PCP v5+
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
# Until Ubuntu catches up with pcp-5.2.3+:
|
||||
# pcp/Platform.c:309:45: warning: passing argument 2 of ‘pmLookupName’ from incompatible pointer type [-Wincompatible-pointer-types]
|
||||
CFLAGS: -Wno-error=incompatible-pointer-types
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install Dependencies
|
||||
@ -120,9 +124,7 @@ jobs:
|
||||
- name: Bootstrap
|
||||
run: ./autogen.sh
|
||||
- name: Configure
|
||||
# Until Ubuntu catches up with pcp-5.2.3+, cannot use -werror due to:
|
||||
# passing argument 2 of ‘pmLookupName’ from incompatible pointer type
|
||||
run: ./configure --enable-pcp --enable-unicode
|
||||
run: ./configure --enable-werror --enable-pcp --enable-unicode
|
||||
- name: Build
|
||||
run: make -k
|
||||
|
||||
|
@ -9,7 +9,8 @@ os:
|
||||
|
||||
script:
|
||||
- ./autogen.sh
|
||||
# clang might warn about C11 generic selections in isnan()
|
||||
- CFLAGS=-Wno-c11-extensions ./configure --enable-werror
|
||||
- ./configure --enable-werror
|
||||
- make -k
|
||||
- CFLAGS=-Wno-c11-extensions make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror
|
||||
- make distcheck DISTCHECK_CONFIGURE_FLAGS=--enable-werror
|
||||
- sudo make install
|
||||
- make installcheck
|
||||
|
170
Action.c
170
Action.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Action.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -58,7 +58,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
|
||||
header->pl->following = pid;
|
||||
unfollow = true;
|
||||
}
|
||||
ScreenManager_run(scr, &panelFocus, &ch);
|
||||
ScreenManager_run(scr, &panelFocus, &ch, NULL);
|
||||
if (unfollow) {
|
||||
header->pl->following = -1;
|
||||
}
|
||||
@ -85,9 +85,10 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
|
||||
static void Action_runSetup(State* st) {
|
||||
ScreenManager* scr = ScreenManager_new(st->header, st->settings, st, true);
|
||||
CategoriesPanel_new(scr, st->settings, st->header, st->pl);
|
||||
ScreenManager_run(scr, NULL, NULL);
|
||||
ScreenManager_run(scr, NULL, NULL, "Setup");
|
||||
ScreenManager_delete(scr);
|
||||
if (st->settings->changed) {
|
||||
CRT_setMouse(st->settings->enableMouse);
|
||||
Header_writeBackToSettings(st->header);
|
||||
}
|
||||
}
|
||||
@ -154,7 +155,7 @@ static bool collapseIntoParent(Panel* panel) {
|
||||
}
|
||||
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||
Settings_setSortKey(settings, sortKey);
|
||||
ScreenSettings_setSortKey(settings->ss, sortKey);
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
@ -164,8 +165,9 @@ static Htop_Reaction actionSetSortColumn(State* st) {
|
||||
Htop_Reaction reaction = HTOP_OK;
|
||||
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
|
||||
Panel_setHeader(sortPanel, "Sort by");
|
||||
const ProcessField* fields = st->settings->fields;
|
||||
Hashtable* dynamicColumns = st->settings->dynamicColumns;
|
||||
const Settings* settings = st->settings;
|
||||
const ProcessField* fields = settings->ss->fields;
|
||||
Hashtable* dynamicColumns = settings->dynamicColumns;
|
||||
for (int i = 0; fields[i]; i++) {
|
||||
char* name = NULL;
|
||||
if (fields[i] >= LAST_PROCESSFIELD) {
|
||||
@ -177,7 +179,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
|
||||
name = String_trim(Process_fields[fields[i]].name);
|
||||
}
|
||||
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
||||
if (fields[i] == Settings_getActiveSortKey(st->settings))
|
||||
if (fields[i] == ScreenSettings_getActiveSortKey(settings->ss))
|
||||
Panel_setSelected(sortPanel, i);
|
||||
|
||||
free(name);
|
||||
@ -188,8 +190,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
|
||||
}
|
||||
Object_delete(sortPanel);
|
||||
|
||||
if (st->pauseProcessUpdate)
|
||||
ProcessList_sort(st->pl);
|
||||
st->pl->needsSort = true;
|
||||
|
||||
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
@ -231,16 +232,21 @@ static Htop_Reaction actionToggleMergedCommand(State* st) {
|
||||
}
|
||||
|
||||
static Htop_Reaction actionToggleTreeView(State* st) {
|
||||
st->settings->treeView = !st->settings->treeView;
|
||||
ScreenSettings* ss = st->settings->ss;
|
||||
ss->treeView = !ss->treeView;
|
||||
|
||||
if (!st->settings->allBranchesCollapsed)
|
||||
if (!ss->allBranchesCollapsed)
|
||||
ProcessList_expandTree(st->pl);
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionExpandOrCollapseAllBranches(State* st) {
|
||||
st->settings->allBranchesCollapsed = !st->settings->allBranchesCollapsed;
|
||||
if (st->settings->allBranchesCollapsed)
|
||||
ScreenSettings* ss = st->settings->ss;
|
||||
if (!ss->treeView) {
|
||||
return HTOP_OK;
|
||||
}
|
||||
ss->allBranchesCollapsed = !ss->allBranchesCollapsed;
|
||||
if (ss->allBranchesCollapsed)
|
||||
ProcessList_collapseAllBranches(st->pl);
|
||||
else
|
||||
ProcessList_expandTree(st->pl);
|
||||
@ -277,9 +283,8 @@ static Htop_Reaction actionLowerPriority(State* st) {
|
||||
}
|
||||
|
||||
static Htop_Reaction actionInvertSortOrder(State* st) {
|
||||
Settings_invertSortOrder(st->settings);
|
||||
if (st->pauseProcessUpdate)
|
||||
ProcessList_sort(st->pl);
|
||||
ScreenSettings_invertSortOrder(st->settings->ss);
|
||||
st->pl->needsSort = true;
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
@ -289,7 +294,7 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
|
||||
}
|
||||
|
||||
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
||||
if (!st->settings->treeView) {
|
||||
if (!st->settings->ss->treeView) {
|
||||
return HTOP_OK;
|
||||
}
|
||||
bool changed = collapseIntoParent((Panel*)st->mainPanel);
|
||||
@ -297,7 +302,46 @@ static Htop_Reaction actionCollapseIntoParent(State* st) {
|
||||
}
|
||||
|
||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||
return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||
return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||
}
|
||||
|
||||
static Htop_Reaction 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 actionQuit(ATTR_UNUSED State* st) {
|
||||
@ -344,9 +388,12 @@ static Htop_Reaction actionKill(State* st) {
|
||||
if (Settings_isReadonly())
|
||||
return HTOP_OK;
|
||||
|
||||
Panel* signalsPanel = SignalsPanel_new();
|
||||
static int preSelectedSignal = SIGNALSPANEL_INITSELECTEDSIGNAL;
|
||||
|
||||
Panel* signalsPanel = SignalsPanel_new(preSelectedSignal);
|
||||
const ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 14, true);
|
||||
if (sgn && sgn->key != 0) {
|
||||
preSelectedSignal = sgn->key;
|
||||
Panel_setHeader((Panel*)st->mainPanel, "Sending...");
|
||||
Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
|
||||
refresh();
|
||||
@ -459,6 +506,7 @@ static const struct {
|
||||
bool roInactive;
|
||||
const char* info;
|
||||
} helpLeft[] = {
|
||||
{ .key = " Tab: ", .roInactive = false, .info = "switch to next screen tab" },
|
||||
{ .key = " Arrows: ", .roInactive = false, .info = "scroll process list" },
|
||||
{ .key = " Digits: ", .roInactive = false, .info = "incremental PID search" },
|
||||
{ .key = " F3 /: ", .roInactive = false, .info = "incremental name search" },
|
||||
@ -483,12 +531,13 @@ static const struct {
|
||||
bool roInactive;
|
||||
const char* info;
|
||||
} helpRight[] = {
|
||||
{ .key = " S-Tab: ", .roInactive = false, .info = "switch to previous screen tab" },
|
||||
{ .key = " Space: ", .roInactive = false, .info = "tag process" },
|
||||
{ .key = " c: ", .roInactive = false, .info = "tag process and its children" },
|
||||
{ .key = " U: ", .roInactive = false, .info = "untag all processes" },
|
||||
{ .key = " F9 k: ", .roInactive = true, .info = "kill process/tagged processes" },
|
||||
{ .key = " F7 ]: ", .roInactive = true, .info = "higher priority (root only)" },
|
||||
{ .key = " F8 [: ", .roInactive = false, .info = "lower priority (+ nice)" },
|
||||
{ .key = " F8 [: ", .roInactive = true, .info = "lower priority (+ nice)" },
|
||||
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY))
|
||||
{ .key = " a: ", .roInactive = true, .info = "set CPU affinity" },
|
||||
#endif
|
||||
@ -519,52 +568,63 @@ static Htop_Reaction actionHelp(State* st) {
|
||||
int line = 0;
|
||||
|
||||
mvaddstr(line++, 0, "htop " VERSION " - " COPYRIGHT);
|
||||
mvaddstr(line++, 0, "Released under the GNU GPLv2. See 'man' page for more info.");
|
||||
mvaddstr(line++, 0, "Released under the GNU GPLv2+. See 'man' page for more info.");
|
||||
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
line++;
|
||||
mvaddstr(line++, 0, "CPU usage bar: ");
|
||||
|
||||
#define addbartext(attr, prefix, text) \
|
||||
do { \
|
||||
addattrstr(CRT_colors[DEFAULT_COLOR], prefix); \
|
||||
addattrstr(attr, text); \
|
||||
} while(0)
|
||||
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
addbartext(CRT_colors[CPU_NICE_TEXT], "", "low");
|
||||
addbartext(CRT_colors[CPU_NORMAL], "/", "normal");
|
||||
addbartext(CRT_colors[CPU_SYSTEM], "/", "kernel");
|
||||
if (st->settings->detailedCPUTime) {
|
||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_GUEST], "guest"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_IOWAIT], "io-wait");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||
addbartext(CRT_colors[CPU_IRQ], "/", "irq");
|
||||
addbartext(CRT_colors[CPU_SOFTIRQ], "/", "soft-irq");
|
||||
addbartext(CRT_colors[CPU_STEAL], "/", "steal");
|
||||
addbartext(CRT_colors[CPU_GUEST], "/", "guest");
|
||||
addbartext(CRT_colors[CPU_IOWAIT], "/", "io-wait");
|
||||
addbartext(CRT_colors[BAR_SHADOW], " ", "used%");
|
||||
} else {
|
||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_SYSTEM], "kernel"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_GUEST], "virtualized");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||
addbartext(CRT_colors[CPU_GUEST], "/", "guest");
|
||||
addbartext(CRT_colors[BAR_SHADOW], " ", "used%");
|
||||
}
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(line++, 0, "Memory bar: ");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
addattrstr(CRT_colors[MEMORY_USED], "used"); addstr("/");
|
||||
addattrstr(CRT_colors[MEMORY_BUFFERS_TEXT], "buffers"); addstr("/");
|
||||
addattrstr(CRT_colors[MEMORY_SHARED], "shared"); addstr("/");
|
||||
addattrstr(CRT_colors[MEMORY_CACHE], "cache");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
addbartext(CRT_colors[MEMORY_USED], "", "used");
|
||||
addbartext(CRT_colors[MEMORY_BUFFERS_TEXT], "/", "buffers");
|
||||
addbartext(CRT_colors[MEMORY_SHARED], "/", "shared");
|
||||
addbartext(CRT_colors[MEMORY_CACHE], "/", "cache");
|
||||
addbartext(CRT_colors[BAR_SHADOW], " ", "used");
|
||||
addbartext(CRT_colors[BAR_SHADOW], "/", "total");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(line++, 0, "Swap bar: ");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
addattrstr(CRT_colors[SWAP], "used");
|
||||
addbartext(CRT_colors[SWAP], "", "used");
|
||||
#ifdef HTOP_LINUX
|
||||
addattrstr(CRT_colors[BAR_SHADOW], "/");
|
||||
addattrstr(CRT_colors[SWAP_CACHE], "cache");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
addbartext(CRT_colors[SWAP_CACHE], "/", "cache");
|
||||
#else
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
addbartext(CRT_colors[SWAP_CACHE], " ", "");
|
||||
#endif
|
||||
addbartext(CRT_colors[BAR_SHADOW], " ", "used");
|
||||
addbartext(CRT_colors[BAR_SHADOW], "/", "total");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
|
||||
line++;
|
||||
|
||||
#undef addbartext
|
||||
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(line++, 0, "Type and layout of header meters are configurable in the setup screen.");
|
||||
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
|
||||
@ -572,9 +632,23 @@ static Htop_Reaction actionHelp(State* st) {
|
||||
}
|
||||
line++;
|
||||
|
||||
mvaddstr(line++, 0, "Process state: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep");
|
||||
#define addattrstatestr(attr, state, desc) \
|
||||
do { \
|
||||
addattrstr(attr, state); \
|
||||
addattrstr(CRT_colors[DEFAULT_COLOR], ": " desc); \
|
||||
} while(0)
|
||||
|
||||
line++;
|
||||
mvaddstr(line, 0, "Process state: ");
|
||||
addattrstatestr(CRT_colors[PROCESS_RUN_STATE], "R", "running; ");
|
||||
addattrstatestr(CRT_colors[PROCESS_SHADOW], "S", "sleeping; ");
|
||||
addattrstatestr(CRT_colors[PROCESS_RUN_STATE], "t", "traced/stopped; ");
|
||||
addattrstatestr(CRT_colors[PROCESS_D_STATE], "Z", "zombie; ");
|
||||
addattrstatestr(CRT_colors[PROCESS_D_STATE], "D", "disk sleep");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
|
||||
#undef addattrstatestr
|
||||
|
||||
line += 2;
|
||||
|
||||
const bool readonly = Settings_isReadonly();
|
||||
|
||||
@ -711,4 +785,6 @@ void Action_setBindings(Htop_Action* keys) {
|
||||
keys[KEY_F(10)] = actionQuit;
|
||||
keys[KEY_F(18)] = actionExpandCollapseOrSortColumn;
|
||||
keys[KEY_RECLICK] = actionExpandOrCollapse;
|
||||
keys[KEY_SHIFT_TAB] = actionPrevScreen;
|
||||
keys['\t'] = actionNextScreen;
|
||||
}
|
||||
|
4
Action.h
4
Action.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Action.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -57,6 +57,8 @@ bool Action_setUserOnly(const char* userName, uid_t* userId);
|
||||
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||
|
||||
Htop_Reaction Action_setScreenTab(Settings* settings, int x);
|
||||
|
||||
Htop_Reaction Action_follow(State* st);
|
||||
|
||||
void Action_setBindings(Htop_Action* keys);
|
||||
|
@ -2,7 +2,7 @@
|
||||
htop - Affinity.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -63,9 +63,9 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
|
||||
Affinity_add(affinity, i);
|
||||
}
|
||||
} else {
|
||||
unsigned int id;
|
||||
hwloc_bitmap_foreach_begin(id, cpuset);
|
||||
Affinity_add(affinity, id);
|
||||
int id;
|
||||
hwloc_bitmap_foreach_begin(id, cpuset)
|
||||
Affinity_add(affinity, (unsigned)id);
|
||||
hwloc_bitmap_foreach_end();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
htop - Affinity.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - AffinityPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -425,9 +425,9 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
|
||||
Affinity* affinity = Affinity_new(pl);
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
unsigned int i;
|
||||
int i;
|
||||
hwloc_bitmap_foreach_begin(i, this->workCpuset)
|
||||
Affinity_add(affinity, i);
|
||||
Affinity_add(affinity, (unsigned)i);
|
||||
hwloc_bitmap_foreach_end();
|
||||
#else
|
||||
for (int i = 0; i < Vector_size(this->cpuids); i++) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - AffinityPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - AvailableColumnsPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - AvailableColumnsPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - AvailableMetersPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -79,6 +79,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
|
||||
}
|
||||
if (update) {
|
||||
this->settings->changed = true;
|
||||
this->settings->lastUpdate++;
|
||||
Header_calculateHeight(header);
|
||||
Header_updateData(header);
|
||||
Header_draw(header);
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - AvailableMetersPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - BatteryMeter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
|
||||
This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - BatteryMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
|
||||
This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
|
||||
|
17
CPUMeter.c
17
CPUMeter.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - CPUMeter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -52,9 +52,9 @@ static void CPUMeter_init(Meter* this) {
|
||||
// Custom uiName runtime logic to include the param (processor)
|
||||
static void CPUMeter_getUiName(const Meter* this, char* buffer, size_t length) {
|
||||
if (this->param > 0)
|
||||
xSnprintf(buffer, sizeof(length), "%s %u", Meter_uiName(this), this->param);
|
||||
xSnprintf(buffer, length, "%s %u", Meter_uiName(this), this->param);
|
||||
else
|
||||
xSnprintf(buffer, sizeof(length), "%s", Meter_uiName(this));
|
||||
xSnprintf(buffer, length, "%s", Meter_uiName(this));
|
||||
}
|
||||
|
||||
static void CPUMeter_updateValues(Meter* this) {
|
||||
@ -381,6 +381,7 @@ const MeterClass AllCPUs2Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs2",
|
||||
@ -401,6 +402,7 @@ const MeterClass LeftCPUsMeter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs",
|
||||
@ -421,6 +423,7 @@ const MeterClass RightCPUsMeter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "RightCPUs",
|
||||
@ -441,6 +444,7 @@ const MeterClass LeftCPUs2Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs2",
|
||||
@ -461,6 +465,7 @@ const MeterClass RightCPUs2Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "RightCPUs2",
|
||||
@ -481,6 +486,7 @@ const MeterClass AllCPUs4Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs4",
|
||||
@ -501,6 +507,7 @@ const MeterClass LeftCPUs4Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs4",
|
||||
@ -521,6 +528,7 @@ const MeterClass RightCPUs4Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "RightCPUs4",
|
||||
@ -541,6 +549,7 @@ const MeterClass AllCPUs8Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs8",
|
||||
@ -561,6 +570,7 @@ const MeterClass LeftCPUs8Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs8",
|
||||
@ -581,6 +591,7 @@ const MeterClass RightCPUs8Meter_class = {
|
||||
},
|
||||
.updateValues = AllCPUsMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "RightCPUs8",
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - CPUMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
176
CRT.c
176
CRT.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - CRT.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -13,6 +13,7 @@ in the source distribution for its full text.
|
||||
#include <fcntl.h>
|
||||
#include <langinfo.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -21,14 +22,22 @@ in the source distribution for its full text.
|
||||
#include "ProvideCurses.h"
|
||||
#include "XUtils.h"
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#if !defined(NDEBUG) && defined(HAVE_MEMFD_CREATE)
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LIBUNWIND)
|
||||
# define PRINT_BACKTRACE
|
||||
# define UNW_LOCAL_ONLY
|
||||
# include <libunwind.h>
|
||||
# if defined(HAVE_DLADDR)
|
||||
# include <dlfcn.h>
|
||||
# endif
|
||||
#elif defined(HAVE_EXECINFO_H)
|
||||
# define PRINT_BACKTRACE
|
||||
# include <execinfo.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define ColorIndex(i,j) ((7-(i))*8+(j))
|
||||
|
||||
@ -138,7 +147,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_GIGABYTES] = ColorPair(Green, Black),
|
||||
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Black),
|
||||
[PROCESS_TREE] = ColorPair(Cyan, Black),
|
||||
[PROCESS_R_STATE] = ColorPair(Green, Black),
|
||||
[PROCESS_RUN_STATE] = ColorPair(Green, Black),
|
||||
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black),
|
||||
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black),
|
||||
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Black),
|
||||
@ -185,6 +194,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[CPU_SOFTIRQ] = ColorPair(Magenta, Black),
|
||||
[CPU_STEAL] = ColorPair(Cyan, Black),
|
||||
[CPU_GUEST] = ColorPair(Cyan, Black),
|
||||
[PANEL_EDIT] = ColorPair(White, Blue),
|
||||
[SCREENS_OTH_BORDER] = ColorPair(Blue, Blue),
|
||||
[SCREENS_OTH_TEXT] = ColorPair(Black, Blue),
|
||||
[SCREENS_CUR_BORDER] = ColorPair(Green, Green),
|
||||
[SCREENS_CUR_TEXT] = ColorPair(Black, Green),
|
||||
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan, Black),
|
||||
[PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan, Black),
|
||||
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Black),
|
||||
@ -240,7 +254,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_GIGABYTES] = A_BOLD,
|
||||
[PROCESS_BASENAME] = A_BOLD,
|
||||
[PROCESS_TREE] = A_BOLD,
|
||||
[PROCESS_R_STATE] = A_BOLD,
|
||||
[PROCESS_RUN_STATE] = A_BOLD,
|
||||
[PROCESS_D_STATE] = A_BOLD,
|
||||
[PROCESS_HIGH_PRIORITY] = A_BOLD,
|
||||
[PROCESS_LOW_PRIORITY] = A_DIM,
|
||||
@ -287,6 +301,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[CPU_SOFTIRQ] = A_BOLD,
|
||||
[CPU_STEAL] = A_DIM,
|
||||
[CPU_GUEST] = A_DIM,
|
||||
[PANEL_EDIT] = A_BOLD,
|
||||
[SCREENS_OTH_BORDER] = A_DIM,
|
||||
[SCREENS_OTH_TEXT] = A_DIM,
|
||||
[SCREENS_CUR_BORDER] = A_REVERSE,
|
||||
[SCREENS_CUR_TEXT] = A_REVERSE,
|
||||
[PRESSURE_STALL_THREEHUNDRED] = A_DIM,
|
||||
[PRESSURE_STALL_SIXTY] = A_NORMAL,
|
||||
[PRESSURE_STALL_TEN] = A_BOLD,
|
||||
@ -342,7 +361,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_GIGABYTES] = ColorPair(Green, White),
|
||||
[PROCESS_BASENAME] = ColorPair(Blue, White),
|
||||
[PROCESS_TREE] = ColorPair(Green, White),
|
||||
[PROCESS_R_STATE] = ColorPair(Green, White),
|
||||
[PROCESS_RUN_STATE] = ColorPair(Green, White),
|
||||
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White),
|
||||
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, White),
|
||||
[PROCESS_LOW_PRIORITY] = ColorPair(Green, White),
|
||||
@ -389,6 +408,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[CPU_SOFTIRQ] = ColorPair(Blue, White),
|
||||
[CPU_STEAL] = ColorPair(Cyan, White),
|
||||
[CPU_GUEST] = ColorPair(Cyan, White),
|
||||
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Black,White),
|
||||
[SCREENS_OTH_TEXT] = A_BOLD | ColorPair(Black,White),
|
||||
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
||||
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, White),
|
||||
[PRESSURE_STALL_SIXTY] = ColorPair(Black, White),
|
||||
[PRESSURE_STALL_TEN] = ColorPair(Black, White),
|
||||
@ -444,7 +468,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_GIGABYTES] = ColorPair(Green, Black),
|
||||
[PROCESS_BASENAME] = ColorPair(Green, Black),
|
||||
[PROCESS_TREE] = ColorPair(Blue, Black),
|
||||
[PROCESS_R_STATE] = ColorPair(Green, Black),
|
||||
[PROCESS_RUN_STATE] = ColorPair(Green, Black),
|
||||
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black),
|
||||
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black),
|
||||
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Black),
|
||||
@ -491,6 +515,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[CPU_SOFTIRQ] = ColorPair(Blue, Black),
|
||||
[CPU_STEAL] = ColorPair(Black, Black),
|
||||
[CPU_GUEST] = ColorPair(Black, Black),
|
||||
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||
[SCREENS_OTH_BORDER] = ColorPair(Blue,Black),
|
||||
[SCREENS_OTH_TEXT] = ColorPair(Blue,Black),
|
||||
[SCREENS_CUR_BORDER] = ColorPair(Green,Green),
|
||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Green),
|
||||
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, Black),
|
||||
[PRESSURE_STALL_SIXTY] = ColorPair(Black, Black),
|
||||
[PRESSURE_STALL_TEN] = ColorPair(Black, Black),
|
||||
@ -546,7 +575,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_GIGABYTES] = ColorPair(Green, Blue),
|
||||
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Blue),
|
||||
[PROCESS_TREE] = ColorPair(Cyan, Blue),
|
||||
[PROCESS_R_STATE] = ColorPair(Green, Blue),
|
||||
[PROCESS_RUN_STATE] = ColorPair(Green, Blue),
|
||||
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue),
|
||||
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue),
|
||||
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue),
|
||||
@ -593,6 +622,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[CPU_SOFTIRQ] = ColorPair(Black, Blue),
|
||||
[CPU_STEAL] = ColorPair(White, Blue),
|
||||
[CPU_GUEST] = ColorPair(White, Blue),
|
||||
[PANEL_EDIT] = ColorPair(White,Blue),
|
||||
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Yellow,Blue),
|
||||
[SCREENS_OTH_TEXT] = ColorPair(Cyan,Blue),
|
||||
[SCREENS_CUR_BORDER] = ColorPair(Cyan,Cyan),
|
||||
[SCREENS_CUR_TEXT] = ColorPair(Black,Cyan),
|
||||
[PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black, Blue),
|
||||
[PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White, Blue),
|
||||
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Blue),
|
||||
@ -652,7 +686,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black),
|
||||
[PROCESS_COMM] = ColorPair(Magenta, Black),
|
||||
[PROCESS_THREAD_COMM] = ColorPair(Yellow, Black),
|
||||
[PROCESS_R_STATE] = ColorPair(Green, Black),
|
||||
[PROCESS_RUN_STATE] = ColorPair(Green, Black),
|
||||
[PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black),
|
||||
[PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black),
|
||||
[PROCESS_LOW_PRIORITY] = ColorPair(Green, Black),
|
||||
@ -693,6 +727,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[CPU_SOFTIRQ] = ColorPair(Blue, Black),
|
||||
[CPU_STEAL] = ColorPair(Cyan, Black),
|
||||
[CPU_GUEST] = ColorPair(Cyan, Black),
|
||||
[PANEL_EDIT] = ColorPair(White,Cyan),
|
||||
[SCREENS_OTH_BORDER] = ColorPair(White,Black),
|
||||
[SCREENS_OTH_TEXT] = ColorPair(Cyan,Black),
|
||||
[SCREENS_CUR_BORDER] = A_BOLD | ColorPair(White,Black),
|
||||
[SCREENS_CUR_TEXT] = A_BOLD | ColorPair(Green,Black),
|
||||
[PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green, Black),
|
||||
[PRESSURE_STALL_SIXTY] = ColorPair(Green, Black),
|
||||
[PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green, Black),
|
||||
@ -717,8 +756,6 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
|
||||
};
|
||||
|
||||
int CRT_cursorX = 0;
|
||||
|
||||
int CRT_scrollHAmount = 5;
|
||||
|
||||
int CRT_scrollWheelVAmount = 10;
|
||||
@ -772,6 +809,8 @@ static void dumpStderr(void) {
|
||||
|
||||
fsync(STDERR_FILENO);
|
||||
dup2(stderrRedirectBackupFd, STDERR_FILENO);
|
||||
close(stderrRedirectBackupFd);
|
||||
stderrRedirectBackupFd = -1;
|
||||
lseek(stderrRedirectNewFd, 0, SEEK_SET);
|
||||
|
||||
bool header = false;
|
||||
@ -806,6 +845,16 @@ static void dumpStderr(void) {
|
||||
stderrRedirectNewFd = -1;
|
||||
}
|
||||
|
||||
void CRT_debug_impl(const char* file, size_t lineno, const char* func, const char* fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
fprintf(stderr, "[%s:%zu (%s)]: ", file, lineno, func);
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#else /* !NDEBUG */
|
||||
|
||||
static void redirectStderr(void) {
|
||||
@ -831,6 +880,7 @@ static void CRT_installSignalHandlers(void) {
|
||||
sigaction (SIGSYS, &act, &old_sig_handler[SIGSYS]);
|
||||
sigaction (SIGABRT, &act, &old_sig_handler[SIGABRT]);
|
||||
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
signal(SIGINT, CRT_handleSIGTERM);
|
||||
signal(SIGTERM, CRT_handleSIGTERM);
|
||||
signal(SIGQUIT, CRT_handleSIGTERM);
|
||||
@ -850,6 +900,20 @@ void CRT_resetSignalHandlers(void) {
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
}
|
||||
|
||||
void CRT_setMouse(bool enabled) {
|
||||
#ifdef HAVE_GETMOUSE
|
||||
if (enabled) {
|
||||
#if NCURSES_MOUSE_VERSION > 1
|
||||
mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
|
||||
#else
|
||||
mousemask(BUTTON1_RELEASED, NULL);
|
||||
#endif
|
||||
} else {
|
||||
mousemask(0, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CRT_init(const Settings* settings, bool allowUnicode) {
|
||||
redirectStderr();
|
||||
|
||||
@ -886,6 +950,10 @@ void CRT_init(const Settings* settings, bool allowUnicode) {
|
||||
}
|
||||
|
||||
if (termType && (String_startsWith(termType, "xterm") || String_eq(termType, "vt220"))) {
|
||||
#ifdef HTOP_NETBSD
|
||||
#define define_key(s_, k_) define_key((char*)s_, k_)
|
||||
IGNORE_WCASTQUAL_BEGIN
|
||||
#endif
|
||||
define_key("\033[H", KEY_HOME);
|
||||
define_key("\033[F", KEY_END);
|
||||
define_key("\033[7~", KEY_HOME);
|
||||
@ -901,11 +969,19 @@ void CRT_init(const Settings* settings, bool allowUnicode) {
|
||||
define_key("\033[14~", KEY_F(4));
|
||||
define_key("\033[14;2~", KEY_F(15));
|
||||
define_key("\033[17;2~", KEY_F(18));
|
||||
define_key("\033[Z", KEY_SHIFT_TAB);
|
||||
char sequence[3] = "\033a";
|
||||
for (char c = 'a'; c <= 'z'; c++) {
|
||||
sequence[1] = c;
|
||||
define_key(sequence, KEY_ALT('A' + (c - 'a')));
|
||||
}
|
||||
#ifdef HTOP_NETBSD
|
||||
IGNORE_WCASTQUAL_END
|
||||
#undef define_key
|
||||
#endif
|
||||
}
|
||||
if (termType && (String_startsWith(termType, "rxvt"))) {
|
||||
define_key("\033[Z", KEY_SHIFT_TAB);
|
||||
}
|
||||
|
||||
CRT_installSignalHandlers();
|
||||
@ -931,18 +1007,17 @@ void CRT_init(const Settings* settings, bool allowUnicode) {
|
||||
#endif
|
||||
CRT_treeStrAscii;
|
||||
|
||||
#ifdef HAVE_GETMOUSE
|
||||
#if NCURSES_MOUSE_VERSION > 1
|
||||
mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
|
||||
#else
|
||||
mousemask(BUTTON1_RELEASED, NULL);
|
||||
#endif
|
||||
#endif
|
||||
CRT_setMouse(settings->enableMouse);
|
||||
|
||||
CRT_degreeSign = initDegreeSign();
|
||||
}
|
||||
|
||||
void CRT_done() {
|
||||
attron(CRT_colors[RESET_COLOR]);
|
||||
mvhline(LINES - 1, 0, ' ', COLS);
|
||||
attroff(CRT_colors[RESET_COLOR]);
|
||||
refresh();
|
||||
|
||||
curs_set(1);
|
||||
endwin();
|
||||
|
||||
@ -998,6 +1073,59 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colors = CRT_colorSchemes[colorScheme];
|
||||
}
|
||||
|
||||
#ifdef PRINT_BACKTRACE
|
||||
static void print_backtrace(void) {
|
||||
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LIBUNWIND)
|
||||
unw_context_t context;
|
||||
unw_getcontext(&context);
|
||||
|
||||
unw_cursor_t cursor;
|
||||
unw_init_local(&cursor, &context);
|
||||
|
||||
unsigned int item = 0;
|
||||
|
||||
while (unw_step(&cursor) > 0) {
|
||||
unw_word_t pc;
|
||||
unw_get_reg(&cursor, UNW_REG_IP, &pc);
|
||||
if (pc == 0)
|
||||
break;
|
||||
|
||||
char symbolName[256] = "?";
|
||||
unw_word_t offset = 0;
|
||||
unw_get_proc_name(&cursor, symbolName, sizeof(symbolName), &offset);
|
||||
|
||||
unw_proc_info_t pip;
|
||||
pip.unwind_info = NULL;
|
||||
|
||||
const char* fname = "?";
|
||||
const void* ptr = 0;
|
||||
if (unw_get_proc_info(&cursor, &pip) == 0) {
|
||||
ptr = (const void*)(pip.start_ip + offset);
|
||||
|
||||
#ifdef HAVE_DLADDR
|
||||
Dl_info dlinfo;
|
||||
if (dladdr(ptr, &dlinfo) && dlinfo.dli_fname && *dlinfo.dli_fname)
|
||||
fname = dlinfo.dli_fname;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* frame = "";
|
||||
if (unw_is_signal_frame(&cursor) > 0)
|
||||
frame = "{signal frame}";
|
||||
|
||||
fprintf(stderr, "%2u: %#14lx %s (%s+%#lx) [%p]%s%s\n", item++, pc, fname, symbolName, offset, ptr, frame ? " " : "", frame);
|
||||
}
|
||||
#elif defined(HAVE_EXECINFO_H)
|
||||
void* backtraceArray[256];
|
||||
|
||||
size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
|
||||
backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
|
||||
#else
|
||||
#error No implementation for print_backtrace()!
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int signal) {
|
||||
CRT_done();
|
||||
|
||||
@ -1012,7 +1140,7 @@ void CRT_handleSIGSEGV(int signal) {
|
||||
" - Likely steps to reproduce (How did it happen?)\n"
|
||||
);
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#ifdef PRINT_BACKTRACE
|
||||
fprintf(stderr, " - Backtrace of the issue (see below)\n");
|
||||
#endif
|
||||
|
||||
@ -1038,16 +1166,14 @@ void CRT_handleSIGSEGV(int signal) {
|
||||
Settings_write(CRT_crashSettings, true);
|
||||
fprintf(stderr, "\n\n");
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#ifdef PRINT_BACKTRACE
|
||||
fprintf(stderr,
|
||||
"Backtrace information:\n"
|
||||
"----------------------\n"
|
||||
);
|
||||
|
||||
void* backtraceArray[256];
|
||||
print_backtrace();
|
||||
|
||||
size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
|
||||
backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
|
||||
fprintf(stderr,
|
||||
"\n"
|
||||
"To make the above information more practical to work with, "
|
||||
|
25
CRT.h
25
CRT.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - CRT.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -74,7 +74,7 @@ typedef enum ColorElements_ {
|
||||
PROCESS_MEGABYTES,
|
||||
PROCESS_GIGABYTES,
|
||||
PROCESS_TREE,
|
||||
PROCESS_R_STATE,
|
||||
PROCESS_RUN_STATE,
|
||||
PROCESS_D_STATE,
|
||||
PROCESS_BASENAME,
|
||||
PROCESS_HIGH_PRIORITY,
|
||||
@ -120,6 +120,11 @@ typedef enum ColorElements_ {
|
||||
CPU_SOFTIRQ,
|
||||
CPU_STEAL,
|
||||
CPU_GUEST,
|
||||
PANEL_EDIT,
|
||||
SCREENS_OTH_BORDER,
|
||||
SCREENS_OTH_TEXT,
|
||||
SCREENS_CUR_BORDER,
|
||||
SCREENS_CUR_TEXT,
|
||||
PRESSURE_STALL_TEN,
|
||||
PRESSURE_STALL_SIXTY,
|
||||
PRESSURE_STALL_THREEHUNDRED,
|
||||
@ -145,11 +150,19 @@ typedef enum ColorElements_ {
|
||||
|
||||
void CRT_fatalError(const char* note) ATTR_NORETURN;
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define CRT_debug(...)
|
||||
#else
|
||||
void CRT_debug_impl(const char* file, size_t lineno, const char* func, const char* fmt, ...) ATTR_FORMAT(printf, 4, 5);
|
||||
# define CRT_debug(...) CRT_debug_impl(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int signal) ATTR_NORETURN;
|
||||
|
||||
#define KEY_WHEELUP KEY_F(20)
|
||||
#define KEY_WHEELDOWN KEY_F(21)
|
||||
#define KEY_RECLICK KEY_F(22)
|
||||
#define KEY_WHEELUP KEY_F(30)
|
||||
#define KEY_WHEELDOWN KEY_F(31)
|
||||
#define KEY_RECLICK KEY_F(32)
|
||||
#define KEY_SHIFT_TAB KEY_F(33)
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A'))
|
||||
|
||||
extern const char* CRT_degreeSign;
|
||||
@ -172,6 +185,8 @@ extern int CRT_scrollWheelVAmount;
|
||||
|
||||
extern ColorScheme CRT_colorScheme;
|
||||
|
||||
void CRT_setMouse(bool enabled);
|
||||
|
||||
void CRT_init(const Settings* settings, bool allowUnicode);
|
||||
|
||||
void CRT_done(void);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - CategoriesPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -14,7 +14,6 @@ in the source distribution for its full text.
|
||||
#include "AvailableColumnsPanel.h"
|
||||
#include "AvailableMetersPanel.h"
|
||||
#include "ColorsPanel.h"
|
||||
#include "ColumnsPanel.h"
|
||||
#include "DisplayOptionsPanel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "Header.h"
|
||||
@ -25,6 +24,7 @@ in the source distribution for its full text.
|
||||
#include "MetersPanel.h"
|
||||
#include "Object.h"
|
||||
#include "ProvideCurses.h"
|
||||
#include "ScreensPanel.h"
|
||||
#include "Vector.h"
|
||||
#include "XUtils.h"
|
||||
|
||||
@ -40,7 +40,7 @@ static void CategoriesPanel_delete(Object* object) {
|
||||
|
||||
static void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
|
||||
size_t columns = HeaderLayout_getColumns(this->scr->header->headerLayout);
|
||||
MetersPanel** meterPanels = xMallocArray(columns, sizeof(MetersPanel));
|
||||
MetersPanel** meterPanels = xMallocArray(columns, sizeof(MetersPanel*));
|
||||
|
||||
for (size_t i = 0; i < columns; i++) {
|
||||
char titleBuffer[32];
|
||||
@ -69,9 +69,11 @@ static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
||||
ScreenManager_add(this->scr, colors, -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
||||
Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
|
||||
static void CategoriesPanel_makeScreensPage(CategoriesPanel* this) {
|
||||
Panel* screens = (Panel*) ScreensPanel_new(this->settings);
|
||||
Panel* columns = (Panel*) ((ScreensPanel*)screens)->columns;
|
||||
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns, this->settings->dynamicColumns);
|
||||
ScreenManager_add(this->scr, screens, 20);
|
||||
ScreenManager_add(this->scr, columns, 20);
|
||||
ScreenManager_add(this->scr, availableColumns, -1);
|
||||
}
|
||||
@ -91,7 +93,7 @@ static const CategoriesPanelPage categoriesPanelPages[] = {
|
||||
{ .name = "Display options", .ctor = CategoriesPanel_makeDisplayOptionsPage },
|
||||
{ .name = "Header layout", .ctor = CategoriesPanel_makeHeaderOptionsPage },
|
||||
{ .name = "Meters", .ctor = CategoriesPanel_makeMetersPage },
|
||||
{ .name = "Columns", .ctor = CategoriesPanel_makeColumnsPage },
|
||||
{ .name = "Screens", .ctor = CategoriesPanel_makeScreensPage },
|
||||
{ .name = "Colors", .ctor = CategoriesPanel_makeColorsPage },
|
||||
};
|
||||
|
||||
@ -157,7 +159,7 @@ CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Hea
|
||||
this->settings = settings;
|
||||
this->header = header;
|
||||
this->pl = pl;
|
||||
Panel_setHeader(super, "Setup");
|
||||
Panel_setHeader(super, "Categories");
|
||||
for (size_t i = 0; i < ARRAYSIZE(categoriesPanelPages); i++)
|
||||
Panel_add(super, (Object*) ListItem_new(categoriesPanelPages[i].name, 0));
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - CategoriesPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
105
ChangeLog
105
ChangeLog
@ -1,5 +1,91 @@
|
||||
What's new in version 3.1.0
|
||||
What's new in version 3.2.1
|
||||
|
||||
* Fix setting to show all branches collapsed by default
|
||||
* Restore functionality of stripExeFromCmdline setting
|
||||
* Fix some command line display settings not being honored without restart
|
||||
* Display single digit precision for CPU% greater than 99.9%
|
||||
* On Linux, FreeBSD and PCP consider only shrinkable ZFS ARC as cache
|
||||
* On Linux, increase field width of CPUD% and SWAPD% columns
|
||||
* Colorize process state characters in help screen
|
||||
* Use mousemask(3X) to enable and disable mouse control
|
||||
* Fix heap buffer overflow in Vector_compact
|
||||
* On Solaris, fix a process time scaling error
|
||||
* On Solaris, fix the build
|
||||
* On NetBSD, OpenBSD and Solaris ensure env buffer size is sufficient
|
||||
* On Linux, resolve processes exiting interfering with sampling
|
||||
* Fix ProcessList quadratic removal when scanning processes
|
||||
* Under LXC, limit CPU count to that given by /proc/cpuinfo
|
||||
* Improve container detection for LXC
|
||||
* Some minor documentation fixes
|
||||
|
||||
What's new in version 3.2.0
|
||||
|
||||
* Support for displaying multiple tabs in the user interface
|
||||
* Allow multiple filter and search terms (logical OR, separate by "|")
|
||||
* Set correct default sorting direction (defaultSortDesc)
|
||||
* Improve performance for process lookup and update
|
||||
* Rework the IOMeters initial display
|
||||
* Removed duplicate sections on COMM and EXE
|
||||
* Highlight process UNINTERRUPTIBLE_WAIT state (D)
|
||||
* Show only integer value when CPU% more than 99.9%
|
||||
* Handle rounding ambiguity between 99.9 and 100.0%
|
||||
* No longer leaves empty the last column in header
|
||||
* Fix header layout and meters reset if a header column is empty
|
||||
* Fix PID and UID column widths off-by-one error
|
||||
* On Linux, read generic sysfs batteries
|
||||
* On Linux, do not collect LRS per thread (it is process-wide)
|
||||
* On Linux, dynamically adjust the SECATTR and CGROUP column widths
|
||||
* On Linux, fix a crash in LXD
|
||||
* On FreeBSD, add support for showing process emulation
|
||||
* On Darwin, lazily set process TTY name
|
||||
* Always set SIGCHLD to default handling
|
||||
* Avoid zombie processes on signal races
|
||||
* Ensure last line is cleared when SIGINT is received
|
||||
* Instead of SIGTERM, pre-select the last sent signal
|
||||
* Internal Hashtable performance and sizing improvements
|
||||
* Add heuristics for guessing LXC or Docker from /proc/1/mounts
|
||||
* Force elapsed time display to zero if process started in the future
|
||||
* Avoid extremely large year values when printing time
|
||||
* Fix division by zero when calculating IO rates
|
||||
* Fix out of boundary writes in XUtils
|
||||
* Fix custom thread name display issue
|
||||
* Use AC_CANONICAL_HOST, not AC_CANONICAL_TARGET in configure.ac
|
||||
* Support libunwind of LLVM
|
||||
|
||||
What's new in version 3.1.2
|
||||
|
||||
* Bugfix for crash when storing modified settings at exit
|
||||
* Generate xz-compressed source tarball (with configure) using github actions
|
||||
* Allow -u UID with numerical value as argument
|
||||
* Added documentation for obsolete/state libraries/program files highlighting
|
||||
* Some obsolete/stale library highlighting refinements
|
||||
* Column width issues resolved
|
||||
* Dynamic UID column sizing improved
|
||||
* Discard stale information from Disk and Network I/O meters
|
||||
* Refined Linux kernel thread detection
|
||||
* Reworked process state handling
|
||||
* New CCGROUP column showing abbreviated cgroup name
|
||||
* New OFFSET column in the list of open files screen
|
||||
|
||||
What's new in version 3.1.1
|
||||
|
||||
* Update license headers to explicitly say GPLv2+
|
||||
* Document minimum version for libcap (thanks to James Brown)
|
||||
* Fix mouse wheel collision with autogroups nice adjustment
|
||||
* Adjust Makefile.am macro definitions for older automake versions
|
||||
* Ensure consistent reporting of MemoryMeter 'used' memory
|
||||
* Report hugepage memory as real and used memory (as before)
|
||||
* Handle procExeDeleted, usesDeletedLib without mergedCommandline mode
|
||||
* Validate meter configuration before proceeding beyond htoprc parsing
|
||||
* Properly release memory on partially read configuration
|
||||
* Handle interrupted sampling from within libpcp PDU transfers
|
||||
* On Linux, provide O_PATH value if not defined
|
||||
* On Linux, always compute procExeDeleted if already set
|
||||
* Workaround for Rosetta 2 on Darwin (thanks to Alexander Momchilov)
|
||||
* Fix FreeBSD cmdline memory leak in Process_updateCmdline, and
|
||||
* Plug a Disk I/O meter memory leak on FreeBSD (thanks to Ximalas)
|
||||
|
||||
What's new in version 3.1.0
|
||||
|
||||
* Updated COPYING file to remove the PLPA exemption (appendix 2)
|
||||
With this change the license is now GPLv2 without any additional wording.
|
||||
@ -26,10 +112,11 @@ What's new in version 3.1.0
|
||||
Moving this column to be handled as a platform-independently available
|
||||
information simplifies the markup of the command line.
|
||||
* Introduce configuration file versioning and config_reader_min_version
|
||||
Starting with this version the configuration file contains an version
|
||||
Starting with this version the configuration file contains a version
|
||||
identifying the minimum version of the configuration parser needed to
|
||||
fully understand the configuration file format.
|
||||
Old configuration file formats are automatically upgraded on startup.
|
||||
Old configuration file formats are automatically upgraded when
|
||||
saving the config file (htoprc).
|
||||
* Make the configuration parser friendlier to users (thanks to Bart Bakker)
|
||||
With this change only settings that cannot be parsed properly are
|
||||
reset to their defaults.
|
||||
@ -48,12 +135,12 @@ What's new in version 3.1.0
|
||||
* Option and key ("*") to collapse / expand all branches under PID 1
|
||||
(and PID 2 if kernel threads are shown) (thanks to Krishna Chaitanya)
|
||||
* Keep following a process when inverting the sort order, displaying
|
||||
the help screen or hiding/unhiding userland threads
|
||||
the help screen or hiding/unhiding userland threads.
|
||||
If a thread is currently selected the selection is updated to point
|
||||
to the thread's parent process. (thanks to Gonzalo, et.al.)
|
||||
* Reorder process scanning to be performed before updating the display
|
||||
of the meters in the header
|
||||
* Always check the user for a process for any changes
|
||||
* Always check the user for a process for any changes.
|
||||
This affects multiple platforms that previously didn't correctly handle
|
||||
the user field for a process to change at runtime (e.g. due to seteuid
|
||||
or similar syscalls).
|
||||
@ -105,14 +192,14 @@ What's new in version 3.1.0
|
||||
* Correctly color the ZFS ARC ratio (thanks to Ross Williams)
|
||||
* Bugfixes related to CPU time display/calculations for darwin on M1 systems
|
||||
(thanks to Alexander Momchilov)
|
||||
* Harmonize the handling of multiple batteries across different platforms
|
||||
* Harmonize the handling of multiple batteries across different platforms.
|
||||
The system is now considered to run on AC if at least one power supply
|
||||
marked as AC is found in the system.
|
||||
Battery capacity is summed up over all batteries found.
|
||||
This also changes the old behavior that batteries reported by the
|
||||
system after the first AC adapter where sometimes ignored.
|
||||
* Correctly handle multiple batteries on Darwin
|
||||
Resolves a possible memory leak on systems with multiple batteries
|
||||
* Correctly handle multiple batteries on Darwin.
|
||||
Resolves a possible memory leak on systems with multiple batteries.
|
||||
* Handle Linux Shmem being part of Cached in the MemoryMeter
|
||||
* Add SwapCached to the Linux swap meter (thanks to David Zarzycki)
|
||||
* Convert process time to days if applicable (thanks to David Zarzycki)
|
||||
@ -138,7 +225,7 @@ What's new in version 3.1.0
|
||||
* Add command line option to drop Linux capabilities
|
||||
* Support scheduler affinity on platforms beyond Linux
|
||||
* Report on any failure to write the configuration file
|
||||
* Cache stderr to be able to print assert messages
|
||||
* Cache stderr to be able to print assert messages.
|
||||
These messages are shown in case htop terminates unexpectedly.
|
||||
* Print current settings on crash
|
||||
* Reset signal handlers on program exit
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ClockMeter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ClockMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ColorsPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -68,6 +68,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
this->settings->colorScheme = mark;
|
||||
this->settings->changed = true;
|
||||
this->settings->lastUpdate++;
|
||||
|
||||
CRT_setColors(mark);
|
||||
clear();
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ColorsPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ColumnsPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -118,12 +118,6 @@ const PanelClass ColumnsPanel_class = {
|
||||
.eventHandler = ColumnsPanel_eventHandler
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
Panel* super;
|
||||
unsigned int id;
|
||||
unsigned int offset;
|
||||
} DynamicIterator;
|
||||
|
||||
static void ColumnsPanel_add(Panel* super, unsigned int key, Hashtable* columns) {
|
||||
const char* name;
|
||||
if (key < LAST_PROCESSFIELD) {
|
||||
@ -144,20 +138,26 @@ static void ColumnsPanel_add(Panel* super, unsigned int key, Hashtable* columns)
|
||||
Panel_add(super, (Object*) ListItem_new(name, key));
|
||||
}
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings) {
|
||||
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* columns) {
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_prune(super);
|
||||
for (const ProcessField* fields = ss->fields; *fields; fields++)
|
||||
ColumnsPanel_add(super, *fields, columns);
|
||||
this->ss = ss;
|
||||
}
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, Hashtable* columns, bool* changed) {
|
||||
ColumnsPanel* this = AllocThis(ColumnsPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->ss = ss;
|
||||
this->changed = changed;
|
||||
this->moving = false;
|
||||
Panel_setHeader(super, "Active Columns");
|
||||
|
||||
Hashtable* dynamicColumns = settings->dynamicColumns;
|
||||
const ProcessField* fields = settings->fields;
|
||||
for (; *fields; fields++)
|
||||
ColumnsPanel_add(super, *fields, dynamicColumns);
|
||||
ColumnsPanel_fill(this, ss, columns);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -165,14 +165,14 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) {
|
||||
void ColumnsPanel_update(Panel* super) {
|
||||
ColumnsPanel* this = (ColumnsPanel*) super;
|
||||
int size = Panel_size(super);
|
||||
this->settings->changed = true;
|
||||
this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size + 1));
|
||||
this->settings->flags = 0;
|
||||
*(this->changed) = true;
|
||||
this->ss->fields = xRealloc(this->ss->fields, sizeof(ProcessField) * (size + 1));
|
||||
this->ss->flags = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
int key = ((ListItem*) Panel_get(super, i))->key;
|
||||
this->settings->fields[i] = key;
|
||||
this->ss->fields[i] = key;
|
||||
if (key < LAST_PROCESSFIELD)
|
||||
this->settings->flags |= Process_fields[key].flags;
|
||||
this->ss->flags |= Process_fields[key].flags;
|
||||
}
|
||||
this->settings->fields[size] = 0;
|
||||
this->ss->fields[size] = 0;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ColumnsPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -15,14 +15,17 @@ in the source distribution for its full text.
|
||||
|
||||
typedef struct ColumnsPanel_ {
|
||||
Panel super;
|
||||
ScreenSettings* ss;
|
||||
bool* changed;
|
||||
|
||||
Settings* settings;
|
||||
bool moving;
|
||||
} ColumnsPanel;
|
||||
|
||||
extern const PanelClass ColumnsPanel_class;
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings);
|
||||
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, Hashtable* columns, bool* changed);
|
||||
|
||||
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* columns);
|
||||
|
||||
void ColumnsPanel_update(Panel* super);
|
||||
|
||||
|
123
CommandLine.c
123
CommandLine.c
@ -2,7 +2,7 @@
|
||||
htop - CommandLine.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2020-2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -11,6 +11,7 @@ in the source distribution for its full text.
|
||||
#include "CommandLine.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
@ -47,20 +48,22 @@ static void printVersionFlag(const char* name) {
|
||||
static void printHelpFlag(const char* name) {
|
||||
printf("%s " VERSION "\n"
|
||||
COPYRIGHT "\n"
|
||||
"Released under the GNU GPLv2.\n\n"
|
||||
"Released under the GNU GPLv2+.\n\n"
|
||||
"-C --no-color Use a monochrome color scheme\n"
|
||||
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
||||
"-F --filter=FILTER Show only the commands matching the given filter\n"
|
||||
"-h --help Print this help screen\n"
|
||||
"-H --highlight-changes[=DELAY] Highlight new and old processes\n"
|
||||
"-M --no-mouse Disable the mouse\n"
|
||||
"-p --pid=PID[,PID,PID...] Show only the given PIDs\n"
|
||||
"-H --highlight-changes[=DELAY] Highlight new and old processes\n", name);
|
||||
#ifdef HAVE_GETMOUSE
|
||||
printf("-M --no-mouse Disable the mouse\n");
|
||||
#endif
|
||||
printf("-p --pid=PID[,PID,PID...] Show only the given PIDs\n"
|
||||
" --readonly Disable all system and process changing features\n"
|
||||
"-s --sort-key=COLUMN Sort by COLUMN in list view (try --sort-key=help for a list)\n"
|
||||
"-t --tree Show the tree view (can be combined with -s)\n"
|
||||
"-u --user[=USERNAME] Show only processes for a given user (or $USER)\n"
|
||||
"-U --no-unicode Do not use unicode but plain ASCII\n"
|
||||
"-V --version Print version info\n", name);
|
||||
"-V --version Print version info\n");
|
||||
Platform_longOptionsUsage(name);
|
||||
printf("\n"
|
||||
"Long options may be passed with a single dash.\n\n"
|
||||
@ -85,9 +88,9 @@ typedef struct CommandLineSettings_ {
|
||||
bool readonly;
|
||||
} CommandLineSettings;
|
||||
|
||||
static CommandLineSettings parseArguments(const char* program, int argc, char** argv) {
|
||||
static CommandLineStatus parseArguments(const char* program, int argc, char** argv, CommandLineSettings* flags) {
|
||||
|
||||
CommandLineSettings flags = {
|
||||
*flags = (CommandLineSettings) {
|
||||
.pidMatchList = NULL,
|
||||
.commFilter = NULL,
|
||||
.userId = (uid_t)-1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2))
|
||||
@ -130,10 +133,10 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
printHelpFlag(program);
|
||||
exit(0);
|
||||
return STATUS_OK_EXIT;
|
||||
case 'V':
|
||||
printVersionFlag(program);
|
||||
exit(0);
|
||||
return STATUS_OK_EXIT;
|
||||
case 's':
|
||||
assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */
|
||||
if (String_eq(optarg, "help")) {
|
||||
@ -142,29 +145,29 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
|
||||
const char* description = Process_fields[j].description;
|
||||
if (name) printf("%19s %s\n", name, description);
|
||||
}
|
||||
exit(0);
|
||||
return STATUS_OK_EXIT;
|
||||
}
|
||||
flags.sortKey = 0;
|
||||
flags->sortKey = 0;
|
||||
for (int j = 1; j < LAST_PROCESSFIELD; j++) {
|
||||
if (Process_fields[j].name == NULL)
|
||||
continue;
|
||||
if (String_eq(optarg, Process_fields[j].name)) {
|
||||
flags.sortKey = j;
|
||||
flags->sortKey = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flags.sortKey == 0) {
|
||||
if (flags->sortKey == 0) {
|
||||
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
|
||||
exit(1);
|
||||
return STATUS_ERROR_EXIT;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (sscanf(optarg, "%16d", &(flags.delay)) == 1) {
|
||||
if (flags.delay < 1) flags.delay = 1;
|
||||
if (flags.delay > 100) flags.delay = 100;
|
||||
if (sscanf(optarg, "%16d", &(flags->delay)) == 1) {
|
||||
if (flags->delay < 1) flags->delay = 1;
|
||||
if (flags->delay > 100) flags->delay = 100;
|
||||
} else {
|
||||
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
|
||||
exit(1);
|
||||
return STATUS_ERROR_EXIT;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
@ -176,26 +179,30 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
|
||||
}
|
||||
|
||||
if (!username) {
|
||||
flags.userId = geteuid();
|
||||
} else if (!Action_setUserOnly(username, &(flags.userId))) {
|
||||
flags->userId = geteuid();
|
||||
} else if (!Action_setUserOnly(username, &(flags->userId))) {
|
||||
for (const char *itr = username; *itr; ++itr)
|
||||
if (!isdigit((unsigned char)*itr)) {
|
||||
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
|
||||
exit(1);
|
||||
return STATUS_ERROR_EXIT;
|
||||
}
|
||||
flags->userId = atol(username);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'C':
|
||||
flags.useColors = false;
|
||||
flags->useColors = false;
|
||||
break;
|
||||
case 'M':
|
||||
#ifdef HAVE_GETMOUSE
|
||||
flags.enableMouse = false;
|
||||
flags->enableMouse = false;
|
||||
#endif
|
||||
break;
|
||||
case 'U':
|
||||
flags.allowUnicode = false;
|
||||
flags->allowUnicode = false;
|
||||
break;
|
||||
case 't':
|
||||
flags.treeView = true;
|
||||
flags->treeView = true;
|
||||
break;
|
||||
case 'p': {
|
||||
assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */
|
||||
@ -203,14 +210,14 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
|
||||
char* saveptr;
|
||||
const char* pid = strtok_r(argCopy, ",", &saveptr);
|
||||
|
||||
if (!flags.pidMatchList) {
|
||||
flags.pidMatchList = Hashtable_new(8, false);
|
||||
if (!flags->pidMatchList) {
|
||||
flags->pidMatchList = Hashtable_new(8, false);
|
||||
}
|
||||
|
||||
while(pid) {
|
||||
unsigned int num_pid = atoi(pid);
|
||||
// deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here
|
||||
Hashtable_put(flags.pidMatchList, num_pid, (void *) 1);
|
||||
// deepcode ignore CastIntegerToAddress: we just want a non-NULL pointer here
|
||||
Hashtable_put(flags->pidMatchList, num_pid, (void *) 1);
|
||||
pid = strtok_r(NULL, ",", &saveptr);
|
||||
}
|
||||
free(argCopy);
|
||||
@ -219,7 +226,7 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
|
||||
}
|
||||
case 'F': {
|
||||
assert(optarg);
|
||||
free_and_xStrdup(&flags.commFilter, optarg);
|
||||
free_and_xStrdup(&flags->commFilter, optarg);
|
||||
break;
|
||||
}
|
||||
case 'H': {
|
||||
@ -229,28 +236,30 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
|
||||
delay = argv[optind++];
|
||||
}
|
||||
if (delay) {
|
||||
if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) {
|
||||
if (flags.highlightDelaySecs < 1)
|
||||
flags.highlightDelaySecs = 1;
|
||||
if (sscanf(delay, "%16d", &(flags->highlightDelaySecs)) == 1) {
|
||||
if (flags->highlightDelaySecs < 1)
|
||||
flags->highlightDelaySecs = 1;
|
||||
} else {
|
||||
fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay);
|
||||
exit(1);
|
||||
return STATUS_ERROR_EXIT;
|
||||
}
|
||||
}
|
||||
flags.highlightChanges = true;
|
||||
flags->highlightChanges = true;
|
||||
break;
|
||||
}
|
||||
case 128:
|
||||
flags.readonly = true;
|
||||
flags->readonly = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Platform_getLongOption(opt, argc, argv) == false)
|
||||
exit(1);
|
||||
default: {
|
||||
CommandLineStatus status;
|
||||
if ((status = Platform_getLongOption(opt, argc, argv)) != STATUS_OK)
|
||||
return status;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
static void CommandLine_delay(ProcessList* pl, unsigned long millisec) {
|
||||
@ -283,12 +292,17 @@ int CommandLine_run(const char* name, int argc, char** argv) {
|
||||
else
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
CommandLineSettings flags = parseArguments(name, argc, argv);
|
||||
CommandLineStatus status = STATUS_OK;
|
||||
CommandLineSettings flags = { 0 };
|
||||
|
||||
if ((status = parseArguments(name, argc, argv, &flags)) != STATUS_OK)
|
||||
return status != STATUS_OK_EXIT ? 1 : 0;
|
||||
|
||||
if (flags.readonly)
|
||||
Settings_enableReadonly();
|
||||
|
||||
Platform_init();
|
||||
if (!Platform_init())
|
||||
return 1;
|
||||
|
||||
Process_setupColumnWidths();
|
||||
|
||||
@ -316,7 +330,7 @@ int CommandLine_run(const char* name, int argc, char** argv) {
|
||||
settings->enableMouse = false;
|
||||
#endif
|
||||
if (flags.treeView)
|
||||
settings->treeView = true;
|
||||
settings->ss->treeView = true;
|
||||
if (flags.highlightChanges)
|
||||
settings->highlightChanges = true;
|
||||
if (flags.highlightDelaySecs != -1)
|
||||
@ -325,9 +339,9 @@ int CommandLine_run(const char* name, int argc, char** argv) {
|
||||
// -t -s <key> means "tree sorted by key"
|
||||
// -s <key> means "list sorted by key" (previous existing behavior)
|
||||
if (!flags.treeView) {
|
||||
settings->treeView = false;
|
||||
settings->ss->treeView = false;
|
||||
}
|
||||
Settings_setSortKey(settings, flags.sortKey);
|
||||
ScreenSettings_setSortKey(settings->ss, flags.sortKey);
|
||||
}
|
||||
|
||||
CRT_init(settings, flags.allowUnicode);
|
||||
@ -335,7 +349,7 @@ int CommandLine_run(const char* name, int argc, char** argv) {
|
||||
MainPanel* panel = MainPanel_new();
|
||||
ProcessList_setPanel(pl, (Panel*) panel);
|
||||
|
||||
MainPanel_updateTreeFunctions(panel, settings->treeView);
|
||||
MainPanel_updateLabels(panel, settings->ss->treeView, flags.commFilter);
|
||||
|
||||
State state = {
|
||||
.settings = settings,
|
||||
@ -358,15 +372,10 @@ int CommandLine_run(const char* name, int argc, char** argv) {
|
||||
CommandLine_delay(pl, 75);
|
||||
ProcessList_scan(pl, false);
|
||||
|
||||
if (settings->allBranchesCollapsed)
|
||||
if (settings->ss->allBranchesCollapsed)
|
||||
ProcessList_collapseAllBranches(pl);
|
||||
|
||||
ScreenManager_run(scr, NULL, NULL);
|
||||
|
||||
attron(CRT_colors[RESET_COLOR]);
|
||||
mvhline(LINES - 1, 0, ' ', COLS);
|
||||
attroff(CRT_colors[RESET_COLOR]);
|
||||
refresh();
|
||||
ScreenManager_run(scr, NULL, NULL, NULL);
|
||||
|
||||
Platform_done();
|
||||
|
||||
@ -393,10 +402,8 @@ int CommandLine_run(const char* name, int argc, char** argv) {
|
||||
|
||||
/* Delete these last, since they can get accessed in the crash handler */
|
||||
Settings_delete(settings);
|
||||
if (dc)
|
||||
Hashtable_delete(dc);
|
||||
if (dm)
|
||||
Hashtable_delete(dm);
|
||||
DynamicColumns_delete(dc);
|
||||
DynamicMeters_delete(dm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,10 +4,15 @@
|
||||
htop - CommandLine.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2020-2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
STATUS_OK,
|
||||
STATUS_ERROR_EXIT,
|
||||
STATUS_OK_EXIT
|
||||
} CommandLineStatus;
|
||||
|
||||
int CommandLine_run(const char* name, int argc, char** argv);
|
||||
|
||||
|
2
Compat.c
2
Compat.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Compat.c
|
||||
(C) 2020 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
2
Compat.h
2
Compat.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Compat.h
|
||||
(C) 2020 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - DateMeter.c
|
||||
(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - DateMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - DateTimeMeter.c
|
||||
(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - DateTimeMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - DiskIOMeter.c
|
||||
(C) 2020 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -12,6 +12,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include "CRT.h"
|
||||
#include "Macros.h"
|
||||
#include "Meter.h"
|
||||
#include "Object.h"
|
||||
#include "Platform.h"
|
||||
#include "ProcessList.h"
|
||||
@ -25,7 +26,7 @@ static const int DiskIOMeter_attributes[] = {
|
||||
METER_VALUE_IOWRITE,
|
||||
};
|
||||
|
||||
static bool hasData = false;
|
||||
static MeterRateStatus status = RATESTATUS_INIT;
|
||||
static uint32_t cached_read_diff;
|
||||
static uint32_t cached_write_diff;
|
||||
static double cached_utilisation_diff;
|
||||
@ -36,20 +37,27 @@ static void DiskIOMeter_updateValues(Meter* this) {
|
||||
static uint64_t cached_last_update;
|
||||
uint64_t passedTimeInMs = pl->realtimeMs - cached_last_update;
|
||||
|
||||
/* update only every 500ms */
|
||||
/* update only every 500ms to have a sane span for rate calculation */
|
||||
if (passedTimeInMs > 500) {
|
||||
static uint64_t cached_read_total;
|
||||
static uint64_t cached_write_total;
|
||||
static uint64_t cached_msTimeSpend_total;
|
||||
uint64_t diff;
|
||||
|
||||
DiskIOData data;
|
||||
if (!Platform_getDiskIO(&data)) {
|
||||
status = RATESTATUS_NODATA;
|
||||
} else if (cached_last_update == 0) {
|
||||
status = RATESTATUS_INIT;
|
||||
} else if (passedTimeInMs > 30000) {
|
||||
status = RATESTATUS_STALE;
|
||||
} else {
|
||||
status = RATESTATUS_DATA;
|
||||
}
|
||||
|
||||
cached_last_update = pl->realtimeMs;
|
||||
|
||||
DiskIOData data;
|
||||
|
||||
hasData = Platform_getDiskIO(&data);
|
||||
if (!hasData) {
|
||||
this->values[0] = 0;
|
||||
if (status == RATESTATUS_NODATA) {
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
|
||||
return;
|
||||
}
|
||||
@ -81,6 +89,15 @@ static void DiskIOMeter_updateValues(Meter* this) {
|
||||
cached_msTimeSpend_total = data.totalMsTimeSpend;
|
||||
}
|
||||
|
||||
if (status == RATESTATUS_INIT) {
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "init");
|
||||
return;
|
||||
}
|
||||
if (status == RATESTATUS_STALE) {
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "stale");
|
||||
return;
|
||||
}
|
||||
|
||||
this->values[0] = cached_utilisation_diff;
|
||||
this->total = MAXIMUM(this->values[0], 100.0); /* fix total after (initial) spike */
|
||||
|
||||
@ -91,9 +108,18 @@ static void DiskIOMeter_updateValues(Meter* this) {
|
||||
}
|
||||
|
||||
static void DiskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
|
||||
if (!hasData) {
|
||||
switch (status) {
|
||||
case RATESTATUS_NODATA:
|
||||
RichString_writeAscii(out, CRT_colors[METER_VALUE_ERROR], "no data");
|
||||
return;
|
||||
case RATESTATUS_INIT:
|
||||
RichString_writeAscii(out, CRT_colors[METER_VALUE], "initializing...");
|
||||
return;
|
||||
case RATESTATUS_STALE:
|
||||
RichString_writeAscii(out, CRT_colors[METER_VALUE_WARN], "stale data");
|
||||
return;
|
||||
case RATESTATUS_DATA:
|
||||
break;
|
||||
}
|
||||
|
||||
char buffer[16];
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - DiskIOMeter.h
|
||||
(C) 2020 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - DisplayOptionsPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -18,6 +18,7 @@ in the source distribution for its full text.
|
||||
#include "Object.h"
|
||||
#include "OptionItem.h"
|
||||
#include "ProvideCurses.h"
|
||||
#include "ScreensPanel.h"
|
||||
|
||||
|
||||
static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
@ -43,6 +44,8 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
case KEY_RECLICK:
|
||||
case ' ':
|
||||
switch (OptionItem_kind(selected)) {
|
||||
case OPTION_ITEM_TEXT:
|
||||
break;
|
||||
case OPTION_ITEM_CHECK:
|
||||
CheckItem_toggle((CheckItem*)selected);
|
||||
result = HANDLED;
|
||||
@ -69,6 +72,7 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
if (result == HANDLED) {
|
||||
this->settings->changed = true;
|
||||
this->settings->lastUpdate++;
|
||||
Header* header = this->scr->header;
|
||||
Header_calculateHeight(header);
|
||||
Header_reinit(header);
|
||||
@ -97,9 +101,18 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||
this->scr = scr;
|
||||
|
||||
Panel_setHeader(super, "Display options");
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->treeViewAlwaysByPID)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->allBranchesCollapsed)));
|
||||
|
||||
#define TABMSG "For current screen tab: \0"
|
||||
char tabheader[sizeof(TABMSG) + SCREEN_NAME_LEN + 1] = TABMSG;
|
||||
strncat(tabheader, settings->ss->name, SCREEN_NAME_LEN);
|
||||
Panel_add(super, (Object*) TextItem_new(tabheader));
|
||||
#undef TABMSG
|
||||
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->ss->treeView)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed)));
|
||||
Panel_add(super, (Object*) TextItem_new("Global options:"));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads)));
|
||||
@ -107,7 +120,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Show custom thread names", &(settings->showThreadNames)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Show program path", &(settings->showProgramPath)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Highlight program \"basename\"", &(settings->highlightBaseName)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs", &(settings->highlightDeletedExe)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs (red) / libraries (yellow)", &(settings->highlightDeletedExe)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Merge exe, comm and cmdline in Command", &(settings->showMergedCommand)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Try to find comm in cmdline (when Command is merged)", &(settings->findCommInCmdline)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Try to strip exe from cmdline (when Command is merged)", &(settings->stripExeFromCmdline)));
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - DisplayOptionsPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@ htop - DynamicColumn.c
|
||||
(C) 2021 Sohaib Mohammed
|
||||
(C) 2021 htop dev team
|
||||
(C) 2021 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -22,6 +22,13 @@ Hashtable* DynamicColumns_new(void) {
|
||||
return Platform_dynamicColumns();
|
||||
}
|
||||
|
||||
void DynamicColumns_delete(Hashtable* dynamics) {
|
||||
if (dynamics) {
|
||||
Platform_dynamicColumnsDone(dynamics);
|
||||
Hashtable_delete(dynamics);
|
||||
}
|
||||
}
|
||||
|
||||
const char* DynamicColumn_init(unsigned int key) {
|
||||
return Platform_dynamicColumnInit(key);
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ typedef struct DynamicColumn_ {
|
||||
|
||||
Hashtable* DynamicColumns_new(void);
|
||||
|
||||
void DynamicColumns_delete(Hashtable* dynamics);
|
||||
|
||||
const char* DynamicColumn_init(unsigned int key);
|
||||
|
||||
const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, unsigned int key);
|
||||
|
@ -2,7 +2,7 @@
|
||||
htop - DynamicMeter.c
|
||||
(C) 2021 htop dev team
|
||||
(C) 2021 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -38,6 +38,13 @@ Hashtable* DynamicMeters_new(void) {
|
||||
return Platform_dynamicMeters();
|
||||
}
|
||||
|
||||
void DynamicMeters_delete(Hashtable* dynamics) {
|
||||
if (dynamics) {
|
||||
Platform_dynamicMetersDone(dynamics);
|
||||
Hashtable_delete(dynamics);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned int key;
|
||||
const char* name;
|
||||
|
@ -17,6 +17,8 @@ typedef struct DynamicMeter_ {
|
||||
|
||||
Hashtable* DynamicMeters_new(void);
|
||||
|
||||
void DynamicMeters_delete(Hashtable* dynamics);
|
||||
|
||||
const char* DynamicMeter_lookup(Hashtable* dynamics, unsigned int key);
|
||||
|
||||
bool DynamicMeter_search(Hashtable* dynamics, const char* name, unsigned int* key);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - FunctionBar.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -88,11 +88,12 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionBar_draw(const FunctionBar* this) {
|
||||
FunctionBar_drawExtra(this, NULL, -1, false);
|
||||
int FunctionBar_draw(const FunctionBar* this) {
|
||||
return FunctionBar_drawExtra(this, NULL, -1, false);
|
||||
}
|
||||
|
||||
void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) {
|
||||
int FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) {
|
||||
int cursorX = 0;
|
||||
attrset(CRT_colors[FUNCTION_BAR]);
|
||||
mvhline(LINES - 1, 0, ' ', COLS);
|
||||
int x = 0;
|
||||
@ -113,18 +114,20 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr
|
||||
}
|
||||
mvaddstr(LINES - 1, x, buffer);
|
||||
x += strlen(buffer);
|
||||
cursorX = x;
|
||||
}
|
||||
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
|
||||
if (setCursor) {
|
||||
CRT_cursorX = x;
|
||||
curs_set(1);
|
||||
} else {
|
||||
curs_set(0);
|
||||
}
|
||||
|
||||
currentLen = x;
|
||||
|
||||
return cursorX;
|
||||
}
|
||||
|
||||
void FunctionBar_append(const char* buffer, int attr) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - FunctionBar.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -29,9 +29,9 @@ void FunctionBar_delete(FunctionBar* this);
|
||||
|
||||
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
||||
|
||||
void FunctionBar_draw(const FunctionBar* this);
|
||||
int FunctionBar_draw(const FunctionBar* this);
|
||||
|
||||
void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor);
|
||||
int FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor);
|
||||
|
||||
void FunctionBar_append(const char* buffer, int attr);
|
||||
|
||||
|
14
Hashtable.c
14
Hashtable.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Hashtable.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -52,7 +52,7 @@ static void Hashtable_dump(const Hashtable* this) {
|
||||
i,
|
||||
this->buckets[i].key,
|
||||
this->buckets[i].probe,
|
||||
this->buckets[i].value ? (const void*)this->buckets[i].value : "(nil)");
|
||||
this->buckets[i].value);
|
||||
|
||||
if (this->buckets[i].value)
|
||||
items++;
|
||||
@ -90,7 +90,7 @@ size_t Hashtable_count(const Hashtable* this) {
|
||||
|
||||
/* https://oeis.org/A014234 */
|
||||
static const uint64_t OEISprimes[] = {
|
||||
2, 3, 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191,
|
||||
7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191,
|
||||
16381, 32749, 65521, 131071, 262139, 524287, 1048573,
|
||||
2097143, 4194301, 8388593, 16777213, 33554393,
|
||||
67108859, 134217689, 268435399, 536870909, 1073741789,
|
||||
@ -191,10 +191,14 @@ void Hashtable_setSize(Hashtable* this, size_t size) {
|
||||
if (size <= this->items)
|
||||
return;
|
||||
|
||||
size_t newSize = nextPrime(size);
|
||||
if (newSize == this->size)
|
||||
return;
|
||||
|
||||
HashtableItem* oldBuckets = this->buckets;
|
||||
size_t oldSize = this->size;
|
||||
|
||||
this->size = nextPrime(size);
|
||||
this->size = newSize;
|
||||
this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem));
|
||||
this->items = 0;
|
||||
|
||||
@ -282,7 +286,7 @@ void* Hashtable_remove(Hashtable* this, ht_key_t key) {
|
||||
|
||||
/* shrink on load-factor < 0.125 */
|
||||
if (8 * this->items < this->size)
|
||||
Hashtable_setSize(this, this->size / 2);
|
||||
Hashtable_setSize(this, this->size / 3); /* account for nextPrime rounding up */
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Hashtable.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
32
Header.c
32
Header.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Header.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -86,8 +86,9 @@ static void Header_addMeterByName(Header* this, const char* name, MeterModeId mo
|
||||
if (paren) {
|
||||
int ok = sscanf(paren, "(%10u)", ¶m); // CPUMeter
|
||||
if (!ok) {
|
||||
char* end, dynamic[32] = {0};
|
||||
char dynamic[32] = {0};
|
||||
if (sscanf(paren, "(%30s)", dynamic)) { // DynamicMeter
|
||||
char* end;
|
||||
if ((end = strrchr(dynamic, ')')) == NULL)
|
||||
return; // htoprc parse failure
|
||||
*end = '\0';
|
||||
@ -144,7 +145,7 @@ void Header_writeBackToSettings(const Header* this) {
|
||||
const Vector* vec = this->columns[col];
|
||||
int len = Vector_size(vec);
|
||||
|
||||
colSettings->names = len ? xCalloc(len, sizeof(char*)) : NULL;
|
||||
colSettings->names = len ? xCalloc(len + 1, sizeof(char*)) : NULL;
|
||||
colSettings->modes = len ? xCalloc(len, sizeof(int)) : NULL;
|
||||
colSettings->len = len;
|
||||
|
||||
@ -193,27 +194,32 @@ void Header_draw(const Header* this) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
mvhline(y, 0, ' ', COLS);
|
||||
}
|
||||
const int width = COLS - pad;
|
||||
const int numCols = HeaderLayout_getColumns(this->headerLayout);
|
||||
const int width = COLS - 2 * pad - (numCols - 1);
|
||||
int x = pad;
|
||||
float roundingLoss = 0.0f;
|
||||
float roundingLoss = 0.0F;
|
||||
|
||||
Header_forEachColumn(this, col) {
|
||||
Vector* meters = this->columns[col];
|
||||
float colWidth = (float)width * HeaderLayout_layouts[this->headerLayout].widths[col] / 100.0f;
|
||||
float colWidth = (float)width * HeaderLayout_layouts[this->headerLayout].widths[col] / 100.0F;
|
||||
|
||||
roundingLoss += colWidth - floorf(colWidth);
|
||||
if (roundingLoss >= 1.0f) {
|
||||
colWidth += 1.0f;
|
||||
roundingLoss -= 1.0f;
|
||||
if (roundingLoss >= 1.0F) {
|
||||
colWidth += 1.0F;
|
||||
roundingLoss -= 1.0F;
|
||||
}
|
||||
|
||||
for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
|
||||
float actualWidth = colWidth;
|
||||
if (meter->mode == TEXT_METERMODE) {
|
||||
|
||||
/* Let meters in text mode expand to the right on empty neighbors;
|
||||
except for multi column meters. */
|
||||
if (meter->mode == TEXT_METERMODE && !Meter_isMultiColumn(meter)) {
|
||||
for (int j = 1; j < meter->columnWidthCount; j++) {
|
||||
actualWidth += (float)width * HeaderLayout_layouts[this->headerLayout].widths[col + j] / 100.0f;
|
||||
actualWidth++; /* separator column */
|
||||
actualWidth += (float)width * HeaderLayout_layouts[this->headerLayout].widths[col + j] / 100.0F;
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,6 +229,7 @@ void Header_draw(const Header* this) {
|
||||
}
|
||||
|
||||
x += floorf(colWidth);
|
||||
x++; /* separator column */
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,6 +286,9 @@ int Header_calculateHeight(Header* this) {
|
||||
}
|
||||
maxHeight = MAXIMUM(maxHeight, height);
|
||||
}
|
||||
if (this->settings->screenTabs) {
|
||||
maxHeight++;
|
||||
}
|
||||
this->height = maxHeight;
|
||||
this->pad = pad;
|
||||
return maxHeight;
|
||||
|
4
Header.h
4
Header.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Header.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -23,7 +23,7 @@ typedef struct Header_ {
|
||||
int height;
|
||||
} Header;
|
||||
|
||||
#define Header_forEachColumn(this_, i_) for (size_t (i_)=0; (i_) < HeaderLayout_getColumns((this_)->headerLayout); ++(i_))
|
||||
#define Header_forEachColumn(this_, i_) for (size_t (i_)=0, H_fEC_numColumns_ = HeaderLayout_getColumns((this_)->headerLayout); (i_) < H_fEC_numColumns_; ++(i_))
|
||||
|
||||
Header* Header_new(ProcessList* pl, Settings* settings, HeaderLayout hLayout);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - HeaderLayout.h
|
||||
(C) 2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -18,6 +18,7 @@ in the source distribution for its full text.
|
||||
|
||||
|
||||
typedef enum HeaderLayout_ {
|
||||
HF_INVALID = -1,
|
||||
HF_TWO_50_50,
|
||||
HF_TWO_33_67,
|
||||
HF_TWO_67_33,
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - HeaderOptionsPanel.c
|
||||
(C) 2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -52,6 +52,7 @@ static HandlerResult HeaderOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
Header_setLayout(this->scr->header, mark);
|
||||
this->settings->changed = true;
|
||||
this->settings->lastUpdate++;
|
||||
|
||||
ScreenManager_resize(this->scr);
|
||||
|
||||
@ -82,6 +83,6 @@ HeaderOptionsPanel* HeaderOptionsPanel_new(Settings* settings, ScreenManager* sc
|
||||
for (int i = 0; i < LAST_HEADER_LAYOUT; i++) {
|
||||
Panel_add(super, (Object*) CheckItem_newByVal(HeaderLayout_layouts[i].description, false));
|
||||
}
|
||||
CheckItem_set((CheckItem*)Panel_get(super, settings->hLayout), true);
|
||||
CheckItem_set((CheckItem*)Panel_get(super, scr->header->headerLayout), true);
|
||||
return this;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ColorsPanel.h
|
||||
(C) 2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - HostnameMeter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - HostnameMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
45
IncSet.c
45
IncSet.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - IncSet.c
|
||||
(C) 2005-2012 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -85,7 +85,7 @@ static void updateWeakPanel(const IncSet* this, Panel* panel, Vector* lines) {
|
||||
const char* incFilter = this->modes[INC_FILTER].buffer;
|
||||
for (int i = 0; i < Vector_size(lines); i++) {
|
||||
ListItem* line = (ListItem*)Vector_get(lines, i);
|
||||
if (String_contains_i(line->value, incFilter)) {
|
||||
if (String_contains_i(line->value, incFilter, true)) {
|
||||
Panel_add(panel, (Object*)line);
|
||||
if (selected == (Object*)line) {
|
||||
Panel_setSelected(panel, n);
|
||||
@ -105,10 +105,10 @@ static void updateWeakPanel(const IncSet* this, Panel* panel, Vector* lines) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool search(const IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
static bool search(const IncSet* this, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
int size = Panel_size(panel);
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||
if (String_contains_i(getPanelValue(panel, i), this->active->buffer, true)) {
|
||||
Panel_setSelected(panel, i);
|
||||
return true;
|
||||
}
|
||||
@ -117,6 +117,21 @@ static bool search(const IncMode* mode, Panel* panel, IncMode_GetPanelValue getP
|
||||
return false;
|
||||
}
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||
this->active = &(this->modes[type]);
|
||||
panel->currentBar = this->active->bar;
|
||||
panel->cursorOn = true;
|
||||
this->panel = panel;
|
||||
IncSet_drawBar(this, CRT_colors[FUNCTION_BAR]);
|
||||
}
|
||||
|
||||
static void IncSet_deactivate(IncSet* this, Panel* panel) {
|
||||
this->active = NULL;
|
||||
Panel_setDefaultBar(panel);
|
||||
panel->cursorOn = false;
|
||||
FunctionBar_draw(this->defaultBar);
|
||||
}
|
||||
|
||||
static bool IncMode_find(const IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
|
||||
int size = Panel_size(panel);
|
||||
int here = Panel_getSelectedIndex(panel);
|
||||
@ -133,7 +148,7 @@ static bool IncMode_find(const IncMode* mode, Panel* panel, IncMode_GetPanelValu
|
||||
return false;
|
||||
}
|
||||
|
||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer, true)) {
|
||||
Panel_setSelected(panel, i);
|
||||
return true;
|
||||
}
|
||||
@ -156,7 +171,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
doSearch = false;
|
||||
} else if (0 < ch && ch < 255 && isprint((unsigned char)ch)) {
|
||||
if (mode->index < INCMODE_MAX) {
|
||||
mode->buffer[mode->index] = ch;
|
||||
mode->buffer[mode->index] = (char) ch;
|
||||
mode->index++;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
@ -194,12 +209,11 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
IncMode_reset(mode);
|
||||
}
|
||||
}
|
||||
this->active = NULL;
|
||||
Panel_setDefaultBar(panel);
|
||||
IncSet_deactivate(this, panel);
|
||||
doSearch = false;
|
||||
}
|
||||
if (doSearch) {
|
||||
this->found = search(mode, panel, getPanelValue);
|
||||
this->found = search(this, panel, getPanelValue);
|
||||
}
|
||||
if (filterChanged && lines) {
|
||||
updateWeakPanel(this, panel, lines);
|
||||
@ -212,14 +226,13 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
|
||||
return l ? l->value : "";
|
||||
}
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||
this->active = &(this->modes[type]);
|
||||
panel->currentBar = this->active->bar;
|
||||
}
|
||||
|
||||
void IncSet_drawBar(const IncSet* this) {
|
||||
void IncSet_drawBar(const IncSet* this, int attr) {
|
||||
if (this->active) {
|
||||
FunctionBar_drawExtra(this->active->bar, this->active->buffer, (this->active->isFilter || this->found) ? -1 : CRT_colors[FAILED_SEARCH], true);
|
||||
if (!this->active->isFilter && !this->found)
|
||||
attr = CRT_colors[FAILED_SEARCH];
|
||||
int cursorX = FunctionBar_drawExtra(this->active->bar, this->active->buffer, attr, true);
|
||||
this->panel->cursorY = LINES - 1;
|
||||
this->panel->cursorX = cursorX;
|
||||
} else {
|
||||
FunctionBar_draw(this->defaultBar);
|
||||
}
|
||||
|
5
IncSet.h
5
IncSet.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - IncSet.h
|
||||
(C) 2005-2012 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -32,6 +32,7 @@ typedef struct IncMode_ {
|
||||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
Panel* panel;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
@ -57,7 +58,7 @@ const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||
|
||||
void IncSet_drawBar(const IncSet* this);
|
||||
void IncSet_drawBar(const IncSet* this, int attr);
|
||||
|
||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||
|
||||
|
16
InfoScreen.c
16
InfoScreen.c
@ -57,13 +57,13 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
Panel_draw(this->display, true, true, true, false);
|
||||
|
||||
IncSet_drawBar(this->inc);
|
||||
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||
}
|
||||
|
||||
void InfoScreen_addLine(InfoScreen* this, const char* line) {
|
||||
Vector_add(this->lines, (Object*) ListItem_new(line, 0));
|
||||
const char* incFilter = IncSet_filter(this->inc);
|
||||
if (!incFilter || String_contains_i(line, incFilter)) {
|
||||
if (!incFilter || String_contains_i(line, incFilter, true)) {
|
||||
Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines) - 1));
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ void InfoScreen_appendLine(InfoScreen* this, const char* line) {
|
||||
ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines) - 1);
|
||||
ListItem_append(last, line);
|
||||
const char* incFilter = IncSet_filter(this->inc);
|
||||
if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) {
|
||||
if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter, true)) {
|
||||
Panel_add(this->display, (Object*)last);
|
||||
}
|
||||
}
|
||||
@ -89,15 +89,9 @@ void InfoScreen_run(InfoScreen* this) {
|
||||
while (looping) {
|
||||
|
||||
Panel_draw(panel, false, true, true, false);
|
||||
IncSet_drawBar(this->inc);
|
||||
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||
|
||||
if (this->inc->active) {
|
||||
(void) move(LINES - 1, CRT_cursorX);
|
||||
}
|
||||
#ifdef HAVE_SET_ESCDELAY
|
||||
set_escdelay(25);
|
||||
#endif
|
||||
int ch = getch();
|
||||
int ch = Panel_getCh(panel);
|
||||
|
||||
if (ch == ERR) {
|
||||
if (As_InfoScreen(this)->onErr) {
|
||||
|
16
ListItem.c
16
ListItem.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ListItem.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -18,13 +18,13 @@ in the source distribution for its full text.
|
||||
#include "XUtils.h"
|
||||
|
||||
|
||||
static void ListItem_delete(Object* cast) {
|
||||
void ListItem_delete(Object* cast) {
|
||||
ListItem* this = (ListItem*)cast;
|
||||
free(this->value);
|
||||
free(this);
|
||||
}
|
||||
|
||||
static void ListItem_display(const Object* cast, RichString* out) {
|
||||
void ListItem_display(const Object* cast, RichString* out) {
|
||||
const ListItem* const this = (const ListItem*)cast;
|
||||
assert (this != NULL);
|
||||
|
||||
@ -38,11 +38,15 @@ static void ListItem_display(const Object* cast, RichString* out) {
|
||||
RichString_appendWide(out, CRT_colors[DEFAULT_COLOR], this->value);
|
||||
}
|
||||
|
||||
ListItem* ListItem_new(const char* value, int key) {
|
||||
ListItem* this = AllocThis(ListItem);
|
||||
void ListItem_init(ListItem* this, const char* value, int key) {
|
||||
this->value = xStrdup(value);
|
||||
this->key = key;
|
||||
this->moving = false;
|
||||
}
|
||||
|
||||
ListItem* ListItem_new(const char* value, int key) {
|
||||
ListItem* this = AllocThis(ListItem);
|
||||
ListItem_init(this, value, key);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -55,7 +59,7 @@ void ListItem_append(ListItem* this, const char* text) {
|
||||
this->value[newLen] = '\0';
|
||||
}
|
||||
|
||||
static int ListItem_compare(const void* cast1, const void* cast2) {
|
||||
int ListItem_compare(const void* cast1, const void* cast2) {
|
||||
const ListItem* obj1 = (const ListItem*) cast1;
|
||||
const ListItem* obj2 = (const ListItem*) cast2;
|
||||
return strcmp(obj1->value, obj2->value);
|
||||
|
10
ListItem.h
10
ListItem.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ListItem.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -21,10 +21,18 @@ typedef struct ListItem_ {
|
||||
|
||||
extern const ObjectClass ListItem_class;
|
||||
|
||||
void ListItem_delete(Object* cast);
|
||||
|
||||
void ListItem_display(const Object* cast, RichString* out);
|
||||
|
||||
void ListItem_init(ListItem* this, const char* value, int key);
|
||||
|
||||
ListItem* ListItem_new(const char* value, int key);
|
||||
|
||||
void ListItem_append(ListItem* this, const char* text);
|
||||
|
||||
int ListItem_compare(const void* cast1, const void* cast2);
|
||||
|
||||
static inline const char* ListItem_getRef(const ListItem* this) {
|
||||
return this->value;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - LoadAverageMeter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - LoadAverageMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
37
MainPanel.c
37
MainPanel.c
@ -2,7 +2,7 @@
|
||||
htop - ColumnsPanel.c
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -24,9 +24,10 @@ in the source distribution for its full text.
|
||||
static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
||||
static const char* const MainFunctions_ro[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", " ", " ", " ", "Quit ", NULL};
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||
void MainPanel_updateLabels(MainPanel* this, bool list, bool filter) {
|
||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||
FunctionBar_setLabel(bar, KEY_F(5), mode ? "List " : "Tree ");
|
||||
FunctionBar_setLabel(bar, KEY_F(5), list ? "List " : "Tree ");
|
||||
FunctionBar_setLabel(bar, KEY_F(4), filter ? "FILTER" : "Filter");
|
||||
}
|
||||
|
||||
static void MainPanel_pidSearch(MainPanel* this, int ch) {
|
||||
@ -62,26 +63,38 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
return IGNORED;
|
||||
|
||||
/* reset on every normal key */
|
||||
if (ch != ERR)
|
||||
bool needReset = ch != ERR;
|
||||
#ifdef HAVE_GETMOUSE
|
||||
/* except mouse events while mouse support is disabled */
|
||||
if (!(ch != KEY_MOUSE || this->state->settings->enableMouse))
|
||||
needReset = false;
|
||||
#endif
|
||||
if (needReset)
|
||||
this->state->hideProcessSelection = false;
|
||||
|
||||
Settings* settings = this->state->settings;
|
||||
ScreenSettings* ss = settings->ss;
|
||||
|
||||
if (EVENT_IS_HEADER_CLICK(ch)) {
|
||||
int x = EVENT_HEADER_CLICK_GET_X(ch);
|
||||
const ProcessList* pl = this->state->pl;
|
||||
Settings* settings = this->state->settings;
|
||||
int hx = super->scrollH + x + 1;
|
||||
ProcessField field = ProcessList_keyAt(pl, hx);
|
||||
if (settings->treeView && settings->treeViewAlwaysByPID) {
|
||||
settings->treeView = false;
|
||||
settings->direction = 1;
|
||||
if (ss->treeView && ss->treeViewAlwaysByPID) {
|
||||
ss->treeView = false;
|
||||
ss->direction = 1;
|
||||
reaction |= Action_setSortKey(settings, field);
|
||||
} else if (field == Settings_getActiveSortKey(settings)) {
|
||||
Settings_invertSortOrder(settings);
|
||||
} else if (field == ScreenSettings_getActiveSortKey(ss)) {
|
||||
ScreenSettings_invertSortOrder(ss);
|
||||
} else {
|
||||
reaction |= Action_setSortKey(settings, field);
|
||||
}
|
||||
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
||||
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) {
|
||||
bool filterChanged = IncSet_handleKey(this->inc, ch, super, MainPanel_getValue, NULL);
|
||||
if (filterChanged) {
|
||||
@ -110,7 +123,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
}
|
||||
|
||||
if (reaction & HTOP_REDRAW_BAR) {
|
||||
MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
|
||||
MainPanel_updateLabels(this, settings->ss->treeView, this->state->pl->incFilter);
|
||||
}
|
||||
if (reaction & HTOP_RESIZE) {
|
||||
result |= RESIZE;
|
||||
@ -176,7 +189,7 @@ static void MainPanel_drawFunctionBar(Panel* super, bool hideFunctionBar) {
|
||||
if (hideFunctionBar && !this->inc->active)
|
||||
return;
|
||||
|
||||
IncSet_drawBar(this->inc);
|
||||
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||
if (this->state->pauseProcessUpdate) {
|
||||
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
htop - ColumnsPanel.h
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -32,7 +32,8 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
||||
// update the Label Keys in the MainPanel bar, list: list / tree mode, filter: filter (inc) active / inactive
|
||||
void MainPanel_updateLabels(MainPanel* this, bool list, bool filter);
|
||||
|
||||
int MainPanel_selectedPid(MainPanel* this);
|
||||
|
||||
|
28
Makefile.am
28
Makefile.am
@ -1,3 +1,11 @@
|
||||
if !HTOP_PCP
|
||||
bin_PROGRAMS = htop
|
||||
myhtopplatprogram = htop.c
|
||||
else
|
||||
bin_PROGRAMS = pcp-htop
|
||||
myhtopplatprogram = pcp-htop.c
|
||||
endif
|
||||
|
||||
dist_man_MANS = htop.1
|
||||
EXTRA_DIST = \
|
||||
$(dist_man_MANS) \
|
||||
@ -66,6 +74,7 @@ myhtopsources = \
|
||||
ProcessLocksScreen.c \
|
||||
RichString.c \
|
||||
ScreenManager.c \
|
||||
ScreensPanel.c \
|
||||
Settings.c \
|
||||
SignalsPanel.c \
|
||||
SwapMeter.c \
|
||||
@ -127,6 +136,7 @@ myhtopheaders = \
|
||||
ProvideCurses.h \
|
||||
RichString.h \
|
||||
ScreenManager.h \
|
||||
ScreensPanel.h \
|
||||
Settings.h \
|
||||
SignalsPanel.h \
|
||||
SwapMeter.h \
|
||||
@ -145,6 +155,7 @@ linux_platform_headers = \
|
||||
generic/gettime.h \
|
||||
generic/hostname.h \
|
||||
generic/uname.h \
|
||||
linux/CGroupUtils.h \
|
||||
linux/HugePageMeter.h \
|
||||
linux/IOPriority.h \
|
||||
linux/IOPriorityPanel.h \
|
||||
@ -166,6 +177,7 @@ linux_platform_sources = \
|
||||
generic/gettime.c \
|
||||
generic/hostname.c \
|
||||
generic/uname.c \
|
||||
linux/CGroupUtils.c \
|
||||
linux/HugePageMeter.c \
|
||||
linux/IOPriorityPanel.c \
|
||||
linux/LibSensors.c \
|
||||
@ -181,7 +193,6 @@ linux_platform_sources = \
|
||||
|
||||
if HTOP_LINUX
|
||||
AM_LDFLAGS += -rdynamic
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(linux_platform_headers)
|
||||
myhtopplatsources = $(linux_platform_sources)
|
||||
endif
|
||||
@ -214,7 +225,6 @@ freebsd_platform_sources = \
|
||||
zfs/ZfsCompressedArcMeter.c
|
||||
|
||||
if HTOP_FREEBSD
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(freebsd_platform_headers)
|
||||
myhtopplatsources = $(freebsd_platform_sources)
|
||||
endif
|
||||
@ -240,7 +250,6 @@ dragonflybsd_platform_sources = \
|
||||
generic/uname.c
|
||||
|
||||
if HTOP_DRAGONFLYBSD
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(dragonflybsd_platform_headers)
|
||||
myhtopplatsources = $(dragonflybsd_platform_sources)
|
||||
endif
|
||||
@ -266,7 +275,6 @@ netbsd_platform_sources = \
|
||||
netbsd/NetBSDProcessList.c
|
||||
|
||||
if HTOP_NETBSD
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(netbsd_platform_headers)
|
||||
myhtopplatsources = $(netbsd_platform_sources)
|
||||
endif
|
||||
@ -292,7 +300,6 @@ openbsd_platform_sources = \
|
||||
openbsd/Platform.c
|
||||
|
||||
if HTOP_OPENBSD
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(openbsd_platform_headers)
|
||||
myhtopplatsources = $(openbsd_platform_sources)
|
||||
endif
|
||||
@ -304,6 +311,7 @@ darwin_platform_headers = \
|
||||
darwin/DarwinProcess.h \
|
||||
darwin/DarwinProcessList.h \
|
||||
darwin/Platform.h \
|
||||
darwin/PlatformHelpers.h \
|
||||
darwin/ProcessField.h \
|
||||
generic/gettime.h \
|
||||
generic/hostname.h \
|
||||
@ -315,6 +323,7 @@ darwin_platform_headers = \
|
||||
|
||||
darwin_platform_sources = \
|
||||
darwin/Platform.c \
|
||||
darwin/PlatformHelpers.c \
|
||||
darwin/DarwinProcess.c \
|
||||
darwin/DarwinProcessList.c \
|
||||
generic/gettime.c \
|
||||
@ -326,7 +335,6 @@ darwin_platform_sources = \
|
||||
|
||||
if HTOP_DARWIN
|
||||
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(darwin_platform_headers)
|
||||
myhtopplatsources = $(darwin_platform_sources)
|
||||
endif
|
||||
@ -357,7 +365,6 @@ solaris_platform_sources = \
|
||||
zfs/ZfsCompressedArcMeter.c
|
||||
|
||||
if HTOP_SOLARIS
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatheaders = $(solaris_platform_headers)
|
||||
myhtopplatsources = $(solaris_platform_sources)
|
||||
endif
|
||||
@ -393,10 +400,9 @@ pcp_platform_sources = \
|
||||
zfs/ZfsCompressedArcMeter.c
|
||||
|
||||
if HTOP_PCP
|
||||
myhtopplatprogram = pcp-htop
|
||||
myhtopplatheaders = $(pcp_platform_headers)
|
||||
myhtopplatsources = $(pcp_platform_sources)
|
||||
pcp_htop_SOURCES = $(myhtopplatprogram).c $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
|
||||
pcp_htop_SOURCES = $(myhtopplatprogram) $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
|
||||
endif
|
||||
|
||||
# Unsupported
|
||||
@ -416,15 +422,13 @@ unsupported_platform_sources = \
|
||||
unsupported/UnsupportedProcessList.c
|
||||
|
||||
if HTOP_UNSUPPORTED
|
||||
myhtopplatprogram = htop
|
||||
myhtopplatsources = $(unsupported_platform_sources)
|
||||
myhtopplatheaders = $(unsupported_platform_headers)
|
||||
endif
|
||||
|
||||
# ----
|
||||
|
||||
bin_PROGRAMS = $(myhtopplatprogram)
|
||||
htop_SOURCES = $(myhtopplatprogram).c $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
|
||||
htop_SOURCES = $(myhtopplatprogram) $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
|
||||
nodist_htop_SOURCES = config.h
|
||||
|
||||
target:
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - MemoryMeter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -36,7 +36,7 @@ static void MemoryMeter_updateValues(Meter* this) {
|
||||
/* Do not print available memory in bar mode */
|
||||
this->curItems = 4;
|
||||
|
||||
written = Meter_humanUnit(buffer, isnan(this->values[4]) ? this->values[0] : this->total - this->values[4], size);
|
||||
written = Meter_humanUnit(buffer, this->values[0], size);
|
||||
METER_BUFFER_CHECK(buffer, size, written);
|
||||
|
||||
METER_BUFFER_APPEND_CHR(buffer, size, '/');
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - MemoryMeter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - MemorySwapMeter.c
|
||||
(C) 2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -33,10 +33,14 @@ static void MemorySwapMeter_updateValues(Meter* this) {
|
||||
static void MemorySwapMeter_draw(Meter* this, int x, int y, int w) {
|
||||
MemorySwapMeterData* data = this->meterData;
|
||||
|
||||
/* Use the same width for each sub meter to align with CPU meter */
|
||||
const int colwidth = w / 2;
|
||||
const int diff = w - colwidth * 2;
|
||||
|
||||
assert(data->memoryMeter->draw);
|
||||
data->memoryMeter->draw(data->memoryMeter, x, y, w / 2);
|
||||
data->memoryMeter->draw(data->memoryMeter, x, y, colwidth);
|
||||
assert(data->swapMeter->draw);
|
||||
data->swapMeter->draw(data->swapMeter, x + w / 2, y, w - w / 2);
|
||||
data->swapMeter->draw(data->swapMeter, x + colwidth + diff, y, colwidth);
|
||||
}
|
||||
|
||||
static void MemorySwapMeter_init(Meter* this) {
|
||||
@ -91,6 +95,7 @@ const MeterClass MemorySwapMeter_class = {
|
||||
},
|
||||
.updateValues = MemorySwapMeter_updateValues,
|
||||
.defaultMode = CUSTOM_METERMODE,
|
||||
.isMultiColumn = true,
|
||||
.name = "MemorySwap",
|
||||
.uiName = "Memory & Swap",
|
||||
.description = "Combined memory and swap usage",
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - MemorySwapMeter.h
|
||||
(C) 2021 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
12
Meter.c
12
Meter.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Meter.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -155,7 +155,7 @@ ListItem* Meter_toListItem(const Meter* this, bool moving) {
|
||||
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
const char* caption = Meter_getCaption(this);
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
mvaddnstr(y, x, caption, w - 1);
|
||||
mvaddnstr(y, x, caption, w);
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
|
||||
int captionLen = strlen(caption);
|
||||
@ -166,7 +166,7 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
RichString_begin(out);
|
||||
Meter_displayBuffer(this, &out);
|
||||
RichString_printoffnVal(out, y, x, 0, w - 1);
|
||||
RichString_printoffnVal(out, y, x, 0, w);
|
||||
RichString_delete(&out);
|
||||
}
|
||||
|
||||
@ -176,7 +176,6 @@ static const char BarMeterMode_characters[] = "|#*@$%&.";
|
||||
|
||||
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
const char* caption = Meter_getCaption(this);
|
||||
w -= 2;
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
int captionLen = 3;
|
||||
mvaddnstr(y, x, caption, captionLen);
|
||||
@ -184,10 +183,11 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
w -= captionLen;
|
||||
attrset(CRT_colors[BAR_BORDER]);
|
||||
mvaddch(y, x, '[');
|
||||
w--;
|
||||
mvaddch(y, x + MAXIMUM(w, 0), ']');
|
||||
w--;
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
|
||||
w--;
|
||||
x++;
|
||||
|
||||
if (w < 1)
|
||||
@ -329,7 +329,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
data->values[nValues - 1] = value;
|
||||
}
|
||||
|
||||
int i = nValues - (w * 2) + 2, k = 0;
|
||||
int i = nValues - (w * 2), k = 0;
|
||||
if (i < 0) {
|
||||
k = -i / 2;
|
||||
i = 0;
|
||||
|
11
Meter.h
11
Meter.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Meter.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -73,6 +73,7 @@ typedef struct MeterClass_ {
|
||||
const char* const caption; /* prefix in the actual header */
|
||||
const char* const description; /* optional meter description in header setup menu */
|
||||
const uint8_t maxItems;
|
||||
const bool isMultiColumn; /* whether the meter draws multiple sub-columns (defaults to false) */
|
||||
} MeterClass;
|
||||
|
||||
#define As_Meter(this_) ((const MeterClass*)((this_)->super.klass))
|
||||
@ -92,6 +93,7 @@ typedef struct MeterClass_ {
|
||||
#define Meter_attributes(this_) As_Meter(this_)->attributes
|
||||
#define Meter_name(this_) As_Meter(this_)->name
|
||||
#define Meter_uiName(this_) As_Meter(this_)->uiName
|
||||
#define Meter_isMultiColumn(this_) As_Meter(this_)->isMultiColumn
|
||||
|
||||
typedef struct GraphData_ {
|
||||
struct timeval time;
|
||||
@ -132,6 +134,13 @@ typedef enum {
|
||||
LAST_METERMODE
|
||||
} MeterModeId;
|
||||
|
||||
typedef enum {
|
||||
RATESTATUS_DATA,
|
||||
RATESTATUS_INIT,
|
||||
RATESTATUS_NODATA,
|
||||
RATESTATUS_STALE
|
||||
} MeterRateStatus;
|
||||
|
||||
extern const MeterClass Meter_class;
|
||||
|
||||
Meter* Meter_new(const ProcessList* pl, unsigned int param, const MeterClass* type);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - MetersPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -184,6 +184,7 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
if (result == HANDLED || sideMove) {
|
||||
Header* header = this->scr->header;
|
||||
this->settings->changed = true;
|
||||
this->settings->lastUpdate++;
|
||||
Header_calculateHeight(header);
|
||||
ScreenManager_resize(this->scr);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - MetersPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "CRT.h"
|
||||
#include "Macros.h"
|
||||
#include "Meter.h"
|
||||
#include "Object.h"
|
||||
#include "Platform.h"
|
||||
#include "Process.h"
|
||||
@ -18,8 +19,7 @@ static const int NetworkIOMeter_attributes[] = {
|
||||
METER_VALUE_IOWRITE,
|
||||
};
|
||||
|
||||
static bool hasData = false;
|
||||
|
||||
static MeterRateStatus status = RATESTATUS_INIT;
|
||||
static uint32_t cached_rxb_diff;
|
||||
static uint32_t cached_rxp_diff;
|
||||
static uint32_t cached_txb_diff;
|
||||
@ -31,7 +31,7 @@ static void NetworkIOMeter_updateValues(Meter* this) {
|
||||
|
||||
uint64_t passedTimeInMs = pl->realtimeMs - cached_last_update;
|
||||
|
||||
/* update only every 500ms */
|
||||
/* update only every 500ms to have a sane span for rate calculation */
|
||||
if (passedTimeInMs > 500) {
|
||||
static uint64_t cached_rxb_total;
|
||||
static uint64_t cached_rxp_total;
|
||||
@ -39,11 +39,20 @@ static void NetworkIOMeter_updateValues(Meter* this) {
|
||||
static uint64_t cached_txp_total;
|
||||
uint64_t diff;
|
||||
|
||||
NetworkIOData data;
|
||||
if (!Platform_getNetworkIO(&data)) {
|
||||
status = RATESTATUS_NODATA;
|
||||
} else if (cached_last_update == 0) {
|
||||
status = RATESTATUS_INIT;
|
||||
} else if (passedTimeInMs > 30000) {
|
||||
status = RATESTATUS_STALE;
|
||||
} else {
|
||||
status = RATESTATUS_DATA;
|
||||
}
|
||||
|
||||
cached_last_update = pl->realtimeMs;
|
||||
|
||||
NetworkIOData data;
|
||||
hasData = Platform_getNetworkIO(&data);
|
||||
if (!hasData) {
|
||||
if (status == RATESTATUS_NODATA) {
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
|
||||
return;
|
||||
}
|
||||
@ -85,6 +94,15 @@ static void NetworkIOMeter_updateValues(Meter* this) {
|
||||
cached_txp_total = data.packetsTransmitted;
|
||||
}
|
||||
|
||||
if (status == RATESTATUS_INIT) {
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "init");
|
||||
return;
|
||||
}
|
||||
if (status == RATESTATUS_STALE) {
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "stale");
|
||||
return;
|
||||
}
|
||||
|
||||
this->values[0] = cached_rxb_diff;
|
||||
this->values[1] = cached_txb_diff;
|
||||
if (cached_rxb_diff + cached_txb_diff > this->total) {
|
||||
@ -98,9 +116,18 @@ static void NetworkIOMeter_updateValues(Meter* this) {
|
||||
}
|
||||
|
||||
static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
|
||||
if (!hasData) {
|
||||
switch (status) {
|
||||
case RATESTATUS_NODATA:
|
||||
RichString_writeAscii(out, CRT_colors[METER_VALUE_ERROR], "no data");
|
||||
return;
|
||||
case RATESTATUS_INIT:
|
||||
RichString_writeAscii(out, CRT_colors[METER_VALUE], "initializing...");
|
||||
return;
|
||||
case RATESTATUS_STALE:
|
||||
RichString_writeAscii(out, CRT_colors[METER_VALUE_WARN], "stale data");
|
||||
return;
|
||||
case RATESTATUS_DATA:
|
||||
break;
|
||||
}
|
||||
|
||||
char buffer[64];
|
||||
|
2
Object.c
2
Object.c
@ -2,7 +2,7 @@
|
||||
htop - Object.c
|
||||
(C) 2004-2012 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
2
Object.h
2
Object.h
@ -4,7 +4,7 @@
|
||||
htop - Object.h
|
||||
(C) 2004-2012 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - OpenFilesScreen.c
|
||||
(C) 2005-2006 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -9,13 +9,16 @@ in the source distribution for its full text.
|
||||
|
||||
#include "OpenFilesScreen.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "Macros.h"
|
||||
#include "Panel.h"
|
||||
@ -25,7 +28,7 @@ in the source distribution for its full text.
|
||||
|
||||
|
||||
typedef struct OpenFiles_Data_ {
|
||||
char* data[7];
|
||||
char* data[8];
|
||||
} OpenFiles_Data;
|
||||
|
||||
typedef struct OpenFiles_ProcessData_ {
|
||||
@ -55,6 +58,8 @@ static size_t getIndexForType(char type) {
|
||||
return 5;
|
||||
case 't':
|
||||
return 6;
|
||||
case 'o':
|
||||
return 7;
|
||||
}
|
||||
|
||||
/* should never reach here */
|
||||
@ -74,7 +79,7 @@ OpenFilesScreen* OpenFilesScreen_new(const Process* process) {
|
||||
} else {
|
||||
this->pid = process->pid;
|
||||
}
|
||||
return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " FD TYPE MODE DEVICE SIZE NODE NAME");
|
||||
return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " FD TYPE MODE DEVICE SIZE OFFSET NODE NAME");
|
||||
}
|
||||
|
||||
void OpenFilesScreen_delete(Object* this) {
|
||||
@ -115,13 +120,16 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
close(fdnull);
|
||||
char buffer[32] = {0};
|
||||
xSnprintf(buffer, sizeof(buffer), "%d", pid);
|
||||
execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL);
|
||||
// Use of NULL in variadic functions must have a pointer cast.
|
||||
// The NULL constant is not required by standard to have a pointer type.
|
||||
execlp("lsof", "lsof", "-P", "-o", "-p", buffer, "-F", (char *)NULL);
|
||||
exit(127);
|
||||
}
|
||||
close(fdpair[1]);
|
||||
|
||||
OpenFiles_Data* item = &(pdata->data);
|
||||
OpenFiles_FileData* fdata = NULL;
|
||||
bool lsofIncludesFileSize = false;
|
||||
|
||||
FILE* fd = fdopen(fdpair[0], "r");
|
||||
if (!fd) {
|
||||
@ -155,8 +163,17 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
case 't': /* file's type */
|
||||
{
|
||||
size_t index = getIndexForType(cmd);
|
||||
free(item->data[index]);
|
||||
item->data[index] = xStrdup(line + 1);
|
||||
free_and_xStrdup(&item->data[index], line + 1);
|
||||
break;
|
||||
}
|
||||
case 'o': /* file's offset */
|
||||
{
|
||||
size_t index = getIndexForType(cmd);
|
||||
if (String_startsWith(line + 1, "0t")) {
|
||||
free_and_xStrdup(&item->data[index], line + 3);
|
||||
} else {
|
||||
free_and_xStrdup(&item->data[index], line + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'c': /* process command name */
|
||||
@ -166,7 +183,6 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
case 'k': /* link count */
|
||||
case 'l': /* file's lock status */
|
||||
case 'L': /* process login name */
|
||||
case 'o': /* file's offset */
|
||||
case 'p': /* process ID */
|
||||
case 'P': /* protocol name */
|
||||
case 'R': /* parent process ID */
|
||||
@ -175,12 +191,17 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
/* ignore */
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd == 's')
|
||||
lsofIncludesFileSize = true;
|
||||
|
||||
free(line);
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
int wstatus;
|
||||
if (waitpid(child, &wstatus, 0) == -1) {
|
||||
while (waitpid(child, &wstatus, 0) == -1)
|
||||
if (errno != EINTR) {
|
||||
pdata->error = 1;
|
||||
return pdata;
|
||||
}
|
||||
@ -191,6 +212,25 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
pdata->error = WEXITSTATUS(wstatus);
|
||||
}
|
||||
|
||||
/* We got all information we need; no post-processing needed */
|
||||
if (lsofIncludesFileSize)
|
||||
return pdata;
|
||||
|
||||
/* On linux, `lsof -o -F` omits SIZE, so add it back. */
|
||||
/* On macOS, `lsof -o -F` includes SIZE, so this block isn't needed. If no open files have a filesize, this will still run, unfortunately. */
|
||||
size_t fileSizeIndex = getIndexForType('s');
|
||||
for (fdata = pdata->files; fdata != NULL; fdata = fdata->next) {
|
||||
item = &fdata->data;
|
||||
const char* filename = getDataForType(item, 'n');
|
||||
|
||||
struct stat st;
|
||||
if (stat(filename, &st) == 0) {
|
||||
char fileSizeBuf[21]; /* 20 (long long) + 1 (NULL) */
|
||||
xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, st.st_size); /* st.st_size is long long on macOS, long on linux */
|
||||
free_and_xStrdup(&item->data[fileSizeIndex], fileSizeBuf);
|
||||
}
|
||||
}
|
||||
|
||||
return pdata;
|
||||
}
|
||||
|
||||
@ -213,14 +253,15 @@ static void OpenFilesScreen_scan(InfoScreen* this) {
|
||||
while (fdata) {
|
||||
OpenFiles_Data* data = &fdata->data;
|
||||
size_t lenN = strlen(getDataForType(data, 'n'));
|
||||
size_t sizeEntry = 5 + 7 + 4 + 10 + 10 + 10 + lenN + 7 /*spaces*/ + 1 /*null*/;
|
||||
size_t sizeEntry = 5 + 7 + 4 + 10 + 10 + 10 + 10 + lenN + 8 /*spaces*/ + 1 /*null*/;
|
||||
char entry[sizeEntry];
|
||||
xSnprintf(entry, sizeof(entry), "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %s",
|
||||
xSnprintf(entry, sizeof(entry), "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %10.10s %s",
|
||||
getDataForType(data, 'f'),
|
||||
getDataForType(data, 't'),
|
||||
getDataForType(data, 'a'),
|
||||
getDataForType(data, 'D'),
|
||||
getDataForType(data, 's'),
|
||||
getDataForType(data, 'o'),
|
||||
getDataForType(data, 'i'),
|
||||
getDataForType(data, 'n'));
|
||||
InfoScreen_addLine(this, entry);
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - OpenFilesScreen.h
|
||||
(C) 2005-2006 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
26
OptionItem.c
26
OptionItem.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - OptionItem.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -25,6 +25,13 @@ static void OptionItem_delete(Object* cast) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
static void TextItem_display(const Object* cast, RichString* out) {
|
||||
const TextItem* this = (const TextItem*)cast;
|
||||
assert (this != NULL);
|
||||
|
||||
RichString_appendWide(out, CRT_colors[HELP_BOLD], this->super.text);
|
||||
}
|
||||
|
||||
static void CheckItem_display(const Object* cast, RichString* out) {
|
||||
const CheckItem* this = (const CheckItem*)cast;
|
||||
assert (this != NULL);
|
||||
@ -68,6 +75,16 @@ const OptionItemClass OptionItem_class = {
|
||||
}
|
||||
};
|
||||
|
||||
const OptionItemClass TextItem_class = {
|
||||
.super = {
|
||||
.extends = Class(OptionItem),
|
||||
.delete = OptionItem_delete,
|
||||
.display = TextItem_display
|
||||
},
|
||||
.kind = OPTION_ITEM_TEXT
|
||||
};
|
||||
|
||||
|
||||
const OptionItemClass CheckItem_class = {
|
||||
.super = {
|
||||
.extends = Class(OptionItem),
|
||||
@ -77,6 +94,7 @@ const OptionItemClass CheckItem_class = {
|
||||
.kind = OPTION_ITEM_CHECK
|
||||
};
|
||||
|
||||
|
||||
const OptionItemClass NumberItem_class = {
|
||||
.super = {
|
||||
.extends = Class(OptionItem),
|
||||
@ -86,6 +104,12 @@ const OptionItemClass NumberItem_class = {
|
||||
.kind = OPTION_ITEM_NUMBER
|
||||
};
|
||||
|
||||
TextItem* TextItem_new(const char* text) {
|
||||
TextItem* this = AllocThis(TextItem);
|
||||
this->super.text = xStrdup(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
CheckItem* CheckItem_newByRef(const char* text, bool* ref) {
|
||||
CheckItem* this = AllocThis(CheckItem);
|
||||
this->super.text = xStrdup(text);
|
||||
|
12
OptionItem.h
12
OptionItem.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - OptionItem.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -13,6 +13,7 @@ in the source distribution for its full text.
|
||||
|
||||
|
||||
enum OptionItemType {
|
||||
OPTION_ITEM_TEXT,
|
||||
OPTION_ITEM_CHECK,
|
||||
OPTION_ITEM_NUMBER,
|
||||
};
|
||||
@ -32,6 +33,12 @@ typedef struct OptionItem_ {
|
||||
char* text;
|
||||
} OptionItem;
|
||||
|
||||
typedef struct TextItem_ {
|
||||
OptionItem super;
|
||||
|
||||
char* text;
|
||||
} TextItem;
|
||||
|
||||
typedef struct CheckItem_ {
|
||||
OptionItem super;
|
||||
|
||||
@ -51,9 +58,12 @@ typedef struct NumberItem_ {
|
||||
} NumberItem;
|
||||
|
||||
extern const OptionItemClass OptionItem_class;
|
||||
extern const OptionItemClass TextItem_class;
|
||||
extern const OptionItemClass CheckItem_class;
|
||||
extern const OptionItemClass NumberItem_class;
|
||||
|
||||
TextItem* TextItem_new(const char* text);
|
||||
|
||||
CheckItem* CheckItem_newByRef(const char* text, bool* ref);
|
||||
CheckItem* CheckItem_newByVal(const char* text, bool value);
|
||||
bool CheckItem_get(const CheckItem* this);
|
||||
|
28
Panel.c
28
Panel.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Panel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -49,6 +49,8 @@ void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type
|
||||
this->y = y;
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->cursorX = 0;
|
||||
this->cursorY = 0;
|
||||
this->eventHandlerState = NULL;
|
||||
this->items = Vector_new(type, owner, DEFAULT_SIZE);
|
||||
this->scrollV = 0;
|
||||
@ -57,6 +59,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type
|
||||
this->oldSelected = 0;
|
||||
this->selectedLen = 0;
|
||||
this->needsRedraw = true;
|
||||
this->cursorOn = false;
|
||||
this->wasFocus = false;
|
||||
RichString_beginAllocated(this->header);
|
||||
this->defaultBar = fuBar;
|
||||
@ -72,6 +75,11 @@ void Panel_done(Panel* this) {
|
||||
RichString_delete(&this->header);
|
||||
}
|
||||
|
||||
void Panel_setCursorToSelection(Panel* this) {
|
||||
this->cursorY = this->y + this->selected - this->scrollV + 1;
|
||||
this->cursorX = this->x + this->selectedLen - this->scrollH;
|
||||
}
|
||||
|
||||
void Panel_setSelectionColor(Panel* this, ColorElements colorId) {
|
||||
this->selectionColorId = colorId;
|
||||
}
|
||||
@ -330,7 +338,6 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
|
||||
this->oldSelected = this->selected;
|
||||
this->wasFocus = focus;
|
||||
this->needsRedraw = false;
|
||||
move(0, 0);
|
||||
}
|
||||
|
||||
static int Panel_headerHeight(const Panel* this) {
|
||||
@ -453,7 +460,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
||||
}
|
||||
|
||||
if (len < 99) {
|
||||
buffer[len] = ch;
|
||||
buffer[len] = (char) ch;
|
||||
buffer[len + 1] = '\0';
|
||||
}
|
||||
|
||||
@ -470,7 +477,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
||||
|
||||
// if current word did not match,
|
||||
// retry considering the character the start of a new word.
|
||||
buffer[0] = ch;
|
||||
buffer[0] = (char) ch;
|
||||
buffer[1] = '\0';
|
||||
}
|
||||
|
||||
@ -485,3 +492,16 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
||||
|
||||
return IGNORED;
|
||||
}
|
||||
|
||||
int Panel_getCh(Panel* this) {
|
||||
if (this->cursorOn) {
|
||||
move(this->cursorY, this->cursorX);
|
||||
curs_set(1);
|
||||
} else {
|
||||
curs_set(0);
|
||||
}
|
||||
#ifdef HAVE_SET_ESCDELAY
|
||||
set_escdelay(25);
|
||||
#endif
|
||||
return getch();
|
||||
}
|
||||
|
14
Panel.h
14
Panel.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Panel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -39,6 +39,10 @@ typedef enum HandlerResult_ {
|
||||
#define EVENT_IS_HEADER_CLICK(ev_) ((ev_) >= -10000 && (ev_) <= -9000)
|
||||
#define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000)
|
||||
|
||||
#define EVENT_SCREEN_TAB_CLICK(x_) (-20000 + (x_))
|
||||
#define EVENT_IS_SCREEN_TAB_CLICK(ev_) ((ev_) >= -20000 && (ev_) < -10000)
|
||||
#define EVENT_SCREEN_TAB_GET_X(ev_) ((ev_) + 20000)
|
||||
|
||||
typedef HandlerResult (*Panel_EventHandler)(Panel*, int);
|
||||
typedef void (*Panel_DrawFunctionBar)(Panel*, bool);
|
||||
typedef void (*Panel_PrintHeader)(Panel*);
|
||||
@ -61,14 +65,16 @@ typedef struct PanelClass_ {
|
||||
struct Panel_ {
|
||||
Object super;
|
||||
int x, y, w, h;
|
||||
int cursorX, cursorY;
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
int scrollH;
|
||||
bool needsRedraw;
|
||||
bool cursorOn;
|
||||
bool wasFocus;
|
||||
FunctionBar* currentBar;
|
||||
FunctionBar* defaultBar;
|
||||
@ -90,6 +96,8 @@ void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type
|
||||
|
||||
void Panel_done(Panel* this);
|
||||
|
||||
void Panel_setCursorToSelection(Panel* this);
|
||||
|
||||
void Panel_setSelectionColor(Panel* this, ColorElements colorId);
|
||||
|
||||
void Panel_setHeader(Panel* this, const char* header);
|
||||
@ -130,4 +138,6 @@ bool Panel_onKey(Panel* this, int key);
|
||||
|
||||
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
||||
|
||||
int Panel_getCh(Panel* this);
|
||||
|
||||
#endif
|
||||
|
302
Process.c
302
Process.c
@ -2,7 +2,7 @@
|
||||
htop - Process.c
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -41,17 +41,33 @@ static const char* const kthreadID = "KTHREAD";
|
||||
|
||||
static uid_t Process_getuid = (uid_t)-1;
|
||||
|
||||
int Process_pidDigits = 7;
|
||||
int Process_pidDigits = PROCESS_MIN_PID_DIGITS;
|
||||
int Process_uidDigits = PROCESS_MIN_UID_DIGITS;
|
||||
|
||||
void Process_setupColumnWidths() {
|
||||
int maxPid = Platform_getMaxPid();
|
||||
if (maxPid == -1)
|
||||
return;
|
||||
|
||||
Process_pidDigits = ceil(log10(maxPid));
|
||||
if (maxPid < (int)pow(10, PROCESS_MIN_PID_DIGITS)) {
|
||||
Process_pidDigits = PROCESS_MIN_PID_DIGITS;
|
||||
return;
|
||||
}
|
||||
|
||||
Process_pidDigits = (int)log10(maxPid) + 1;
|
||||
assert(Process_pidDigits <= PROCESS_MAX_PID_DIGITS);
|
||||
}
|
||||
|
||||
void Process_setUidColumnWidth(uid_t maxUid) {
|
||||
if (maxUid < (uid_t)pow(10, PROCESS_MIN_UID_DIGITS)) {
|
||||
Process_uidDigits = PROCESS_MIN_UID_DIGITS;
|
||||
return;
|
||||
}
|
||||
|
||||
Process_uidDigits = (int)log10(maxUid) + 1;
|
||||
assert(Process_uidDigits <= PROCESS_MAX_UID_DIGITS);
|
||||
}
|
||||
|
||||
void Process_printBytes(RichString* str, unsigned long long number, bool coloring) {
|
||||
char buffer[16];
|
||||
int len;
|
||||
@ -195,7 +211,12 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths, bool
|
||||
int years = days / 365;
|
||||
int daysLeft = days - 365 * years;
|
||||
|
||||
if (daysLeft >= 100) {
|
||||
if (years >= 10000000) {
|
||||
RichString_appendnAscii(str, yearColor, "eternity ", 9);
|
||||
} else if (years >= 1000) {
|
||||
len = xSnprintf(buffer, sizeof(buffer), "%7dy ", years);
|
||||
RichString_appendnAscii(str, yearColor, buffer, len);
|
||||
} else if (daysLeft >= 100) {
|
||||
len = xSnprintf(buffer, sizeof(buffer), "%3dy", years);
|
||||
RichString_appendnAscii(str, yearColor, buffer, len);
|
||||
len = xSnprintf(buffer, sizeof(buffer), "%3dd ", daysLeft);
|
||||
@ -381,7 +402,7 @@ static inline char* stpcpyWithNewlineConversion(char* dstStr, const char* srcStr
|
||||
* This function makes the merged Command string. It also stores the offsets of the
|
||||
* basename, comm w.r.t the merged Command string - these offsets will be used by
|
||||
* Process_writeCommand() for coloring. The merged Command string is also
|
||||
* returned by Process_getCommandStr() for searching, sorting and filtering.
|
||||
* returned by Process_getCommand() for searching, sorting and filtering.
|
||||
*/
|
||||
void Process_makeCommandStr(Process* this) {
|
||||
ProcessMergedCommand* mc = &this->mergedCommand;
|
||||
@ -393,60 +414,37 @@ void Process_makeCommandStr(Process* this) {
|
||||
bool stripExeFromCmdline = settings->stripExeFromCmdline;
|
||||
bool showThreadNames = settings->showThreadNames;
|
||||
|
||||
uint64_t settingsStamp = settings->lastUpdate;
|
||||
|
||||
/* Nothing to do to (Re)Generate the Command string, if the process is:
|
||||
* - a kernel thread, or
|
||||
* - a zombie from before being under htop's watch, or
|
||||
* - a user thread and showThreadNames is not set */
|
||||
if (Process_isKernelThread(this))
|
||||
return;
|
||||
if (this->state == 'Z' && !this->mergedCommand.str)
|
||||
return;
|
||||
if (Process_isUserlandThread(this) && settings->showThreadNames && (showThreadNames == mc->prevShowThreadNames))
|
||||
if (this->state == ZOMBIE && !this->mergedCommand.str)
|
||||
return;
|
||||
|
||||
/* this->mergedCommand.str needs updating only if its state or contents changed.
|
||||
* Its content is based on the fields cmdline, comm, and exe. */
|
||||
if (
|
||||
mc->prevMergeSet == showMergedCommand &&
|
||||
mc->prevPathSet == showProgramPath &&
|
||||
mc->prevCommSet == searchCommInCmdline &&
|
||||
mc->prevCmdlineSet == stripExeFromCmdline &&
|
||||
mc->prevShowThreadNames == showThreadNames &&
|
||||
!mc->cmdlineChanged &&
|
||||
!mc->commChanged &&
|
||||
!mc->exeChanged
|
||||
) {
|
||||
if (mc->lastUpdate >= settingsStamp)
|
||||
return;
|
||||
}
|
||||
|
||||
mc->lastUpdate = settingsStamp;
|
||||
|
||||
/* The field separtor "│" has been chosen such that it will not match any
|
||||
* valid string used for searching or filtering */
|
||||
const char* SEPARATOR = CRT_treeStr[TREE_STR_VERT];
|
||||
const int SEPARATOR_LEN = strlen(SEPARATOR);
|
||||
|
||||
/* Check for any changed fields since we last built this string */
|
||||
if (mc->cmdlineChanged || mc->commChanged || mc->exeChanged) {
|
||||
free(mc->str);
|
||||
/* Accommodate the column text, two field separators and terminating NUL */
|
||||
size_t maxLen = 2 * SEPARATOR_LEN + 1;
|
||||
maxLen += this->cmdline ? strlen(this->cmdline) : strlen("(zombie)");
|
||||
maxLen += this->procComm ? strlen(this->procComm) : 0;
|
||||
maxLen += this->procExe ? strlen(this->procExe) : 0;
|
||||
|
||||
free(mc->str);
|
||||
mc->str = xCalloc(1, maxLen);
|
||||
}
|
||||
|
||||
/* Preserve the settings used in this run */
|
||||
mc->prevMergeSet = showMergedCommand;
|
||||
mc->prevPathSet = showProgramPath;
|
||||
mc->prevCommSet = searchCommInCmdline;
|
||||
mc->prevCmdlineSet = stripExeFromCmdline;
|
||||
mc->prevShowThreadNames = showThreadNames;
|
||||
|
||||
/* Mark everything as unchanged */
|
||||
mc->cmdlineChanged = false;
|
||||
mc->commChanged = false;
|
||||
mc->exeChanged = false;
|
||||
|
||||
/* Reset all locations that need extra handling when actually displaying */
|
||||
mc->highlightCount = 0;
|
||||
@ -500,17 +498,26 @@ void Process_makeCommandStr(Process* this) {
|
||||
assert(cmdlineBasenameStart <= (int)strlen(cmdline));
|
||||
|
||||
if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */
|
||||
if (showMergedCommand && (!Process_isUserlandThread(this) || showThreadNames) && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
|
||||
if ((showMergedCommand || (Process_isUserlandThread(this) && showThreadNames)) && procComm && strlen(procComm)) { /* set column to or prefix it with comm */
|
||||
if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
|
||||
WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
|
||||
str = stpcpy(str, procComm);
|
||||
|
||||
if(!showMergedCommand)
|
||||
return;
|
||||
|
||||
WRITE_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdlineBasenameEnd > cmdlineBasenameStart)
|
||||
WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME);
|
||||
|
||||
if (this->procExeDeleted)
|
||||
WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, delExeAttr, CMDLINE_HIGHLIGHT_FLAG_DELETED);
|
||||
else if (this->usesDeletedLib)
|
||||
WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, delLibAttr, CMDLINE_HIGHLIGHT_FLAG_DELETED);
|
||||
|
||||
(void)stpcpyWithNewlineConversion(str, cmdline + (showProgramPath ? 0 : cmdlineBasenameStart));
|
||||
|
||||
return;
|
||||
@ -571,11 +578,15 @@ void Process_makeCommandStr(Process* this) {
|
||||
}
|
||||
|
||||
if (matchLen) {
|
||||
if (stripExeFromCmdline) {
|
||||
/* strip the matched exe prefix */
|
||||
cmdline += matchLen;
|
||||
|
||||
commStart -= matchLen;
|
||||
commEnd -= matchLen;
|
||||
} else {
|
||||
matchLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchLen || (haveCommField && *cmdline)) {
|
||||
@ -707,6 +718,50 @@ void Process_printLeftAlignedField(RichString* str, int attr, const char* conten
|
||||
RichString_appendChr(str, attr, ' ', width + 1 - columns);
|
||||
}
|
||||
|
||||
void Process_printPercentage(float val, char* buffer, int n, uint8_t width, int* attr) {
|
||||
if (val >= 0) {
|
||||
if (val < 0.05F)
|
||||
*attr = CRT_colors[PROCESS_SHADOW];
|
||||
else if (val >= 99.9F)
|
||||
*attr = CRT_colors[PROCESS_MEGABYTES];
|
||||
|
||||
int precision = 1;
|
||||
|
||||
// Display "val" as "100" for columns like "MEM%".
|
||||
if (width == 4 && val > 99.9F) {
|
||||
precision = 0;
|
||||
val = 100.0F;
|
||||
}
|
||||
|
||||
xSnprintf(buffer, n, "%*.*f ", width, precision, val);
|
||||
} else {
|
||||
*attr = CRT_colors[PROCESS_SHADOW];
|
||||
xSnprintf(buffer, n, "%*.*s ", width, width, "N/A");
|
||||
}
|
||||
}
|
||||
|
||||
static inline char processStateChar(ProcessState state) {
|
||||
switch (state) {
|
||||
case UNKNOWN: return '?';
|
||||
case RUNNABLE: return 'U';
|
||||
case RUNNING: return 'R';
|
||||
case QUEUED: return 'Q';
|
||||
case WAITING: return 'W';
|
||||
case UNINTERRUPTIBLE_WAIT: return 'D';
|
||||
case BLOCKED: return 'B';
|
||||
case PAGING: return 'P';
|
||||
case STOPPED: return 'T';
|
||||
case TRACED: return 't';
|
||||
case ZOMBIE: return 'Z';
|
||||
case DEFUNCT: return 'X';
|
||||
case IDLE: return 'I';
|
||||
case SLEEPING: return 'S';
|
||||
default:
|
||||
assert(0);
|
||||
return '!';
|
||||
}
|
||||
}
|
||||
|
||||
void Process_writeField(const Process* this, RichString* str, ProcessField field) {
|
||||
char buffer[256];
|
||||
size_t n = sizeof(buffer);
|
||||
@ -720,7 +775,8 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
attr = CRT_colors[PROCESS_THREAD];
|
||||
baseattr = CRT_colors[PROCESS_THREAD_BASENAME];
|
||||
}
|
||||
if (!this->settings->treeView || this->indent == 0) {
|
||||
const ScreenSettings* ss = this->settings->ss;
|
||||
if (!ss->treeView || this->indent == 0) {
|
||||
Process_writeCommand(this, attr, baseattr, str);
|
||||
return;
|
||||
}
|
||||
@ -804,7 +860,15 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
Process_printLeftAlignedField(str, attr, cwd, 25);
|
||||
return;
|
||||
}
|
||||
case ELAPSED: Process_printTime(str, /* convert to hundreds of a second */ this->processList->realtimeMs / 10 - 100 * this->starttime_ctime, coloring); return;
|
||||
case ELAPSED: {
|
||||
const uint64_t rt = this->processList->realtimeMs;
|
||||
const uint64_t st = this->starttime_ctime * 1000;
|
||||
const uint64_t dt =
|
||||
rt < st ? 0 :
|
||||
rt - st;
|
||||
Process_printTime(str, /* convert to hundreds of a second */ dt / 10, coloring);
|
||||
return;
|
||||
}
|
||||
case MAJFLT: Process_printCount(str, this->majflt, coloring); return;
|
||||
case MINFLT: Process_printCount(str, this->minflt, coloring); return;
|
||||
case M_RESIDENT: Process_printKBytes(str, this->m_resident, coloring); return;
|
||||
@ -821,34 +885,13 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
|
||||
xSnprintf(buffer, n, "%4ld ", this->nlwp);
|
||||
break;
|
||||
case PERCENT_CPU:
|
||||
case PERCENT_CPU: Process_printPercentage(this->percent_cpu, buffer, n, Process_fieldWidths[PERCENT_CPU], &attr); break;
|
||||
case PERCENT_NORM_CPU: {
|
||||
float cpuPercentage = this->percent_cpu;
|
||||
if (field == PERCENT_NORM_CPU) {
|
||||
cpuPercentage /= this->processList->activeCPUs;
|
||||
}
|
||||
if (cpuPercentage > 999.9F) {
|
||||
xSnprintf(buffer, n, "%4u ", (unsigned int)cpuPercentage);
|
||||
} else if (cpuPercentage > 99.9F) {
|
||||
xSnprintf(buffer, n, "%3u. ", (unsigned int)cpuPercentage);
|
||||
} else {
|
||||
if (cpuPercentage < 0.05F)
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
|
||||
xSnprintf(buffer, n, "%4.1f ", cpuPercentage);
|
||||
}
|
||||
float cpuPercentage = this->percent_cpu / this->processList->activeCPUs;
|
||||
Process_printPercentage(cpuPercentage, buffer, n, Process_fieldWidths[PERCENT_CPU], &attr);
|
||||
break;
|
||||
}
|
||||
case PERCENT_MEM:
|
||||
if (this->percent_mem > 99.9F) {
|
||||
xSnprintf(buffer, n, "100. ");
|
||||
} else {
|
||||
if (this->percent_mem < 0.05F)
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
|
||||
xSnprintf(buffer, n, "%4.1f ", this->percent_mem);
|
||||
}
|
||||
break;
|
||||
case PERCENT_MEM: Process_printPercentage(this->percent_mem, buffer, n, 4, &attr); break;
|
||||
case PGRP: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->pgrp); break;
|
||||
case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->pid); break;
|
||||
case PPID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->ppid); break;
|
||||
@ -862,21 +905,35 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
case SESSION: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->session); break;
|
||||
case STARTTIME: xSnprintf(buffer, n, "%s", this->starttime_show); break;
|
||||
case STATE:
|
||||
xSnprintf(buffer, n, "%c ", this->state);
|
||||
xSnprintf(buffer, n, "%c ", processStateChar(this->state));
|
||||
switch (this->state) {
|
||||
case 'R':
|
||||
attr = CRT_colors[PROCESS_R_STATE];
|
||||
case RUNNABLE:
|
||||
case RUNNING:
|
||||
case TRACED:
|
||||
attr = CRT_colors[PROCESS_RUN_STATE];
|
||||
break;
|
||||
case 'D':
|
||||
|
||||
case BLOCKED:
|
||||
case DEFUNCT:
|
||||
case STOPPED:
|
||||
case UNINTERRUPTIBLE_WAIT:
|
||||
case ZOMBIE:
|
||||
attr = CRT_colors[PROCESS_D_STATE];
|
||||
break;
|
||||
case 'I':
|
||||
case 'S':
|
||||
|
||||
case QUEUED:
|
||||
case WAITING:
|
||||
case IDLE:
|
||||
case SLEEPING:
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
break;
|
||||
|
||||
case UNKNOWN:
|
||||
case PAGING:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break;
|
||||
case ST_UID: xSnprintf(buffer, n, "%*d ", Process_uidDigits, this->st_uid); break;
|
||||
case TIME: Process_printTime(str, this->time, coloring); return;
|
||||
case TGID:
|
||||
if (this->tgid == this->pid)
|
||||
@ -899,11 +956,11 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
|
||||
if (this->user) {
|
||||
Process_printLeftAlignedField(str, attr, this->user, 9);
|
||||
Process_printLeftAlignedField(str, attr, this->user, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
xSnprintf(buffer, n, "%-9d ", this->st_uid);
|
||||
xSnprintf(buffer, n, "%-10d ", this->st_uid);
|
||||
break;
|
||||
default:
|
||||
if (DynamicColumn_writeField(this, str, field))
|
||||
@ -917,7 +974,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
|
||||
void Process_display(const Object* cast, RichString* out) {
|
||||
const Process* this = (const Process*) cast;
|
||||
const ProcessField* fields = this->settings->fields;
|
||||
const ProcessField* fields = this->settings->ss->fields;
|
||||
for (int i = 0; fields[i]; i++)
|
||||
As_Process(this)->writeField(this, out, fields[i]);
|
||||
|
||||
@ -953,7 +1010,7 @@ void Process_done(Process* this) {
|
||||
/* This function returns the string displayed in Command column, so that sorting
|
||||
* happens on what is displayed - whether comm, full path, basename, etc.. So
|
||||
* this follows Process_writeField(COMM) and Process_writeCommand */
|
||||
const char* Process_getCommandStr(const Process* this) {
|
||||
const char* Process_getCommand(const Process* this) {
|
||||
if ((Process_isUserlandThread(this) && this->settings->showThreadNames) || !this->mergedCommand.str) {
|
||||
return this->cmdline;
|
||||
}
|
||||
@ -969,7 +1026,6 @@ const ProcessClass Process_class = {
|
||||
.compare = Process_compare
|
||||
},
|
||||
.writeField = Process_writeField,
|
||||
.getCommandStr = Process_getCommandStr,
|
||||
};
|
||||
|
||||
void Process_init(Process* this, const Settings* settings) {
|
||||
@ -1023,20 +1079,14 @@ bool Process_sendSignal(Process* this, Arg sgn) {
|
||||
return kill(this->pid, sgn.i) == 0;
|
||||
}
|
||||
|
||||
int Process_pidCompare(const void* v1, const void* v2) {
|
||||
const Process* p1 = (const Process*)v1;
|
||||
const Process* p2 = (const Process*)v2;
|
||||
|
||||
return SPACESHIP_NUMBER(p1->pid, p2->pid);
|
||||
}
|
||||
|
||||
int Process_compare(const void* v1, const void* v2) {
|
||||
const Process* p1 = (const Process*)v1;
|
||||
const Process* p2 = (const Process*)v2;
|
||||
|
||||
const Settings* settings = p1->settings;
|
||||
const ScreenSettings* ss = settings->ss;
|
||||
|
||||
ProcessField key = Settings_getActiveSortKey(settings);
|
||||
ProcessField key = ScreenSettings_getActiveSortKey(ss);
|
||||
|
||||
int result = Process_compareByKey(p1, p2, key);
|
||||
|
||||
@ -1044,45 +1094,7 @@ int Process_compare(const void* v1, const void* v2) {
|
||||
if (!result)
|
||||
return SPACESHIP_NUMBER(p1->pid, p2->pid);
|
||||
|
||||
return (Settings_getActiveDirection(settings) == 1) ? result : -result;
|
||||
}
|
||||
|
||||
static uint8_t stateCompareValue(char state) {
|
||||
switch (state) {
|
||||
|
||||
case 'S':
|
||||
return 10;
|
||||
|
||||
case 'I':
|
||||
return 9;
|
||||
|
||||
case 'X':
|
||||
return 8;
|
||||
|
||||
case 'Z':
|
||||
return 7;
|
||||
|
||||
case 't':
|
||||
return 6;
|
||||
|
||||
case 'T':
|
||||
return 5;
|
||||
|
||||
case 'L':
|
||||
return 4;
|
||||
|
||||
case 'D':
|
||||
return 3;
|
||||
|
||||
case 'R':
|
||||
return 2;
|
||||
|
||||
case '?':
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return (ScreenSettings_getActiveDirection(ss) == 1) ? result : -result;
|
||||
}
|
||||
|
||||
int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key) {
|
||||
@ -1139,7 +1151,7 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
|
||||
r = SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime);
|
||||
return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid);
|
||||
case STATE:
|
||||
return SPACESHIP_NUMBER(stateCompareValue(p1->state), stateCompareValue(p2->state));
|
||||
return SPACESHIP_NUMBER(p1->state, p2->state);
|
||||
case ST_UID:
|
||||
return SPACESHIP_NUMBER(p1->st_uid, p2->st_uid);
|
||||
case TIME:
|
||||
@ -1154,6 +1166,7 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
|
||||
case USER:
|
||||
return SPACESHIP_NULLSTR(p1->user, p2->user);
|
||||
default:
|
||||
CRT_debug("Process_compareByKey_Base() called with key %d", key);
|
||||
assert(0 && "Process_compareByKey_Base: default key reached"); /* should never be reached */
|
||||
return SPACESHIP_NUMBER(p1->pid, p2->pid);
|
||||
}
|
||||
@ -1168,7 +1181,8 @@ void Process_updateComm(Process* this, const char* comm) {
|
||||
|
||||
free(this->procComm);
|
||||
this->procComm = comm ? xStrdup(comm) : NULL;
|
||||
this->mergedCommand.commChanged = true;
|
||||
|
||||
this->mergedCommand.lastUpdate = 0;
|
||||
}
|
||||
|
||||
static int skipPotentialPath(const char* cmdline, int end) {
|
||||
@ -1208,7 +1222,8 @@ void Process_updateCmdline(Process* this, const char* cmdline, int basenameStart
|
||||
this->cmdline = cmdline ? xStrdup(cmdline) : NULL;
|
||||
this->cmdlineBasenameStart = (basenameStart || !cmdline) ? basenameStart : skipPotentialPath(cmdline, basenameEnd);
|
||||
this->cmdlineBasenameEnd = basenameEnd;
|
||||
this->mergedCommand.cmdlineChanged = true;
|
||||
|
||||
this->mergedCommand.lastUpdate = 0;
|
||||
}
|
||||
|
||||
void Process_updateExe(Process* this, const char* exe) {
|
||||
@ -1227,5 +1242,40 @@ void Process_updateExe(Process* this, const char* exe) {
|
||||
this->procExe = NULL;
|
||||
this->procExeBasenameOffset = 0;
|
||||
}
|
||||
this->mergedCommand.exeChanged = true;
|
||||
|
||||
this->mergedCommand.lastUpdate = 0;
|
||||
}
|
||||
|
||||
uint8_t Process_fieldWidths[LAST_PROCESSFIELD] = { 0 };
|
||||
|
||||
void Process_resetFieldWidths() {
|
||||
for (size_t i = 0; i < LAST_PROCESSFIELD; i++) {
|
||||
if (!Process_fields[i].autoWidth)
|
||||
continue;
|
||||
|
||||
size_t len = strlen(Process_fields[i].title);
|
||||
assert(len <= UINT8_MAX);
|
||||
Process_fieldWidths[i] = (uint8_t)len;
|
||||
}
|
||||
}
|
||||
|
||||
void Process_updateFieldWidth(ProcessField key, size_t width) {
|
||||
if (width > UINT8_MAX)
|
||||
Process_fieldWidths[key] = UINT8_MAX;
|
||||
else if (width > Process_fieldWidths[key])
|
||||
Process_fieldWidths[key] = (uint8_t)width;
|
||||
}
|
||||
|
||||
void Process_updateCPUFieldWidths(float percentage) {
|
||||
if (percentage < 99.9F) {
|
||||
Process_updateFieldWidth(PERCENT_CPU, 4);
|
||||
Process_updateFieldWidth(PERCENT_NORM_CPU, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add additional two characters, one for "." and another for precision.
|
||||
uint8_t width = ceil(log10(percentage + 0.1)) + 2;
|
||||
|
||||
Process_updateFieldWidth(PERCENT_CPU, width);
|
||||
Process_updateFieldWidth(PERCENT_NORM_CPU, width);
|
||||
}
|
||||
|
86
Process.h
86
Process.h
@ -4,7 +4,7 @@
|
||||
htop - Process.h
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -60,6 +60,26 @@ typedef enum ProcessField_ {
|
||||
LAST_PROCESSFIELD
|
||||
} ProcessField;
|
||||
|
||||
/* Core process states (shared by platforms)
|
||||
* NOTE: The enum has an ordering that is important!
|
||||
* See processStateChar in process.c for ProcessSate -> letter mapping */
|
||||
typedef enum ProcessState_ {
|
||||
UNKNOWN = 1,
|
||||
RUNNABLE,
|
||||
RUNNING,
|
||||
QUEUED,
|
||||
WAITING,
|
||||
UNINTERRUPTIBLE_WAIT,
|
||||
BLOCKED,
|
||||
PAGING,
|
||||
STOPPED,
|
||||
TRACED,
|
||||
ZOMBIE,
|
||||
DEFUNCT,
|
||||
IDLE,
|
||||
SLEEPING
|
||||
} ProcessState;
|
||||
|
||||
struct Settings_;
|
||||
|
||||
/* Holds information about regions of the cmdline that should be
|
||||
@ -76,19 +96,10 @@ typedef struct ProcessCmdlineHighlight_ {
|
||||
* Process_writeCommand to color the string. str will be NULL for kernel
|
||||
* threads and zombies */
|
||||
typedef struct ProcessMergedCommand_ {
|
||||
uint64_t lastUpdate; /* Marker based on settings->lastUpdate to track when the rendering needs refreshing */
|
||||
char* str; /* merged Command string */
|
||||
size_t highlightCount; /* how many portions of cmdline to highlight */
|
||||
ProcessCmdlineHighlight highlights[8]; /* which portions of cmdline to highlight */
|
||||
bool separateComm : 1; /* whether comm is a separate field */
|
||||
bool unmatchedExe : 1; /* whether exe matched with cmdline */
|
||||
bool cmdlineChanged : 1; /* whether cmdline changed */
|
||||
bool exeChanged : 1; /* whether exe changed */
|
||||
bool commChanged : 1; /* whether comm changed */
|
||||
bool prevMergeSet : 1; /* whether showMergedCommand was set */
|
||||
bool prevPathSet : 1; /* whether showProgramPath was set */
|
||||
bool prevCommSet : 1; /* whether findCommInCmdline was set */
|
||||
bool prevCmdlineSet : 1; /* whether stripExeFromCmdline was set */
|
||||
bool prevShowThreadNames : 1; /* whether showThreadNames was set */
|
||||
} ProcessMergedCommand;
|
||||
|
||||
typedef struct Process_ {
|
||||
@ -204,20 +215,8 @@ typedef struct Process_ {
|
||||
/* Number of major faults the process has made which have required loading a memory page from disk */
|
||||
unsigned long int majflt;
|
||||
|
||||
/*
|
||||
* Process state (platform dependent):
|
||||
* D - Waiting
|
||||
* I - Idle
|
||||
* L - Acquiring lock
|
||||
* R - Running
|
||||
* S - Sleeping
|
||||
* T - Stopped (on a signal)
|
||||
* X - Dead
|
||||
* Z - Zombie
|
||||
* t - Tracing stop
|
||||
* ? - Unknown
|
||||
*/
|
||||
char state;
|
||||
/* Process state enum field (platform dependent) */
|
||||
ProcessState state;
|
||||
|
||||
/* Whether the process was updated during the current scan */
|
||||
bool updated;
|
||||
@ -244,10 +243,10 @@ typedef struct Process_ {
|
||||
* Internal state for tree-mode.
|
||||
*/
|
||||
int indent;
|
||||
unsigned int tree_left;
|
||||
unsigned int tree_right;
|
||||
unsigned int tree_depth;
|
||||
unsigned int tree_index;
|
||||
|
||||
/* Has no known parent process */
|
||||
bool isRoot;
|
||||
|
||||
/*
|
||||
* Internal state for merged Command display
|
||||
@ -273,6 +272,9 @@ typedef struct ProcessFieldData_ {
|
||||
|
||||
/* Whether the column should be sorted in descending order by default */
|
||||
bool defaultSortDesc;
|
||||
|
||||
/* Whether the column width is dynamically adjusted (the minimum width is determined by the title length) */
|
||||
bool autoWidth;
|
||||
} ProcessFieldData;
|
||||
|
||||
// Implemented in platform-specific code:
|
||||
@ -280,24 +282,26 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
int Process_compare(const void* v1, const void* v2);
|
||||
void Process_delete(Object* cast);
|
||||
extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
|
||||
extern uint8_t Process_fieldWidths[LAST_PROCESSFIELD];
|
||||
#define PROCESS_MIN_PID_DIGITS 5
|
||||
#define PROCESS_MAX_PID_DIGITS 19
|
||||
#define PROCESS_MIN_UID_DIGITS 5
|
||||
#define PROCESS_MAX_UID_DIGITS 20
|
||||
extern int Process_pidDigits;
|
||||
extern int Process_uidDigits;
|
||||
|
||||
typedef Process* (*Process_New)(const struct Settings_*);
|
||||
typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField);
|
||||
typedef int (*Process_CompareByKey)(const Process*, const Process*, ProcessField);
|
||||
typedef const char* (*Process_GetCommandStr)(const Process*);
|
||||
|
||||
typedef struct ProcessClass_ {
|
||||
const ObjectClass super;
|
||||
const Process_WriteField writeField;
|
||||
const Process_CompareByKey compareByKey;
|
||||
const Process_GetCommandStr getCommandStr;
|
||||
} ProcessClass;
|
||||
|
||||
#define As_Process(this_) ((const ProcessClass*)((this_)->super.klass))
|
||||
|
||||
#define Process_getCommand(this_) (As_Process(this_)->getCommandStr ? As_Process(this_)->getCommandStr((const Process*)(this_)) : Process_getCommandStr((const Process*)(this_)))
|
||||
#define Process_compareByKey(p1_, p2_, key_) (As_Process(p1_)->compareByKey ? (As_Process(p1_)->compareByKey(p1_, p2_, key_)) : Process_compareByKey_Base(p1_, p2_, key_))
|
||||
|
||||
static inline pid_t Process_getParentPid(const Process* this) {
|
||||
@ -339,6 +343,9 @@ static inline bool Process_isThread(const Process* this) {
|
||||
|
||||
void Process_setupColumnWidths(void);
|
||||
|
||||
/* Sets the size of the UID column based on the passed UID */
|
||||
void Process_setUidColumnWidth(uid_t maxUid);
|
||||
|
||||
/* Takes number in bytes (base 1024). Prints 6 columns. */
|
||||
void Process_printBytes(RichString* str, unsigned long long number, bool coloring);
|
||||
|
||||
@ -358,6 +365,8 @@ void Process_fillStarttimeBuffer(Process* this);
|
||||
|
||||
void Process_printLeftAlignedField(RichString* str, int attr, const char* content, unsigned int width);
|
||||
|
||||
void Process_printPercentage(float val, char* buffer, int n, uint8_t width, int* attr);
|
||||
|
||||
void Process_display(const Object* cast, RichString* out);
|
||||
|
||||
void Process_done(Process* this);
|
||||
@ -378,21 +387,28 @@ bool Process_changePriorityBy(Process* this, Arg delta);
|
||||
|
||||
bool Process_sendSignal(Process* this, Arg sgn);
|
||||
|
||||
int Process_pidCompare(const void* v1, const void* v2);
|
||||
static inline int Process_pidEqualCompare(const void* v1, const void* v2) {
|
||||
const pid_t p1 = ((const Process*)v1)->pid;
|
||||
const pid_t p2 = ((const Process*)v2)->pid;
|
||||
return p1 != p2; /* return zero when equal */
|
||||
}
|
||||
|
||||
int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key);
|
||||
|
||||
// Avoid direct calls, use Process_getCommand instead
|
||||
const char* Process_getCommandStr(const Process* this);
|
||||
const char* Process_getCommand(const Process* this);
|
||||
|
||||
void Process_updateComm(Process* this, const char* comm);
|
||||
void Process_updateCmdline(Process* this, const char* cmdline, int basenameStart, int basenameEnd);
|
||||
void Process_updateExe(Process* this, const char* exe);
|
||||
|
||||
/* This function constructs the string that is displayed by
|
||||
* Process_writeCommand and also returned by Process_getCommandStr */
|
||||
* Process_writeCommand and also returned by Process_getCommand */
|
||||
void Process_makeCommandStr(Process* this);
|
||||
|
||||
void Process_writeCommand(const Process* this, int attr, int baseAttr, RichString* str);
|
||||
|
||||
void Process_resetFieldWidths(void);
|
||||
void Process_updateFieldWidth(ProcessField key, size_t width);
|
||||
void Process_updateCPUFieldWidths(float percentage);
|
||||
|
||||
#endif
|
||||
|
444
ProcessList.c
444
ProcessList.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ProcessList.c
|
||||
(C) 2004,2005 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -22,11 +22,10 @@ in the source distribution for its full text.
|
||||
|
||||
ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId) {
|
||||
this->processes = Vector_new(klass, true, DEFAULT_SIZE);
|
||||
this->processes2 = Vector_new(klass, true, DEFAULT_SIZE); // tree-view auxiliary buffer
|
||||
this->displayList = Vector_new(klass, false, DEFAULT_SIZE);
|
||||
|
||||
this->processTable = Hashtable_new(200, false);
|
||||
this->displayTreeSet = Hashtable_new(200, false);
|
||||
this->draftingTreeSet = Hashtable_new(200, false);
|
||||
this->needsSort = true;
|
||||
|
||||
this->usersTable = usersTable;
|
||||
this->pidMatchList = pidMatchList;
|
||||
@ -73,11 +72,9 @@ void ProcessList_done(ProcessList* this) {
|
||||
}
|
||||
#endif
|
||||
|
||||
Hashtable_delete(this->draftingTreeSet);
|
||||
Hashtable_delete(this->displayTreeSet);
|
||||
Hashtable_delete(this->processTable);
|
||||
|
||||
Vector_delete(this->processes2);
|
||||
Vector_delete(this->displayList);
|
||||
Vector_delete(this->processes);
|
||||
}
|
||||
|
||||
@ -85,46 +82,63 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
|
||||
this->panel = panel;
|
||||
}
|
||||
|
||||
static const char* alignedDynamicColumnTitle(const ProcessList* this, int key) {
|
||||
static const char* alignedDynamicColumnTitle(const ProcessList* this, int key, char* titleBuffer, size_t titleBufferSize) {
|
||||
const DynamicColumn* column = Hashtable_get(this->dynamicColumns, key);
|
||||
if (column == NULL)
|
||||
return "- ";
|
||||
static char titleBuffer[DYNAMIC_MAX_COLUMN_WIDTH + /* space */ 1 + /* null terminator */ + 1];
|
||||
int width = column->width;
|
||||
if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
|
||||
width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
|
||||
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s", width, column->heading);
|
||||
xSnprintf(titleBuffer, titleBufferSize, "%*s", width, column->heading);
|
||||
return titleBuffer;
|
||||
}
|
||||
|
||||
static const char* alignedProcessFieldTitle(const ProcessList* this, ProcessField field) {
|
||||
static char titleBuffer[UINT8_MAX + sizeof(" ")];
|
||||
assert(sizeof(titleBuffer) >= DYNAMIC_MAX_COLUMN_WIDTH + sizeof(" "));
|
||||
assert(sizeof(titleBuffer) >= PROCESS_MAX_PID_DIGITS + sizeof(" "));
|
||||
assert(sizeof(titleBuffer) >= PROCESS_MAX_UID_DIGITS + sizeof(" "));
|
||||
|
||||
if (field >= LAST_PROCESSFIELD)
|
||||
return alignedDynamicColumnTitle(this, field);
|
||||
return alignedDynamicColumnTitle(this, field, titleBuffer, sizeof(titleBuffer));
|
||||
|
||||
const char* title = Process_fields[field].title;
|
||||
if (!title)
|
||||
return "- ";
|
||||
|
||||
if (!Process_fields[field].pidColumn)
|
||||
return title;
|
||||
|
||||
static char titleBuffer[PROCESS_MAX_PID_DIGITS + /* space */ 1 + /* null-terminator */ + 1];
|
||||
if (Process_fields[field].pidColumn) {
|
||||
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_pidDigits, title);
|
||||
|
||||
return titleBuffer;
|
||||
}
|
||||
|
||||
if (field == ST_UID) {
|
||||
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_uidDigits, title);
|
||||
return titleBuffer;
|
||||
}
|
||||
|
||||
if (Process_fields[field].autoWidth) {
|
||||
if (field == PERCENT_CPU)
|
||||
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_fieldWidths[field], title);
|
||||
else
|
||||
xSnprintf(titleBuffer, sizeof(titleBuffer), "%-*.*s ", Process_fieldWidths[field], Process_fieldWidths[field], title);
|
||||
return titleBuffer;
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
void ProcessList_printHeader(const ProcessList* this, RichString* header) {
|
||||
RichString_rewind(header, RichString_size(header));
|
||||
|
||||
const Settings* settings = this->settings;
|
||||
const ProcessField* fields = settings->fields;
|
||||
const ScreenSettings* ss = settings->ss;
|
||||
const ProcessField* fields = ss->fields;
|
||||
|
||||
ProcessField key = Settings_getActiveSortKey(settings);
|
||||
ProcessField key = ScreenSettings_getActiveSortKey(ss);
|
||||
|
||||
for (int i = 0; fields[i]; i++) {
|
||||
int color;
|
||||
if (settings->treeView && settings->treeViewAlwaysByPID) {
|
||||
if (ss->treeView && ss->treeViewAlwaysByPID) {
|
||||
color = CRT_colors[PANEL_HEADER_FOCUS];
|
||||
} else if (key == fields[i]) {
|
||||
color = CRT_colors[PANEL_SELECTION_FOCUS];
|
||||
@ -134,10 +148,11 @@ void ProcessList_printHeader(const ProcessList* this, RichString* header) {
|
||||
|
||||
RichString_appendWide(header, color, alignedProcessFieldTitle(this, fields[i]));
|
||||
if (key == fields[i] && RichString_getCharVal(*header, RichString_size(header) - 1) == ' ') {
|
||||
bool ascending = ScreenSettings_getActiveDirection(ss) == 1;
|
||||
RichString_rewind(header, 1); // rewind to override space
|
||||
RichString_appendnWide(header,
|
||||
CRT_colors[PANEL_SELECTION_FOCUS],
|
||||
CRT_treeStr[Settings_getActiveDirection(this->settings) == 1 ? TREE_STR_ASC : TREE_STR_DESC],
|
||||
CRT_treeStr[ascending ? TREE_STR_ASC : TREE_STR_DESC],
|
||||
1);
|
||||
}
|
||||
if (COMM == fields[i] && settings->showMergedCommand) {
|
||||
@ -147,7 +162,7 @@ void ProcessList_printHeader(const ProcessList* this, RichString* header) {
|
||||
}
|
||||
|
||||
void ProcessList_add(ProcessList* this, Process* p) {
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidEqualCompare) == -1);
|
||||
assert(Hashtable_get(this->processTable, p->pid) == NULL);
|
||||
p->processList = this;
|
||||
|
||||
@ -157,25 +172,23 @@ void ProcessList_add(ProcessList* this, Process* p) {
|
||||
Vector_add(this->processes, p);
|
||||
Hashtable_put(this->processTable, p->pid, p);
|
||||
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidEqualCompare) != -1);
|
||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||
assert(Vector_countEquals(this->processes, Hashtable_count(this->processTable)));
|
||||
}
|
||||
|
||||
void ProcessList_remove(ProcessList* this, const Process* p) {
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
||||
|
||||
const Process* pp = Hashtable_remove(this->processTable, p->pid);
|
||||
assert(pp == p); (void)pp;
|
||||
|
||||
// ProcessList_removeIndex removes Process p from the list's map and soft deletes
|
||||
// it from its vector. Vector_compact *must* be called once the caller is done
|
||||
// removing items.
|
||||
// Should only be called from ProcessList_scan to avoid breaking dying process highlighting.
|
||||
static void ProcessList_removeIndex(ProcessList* this, const Process* p, int idx) {
|
||||
pid_t pid = p->pid;
|
||||
int idx = Vector_indexOf(this->processes, p, Process_pidCompare);
|
||||
assert(idx != -1);
|
||||
|
||||
if (idx >= 0) {
|
||||
Vector_remove(this->processes, idx);
|
||||
}
|
||||
assert(p == (Process*)Vector_get(this->processes, idx));
|
||||
assert(Hashtable_get(this->processTable, pid) != NULL);
|
||||
|
||||
Hashtable_remove(this->processTable, pid);
|
||||
Vector_softRemove(this->processes, idx);
|
||||
|
||||
if (this->following != -1 && this->following == pid) {
|
||||
this->following = -1;
|
||||
@ -183,316 +196,148 @@ void ProcessList_remove(ProcessList* this, const Process* p) {
|
||||
}
|
||||
|
||||
assert(Hashtable_get(this->processTable, pid) == NULL);
|
||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||
assert(Vector_countEquals(this->processes, Hashtable_count(this->processTable)));
|
||||
}
|
||||
|
||||
// ProcessList_updateTreeSetLayer sorts this->displayTreeSet,
|
||||
// relying only on itself.
|
||||
//
|
||||
// Algorithm
|
||||
//
|
||||
// The algorithm is based on `depth-first search`,
|
||||
// even though `breadth-first search` approach may be more efficient on first glance,
|
||||
// after comparison it may be not, as it's not safe to go deeper without first updating the tree structure.
|
||||
// If it would be safe that approach would likely bring an advantage in performance.
|
||||
//
|
||||
// Each call of the function looks for a 'layer'. A 'layer' is a list of processes with the same depth.
|
||||
// First it sorts a list. Then it runs the function recursively for each element of the sorted list.
|
||||
// After that it updates the settings of processes.
|
||||
//
|
||||
// It relies on `leftBound` and `rightBound` as an optimization to cut the list size at the time it builds a 'layer'.
|
||||
//
|
||||
// It uses a temporary Hashtable `draftingTreeSet` because it's not safe to traverse a tree
|
||||
// and at the same time make changes in it.
|
||||
//
|
||||
static void ProcessList_updateTreeSetLayer(ProcessList* this, unsigned int leftBound, unsigned int rightBound, unsigned int deep, unsigned int left, unsigned int right, unsigned int* index, unsigned int* treeIndex, int indent) {
|
||||
|
||||
// It's guaranteed that layer_size is enough space
|
||||
// but most likely it needs less. Specifically on first iteration.
|
||||
int layerSize = (right - left) / 2;
|
||||
|
||||
// check if we reach `children` of `leaves`
|
||||
if (layerSize == 0)
|
||||
return;
|
||||
|
||||
Vector* layer = Vector_new(Vector_type(this->processes), false, layerSize);
|
||||
|
||||
// Find all processes on the same layer (process with the same `deep` value
|
||||
// and included in a range from `leftBound` to `rightBound`).
|
||||
//
|
||||
// This loop also keeps track of left_bound and right_bound of these processes
|
||||
// in order not to lose this information once the list is sorted.
|
||||
//
|
||||
// The variables left_bound and right_bound are different from what the values lhs and rhs represent.
|
||||
// While left_bound and right_bound define a range of processes to look at, the values given by lhs and rhs are indices into an array
|
||||
//
|
||||
// In the below example note how filtering a range of indices i is different from filtering for processes in the bounds left_bound < x < right_bound …
|
||||
//
|
||||
// The nested tree set is sorted by left value, which is guaranteed upon entry/exit of this function.
|
||||
//
|
||||
// i | l | r
|
||||
// 1 | 1 | 9
|
||||
// 2 | 2 | 8
|
||||
// 3 | 4 | 5
|
||||
// 4 | 6 | 7
|
||||
for (unsigned int i = leftBound; i < rightBound; i++) {
|
||||
Process* proc = (Process*)Hashtable_get(this->displayTreeSet, i);
|
||||
assert(proc);
|
||||
if (proc && proc->tree_depth == deep && proc->tree_left > left && proc->tree_right < right) {
|
||||
if (Vector_size(layer) > 0) {
|
||||
Process* previous_process = (Process*)Vector_get(layer, Vector_size(layer) - 1);
|
||||
|
||||
// Make a 'right_bound' of previous_process in a layer the current process's index.
|
||||
//
|
||||
// Use 'tree_depth' as a temporal variable.
|
||||
// It's safe to do as later 'tree_depth' will be renovated.
|
||||
previous_process->tree_depth = proc->tree_index;
|
||||
}
|
||||
|
||||
Vector_add(layer, proc);
|
||||
}
|
||||
}
|
||||
|
||||
// The loop above changes just up to process-1.
|
||||
// So the last process of the layer isn't updated by the above code.
|
||||
//
|
||||
// Thus, if present, set the `rightBound` to the last process on the layer
|
||||
if (Vector_size(layer) > 0) {
|
||||
Process* previous_process = (Process*)Vector_get(layer, Vector_size(layer) - 1);
|
||||
previous_process->tree_depth = rightBound;
|
||||
}
|
||||
|
||||
Vector_quickSort(layer);
|
||||
|
||||
int size = Vector_size(layer);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Process* proc = (Process*)Vector_get(layer, i);
|
||||
|
||||
unsigned int idx = (*index)++;
|
||||
int newLeft = (*treeIndex)++;
|
||||
|
||||
int level = deep == 0 ? 0 : (int)deep - 1;
|
||||
int currentIndent = indent == -1 ? 0 : indent | (1 << level);
|
||||
int nextIndent = indent == -1 ? 0 : ((i < size - 1) ? currentIndent : indent);
|
||||
|
||||
unsigned int newLeftBound = proc->tree_index;
|
||||
unsigned int newRightBound = proc->tree_depth;
|
||||
ProcessList_updateTreeSetLayer(this, newLeftBound, newRightBound, deep + 1, proc->tree_left, proc->tree_right, index, treeIndex, nextIndent);
|
||||
|
||||
int newRight = (*treeIndex)++;
|
||||
|
||||
proc->tree_left = newLeft;
|
||||
proc->tree_right = newRight;
|
||||
proc->tree_index = idx;
|
||||
proc->tree_depth = deep;
|
||||
|
||||
if (indent == -1) {
|
||||
proc->indent = 0;
|
||||
} else if (i == size - 1) {
|
||||
proc->indent = -currentIndent;
|
||||
} else {
|
||||
proc->indent = currentIndent;
|
||||
}
|
||||
|
||||
Hashtable_put(this->draftingTreeSet, proc->tree_index, proc);
|
||||
|
||||
// It's not strictly necessary to do this, but doing so anyways
|
||||
// allows for checking the correctness of the inner workings.
|
||||
Hashtable_remove(this->displayTreeSet, newLeftBound);
|
||||
}
|
||||
|
||||
Vector_delete(layer);
|
||||
}
|
||||
|
||||
static void ProcessList_updateTreeSet(ProcessList* this) {
|
||||
unsigned int index = 0;
|
||||
unsigned int tree_index = 1;
|
||||
|
||||
const int vsize = Vector_size(this->processes);
|
||||
|
||||
assert(Hashtable_count(this->draftingTreeSet) == 0);
|
||||
assert((int)Hashtable_count(this->displayTreeSet) == vsize);
|
||||
|
||||
ProcessList_updateTreeSetLayer(this, 0, vsize, 0, 0, vsize * 2 + 1, &index, &tree_index, -1);
|
||||
|
||||
Hashtable* tmp = this->draftingTreeSet;
|
||||
this->draftingTreeSet = this->displayTreeSet;
|
||||
this->displayTreeSet = tmp;
|
||||
|
||||
assert(Hashtable_count(this->draftingTreeSet) == 0);
|
||||
assert((int)Hashtable_count(this->displayTreeSet) == vsize);
|
||||
}
|
||||
|
||||
static void ProcessList_buildTreeBranch(ProcessList* this, pid_t pid, int level, int indent, int direction, bool show, int* node_counter, int* node_index) {
|
||||
static void ProcessList_buildTreeBranch(ProcessList* this, pid_t pid, int level, int indent, bool show) {
|
||||
// On OpenBSD the kernel thread 'swapper' has pid 0.
|
||||
// Do not treat it as root of any tree.
|
||||
if (pid == 0)
|
||||
return;
|
||||
|
||||
Vector* children = Vector_new(Class(Process), false, DEFAULT_SIZE);
|
||||
// The vector is sorted by parent PID, find the start of the range by bisection
|
||||
int vsize = Vector_size(this->processes);
|
||||
int l = 0;
|
||||
int r = vsize;
|
||||
while (l < r) {
|
||||
int c = (l + r) / 2;
|
||||
Process* process = (Process*)Vector_get(this->processes, c);
|
||||
pid_t ppid = process->isRoot ? 0 : Process_getParentPid(process);
|
||||
if (ppid < pid) {
|
||||
l = c + 1;
|
||||
} else {
|
||||
r = c;
|
||||
}
|
||||
}
|
||||
// Find the end to know the last line for indent handling purposes
|
||||
int lastShown = r;
|
||||
while (r < vsize) {
|
||||
Process* process = (Process*)Vector_get(this->processes, r);
|
||||
if (!Process_isChildOf(process, pid))
|
||||
break;
|
||||
if (process->show)
|
||||
lastShown = r;
|
||||
r++;
|
||||
}
|
||||
|
||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
||||
for (int i = l; i < r; i++) {
|
||||
Process* process = (Process*)Vector_get(this->processes, i);
|
||||
if (process->show && Process_isChildOf(process, pid)) {
|
||||
process = (Process*)Vector_take(this->processes, i);
|
||||
Vector_add(children, process);
|
||||
}
|
||||
}
|
||||
|
||||
int size = Vector_size(children);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int index = (*node_index)++;
|
||||
Process* process = (Process*)Vector_get(children, i);
|
||||
|
||||
int lft = (*node_counter)++;
|
||||
|
||||
if (!show) {
|
||||
process->show = false;
|
||||
}
|
||||
|
||||
int s = Vector_size(this->processes2);
|
||||
if (direction == 1) {
|
||||
Vector_add(this->processes2, process);
|
||||
} else {
|
||||
Vector_insert(this->processes2, 0, process);
|
||||
}
|
||||
|
||||
assert(Vector_size(this->processes2) == s + 1); (void)s;
|
||||
Vector_add(this->displayList, process);
|
||||
|
||||
int nextIndent = indent | (1 << level);
|
||||
ProcessList_buildTreeBranch(this, process->pid, level + 1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false, node_counter, node_index);
|
||||
if (i == size - 1) {
|
||||
ProcessList_buildTreeBranch(this, process->pid, level + 1, (i < lastShown) ? nextIndent : indent, process->show && process->showChildren);
|
||||
if (i == lastShown) {
|
||||
process->indent = -nextIndent;
|
||||
} else {
|
||||
process->indent = nextIndent;
|
||||
}
|
||||
|
||||
int rht = (*node_counter)++;
|
||||
|
||||
process->tree_left = lft;
|
||||
process->tree_right = rht;
|
||||
process->tree_depth = level + 1;
|
||||
process->tree_index = index;
|
||||
Hashtable_put(this->displayTreeSet, index, process);
|
||||
}
|
||||
Vector_delete(children);
|
||||
}
|
||||
|
||||
static int ProcessList_treeProcessCompare(const void* v1, const void* v2) {
|
||||
static int compareProcessByKnownParentThenNatural(const void* v1, const void* v2) {
|
||||
const Process* p1 = (const Process*)v1;
|
||||
const Process* p2 = (const Process*)v2;
|
||||
|
||||
return SPACESHIP_NUMBER(p1->tree_left, p2->tree_left);
|
||||
}
|
||||
int result = SPACESHIP_NUMBER(
|
||||
p1->isRoot ? 0 : Process_getParentPid(p1),
|
||||
p2->isRoot ? 0 : Process_getParentPid(p2)
|
||||
);
|
||||
|
||||
static int ProcessList_treeProcessCompareByPID(const void* v1, const void* v2) {
|
||||
const Process* p1 = (const Process*)v1;
|
||||
const Process* p2 = (const Process*)v2;
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
return SPACESHIP_NUMBER(p1->pid, p2->pid);
|
||||
return Process_compare(v1, v2);
|
||||
}
|
||||
|
||||
// Builds a sorted tree from scratch, without relying on previously gathered information
|
||||
static void ProcessList_buildTree(ProcessList* this) {
|
||||
int node_counter = 1;
|
||||
int node_index = 0;
|
||||
int direction = Settings_getActiveDirection(this->settings);
|
||||
Vector_prune(this->displayList);
|
||||
|
||||
// Sort by PID
|
||||
Vector_quickSortCustomCompare(this->processes, ProcessList_treeProcessCompareByPID);
|
||||
// Mark root processes
|
||||
int vsize = Vector_size(this->processes);
|
||||
|
||||
// Find all processes whose parent is not visible
|
||||
int size;
|
||||
while ((size = Vector_size(this->processes))) {
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
for (int i = 0; i < vsize; i++) {
|
||||
Process* process = (Process*)Vector_get(this->processes, i);
|
||||
|
||||
// Immediately consume processes hidden from view
|
||||
if (!process->show) {
|
||||
process = (Process*)Vector_take(this->processes, i);
|
||||
process->indent = 0;
|
||||
process->tree_depth = 0;
|
||||
process->tree_left = node_counter++;
|
||||
process->tree_index = node_index++;
|
||||
Vector_add(this->processes2, process);
|
||||
ProcessList_buildTreeBranch(this, process->pid, 0, 0, direction, false, &node_counter, &node_index);
|
||||
process->tree_right = node_counter++;
|
||||
Hashtable_put(this->displayTreeSet, process->tree_index, process);
|
||||
break;
|
||||
}
|
||||
|
||||
pid_t ppid = Process_getParentPid(process);
|
||||
|
||||
// Bisect the process vector to find parent
|
||||
int l = 0;
|
||||
int r = size;
|
||||
process->isRoot = false;
|
||||
|
||||
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
||||
// on Mac OS X 10.11.6) cancel bisecting and regard this process as
|
||||
// root.
|
||||
if (process->pid == ppid)
|
||||
r = 0;
|
||||
// on Mac OS X 10.11.6) regard this process as root.
|
||||
if (process->pid == ppid) {
|
||||
process->isRoot = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// On Linux both the init process (pid 1) and the root UMH kernel thread (pid 2)
|
||||
// use a ppid of 0. As that PID can't exist, we can skip searching for it.
|
||||
if (!ppid)
|
||||
r = 0;
|
||||
if (!ppid) {
|
||||
process->isRoot = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
while (l < r) {
|
||||
int c = (l + r) / 2;
|
||||
pid_t pid = ((Process*)Vector_get(this->processes, c))->pid;
|
||||
if (ppid == pid) {
|
||||
break;
|
||||
} else if (ppid < pid) {
|
||||
r = c;
|
||||
} else {
|
||||
l = c + 1;
|
||||
}
|
||||
// We don't know about its parent for whatever reason
|
||||
if (ProcessList_findProcess(this, ppid) == NULL)
|
||||
process->isRoot = true;
|
||||
}
|
||||
|
||||
// Sort by known parent PID (roots first), then PID
|
||||
Vector_quickSortCustomCompare(this->processes, compareProcessByKnownParentThenNatural);
|
||||
|
||||
// Find all processes whose parent is not visible
|
||||
for (int i = 0; i < vsize; i++) {
|
||||
Process* process = (Process*)Vector_get(this->processes, i);
|
||||
|
||||
// If parent not found, then construct the tree with this node as root
|
||||
if (l >= r) {
|
||||
process = (Process*)Vector_take(this->processes, i);
|
||||
if (process->isRoot) {
|
||||
process = (Process*)Vector_get(this->processes, i);
|
||||
process->indent = 0;
|
||||
process->tree_depth = 0;
|
||||
process->tree_left = node_counter++;
|
||||
process->tree_index = node_index++;
|
||||
Vector_add(this->processes2, process);
|
||||
Hashtable_put(this->displayTreeSet, process->tree_index, process);
|
||||
ProcessList_buildTreeBranch(this, process->pid, 0, 0, direction, process->showChildren, &node_counter, &node_index);
|
||||
process->tree_right = node_counter++;
|
||||
break;
|
||||
Vector_add(this->displayList, process);
|
||||
ProcessList_buildTreeBranch(this, process->pid, 0, 0, process->showChildren);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// There should be no loop in the process tree
|
||||
assert(i < size);
|
||||
}
|
||||
|
||||
// Swap listings around
|
||||
Vector* t = this->processes;
|
||||
this->processes = this->processes2;
|
||||
this->processes2 = t;
|
||||
this->needsSort = false;
|
||||
|
||||
// Check consistency of the built structures
|
||||
assert(Vector_size(this->processes) == vsize); (void)vsize;
|
||||
assert(Vector_size(this->processes2) == 0);
|
||||
assert(Vector_size(this->displayList) == vsize); (void)vsize;
|
||||
}
|
||||
|
||||
void ProcessList_sort(ProcessList* this) {
|
||||
if (this->settings->treeView) {
|
||||
ProcessList_updateTreeSet(this);
|
||||
Vector_quickSortCustomCompare(this->processes, ProcessList_treeProcessCompare);
|
||||
void ProcessList_updateDisplayList(ProcessList* this) {
|
||||
if (this->settings->ss->treeView) {
|
||||
if (this->needsSort)
|
||||
ProcessList_buildTree(this);
|
||||
} else {
|
||||
if (this->needsSort)
|
||||
Vector_insertionSort(this->processes);
|
||||
Vector_prune(this->displayList);
|
||||
int size = Vector_size(this->processes);
|
||||
for (int i = 0; i < size; i++)
|
||||
Vector_add(this->displayList, Vector_get(this->processes, i));
|
||||
}
|
||||
this->needsSort = false;
|
||||
}
|
||||
|
||||
ProcessField ProcessList_keyAt(const ProcessList* this, int at) {
|
||||
int x = 0;
|
||||
const ProcessField* fields = this->settings->fields;
|
||||
const ProcessField* fields = this->settings->ss->fields;
|
||||
ProcessField field;
|
||||
for (int i = 0; (field = fields[i]); i++) {
|
||||
int len = strlen(alignedProcessFieldTitle(this, field));
|
||||
@ -512,7 +357,10 @@ void ProcessList_expandTree(ProcessList* this) {
|
||||
}
|
||||
}
|
||||
|
||||
// Called on collapse-all toggle and on startup, possibly in non-tree mode
|
||||
void ProcessList_collapseAllBranches(ProcessList* this) {
|
||||
ProcessList_buildTree(this); // Update `tree_depth` fields of the processes
|
||||
this->needsSort = true; // ProcessList is sorted by parent now, force new sort
|
||||
int size = Vector_size(this->processes);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Process* process = (Process*) Vector_get(this->processes, i);
|
||||
@ -523,6 +371,8 @@ void ProcessList_collapseAllBranches(ProcessList* this) {
|
||||
}
|
||||
|
||||
void ProcessList_rebuildPanel(ProcessList* this) {
|
||||
ProcessList_updateDisplayList(this);
|
||||
|
||||
const char* incFilter = this->incFilter;
|
||||
|
||||
const int currPos = Panel_getSelectedIndex(this->panel);
|
||||
@ -540,16 +390,16 @@ void ProcessList_rebuildPanel(ProcessList* this) {
|
||||
}
|
||||
}
|
||||
|
||||
const int processCount = Vector_size(this->processes);
|
||||
const int processCount = Vector_size(this->displayList);
|
||||
int idx = 0;
|
||||
bool foundFollowed = false;
|
||||
|
||||
for (int i = 0; i < processCount; i++) {
|
||||
Process* p = (Process*) Vector_get(this->processes, i);
|
||||
Process* p = (Process*) Vector_get(this->displayList, i);
|
||||
|
||||
if ( (!p->show)
|
||||
|| (this->userId != (uid_t) -1 && (p->st_uid != this->userId))
|
||||
|| (incFilter && !(String_contains_i(Process_getCommand(p), incFilter)))
|
||||
|| (incFilter && !(String_contains_i(Process_getCommand(p), incFilter, true)))
|
||||
|| (this->pidMatchList && !Hashtable_get(this->pidMatchList, p->tgid)) )
|
||||
continue;
|
||||
|
||||
@ -584,7 +434,7 @@ Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting,
|
||||
Process* proc = (Process*) Hashtable_get(this->processTable, pid);
|
||||
*preExisting = proc != NULL;
|
||||
if (proc) {
|
||||
assert(Vector_indexOf(this->processes, proc, Process_pidCompare) != -1);
|
||||
assert(Vector_indexOf(this->processes, proc, Process_pidEqualCompare) != -1);
|
||||
assert(proc->pid == pid);
|
||||
} else {
|
||||
proc = constructor(this->settings);
|
||||
@ -614,6 +464,7 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
|
||||
this->kernelThreads = 0;
|
||||
this->runningTasks = 0;
|
||||
|
||||
Process_resetFieldWidths();
|
||||
|
||||
// set scan timestamp
|
||||
static bool firstScanDone = false;
|
||||
@ -626,14 +477,19 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
|
||||
|
||||
ProcessList_goThroughEntries(this, false);
|
||||
|
||||
uid_t maxUid = 0;
|
||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
||||
Process* p = (Process*) Vector_get(this->processes, i);
|
||||
Process_makeCommandStr(p);
|
||||
|
||||
// keep track of the highest UID for column scaling
|
||||
if (p->st_uid > maxUid)
|
||||
maxUid = p->st_uid;
|
||||
|
||||
if (p->tombStampMs > 0) {
|
||||
// remove tombed process
|
||||
if (this->monotonicMs >= p->tombStampMs) {
|
||||
ProcessList_remove(this, p);
|
||||
ProcessList_removeIndex(this, p, i);
|
||||
}
|
||||
} else if (p->updated == false) {
|
||||
// process no longer exists
|
||||
@ -642,18 +498,14 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
|
||||
p->tombStampMs = this->monotonicMs + 1000 * this->settings->highlightDelaySecs;
|
||||
} else {
|
||||
// immediately remove
|
||||
ProcessList_remove(this, p);
|
||||
ProcessList_removeIndex(this, p, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->settings->treeView) {
|
||||
// Clear out the hashtable to avoid any left-over processes from previous build
|
||||
//
|
||||
// The sorting algorithm relies on the fact that
|
||||
// len(this->displayTreeSet) == len(this->processes)
|
||||
Hashtable_clear(this->displayTreeSet);
|
||||
// Compact the processes vector in case of any deletions
|
||||
Vector_compact(this->processes);
|
||||
|
||||
ProcessList_buildTree(this);
|
||||
}
|
||||
// Set UID column width based on max UID.
|
||||
Process_setUidColumnWidth(maxUid);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ProcessList.h
|
||||
(C) 2004,2005 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -43,13 +43,13 @@ typedef unsigned long long int memory_t;
|
||||
typedef struct ProcessList_ {
|
||||
const Settings* settings;
|
||||
|
||||
Vector* processes;
|
||||
Vector* processes2;
|
||||
Hashtable* processTable;
|
||||
Vector* processes; /* all known processes; sort order can vary and differ from display order */
|
||||
Vector* displayList; /* process tree flattened in display order (borrowed);
|
||||
updated in ProcessList_updateDisplayList when rebuilding panel */
|
||||
Hashtable* processTable; /* fast known process lookup by PID */
|
||||
UsersTable* usersTable;
|
||||
|
||||
Hashtable* displayTreeSet;
|
||||
Hashtable* draftingTreeSet;
|
||||
bool needsSort;
|
||||
|
||||
Hashtable* dynamicMeters; /* runtime-discovered meters */
|
||||
Hashtable* dynamicColumns; /* runtime-discovered Columns */
|
||||
@ -106,9 +106,7 @@ void ProcessList_printHeader(const ProcessList* this, RichString* header);
|
||||
|
||||
void ProcessList_add(ProcessList* this, Process* p);
|
||||
|
||||
void ProcessList_remove(ProcessList* this, const Process* p);
|
||||
|
||||
void ProcessList_sort(ProcessList* this);
|
||||
void ProcessList_updateDisplayList(ProcessList* this);
|
||||
|
||||
ProcessField ProcessList_keyAt(const ProcessList* this, int at);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ProcessLocksScreen.c
|
||||
(C) 2020 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ProcessLocksScreen.h
|
||||
(C) 2020 htop dev team
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - RichString.h
|
||||
(C) 2004,2011 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
122
README
122
README
@ -1,10 +1,12 @@
|
||||
# [](https://htop.dev)
|
||||
# [](https://htop.dev)
|
||||
|
||||
[](https://github.com/htop-dev/htop/actions)
|
||||
[](https://scan.coverity.com/projects/21665)
|
||||
[](https://groups.io/g/htop)
|
||||
[](https://web.libera.chat/#htop)
|
||||
[](https://github.com/htop-dev/htop/releases/latest)
|
||||
[](https://github.com/htop-dev/htop/releases/latest)
|
||||
[](https://repology.org/project/htop/versions)
|
||||
[](COPYING?raw=true)
|
||||
|
||||

|
||||
|
||||
@ -13,26 +15,30 @@
|
||||
`htop` is a cross-platform interactive process viewer.
|
||||
|
||||
`htop` allows scrolling the list of processes vertically and horizontally to see their full command lines and related information like memory and CPU consumption.
|
||||
Also system wide information, like load average or swap usage, is shown.
|
||||
|
||||
The information displayed is configurable through a graphical setup and can be sorted and filtered interactively.
|
||||
|
||||
Tasks related to processes (e.g. killing and renicing) can be done without entering their PIDs.
|
||||
|
||||
Running `htop` requires `ncurses` libraries (typically named libncursesw*).
|
||||
Running `htop` requires `ncurses` libraries, typically named libncurses(w).
|
||||
|
||||
For more information and details on how to contribute to `htop` visit [htop.dev](https://htop.dev).
|
||||
`htop` is written in C.
|
||||
|
||||
For more information and details visit [htop.dev](https://htop.dev).
|
||||
|
||||
## Build instructions
|
||||
|
||||
### Prerequisite
|
||||
List of build-time dependencies:
|
||||
* `build-essential` standard GNU autotools-based
|
||||
* `autoconf`
|
||||
* `autotools`
|
||||
* standard GNU autotools-based C toolchain
|
||||
- C99 compliant compiler
|
||||
- `autoconf`
|
||||
- `autotools`
|
||||
* `ncurses`
|
||||
|
||||
**Note about `ncurses`:**
|
||||
> htop requires ncurses 6.0. Be aware the appropriate package is sometimes still called libncurses5 (on Debian/Ubuntu). Also ncurses usually comes in two flavours:
|
||||
> `htop` requires `ncurses` 6.0. Be aware the appropriate package is sometimes still called libncurses5 (on Debian/Ubuntu). Also `ncurses` usually comes in two flavours:
|
||||
>* With Unicode support.
|
||||
>* Without Unicode support.
|
||||
>
|
||||
@ -41,28 +47,37 @@ List of build-time dependencies:
|
||||
List of additional build-time dependencies (based on feature flags):
|
||||
* `sensors`
|
||||
* `hwloc`
|
||||
* `libcap`
|
||||
* `libcap` (v2.21 or later)
|
||||
* `libnl-3`
|
||||
|
||||
Compiling `htop` requires the header files for `ncurses` . Install these and other required packages for C development from your package manager.
|
||||
Install these and other required packages for C development from your package manager.
|
||||
|
||||
**Debian/Ubuntu**
|
||||
~~~ shell
|
||||
sudo apt install libncursesw5-dev autotools-dev autoconf
|
||||
sudo apt install libncursesw5-dev autotools-dev autoconf build-essential
|
||||
~~~
|
||||
|
||||
**Fedora/RHEL**
|
||||
~~~ shell
|
||||
sudo dnf install ncurses-devel automake autoconf
|
||||
sudo dnf install ncurses-devel automake autoconf gcc
|
||||
~~~
|
||||
|
||||
### Compiling from source:
|
||||
To compile from sources downloaded from the Git repository (`git clone` or downloads from [Github releases](https://github.com/htop-dev/htop/releases/)), then run:
|
||||
**Archlinux/Manjaro**
|
||||
~~~ shell
|
||||
sudo pacman -S ncurses automake autoconf gcc
|
||||
~~~
|
||||
|
||||
**macOS**
|
||||
~~~ shell
|
||||
brew install ncurses automake autoconf gcc
|
||||
~~~
|
||||
|
||||
### Compile from source:
|
||||
To compile from source, download from the Git repository (`git clone` or downloads from [GitHub releases](https://github.com/htop-dev/htop/releases/)), then run:
|
||||
~~~ shell
|
||||
./autogen.sh && ./configure && make
|
||||
~~~
|
||||
|
||||
By default `make install` will install into `/usr/local`, for changing the path use `./configure --prefix=/some/path`.
|
||||
|
||||
### Install
|
||||
To install on the local system run `make install`. By default `make install` installs into `/usr/local`. To change this path use `./configure --prefix=/some/path`.
|
||||
|
||||
@ -74,52 +89,55 @@ To install on the local system run `make install`. By default `make install` ins
|
||||
|
||||
* `--enable-unicode`:
|
||||
enable Unicode support
|
||||
dependency: *libncursesw*
|
||||
default: *yes*
|
||||
* `--enable-pcp`:
|
||||
enable Performance Co-Pilot support via a new pcp-htop utility
|
||||
dependency: *libpcp*
|
||||
default: *no*
|
||||
- dependency: *libncursesw*
|
||||
- default: *yes*
|
||||
* `--enable-affinity`:
|
||||
enable `sched_setaffinity(2)` and `sched_getaffinity(2)` for affinity support; conflicts with hwloc
|
||||
default: *check*
|
||||
- default: *check*
|
||||
* `--enable-hwloc`:
|
||||
enable hwloc support for CPU affinity; disables affinity support
|
||||
dependency: *libhwloc*
|
||||
default: *no*
|
||||
- dependency: *libhwloc*
|
||||
- default: *no*
|
||||
* `--enable-static`:
|
||||
build a static htop binary; hwloc and delay accounting are not supported
|
||||
default: *no*
|
||||
- default: *no*
|
||||
* `--enable-debug`:
|
||||
Enable asserts and internal sanity checks; implies a performance penalty
|
||||
default: *no*
|
||||
- default: *no*
|
||||
|
||||
#### Performance Co-Pilot
|
||||
|
||||
* `--enable-pcp`:
|
||||
enable Performance Co-Pilot support via a new pcp-htop utility
|
||||
- dependency: *libpcp*
|
||||
- default: *no*
|
||||
|
||||
#### Linux
|
||||
|
||||
* `--enable-sensors`:
|
||||
enable libsensors(3) support for reading temperature data
|
||||
dependencies: *libsensors-dev*(build-time), at runtime *libsensors* is loaded via `dlopen(3)` if available
|
||||
default: *check*
|
||||
- dependencies: *libsensors-dev*(build-time), at runtime *libsensors* is loaded via `dlopen(3)` if available
|
||||
- default: *check*
|
||||
* `--enable-capabilities`:
|
||||
enable Linux capabilities support
|
||||
dependency: *libcap*
|
||||
default: *check*
|
||||
- dependency: *libcap*
|
||||
- default: *check*
|
||||
* `--with-proc`:
|
||||
location of a Linux-compatible proc filesystem
|
||||
default: */proc*
|
||||
- default: */proc*
|
||||
* `--enable-openvz`:
|
||||
enable OpenVZ support
|
||||
default: *no*
|
||||
- default: *no*
|
||||
* `--enable-vserver`:
|
||||
enable VServer support
|
||||
default: *no*
|
||||
- default: *no*
|
||||
* `--enable-ancient-vserver`:
|
||||
enable ancient VServer support (implies `--enable-vserver`)
|
||||
default: *no*
|
||||
- default: *no*
|
||||
* `--enable-delayacct`:
|
||||
enable Linux delay accounting support
|
||||
dependencies: *pkg-config*(build-time), *libnl-3* and *libnl-genl-3*
|
||||
default: *check*
|
||||
- dependencies: *pkg-config*(build-time), *libnl-3* and *libnl-genl-3*
|
||||
- default: *check*
|
||||
|
||||
|
||||
## Runtime dependencies:
|
||||
@ -128,40 +146,42 @@ To install on the local system run `make install`. By default `make install` ins
|
||||
|
||||
### Runtime optional dependencies:
|
||||
`htop` has a set of fixed optional dependencies, depending on build/configure option used:
|
||||
* `libdl`, if not building static and support for some of the optional libraries is enabled, is always required when support for to optionally load dependencies (i.e. `libsensors`, `systemd`) is present.
|
||||
* `libcap`, user-space interfaces to the POSIX 1003.1e, is always required when `--enable-capabilities` was used to configure `htop`.
|
||||
|
||||
#### Linux
|
||||
* `libdl`, if not building a static binary, is always required when support for optional dependencies (i.e. `libsensors`, `libsystemd`) is present.
|
||||
* `libcap`, user-space interfaces to POSIX 1003.1e capabilities, is always required when `--enable-capabilities` was used to configure `htop`.
|
||||
* `libsensors`, readout of temperatures and CPU speeds, is optional even when `--enable-sensors` was used to configure `htop`.
|
||||
* `systemd` is optional when `--enable-static` was not used to configure `htop` (Linux only). If building statically and `libsystemd` is not found by `configure` support for the SystemD meter is disabled entirely.
|
||||
* `libsystemd` is optional when `--enable-static` was not used to configure `htop`. If building statically and `libsystemd` is not found by `configure`, support for the systemd meter is disabled entirely.
|
||||
|
||||
`htop` checks for the availability of the actual runtime lib as `htop` runs.
|
||||
`htop` checks for the availability of the actual runtime libraries as `htop` runs.
|
||||
|
||||
**BSD**
|
||||
On most *BSD systems you also have `kvm` as a static requirement to read all the kernel information.
|
||||
#### BSD
|
||||
On most BSD systems `kvm` is a requirement to read kernel information.
|
||||
|
||||
More information on required and optional dependencies can be found in [configure.ac](configure.ac).
|
||||
|
||||
## Usage
|
||||
See the manual page (`man htop`) or the on-line help ('F1' or 'h' inside `htop`) for a list of supported key commands.
|
||||
See the manual page (`man htop`) or the help menu (**F1** or **h** inside `htop`) for a list of supported key commands.
|
||||
|
||||
## Support
|
||||
|
||||
If you have trouble running `htop` please consult your Operating System / Linux distribution documentation for getting support and filing bugs.
|
||||
If you have trouble running `htop` please consult your operating system / Linux distribution documentation for getting support and filing bugs.
|
||||
|
||||
## Bugs, development feedback
|
||||
|
||||
We have a [development mailing list](https://htop.dev/mailinglist.html). Feel free to subscribe for release announcements or asking questions on the development of htop.
|
||||
We have a [development mailing list](https://htop.dev/mailinglist.html). Feel free to subscribe for release announcements or asking questions on the development of `htop`.
|
||||
|
||||
You can also join our IRC channel #htop on Libera.Chat and talk to the developers there.
|
||||
You can also join our IRC channel [#htop on Libera.Chat](https://web.libera.chat/#htop) and talk to the developers there.
|
||||
|
||||
If you have found an issue with the source of htop, please check whether this has already been reported in our [Github issue tracker](https://github.com/htop-dev/htop/issues).
|
||||
If not, please file a new issue describing the problem you have found, the location in the source code you are referring to and a possible fix.
|
||||
If you have found an issue within the source of `htop`, please check whether this has already been reported in our [GitHub issue tracker](https://github.com/htop-dev/htop/issues).
|
||||
If not, please file a new issue describing the problem you have found, the potential location in the source code you are referring to and a possible fix if available.
|
||||
|
||||
## History
|
||||
|
||||
`htop` was invented, developed and maintained by Hisham Muhammad from 2004 to 2019. His [legacy repository](https://github.com/hishamhm/htop/) has been archived to preserve the history.
|
||||
`htop` was invented, developed and maintained by [Hisham Muhammad](https://hisham.hm/) from 2004 to 2019. His [legacy repository](https://github.com/hishamhm/htop/) has been archived to preserve the history.
|
||||
|
||||
In 2020 a [team](https://github.com/orgs/htop-dev/people) took over the development amicably and continues to maintain `htop` collaboratively.
|
||||
|
||||
## License
|
||||
|
||||
GNU General Public License, version 2 (GPL-2.0)
|
||||
GNU General Public License, version 2 (GPL-2.0) or, at your option, any later version.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - RichString.c
|
||||
(C) 2004,2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - RichString.h
|
||||
(C) 2004,2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
106
ScreenManager.c
106
ScreenManager.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - ScreenManager.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include "CRT.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "Macros.h"
|
||||
#include "Object.h"
|
||||
#include "Platform.h"
|
||||
#include "ProcessList.h"
|
||||
@ -49,27 +50,43 @@ inline int ScreenManager_size(const ScreenManager* this) {
|
||||
}
|
||||
|
||||
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) {
|
||||
int lastX = 0;
|
||||
if (this->panelCount > 0) {
|
||||
const Panel* last = (const Panel*) Vector_get(this->panels, this->panelCount - 1);
|
||||
if (idx > 0) {
|
||||
const Panel* last = (const Panel*) Vector_get(this->panels, idx - 1);
|
||||
lastX = last->x + last->w + 1;
|
||||
}
|
||||
int height = LINES - this->y1 - (this->header ? this->header->height : 0) + this->y2;
|
||||
if (size > 0) {
|
||||
Panel_resize(item, size, height);
|
||||
} else {
|
||||
Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height);
|
||||
if (size <= 0) {
|
||||
size = COLS - this->x1 + this->x2 - lastX;
|
||||
}
|
||||
Panel_resize(item, size, height);
|
||||
Panel_move(item, lastX, this->y1 + (this->header ? this->header->height : 0));
|
||||
Vector_add(this->panels, item);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Vector_insert(this->panels, idx, item);
|
||||
item->needsRedraw = true;
|
||||
this->panelCount++;
|
||||
}
|
||||
|
||||
Panel* ScreenManager_remove(ScreenManager* this, int idx) {
|
||||
assert(this->panelCount > idx);
|
||||
int w = ((Panel*) Vector_get(this->panels, idx))->w;
|
||||
Panel* panel = (Panel*) Vector_remove(this->panels, idx);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -88,7 +105,7 @@ void ScreenManager_resize(ScreenManager* this) {
|
||||
Panel_move(panel, lastX, y1_header);
|
||||
}
|
||||
|
||||
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) {
|
||||
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut, bool *force_redraw) {
|
||||
ProcessList* pl = this->header->pl;
|
||||
|
||||
Platform_gettime_realtime(&pl->realtime, &pl->realtimeMs);
|
||||
@ -103,13 +120,18 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
|
||||
|
||||
if (*rescan) {
|
||||
*oldTime = newTime;
|
||||
int oldUidDigits = Process_uidDigits;
|
||||
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) {
|
||||
pl->needsSort = true;
|
||||
*sortTimeout = 1;
|
||||
}
|
||||
// scan processes first - some header values are calculated there
|
||||
ProcessList_scan(pl, this->state->pauseProcessUpdate);
|
||||
// always update header, especially to avoid gaps in graph meters
|
||||
Header_updateData(this->header);
|
||||
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->treeView)) {
|
||||
ProcessList_sort(pl);
|
||||
*sortTimeout = 1;
|
||||
// force redraw if the number of UID digits was changed
|
||||
if (Process_uidDigits != oldUidDigits) {
|
||||
*force_redraw = true;
|
||||
}
|
||||
*redraw = true;
|
||||
}
|
||||
@ -120,7 +142,53 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
|
||||
*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 = MINIMUM(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, bool force_redraw) {
|
||||
if (this->settings->screenTabs) {
|
||||
ScreenManager_drawScreenTabs(this);
|
||||
}
|
||||
const int nPanels = this->panelCount;
|
||||
for (int i = 0; i < nPanels; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
@ -133,7 +201,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, const char* name) {
|
||||
bool quit = false;
|
||||
int focus = 0;
|
||||
|
||||
@ -151,9 +219,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
int sortTimeout = 0;
|
||||
int resetSortTimeout = 5;
|
||||
|
||||
this->name = name;
|
||||
|
||||
while (!quit) {
|
||||
if (this->header) {
|
||||
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
|
||||
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut, &force_redraw);
|
||||
}
|
||||
|
||||
if (redraw || force_redraw) {
|
||||
@ -162,10 +232,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
}
|
||||
|
||||
int prevCh = ch;
|
||||
#ifdef HAVE_SET_ESCDELAY
|
||||
set_escdelay(25);
|
||||
#endif
|
||||
ch = getch();
|
||||
ch = Panel_getCh(panelFocus);
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
#ifdef HAVE_GETMOUSE
|
||||
@ -184,6 +251,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
if (mevent.y == panel->y) {
|
||||
ch = EVENT_HEADER_CLICK(mevent.x - panel->x);
|
||||
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) {
|
||||
ch = KEY_MOUSE;
|
||||
if (panel == panelFocus || this->allowFocusChange) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - ScreenManager.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -22,6 +22,7 @@ typedef struct ScreenManager_ {
|
||||
int x2;
|
||||
int y2;
|
||||
Vector* panels;
|
||||
const char* name;
|
||||
int panelCount;
|
||||
Header* header;
|
||||
const Settings* settings;
|
||||
@ -37,10 +38,12 @@ int ScreenManager_size(const ScreenManager* this);
|
||||
|
||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
||||
|
||||
void ScreenManager_insert(ScreenManager* this, Panel* item, int size, int idx);
|
||||
|
||||
Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
||||
|
||||
void ScreenManager_resize(ScreenManager* this);
|
||||
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey);
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, const char* name);
|
||||
|
||||
#endif
|
||||
|
328
ScreensPanel.c
Normal file
328
ScreensPanel.c
Normal file
@ -0,0 +1,328 @@
|
||||
/*
|
||||
htop - ScreensPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2020-2022 htop dev team
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ScreensPanel.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "CRT.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "Hashtable.h"
|
||||
#include "ProvideCurses.h"
|
||||
#include "Settings.h"
|
||||
#include "XUtils.h"
|
||||
|
||||
|
||||
static void ScreenListItem_delete(Object* cast) {
|
||||
ScreenListItem* this = (ScreenListItem*)cast;
|
||||
if (this->ss) {
|
||||
ScreenSettings_delete(this->ss);
|
||||
}
|
||||
ListItem_delete(cast);
|
||||
}
|
||||
|
||||
ObjectClass ScreenListItem_class = {
|
||||
.extends = Class(ListItem),
|
||||
.display = ListItem_display,
|
||||
.delete = ScreenListItem_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;
|
||||
|
||||
/* do not delete screen settings still in use */
|
||||
int n = Panel_size(super);
|
||||
for (int i = 0; i < n; i++) {
|
||||
ScreenListItem* item = (ScreenListItem*) Panel_get(super, i);
|
||||
item->ss = NULL;
|
||||
}
|
||||
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
static HandlerResult ScreensPanel_eventHandlerRenaming(Panel* super, int ch) {
|
||||
ScreensPanel* const this = (ScreensPanel*) super;
|
||||
|
||||
if (ch >= 32 && ch < 127 && ch != '=') {
|
||||
if (this->cursor < SCREEN_NAME_LEN - 1) {
|
||||
this->buffer[this->cursor] = (char)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 '\n':
|
||||
case '\r':
|
||||
case KEY_ENTER:
|
||||
{
|
||||
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||
if (!item)
|
||||
break;
|
||||
free(this->saved);
|
||||
item->value = xStrdup(this->buffer);
|
||||
this->renaming = false;
|
||||
super->cursorOn = false;
|
||||
Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
|
||||
ScreensPanel_update(super);
|
||||
break;
|
||||
}
|
||||
case 27: // Esc
|
||||
{
|
||||
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||
if (!item)
|
||||
break;
|
||||
item->value = this->saved;
|
||||
this->renaming = false;
|
||||
super->cursorOn = false;
|
||||
Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return HANDLED;
|
||||
}
|
||||
|
||||
static void startRenaming(Panel* super) {
|
||||
ScreensPanel* const this = (ScreensPanel*) super;
|
||||
|
||||
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||
if (item == NULL)
|
||||
return;
|
||||
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, 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 = xMallocArray(n + 1, sizeof(ScreenSettings*));
|
||||
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;
|
||||
|
||||
const char* name = "New";
|
||||
ScreenSettings* ss = Settings_newScreen(this->settings, &(const ScreenDefaults){ .name = name, .columns = "PID Command", .sortKey = "PID" });
|
||||
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 '\n':
|
||||
case '\r':
|
||||
case KEY_ENTER:
|
||||
case KEY_MOUSE:
|
||||
case KEY_RECLICK:
|
||||
{
|
||||
this->moving = !(this->moving);
|
||||
Panel_setSelectionColor(super, this->moving ? PANEL_SELECTION_FOLLOW : PANEL_SELECTION_FOCUS);
|
||||
ListItem* item = (ListItem*) Panel_getSelected(super);
|
||||
if (item)
|
||||
item->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 */
|
||||
} /* FALLTHRU */
|
||||
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 */
|
||||
} /* FALLTHRU */
|
||||
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 (newFocus && oldFocus != newFocus) {
|
||||
ColumnsPanel_fill(this->columns, newFocus->ss, this->settings->dynamicColumns);
|
||||
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;
|
||||
Hashtable* columns = settings->dynamicColumns;
|
||||
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], columns, &(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->lastUpdate++;
|
||||
this->settings->screens = xReallocArray(this->settings->screens, size + 1, sizeof(ScreenSettings*));
|
||||
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;
|
||||
}
|
53
ScreensPanel.h
Normal file
53
ScreensPanel.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef HEADER_ScreensPanel
|
||||
#define HEADER_ScreensPanel
|
||||
/*
|
||||
htop - ScreensPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2020-2022 htop dev team
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "ColumnsPanel.h"
|
||||
#include "ListItem.h"
|
||||
#include "Object.h"
|
||||
#include "Panel.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "Settings.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
|
405
Settings.c
405
Settings.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
htop - Settings.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -24,18 +24,61 @@ in the source distribution for its full text.
|
||||
#include "XUtils.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
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) {
|
||||
free(this->filename);
|
||||
free(this->fields);
|
||||
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
|
||||
if (this->hColumns[i].names) {
|
||||
for (uint8_t j = 0; j < this->hColumns[i].len; j++)
|
||||
free(this->hColumns[i].names[j]);
|
||||
free(this->hColumns[i].names);
|
||||
}
|
||||
String_freeArray(this->hColumns[i].names);
|
||||
free(this->hColumns[i].modes);
|
||||
}
|
||||
free(this->hColumns);
|
||||
if (this->screens) {
|
||||
for (unsigned int i = 0; this->screens[i]; i++) {
|
||||
ScreenSettings_delete(this->screens[i]);
|
||||
}
|
||||
free(this->screens);
|
||||
}
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -65,16 +108,58 @@ static void Settings_readMeterModes(Settings* this, const char* line, unsigned i
|
||||
this->hColumns[column].modes = modes;
|
||||
}
|
||||
|
||||
static bool Settings_validateMeters(Settings* this) {
|
||||
const size_t colCount = HeaderLayout_getColumns(this->hLayout);
|
||||
|
||||
bool anyMeter = false;
|
||||
|
||||
for (size_t column = 0; column < colCount; column++) {
|
||||
char** names = this->hColumns[column].names;
|
||||
const int* modes = this->hColumns[column].modes;
|
||||
const size_t len = this->hColumns[column].len;
|
||||
|
||||
if (!len)
|
||||
continue;
|
||||
|
||||
if (!names || !modes)
|
||||
return false;
|
||||
|
||||
anyMeter |= !!len;
|
||||
|
||||
// Check for each mode there is an entry with a non-NULL name
|
||||
for (size_t meterIdx = 0; meterIdx < len; meterIdx++)
|
||||
if (!names[meterIdx])
|
||||
return false;
|
||||
|
||||
if (names[len])
|
||||
return false;
|
||||
}
|
||||
|
||||
return anyMeter;
|
||||
}
|
||||
|
||||
static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) {
|
||||
int sizes[] = { 3, 3 };
|
||||
|
||||
if (initialCpuCount > 4 && initialCpuCount <= 128) {
|
||||
sizes[1]++;
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
// Release any previously allocated memory
|
||||
for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
|
||||
String_freeArray(this->hColumns[i].names);
|
||||
free(this->hColumns[i].modes);
|
||||
}
|
||||
free(this->hColumns);
|
||||
|
||||
this->hLayout = HF_TWO_50_50;
|
||||
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
|
||||
this->hColumns[i].modes = xCalloc(sizes[i], sizeof(int));
|
||||
this->hColumns[i].len = sizes[i];
|
||||
}
|
||||
|
||||
int r = 0;
|
||||
|
||||
if (initialCpuCount > 128) {
|
||||
@ -117,43 +202,113 @@ static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount)
|
||||
this->hColumns[1].modes[r++] = TEXT_METERMODE;
|
||||
}
|
||||
|
||||
static void Settings_readFields(Settings* settings, const char* line) {
|
||||
static const char* toFieldName(Hashtable* columns, int id) {
|
||||
if (id < 0)
|
||||
return NULL;
|
||||
if (id >= LAST_PROCESSFIELD) {
|
||||
const DynamicColumn* column = DynamicColumn_lookup(columns, id);
|
||||
return column->name;
|
||||
}
|
||||
return Process_fields[id].name;
|
||||
}
|
||||
|
||||
static int toFieldIndex(Hashtable* columns, const char* str) {
|
||||
if (isdigit(str[0])) {
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
int id = atoi(str) + 1;
|
||||
if (toFieldName(columns, id)) {
|
||||
return id;
|
||||
}
|
||||
} else {
|
||||
// Dynamically-defined columns are always stored by-name.
|
||||
char dynamic[32] = {0};
|
||||
if (sscanf(str, "Dynamic(%30s)", dynamic)) {
|
||||
char* end;
|
||||
if ((end = strrchr(dynamic, ')')) != NULL) {
|
||||
bool success;
|
||||
unsigned int key;
|
||||
*end = '\0';
|
||||
success = DynamicColumn_search(columns, dynamic, &key) != NULL;
|
||||
*end = ')';
|
||||
if (success)
|
||||
return key;
|
||||
}
|
||||
}
|
||||
// Fallback to iterative scan of table of fields by-name.
|
||||
for (int p = 1; p < LAST_PROCESSFIELD; p++) {
|
||||
const char* pName = toFieldName(columns, p);
|
||||
if (pName && strcmp(pName, str) == 0)
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void ScreenSettings_readFields(ScreenSettings* ss, Hashtable* columns, const char* line) {
|
||||
char* trim = String_trim(line);
|
||||
char** ids = String_split(trim, ' ', NULL);
|
||||
free(trim);
|
||||
|
||||
settings->flags = 0;
|
||||
/* reset default fields */
|
||||
memset(ss->fields, '\0', LAST_PROCESSFIELD * sizeof(ProcessField));
|
||||
|
||||
unsigned int i, j;
|
||||
for (j = 0, i = 0; ids[i]; i++) {
|
||||
for (size_t j = 0, i = 0; ids[i]; i++) {
|
||||
if (j >= UINT_MAX / sizeof(ProcessField))
|
||||
continue;
|
||||
if (j >= LAST_PROCESSFIELD) {
|
||||
settings->fields = xRealloc(settings->fields, j * sizeof(ProcessField));
|
||||
memset(&settings->fields[j], 0, sizeof(ProcessField));
|
||||
ss->fields = xRealloc(ss->fields, (j + 1) * sizeof(ProcessField));
|
||||
memset(&ss->fields[j], 0, sizeof(ProcessField));
|
||||
}
|
||||
int id = toFieldIndex(columns, ids[i]);
|
||||
if (id >= 0)
|
||||
ss->fields[j] = id;
|
||||
if (id > 0 && id < LAST_PROCESSFIELD)
|
||||
ss->flags |= Process_fields[id].flags;
|
||||
j++;
|
||||
}
|
||||
String_freeArray(ids);
|
||||
}
|
||||
|
||||
// Dynamically-defined columns are always stored by-name.
|
||||
char* end, dynamic[32] = {0};
|
||||
if (sscanf(ids[i], "Dynamic(%30s)", dynamic)) {
|
||||
if ((end = strrchr(dynamic, ')')) == NULL)
|
||||
continue;
|
||||
*end = '\0';
|
||||
unsigned int key;
|
||||
if (!DynamicColumn_search(settings->dynamicColumns, dynamic, &key))
|
||||
continue;
|
||||
settings->fields[j++] = key;
|
||||
continue;
|
||||
ScreenSettings* Settings_newScreen(Settings* this, const ScreenDefaults* defaults) {
|
||||
int sortKey = defaults->sortKey ? toFieldIndex(this->dynamicColumns, defaults->sortKey) : PID;
|
||||
int sortDesc = (sortKey >= 0 && sortKey < LAST_PROCESSFIELD) ? Process_fields[sortKey].defaultSortDesc : 1;
|
||||
|
||||
ScreenSettings* ss = xMalloc(sizeof(ScreenSettings));
|
||||
*ss = (ScreenSettings) {
|
||||
.name = xStrdup(defaults->name),
|
||||
.fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)),
|
||||
.flags = 0,
|
||||
.direction = sortDesc ? -1 : 1,
|
||||
.treeDirection = 1,
|
||||
.sortKey = sortKey,
|
||||
.treeSortKey = PID,
|
||||
.treeView = false,
|
||||
.treeViewAlwaysByPID = false,
|
||||
.allBranchesCollapsed = false,
|
||||
};
|
||||
|
||||
ScreenSettings_readFields(ss, this->dynamicColumns, defaults->columns);
|
||||
this->screens[this->nScreens] = ss;
|
||||
this->nScreens++;
|
||||
this->screens = xRealloc(this->screens, sizeof(ScreenSettings*) * (this->nScreens + 1));
|
||||
this->screens[this->nScreens] = NULL;
|
||||
return ss;
|
||||
}
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
int id = atoi(ids[i]) + 1;
|
||||
if (id > 0 && id < LAST_PROCESSFIELD && Process_fields[id].name) {
|
||||
settings->flags |= Process_fields[id].flags;
|
||||
settings->fields[j++] = id;
|
||||
|
||||
void ScreenSettings_delete(ScreenSettings* this) {
|
||||
free(this->name);
|
||||
free(this->fields);
|
||||
free(this);
|
||||
}
|
||||
|
||||
static ScreenSettings* Settings_defaultScreens(Settings* this) {
|
||||
if (this->nScreens)
|
||||
return this->screens[0];
|
||||
for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++) {
|
||||
const ScreenDefaults* defaults = &Platform_defaultScreens[i];
|
||||
Settings_newScreen(this, defaults);
|
||||
}
|
||||
settings->fields[j] = NULL_PROCESSFIELD;
|
||||
String_freeArray(ids);
|
||||
return this->screens[0];
|
||||
}
|
||||
|
||||
static bool Settings_read(Settings* this, const char* fileName, unsigned int initialCpuCount) {
|
||||
@ -161,6 +316,7 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
|
||||
if (!fd)
|
||||
return false;
|
||||
|
||||
ScreenSettings* screen = NULL;
|
||||
bool didReadMeters = false;
|
||||
bool didReadAny = false;
|
||||
for (;;) {
|
||||
@ -180,28 +336,47 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
|
||||
this->config_version = atoi(option[1]);
|
||||
if (this->config_version > CONFIG_READER_MIN_VERSION) {
|
||||
// the version of the config file on disk is newer than what we can read
|
||||
fprintf(stderr, "WARNING: %s specifies configuration format version v%d, but this %s binary supports up to v%d.", fileName, this->config_version, PACKAGE, CONFIG_READER_MIN_VERSION);
|
||||
fprintf(stderr, " The configuration version will be downgraded to v%d when %s exits.\n", CONFIG_READER_MIN_VERSION, PACKAGE);
|
||||
fprintf(stderr, "WARNING: %s specifies configuration format\n", fileName);
|
||||
fprintf(stderr, " version v%d, but this %s binary only supports up to version v%d.\n", this->config_version, PACKAGE, CONFIG_READER_MIN_VERSION);
|
||||
fprintf(stderr, " The configuration file will be downgraded to v%d when %s exits.\n", CONFIG_READER_MIN_VERSION, PACKAGE);
|
||||
String_freeArray(option);
|
||||
fclose(fd);
|
||||
return false;
|
||||
}
|
||||
} else if (String_eq(option[0], "fields")) {
|
||||
Settings_readFields(this, option[1]);
|
||||
} else if (String_eq(option[0], "sort_key")) {
|
||||
} else if (String_eq(option[0], "fields") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
screen = Settings_defaultScreens(this);
|
||||
ScreenSettings_readFields(screen, this->dynamicColumns, option[1]);
|
||||
} else if (String_eq(option[0], "sort_key") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
this->sortKey = atoi(option[1]) + 1;
|
||||
} else if (String_eq(option[0], "tree_sort_key")) {
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->sortKey = atoi(option[1]) + 1;
|
||||
} else if (String_eq(option[0], "tree_sort_key") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
this->treeSortKey = atoi(option[1]) + 1;
|
||||
} else if (String_eq(option[0], "sort_direction")) {
|
||||
this->direction = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_sort_direction")) {
|
||||
this->treeDirection = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view")) {
|
||||
this->treeView = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view_always_by_pid")) {
|
||||
this->treeViewAlwaysByPID = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "all_branches_collapsed")) {
|
||||
this->allBranchesCollapsed = atoi(option[1]);
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->treeSortKey = atoi(option[1]) + 1;
|
||||
} else if (String_eq(option[0], "sort_direction") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->direction = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_sort_direction") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->treeDirection = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->treeView = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view_always_by_pid") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->treeViewAlwaysByPID = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "all_branches_collapsed") && this->config_version <= 2) {
|
||||
// old (no screen) naming also supported for backwards compatibility
|
||||
screen = Settings_defaultScreens(this);
|
||||
screen->allBranchesCollapsed = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
||||
this->hideKernelThreads = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_userland_threads")) {
|
||||
@ -232,6 +407,8 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
|
||||
this->showMergedCommand = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "header_margin")) {
|
||||
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")) {
|
||||
// Compatibility option.
|
||||
this->detailedCPUTime = atoi(option[1]);
|
||||
@ -297,23 +474,49 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
|
||||
} else if (String_eq(option[0], "topology_affinity")) {
|
||||
this->topologyAffinity = !!atoi(option[1]);
|
||||
#endif
|
||||
} else if (strncmp(option[0], "screen:", 7) == 0) {
|
||||
screen = Settings_newScreen(this, &(const ScreenDefaults){ .name = option[0] + 7, .columns = option[1] });
|
||||
} else if (String_eq(option[0], ".sort_key")) {
|
||||
if (screen)
|
||||
screen->sortKey = toFieldIndex(this->dynamicColumns, option[1]);
|
||||
} else if (String_eq(option[0], ".tree_sort_key")) {
|
||||
if (screen)
|
||||
screen->treeSortKey = toFieldIndex(this->dynamicColumns, option[1]);
|
||||
} else if (String_eq(option[0], ".sort_direction")) {
|
||||
if (screen)
|
||||
screen->direction = atoi(option[1]);
|
||||
} else if (String_eq(option[0], ".tree_sort_direction")) {
|
||||
if (screen)
|
||||
screen->treeDirection = atoi(option[1]);
|
||||
} else if (String_eq(option[0], ".tree_view")) {
|
||||
if (screen)
|
||||
screen->treeView = atoi(option[1]);
|
||||
} else if (String_eq(option[0], ".tree_view_always_by_pid")) {
|
||||
if (screen)
|
||||
screen->treeViewAlwaysByPID = atoi(option[1]);
|
||||
} else if (String_eq(option[0], ".all_branches_collapsed")) {
|
||||
if (screen)
|
||||
screen->allBranchesCollapsed = atoi(option[1]);
|
||||
}
|
||||
String_freeArray(option);
|
||||
}
|
||||
fclose(fd);
|
||||
if (!didReadMeters) {
|
||||
if (!didReadMeters || !Settings_validateMeters(this))
|
||||
Settings_defaultMeters(this, initialCpuCount);
|
||||
}
|
||||
if (!this->nScreens)
|
||||
Settings_defaultScreens(this);
|
||||
return didReadAny;
|
||||
}
|
||||
|
||||
static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns, const char* name, char separator) {
|
||||
fprintf(fd, "%s=", name);
|
||||
static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns, bool byName, char separator) {
|
||||
const char* sep = "";
|
||||
for (unsigned int i = 0; fields[i]; i++) {
|
||||
if (fields[i] >= LAST_PROCESSFIELD) {
|
||||
const DynamicColumn* column = DynamicColumn_lookup(columns, fields[i]);
|
||||
fprintf(fd, "%sDynamic(%s)", sep, column->name);
|
||||
if (fields[i] < LAST_PROCESSFIELD && byName) {
|
||||
const char* pName = toFieldName(columns, fields[i]);
|
||||
fprintf(fd, "%s%s", sep, pName);
|
||||
} else if (fields[i] >= LAST_PROCESSFIELD && byName) {
|
||||
const char* pName = toFieldName(columns, fields[i]);
|
||||
fprintf(fd, " Dynamic(%s)", pName);
|
||||
} else {
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
fprintf(fd, "%s%d", sep, (int) fields[i] - 1);
|
||||
@ -323,18 +526,22 @@ static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns
|
||||
fputc(separator, fd);
|
||||
}
|
||||
|
||||
static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned int column) {
|
||||
static void writeList(FILE* fd, char** list, int len, char separator) {
|
||||
const char* sep = "";
|
||||
for (uint8_t i = 0; i < this->hColumns[column].len; i++) {
|
||||
fprintf(fd, "%s%s", sep, this->hColumns[column].names[i]);
|
||||
for (int i = 0; i < len; i++) {
|
||||
fprintf(fd, "%s%s", sep, list[i]);
|
||||
sep = " ";
|
||||
}
|
||||
fputc(separator, fd);
|
||||
}
|
||||
|
||||
static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned int column) {
|
||||
writeList(fd, this->hColumns[column].names, this->hColumns[column].len, separator);
|
||||
}
|
||||
|
||||
static void writeMeterModes(const Settings* this, FILE* fd, char separator, unsigned int column) {
|
||||
const char* sep = "";
|
||||
for (uint8_t i = 0; i < this->hColumns[column].len; i++) {
|
||||
for (size_t i = 0; i < this->hColumns[column].len; i++) {
|
||||
fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]);
|
||||
sep = " ";
|
||||
}
|
||||
@ -355,9 +562,9 @@ int Settings_write(const Settings* this, bool onCrash) {
|
||||
}
|
||||
|
||||
#define printSettingInteger(setting_, value_) \
|
||||
fprintf(fd, setting_ "=%d%c", (int) value_, separator);
|
||||
fprintf(fd, setting_ "=%d%c", (int) (value_), separator)
|
||||
#define printSettingString(setting_, value_) \
|
||||
fprintf(fd, setting_ "=%s%c", value_, separator);
|
||||
fprintf(fd, setting_ "=%s%c", value_, separator)
|
||||
|
||||
if (!onCrash) {
|
||||
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
||||
@ -365,12 +572,7 @@ int Settings_write(const Settings* this, bool onCrash) {
|
||||
}
|
||||
printSettingString("htop_version", VERSION);
|
||||
printSettingInteger("config_reader_min_version", CONFIG_READER_MIN_VERSION);
|
||||
writeFields(fd, this->fields, this->dynamicColumns, "fields", separator);
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
printSettingInteger("sort_key", this->sortKey - 1);
|
||||
printSettingInteger("sort_direction", this->direction);
|
||||
printSettingInteger("tree_sort_key", this->treeSortKey - 1);
|
||||
printSettingInteger("tree_sort_direction", this->treeDirection);
|
||||
fprintf(fd, "fields="); writeFields(fd, this->screens[0]->fields, this->dynamicColumns, false, separator);
|
||||
printSettingInteger("hide_kernel_threads", this->hideKernelThreads);
|
||||
printSettingInteger("hide_userland_threads", this->hideUserlandThreads);
|
||||
printSettingInteger("shadow_other_users", this->shadowOtherUsers);
|
||||
@ -385,10 +587,8 @@ int Settings_write(const Settings* this, bool onCrash) {
|
||||
printSettingInteger("find_comm_in_cmdline", this->findCommInCmdline);
|
||||
printSettingInteger("strip_exe_from_cmdline", this->stripExeFromCmdline);
|
||||
printSettingInteger("show_merged_command", this->showMergedCommand);
|
||||
printSettingInteger("tree_view", this->treeView);
|
||||
printSettingInteger("tree_view_always_by_pid", this->treeViewAlwaysByPID);
|
||||
printSettingInteger("all_branches_collapsed", this->allBranchesCollapsed);
|
||||
printSettingInteger("header_margin", this->headerMargin);
|
||||
printSettingInteger("screen_tabs", this->screenTabs);
|
||||
printSettingInteger("detailed_cpu_time", this->detailedCPUTime);
|
||||
printSettingInteger("cpu_count_from_one", this->countCPUsFromOne);
|
||||
printSettingInteger("show_cpu_usage", this->showCPUUsage);
|
||||
@ -417,6 +617,29 @@ int Settings_write(const Settings* this, bool onCrash) {
|
||||
writeMeterModes(this, fd, separator, i);
|
||||
}
|
||||
|
||||
// Legacy compatibility with older versions of htop
|
||||
printSettingInteger("tree_view", this->screens[0]->treeView);
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
printSettingInteger("sort_key", this->screens[0]->sortKey - 1);
|
||||
printSettingInteger("tree_sort_key", this->screens[0]->treeSortKey - 1);
|
||||
printSettingInteger("sort_direction", this->screens[0]->direction);
|
||||
printSettingInteger("tree_sort_direction", this->screens[0]->treeDirection);
|
||||
printSettingInteger("tree_view_always_by_pid", this->screens[0]->treeViewAlwaysByPID);
|
||||
printSettingInteger("all_branches_collapsed", this->screens[0]->allBranchesCollapsed);
|
||||
|
||||
for (unsigned int i = 0; i < this->nScreens; i++) {
|
||||
ScreenSettings* ss = this->screens[i];
|
||||
fprintf(fd, "screen:%s=", ss->name);
|
||||
writeFields(fd, ss->fields, this->dynamicColumns, true, separator);
|
||||
printSettingString(".sort_key", toFieldName(this->dynamicColumns, ss->sortKey));
|
||||
printSettingString(".tree_sort_key", toFieldName(this->dynamicColumns, ss->treeSortKey));
|
||||
printSettingInteger(".tree_view", ss->treeView);
|
||||
printSettingInteger(".tree_view_always_by_pid", ss->treeViewAlwaysByPID);
|
||||
printSettingInteger(".sort_direction", ss->direction);
|
||||
printSettingInteger(".tree_sort_direction", ss->treeDirection);
|
||||
printSettingInteger(".all_branches_collapsed", ss->allBranchesCollapsed);
|
||||
}
|
||||
|
||||
#undef printSettingString
|
||||
#undef printSettingInteger
|
||||
|
||||
@ -440,16 +663,11 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns)
|
||||
this->dynamicColumns = dynamicColumns;
|
||||
this->hLayout = HF_TWO_50_50;
|
||||
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
|
||||
this->sortKey = PERCENT_CPU;
|
||||
this->treeSortKey = PID;
|
||||
this->direction = -1;
|
||||
this->treeDirection = 1;
|
||||
|
||||
this->shadowOtherUsers = false;
|
||||
this->showThreadNames = false;
|
||||
this->hideKernelThreads = true;
|
||||
this->hideUserlandThreads = false;
|
||||
this->treeView = false;
|
||||
this->allBranchesCollapsed = false;
|
||||
this->highlightBaseName = false;
|
||||
this->highlightDeletedExe = true;
|
||||
this->highlightMegabytes = true;
|
||||
@ -474,15 +692,9 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns)
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
this->topologyAffinity = false;
|
||||
#endif
|
||||
this->fields = xCalloc(LAST_PROCESSFIELD + 1, sizeof(ProcessField));
|
||||
// TODO: turn 'fields' into a Vector,
|
||||
// (and ProcessFields into proper objects).
|
||||
this->flags = 0;
|
||||
const ProcessField* defaults = Platform_defaultFields;
|
||||
for (int i = 0; defaults[i]; i++) {
|
||||
this->fields[i] = defaults[i];
|
||||
this->flags |= Process_fields[defaults[i]].flags;
|
||||
}
|
||||
|
||||
this->screens = xCalloc(Platform_numberOfDefaultScreens * sizeof(ScreenSettings*), 1);
|
||||
this->nScreens = 0;
|
||||
|
||||
char* legacyDotfile = NULL;
|
||||
const char* rcfile = getenv("HTOPRC");
|
||||
@ -538,18 +750,29 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns)
|
||||
ok = Settings_read(this, this->filename, initialCpuCount);
|
||||
}
|
||||
if (!ok) {
|
||||
this->screenTabs = true;
|
||||
this->changed = true;
|
||||
Settings_read(this, SYSCONFDIR "/htoprc", initialCpuCount);
|
||||
ok = Settings_read(this, SYSCONFDIR "/htoprc", initialCpuCount);
|
||||
}
|
||||
if (!ok) {
|
||||
Settings_defaultMeters(this, initialCpuCount);
|
||||
Settings_defaultScreens(this);
|
||||
}
|
||||
|
||||
this->ssIndex = 0;
|
||||
this->ss = this->screens[this->ssIndex];
|
||||
|
||||
this->lastUpdate = 1;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void Settings_invertSortOrder(Settings* this) {
|
||||
void ScreenSettings_invertSortOrder(ScreenSettings* this) {
|
||||
int* attr = (this->treeView) ? &(this->treeDirection) : &(this->direction);
|
||||
*attr = (*attr == 1) ? -1 : 1;
|
||||
}
|
||||
|
||||
void Settings_setSortKey(Settings* this, ProcessField sortKey) {
|
||||
void ScreenSettings_setSortKey(ScreenSettings* this, ProcessField sortKey) {
|
||||
if (this->treeViewAlwaysByPID || !this->treeView) {
|
||||
this->sortKey = sortKey;
|
||||
this->direction = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1;
|
||||
@ -580,7 +803,7 @@ void Settings_setHeaderLayout(Settings* this, HeaderLayout hLayout) {
|
||||
} else if (newColumns < oldColumns) {
|
||||
for (unsigned int i = newColumns; i < oldColumns; i++) {
|
||||
if (this->hColumns[i].names) {
|
||||
for (uint8_t j = 0; j < this->hColumns[i].len; j++)
|
||||
for (size_t j = 0; j < this->hColumns[i].len; j++)
|
||||
free(this->hColumns[i].names[j]);
|
||||
free(this->hColumns[i].names);
|
||||
}
|
||||
|
54
Settings.h
54
Settings.h
@ -3,7 +3,7 @@
|
||||
/*
|
||||
htop - Settings.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
@ -19,14 +19,33 @@ in the source distribution for its full text.
|
||||
|
||||
#define DEFAULT_DELAY 15
|
||||
|
||||
#define CONFIG_READER_MIN_VERSION 2
|
||||
#define CONFIG_READER_MIN_VERSION 3
|
||||
|
||||
typedef struct {
|
||||
uint8_t len;
|
||||
const char* name;
|
||||
const char* columns;
|
||||
const char* sortKey;
|
||||
} ScreenDefaults;
|
||||
|
||||
typedef struct {
|
||||
size_t len;
|
||||
char** names;
|
||||
int* modes;
|
||||
} MeterColumnSetting;
|
||||
|
||||
typedef struct {
|
||||
char* name;
|
||||
ProcessField* fields;
|
||||
uint32_t flags;
|
||||
int direction;
|
||||
int treeDirection;
|
||||
ProcessField sortKey;
|
||||
ProcessField treeSortKey;
|
||||
bool treeView;
|
||||
bool treeViewAlwaysByPID;
|
||||
bool allBranchesCollapsed;
|
||||
} ScreenSettings;
|
||||
|
||||
typedef struct Settings_ {
|
||||
char* filename;
|
||||
int config_version;
|
||||
@ -34,16 +53,14 @@ typedef struct Settings_ {
|
||||
MeterColumnSetting* hColumns;
|
||||
Hashtable* dynamicColumns;
|
||||
|
||||
ProcessField* fields;
|
||||
uint32_t flags;
|
||||
ScreenSettings** screens;
|
||||
unsigned int nScreens;
|
||||
unsigned int ssIndex;
|
||||
ScreenSettings* ss;
|
||||
|
||||
int colorScheme;
|
||||
int delay;
|
||||
|
||||
int direction;
|
||||
int treeDirection;
|
||||
ProcessField sortKey;
|
||||
ProcessField treeSortKey;
|
||||
|
||||
bool countCPUsFromOne;
|
||||
bool detailedCPUTime;
|
||||
bool showCPUUsage;
|
||||
@ -52,9 +69,6 @@ typedef struct Settings_ {
|
||||
bool showCPUTemperature;
|
||||
bool degreeFahrenheit;
|
||||
#endif
|
||||
bool treeView;
|
||||
bool treeViewAlwaysByPID;
|
||||
bool allBranchesCollapsed;
|
||||
bool showProgramPath;
|
||||
bool shadowOtherUsers;
|
||||
bool showThreadNames;
|
||||
@ -72,6 +86,7 @@ typedef struct Settings_ {
|
||||
bool updateProcessNames;
|
||||
bool accountGuestInCPUMeter;
|
||||
bool headerMargin;
|
||||
bool screenTabs;
|
||||
#ifdef HAVE_GETMOUSE
|
||||
bool enableMouse;
|
||||
#endif
|
||||
@ -81,17 +96,18 @@ typedef struct Settings_ {
|
||||
#endif
|
||||
|
||||
bool changed;
|
||||
uint64_t lastUpdate;
|
||||
} Settings;
|
||||
|
||||
#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromOne ? (cpu)+1 : (cpu))
|
||||
|
||||
static inline ProcessField Settings_getActiveSortKey(const Settings* this) {
|
||||
static inline ProcessField ScreenSettings_getActiveSortKey(const ScreenSettings* this) {
|
||||
return (this->treeView)
|
||||
? (this->treeViewAlwaysByPID ? PID : this->treeSortKey)
|
||||
: this->sortKey;
|
||||
}
|
||||
|
||||
static inline int Settings_getActiveDirection(const Settings* this) {
|
||||
static inline int ScreenSettings_getActiveDirection(const ScreenSettings* this) {
|
||||
return this->treeView ? this->treeDirection : this->direction;
|
||||
}
|
||||
|
||||
@ -101,9 +117,13 @@ int Settings_write(const Settings* this, bool onCrash);
|
||||
|
||||
Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns);
|
||||
|
||||
void Settings_invertSortOrder(Settings* this);
|
||||
ScreenSettings* Settings_newScreen(Settings* this, const ScreenDefaults* defaults);
|
||||
|
||||
void Settings_setSortKey(Settings* this, ProcessField sortKey);
|
||||
void ScreenSettings_delete(ScreenSettings* this);
|
||||
|
||||
void ScreenSettings_invertSortOrder(ScreenSettings* this);
|
||||
|
||||
void ScreenSettings_setSortKey(ScreenSettings* this, ProcessField sortKey);
|
||||
|
||||
void Settings_enableReadonly(void);
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
/*
|
||||
htop - SignalsPanel.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "SignalsPanel.h"
|
||||
// the above contains #include <signal.h> so do not add that here again (breaks Solaris build)
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "FunctionBar.h"
|
||||
@ -18,15 +18,14 @@ in the source distribution for its full text.
|
||||
#include "XUtils.h"
|
||||
|
||||
|
||||
Panel* SignalsPanel_new() {
|
||||
Panel* SignalsPanel_new(int preSelectedSignal) {
|
||||
Panel* this = Panel_new(1, 1, 1, 1, Class(ListItem), true, FunctionBar_newEnterEsc("Send ", "Cancel "));
|
||||
const int defaultSignal = SIGTERM;
|
||||
int defaultPosition = 15;
|
||||
unsigned int i;
|
||||
for (i = 0; i < Platform_numberOfSignals; i++) {
|
||||
Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
|
||||
// signal 15 is not always the 15th signal in the table
|
||||
if (Platform_signals[i].number == defaultSignal) {
|
||||
if (Platform_signals[i].number == preSelectedSignal) {
|
||||
defaultPosition = i;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,16 @@
|
||||
/*
|
||||
htop - SignalsPanel.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPLv2, see the COPYING file
|
||||
Released under the GNU GPLv2+, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#ifndef HTOP_SOLARIS
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "Panel.h"
|
||||
|
||||
|
||||
@ -15,6 +21,8 @@ typedef struct SignalItem_ {
|
||||
int number;
|
||||
} SignalItem;
|
||||
|
||||
Panel* SignalsPanel_new(void);
|
||||
#define SIGNALSPANEL_INITSELECTEDSIGNAL SIGTERM
|
||||
|
||||
Panel* SignalsPanel_new(int preSelectedSignal);
|
||||
|
||||
#endif
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user