mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 13:34:35 +03:00
Compare commits
533 Commits
Author | SHA1 | Date | |
---|---|---|---|
f80e577c59 | |||
81552d4ab5 | |||
265d04821a | |||
78b82d0fdc | |||
7f9c82f28d | |||
7d5ef246f1 | |||
0fa03322a9 | |||
52f814481c | |||
b139671cbd | |||
adcc944e35 | |||
a5ef374bb8 | |||
6dd32d3604 | |||
8cd045cc79 | |||
0128d222b9 | |||
1a13b4d0f4 | |||
9ec41d1b65 | |||
c0e37bc5f5 | |||
f9c1db514d | |||
3297616efa | |||
e288f690af | |||
ea9dc4ab74 | |||
112db9a609 | |||
5db1b0e9a0 | |||
4674b4a732 | |||
7ededce9b5 | |||
3126cfce6c | |||
313b3d3752 | |||
fa0c637c55 | |||
b7ac416634 | |||
6cc0a8c820 | |||
645057d81a | |||
6c1be63291 | |||
642ccb49ca | |||
6028e1b4c4 | |||
95d1984339 | |||
c0df404701 | |||
b71b07f5e0 | |||
f0df28a470 | |||
7d72715a6b | |||
54621e8b8f | |||
572546f806 | |||
d464be13db | |||
759caf0f8f | |||
cdc91b0b33 | |||
1754a1cd48 | |||
8e6ffdb0ab | |||
c37be409a9 | |||
fa1b5d1e2e | |||
19f0f4db27 | |||
9dea20e068 | |||
2ea4bee66d | |||
1809f4be98 | |||
5776cb56b4 | |||
74f8b31040 | |||
4d3f483b96 | |||
2de52862a6 | |||
a9508275cc | |||
306c5443ae | |||
d15555ed2c | |||
d64f2bdd56 | |||
6c2f698a47 | |||
7b3c8bc77a | |||
3a4c0fa2d6 | |||
328de35623 | |||
c8a735e471 | |||
99fb3070a2 | |||
7d3f67e822 | |||
3283c6d23c | |||
8a928c8b89 | |||
f295a52ed9 | |||
e2ccc7b240 | |||
ef1e62d1fa | |||
453105e77a | |||
db80f202f2 | |||
98e43816a5 | |||
694addceb5 | |||
4623394456 | |||
4ad7aa6432 | |||
4b780a3499 | |||
b08cb7352e | |||
b886ecc479 | |||
63c55854e5 | |||
4f1bd232d8 | |||
84a69b1ea4 | |||
e77811e99b | |||
0a4a447d0d | |||
cc8375f9ea | |||
03af73bbc7 | |||
0cf3cfa3af | |||
797bcd0961 | |||
baec4bdcb0 | |||
a8a5e62760 | |||
f5ddb974a1 | |||
565101234a | |||
d4741d5410 | |||
9668cd11ed | |||
c23d4f12d1 | |||
34431dc7fd | |||
42c4459375 | |||
48254f92e4 | |||
5ee6715843 | |||
c18309466d | |||
fe0ad86e6d | |||
dc4f145629 | |||
d43e709364 | |||
0627a5f0e9 | |||
d10f4f615a | |||
e0c364b9cc | |||
fd216309d9 | |||
474d26cea8 | |||
471cd60635 | |||
f554f08fa9 | |||
d753996b96 | |||
b10278318b | |||
35657208d7 | |||
ae823c375a | |||
1b5025e6f5 | |||
c66ac09a66 | |||
0b70439316 | |||
e9b32eb62f | |||
3b9a4b1024 | |||
0e3cf6975f | |||
a618f477b2 | |||
cc4267cc5c | |||
d0d14da8d9 | |||
1bedac1ca2 | |||
011bf30d22 | |||
c56b1a8830 | |||
01edfcf4d4 | |||
d916f6e6f0 | |||
e46488463d | |||
8fa9da47de | |||
d408c74465 | |||
bb0333e45d | |||
b6f927bffa | |||
f1d1d6e0d6 | |||
563d5d3ab9 | |||
f1f805f29f | |||
807640e49b | |||
5c593fae42 | |||
d311e85b91 | |||
c148907e7b | |||
820c079b14 | |||
f87462d60e | |||
b2c2b2bfb3 | |||
ffcf48fb74 | |||
1cfcc42a8f | |||
b54d2dde40 | |||
301c346c85 | |||
21da044fb4 | |||
6434db5b6b | |||
a1f7f2869e | |||
dcfcae1ed4 | |||
040613db33 | |||
d54ab24d97 | |||
09cf369f2b | |||
6dae8108f8 | |||
195f5edbc8 | |||
d312510223 | |||
9c39422c71 | |||
99b947058f | |||
466d4da0c6 | |||
faf2860669 | |||
032af1577c | |||
d850803eb8 | |||
c6ca311d18 | |||
fc61e25f5b | |||
4b29e8485f | |||
b14f89e9d4 | |||
b10e54cdee | |||
fc4c9757b0 | |||
82db9979b1 | |||
4c23a81d72 | |||
6bc98bb227 | |||
e595f6865e | |||
3ad2510fc2 | |||
be6b0c2830 | |||
f342a9eb83 | |||
c5b9045f18 | |||
77cffaacf6 | |||
9ca646acbb | |||
61f2d674b0 | |||
198592a0f1 | |||
be9edc5d43 | |||
70cd5c2b88 | |||
86954f9204 | |||
fe83bc8e68 | |||
918cfd54d6 | |||
3da36bbc61 | |||
c1b3289219 | |||
ae5c01f485 | |||
7170382706 | |||
22cfda6332 | |||
c8cadfb905 | |||
526eca9a19 | |||
adaa4de295 | |||
71ad9b304d | |||
c67e482c67 | |||
802e216870 | |||
e0b6e2eef2 | |||
9d55c56f26 | |||
80f594f314 | |||
c2769985cc | |||
bc84920b91 | |||
563abbc44b | |||
065aab5247 | |||
cccc18dd2f | |||
84783bd6f0 | |||
db6828617d | |||
ab3a7c2fa8 | |||
6b1b073ae4 | |||
c23770245e | |||
cc23d13f87 | |||
42b08f2233 | |||
0919ea32f9 | |||
d18e9a4895 | |||
670a2de692 | |||
96c929f82b | |||
a84aa2e782 | |||
5bc1f5ed04 | |||
d34645f8f1 | |||
f02d8f4386 | |||
aae02bbfc9 | |||
5521094b1e | |||
347141502b | |||
0837fc5b62 | |||
d12084b032 | |||
c24270be0a | |||
d820d11c80 | |||
4b83a82dca | |||
ad5d9c2542 | |||
8895f09880 | |||
f097bdce8f | |||
1e31b63a7e | |||
33cdaf3ac0 | |||
bef00a4fd9 | |||
5e0f1788e6 | |||
a7fcbba75a | |||
3cfbcb72c8 | |||
f187be9296 | |||
fd5dd6605a | |||
cd3d2337f8 | |||
0fb9a8c389 | |||
b669540e4e | |||
ea8a8b2d6b | |||
bd93b2e1d7 | |||
71190654bc | |||
9c146393a3 | |||
57333d8a47 | |||
78f2933e2b | |||
8673a84e5f | |||
9f1884c28f | |||
e906c0dddb | |||
93f05b459f | |||
23bf564d73 | |||
214d0cff0d | |||
3ea7b34735 | |||
cc0fc3655d | |||
56193323ce | |||
ee0d602a47 | |||
125c23ef23 | |||
384c92f7e4 | |||
c4eb99f264 | |||
77f12bbecd | |||
2379835910 | |||
86417e4157 | |||
7859857fdd | |||
3fe2f3e28e | |||
fbb4c49edd | |||
bf276a0993 | |||
5c2b0a6bbc | |||
1cda2d7397 | |||
68c3270be8 | |||
8c00fa4582 | |||
2d1507ad5a | |||
6a21d2f3a6 | |||
ad1a0ad08d | |||
571cbc0aa1 | |||
e2bbd5cfa4 | |||
c5d725daf9 | |||
9c14fa6fad | |||
a9a5a539cf | |||
b0e074f6b6 | |||
02727bda81 | |||
445222e48c | |||
b37d4f172f | |||
40525d85bc | |||
661a4cec4a | |||
1d805b36b4 | |||
8e81119c33 | |||
0c2ccde306 | |||
a92f803903 | |||
e52c070ef5 | |||
ffacac14a9 | |||
229d005851 | |||
e8970b6f32 | |||
2df36ee2f2 | |||
bf456972b7 | |||
a859e9204c | |||
08392ce5d3 | |||
ba3504fa26 | |||
804bd37dca | |||
8a2dd83efa | |||
a008cb73a4 | |||
7985724933 | |||
bdadd45a88 | |||
bde3406add | |||
3c4326b450 | |||
6082db2121 | |||
f6c31eeaf5 | |||
f6d48c172c | |||
696e36cb45 | |||
f585fc9825 | |||
79356dc125 | |||
cf47f4fca1 | |||
6f58fbc5dd | |||
f3a9f5406b | |||
93b811a051 | |||
f10cbaa812 | |||
8f07868fef | |||
0507cd38f7 | |||
544c7efa6b | |||
c7387fac15 | |||
4597014ea3 | |||
f019f4cd9e | |||
ea18a50091 | |||
c9cab824e9 | |||
5e4f1e46cc | |||
9428010121 | |||
8bd603cb68 | |||
78be8201dc | |||
b003636958 | |||
a2a34e89a1 | |||
d8e23bb084 | |||
9e67b6585e | |||
3e93f9b852 | |||
f70649a178 | |||
907f8298a0 | |||
57ab332d5a | |||
6463ea2956 | |||
7f3faa276a | |||
43ef703f03 | |||
70e7c8db59 | |||
feb7a01fd3 | |||
5e602f18d5 | |||
f2c053a884 | |||
0ebe688d24 | |||
e1e3ffad19 | |||
4d44c35519 | |||
4e135bb6b6 | |||
2ed83d6902 | |||
041fa9ffa6 | |||
c34b574073 | |||
e42d78007e | |||
fc0e44662c | |||
293eec4265 | |||
c33d32e66b | |||
6f6f0e36ad | |||
cea591181d | |||
1bdee6b6ba | |||
77df258636 | |||
1728483aa2 | |||
016dbbe6a4 | |||
ff49f558b2 | |||
e5f810e0a2 | |||
a588c6d179 | |||
b1aea7f748 | |||
5f60486002 | |||
67a88ae11d | |||
b796362e90 | |||
a804f1f848 | |||
03826fbc54 | |||
16d8cc7c38 | |||
abe165fe5c | |||
2351fdea31 | |||
75d0eda6f9 | |||
d7c3dc748f | |||
5a5dc71770 | |||
1efa544e1b | |||
a8e1c1c63f | |||
867dece8fe | |||
08829cbc3b | |||
f1e8a074f2 | |||
f4f6d54ffd | |||
64ecba2583 | |||
ac8b934498 | |||
01737ed66b | |||
2f45008477 | |||
b291fba02b | |||
dc4576d327 | |||
b1f934c5d5 | |||
01a29f0267 | |||
094ddc4051 | |||
d4256d6300 | |||
fde3457235 | |||
86d5750451 | |||
e3d1ca0d20 | |||
4e29cad4fe | |||
e5b08447fe | |||
d880def0e9 | |||
4315e0c2a0 | |||
1179906e95 | |||
cb8ac6b0f1 | |||
a7236559a7 | |||
4c24a9b462 | |||
5320bab202 | |||
849adf6155 | |||
99e58b3200 | |||
4eee71051b | |||
2939a84ea3 | |||
63aa02c7a9 | |||
80ef119fe7 | |||
70abaadbaf | |||
a93db5234c | |||
38fd1bfaba | |||
7cb8cb05fb | |||
8a11281c67 | |||
b1b3f57976 | |||
54f8d8154b | |||
ade7993fcb | |||
d0c72c3fb2 | |||
442a0d33e4 | |||
1084a3ff8f | |||
09c7152990 | |||
1e0c530a46 | |||
4e064e0db7 | |||
272e2d9b34 | |||
9ff5d2b243 | |||
14a177800b | |||
59914bfd5b | |||
7fd4af80ff | |||
5c8b83405b | |||
ddbb71d1c8 | |||
adbfe3c3f1 | |||
40f3391a3c | |||
be1700cf94 | |||
a44a64d0ee | |||
bc928d7f47 | |||
967b6569a1 | |||
d2acffa59a | |||
e3fe3962cb | |||
e7d6eb6a82 | |||
a4b03e8875 | |||
39a725abc2 | |||
0a184b769f | |||
50000d808e | |||
8b5b73825e | |||
9780c312f4 | |||
cce2202a1f | |||
5ca9b8e002 | |||
6f868b00c0 | |||
f97d1bc54a | |||
aed9b9d18e | |||
cc26974129 | |||
574c3decb5 | |||
4a26ac05b0 | |||
cfc773f7ee | |||
6302b3e593 | |||
d7c843c23b | |||
14bd77c5f4 | |||
f5f29ceeb9 | |||
c3a7b2f134 | |||
83a829a286 | |||
c2108e5a48 | |||
3383d8e556 | |||
36b7832884 | |||
c29e53c5d5 | |||
d4c26a3932 | |||
d20160cb4f | |||
430c7c9a9b | |||
f4c49ff92e | |||
da0956d1cd | |||
03ca7da85f | |||
b4f6b11092 | |||
a89758094f | |||
6d92d7f73d | |||
96e03739c4 | |||
5578a316f0 | |||
529095607c | |||
e748401588 | |||
3ba3d6fa6f | |||
1dd165c14b | |||
ca03094bb2 | |||
2dcdd87658 | |||
a9f05c2a8b | |||
79662291fa | |||
357e7a3243 | |||
b192af006f | |||
0aa485cf47 | |||
d8f2b5abf7 | |||
cda6bdd56b | |||
28712f22b1 | |||
8a2e235a48 | |||
ff4d1b466f | |||
6afacee50d | |||
8915b29395 | |||
a75161f862 | |||
aaaaf063a1 | |||
26422af608 | |||
eb229d9aef | |||
1eda099d06 | |||
9faf4938b8 | |||
300af4b829 | |||
66ec872fc6 | |||
b2e94d626d | |||
64e0d9452d | |||
ab0bceb550 | |||
0e8a02367e | |||
eb196f8ba4 | |||
e4882ed9fb | |||
0fc388f2ee | |||
0341cb3b5f | |||
56cf323ccf | |||
afe0c8cb45 | |||
bbd62c1929 | |||
9ba8e2ed05 | |||
4eeb9d5e64 | |||
8a1c304bed | |||
b7de9bd0f5 | |||
f0e2a0e771 | |||
730ab0c9a8 | |||
ff6cddfd16 | |||
da16de5a86 | |||
4939468df0 | |||
7f92c58916 | |||
f54a37b4a9 | |||
c3e66b2d81 | |||
ebd5de37ac | |||
78d09f955a | |||
d7e5020169 | |||
ea191b53bd | |||
88c3758051 | |||
c8be3701b8 |
16
.editorconfig
Normal file
16
.editorconfig
Normal file
@ -0,0 +1,16 @@
|
||||
# EditorConfig configuration for htop
|
||||
# http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file, utf-8 charset
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
|
||||
# match C source and header files, set indent to three spaces
|
||||
[*.{c,h}]
|
||||
indent_style = space
|
||||
indent_size = 3
|
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# the binary:
|
||||
htop
|
||||
|
||||
# all object files
|
||||
*.o
|
||||
|
||||
*.gcda
|
||||
*/*.gcda
|
||||
*.gcno
|
||||
*/*.gcno
|
||||
*.h.gch
|
||||
*/.dirstamp
|
||||
|
||||
.deps/
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
compile
|
||||
config.guess
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
config.status
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
htop.1
|
||||
install-sh
|
||||
libtool
|
||||
ltmain.sh
|
||||
m4/
|
||||
missing
|
||||
stamp-h1
|
||||
|
11
.travis.yml
Normal file
11
.travis.yml
Normal file
@ -0,0 +1,11 @@
|
||||
language: c
|
||||
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
script: ./autogen.sh && ./configure && make
|
575
Action.c
Normal file
575
Action.c
Normal file
@ -0,0 +1,575 @@
|
||||
/*
|
||||
htop - Action.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "Action.h"
|
||||
#include "Affinity.h"
|
||||
#include "AffinityPanel.h"
|
||||
#include "CategoriesPanel.h"
|
||||
#include "CRT.h"
|
||||
#include "EnvScreen.h"
|
||||
#include "MainPanel.h"
|
||||
#include "OpenFilesScreen.h"
|
||||
#include "Process.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "StringUtils.h"
|
||||
#include "TraceScreen.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/*{
|
||||
|
||||
#include "IncSet.h"
|
||||
#include "Settings.h"
|
||||
#include "Header.h"
|
||||
#include "UsersTable.h"
|
||||
#include "ProcessList.h"
|
||||
#include "Panel.h"
|
||||
|
||||
typedef enum {
|
||||
HTOP_OK = 0x00,
|
||||
HTOP_REFRESH = 0x01,
|
||||
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
|
||||
HTOP_SAVE_SETTINGS = 0x04,
|
||||
HTOP_KEEP_FOLLOWING = 0x08,
|
||||
HTOP_QUIT = 0x10,
|
||||
HTOP_REDRAW_BAR = 0x20,
|
||||
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
|
||||
} Htop_Reaction;
|
||||
|
||||
typedef Htop_Reaction (*Htop_Action)();
|
||||
|
||||
typedef struct State_ {
|
||||
Settings* settings;
|
||||
UsersTable* ut;
|
||||
ProcessList* pl;
|
||||
Panel* panel;
|
||||
Header* header;
|
||||
} State;
|
||||
|
||||
}*/
|
||||
|
||||
Object* Action_pickFromVector(State* st, Panel* list, int x) {
|
||||
Panel* panel = st->panel;
|
||||
Header* header = st->header;
|
||||
Settings* settings = st->settings;
|
||||
|
||||
int y = panel->y;
|
||||
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false);
|
||||
scr->allowFocusChange = false;
|
||||
ScreenManager_add(scr, list, x - 1);
|
||||
ScreenManager_add(scr, panel, -1);
|
||||
Panel* panelFocus;
|
||||
int ch;
|
||||
bool unfollow = false;
|
||||
int pid = MainPanel_selectedPid((MainPanel*)panel);
|
||||
if (header->pl->following == -1) {
|
||||
header->pl->following = pid;
|
||||
unfollow = true;
|
||||
}
|
||||
ScreenManager_run(scr, &panelFocus, &ch);
|
||||
if (unfollow) {
|
||||
header->pl->following = -1;
|
||||
}
|
||||
ScreenManager_delete(scr);
|
||||
Panel_move(panel, 0, y);
|
||||
Panel_resize(panel, COLS, LINES-y-1);
|
||||
if (panelFocus == list && ch == 13) {
|
||||
Process* selected = (Process*)Panel_getSelected(panel);
|
||||
if (selected && selected->pid == pid)
|
||||
return Panel_getSelected(list);
|
||||
else
|
||||
beep();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
static void Action_runSetup(Settings* settings, const Header* header, ProcessList* pl) {
|
||||
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true);
|
||||
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, (Header*) header, pl);
|
||||
ScreenManager_add(scr, (Panel*) panelCategories, 16);
|
||||
CategoriesPanel_makeMetersPage(panelCategories);
|
||||
Panel* panelFocus;
|
||||
int ch;
|
||||
ScreenManager_run(scr, &panelFocus, &ch);
|
||||
ScreenManager_delete(scr);
|
||||
if (settings->changed) {
|
||||
Header_writeBackToSettings(header);
|
||||
}
|
||||
}
|
||||
|
||||
static bool changePriority(MainPanel* panel, int delta) {
|
||||
bool anyTagged;
|
||||
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged);
|
||||
if (!ok)
|
||||
beep();
|
||||
return anyTagged;
|
||||
}
|
||||
|
||||
static void addUserToVector(int key, void* userCast, void* panelCast) {
|
||||
char* user = (char*) userCast;
|
||||
Panel* panel = (Panel*) panelCast;
|
||||
Panel_add(panel, (Object*) ListItem_new(user, key));
|
||||
}
|
||||
|
||||
bool Action_setUserOnly(const char* userName, uid_t* userId) {
|
||||
struct passwd* user = getpwnam(userName);
|
||||
if (user) {
|
||||
*userId = user->pw_uid;
|
||||
return true;
|
||||
}
|
||||
*userId = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void tagAllChildren(Panel* panel, Process* parent) {
|
||||
parent->tag = true;
|
||||
pid_t ppid = parent->pid;
|
||||
for (int i = 0; i < Panel_size(panel); i++) {
|
||||
Process* p = (Process*) Panel_get(panel, i);
|
||||
if (!p->tag && p->ppid == ppid) {
|
||||
tagAllChildren(panel, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool expandCollapse(Panel* panel) {
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (!p) return false;
|
||||
p->showChildren = !p->showChildren;
|
||||
return true;
|
||||
}
|
||||
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||
settings->sortKey = sortKey;
|
||||
settings->direction = 1;
|
||||
settings->treeView = false;
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction sortBy(State* st) {
|
||||
Htop_Reaction reaction = HTOP_OK;
|
||||
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_newEnterEsc("Sort ", "Cancel "));
|
||||
Panel_setHeader(sortPanel, "Sort by");
|
||||
ProcessField* fields = st->settings->fields;
|
||||
for (int i = 0; fields[i]; i++) {
|
||||
char* name = String_trim(Process_fields[fields[i]].name);
|
||||
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
||||
if (fields[i] == st->settings->sortKey)
|
||||
Panel_setSelected(sortPanel, i);
|
||||
free(name);
|
||||
}
|
||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
|
||||
if (field) {
|
||||
reaction |= Action_setSortKey(st->settings, field->key);
|
||||
}
|
||||
Object_delete(sortPanel);
|
||||
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
static Htop_Reaction actionResize(State* st) {
|
||||
Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1);
|
||||
return HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionSortByMemory(State* st) {
|
||||
return Action_setSortKey(st->settings, PERCENT_MEM);
|
||||
}
|
||||
|
||||
static Htop_Reaction actionSortByCPU(State* st) {
|
||||
return Action_setSortKey(st->settings, PERCENT_CPU);
|
||||
}
|
||||
|
||||
static Htop_Reaction actionSortByTime(State* st) {
|
||||
return Action_setSortKey(st->settings, TIME);
|
||||
}
|
||||
|
||||
static Htop_Reaction actionToggleKernelThreads(State* st) {
|
||||
st->settings->hideKernelThreads = !st->settings->hideKernelThreads;
|
||||
return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionToggleUserlandThreads(State* st) {
|
||||
st->settings->hideUserlandThreads = !st->settings->hideUserlandThreads;
|
||||
st->settings->hideThreads = st->settings->hideUserlandThreads;
|
||||
return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionToggleProgramPath(State* st) {
|
||||
st->settings->showProgramPath = !st->settings->showProgramPath;
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionToggleTreeView(State* st) {
|
||||
st->settings->treeView = !st->settings->treeView;
|
||||
if (st->settings->treeView) st->settings->direction = 1;
|
||||
ProcessList_expandTree(st->pl);
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionIncFilter(State* st) {
|
||||
IncSet* inc = ((MainPanel*)st->panel)->inc;
|
||||
IncSet_activate(inc, INC_FILTER, st->panel);
|
||||
st->pl->incFilter = IncSet_filter(inc);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionIncSearch(State* st) {
|
||||
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionHigherPriority(State* st) {
|
||||
bool changed = changePriority((MainPanel*)st->panel, -1);
|
||||
return changed ? HTOP_REFRESH : HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionLowerPriority(State* st) {
|
||||
bool changed = changePriority((MainPanel*)st->panel, 1);
|
||||
return changed ? HTOP_REFRESH : HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionInvertSortOrder(State* st) {
|
||||
Settings_invertSortOrder(st->settings);
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionSetSortColumn(State* st) {
|
||||
return sortBy(st);
|
||||
}
|
||||
|
||||
static Htop_Reaction actionExpandOrCollapse(State* st) {
|
||||
bool changed = expandCollapse(st->panel);
|
||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||
return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||
}
|
||||
|
||||
static Htop_Reaction actionQuit() {
|
||||
return HTOP_QUIT;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionSetAffinity(State* st) {
|
||||
if (st->pl->cpuCount == 1)
|
||||
return HTOP_OK;
|
||||
#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY)
|
||||
Panel* panel = st->panel;
|
||||
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (!p) return HTOP_OK;
|
||||
Affinity* affinity = Affinity_get(p, st->pl);
|
||||
if (!affinity) return HTOP_OK;
|
||||
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
|
||||
Affinity_delete(affinity);
|
||||
|
||||
void* set = Action_pickFromVector(st, affinityPanel, 15);
|
||||
if (set) {
|
||||
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL);
|
||||
if (!ok) beep();
|
||||
Affinity_delete(affinity);
|
||||
}
|
||||
Panel_delete((Object*)affinityPanel);
|
||||
#endif
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionKill(State* st) {
|
||||
Panel* signalsPanel = (Panel*) SignalsPanel_new();
|
||||
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15);
|
||||
if (sgn) {
|
||||
if (sgn->key != 0) {
|
||||
Panel_setHeader(st->panel, "Sending...");
|
||||
Panel_draw(st->panel, true);
|
||||
refresh();
|
||||
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL);
|
||||
napms(500);
|
||||
}
|
||||
}
|
||||
Panel_delete((Object*)signalsPanel);
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionFilterByUser(State* st) {
|
||||
Panel* usersPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_newEnterEsc("Show ", "Cancel "));
|
||||
Panel_setHeader(usersPanel, "Show processes of:");
|
||||
UsersTable_foreach(st->ut, addUserToVector, usersPanel);
|
||||
Vector_insertionSort(usersPanel->items);
|
||||
ListItem* allUsers = ListItem_new("All users", -1);
|
||||
Panel_insert(usersPanel, 0, (Object*) allUsers);
|
||||
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20);
|
||||
if (picked) {
|
||||
if (picked == allUsers) {
|
||||
st->pl->userId = -1;
|
||||
} else {
|
||||
Action_setUserOnly(ListItem_getRef(picked), &(st->pl->userId));
|
||||
}
|
||||
}
|
||||
Panel_delete((Object*)usersPanel);
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
Htop_Reaction Action_follow(State* st) {
|
||||
st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
|
||||
Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
||||
return HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionSetup(State* st) {
|
||||
Action_runSetup(st->settings, st->header, st->pl);
|
||||
// TODO: shouldn't need this, colors should be dynamic
|
||||
int headerHeight = Header_calculateHeight(st->header);
|
||||
Panel_move(st->panel, 0, headerHeight);
|
||||
Panel_resize(st->panel, COLS, LINES-headerHeight-1);
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionLsof(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
OpenFilesScreen* ofs = OpenFilesScreen_new(p);
|
||||
InfoScreen_run((InfoScreen*)ofs);
|
||||
OpenFilesScreen_delete((Object*)ofs);
|
||||
clear();
|
||||
CRT_enableDelay();
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionStrace(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
TraceScreen* ts = TraceScreen_new(p);
|
||||
bool ok = TraceScreen_forkTracer(ts);
|
||||
if (ok) {
|
||||
InfoScreen_run((InfoScreen*)ts);
|
||||
}
|
||||
TraceScreen_delete((Object*)ts);
|
||||
clear();
|
||||
CRT_enableDelay();
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionTag(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
Process_toggleTag(p);
|
||||
Panel_onKey(st->panel, KEY_DOWN);
|
||||
return HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionRedraw() {
|
||||
clear();
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
static struct { const char* key; const char* info; } helpLeft[] = {
|
||||
{ .key = " Arrows: ", .info = "scroll process list" },
|
||||
{ .key = " Digits: ", .info = "incremental PID search" },
|
||||
{ .key = " F3 /: ", .info = "incremental name search" },
|
||||
{ .key = " F4 \\: ",.info = "incremental name filtering" },
|
||||
{ .key = " F5 t: ", .info = "tree view" },
|
||||
{ .key = " p: ", .info = "toggle program path" },
|
||||
{ .key = " u: ", .info = "show processes of a single user" },
|
||||
{ .key = " H: ", .info = "hide/show user process threads" },
|
||||
{ .key = " K: ", .info = "hide/show kernel threads" },
|
||||
{ .key = " F: ", .info = "cursor follows process" },
|
||||
{ .key = " F6 + -: ", .info = "expand/collapse tree" },
|
||||
{ .key = " P M T: ", .info = "sort by CPU%, MEM% or TIME" },
|
||||
{ .key = " I: ", .info = "invert sort order" },
|
||||
{ .key = " F6 >: ", .info = "select sort column" },
|
||||
{ .key = NULL, .info = NULL }
|
||||
};
|
||||
|
||||
static struct { const char* key; const char* info; } helpRight[] = {
|
||||
{ .key = " Space: ", .info = "tag process" },
|
||||
{ .key = " c: ", .info = "tag process and its children" },
|
||||
{ .key = " U: ", .info = "untag all processes" },
|
||||
{ .key = " F9 k: ", .info = "kill process/tagged processes" },
|
||||
{ .key = " F7 ]: ", .info = "higher priority (root only)" },
|
||||
{ .key = " F8 [: ", .info = "lower priority (+ nice)" },
|
||||
#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY)
|
||||
{ .key = " a: ", .info = "set CPU affinity" },
|
||||
#endif
|
||||
{ .key = " e: ", .info = "show process environment" },
|
||||
{ .key = " i: ", .info = "set IO priority" },
|
||||
{ .key = " l: ", .info = "list open files with lsof" },
|
||||
{ .key = " s: ", .info = "trace syscalls with strace" },
|
||||
{ .key = " ", .info = "" },
|
||||
{ .key = " F2 S: ", .info = "setup" },
|
||||
{ .key = " F1 h: ", .info = "show this help screen" },
|
||||
{ .key = " F10 q: ", .info = "quit" },
|
||||
{ .key = NULL, .info = NULL }
|
||||
};
|
||||
|
||||
static Htop_Reaction actionHelp(State* st) {
|
||||
Settings* settings = st->settings;
|
||||
|
||||
clear();
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
|
||||
for (int i = 0; i < LINES-1; i++)
|
||||
mvhline(i, 0, ' ', COLS);
|
||||
|
||||
mvaddstr(0, 0, "htop " VERSION " - " COPYRIGHT);
|
||||
mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info.");
|
||||
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(3, 0, "CPU usage bar: ");
|
||||
#define addattrstr(a,s) attrset(a);addstr(s)
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
if (settings->detailedCPUTime) {
|
||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_KERNEL], "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%");
|
||||
} else {
|
||||
addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
|
||||
addattrstr(CRT_colors[CPU_STEAL], "virtualiz");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used%");
|
||||
}
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(4, 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_CACHE], "cache");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(5, 0, "Swap bar: ");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
addattrstr(CRT_colors[SWAP], "used");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(6,0, "Type and layout of header meters are configurable in the setup screen.");
|
||||
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
|
||||
mvaddstr(7, 0, "In monochrome, meters display as different chars, in order: |#*@$%&.");
|
||||
}
|
||||
mvaddstr( 8, 0, " Status: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep");
|
||||
for (int i = 0; helpLeft[i].info; i++) { mvaddstr(9+i, 9, helpLeft[i].info); }
|
||||
for (int i = 0; helpRight[i].info; i++) { mvaddstr(9+i, 49, helpRight[i].info); }
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); }
|
||||
for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); }
|
||||
attrset(CRT_colors[PROCESS_THREAD]);
|
||||
mvaddstr(16, 32, "threads");
|
||||
mvaddstr(17, 26, "threads");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
mvaddstr(23,0, "Press any key to return.");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
refresh();
|
||||
CRT_readKey();
|
||||
clear();
|
||||
|
||||
return HTOP_RECALCULATE | HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionUntagAll(State* st) {
|
||||
for (int i = 0; i < Panel_size(st->panel); i++) {
|
||||
Process* p = (Process*) Panel_get(st->panel, i);
|
||||
p->tag = false;
|
||||
}
|
||||
return HTOP_REFRESH;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionTagAllChildren(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
tagAllChildren(st->panel, p);
|
||||
return HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionShowEnvScreen(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
EnvScreen* es = EnvScreen_new(p);
|
||||
InfoScreen_run((InfoScreen*)es);
|
||||
EnvScreen_delete((Object*)es);
|
||||
clear();
|
||||
CRT_enableDelay();
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
|
||||
void Action_setBindings(Htop_Action* keys) {
|
||||
keys[KEY_RESIZE] = actionResize;
|
||||
keys['M'] = actionSortByMemory;
|
||||
keys['T'] = actionSortByTime;
|
||||
keys['P'] = actionSortByCPU;
|
||||
keys['H'] = actionToggleUserlandThreads;
|
||||
keys['K'] = actionToggleKernelThreads;
|
||||
keys['p'] = actionToggleProgramPath;
|
||||
keys['t'] = actionToggleTreeView;
|
||||
keys[KEY_F(5)] = actionToggleTreeView;
|
||||
keys[KEY_F(4)] = actionIncFilter;
|
||||
keys['\\'] = actionIncFilter;
|
||||
keys[KEY_F(3)] = actionIncSearch;
|
||||
keys['/'] = actionIncSearch;
|
||||
|
||||
keys[']'] = actionHigherPriority;
|
||||
keys[KEY_F(7)] = actionHigherPriority;
|
||||
keys['['] = actionLowerPriority;
|
||||
keys[KEY_F(8)] = actionLowerPriority;
|
||||
keys['I'] = actionInvertSortOrder;
|
||||
keys[KEY_F(6)] = actionExpandCollapseOrSortColumn;
|
||||
keys[KEY_F(18)] = actionExpandCollapseOrSortColumn;
|
||||
keys['<'] = actionSetSortColumn;
|
||||
keys[','] = actionSetSortColumn;
|
||||
keys['>'] = actionSetSortColumn;
|
||||
keys['.'] = actionSetSortColumn;
|
||||
keys[KEY_F(10)] = actionQuit;
|
||||
keys['q'] = actionQuit;
|
||||
keys['a'] = actionSetAffinity;
|
||||
keys[KEY_F(9)] = actionKill;
|
||||
keys['k'] = actionKill;
|
||||
keys[KEY_RECLICK] = actionExpandOrCollapse;
|
||||
keys['+'] = actionExpandOrCollapse;
|
||||
keys['='] = actionExpandOrCollapse;
|
||||
keys['-'] = actionExpandOrCollapse;
|
||||
keys['u'] = actionFilterByUser;
|
||||
keys['F'] = Action_follow;
|
||||
keys['S'] = actionSetup;
|
||||
keys['C'] = actionSetup;
|
||||
keys[KEY_F(2)] = actionSetup;
|
||||
keys['l'] = actionLsof;
|
||||
keys['s'] = actionStrace;
|
||||
keys[' '] = actionTag;
|
||||
keys['\014'] = actionRedraw; // Ctrl+L
|
||||
keys[KEY_F(1)] = actionHelp;
|
||||
keys['h'] = actionHelp;
|
||||
keys['?'] = actionHelp;
|
||||
keys['U'] = actionUntagAll;
|
||||
keys['c'] = actionTagAllChildren;
|
||||
keys['e'] = actionShowEnvScreen;
|
||||
}
|
||||
|
58
Action.h
Normal file
58
Action.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Action
|
||||
#define HEADER_Action
|
||||
/*
|
||||
htop - Action.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
||||
#include "IncSet.h"
|
||||
#include "Settings.h"
|
||||
#include "Header.h"
|
||||
#include "UsersTable.h"
|
||||
#include "ProcessList.h"
|
||||
#include "Panel.h"
|
||||
|
||||
typedef enum {
|
||||
HTOP_OK = 0x00,
|
||||
HTOP_REFRESH = 0x01,
|
||||
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
|
||||
HTOP_SAVE_SETTINGS = 0x04,
|
||||
HTOP_KEEP_FOLLOWING = 0x08,
|
||||
HTOP_QUIT = 0x10,
|
||||
HTOP_REDRAW_BAR = 0x20,
|
||||
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
|
||||
} Htop_Reaction;
|
||||
|
||||
typedef Htop_Reaction (*Htop_Action)();
|
||||
|
||||
typedef struct State_ {
|
||||
Settings* settings;
|
||||
UsersTable* ut;
|
||||
ProcessList* pl;
|
||||
Panel* panel;
|
||||
Header* header;
|
||||
} State;
|
||||
|
||||
|
||||
Object* Action_pickFromVector(State* st, Panel* list, int x);
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
bool Action_setUserOnly(const char* userName, uid_t* userId);
|
||||
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
Htop_Reaction Action_follow(State* st);
|
||||
|
||||
|
||||
void Action_setBindings(Htop_Action* keys);
|
||||
|
||||
|
||||
#endif
|
82
Affinity.c
82
Affinity.c
@ -9,9 +9,23 @@ in the source distribution for its full text.
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#include <hwloc.h>
|
||||
#if __linux__
|
||||
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD
|
||||
#else
|
||||
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS
|
||||
#endif
|
||||
#elif HAVE_LINUX_AFFINITY
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
/*{
|
||||
#include "Process.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
typedef struct Affinity_ {
|
||||
ProcessList* pl;
|
||||
int size;
|
||||
int used;
|
||||
int* cpus;
|
||||
@ -19,10 +33,11 @@ typedef struct Affinity_ {
|
||||
|
||||
}*/
|
||||
|
||||
Affinity* Affinity_new() {
|
||||
Affinity* this = calloc(1, sizeof(Affinity));
|
||||
Affinity* Affinity_new(ProcessList* pl) {
|
||||
Affinity* this = xCalloc(1, sizeof(Affinity));
|
||||
this->size = 8;
|
||||
this->cpus = calloc(this->size, sizeof(int));
|
||||
this->cpus = xCalloc(this->size, sizeof(int));
|
||||
this->pl = pl;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -34,9 +49,68 @@ void Affinity_delete(Affinity* this) {
|
||||
void Affinity_add(Affinity* this, int id) {
|
||||
if (this->used == this->size) {
|
||||
this->size *= 2;
|
||||
this->cpus = realloc(this->cpus, sizeof(int) * this->size);
|
||||
this->cpus = xRealloc(this->cpus, sizeof(int) * this->size);
|
||||
}
|
||||
this->cpus[this->used] = id;
|
||||
this->used++;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||
bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
|
||||
Affinity* affinity = NULL;
|
||||
if (ok) {
|
||||
affinity = Affinity_new(pl);
|
||||
if (hwloc_bitmap_last(cpuset) == -1) {
|
||||
for (int i = 0; i < pl->cpuCount; i++) {
|
||||
Affinity_add(affinity, i);
|
||||
}
|
||||
} else {
|
||||
unsigned int id;
|
||||
hwloc_bitmap_foreach_begin(id, cpuset);
|
||||
Affinity_add(affinity, id);
|
||||
hwloc_bitmap_foreach_end();
|
||||
}
|
||||
}
|
||||
hwloc_bitmap_free(cpuset);
|
||||
return affinity;
|
||||
}
|
||||
|
||||
bool Affinity_set(Process* proc, Affinity* this) {
|
||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||
for (int i = 0; i < this->used; i++) {
|
||||
hwloc_bitmap_set(cpuset, this->cpus[i]);
|
||||
}
|
||||
bool ok = (hwloc_set_proc_cpubind(this->pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
|
||||
hwloc_bitmap_free(cpuset);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#elif HAVE_LINUX_AFFINITY
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||
cpu_set_t cpuset;
|
||||
bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0);
|
||||
if (!ok) return NULL;
|
||||
Affinity* affinity = Affinity_new(pl);
|
||||
for (int i = 0; i < pl->cpuCount; i++) {
|
||||
if (CPU_ISSET(i, &cpuset))
|
||||
Affinity_add(affinity, i);
|
||||
}
|
||||
return affinity;
|
||||
}
|
||||
|
||||
bool Affinity_set(Process* proc, Affinity* this) {
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
for (int i = 0; i < this->used; i++) {
|
||||
CPU_SET(this->cpus[i], &cpuset);
|
||||
}
|
||||
bool ok = (sched_setaffinity(proc->pid, sizeof(unsigned long), &cpuset) == 0);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
27
Affinity.h
27
Affinity.h
@ -9,19 +9,44 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#if __linux__
|
||||
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD
|
||||
#else
|
||||
#define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS
|
||||
#endif
|
||||
#elif HAVE_LINUX_AFFINITY
|
||||
#endif
|
||||
|
||||
#include "Process.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
typedef struct Affinity_ {
|
||||
ProcessList* pl;
|
||||
int size;
|
||||
int used;
|
||||
int* cpus;
|
||||
} Affinity;
|
||||
|
||||
|
||||
Affinity* Affinity_new();
|
||||
Affinity* Affinity_new(ProcessList* pl);
|
||||
|
||||
void Affinity_delete(Affinity* this);
|
||||
|
||||
void Affinity_add(Affinity* this, int id);
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||
|
||||
bool Affinity_set(Process* proc, Affinity* this);
|
||||
|
||||
#elif HAVE_LINUX_AFFINITY
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||
|
||||
bool Affinity_set(Process* proc, Affinity* this);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -6,6 +6,7 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "AffinityPanel.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include "CheckItem.h"
|
||||
|
||||
@ -23,6 +24,7 @@ static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
|
||||
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
|
||||
switch(ch) {
|
||||
case KEY_MOUSE:
|
||||
case KEY_RECLICK:
|
||||
case ' ':
|
||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
||||
return HANDLED;
|
||||
@ -43,14 +45,14 @@ PanelClass AffinityPanel_class = {
|
||||
};
|
||||
|
||||
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
||||
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem));
|
||||
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_newEnterEsc("Set ", "Cancel "));
|
||||
Object_setClass(this, Class(AffinityPanel));
|
||||
|
||||
Panel_setHeader(this, "Use CPUs:");
|
||||
int curCpu = 0;
|
||||
for (int i = 0; i < pl->cpuCount; i++) {
|
||||
char number[10];
|
||||
snprintf(number, 9, "%d", ProcessList_cpuId(pl, i));
|
||||
snprintf(number, 9, "%d", Settings_cpuId(pl->settings, i));
|
||||
bool mode;
|
||||
if (curCpu < affinity->used && affinity->cpus[curCpu] == i) {
|
||||
mode = true;
|
||||
@ -58,13 +60,13 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
||||
} else {
|
||||
mode = false;
|
||||
}
|
||||
Panel_add(this, (Object*) CheckItem_new(strdup(number), NULL, mode));
|
||||
Panel_add(this, (Object*) CheckItem_newByVal(xStrdup(number), mode));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Affinity* AffinityPanel_getAffinity(Panel* this) {
|
||||
Affinity* affinity = Affinity_new();
|
||||
Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl) {
|
||||
Affinity* affinity = Affinity_new(pl);
|
||||
int size = Panel_size(this);
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (CheckItem_get((CheckItem*)Panel_get(this, i)))
|
||||
|
@ -18,6 +18,6 @@ extern PanelClass AffinityPanel_class;
|
||||
|
||||
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity);
|
||||
|
||||
Affinity* AffinityPanel_getAffinity(Panel* this);
|
||||
Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl);
|
||||
|
||||
#endif
|
||||
|
@ -6,6 +6,7 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "AvailableColumnsPanel.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include "Header.h"
|
||||
#include "ColumnsPanel.h"
|
||||
@ -13,22 +14,20 @@ in the source distribution for its full text.
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/*{
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
typedef struct AvailableColumnsPanel_ {
|
||||
Panel super;
|
||||
Panel* columns;
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
} AvailableColumnsPanel;
|
||||
|
||||
}*/
|
||||
|
||||
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static void AvailableColumnsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
|
||||
@ -38,7 +37,7 @@ static void AvailableColumnsPanel_delete(Object* object) {
|
||||
|
||||
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
|
||||
char* text = ((ListItem*) Panel_getSelected(super))->value;
|
||||
int key = ((ListItem*) Panel_getSelected(super))->key;
|
||||
HandlerResult result = IGNORED;
|
||||
|
||||
switch(ch) {
|
||||
@ -47,7 +46,7 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
case KEY_F(5):
|
||||
{
|
||||
int at = Panel_getSelectedIndex(this->columns);
|
||||
Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
|
||||
Panel_insert(this->columns, at, (Object*) ListItem_new(Process_fields[key].name, key));
|
||||
Panel_setSelected(this->columns, at+1);
|
||||
ColumnsPanel_update(this->columns);
|
||||
result = HANDLED;
|
||||
@ -55,7 +54,7 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (isalpha(ch))
|
||||
if (ch < 255 && isalpha(ch))
|
||||
result = Panel_selectByTyping(super, ch);
|
||||
break;
|
||||
}
|
||||
@ -71,19 +70,20 @@ PanelClass AvailableColumnsPanel_class = {
|
||||
.eventHandler = AvailableColumnsPanel_eventHandler
|
||||
};
|
||||
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) {
|
||||
AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL);
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||
|
||||
Panel_setHeader(super, "Available Columns");
|
||||
|
||||
for (int i = 1; i < LAST_PROCESSFIELD; i++) {
|
||||
if (i != COMM)
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
|
||||
for (int i = 1; i < Platform_numberOfFields; i++) {
|
||||
if (i != COMM && Process_fields[i].description) {
|
||||
char description[256];
|
||||
snprintf(description, sizeof(description), "%s - %s", Process_fields[i].name, Process_fields[i].description);
|
||||
Panel_add(super, (Object*) ListItem_new(description, i));
|
||||
}
|
||||
}
|
||||
this->columns = columns;
|
||||
return this;
|
||||
|
@ -10,20 +10,15 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
typedef struct AvailableColumnsPanel_ {
|
||||
Panel super;
|
||||
Panel* columns;
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
} AvailableColumnsPanel;
|
||||
|
||||
|
||||
extern PanelClass AvailableColumnsPanel_class;
|
||||
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr);
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns);
|
||||
|
||||
#endif
|
||||
|
@ -6,10 +6,12 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "AvailableMetersPanel.h"
|
||||
#include "MetersPanel.h"
|
||||
|
||||
#include "CPUMeter.h"
|
||||
#include "Header.h"
|
||||
#include "ListItem.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@ -18,14 +20,16 @@ in the source distribution for its full text.
|
||||
#include "Settings.h"
|
||||
#include "Panel.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
typedef struct AvailableMetersPanel_ {
|
||||
Panel super;
|
||||
ScreenManager* scr;
|
||||
|
||||
Settings* settings;
|
||||
Header* header;
|
||||
Panel* leftPanel;
|
||||
Panel* rightPanel;
|
||||
ScreenManager* scr;
|
||||
} AvailableMetersPanel;
|
||||
|
||||
}*/
|
||||
@ -37,39 +41,48 @@ static void AvailableMetersPanel_delete(Object* object) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
static inline void AvailableMetersPanel_addHeader(Header* header, Panel* panel, MeterClass* type, int param, HeaderSide side) {
|
||||
Meter* meter = (Meter*) Header_addMeter(header, type, param, side);
|
||||
Panel_add(panel, (Object*) Meter_toListItem(meter));
|
||||
static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) {
|
||||
Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column);
|
||||
Panel_add(panel, (Object*) Meter_toListItem(meter, false));
|
||||
Panel_setSelected(panel, Panel_size(panel) - 1);
|
||||
MetersPanel_setMoving((MetersPanel*)panel, true);
|
||||
FunctionBar_draw(panel->currentBar, NULL);
|
||||
}
|
||||
|
||||
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
|
||||
AvailableMetersPanel* this = (AvailableMetersPanel*) super;
|
||||
Header* header = this->settings->header;
|
||||
Header* header = this->header;
|
||||
|
||||
ListItem* selected = (ListItem*) Panel_getSelected(super);
|
||||
int param = selected->key & 0xff;
|
||||
int type = selected->key >> 16;
|
||||
HandlerResult result = IGNORED;
|
||||
bool update = false;
|
||||
|
||||
switch(ch) {
|
||||
case KEY_F(5):
|
||||
case 'l':
|
||||
case 'L':
|
||||
{
|
||||
AvailableMetersPanel_addHeader(header, this->leftPanel, Meter_types[type], param, LEFT_HEADER);
|
||||
AvailableMetersPanel_addMeter(header, this->leftPanel, Platform_meterTypes[type], param, 0);
|
||||
result = HANDLED;
|
||||
update = true;
|
||||
break;
|
||||
}
|
||||
case 0x0a:
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
case KEY_F(6):
|
||||
case 'r':
|
||||
case 'R':
|
||||
{
|
||||
AvailableMetersPanel_addHeader(header, this->rightPanel, Meter_types[type], param, RIGHT_HEADER);
|
||||
result = HANDLED;
|
||||
AvailableMetersPanel_addMeter(header, this->rightPanel, Platform_meterTypes[type], param, 1);
|
||||
result = (KEY_LEFT << 16) | SYNTH_KEY;
|
||||
update = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == HANDLED) {
|
||||
if (update) {
|
||||
this->settings->changed = true;
|
||||
Header_calculateHeight(header);
|
||||
Header_draw(header);
|
||||
@ -86,30 +99,35 @@ PanelClass AvailableMetersPanel_class = {
|
||||
.eventHandler = AvailableMetersPanel_eventHandler
|
||||
};
|
||||
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) {
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) {
|
||||
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
|
||||
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->header = header;
|
||||
this->leftPanel = leftMeters;
|
||||
this->rightPanel = rightMeters;
|
||||
this->scr = scr;
|
||||
|
||||
Panel_setHeader(super, "Available meters");
|
||||
for (int i = 1; Meter_types[i]; i++) {
|
||||
MeterClass* type = Meter_types[i];
|
||||
if (type != &CPUMeter_class) {
|
||||
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
|
||||
}
|
||||
// Platform_meterTypes[0] should be always (&CPUMeter_class), which we will
|
||||
// handle separately in the code below.
|
||||
for (int i = 1; Platform_meterTypes[i]; i++) {
|
||||
MeterClass* type = Platform_meterTypes[i];
|
||||
assert(type != &CPUMeter_class);
|
||||
const char* label = type->description ? type->description : type->uiName;
|
||||
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
||||
}
|
||||
// Handle (&CPUMeter_class)
|
||||
MeterClass* type = &CPUMeter_class;
|
||||
int cpus = settings->pl->cpuCount;
|
||||
int cpus = pl->cpuCount;
|
||||
if (cpus > 1) {
|
||||
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
||||
for (int i = 1; i <= cpus; i++) {
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%s %d", type->uiName, i);
|
||||
snprintf(buffer, 50, "%s %d", type->uiName, i);
|
||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||
}
|
||||
} else {
|
||||
|
@ -12,19 +12,21 @@ in the source distribution for its full text.
|
||||
#include "Settings.h"
|
||||
#include "Panel.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
typedef struct AvailableMetersPanel_ {
|
||||
Panel super;
|
||||
ScreenManager* scr;
|
||||
|
||||
Settings* settings;
|
||||
Header* header;
|
||||
Panel* leftPanel;
|
||||
Panel* rightPanel;
|
||||
ScreenManager* scr;
|
||||
} AvailableMetersPanel;
|
||||
|
||||
|
||||
extern PanelClass AvailableMetersPanel_class;
|
||||
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr);
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl);
|
||||
|
||||
#endif
|
||||
|
284
BatteryMeter.c
284
BatteryMeter.c
@ -9,14 +9,14 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
|
||||
|
||||
#include "BatteryMeter.h"
|
||||
|
||||
#include "Battery.h"
|
||||
#include "ProcessList.h"
|
||||
#include "CRT.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*{
|
||||
#include "Meter.h"
|
||||
@ -26,273 +26,22 @@ typedef enum ACPresence_ {
|
||||
AC_PRESENT,
|
||||
AC_ERROR
|
||||
} ACPresence;
|
||||
|
||||
}*/
|
||||
|
||||
int BatteryMeter_attributes[] = {
|
||||
BATTERY
|
||||
};
|
||||
|
||||
static unsigned long int parseUevent(FILE * file, const char *key) {
|
||||
char line[100];
|
||||
unsigned long int dValue = 0;
|
||||
char* saveptr;
|
||||
static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) {
|
||||
ACPresence isOnAC;
|
||||
double percent;
|
||||
|
||||
Battery_getData(&percent, &isOnAC);
|
||||
|
||||
while (fgets(line, sizeof line, file)) {
|
||||
if (strncmp(line, key, strlen(key)) == 0) {
|
||||
char *value;
|
||||
strtok_r(line, "=", &saveptr);
|
||||
value = strtok_r(NULL, "=", &saveptr);
|
||||
dValue = atoi(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dValue;
|
||||
}
|
||||
|
||||
static unsigned long int parseBatInfo(const char *fileName, const unsigned short int lineNum, const unsigned short int wordNum) {
|
||||
const char batteryPath[] = PROCDIR "/acpi/battery/";
|
||||
DIR* batteryDir = opendir(batteryPath);
|
||||
if (!batteryDir)
|
||||
return 0;
|
||||
|
||||
#define MAX_BATTERIES 64
|
||||
char* batteries[MAX_BATTERIES];
|
||||
unsigned int nBatteries = 0;
|
||||
memset(batteries, 0, MAX_BATTERIES * sizeof(char*));
|
||||
|
||||
struct dirent result;
|
||||
struct dirent* dirEntry;
|
||||
while (nBatteries < MAX_BATTERIES) {
|
||||
int err = readdir_r(batteryDir, &result, &dirEntry);
|
||||
if (err || !dirEntry)
|
||||
break;
|
||||
char* entryName = dirEntry->d_name;
|
||||
if (strncmp(entryName, "BAT", 3))
|
||||
continue;
|
||||
batteries[nBatteries] = strdup(entryName);
|
||||
nBatteries++;
|
||||
}
|
||||
closedir(batteryDir);
|
||||
|
||||
unsigned long int total = 0;
|
||||
for (unsigned int i = 0; i < nBatteries; i++) {
|
||||
char infoPath[30];
|
||||
snprintf(infoPath, sizeof infoPath, "%s%s/%s", batteryPath, batteries[i], fileName);
|
||||
|
||||
FILE* file = fopen(infoPath, "r");
|
||||
if (!file) {
|
||||
break;
|
||||
}
|
||||
|
||||
char line[50] = "";
|
||||
for (unsigned short int i = 0; i < lineNum; i++) {
|
||||
char* ok = fgets(line, sizeof line, file);
|
||||
if (!ok) break;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
char *foundNumStr = String_getToken(line, wordNum);
|
||||
const unsigned long int foundNum = atoi(foundNumStr);
|
||||
free(foundNumStr);
|
||||
|
||||
total += foundNum;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < nBatteries; i++) {
|
||||
free(batteries[i]);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
static ACPresence procAcpiCheck() {
|
||||
ACPresence isOn = AC_ERROR;
|
||||
const char *power_supplyPath = PROCDIR "/acpi/ac_adapter";
|
||||
DIR *power_supplyDir = opendir(power_supplyPath);
|
||||
if (!power_supplyDir) {
|
||||
return AC_ERROR;
|
||||
}
|
||||
|
||||
struct dirent result;
|
||||
struct dirent* dirEntry;
|
||||
for (;;) {
|
||||
int err = readdir_r((DIR *) power_supplyDir, &result, &dirEntry);
|
||||
if (err || !dirEntry)
|
||||
break;
|
||||
|
||||
char* entryName = (char *) dirEntry->d_name;
|
||||
|
||||
if (entryName[0] != 'A')
|
||||
continue;
|
||||
|
||||
char statePath[50];
|
||||
snprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
|
||||
FILE* file = fopen(statePath, "r");
|
||||
|
||||
if (!file) {
|
||||
isOn = AC_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
char line[100];
|
||||
fgets(line, sizeof line, file);
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
|
||||
fclose(file);
|
||||
|
||||
const char *isOnline = String_getToken(line, 2);
|
||||
|
||||
if (strcmp(isOnline, "on-line") == 0) {
|
||||
isOn = AC_PRESENT;
|
||||
} else {
|
||||
isOn = AC_ABSENT;
|
||||
}
|
||||
free((char *) isOnline);
|
||||
if (isOn == AC_PRESENT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (power_supplyDir)
|
||||
closedir(power_supplyDir);
|
||||
return isOn;
|
||||
}
|
||||
|
||||
static ACPresence sysCheck() {
|
||||
ACPresence isOn = AC_ERROR;
|
||||
const char *power_supplyPath = "/sys/class/power_supply";
|
||||
DIR *power_supplyDir = opendir(power_supplyPath);
|
||||
if (!power_supplyDir) {
|
||||
return AC_ERROR;
|
||||
}
|
||||
|
||||
struct dirent result;
|
||||
struct dirent* dirEntry;
|
||||
for (;;) {
|
||||
int err = readdir_r((DIR *) power_supplyDir, &result, &dirEntry);
|
||||
if (err || !dirEntry)
|
||||
break;
|
||||
|
||||
char* entryName = (char *) dirEntry->d_name;
|
||||
if (strncmp(entryName, "A", 1)) {
|
||||
continue;
|
||||
}
|
||||
char onlinePath[50];
|
||||
snprintf((char *) onlinePath, sizeof onlinePath, "%s/%s/online", power_supplyPath, entryName);
|
||||
FILE* file = fopen(onlinePath, "r");
|
||||
if (!file) {
|
||||
isOn = AC_ERROR;
|
||||
} else {
|
||||
isOn = (fgetc(file) - '0');
|
||||
fclose(file);
|
||||
if (isOn == AC_PRESENT) {
|
||||
// If any AC adapter is being used then stop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (power_supplyDir)
|
||||
closedir(power_supplyDir);
|
||||
|
||||
return isOn;
|
||||
}
|
||||
|
||||
static ACPresence chkIsOnline() {
|
||||
if (access(PROCDIR "/acpi/ac_adapter", F_OK) == 0) {
|
||||
return procAcpiCheck();
|
||||
} else if (access("/sys/class/power_supply", F_OK) == 0) {
|
||||
return sysCheck();
|
||||
} else {
|
||||
return AC_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static double getProcBatData() {
|
||||
const unsigned long int totalFull = parseBatInfo("info", 3, 4);
|
||||
if (totalFull == 0)
|
||||
return 0;
|
||||
|
||||
const unsigned long int totalRemain = parseBatInfo("state", 5, 3);
|
||||
if (totalRemain == 0)
|
||||
return 0;
|
||||
|
||||
return totalRemain * 100.0 / (double) totalFull;
|
||||
}
|
||||
|
||||
static double getSysBatData() {
|
||||
const char *power_supplyPath = "/sys/class/power_supply/";
|
||||
DIR *power_supplyDir = opendir(power_supplyPath);
|
||||
if (!power_supplyDir)
|
||||
return 0;
|
||||
|
||||
unsigned long int totalFull = 0;
|
||||
unsigned long int totalRemain = 0;
|
||||
|
||||
struct dirent result;
|
||||
struct dirent* dirEntry;
|
||||
for (;;) {
|
||||
int err = readdir_r((DIR *) power_supplyDir, &result, &dirEntry);
|
||||
if (err || !dirEntry)
|
||||
break;
|
||||
char* entryName = (char *) dirEntry->d_name;
|
||||
|
||||
if (strncmp(entryName, "BAT", 3)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const char ueventPath[50];
|
||||
|
||||
snprintf((char *) ueventPath, sizeof ueventPath, "%s%s/uevent", power_supplyPath, entryName);
|
||||
|
||||
FILE *file;
|
||||
if ((file = fopen(ueventPath, "r")) == NULL) {
|
||||
closedir(power_supplyDir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((totalFull += parseUevent(file, "POWER_SUPPLY_ENERGY_FULL="))) {
|
||||
totalRemain += parseUevent(file, "POWER_SUPPLY_ENERGY_NOW=");
|
||||
} else {
|
||||
//reset file pointer
|
||||
if (fseek(file, 0, SEEK_SET) < 0) {
|
||||
closedir(power_supplyDir);
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Some systems have it as CHARGE instead of ENERGY.
|
||||
if ((totalFull += parseUevent(file, "POWER_SUPPLY_CHARGE_FULL="))) {
|
||||
totalRemain += parseUevent(file, "POWER_SUPPLY_CHARGE_NOW=");
|
||||
} else {
|
||||
//reset file pointer
|
||||
if (fseek(file, 0, SEEK_SET) < 0) {
|
||||
closedir(power_supplyDir);
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
const double percent = totalFull > 0 ? ((double) totalRemain * 100) / (double) totalFull : 0;
|
||||
closedir(power_supplyDir);
|
||||
return percent;
|
||||
}
|
||||
|
||||
static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
||||
double percent = getProcBatData();
|
||||
|
||||
if (percent == 0) {
|
||||
percent = getSysBatData();
|
||||
if (percent == 0) {
|
||||
snprintf(buffer, len, "n/a");
|
||||
return;
|
||||
}
|
||||
if (percent == -1) {
|
||||
this->values[0] = 0;
|
||||
snprintf(buffer, len, "n/a");
|
||||
return;
|
||||
}
|
||||
|
||||
this->values[0] = percent;
|
||||
@ -308,11 +57,9 @@ static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
||||
onBatteryText = "%.1f%%(bat)";
|
||||
}
|
||||
|
||||
ACPresence isOnLine = chkIsOnline();
|
||||
|
||||
if (isOnLine == AC_PRESENT) {
|
||||
if (isOnAC == AC_PRESENT) {
|
||||
snprintf(buffer, len, onAcText, percent);
|
||||
} else if (isOnLine == AC_ABSENT) {
|
||||
} else if (isOnAC == AC_ABSENT) {
|
||||
snprintf(buffer, len, onBatteryText, percent);
|
||||
} else {
|
||||
snprintf(buffer, len, unknownText, percent);
|
||||
@ -326,8 +73,9 @@ MeterClass BatteryMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = BatteryMeter_setValues,
|
||||
.updateValues = BatteryMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = BatteryMeter_attributes,
|
||||
.name = "Battery",
|
||||
|
@ -19,7 +19,6 @@ typedef enum ACPresence_ {
|
||||
AC_ERROR
|
||||
} ACPresence;
|
||||
|
||||
|
||||
extern int BatteryMeter_attributes[];
|
||||
|
||||
extern MeterClass BatteryMeter_class;
|
||||
|
97
CPUMeter.c
97
CPUMeter.c
@ -8,7 +8,8 @@ in the source distribution for its full text.
|
||||
#include "CPUMeter.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "ProcessList.h"
|
||||
#include "Settings.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@ -17,6 +18,19 @@ in the source distribution for its full text.
|
||||
|
||||
/*{
|
||||
#include "Meter.h"
|
||||
|
||||
typedef enum {
|
||||
CPU_METER_NICE = 0,
|
||||
CPU_METER_NORMAL = 1,
|
||||
CPU_METER_KERNEL = 2,
|
||||
CPU_METER_IRQ = 3,
|
||||
CPU_METER_SOFTIRQ = 4,
|
||||
CPU_METER_STEAL = 5,
|
||||
CPU_METER_GUEST = 6,
|
||||
CPU_METER_IOWAIT = 7,
|
||||
CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
|
||||
} CPUMeterValues;
|
||||
|
||||
}*/
|
||||
|
||||
int CPUMeter_attributes[] = {
|
||||
@ -34,47 +48,21 @@ static void CPUMeter_init(Meter* this) {
|
||||
int cpu = this->param;
|
||||
if (this->pl->cpuCount > 1) {
|
||||
char caption[10];
|
||||
sprintf(caption, "%-3d", ProcessList_cpuId(this->pl, cpu - 1));
|
||||
sprintf(caption, "%-3d", Settings_cpuId(this->pl->settings, cpu - 1));
|
||||
Meter_setCaption(this, caption);
|
||||
}
|
||||
if (this->param == 0)
|
||||
Meter_setCaption(this, "Avg");
|
||||
}
|
||||
|
||||
static void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
ProcessList* pl = this->pl;
|
||||
static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int cpu = this->param;
|
||||
if (cpu > this->pl->cpuCount) {
|
||||
snprintf(buffer, size, "absent");
|
||||
return;
|
||||
}
|
||||
CPUData* cpuData = &(pl->cpus[cpu]);
|
||||
double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);
|
||||
double percent;
|
||||
double* v = this->values;
|
||||
v[0] = cpuData->nicePeriod / total * 100.0;
|
||||
v[1] = cpuData->userPeriod / total * 100.0;
|
||||
if (pl->detailedCPUTime) {
|
||||
v[2] = cpuData->systemPeriod / total * 100.0;
|
||||
v[3] = cpuData->irqPeriod / total * 100.0;
|
||||
v[4] = cpuData->softIrqPeriod / total * 100.0;
|
||||
v[5] = cpuData->stealPeriod / total * 100.0;
|
||||
v[6] = cpuData->guestPeriod / total * 100.0;
|
||||
v[7] = cpuData->ioWaitPeriod / total * 100.0;
|
||||
Meter_setItems(this, 8);
|
||||
if (pl->accountGuestInCPUMeter) {
|
||||
percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6];
|
||||
} else {
|
||||
percent = v[0]+v[1]+v[2]+v[3]+v[4];
|
||||
}
|
||||
} else {
|
||||
v[2] = cpuData->systemAllPeriod / total * 100.0;
|
||||
v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
|
||||
Meter_setItems(this, 4);
|
||||
percent = v[0]+v[1]+v[2]+v[3];
|
||||
}
|
||||
percent = MIN(100.0, MAX(0.0, percent));
|
||||
if (isnan(percent)) percent = 0.0;
|
||||
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
|
||||
double percent = Platform_setCPUValues(this, cpu);
|
||||
snprintf(buffer, size, "%5.1f%%", percent);
|
||||
}
|
||||
|
||||
@ -86,44 +74,44 @@ static void CPUMeter_display(Object* cast, RichString* out) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "absent");
|
||||
return;
|
||||
}
|
||||
sprintf(buffer, "%5.1f%% ", this->values[1]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NORMAL]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], ":");
|
||||
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
|
||||
if (this->pl->detailedCPUTime) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[2]);
|
||||
if (this->pl->settings->detailedCPUTime) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[0]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[3]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "hi:");
|
||||
RichString_append(out, CRT_colors[CPU_IRQ], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[4]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_SOFTIRQ]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "si:");
|
||||
RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer);
|
||||
if (this->values[5]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[5]);
|
||||
if (this->values[CPU_METER_STEAL]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_STEAL]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "st:");
|
||||
RichString_append(out, CRT_colors[CPU_STEAL], buffer);
|
||||
}
|
||||
if (this->values[6]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[6]);
|
||||
if (this->values[CPU_METER_GUEST]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_GUEST]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "gu:");
|
||||
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
||||
}
|
||||
sprintf(buffer, "%5.1f%% ", this->values[7]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IOWAIT]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "wa:");
|
||||
RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
|
||||
} else {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[2]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[0]);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||
if (this->values[3]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[3]);
|
||||
if (this->values[CPU_METER_IRQ]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "vir:");
|
||||
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
||||
}
|
||||
@ -152,7 +140,7 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) {
|
||||
static void AllCPUsMeter_init(Meter* this) {
|
||||
int cpus = this->pl->cpuCount;
|
||||
if (!this->drawData)
|
||||
this->drawData = calloc(cpus, sizeof(Meter*));
|
||||
this->drawData = xCalloc(cpus, sizeof(Meter*));
|
||||
Meter** meters = (Meter**) this->drawData;
|
||||
int start, count;
|
||||
AllCPUsMeter_getRange(this, &start, &count);
|
||||
@ -196,16 +184,17 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) {
|
||||
static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
||||
Meter** meters = (Meter**) this->drawData;
|
||||
int start, count;
|
||||
int pad = this->pl->settings->headerMargin ? 2 : 0;
|
||||
AllCPUsMeter_getRange(this, &start, &count);
|
||||
int height = (count+1)/2;
|
||||
int startY = y;
|
||||
for (int i = 0; i < height; i++) {
|
||||
meters[i]->draw(meters[i], x, y, (w-2)/2);
|
||||
meters[i]->draw(meters[i], x, y, (w-pad)/2);
|
||||
y += meters[i]->h;
|
||||
}
|
||||
y = startY;
|
||||
for (int i = height; i < count; i++) {
|
||||
meters[i]->draw(meters[i], x+(w-1)/2+2, y, (w-2)/2);
|
||||
meters[i]->draw(meters[i], x+(w-1)/2+1+(pad/2), y, (w-pad)/2);
|
||||
y += meters[i]->h;
|
||||
}
|
||||
}
|
||||
@ -226,9 +215,9 @@ MeterClass CPUMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = CPUMeter_display
|
||||
},
|
||||
.setValues = CPUMeter_setValues,
|
||||
.updateValues = CPUMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 8,
|
||||
.maxItems = CPU_METER_ITEMCOUNT,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "CPU",
|
||||
@ -248,6 +237,7 @@ MeterClass AllCPUsMeter_class = {
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs",
|
||||
.uiName = "CPUs (1/1)",
|
||||
.description = "CPUs (1/1): all CPUs",
|
||||
.caption = "CPU",
|
||||
.draw = SingleColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
@ -266,6 +256,7 @@ MeterClass AllCPUs2Meter_class = {
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs2",
|
||||
.uiName = "CPUs (1&2/2)",
|
||||
.description = "CPUs (1&2/2): all CPUs in 2 shorter columns",
|
||||
.caption = "CPU",
|
||||
.draw = DualColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
@ -284,6 +275,7 @@ MeterClass LeftCPUsMeter_class = {
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs",
|
||||
.uiName = "CPUs (1/2)",
|
||||
.description = "CPUs (1/2): first half of list",
|
||||
.caption = "CPU",
|
||||
.draw = SingleColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
@ -302,6 +294,7 @@ MeterClass RightCPUsMeter_class = {
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "RightCPUs",
|
||||
.uiName = "CPUs (2/2)",
|
||||
.description = "CPUs (2/2): second half of list",
|
||||
.caption = "CPU",
|
||||
.draw = SingleColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
@ -320,6 +313,7 @@ MeterClass LeftCPUs2Meter_class = {
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs2",
|
||||
.uiName = "CPUs (1&2/4)",
|
||||
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
||||
.caption = "CPU",
|
||||
.draw = DualColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
@ -338,6 +332,7 @@ MeterClass RightCPUs2Meter_class = {
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "RightCPUs2",
|
||||
.uiName = "CPUs (3&4/4)",
|
||||
.description = "CPUs (3&4/4): second half in 2 shorter columns",
|
||||
.caption = "CPU",
|
||||
.draw = DualColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
|
13
CPUMeter.h
13
CPUMeter.h
@ -11,6 +11,19 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Meter.h"
|
||||
|
||||
typedef enum {
|
||||
CPU_METER_NICE = 0,
|
||||
CPU_METER_NORMAL = 1,
|
||||
CPU_METER_KERNEL = 2,
|
||||
CPU_METER_IRQ = 3,
|
||||
CPU_METER_SOFTIRQ = 4,
|
||||
CPU_METER_STEAL = 5,
|
||||
CPU_METER_GUEST = 6,
|
||||
CPU_METER_IOWAIT = 7,
|
||||
CPU_METER_ITEMCOUNT = 8, // number of entries in this enum
|
||||
} CPUMeterValues;
|
||||
|
||||
|
||||
extern int CPUMeter_attributes[];
|
||||
|
||||
#ifndef MIN
|
||||
|
75
CRT.h
75
CRT.h
@ -9,18 +9,8 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#endif
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||
|
||||
#define COLORSCHEME_DEFAULT 0
|
||||
#define COLORSCHEME_MONOCHROME 1
|
||||
#define COLORSCHEME_BLACKONWHITE 2
|
||||
#define COLORSCHEME_BLACKONWHITE2 3
|
||||
#define COLORSCHEME_MIDNIGHT 4
|
||||
#define COLORSCHEME_BLACKNIGHT 5
|
||||
|
||||
#define Black COLOR_BLACK
|
||||
#define Red COLOR_RED
|
||||
#define Green COLOR_GREEN
|
||||
@ -30,10 +20,36 @@ in the source distribution for its full text.
|
||||
#define Cyan COLOR_CYAN
|
||||
#define White COLOR_WHITE
|
||||
|
||||
#define KEY_WHEELUP KEY_F(20)
|
||||
#define KEY_WHEELDOWN KEY_F(21)
|
||||
#define KEY_RECLICK KEY_F(22)
|
||||
|
||||
//#link curses
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum TreeStr_ {
|
||||
TREE_STR_HORZ,
|
||||
TREE_STR_VERT,
|
||||
TREE_STR_RTEE,
|
||||
TREE_STR_BEND,
|
||||
TREE_STR_TEND,
|
||||
TREE_STR_OPEN,
|
||||
TREE_STR_SHUT,
|
||||
TREE_STR_COUNT
|
||||
} TreeStr;
|
||||
|
||||
typedef enum ColorSchemes_ {
|
||||
COLORSCHEME_DEFAULT = 0,
|
||||
COLORSCHEME_MONOCHROME = 1,
|
||||
COLORSCHEME_BLACKONWHITE = 2,
|
||||
COLORSCHEME_LIGHTTERMINAL = 3,
|
||||
COLORSCHEME_MIDNIGHT = 4,
|
||||
COLORSCHEME_BLACKNIGHT = 5,
|
||||
COLORSCHEME_BROKENGRAY = 6,
|
||||
LAST_COLORSCHEME = 7,
|
||||
} ColorSchemes;
|
||||
|
||||
typedef enum ColorElements_ {
|
||||
RESET_COLOR,
|
||||
DEFAULT_COLOR,
|
||||
@ -42,8 +58,9 @@ typedef enum ColorElements_ {
|
||||
FAILED_SEARCH,
|
||||
PANEL_HEADER_FOCUS,
|
||||
PANEL_HEADER_UNFOCUS,
|
||||
PANEL_HIGHLIGHT_FOCUS,
|
||||
PANEL_HIGHLIGHT_UNFOCUS,
|
||||
PANEL_SELECTION_FOCUS,
|
||||
PANEL_SELECTION_FOLLOW,
|
||||
PANEL_SELECTION_UNFOCUS,
|
||||
LARGE_NUMBER,
|
||||
METER_TEXT,
|
||||
METER_VALUE,
|
||||
@ -58,6 +75,7 @@ typedef enum ColorElements_ {
|
||||
PROCESS_MEGABYTES,
|
||||
PROCESS_TREE,
|
||||
PROCESS_R_STATE,
|
||||
PROCESS_D_STATE,
|
||||
PROCESS_BASENAME,
|
||||
PROCESS_HIGH_PRIORITY,
|
||||
PROCESS_LOW_PRIORITY,
|
||||
@ -67,13 +85,6 @@ typedef enum ColorElements_ {
|
||||
BAR_SHADOW,
|
||||
GRAPH_1,
|
||||
GRAPH_2,
|
||||
GRAPH_3,
|
||||
GRAPH_4,
|
||||
GRAPH_5,
|
||||
GRAPH_6,
|
||||
GRAPH_7,
|
||||
GRAPH_8,
|
||||
GRAPH_9,
|
||||
MEMORY_USED,
|
||||
MEMORY_BUFFERS,
|
||||
MEMORY_BUFFERS_TEXT,
|
||||
@ -102,21 +113,41 @@ typedef enum ColorElements_ {
|
||||
|
||||
void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
// TODO: centralize these in Settings.
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||
|
||||
extern int CRT_colorScheme;
|
||||
|
||||
extern const char *CRT_treeStrAscii[TREE_STR_COUNT];
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
extern const char *CRT_treeStrUtf8[TREE_STR_COUNT];
|
||||
|
||||
extern bool CRT_utf8;
|
||||
|
||||
extern int CRT_colors[LAST_COLORELEMENT];
|
||||
#endif
|
||||
|
||||
extern const char **CRT_treeStr;
|
||||
|
||||
extern int CRT_delay;
|
||||
|
||||
int* CRT_colors;
|
||||
|
||||
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
|
||||
|
||||
extern int CRT_cursorX;
|
||||
|
||||
extern int CRT_scrollHAmount;
|
||||
|
||||
extern int CRT_scrollWheelVAmount;
|
||||
|
||||
char* CRT_termType;
|
||||
|
||||
// TODO move color scheme to Settings, perhaps?
|
||||
|
||||
extern int CRT_colorScheme;
|
||||
|
||||
void *backtraceArray[128];
|
||||
|
||||
// TODO: pass an instance of Settings instead.
|
||||
|
@ -21,27 +21,20 @@ in the source distribution for its full text.
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
typedef struct CategoriesPanel_ {
|
||||
Panel super;
|
||||
ScreenManager* scr;
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
Header* header;
|
||||
ProcessList* pl;
|
||||
} CategoriesPanel;
|
||||
|
||||
}*/
|
||||
|
||||
static const char* MetersFunctions[] = {" ", " ", " ", "Type ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||
|
||||
static const char* AvailableMetersFunctions[] = {" ", " ", " ", " ", "Add L ", "Add R ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||
|
||||
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
|
||||
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static void CategoriesPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
@ -51,29 +44,31 @@ static void CategoriesPanel_delete(Object* object) {
|
||||
}
|
||||
|
||||
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
|
||||
Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
|
||||
Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
|
||||
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, leftMeters, rightMeters, this->scr);
|
||||
ScreenManager_add(this->scr, leftMeters, FunctionBar_new(MetersFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, rightMeters, FunctionBar_new(MetersFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, availableMeters, FunctionBar_new(AvailableMetersFunctions, NULL, NULL), -1);
|
||||
MetersPanel* leftMeters = MetersPanel_new(this->settings, "Left column", this->header->columns[0], this->scr);
|
||||
MetersPanel* rightMeters = MetersPanel_new(this->settings, "Right column", this->header->columns[1], this->scr);
|
||||
leftMeters->rightNeighbor = rightMeters;
|
||||
rightMeters->leftNeighbor = leftMeters;
|
||||
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, this->header, (Panel*) leftMeters, (Panel*) rightMeters, this->scr, this->pl);
|
||||
ScreenManager_add(this->scr, (Panel*) leftMeters, 20);
|
||||
ScreenManager_add(this->scr, (Panel*) rightMeters, 20);
|
||||
ScreenManager_add(this->scr, availableMeters, -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
|
||||
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
|
||||
ScreenManager_add(this->scr, displayOptions, FunctionBar_new(DisplayOptionsFunctions, NULL, NULL), -1);
|
||||
ScreenManager_add(this->scr, displayOptions, -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
||||
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
|
||||
ScreenManager_add(this->scr, colors, FunctionBar_new(ColorsFunctions, NULL, NULL), -1);
|
||||
ScreenManager_add(this->scr, colors, -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
||||
Panel* columns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
|
||||
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, columns, this->scr);
|
||||
ScreenManager_add(this->scr, columns, FunctionBar_new(ColumnsFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, availableColumns, FunctionBar_new(AvailableColumnsFunctions, NULL, NULL), -1);
|
||||
Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
|
||||
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
|
||||
ScreenManager_add(this->scr, columns, 20);
|
||||
ScreenManager_add(this->scr, availableColumns, -1);
|
||||
}
|
||||
|
||||
static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
@ -83,13 +78,13 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
int selected = Panel_getSelectedIndex(super);
|
||||
switch (ch) {
|
||||
case EVENT_SETSELECTED:
|
||||
case EVENT_SET_SELECTED:
|
||||
result = HANDLED;
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_CTRLP:
|
||||
case KEY_CTRL('P'):
|
||||
case KEY_DOWN:
|
||||
case KEY_CTRLN:
|
||||
case KEY_CTRL('N'):
|
||||
case KEY_NPAGE:
|
||||
case KEY_PPAGE:
|
||||
case KEY_HOME:
|
||||
@ -102,13 +97,12 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (isalpha(ch))
|
||||
if (ch < 255 && isalpha(ch))
|
||||
result = Panel_selectByTyping(super, ch);
|
||||
if (result == BREAK_LOOP)
|
||||
result = IGNORED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == HANDLED) {
|
||||
int size = ScreenManager_size(this->scr);
|
||||
for (int i = 1; i < size; i++)
|
||||
@ -128,7 +122,6 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -140,13 +133,16 @@ PanelClass CategoriesPanel_class = {
|
||||
.eventHandler = CategoriesPanel_eventHandler
|
||||
};
|
||||
|
||||
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) {
|
||||
CategoriesPanel* this = AllocThis(CategoriesPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
|
||||
FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
this->settings = settings;
|
||||
this->header = header;
|
||||
this->pl = pl;
|
||||
Panel_setHeader(super, "Setup");
|
||||
Panel_add(super, (Object*) ListItem_new("Meters", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Display options", 0));
|
||||
|
@ -12,12 +12,15 @@ in the source distribution for its full text.
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
typedef struct CategoriesPanel_ {
|
||||
Panel super;
|
||||
ScreenManager* scr;
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
Header* header;
|
||||
ProcessList* pl;
|
||||
} CategoriesPanel;
|
||||
|
||||
|
||||
@ -25,6 +28,6 @@ void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
|
||||
|
||||
extern PanelClass CategoriesPanel_class;
|
||||
|
||||
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr);
|
||||
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl);
|
||||
|
||||
#endif
|
||||
|
64
ChangeLog
64
ChangeLog
@ -1,4 +1,68 @@
|
||||
|
||||
What's new in version 2.0.2
|
||||
|
||||
* Mac OS X: stop trying when task_for_pid fails for a process,
|
||||
stops spamming logs with errors.
|
||||
* Add Ctrl+A and Ctrl+E to go to beginning and end of line
|
||||
* FreeBSD: fixes for CPU calculation
|
||||
(thanks to Tim Creech, Andy Pilate)
|
||||
* Usability: auto-follow process after a search.
|
||||
* Use Linux backend on GNU Hurd
|
||||
* Improvement for reproducible builds.
|
||||
* BUGFIX: Fix behavior of Alt-key combinations
|
||||
(thanks to Kang-Che Sung)
|
||||
* Various code tweaks and cleanups
|
||||
(thanks to Kang-Che Sung)
|
||||
|
||||
What's new in version 2.0.1
|
||||
|
||||
* OpenBSD: Various fixes and improvements
|
||||
(thanks to Michael McConville and Juan Francisco Cantero Hurtado)
|
||||
* FreeBSD: fix CPU and memory readings
|
||||
(thanks to Tim Creech, Hung-Yi Chen, Bernard Spil, Greg V)
|
||||
* FreeBSD: add battery support
|
||||
(thanks to Greg V)
|
||||
* Linux: Retain last-obtained name of a zombie process
|
||||
* Mac OS X: Improve portability for OS X versions
|
||||
(thanks to Michael Klein)
|
||||
* Mac OS X: Fix reading command-line arguments and basename
|
||||
* Mac OS X: Fix process state information
|
||||
* Mac OS X: Fix tree view collapsing/expanding
|
||||
* Mac OS X: Fix tree organization
|
||||
* Mac OS X: Fix memory accounting
|
||||
* Fix crash when emptying a column of meters
|
||||
* Make Esc key more responsive
|
||||
|
||||
What's new in version 2.0.0
|
||||
|
||||
* Platform abstraction layer
|
||||
* Initial FreeBSD support
|
||||
* Initial Mac OS X support
|
||||
(thanks to David Hunt)
|
||||
* Swap meter for Mac OSX
|
||||
(thanks to Ștefan Rusu)
|
||||
* OpenBSD port
|
||||
(thanks to Michael McConville)
|
||||
* FreeBSD support improvements
|
||||
(thanks to Martin Misuth)
|
||||
* Support for NCurses 6 ABI, including mouse wheel support
|
||||
* Much improved mouse responsiveness
|
||||
* Process environment variables screen
|
||||
(thanks to Michael Klein)
|
||||
* Higher-resolution UTF-8 based Graph mode
|
||||
(Thanks to James Hall from vtop for the idea!)
|
||||
* Show program path settings
|
||||
(thanks to Tobias Geerinckx-Rice)
|
||||
* BUGFIX: Fix crash when scrolling an empty filtered list.
|
||||
* Use dynamic units for text display, and several fixes
|
||||
(thanks to Christian Hesse)
|
||||
* BUGFIX: fix error caused by overflow in usertime calculation.
|
||||
(thanks to Patrick Marlier)
|
||||
* Catch all memory allocation errors
|
||||
(thanks to Michael McConville for the push)
|
||||
* Several tweaks and bugfixes
|
||||
(See the Git log for details and contributors!)
|
||||
|
||||
What's new in version 1.0.3
|
||||
|
||||
* Tag all children ('c' key)
|
||||
|
12
CheckItem.c
12
CheckItem.c
@ -49,11 +49,19 @@ ObjectClass CheckItem_class = {
|
||||
.delete = CheckItem_delete
|
||||
};
|
||||
|
||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
|
||||
CheckItem* CheckItem_newByRef(char* text, bool* ref) {
|
||||
CheckItem* this = AllocThis(CheckItem);
|
||||
this->text = text;
|
||||
this->value = false;
|
||||
this->ref = ref;
|
||||
return this;
|
||||
}
|
||||
|
||||
CheckItem* CheckItem_newByVal(char* text, bool value) {
|
||||
CheckItem* this = AllocThis(CheckItem);
|
||||
this->text = text;
|
||||
this->value = value;
|
||||
this->ref = ref;
|
||||
this->ref = NULL;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,9 @@ typedef struct CheckItem_ {
|
||||
|
||||
extern ObjectClass CheckItem_class;
|
||||
|
||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value);
|
||||
CheckItem* CheckItem_newByRef(char* text, bool* ref);
|
||||
|
||||
CheckItem* CheckItem_newByVal(char* text, bool value);
|
||||
|
||||
void CheckItem_set(CheckItem* this, bool value);
|
||||
|
||||
|
@ -19,7 +19,7 @@ int ClockMeter_attributes[] = {
|
||||
CLOCK
|
||||
};
|
||||
|
||||
static void ClockMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void ClockMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
time_t t = time(NULL);
|
||||
struct tm result;
|
||||
struct tm *lt = localtime_r(&t, &result);
|
||||
@ -32,9 +32,10 @@ MeterClass ClockMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = ClockMeter_setValues,
|
||||
.updateValues = ClockMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.total = 100.0,
|
||||
.maxItems = 1,
|
||||
.total = 1440, /* 24*60 */
|
||||
.attributes = ClockMeter_attributes,
|
||||
.name = "Clock",
|
||||
.uiName = "Clock",
|
||||
|
@ -16,7 +16,7 @@ in the source distribution for its full text.
|
||||
|
||||
// TO ADD A NEW SCHEME:
|
||||
// * Increment the size of bool check in ColorsPanel.h
|
||||
// * Add the entry in the ColorSchemes array below in the file
|
||||
// * Add the entry in the ColorSchemeNames array below in the file
|
||||
// * Add a define in CRT.h that matches the order of the array
|
||||
// * Add the colors in CRT_setColors
|
||||
|
||||
@ -34,13 +34,16 @@ typedef struct ColorsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* ColorSchemes[] = {
|
||||
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static const char* ColorSchemeNames[] = {
|
||||
"Default",
|
||||
"Monochromatic",
|
||||
"Black on White",
|
||||
"Light Terminal",
|
||||
"MC",
|
||||
"Black Night",
|
||||
"Broken Gray",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -62,8 +65,9 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
case KEY_MOUSE:
|
||||
case KEY_RECLICK:
|
||||
case ' ':
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++)
|
||||
for (int i = 0; ColorSchemeNames[i] != NULL; i++)
|
||||
CheckItem_set((CheckItem*)Panel_get(super, i), false);
|
||||
CheckItem_set((CheckItem*)Panel_get(super, mark), true);
|
||||
this->settings->colorScheme = mark;
|
||||
@ -72,7 +76,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
if (result == HANDLED) {
|
||||
this->settings->changed = true;
|
||||
Header* header = this->settings->header;
|
||||
const Header* header = this->scr->header;
|
||||
CRT_setColors(mark);
|
||||
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
|
||||
Header_draw(header);
|
||||
@ -94,14 +98,15 @@ PanelClass ColorsPanel_class = {
|
||||
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
ColorsPanel* this = AllocThis(ColorsPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true);
|
||||
FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL);
|
||||
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
|
||||
Panel_setHeader(super, "Colors");
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup(ColorSchemes[i]), NULL, false));
|
||||
for (int i = 0; ColorSchemeNames[i] != NULL; i++) {
|
||||
Panel_add(super, (Object*) CheckItem_newByVal(xStrdup(ColorSchemeNames[i]), false));
|
||||
}
|
||||
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
||||
return this;
|
||||
|
@ -11,7 +11,7 @@ in the source distribution for its full text.
|
||||
|
||||
// TO ADD A NEW SCHEME:
|
||||
// * Increment the size of bool check in ColorsPanel.h
|
||||
// * Add the entry in the ColorSchemes array below in the file
|
||||
// * Add the entry in the ColorSchemeNames array below in the file
|
||||
// * Add a define in CRT.h that matches the order of the array
|
||||
// * Add the colors in CRT_setColors
|
||||
|
||||
|
@ -6,8 +6,11 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ColumnsPanel.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "ListItem.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@ -16,17 +19,18 @@ in the source distribution for its full text.
|
||||
/*{
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
typedef struct ColumnsPanel_ {
|
||||
Panel super;
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
bool moving;
|
||||
} ColumnsPanel;
|
||||
|
||||
}*/
|
||||
|
||||
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||
|
||||
static void ColumnsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
ColumnsPanel* this = (ColumnsPanel*) object;
|
||||
@ -35,12 +39,34 @@ static void ColumnsPanel_delete(Object* object) {
|
||||
}
|
||||
|
||||
static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
ColumnsPanel* const this = (ColumnsPanel*) super;
|
||||
|
||||
int selected = Panel_getSelectedIndex(super);
|
||||
HandlerResult result = IGNORED;
|
||||
int size = Panel_size(super);
|
||||
|
||||
switch(ch) {
|
||||
case 0x0a:
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
case KEY_MOUSE:
|
||||
case KEY_RECLICK:
|
||||
{
|
||||
if (selected < size - 1) {
|
||||
this->moving = !(this->moving);
|
||||
Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||
((ListItem*)Panel_getSelected(super))->moving = this->moving;
|
||||
result = HANDLED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KEY_UP:
|
||||
{
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
case KEY_F(7):
|
||||
case '[':
|
||||
case '-':
|
||||
@ -50,6 +76,13 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
case KEY_DOWN:
|
||||
{
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
case KEY_F(8):
|
||||
case ']':
|
||||
case '+':
|
||||
@ -70,7 +103,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (isalpha(ch))
|
||||
if (ch < 255 && isalpha(ch))
|
||||
result = Panel_selectByTyping(super, ch);
|
||||
if (result == BREAK_LOOP)
|
||||
result = IGNORED;
|
||||
@ -90,47 +123,45 @@ PanelClass ColumnsPanel_class = {
|
||||
.eventHandler = ColumnsPanel_eventHandler
|
||||
};
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings) {
|
||||
ColumnsPanel* this = AllocThis(ColumnsPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
|
||||
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
this->moving = false;
|
||||
Panel_setHeader(super, "Active Columns");
|
||||
|
||||
ProcessField* fields = this->settings->pl->fields;
|
||||
ProcessField* fields = this->settings->fields;
|
||||
for (; *fields; fields++) {
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0));
|
||||
if (Process_fields[*fields].name) {
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
int ColumnsPanel_fieldNameToIndex(const char* name) {
|
||||
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
|
||||
if (String_eq(name, Process_fieldNames[j])) {
|
||||
for (int j = 1; j <= Platform_numberOfFields; j++) {
|
||||
if (String_eq(name, Process_fields[j].name)) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ColumnsPanel_update(Panel* super) {
|
||||
ColumnsPanel* this = (ColumnsPanel*) super;
|
||||
int size = Panel_size(super);
|
||||
this->settings->changed = true;
|
||||
// FIXME: this is crappily inefficient
|
||||
free(this->settings->pl->fields);
|
||||
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
|
||||
this->settings->pl->flags = 0;
|
||||
this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1));
|
||||
this->settings->flags = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
char* text = ((ListItem*) Panel_get(super, i))->value;
|
||||
int j = ColumnsPanel_fieldNameToIndex(text);
|
||||
if (j > 0) {
|
||||
this->settings->pl->fields[i] = j;
|
||||
this->settings->pl->flags |= Process_fieldFlags[j];
|
||||
}
|
||||
int key = ((ListItem*) Panel_get(super, i))->key;
|
||||
this->settings->fields[i] = key;
|
||||
this->settings->flags |= Process_fields[key].flags;
|
||||
}
|
||||
this->settings->pl->fields[size] = 0;
|
||||
this->settings->fields[size] = 0;
|
||||
}
|
||||
|
||||
|
@ -11,19 +11,18 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
typedef struct ColumnsPanel_ {
|
||||
Panel super;
|
||||
|
||||
Settings* settings;
|
||||
ScreenManager* scr;
|
||||
bool moving;
|
||||
} ColumnsPanel;
|
||||
|
||||
|
||||
extern PanelClass ColumnsPanel_class;
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr);
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings);
|
||||
|
||||
int ColumnsPanel_fieldNameToIndex(const char* name);
|
||||
|
||||
|
@ -8,6 +8,7 @@ in the source distribution for its full text.
|
||||
#include "DisplayOptionsPanel.h"
|
||||
|
||||
#include "CheckItem.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@ -27,6 +28,8 @@ typedef struct DisplayOptionsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static void DisplayOptionsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
|
||||
@ -45,6 +48,7 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
case KEY_MOUSE:
|
||||
case KEY_RECLICK:
|
||||
case ' ':
|
||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
||||
result = HANDLED;
|
||||
@ -52,9 +56,9 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
if (result == HANDLED) {
|
||||
this->settings->changed = true;
|
||||
Header* header = this->settings->header;
|
||||
Header_calculateHeight(header);
|
||||
Header_reinit(header);
|
||||
const Header* header = this->scr->header;
|
||||
Header_calculateHeight((Header*) header);
|
||||
Header_reinit((Header*) header);
|
||||
Header_draw(header);
|
||||
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
|
||||
}
|
||||
@ -72,24 +76,26 @@ PanelClass DisplayOptionsPanel_class = {
|
||||
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true);
|
||||
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
|
||||
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
|
||||
Panel_setHeader(super, "Display options");
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->pl->treeView), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->pl->highlightThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->pl->showThreadNames), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->header->margin), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Update process names on every refresh"), &(settings->pl->updateProcessNames), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(strdup("Add guest time in CPU meter percentage"), &(settings->pl->accountGuestInCPUMeter), false));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Tree view"), &(settings->treeView)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Shadow other users' processes"), &(settings->shadowOtherUsers)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide kernel threads"), &(settings->hideKernelThreads)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide userland process threads"), &(settings->hideUserlandThreads)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Display threads in a different color"), &(settings->highlightThreads)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show custom thread names"), &(settings->showThreadNames)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show program path"), &(settings->showProgramPath)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight program \"basename\""), &(settings->highlightBaseName)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Leave a margin around header"), &(settings->headerMargin)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
|
||||
return this;
|
||||
}
|
||||
|
67
EnvScreen.c
Normal file
67
EnvScreen.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include "EnvScreen.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "CRT.h"
|
||||
#include "IncSet.h"
|
||||
#include "ListItem.h"
|
||||
#include "Platform.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*{
|
||||
#include "InfoScreen.h"
|
||||
|
||||
typedef struct EnvScreen_ {
|
||||
InfoScreen super;
|
||||
} EnvScreen;
|
||||
}*/
|
||||
|
||||
InfoScreenClass EnvScreen_class = {
|
||||
.super = {
|
||||
.extends = Class(Object),
|
||||
.delete = EnvScreen_delete
|
||||
},
|
||||
.scan = EnvScreen_scan,
|
||||
.draw = EnvScreen_draw
|
||||
};
|
||||
|
||||
EnvScreen* EnvScreen_new(Process* process) {
|
||||
EnvScreen* this = xMalloc(sizeof(EnvScreen));
|
||||
Object_setClass(this, Class(EnvScreen));
|
||||
return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " ");
|
||||
}
|
||||
|
||||
void EnvScreen_delete(Object* this) {
|
||||
free(InfoScreen_done((InfoScreen*)this));
|
||||
}
|
||||
|
||||
void EnvScreen_draw(InfoScreen* this) {
|
||||
InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, this->process->comm);
|
||||
}
|
||||
|
||||
void EnvScreen_scan(InfoScreen* this) {
|
||||
Panel* panel = this->display;
|
||||
int idx = MAX(Panel_getSelectedIndex(panel), 0);
|
||||
|
||||
Panel_prune(panel);
|
||||
|
||||
uid_t euid = geteuid();
|
||||
(void) seteuid(getuid());
|
||||
char *env = Platform_getProcessEnv(this->process->pid);
|
||||
(void) seteuid(euid);
|
||||
if (env) {
|
||||
for (char *p = env; *p; p = strrchr(p, 0)+1)
|
||||
InfoScreen_addLine(this, p);
|
||||
free(env);
|
||||
}
|
||||
else {
|
||||
InfoScreen_addLine(this, "Could not read process environment.");
|
||||
}
|
||||
|
||||
Vector_insertionSort(this->lines);
|
||||
Vector_insertionSort(panel->items);
|
||||
Panel_setSelected(panel, idx);
|
||||
}
|
22
EnvScreen.h
Normal file
22
EnvScreen.h
Normal file
@ -0,0 +1,22 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_EnvScreen
|
||||
#define HEADER_EnvScreen
|
||||
|
||||
#include "InfoScreen.h"
|
||||
|
||||
typedef struct EnvScreen_ {
|
||||
InfoScreen super;
|
||||
} EnvScreen;
|
||||
|
||||
extern InfoScreenClass EnvScreen_class;
|
||||
|
||||
EnvScreen* EnvScreen_new(Process* process);
|
||||
|
||||
void EnvScreen_delete(Object* this);
|
||||
|
||||
void EnvScreen_draw(InfoScreen* this);
|
||||
|
||||
void EnvScreen_scan(InfoScreen* this);
|
||||
|
||||
#endif
|
@ -6,19 +6,19 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "FunctionBar.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "RichString.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/*{
|
||||
#include "Object.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct FunctionBar_ {
|
||||
Object super;
|
||||
int size;
|
||||
char** functions;
|
||||
char** keys;
|
||||
@ -34,26 +34,30 @@ static const char* FunctionBar_FLabels[] = {" ", " ", " ", "
|
||||
|
||||
static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)};
|
||||
|
||||
ObjectClass FunctionBar_class = {
|
||||
.delete = FunctionBar_delete
|
||||
};
|
||||
static const char* FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
|
||||
static int FunctionBar_EnterEscEvents[] = {13, 27};
|
||||
|
||||
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
|
||||
const char* functions[] = {enter, esc, NULL};
|
||||
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
|
||||
}
|
||||
|
||||
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) {
|
||||
FunctionBar* this = AllocThis(FunctionBar);
|
||||
this->functions = calloc(16, sizeof(char*));
|
||||
FunctionBar* this = xCalloc(1, sizeof(FunctionBar));
|
||||
this->functions = xCalloc(16, sizeof(char*));
|
||||
if (!functions) {
|
||||
functions = FunctionBar_FLabels;
|
||||
}
|
||||
for (int i = 0; i < 15 && functions[i]; i++) {
|
||||
this->functions[i] = strdup(functions[i]);
|
||||
this->functions[i] = xStrdup(functions[i]);
|
||||
}
|
||||
if (keys && events) {
|
||||
this->staticData = false;
|
||||
this->keys = malloc(sizeof(char*) * 15);
|
||||
this->events = malloc(sizeof(int) * 15);
|
||||
this->keys = xCalloc(15, sizeof(char*));
|
||||
this->events = xCalloc(15, sizeof(int));
|
||||
int i = 0;
|
||||
while (i < 15 && functions[i]) {
|
||||
this->keys[i] = strdup(keys[i]);
|
||||
this->keys[i] = xStrdup(keys[i]);
|
||||
this->events[i] = events[i];
|
||||
i++;
|
||||
}
|
||||
@ -67,8 +71,7 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve
|
||||
return this;
|
||||
}
|
||||
|
||||
void FunctionBar_delete(Object* cast) {
|
||||
FunctionBar* this = (FunctionBar*) cast;
|
||||
void FunctionBar_delete(FunctionBar* this) {
|
||||
for (int i = 0; i < 15 && this->functions[i]; i++) {
|
||||
free(this->functions[i]);
|
||||
}
|
||||
@ -87,7 +90,7 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
if (this->events[i] == event) {
|
||||
free(this->functions[i]);
|
||||
this->functions[i] = strdup(text);
|
||||
this->functions[i] = xStrdup(text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct FunctionBar_ {
|
||||
Object super;
|
||||
int size;
|
||||
char** functions;
|
||||
char** keys;
|
||||
@ -21,11 +21,12 @@ typedef struct FunctionBar_ {
|
||||
} FunctionBar;
|
||||
|
||||
|
||||
extern ObjectClass FunctionBar_class;
|
||||
|
||||
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
|
||||
|
||||
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events);
|
||||
|
||||
void FunctionBar_delete(Object* cast);
|
||||
void FunctionBar_delete(FunctionBar* this);
|
||||
|
||||
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
||||
|
||||
|
@ -6,6 +6,7 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Hashtable.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@ -63,7 +64,7 @@ int Hashtable_count(Hashtable* this) {
|
||||
static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
|
||||
HashtableItem* this;
|
||||
|
||||
this = (HashtableItem*) malloc(sizeof(HashtableItem));
|
||||
this = xMalloc(sizeof(HashtableItem));
|
||||
this->key = key;
|
||||
this->value = value;
|
||||
this->next = NULL;
|
||||
@ -73,10 +74,10 @@ static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
|
||||
Hashtable* Hashtable_new(int size, bool owner) {
|
||||
Hashtable* this;
|
||||
|
||||
this = (Hashtable*) malloc(sizeof(Hashtable));
|
||||
this = xMalloc(sizeof(Hashtable));
|
||||
this->items = 0;
|
||||
this->size = size;
|
||||
this->buckets = (HashtableItem**) calloc(size, sizeof(HashtableItem*));
|
||||
this->buckets = (HashtableItem**) xCalloc(size, sizeof(HashtableItem*));
|
||||
this->owner = owner;
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return this;
|
||||
|
217
Header.c
217
Header.c
@ -8,16 +8,8 @@ in the source distribution for its full text.
|
||||
#include "Header.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "MemoryMeter.h"
|
||||
#include "SwapMeter.h"
|
||||
#include "TasksMeter.h"
|
||||
#include "LoadAverageMeter.h"
|
||||
#include "UptimeMeter.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "ClockMeter.h"
|
||||
#include "HostnameMeter.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
@ -25,21 +17,17 @@ in the source distribution for its full text.
|
||||
#include <stdlib.h>
|
||||
|
||||
/*{
|
||||
#include "ProcessList.h"
|
||||
#include "Meter.h"
|
||||
|
||||
typedef enum HeaderSide_ {
|
||||
LEFT_HEADER,
|
||||
RIGHT_HEADER
|
||||
} HeaderSide;
|
||||
#include "Settings.h"
|
||||
#include "Vector.h"
|
||||
|
||||
typedef struct Header_ {
|
||||
Vector* leftMeters;
|
||||
Vector* rightMeters;
|
||||
ProcessList* pl;
|
||||
int height;
|
||||
Vector** columns;
|
||||
Settings* settings;
|
||||
struct ProcessList_* pl;
|
||||
int nrColumns;
|
||||
int pad;
|
||||
bool margin;
|
||||
int height;
|
||||
} Header;
|
||||
|
||||
}*/
|
||||
@ -48,25 +36,73 @@ typedef struct Header_ {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
Header* Header_new(ProcessList* pl) {
|
||||
Header* this = calloc(1, sizeof(Header));
|
||||
this->leftMeters = Vector_new(Class(Meter), true, DEFAULT_SIZE);
|
||||
this->rightMeters = Vector_new(Class(Meter), true, DEFAULT_SIZE);
|
||||
this->margin = true;
|
||||
#ifndef Header_forEachColumn
|
||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||
#endif
|
||||
|
||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) {
|
||||
Header* this = xCalloc(1, sizeof(Header));
|
||||
this->columns = xCalloc(nrColumns, sizeof(Vector*));
|
||||
this->settings = settings;
|
||||
this->pl = pl;
|
||||
this->nrColumns = nrColumns;
|
||||
Header_forEachColumn(this, i) {
|
||||
this->columns[i] = Vector_new(Class(Meter), true, DEFAULT_SIZE);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void Header_delete(Header* this) {
|
||||
Vector_delete(this->leftMeters);
|
||||
Vector_delete(this->rightMeters);
|
||||
Header_forEachColumn(this, i) {
|
||||
Vector_delete(this->columns[i]);
|
||||
}
|
||||
free(this->columns);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void Header_createMeter(Header* this, char* name, HeaderSide side) {
|
||||
Vector* meters = side == LEFT_HEADER
|
||||
? this->leftMeters
|
||||
: this->rightMeters;
|
||||
void Header_populateFromSettings(Header* this) {
|
||||
Header_forEachColumn(this, col) {
|
||||
MeterColumnSettings* colSettings = &this->settings->columns[col];
|
||||
for (int i = 0; i < colSettings->len; i++) {
|
||||
Header_addMeterByName(this, colSettings->names[i], col);
|
||||
if (colSettings->modes[i] != 0) {
|
||||
Header_setMode(this, i, colSettings->modes[i], col);
|
||||
}
|
||||
}
|
||||
}
|
||||
Header_calculateHeight(this);
|
||||
}
|
||||
|
||||
void Header_writeBackToSettings(const Header* this) {
|
||||
Header_forEachColumn(this, col) {
|
||||
MeterColumnSettings* colSettings = &this->settings->columns[col];
|
||||
|
||||
String_freeArray(colSettings->names);
|
||||
free(colSettings->modes);
|
||||
|
||||
Vector* vec = this->columns[col];
|
||||
int len = Vector_size(vec);
|
||||
|
||||
colSettings->names = xCalloc(len+1, sizeof(char*));
|
||||
colSettings->modes = xCalloc(len, sizeof(int));
|
||||
colSettings->len = len;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
Meter* meter = (Meter*) Vector_get(vec, i);
|
||||
char* name = xCalloc(64, sizeof(char));
|
||||
if (meter->param) {
|
||||
snprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param);
|
||||
} else {
|
||||
snprintf(name, 63, "%s", As_Meter(meter)->name);
|
||||
}
|
||||
colSettings->names[i] = name;
|
||||
colSettings->modes[i] = meter->mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MeterModeId Header_addMeterByName(Header* this, char* name, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
|
||||
char* paren = strchr(name, '(');
|
||||
int param = 0;
|
||||
@ -75,18 +111,20 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) {
|
||||
if (!ok) param = 0;
|
||||
*paren = '\0';
|
||||
}
|
||||
for (MeterClass** type = Meter_types; *type; type++) {
|
||||
MeterModeId mode = TEXT_METERMODE;
|
||||
for (MeterClass** type = Platform_meterTypes; *type; type++) {
|
||||
if (String_eq(name, (*type)->name)) {
|
||||
Vector_add(meters, Meter_new(this->pl, param, *type));
|
||||
Meter* meter = Meter_new(this->pl, param, *type);
|
||||
Vector_add(meters, meter);
|
||||
mode = meter->mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) {
|
||||
Vector* meters = side == LEFT_HEADER
|
||||
? this->leftMeters
|
||||
: this->rightMeters;
|
||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
|
||||
if (i >= Vector_size(meters))
|
||||
return;
|
||||
@ -94,33 +132,26 @@ void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) {
|
||||
Meter_setMode(meter, mode);
|
||||
}
|
||||
|
||||
Meter* Header_addMeter(Header* this, MeterClass* type, int param, HeaderSide side) {
|
||||
Vector* meters = side == LEFT_HEADER
|
||||
? this->leftMeters
|
||||
: this->rightMeters;
|
||||
Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
|
||||
Meter* meter = Meter_new(this->pl, param, type);
|
||||
Vector_add(meters, meter);
|
||||
return meter;
|
||||
}
|
||||
|
||||
int Header_size(Header* this, HeaderSide side) {
|
||||
Vector* meters = side == LEFT_HEADER
|
||||
? this->leftMeters
|
||||
: this->rightMeters;
|
||||
|
||||
int Header_size(Header* this, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
return Vector_size(meters);
|
||||
}
|
||||
|
||||
char* Header_readMeterName(Header* this, int i, HeaderSide side) {
|
||||
Vector* meters = side == LEFT_HEADER
|
||||
? this->leftMeters
|
||||
: this->rightMeters;
|
||||
char* Header_readMeterName(Header* this, int i, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
|
||||
int nameLen = strlen(Meter_name(meter));
|
||||
int len = nameLen + 100;
|
||||
char* name = malloc(len);
|
||||
char* name = xMalloc(len);
|
||||
strncpy(name, Meter_name(meter), nameLen);
|
||||
name[nameLen] = '\0';
|
||||
if (meter->param)
|
||||
@ -129,42 +160,20 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) {
|
||||
return name;
|
||||
}
|
||||
|
||||
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) {
|
||||
Vector* meters = side == LEFT_HEADER
|
||||
? this->leftMeters
|
||||
: this->rightMeters;
|
||||
MeterModeId Header_readMeterMode(Header* this, int i, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
return meter->mode;
|
||||
}
|
||||
|
||||
void Header_defaultMeters(Header* this, int cpuCount) {
|
||||
if (cpuCount > 8) {
|
||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LeftCPUs2Meter)));
|
||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(RightCPUs2Meter)));
|
||||
} else if (cpuCount > 4) {
|
||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LeftCPUsMeter)));
|
||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(RightCPUsMeter)));
|
||||
} else {
|
||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(AllCPUsMeter)));
|
||||
}
|
||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(MemoryMeter)));
|
||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(SwapMeter)));
|
||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(TasksMeter)));
|
||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LoadAverageMeter)));
|
||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(UptimeMeter)));
|
||||
}
|
||||
|
||||
void Header_reinit(Header* this) {
|
||||
for (int i = 0; i < Vector_size(this->leftMeters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
|
||||
if (Meter_initFn(meter))
|
||||
Meter_init(meter);
|
||||
}
|
||||
for (int i = 0; i < Vector_size(this->rightMeters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
|
||||
if (Meter_initFn(meter))
|
||||
Meter_init(meter);
|
||||
Header_forEachColumn(this, col) {
|
||||
for (int i = 0; i < Vector_size(this->columns[col]); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->columns[col], i);
|
||||
if (Meter_initFn(meter))
|
||||
Meter_init(meter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,32 +184,34 @@ void Header_draw(const Header* this) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
mvhline(y, 0, ' ', COLS);
|
||||
}
|
||||
for (int y = (pad / 2), i = 0; i < Vector_size(this->leftMeters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
|
||||
meter->draw(meter, pad, y, COLS / 2 - (pad * 2 - 1) - 1);
|
||||
y += meter->h;
|
||||
}
|
||||
for (int y = (pad / 2), i = 0; i < Vector_size(this->rightMeters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
|
||||
meter->draw(meter, COLS / 2 + pad, y, COLS / 2 - (pad * 2 - 1) - 1);
|
||||
y += meter->h;
|
||||
int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1;
|
||||
int x = pad;
|
||||
|
||||
Header_forEachColumn(this, col) {
|
||||
Vector* meters = this->columns[col];
|
||||
for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
meter->draw(meter, x, y, width);
|
||||
y += meter->h;
|
||||
}
|
||||
x += width + pad;
|
||||
}
|
||||
}
|
||||
|
||||
int Header_calculateHeight(Header* this) {
|
||||
int pad = this->margin ? 2 : 0;
|
||||
int leftHeight = pad;
|
||||
int rightHeight = pad;
|
||||
int pad = this->settings->headerMargin ? 2 : 0;
|
||||
int maxHeight = pad;
|
||||
|
||||
for (int i = 0; i < Vector_size(this->leftMeters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
|
||||
leftHeight += meter->h;
|
||||
}
|
||||
for (int i = 0; i < Vector_size(this->rightMeters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
|
||||
rightHeight += meter->h;
|
||||
Header_forEachColumn(this, col) {
|
||||
Vector* meters = this->columns[col];
|
||||
int height = pad;
|
||||
for (int i = 0; i < Vector_size(meters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
height += meter->h;
|
||||
}
|
||||
maxHeight = MAX(maxHeight, height);
|
||||
}
|
||||
this->height = maxHeight;
|
||||
this->pad = pad;
|
||||
this->height = MAX(leftHeight, rightHeight);
|
||||
return this->height;
|
||||
return maxHeight;
|
||||
}
|
||||
|
40
Header.h
40
Header.h
@ -9,21 +9,17 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "Meter.h"
|
||||
|
||||
typedef enum HeaderSide_ {
|
||||
LEFT_HEADER,
|
||||
RIGHT_HEADER
|
||||
} HeaderSide;
|
||||
#include "Settings.h"
|
||||
#include "Vector.h"
|
||||
|
||||
typedef struct Header_ {
|
||||
Vector* leftMeters;
|
||||
Vector* rightMeters;
|
||||
ProcessList* pl;
|
||||
int height;
|
||||
Vector** columns;
|
||||
Settings* settings;
|
||||
struct ProcessList_* pl;
|
||||
int nrColumns;
|
||||
int pad;
|
||||
bool margin;
|
||||
int height;
|
||||
} Header;
|
||||
|
||||
|
||||
@ -31,23 +27,29 @@ typedef struct Header_ {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
Header* Header_new(ProcessList* pl);
|
||||
#ifndef Header_forEachColumn
|
||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||
#endif
|
||||
|
||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
||||
|
||||
void Header_delete(Header* this);
|
||||
|
||||
void Header_createMeter(Header* this, char* name, HeaderSide side);
|
||||
void Header_populateFromSettings(Header* this);
|
||||
|
||||
void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side);
|
||||
void Header_writeBackToSettings(const Header* this);
|
||||
|
||||
Meter* Header_addMeter(Header* this, MeterClass* type, int param, HeaderSide side);
|
||||
MeterModeId Header_addMeterByName(Header* this, char* name, int column);
|
||||
|
||||
int Header_size(Header* this, HeaderSide side);
|
||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
||||
|
||||
char* Header_readMeterName(Header* this, int i, HeaderSide side);
|
||||
Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column);
|
||||
|
||||
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side);
|
||||
int Header_size(Header* this, int column);
|
||||
|
||||
void Header_defaultMeters(Header* this, int cpuCount);
|
||||
char* Header_readMeterName(Header* this, int i, int column);
|
||||
|
||||
MeterModeId Header_readMeterMode(Header* this, int i, int column);
|
||||
|
||||
void Header_reinit(Header* this);
|
||||
|
||||
|
@ -19,7 +19,7 @@ int HostnameMeter_attributes[] = {
|
||||
HOSTNAME
|
||||
};
|
||||
|
||||
static void HostnameMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
(void) this;
|
||||
gethostname(buffer, size-1);
|
||||
}
|
||||
@ -29,8 +29,9 @@ MeterClass HostnameMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = HostnameMeter_setValues,
|
||||
.updateValues = HostnameMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 0,
|
||||
.total = 100.0,
|
||||
.attributes = HostnameMeter_attributes,
|
||||
.name = "Hostname",
|
||||
|
233
INSTALL
233
INSTALL
@ -1,13 +1,25 @@
|
||||
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
||||
Foundation, Inc.
|
||||
Installation Instructions
|
||||
*************************
|
||||
|
||||
This file is free documentation; the Free Software Foundation gives
|
||||
unlimited permission to copy, distribute and modify it.
|
||||
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved. This file is offered as-is,
|
||||
without warranty of any kind.
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
These are generic installation instructions.
|
||||
Briefly, the shell command `./configure && make && make install'
|
||||
should configure, build, and install this package. The following
|
||||
more-detailed instructions are generic; see the `README' file for
|
||||
instructions specific to this package. Some packages provide this
|
||||
`INSTALL' file but do not implement all of the features documented
|
||||
below. The lack of an optional feature in a given package is not
|
||||
necessarily a bug. More recommendations for GNU packages can be found
|
||||
in *note Makefile Conventions: (standards)Makefile Conventions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
@ -20,9 +32,9 @@ debugging `configure').
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. (Caching is
|
||||
the results of its tests to speed up reconfiguring. Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.)
|
||||
cache files.
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
@ -32,30 +44,37 @@ some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You only need
|
||||
`configure.ac' if you want to change it or regenerate `configure' using
|
||||
a newer version of `autoconf'.
|
||||
`configure' by a program called `autoconf'. You need `configure.ac' if
|
||||
you want to change it or regenerate `configure' using a newer version
|
||||
of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system. If you're
|
||||
using `csh' on an old version of System V, you might need to type
|
||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||
`configure' itself.
|
||||
`./configure' to configure the package for your system.
|
||||
|
||||
Running `configure' takes awhile. While running, it prints some
|
||||
messages telling which features it is checking for.
|
||||
Running `configure' might take a while. While running, it prints
|
||||
some messages telling which features it is checking for.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package.
|
||||
the package, generally using the just-built uninstalled binaries.
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation.
|
||||
documentation. When installing into a prefix owned by root, it is
|
||||
recommended that the package be configured and built as a regular
|
||||
user, and only the `make install' phase executed with root
|
||||
privileges.
|
||||
|
||||
5. You can remove the program binaries and object files from the
|
||||
5. Optionally, type `make installcheck' to repeat any self-tests, but
|
||||
this time using the binaries in their final installed location.
|
||||
This target does not install anything. Running this target as a
|
||||
regular user, particularly if the prior `make install' required
|
||||
root privileges, verifies that the installation completed
|
||||
correctly.
|
||||
|
||||
6. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
@ -64,6 +83,16 @@ The simplest way to compile this package is:
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
|
||||
7. Often, you can also type `make uninstall' to remove the installed
|
||||
files again. In practice, not all packages have tested that
|
||||
uninstallation works correctly, even though it is required by the
|
||||
GNU Coding Standards.
|
||||
|
||||
8. Some packages, particularly those that use Automake, provide `make
|
||||
distcheck', which can by used by developers to test that all other
|
||||
targets like `make install' and `make uninstall' work correctly.
|
||||
This target is generally not run by end users.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
@ -75,7 +104,7 @@ for details on some of the pertinent environment variables.
|
||||
by setting variables in the command line or in the environment. Here
|
||||
is an example:
|
||||
|
||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||
./configure CC=c99 CFLAGS=-g LIBS=-lposix
|
||||
|
||||
*Note Defining Variables::, for more details.
|
||||
|
||||
@ -84,44 +113,89 @@ Compiling For Multiple Architectures
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you must use a version of `make' that
|
||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||
own directory. To do this, you can use GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'.
|
||||
source code in the directory that `configure' is in and in `..'. This
|
||||
is known as a "VPATH" build.
|
||||
|
||||
If you have to use a `make' that does not support the `VPATH'
|
||||
variable, you have to compile the package for one architecture at a
|
||||
time in the source code directory. After you have installed the
|
||||
package for one architecture, use `make distclean' before reconfiguring
|
||||
for another architecture.
|
||||
With a non-GNU `make', it is safer to compile the package for one
|
||||
architecture at a time in the source code directory. After you have
|
||||
installed the package for one architecture, use `make distclean' before
|
||||
reconfiguring for another architecture.
|
||||
|
||||
On MacOS X 10.5 and later systems, you can create libraries and
|
||||
executables that work on multiple system types--known as "fat" or
|
||||
"universal" binaries--by specifying multiple `-arch' options to the
|
||||
compiler but only a single `-arch' option to the preprocessor. Like
|
||||
this:
|
||||
|
||||
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
|
||||
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
|
||||
CPP="gcc -E" CXXCPP="g++ -E"
|
||||
|
||||
This is not guaranteed to produce working output in all cases, you
|
||||
may have to build one architecture at a time and combine the results
|
||||
using the `lipo' tool if you have problems.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' will install the package's files in
|
||||
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||
installation prefix other than `/usr/local' by giving `configure' the
|
||||
option `--prefix=PATH'.
|
||||
By default, `make install' installs the package's commands under
|
||||
`/usr/local/bin', include files under `/usr/local/include', etc. You
|
||||
can specify an installation prefix other than `/usr/local' by giving
|
||||
`configure' the option `--prefix=PREFIX', where PREFIX must be an
|
||||
absolute file name.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||
PATH as the prefix for installing programs and libraries.
|
||||
Documentation and other data files will still use the regular prefix.
|
||||
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
|
||||
PREFIX as the prefix for installing programs and libraries.
|
||||
Documentation and other data files still use the regular prefix.
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=PATH' to specify different values for particular
|
||||
options like `--bindir=DIR' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them.
|
||||
you can set and what kinds of files go in them. In general, the
|
||||
default for these options is expressed in terms of `${prefix}', so that
|
||||
specifying just `--prefix' will affect all of the other directory
|
||||
specifications that were not explicitly provided.
|
||||
|
||||
The most portable way to affect installation locations is to pass the
|
||||
correct locations to `configure'; however, many packages provide one or
|
||||
both of the following shortcuts of passing variable assignments to the
|
||||
`make install' command line to change installation locations without
|
||||
having to reconfigure or recompile.
|
||||
|
||||
The first method involves providing an override variable for each
|
||||
affected directory. For example, `make install
|
||||
prefix=/alternate/directory' will choose an alternate location for all
|
||||
directory configuration variables that were expressed in terms of
|
||||
`${prefix}'. Any directories that were specified during `configure',
|
||||
but not in terms of `${prefix}', must each be overridden at install
|
||||
time for the entire installation to be relocated. The approach of
|
||||
makefile variable overrides for each directory variable is required by
|
||||
the GNU Coding Standards, and ideally causes no recompilation.
|
||||
However, some platforms have known limitations with the semantics of
|
||||
shared libraries that end up requiring recompilation when using this
|
||||
method, particularly noticeable in packages that use GNU Libtool.
|
||||
|
||||
The second method involves providing the `DESTDIR' variable. For
|
||||
example, `make install DESTDIR=/alternate/directory' will prepend
|
||||
`/alternate/directory' before all installation names. The approach of
|
||||
`DESTDIR' overrides is not required by the GNU Coding Standards, and
|
||||
does not work on platforms that have drive letters. On the other hand,
|
||||
it does better at avoiding recompilation issues, and works well even
|
||||
when some directory options were not specified in terms of `${prefix}'
|
||||
at `configure' time.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
@ -134,6 +208,50 @@ find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Some packages offer the ability to configure how verbose the
|
||||
execution of `make' will be. For these packages, running `./configure
|
||||
--enable-silent-rules' sets the default to minimal output, which can be
|
||||
overridden with `make V=1'; while running `./configure
|
||||
--disable-silent-rules' sets the default to verbose, which can be
|
||||
overridden with `make V=0'.
|
||||
|
||||
Particular systems
|
||||
==================
|
||||
|
||||
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
|
||||
CC is not installed, it is recommended to use the following options in
|
||||
order to use an ANSI C compiler:
|
||||
|
||||
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
|
||||
|
||||
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
|
||||
|
||||
HP-UX `make' updates targets which have the same time stamps as
|
||||
their prerequisites, which makes it generally unusable when shipped
|
||||
generated files such as `configure' are involved. Use GNU `make'
|
||||
instead.
|
||||
|
||||
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
|
||||
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
|
||||
a workaround. If GNU CC is not installed, it is therefore recommended
|
||||
to try
|
||||
|
||||
./configure CC="cc"
|
||||
|
||||
and if that doesn't work, try
|
||||
|
||||
./configure CC="cc -nodtk"
|
||||
|
||||
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
|
||||
directory contains several dysfunctional programs; working variants of
|
||||
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
|
||||
in your `PATH', put it _after_ `/usr/bin'.
|
||||
|
||||
On Haiku, software installed for all users goes in `/boot/common',
|
||||
not `/usr/local'. It is recommended to use the following options:
|
||||
|
||||
./configure --prefix=/boot/common
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
@ -149,14 +267,15 @@ type, such as `sun4', or a canonical name which has the form:
|
||||
|
||||
where SYSTEM can have one of these forms:
|
||||
|
||||
OS KERNEL-OS
|
||||
OS
|
||||
KERNEL-OS
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the machine type.
|
||||
|
||||
If you are _building_ compiler tools for cross-compiling, you should
|
||||
use the `--target=TYPE' option to select the type of system they will
|
||||
use the option `--target=TYPE' to select the type of system they will
|
||||
produce code for.
|
||||
|
||||
If you want to _use_ a cross compiler, that generates code for a
|
||||
@ -186,9 +305,15 @@ them in the `configure' command line, using `VAR=value'. For example:
|
||||
|
||||
./configure CC=/usr/local2/bin/gcc
|
||||
|
||||
will cause the specified gcc to be used as the C compiler (unless it is
|
||||
causes the specified `gcc' to be used as the C compiler (unless it is
|
||||
overridden in the site shell script).
|
||||
|
||||
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
|
||||
an Autoconf limitation. Until the limitation is lifted, you can use
|
||||
this workaround:
|
||||
|
||||
CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
|
||||
|
||||
`configure' Invocation
|
||||
======================
|
||||
|
||||
@ -197,7 +322,14 @@ operates.
|
||||
|
||||
`--help'
|
||||
`-h'
|
||||
Print a summary of the options to `configure', and exit.
|
||||
Print a summary of all of the options to `configure', and exit.
|
||||
|
||||
`--help=short'
|
||||
`--help=recursive'
|
||||
Print a summary of the options unique to this package's
|
||||
`configure', and exit. The `short' variant lists options used
|
||||
only in the top level, while the `recursive' variant lists options
|
||||
also present in any nested packages.
|
||||
|
||||
`--version'
|
||||
`-V'
|
||||
@ -224,6 +356,15 @@ operates.
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`--prefix=DIR'
|
||||
Use DIR as the installation prefix. *note Installation Names::
|
||||
for more details, including other options available for fine-tuning
|
||||
the installation locations.
|
||||
|
||||
`--no-create'
|
||||
`-n'
|
||||
Run the configure checks, but stop before creating any output
|
||||
files.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options. Run
|
||||
`configure --help' for more details.
|
||||
|
||||
|
82
IncSet.c
82
IncSet.c
@ -6,7 +6,7 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "IncSet.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "Panel.h"
|
||||
#include "ListItem.h"
|
||||
#include "CRT.h"
|
||||
@ -38,9 +38,9 @@ typedef struct IncMode_ {
|
||||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
FunctionBar* bar;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
} IncSet;
|
||||
|
||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
@ -73,16 +73,15 @@ static inline void IncMode_initFilter(IncMode* filter) {
|
||||
}
|
||||
|
||||
static inline void IncMode_done(IncMode* mode) {
|
||||
FunctionBar_delete((Object*)mode->bar);
|
||||
FunctionBar_delete(mode->bar);
|
||||
}
|
||||
|
||||
IncSet* IncSet_new(FunctionBar* bar) {
|
||||
IncSet* this = calloc(1, sizeof(IncSet));
|
||||
IncSet* this = xCalloc(1, sizeof(IncSet));
|
||||
IncMode_initSearch(&(this->modes[INC_SEARCH]));
|
||||
IncMode_initFilter(&(this->modes[INC_FILTER]));
|
||||
this->active = NULL;
|
||||
this->filtering = false;
|
||||
this->bar = bar;
|
||||
this->defaultBar = bar;
|
||||
return this;
|
||||
}
|
||||
@ -116,7 +115,7 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
|
||||
}
|
||||
}
|
||||
|
||||
static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
int size = Panel_size(panel);
|
||||
bool found = false;
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -130,6 +129,7 @@ static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
|
||||
FunctionBar_draw(mode->bar, mode->buffer);
|
||||
else
|
||||
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
||||
@ -137,7 +137,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
return true;
|
||||
IncMode* mode = this->active;
|
||||
int size = Panel_size(panel);
|
||||
bool filterChange = false;
|
||||
bool filterChanged = false;
|
||||
bool doSearch = true;
|
||||
if (ch == KEY_F(3)) {
|
||||
if (size == 0) return true;
|
||||
@ -153,27 +153,35 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
}
|
||||
}
|
||||
doSearch = false;
|
||||
} else if (isprint((char)ch) && (mode->index < INCMODE_MAX)) {
|
||||
mode->buffer[mode->index] = ch;
|
||||
mode->index++;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChange = true;
|
||||
if (mode->index == 1) this->filtering = true;
|
||||
}
|
||||
} else if ((ch == KEY_BACKSPACE || ch == 127) && (mode->index > 0)) {
|
||||
mode->index--;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChange = true;
|
||||
if (mode->index == 0) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
} else if (ch < 255 && isprint((char)ch)) {
|
||||
if (mode->index < INCMODE_MAX) {
|
||||
mode->buffer[mode->index] = ch;
|
||||
mode->index++;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChanged = true;
|
||||
if (mode->index == 1) this->filtering = true;
|
||||
}
|
||||
}
|
||||
} else if ((ch == KEY_BACKSPACE || ch == 127)) {
|
||||
if (mode->index > 0) {
|
||||
mode->index--;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChanged = true;
|
||||
if (mode->index == 0) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doSearch = false;
|
||||
}
|
||||
} else if (ch == KEY_RESIZE) {
|
||||
Panel_resize(panel, COLS, LINES-panel->y-1);
|
||||
} else {
|
||||
if (mode->isFilter) {
|
||||
filterChange = true;
|
||||
filterChanged = true;
|
||||
if (ch == 27) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
@ -182,17 +190,17 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
IncMode_reset(mode);
|
||||
}
|
||||
this->active = NULL;
|
||||
this->bar = this->defaultBar;
|
||||
Panel_setDefaultBar(panel);
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
doSearch = false;
|
||||
}
|
||||
if (doSearch) {
|
||||
search(mode, panel, getPanelValue);
|
||||
this->found = search(mode, panel, getPanelValue);
|
||||
}
|
||||
if (filterChange && lines) {
|
||||
if (filterChanged && lines) {
|
||||
updateWeakPanel(this, panel, lines);
|
||||
}
|
||||
return filterChange;
|
||||
return filterChanged;
|
||||
}
|
||||
|
||||
const char* IncSet_getListItemValue(Panel* panel, int i) {
|
||||
@ -202,12 +210,24 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type) {
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||
this->active = &(this->modes[type]);
|
||||
this->bar = this->active->bar;
|
||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||
panel->currentBar = this->active->bar;
|
||||
}
|
||||
|
||||
void IncSet_drawBar(IncSet* this) {
|
||||
FunctionBar_draw(this->bar, this->active ? this->active->buffer : NULL);
|
||||
if (this->active) {
|
||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||
} else {
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int IncSet_synthesizeEvent(IncSet* this, int x) {
|
||||
if (this->active) {
|
||||
return FunctionBar_synthesizeEvent(this->active->bar, x);
|
||||
} else {
|
||||
return FunctionBar_synthesizeEvent(this->defaultBar, x);
|
||||
}
|
||||
}
|
||||
|
6
IncSet.h
6
IncSet.h
@ -33,9 +33,9 @@ typedef struct IncMode_ {
|
||||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
FunctionBar* bar;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
} IncSet;
|
||||
|
||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
@ -49,8 +49,10 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
|
||||
const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type);
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||
|
||||
void IncSet_drawBar(IncSet* this);
|
||||
|
||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||
|
||||
#endif
|
||||
|
182
InfoScreen.c
Normal file
182
InfoScreen.c
Normal file
@ -0,0 +1,182 @@
|
||||
#include "InfoScreen.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "Object.h"
|
||||
#include "CRT.h"
|
||||
#include "IncSet.h"
|
||||
#include "ListItem.h"
|
||||
#include "Platform.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*{
|
||||
#include "Process.h"
|
||||
#include "Panel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "IncSet.h"
|
||||
|
||||
typedef struct InfoScreen_ InfoScreen;
|
||||
|
||||
typedef void(*InfoScreen_Scan)(InfoScreen*);
|
||||
typedef void(*InfoScreen_Draw)(InfoScreen*);
|
||||
typedef void(*InfoScreen_OnErr)(InfoScreen*);
|
||||
typedef bool(*InfoScreen_OnKey)(InfoScreen*, int);
|
||||
|
||||
typedef struct InfoScreenClass_ {
|
||||
ObjectClass super;
|
||||
const InfoScreen_Scan scan;
|
||||
const InfoScreen_Draw draw;
|
||||
const InfoScreen_OnErr onErr;
|
||||
const InfoScreen_OnKey onKey;
|
||||
} InfoScreenClass;
|
||||
|
||||
#define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass))
|
||||
#define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_))
|
||||
#define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_))
|
||||
#define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_))
|
||||
#define InfoScreen_onKey(this_, ch_) As_InfoScreen(this_)->onKey((InfoScreen*)(this_), ch_)
|
||||
|
||||
struct InfoScreen_ {
|
||||
Object super;
|
||||
Process* process;
|
||||
Panel* display;
|
||||
FunctionBar* bar;
|
||||
IncSet* inc;
|
||||
Vector* lines;
|
||||
};
|
||||
}*/
|
||||
|
||||
static const char* InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
|
||||
|
||||
static const char* InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"};
|
||||
|
||||
static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};
|
||||
|
||||
InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader) {
|
||||
this->process = process;
|
||||
if (!bar) {
|
||||
bar = FunctionBar_new(InfoScreenFunctions, InfoScreenKeys, InfoScreenEvents);
|
||||
}
|
||||
this->display = Panel_new(0, 1, COLS, height, false, Class(ListItem), bar);
|
||||
this->inc = IncSet_new(bar);
|
||||
this->lines = Vector_new(this->display->items->type, true, DEFAULT_SIZE);
|
||||
Panel_setHeader(this->display, panelHeader);
|
||||
return this;
|
||||
}
|
||||
|
||||
InfoScreen* InfoScreen_done(InfoScreen* this) {
|
||||
Panel_delete((Object*)this->display);
|
||||
IncSet_delete(this->inc);
|
||||
Vector_delete(this->lines);
|
||||
return this;
|
||||
}
|
||||
|
||||
void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
mvhline(0, 0, ' ', COLS);
|
||||
wmove(stdscr, 0, 0);
|
||||
vw_printw(stdscr, fmt, ap);
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
this->display->needsRedraw = true;
|
||||
Panel_draw(this->display, true);
|
||||
IncSet_drawBar(this->inc);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
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))
|
||||
Panel_add(this->display, (Object*)Vector_get(this->lines, Vector_size(this->lines)-1));
|
||||
}
|
||||
|
||||
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))
|
||||
Panel_add(this->display, (Object*)last);
|
||||
}
|
||||
|
||||
void InfoScreen_run(InfoScreen* this) {
|
||||
Panel* panel = this->display;
|
||||
|
||||
if (As_InfoScreen(this)->scan) InfoScreen_scan(this);
|
||||
InfoScreen_draw(this);
|
||||
|
||||
bool looping = true;
|
||||
while (looping) {
|
||||
|
||||
Panel_draw(panel, true);
|
||||
|
||||
if (this->inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
set_escdelay(25);
|
||||
int ch = getch();
|
||||
|
||||
if (ch == ERR) {
|
||||
if (As_InfoScreen(this)->onErr) {
|
||||
InfoScreen_onErr(this);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == KEY_MOUSE) {
|
||||
MEVENT mevent;
|
||||
int ok = getmouse(&mevent);
|
||||
if (ok == OK)
|
||||
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
||||
ch = 0;
|
||||
} if (mevent.y == LINES - 1)
|
||||
ch = IncSet_synthesizeEvent(this->inc, mevent.x);
|
||||
}
|
||||
|
||||
if (this->inc->active) {
|
||||
IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(ch) {
|
||||
case ERR:
|
||||
continue;
|
||||
case KEY_F(3):
|
||||
case '/':
|
||||
IncSet_activate(this->inc, INC_SEARCH, panel);
|
||||
break;
|
||||
case KEY_F(4):
|
||||
case '\\':
|
||||
IncSet_activate(this->inc, INC_FILTER, panel);
|
||||
break;
|
||||
case KEY_F(5):
|
||||
clear();
|
||||
if (As_InfoScreen(this)->scan) InfoScreen_scan(this);
|
||||
InfoScreen_draw(this);
|
||||
break;
|
||||
case '\014': // Ctrl+L
|
||||
clear();
|
||||
InfoScreen_draw(this);
|
||||
break;
|
||||
case 'q':
|
||||
case 27:
|
||||
case KEY_F(10):
|
||||
looping = false;
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
Panel_resize(panel, COLS, LINES-2);
|
||||
InfoScreen_draw(this);
|
||||
break;
|
||||
default:
|
||||
if (As_InfoScreen(this)->onKey && InfoScreen_onKey(this, ch)) {
|
||||
continue;
|
||||
}
|
||||
Panel_onKey(panel, ch);
|
||||
}
|
||||
}
|
||||
}
|
53
InfoScreen.h
Normal file
53
InfoScreen.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_InfoScreen
|
||||
#define HEADER_InfoScreen
|
||||
|
||||
#include "Process.h"
|
||||
#include "Panel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "IncSet.h"
|
||||
|
||||
typedef struct InfoScreen_ InfoScreen;
|
||||
|
||||
typedef void(*InfoScreen_Scan)(InfoScreen*);
|
||||
typedef void(*InfoScreen_Draw)(InfoScreen*);
|
||||
typedef void(*InfoScreen_OnErr)(InfoScreen*);
|
||||
typedef bool(*InfoScreen_OnKey)(InfoScreen*, int);
|
||||
|
||||
typedef struct InfoScreenClass_ {
|
||||
ObjectClass super;
|
||||
const InfoScreen_Scan scan;
|
||||
const InfoScreen_Draw draw;
|
||||
const InfoScreen_OnErr onErr;
|
||||
const InfoScreen_OnKey onKey;
|
||||
} InfoScreenClass;
|
||||
|
||||
#define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass))
|
||||
#define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_))
|
||||
#define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_))
|
||||
#define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_))
|
||||
#define InfoScreen_onKey(this_, ch_) As_InfoScreen(this_)->onKey((InfoScreen*)(this_), ch_)
|
||||
|
||||
struct InfoScreen_ {
|
||||
Object super;
|
||||
Process* process;
|
||||
Panel* display;
|
||||
FunctionBar* bar;
|
||||
IncSet* inc;
|
||||
Vector* lines;
|
||||
};
|
||||
|
||||
InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader);
|
||||
|
||||
InfoScreen* InfoScreen_done(InfoScreen* this);
|
||||
|
||||
void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...);
|
||||
|
||||
void InfoScreen_addLine(InfoScreen* this, const char* line);
|
||||
|
||||
void InfoScreen_appendLine(InfoScreen* this, const char* line);
|
||||
|
||||
void InfoScreen_run(InfoScreen* this);
|
||||
|
||||
#endif
|
23
ListItem.c
23
ListItem.c
@ -8,7 +8,7 @@ in the source distribution for its full text.
|
||||
#include "ListItem.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "RichString.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -22,6 +22,7 @@ typedef struct ListItem_ {
|
||||
Object super;
|
||||
char* value;
|
||||
int key;
|
||||
bool moving;
|
||||
} ListItem;
|
||||
|
||||
}*/
|
||||
@ -33,14 +34,23 @@ static void ListItem_delete(Object* cast) {
|
||||
}
|
||||
|
||||
static void ListItem_display(Object* cast, RichString* out) {
|
||||
ListItem* this = (ListItem*)cast;
|
||||
ListItem* const this = (ListItem*)cast;
|
||||
assert (this != NULL);
|
||||
/*
|
||||
int len = strlen(this->value)+1;
|
||||
char buffer[len+1];
|
||||
snprintf(buffer, len, "%s", this->value);
|
||||
*/
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/);
|
||||
if (this->moving) {
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR],
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
CRT_utf8 ? "↕ " :
|
||||
#endif
|
||||
"+ ");
|
||||
} else {
|
||||
RichString_prune(out);
|
||||
}
|
||||
RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/);
|
||||
}
|
||||
|
||||
ObjectClass ListItem_class = {
|
||||
@ -51,8 +61,9 @@ ObjectClass ListItem_class = {
|
||||
|
||||
ListItem* ListItem_new(const char* value, int key) {
|
||||
ListItem* this = AllocThis(ListItem);
|
||||
this->value = strdup(value);
|
||||
this->value = xStrdup(value);
|
||||
this->key = key;
|
||||
this->moving = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -60,7 +71,7 @@ void ListItem_append(ListItem* this, const char* text) {
|
||||
int oldLen = strlen(this->value);
|
||||
int textLen = strlen(text);
|
||||
int newLen = strlen(this->value) + textLen;
|
||||
this->value = realloc(this->value, newLen + 1);
|
||||
this->value = xRealloc(this->value, newLen + 1);
|
||||
memcpy(this->value + oldLen, text, textLen);
|
||||
this->value[newLen] = '\0';
|
||||
}
|
||||
@ -69,7 +80,7 @@ const char* ListItem_getRef(ListItem* this) {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
int ListItem_compare(const void* cast1, const void* cast2) {
|
||||
long ListItem_compare(const void* cast1, const void* cast2) {
|
||||
ListItem* obj1 = (ListItem*) cast1;
|
||||
ListItem* obj2 = (ListItem*) cast2;
|
||||
return strcmp(obj1->value, obj2->value);
|
||||
|
@ -15,6 +15,7 @@ typedef struct ListItem_ {
|
||||
Object super;
|
||||
char* value;
|
||||
int key;
|
||||
bool moving;
|
||||
} ListItem;
|
||||
|
||||
|
||||
@ -26,7 +27,7 @@ void ListItem_append(ListItem* this, const char* text);
|
||||
|
||||
const char* ListItem_getRef(ListItem* this);
|
||||
|
||||
int ListItem_compare(const void* cast1, const void* cast2);
|
||||
long ListItem_compare(const void* cast1, const void* cast2);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -8,51 +8,37 @@ in the source distribution for its full text.
|
||||
#include "LoadAverageMeter.h"
|
||||
|
||||
#include "CRT.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include "Platform.h"
|
||||
|
||||
/*{
|
||||
#include "Meter.h"
|
||||
}*/
|
||||
|
||||
int LoadAverageMeter_attributes[] = {
|
||||
LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE
|
||||
LOAD_AVERAGE_ONE, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_FIFTEEN
|
||||
};
|
||||
|
||||
int LoadMeter_attributes[] = { LOAD };
|
||||
|
||||
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
|
||||
int activeProcs, totalProcs, lastProc;
|
||||
*one = 0; *five = 0; *fifteen = 0;
|
||||
FILE *fd = fopen(PROCDIR "/loadavg", "r");
|
||||
if (fd) {
|
||||
int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen,
|
||||
&activeProcs, &totalProcs, &lastProc);
|
||||
(void) total;
|
||||
assert(total == 6);
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
|
||||
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
|
||||
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
|
||||
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
|
||||
}
|
||||
|
||||
static void LoadAverageMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
char buffer[20];
|
||||
sprintf(buffer, "%.2f ", this->values[2]);
|
||||
RichString_write(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[0]);
|
||||
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[1]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[0]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[2]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
||||
}
|
||||
|
||||
static void LoadMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
double five, fifteen;
|
||||
LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
|
||||
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
|
||||
if (this->values[0] > this->total) {
|
||||
this->total = this->values[0];
|
||||
}
|
||||
@ -72,13 +58,14 @@ MeterClass LoadAverageMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = LoadAverageMeter_display,
|
||||
},
|
||||
.setValues = LoadAverageMeter_setValues,
|
||||
.updateValues = LoadAverageMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 3,
|
||||
.total = 100.0,
|
||||
.attributes = LoadAverageMeter_attributes,
|
||||
.name = "LoadAverage",
|
||||
.uiName = "Load average",
|
||||
.description = "Load averages: 1 minute, 5 minutes, 15 minutes",
|
||||
.caption = "Load average: "
|
||||
};
|
||||
|
||||
@ -88,11 +75,13 @@ MeterClass LoadMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = LoadMeter_display,
|
||||
},
|
||||
.setValues = LoadMeter_setValues,
|
||||
.updateValues = LoadMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = LoadMeter_attributes,
|
||||
.name = "Load",
|
||||
.uiName = "Load",
|
||||
.description = "Load: average of ready processes in the last minute",
|
||||
.caption = "Load: "
|
||||
};
|
||||
|
202
MainPanel.c
Normal file
202
MainPanel.c
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
htop - ColumnsPanel.c
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "MainPanel.h"
|
||||
#include "Process.h"
|
||||
#include "Platform.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/*{
|
||||
#include "Panel.h"
|
||||
#include "Action.h"
|
||||
#include "Settings.h"
|
||||
|
||||
typedef struct MainPanel_ {
|
||||
Panel super;
|
||||
State* state;
|
||||
IncSet* inc;
|
||||
Htop_Action *keys;
|
||||
pid_t pidSearch;
|
||||
} MainPanel;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
}*/
|
||||
|
||||
static const char* MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||
if (mode) {
|
||||
FunctionBar_setLabel(bar, KEY_F(5), "Sorted");
|
||||
FunctionBar_setLabel(bar, KEY_F(6), "Collap");
|
||||
} else {
|
||||
FunctionBar_setLabel(bar, KEY_F(5), "Tree ");
|
||||
FunctionBar_setLabel(bar, KEY_F(6), "SortBy");
|
||||
}
|
||||
}
|
||||
|
||||
void MainPanel_pidSearch(MainPanel* this, int ch) {
|
||||
Panel* super = (Panel*) this;
|
||||
pid_t pid = ch-48 + this->pidSearch;
|
||||
for (int i = 0; i < Panel_size(super); i++) {
|
||||
Process* p = (Process*) Panel_get(super, i);
|
||||
if (p && p->pid == pid) {
|
||||
Panel_setSelected(super, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->pidSearch = pid * 10;
|
||||
if (this->pidSearch > 10000000) {
|
||||
this->pidSearch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
MainPanel* this = (MainPanel*) super;
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
|
||||
Htop_Reaction reaction = HTOP_OK;
|
||||
|
||||
if (EVENT_IS_HEADER_CLICK(ch)) {
|
||||
int x = EVENT_HEADER_CLICK_GET_X(ch);
|
||||
ProcessList* pl = this->state->pl;
|
||||
Settings* settings = this->state->settings;
|
||||
int hx = super->scrollH + x + 1;
|
||||
ProcessField field = ProcessList_keyAt(pl, hx);
|
||||
if (field == settings->sortKey) {
|
||||
Settings_invertSortOrder(settings);
|
||||
settings->treeView = false;
|
||||
} else {
|
||||
reaction |= Action_setSortKey(settings, field);
|
||||
}
|
||||
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
||||
result = HANDLED;
|
||||
} else if (ch != ERR && this->inc->active) {
|
||||
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
||||
if (this->inc->found) {
|
||||
reaction |= Action_follow(this->state);
|
||||
}
|
||||
if (filterChanged) {
|
||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
result = HANDLED;
|
||||
} else if (ch == 27) {
|
||||
return HANDLED;
|
||||
} else if (ch != ERR && ch > 0 && ch < KEY_MAX && this->keys[ch]) {
|
||||
reaction |= (this->keys[ch])(this->state);
|
||||
result = HANDLED;
|
||||
} else if (isdigit(ch)) {
|
||||
MainPanel_pidSearch(this, ch);
|
||||
} else {
|
||||
if (ch != ERR) {
|
||||
this->pidSearch = 0;
|
||||
} else {
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
}
|
||||
|
||||
if (reaction & HTOP_REDRAW_BAR) {
|
||||
MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
|
||||
IncSet_drawBar(this->inc);
|
||||
}
|
||||
if (reaction & HTOP_UPDATE_PANELHDR) {
|
||||
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
|
||||
}
|
||||
if (reaction & HTOP_REFRESH) {
|
||||
result |= REDRAW;
|
||||
}
|
||||
if (reaction & HTOP_RECALCULATE) {
|
||||
result |= RESCAN;
|
||||
}
|
||||
if (reaction & HTOP_SAVE_SETTINGS) {
|
||||
this->state->settings->changed = true;
|
||||
}
|
||||
if (reaction & HTOP_QUIT) {
|
||||
return BREAK_LOOP;
|
||||
}
|
||||
if (!(reaction & HTOP_KEEP_FOLLOWING)) {
|
||||
this->state->pl->following = -1;
|
||||
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int MainPanel_selectedPid(MainPanel* this) {
|
||||
Process* p = (Process*) Panel_getSelected((Panel*)this);
|
||||
if (p) {
|
||||
return p->pid;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* MainPanel_getValue(MainPanel* this, int i) {
|
||||
Process* p = (Process*) Panel_get((Panel*)this, i);
|
||||
if (p)
|
||||
return p->comm;
|
||||
return "";
|
||||
}
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged) {
|
||||
Panel* super = (Panel*) this;
|
||||
bool ok = true;
|
||||
bool anyTagged = false;
|
||||
for (int i = 0; i < Panel_size(super); i++) {
|
||||
Process* p = (Process*) Panel_get(super, i);
|
||||
if (p->tag) {
|
||||
ok = fn(p, arg) && ok;
|
||||
anyTagged = true;
|
||||
}
|
||||
}
|
||||
if (!anyTagged) {
|
||||
Process* p = (Process*) Panel_getSelected(super);
|
||||
if (p) ok = fn(p, arg) && ok;
|
||||
}
|
||||
if (wasAnyTagged)
|
||||
*wasAnyTagged = anyTagged;
|
||||
return ok;
|
||||
}
|
||||
|
||||
PanelClass MainPanel_class = {
|
||||
.super = {
|
||||
.extends = Class(Panel),
|
||||
.delete = MainPanel_delete
|
||||
},
|
||||
.eventHandler = MainPanel_eventHandler
|
||||
};
|
||||
|
||||
MainPanel* MainPanel_new() {
|
||||
MainPanel* this = AllocThis(MainPanel);
|
||||
Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(MainFunctions, NULL, NULL));
|
||||
this->keys = xCalloc(KEY_MAX, sizeof(Htop_Action));
|
||||
this->inc = IncSet_new(MainPanel_getFunctionBar(this));
|
||||
|
||||
Action_setBindings(this->keys);
|
||||
Platform_setBindings(this->keys);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void MainPanel_setState(MainPanel* this, State* state) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
void MainPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
MainPanel* this = (MainPanel*) object;
|
||||
Panel_done(super);
|
||||
IncSet_delete(this->inc);
|
||||
free(this->keys);
|
||||
free(this);
|
||||
}
|
47
MainPanel.h
Normal file
47
MainPanel.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_MainPanel
|
||||
#define HEADER_MainPanel
|
||||
/*
|
||||
htop - ColumnsPanel.h
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Panel.h"
|
||||
#include "Action.h"
|
||||
#include "Settings.h"
|
||||
|
||||
typedef struct MainPanel_ {
|
||||
Panel super;
|
||||
State* state;
|
||||
IncSet* inc;
|
||||
Htop_Action *keys;
|
||||
pid_t pidSearch;
|
||||
} MainPanel;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
||||
|
||||
void MainPanel_pidSearch(MainPanel* this, int ch);
|
||||
|
||||
int MainPanel_selectedPid(MainPanel* this);
|
||||
|
||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged);
|
||||
|
||||
extern PanelClass MainPanel_class;
|
||||
|
||||
MainPanel* MainPanel_new();
|
||||
|
||||
void MainPanel_setState(MainPanel* this, State* state);
|
||||
|
||||
void MainPanel_delete(Object* object);
|
||||
|
||||
#endif
|
84
Makefile.am
84
Makefile.am
@ -1,7 +1,9 @@
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
|
||||
bin_PROGRAMS = htop
|
||||
|
||||
dist_man_MANS = htop.1
|
||||
EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \
|
||||
install-sh autogen.sh missing
|
||||
@ -10,31 +12,81 @@ applications_DATA = htop.desktop
|
||||
pixmapdir = $(datadir)/pixmaps
|
||||
pixmap_DATA = htop.png
|
||||
|
||||
htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
||||
htop_LDFLAGS =
|
||||
AM_CPPFLAGS = -DNDEBUG
|
||||
|
||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \
|
||||
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c MainPanel.c \
|
||||
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
|
||||
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
|
||||
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
|
||||
IOPriorityPanel.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
|
||||
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
|
||||
HostnameMeter.c OpenFilesScreen.c Affinity.c IOPriority.c IncSet.c
|
||||
SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \
|
||||
TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \
|
||||
HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \
|
||||
InfoScreen.c XAlloc.c
|
||||
|
||||
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
|
||||
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
|
||||
IOPriorityPanel.h CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \
|
||||
CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \
|
||||
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
|
||||
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
|
||||
ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
|
||||
TraceScreen.h UptimeMeter.h UsersTable.h Vector.h Process.h AffinityPanel.h \
|
||||
HostnameMeter.h OpenFilesScreen.h Affinity.h IOPriority.h IncSet.h
|
||||
ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \
|
||||
TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \
|
||||
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
||||
EnvScreen.h InfoScreen.h XAlloc.h
|
||||
|
||||
if HTOP_LINUX
|
||||
htop_CFLAGS += -rdynamic
|
||||
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
||||
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c
|
||||
|
||||
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
|
||||
linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h
|
||||
endif
|
||||
|
||||
if HTOP_FREEBSD
|
||||
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
||||
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
||||
|
||||
myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
|
||||
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
|
||||
endif
|
||||
|
||||
if HTOP_OPENBSD
|
||||
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
||||
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
||||
|
||||
myhtopplatheaders = openbsd/Platform.h openbsd/OpenBSDProcessList.h \
|
||||
openbsd/OpenBSDProcess.h openbsd/OpenBSDCRT.h openbsd/Battery.h
|
||||
endif
|
||||
|
||||
if HTOP_DARWIN
|
||||
htop_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
||||
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
||||
|
||||
myhtopplatheaders = darwin/Platform.h darwin/DarwinProcess.h \
|
||||
darwin/DarwinProcessList.h darwin/DarwinCRT.h darwin/Battery.h
|
||||
endif
|
||||
|
||||
if HTOP_UNSUPPORTED
|
||||
myhtopplatsources = unsupported/Platform.c \
|
||||
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
||||
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
||||
|
||||
myhtopplatheaders = unsupported/Platform.h \
|
||||
unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \
|
||||
unsupported/UnsupportedCRT.h unsupported/Battery.h
|
||||
endif
|
||||
|
||||
SUFFIXES = .h
|
||||
|
||||
BUILT_SOURCES = $(myhtopheaders)
|
||||
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h
|
||||
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
||||
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
||||
|
||||
target:
|
||||
echo $(htop_SOURCES)
|
||||
|
||||
profile:
|
||||
$(MAKE) all CFLAGS="-pg" AM_CPPFLAGS="-pg -O2 -DNDEBUG"
|
||||
@ -42,8 +94,18 @@ profile:
|
||||
debug:
|
||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG"
|
||||
|
||||
coverage:
|
||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov"
|
||||
|
||||
.c.h:
|
||||
@srcdir@/scripts/MakeHeader.py $<
|
||||
|
||||
cppcheck:
|
||||
cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS
|
||||
|
||||
.PHONY: lcov
|
||||
|
||||
lcov:
|
||||
mkdir -p lcov
|
||||
lcov --capture --directory . --output-file coverage.info
|
||||
genhtml coverage.info --output-directory lcov
|
||||
|
@ -8,7 +8,7 @@ in the source distribution for its full text.
|
||||
#include "MemoryMeter.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "ProcessList.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -24,37 +24,33 @@ int MemoryMeter_attributes[] = {
|
||||
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
|
||||
};
|
||||
|
||||
static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
long int usedMem = this->pl->usedMem;
|
||||
long int buffersMem = this->pl->buffersMem;
|
||||
long int cachedMem = this->pl->cachedMem;
|
||||
usedMem -= buffersMem + cachedMem;
|
||||
this->total = this->pl->totalMem;
|
||||
this->values[0] = usedMem;
|
||||
this->values[1] = buffersMem;
|
||||
this->values[2] = cachedMem;
|
||||
snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024);
|
||||
static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int written;
|
||||
Platform_setMemoryValues(this);
|
||||
|
||||
written = Meter_humanUnit(buffer, this->values[0], size);
|
||||
buffer += written;
|
||||
if ((size -= written) > 0) {
|
||||
*buffer++ = '/';
|
||||
size--;
|
||||
Meter_humanUnit(buffer, this->total, size);
|
||||
}
|
||||
}
|
||||
|
||||
static void MemoryMeter_display(Object* cast, RichString* out) {
|
||||
char buffer[50];
|
||||
Meter* this = (Meter*)cast;
|
||||
int k = 1024; const char* format = "%ldM ";
|
||||
long int totalMem = this->total / k;
|
||||
long int usedMem = this->values[0] / k;
|
||||
long int buffersMem = this->values[1] / k;
|
||||
long int cachedMem = this->values[2] / k;
|
||||
RichString_write(out, CRT_colors[METER_TEXT], ":");
|
||||
sprintf(buffer, format, totalMem);
|
||||
Meter_humanUnit(buffer, this->total, 50);
|
||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||
sprintf(buffer, format, usedMem);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "used:");
|
||||
Meter_humanUnit(buffer, this->values[0], 50);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " used:");
|
||||
RichString_append(out, CRT_colors[MEMORY_USED], buffer);
|
||||
sprintf(buffer, format, buffersMem);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "buffers:");
|
||||
Meter_humanUnit(buffer, this->values[1], 50);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " buffers:");
|
||||
RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer);
|
||||
sprintf(buffer, format, cachedMem);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "cache:");
|
||||
Meter_humanUnit(buffer, this->values[2], 50);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " cache:");
|
||||
RichString_append(out, CRT_colors[MEMORY_CACHE], buffer);
|
||||
}
|
||||
|
||||
@ -64,12 +60,12 @@ MeterClass MemoryMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = MemoryMeter_display,
|
||||
},
|
||||
.setValues = MemoryMeter_setValues,
|
||||
.updateValues = MemoryMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 3,
|
||||
.total = 100.0,
|
||||
.attributes = MemoryMeter_attributes,
|
||||
"Memory",
|
||||
"Memory",
|
||||
"Mem"
|
||||
.name = "Memory",
|
||||
.uiName = "Memory",
|
||||
.caption = "Mem"
|
||||
};
|
||||
|
272
Meter.c
272
Meter.c
@ -7,19 +7,10 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Meter.h"
|
||||
|
||||
#include "CPUMeter.h"
|
||||
#include "MemoryMeter.h"
|
||||
#include "SwapMeter.h"
|
||||
#include "TasksMeter.h"
|
||||
#include "LoadAverageMeter.h"
|
||||
#include "UptimeMeter.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "ClockMeter.h"
|
||||
#include "HostnameMeter.h"
|
||||
#include "RichString.h"
|
||||
#include "Object.h"
|
||||
#include "CRT.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "ListItem.h"
|
||||
#include "Settings.h"
|
||||
|
||||
@ -30,18 +21,23 @@ in the source distribution for its full text.
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define METER_BUFFER_LEN 128
|
||||
#define METER_BUFFER_LEN 256
|
||||
|
||||
#define GRAPH_DELAY (DEFAULT_DELAY/2)
|
||||
|
||||
#define GRAPH_HEIGHT 4 /* Unit: rows (lines) */
|
||||
|
||||
/*{
|
||||
#include "ListItem.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
typedef struct Meter_ Meter;
|
||||
|
||||
typedef void(*Meter_Init)(Meter*);
|
||||
typedef void(*Meter_Done)(Meter*);
|
||||
typedef void(*Meter_UpdateMode)(Meter*, int);
|
||||
typedef void(*Meter_SetValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_Draw)(Meter*, int, int, int);
|
||||
|
||||
typedef struct MeterClass_ {
|
||||
@ -50,13 +46,14 @@ typedef struct MeterClass_ {
|
||||
const Meter_Done done;
|
||||
const Meter_UpdateMode updateMode;
|
||||
const Meter_Draw draw;
|
||||
const Meter_SetValues setValues;
|
||||
const Meter_UpdateValues updateValues;
|
||||
const int defaultMode;
|
||||
const double total;
|
||||
const int* attributes;
|
||||
const char* name;
|
||||
const char* uiName;
|
||||
const char* caption;
|
||||
const char* description;
|
||||
const char maxItems;
|
||||
char curItems;
|
||||
} MeterClass;
|
||||
@ -69,7 +66,8 @@ typedef struct MeterClass_ {
|
||||
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
||||
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
||||
#define Meter_doneFn(this_) As_Meter(this_)->done
|
||||
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
|
||||
#define Meter_updateValues(this_, buf_, sz_) \
|
||||
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
|
||||
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
|
||||
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
||||
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
||||
@ -86,7 +84,7 @@ struct Meter_ {
|
||||
int param;
|
||||
void* drawData;
|
||||
int h;
|
||||
ProcessList* pl;
|
||||
struct ProcessList_* pl;
|
||||
double* values;
|
||||
double total;
|
||||
};
|
||||
@ -119,6 +117,9 @@ typedef struct GraphData_ {
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
MeterClass Meter_class = {
|
||||
.super = {
|
||||
@ -126,47 +127,53 @@ MeterClass Meter_class = {
|
||||
}
|
||||
};
|
||||
|
||||
MeterClass* Meter_types[] = {
|
||||
&CPUMeter_class,
|
||||
&ClockMeter_class,
|
||||
&LoadAverageMeter_class,
|
||||
&LoadMeter_class,
|
||||
&MemoryMeter_class,
|
||||
&SwapMeter_class,
|
||||
&TasksMeter_class,
|
||||
&UptimeMeter_class,
|
||||
&BatteryMeter_class,
|
||||
&HostnameMeter_class,
|
||||
&AllCPUsMeter_class,
|
||||
&AllCPUs2Meter_class,
|
||||
&LeftCPUsMeter_class,
|
||||
&RightCPUsMeter_class,
|
||||
&LeftCPUs2Meter_class,
|
||||
&RightCPUs2Meter_class,
|
||||
&BlankMeter_class,
|
||||
NULL
|
||||
};
|
||||
|
||||
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) {
|
||||
Meter* this = calloc(1, sizeof(Meter));
|
||||
Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
|
||||
Meter* this = xCalloc(1, sizeof(Meter));
|
||||
Object_setClass(this, type);
|
||||
this->h = 1;
|
||||
this->param = param;
|
||||
this->pl = pl;
|
||||
char maxItems = type->maxItems;
|
||||
if (maxItems == 0) {
|
||||
maxItems = 1;
|
||||
}
|
||||
type->curItems = maxItems;
|
||||
this->values = calloc(maxItems, sizeof(double));
|
||||
type->curItems = type->maxItems;
|
||||
this->values = xCalloc(type->maxItems, sizeof(double));
|
||||
this->total = type->total;
|
||||
this->caption = strdup(type->caption);
|
||||
this->caption = xStrdup(type->caption);
|
||||
if (Meter_initFn(this))
|
||||
Meter_init(this);
|
||||
Meter_setMode(this, type->defaultMode);
|
||||
return this;
|
||||
}
|
||||
|
||||
int Meter_humanUnit(char* buffer, unsigned long int value, int size) {
|
||||
const char * prefix = "KMGTPEZY";
|
||||
unsigned long int powi = 1;
|
||||
unsigned int written, powj = 1, precision = 2;
|
||||
|
||||
for(;;) {
|
||||
if (value / 1024 < powi)
|
||||
break;
|
||||
|
||||
if (prefix[1] == 0)
|
||||
break;
|
||||
|
||||
powi *= 1024;
|
||||
++prefix;
|
||||
}
|
||||
|
||||
if (*prefix == 'K')
|
||||
precision = 0;
|
||||
|
||||
for (; precision > 0; precision--) {
|
||||
powj *= 10;
|
||||
if (value / powi < powj)
|
||||
break;
|
||||
}
|
||||
|
||||
written = snprintf(buffer, size, "%.*f%c",
|
||||
precision, (double) value / powi, *prefix);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
void Meter_delete(Object* cast) {
|
||||
if (!cast)
|
||||
return;
|
||||
@ -174,8 +181,7 @@ void Meter_delete(Object* cast) {
|
||||
if (Meter_doneFn(this)) {
|
||||
Meter_done(this);
|
||||
}
|
||||
if (this->drawData)
|
||||
free(this->drawData);
|
||||
free(this->drawData);
|
||||
free(this->caption);
|
||||
free(this->values);
|
||||
free(this);
|
||||
@ -183,7 +189,7 @@ void Meter_delete(Object* cast) {
|
||||
|
||||
void Meter_setCaption(Meter* this, const char* caption) {
|
||||
free(this->caption);
|
||||
this->caption = strdup(caption);
|
||||
this->caption = xStrdup(caption);
|
||||
}
|
||||
|
||||
static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) {
|
||||
@ -206,8 +212,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
||||
Meter_updateMode(this, modeIndex);
|
||||
} else {
|
||||
assert(modeIndex >= 1);
|
||||
if (this->drawData)
|
||||
free(this->drawData);
|
||||
free(this->drawData);
|
||||
this->drawData = NULL;
|
||||
|
||||
MeterMode* mode = Meter_modes[modeIndex];
|
||||
@ -217,7 +222,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
||||
this->mode = modeIndex;
|
||||
}
|
||||
|
||||
ListItem* Meter_toListItem(Meter* this) {
|
||||
ListItem* Meter_toListItem(Meter* this, bool moving) {
|
||||
char mode[21];
|
||||
if (this->mode)
|
||||
snprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName);
|
||||
@ -230,21 +235,22 @@ ListItem* Meter_toListItem(Meter* this) {
|
||||
number[0] = '\0';
|
||||
char buffer[51];
|
||||
snprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode);
|
||||
return ListItem_new(buffer, 0);
|
||||
ListItem* li = ListItem_new(buffer, 0);
|
||||
li->moving = moving;
|
||||
return li;
|
||||
}
|
||||
|
||||
/* ---------- TextMeterMode ---------- */
|
||||
|
||||
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
(void) w;
|
||||
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
mvaddstr(y, x, this->caption);
|
||||
int captionLen = strlen(this->caption);
|
||||
x += captionLen;
|
||||
mvhline(y, x, ' ', CRT_colors[DEFAULT_COLOR]);
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
RichString_begin(out);
|
||||
Meter_displayBuffer(this, buffer, &out);
|
||||
@ -254,11 +260,11 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
/* ---------- BarMeterMode ---------- */
|
||||
|
||||
static char BarMeterMode_characters[] = "|#*@$%&";
|
||||
static char BarMeterMode_characters[] = "|#*@$%&.";
|
||||
|
||||
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
|
||||
w -= 2;
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
@ -280,19 +286,15 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
char bar[w + 1];
|
||||
|
||||
int blockSizes[10];
|
||||
for (int i = 0; i < w; i++)
|
||||
bar[i] = ' ';
|
||||
|
||||
const size_t barOffset = w - MIN((int)strlen(buffer), w);
|
||||
snprintf(bar + barOffset, w - barOffset + 1, "%s", buffer);
|
||||
snprintf(bar, w + 1, "%*s", w, buffer);
|
||||
|
||||
// First draw in the bar[] buffer...
|
||||
int offset = 0;
|
||||
int items = Meter_getItems(this);
|
||||
for (int i = 0; i < items; i++) {
|
||||
double value = this->values[i];
|
||||
value = MAX(value, 0);
|
||||
value = MIN(value, this->total);
|
||||
value = CLAMP(value, 0.0, this->total);
|
||||
if (value > 0) {
|
||||
blockSizes[i] = ceil((value/this->total) * w);
|
||||
} else {
|
||||
@ -300,7 +302,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
}
|
||||
int nextOffset = offset + blockSizes[i];
|
||||
// (Control against invalid values)
|
||||
nextOffset = MIN(MAX(nextOffset, 0), w);
|
||||
nextOffset = CLAMP(nextOffset, 0, w);
|
||||
for (int j = offset; j < nextOffset; j++)
|
||||
if (bar[j] == ' ') {
|
||||
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
|
||||
@ -318,8 +320,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
attrset(CRT_colors[Meter_attributes(this)[i]]);
|
||||
mvaddnstr(y, x + offset, bar + offset, blockSizes[i]);
|
||||
offset += blockSizes[i];
|
||||
offset = MAX(offset, 0);
|
||||
offset = MIN(offset, w);
|
||||
offset = CLAMP(offset, 0, w);
|
||||
}
|
||||
if (offset < w) {
|
||||
attrset(CRT_colors[BAR_SHADOW]);
|
||||
@ -332,37 +333,63 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
/* ---------- GraphMeterMode ---------- */
|
||||
|
||||
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0)
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
static int GraphMeterMode_colors[21] = {
|
||||
GRAPH_1, GRAPH_1, GRAPH_1,
|
||||
GRAPH_2, GRAPH_2, GRAPH_2,
|
||||
GRAPH_3, GRAPH_3, GRAPH_3,
|
||||
GRAPH_4, GRAPH_4, GRAPH_4,
|
||||
GRAPH_5, GRAPH_5, GRAPH_6,
|
||||
GRAPH_7, GRAPH_7, GRAPH_7,
|
||||
GRAPH_8, GRAPH_8, GRAPH_9
|
||||
#define PIXPERROW_UTF8 4
|
||||
static const char* GraphMeterMode_dotsUtf8[] = {
|
||||
/*00*/" ", /*01*/"⢀", /*02*/"⢠", /*03*/"⢰", /*04*/ "⢸",
|
||||
/*10*/"⡀", /*11*/"⣀", /*12*/"⣠", /*13*/"⣰", /*14*/ "⣸",
|
||||
/*20*/"⡄", /*21*/"⣄", /*22*/"⣤", /*23*/"⣴", /*24*/ "⣼",
|
||||
/*30*/"⡆", /*31*/"⣆", /*32*/"⣦", /*33*/"⣶", /*34*/ "⣾",
|
||||
/*40*/"⡇", /*41*/"⣇", /*42*/"⣧", /*43*/"⣷", /*44*/ "⣿"
|
||||
};
|
||||
|
||||
static const char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_";
|
||||
#endif
|
||||
|
||||
#define PIXPERROW_ASCII 2
|
||||
static const char* GraphMeterMode_dotsAscii[] = {
|
||||
/*00*/" ", /*01*/".", /*02*/":",
|
||||
/*10*/".", /*11*/".", /*12*/":",
|
||||
/*20*/":", /*21*/":", /*22*/":"
|
||||
};
|
||||
|
||||
static const char** GraphMeterMode_dots;
|
||||
static int GraphMeterMode_pixPerRow;
|
||||
|
||||
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
if (!this->drawData) this->drawData = calloc(1, sizeof(GraphData));
|
||||
GraphData* data = (GraphData*) this->drawData;
|
||||
if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData));
|
||||
GraphData* data = (GraphData*) this->drawData;
|
||||
const int nValues = METER_BUFFER_LEN;
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
if (CRT_utf8) {
|
||||
GraphMeterMode_dots = GraphMeterMode_dotsUtf8;
|
||||
GraphMeterMode_pixPerRow = PIXPERROW_UTF8;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
GraphMeterMode_dots = GraphMeterMode_dotsAscii;
|
||||
GraphMeterMode_pixPerRow = PIXPERROW_ASCII;
|
||||
}
|
||||
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
int captionLen = 3;
|
||||
mvaddnstr(y, x, this->caption, captionLen);
|
||||
x += captionLen;
|
||||
w -= captionLen;
|
||||
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
if (!timercmp(&now, &(data->time), <)) {
|
||||
struct timeval delay = { .tv_sec = (int)(DEFAULT_DELAY/10), .tv_usec = (DEFAULT_DELAY-((int)(DEFAULT_DELAY/10)*10)) * 100000 };
|
||||
struct timeval delay = { .tv_sec = (int)(CRT_delay/10), .tv_usec = (CRT_delay-((int)(CRT_delay/10)*10)) * 100000 };
|
||||
timeradd(&now, &delay, &(data->time));
|
||||
|
||||
for (int i = 0; i < nValues - 1; i++)
|
||||
data->values[i] = data->values[i+1];
|
||||
|
||||
char buffer[nValues];
|
||||
Meter_setValues(this, buffer, nValues - 1);
|
||||
Meter_updateValues(this, buffer, nValues - 1);
|
||||
|
||||
double value = 0.0;
|
||||
int items = Meter_getItems(this);
|
||||
@ -372,55 +399,75 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
data->values[nValues - 1] = value;
|
||||
}
|
||||
|
||||
for (int i = nValues - w, k = 0; i < nValues; i++, k++) {
|
||||
double value = data->values[i];
|
||||
DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' );
|
||||
DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' );
|
||||
DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' );
|
||||
|
||||
double threshold = 1.00;
|
||||
for (int j = 0; j < 21; j++, threshold -= 0.05)
|
||||
if (value >= threshold) {
|
||||
DrawDot(CRT_colors[GraphMeterMode_colors[j]], y+(j/7.0), GraphMeterMode_characters[j]);
|
||||
break;
|
||||
}
|
||||
int i = nValues - (w*2) + 2, k = 0;
|
||||
if (i < 0) {
|
||||
k = -i/2;
|
||||
i = 0;
|
||||
}
|
||||
for (; i < nValues; i+=2, k++) {
|
||||
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
|
||||
int v1 = CLAMP(data->values[i] * pix, 1, pix);
|
||||
int v2 = CLAMP(data->values[i+1] * pix, 1, pix);
|
||||
|
||||
int colorIdx = GRAPH_1;
|
||||
for (int line = 0; line < GRAPH_HEIGHT; line++) {
|
||||
int line1 = CLAMP(v1 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line)), 0, GraphMeterMode_pixPerRow);
|
||||
int line2 = CLAMP(v2 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line)), 0, GraphMeterMode_pixPerRow);
|
||||
|
||||
attrset(CRT_colors[colorIdx]);
|
||||
mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (GraphMeterMode_pixPerRow + 1) + line2]);
|
||||
colorIdx = GRAPH_2;
|
||||
}
|
||||
}
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
}
|
||||
|
||||
/* ---------- LEDMeterMode ---------- */
|
||||
|
||||
static const char* LEDMeterMode_digitsAscii[3][10] = {
|
||||
{ " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ "},
|
||||
{ "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|"},
|
||||
{ "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"},
|
||||
static const char* LEDMeterMode_digitsAscii[] = {
|
||||
" __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ",
|
||||
"| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|",
|
||||
"|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"
|
||||
};
|
||||
|
||||
static const char* LEDMeterMode_digitsUtf8[3][10] = {
|
||||
{ "┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐"},
|
||||
{ "│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤"},
|
||||
{ "└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"},
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
static const char* LEDMeterMode_digitsUtf8[] = {
|
||||
"┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐",
|
||||
"│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤",
|
||||
"└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static const char** LEDMeterMode_digits;
|
||||
|
||||
static void LEDMeterMode_drawDigit(int x, int y, int n) {
|
||||
if (CRT_utf8) {
|
||||
for (int i = 0; i < 3; i++)
|
||||
mvaddstr(y+i, x, LEDMeterMode_digitsUtf8[i][n]);
|
||||
} else {
|
||||
for (int i = 0; i < 3; i++)
|
||||
mvaddstr(y+i, x, LEDMeterMode_digitsAscii[i][n]);
|
||||
}
|
||||
for (int i = 0; i < 3; i++)
|
||||
mvaddstr(y+i, x, LEDMeterMode_digits[i * 10 + n]);
|
||||
}
|
||||
|
||||
static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
(void) w;
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
if (CRT_utf8)
|
||||
LEDMeterMode_digits = LEDMeterMode_digitsUtf8;
|
||||
else
|
||||
#endif
|
||||
LEDMeterMode_digits = LEDMeterMode_digitsAscii;
|
||||
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
Meter_updateValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
|
||||
RichString_begin(out);
|
||||
Meter_displayBuffer(this, buffer, &out);
|
||||
|
||||
int yText = CRT_utf8 ? y+1 : y+2;
|
||||
int yText =
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
CRT_utf8 ? y+1 :
|
||||
#endif
|
||||
y+2;
|
||||
attrset(CRT_colors[LED_COLOR]);
|
||||
mvaddstr(yText, x, this->caption);
|
||||
int xx = x + strlen(this->caption);
|
||||
@ -453,7 +500,7 @@ static MeterMode TextMeterMode = {
|
||||
|
||||
static MeterMode GraphMeterMode = {
|
||||
.uiName = "Graph",
|
||||
.h = 3,
|
||||
.h = GRAPH_HEIGHT,
|
||||
.draw = GraphMeterMode_draw,
|
||||
};
|
||||
|
||||
@ -474,7 +521,7 @@ MeterMode* Meter_modes[] = {
|
||||
|
||||
/* Blank meter */
|
||||
|
||||
static void BlankMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
(void) this; (void) buffer; (void) size;
|
||||
}
|
||||
|
||||
@ -493,8 +540,9 @@ MeterClass BlankMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = BlankMeter_display,
|
||||
},
|
||||
.setValues = BlankMeter_setValues,
|
||||
.updateValues = BlankMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 0,
|
||||
.total = 100.0,
|
||||
.attributes = BlankMeter_attributes,
|
||||
.name = "Blank",
|
||||
|
39
Meter.h
39
Meter.h
@ -9,17 +9,22 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#define METER_BUFFER_LEN 128
|
||||
#define METER_BUFFER_LEN 256
|
||||
|
||||
#define GRAPH_DELAY (DEFAULT_DELAY/2)
|
||||
|
||||
#define GRAPH_HEIGHT 4 /* Unit: rows (lines) */
|
||||
|
||||
#include "ListItem.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
typedef struct Meter_ Meter;
|
||||
|
||||
typedef void(*Meter_Init)(Meter*);
|
||||
typedef void(*Meter_Done)(Meter*);
|
||||
typedef void(*Meter_UpdateMode)(Meter*, int);
|
||||
typedef void(*Meter_SetValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
|
||||
typedef void(*Meter_Draw)(Meter*, int, int, int);
|
||||
|
||||
typedef struct MeterClass_ {
|
||||
@ -28,13 +33,14 @@ typedef struct MeterClass_ {
|
||||
const Meter_Done done;
|
||||
const Meter_UpdateMode updateMode;
|
||||
const Meter_Draw draw;
|
||||
const Meter_SetValues setValues;
|
||||
const Meter_UpdateValues updateValues;
|
||||
const int defaultMode;
|
||||
const double total;
|
||||
const int* attributes;
|
||||
const char* name;
|
||||
const char* uiName;
|
||||
const char* caption;
|
||||
const char* description;
|
||||
const char maxItems;
|
||||
char curItems;
|
||||
} MeterClass;
|
||||
@ -47,7 +53,8 @@ typedef struct MeterClass_ {
|
||||
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
|
||||
#define Meter_drawFn(this_) As_Meter(this_)->draw
|
||||
#define Meter_doneFn(this_) As_Meter(this_)->done
|
||||
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
|
||||
#define Meter_updateValues(this_, buf_, sz_) \
|
||||
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
|
||||
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
|
||||
#define Meter_getItems(this_) As_Meter(this_)->curItems
|
||||
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
|
||||
@ -64,7 +71,7 @@ struct Meter_ {
|
||||
int param;
|
||||
void* drawData;
|
||||
int h;
|
||||
ProcessList* pl;
|
||||
struct ProcessList_* pl;
|
||||
double* values;
|
||||
double total;
|
||||
};
|
||||
@ -96,12 +103,15 @@ typedef struct GraphData_ {
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern MeterClass Meter_class;
|
||||
|
||||
extern MeterClass* Meter_types[];
|
||||
Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
|
||||
|
||||
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type);
|
||||
int Meter_humanUnit(char* buffer, unsigned long int value, int size);
|
||||
|
||||
void Meter_delete(Object* cast);
|
||||
|
||||
@ -109,7 +119,7 @@ void Meter_setCaption(Meter* this, const char* caption);
|
||||
|
||||
void Meter_setMode(Meter* this, int modeIndex);
|
||||
|
||||
ListItem* Meter_toListItem(Meter* this);
|
||||
ListItem* Meter_toListItem(Meter* this, bool moving);
|
||||
|
||||
/* ---------- TextMeterMode ---------- */
|
||||
|
||||
@ -117,10 +127,19 @@ ListItem* Meter_toListItem(Meter* this);
|
||||
|
||||
/* ---------- GraphMeterMode ---------- */
|
||||
|
||||
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0)
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
#define PIXPERROW_UTF8 4
|
||||
#endif
|
||||
|
||||
#define PIXPERROW_ASCII 2
|
||||
|
||||
/* ---------- LEDMeterMode ---------- */
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
#endif
|
||||
|
||||
extern MeterMode* Meter_modes[];
|
||||
|
||||
/* Blank meter */
|
||||
|
121
MetersPanel.c
121
MetersPanel.c
@ -9,22 +9,37 @@ in the source distribution for its full text.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "CRT.h"
|
||||
|
||||
/*{
|
||||
#include "Panel.h"
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
typedef struct MetersPanel_ {
|
||||
typedef struct MetersPanel_ MetersPanel;
|
||||
|
||||
struct MetersPanel_ {
|
||||
Panel super;
|
||||
|
||||
Settings* settings;
|
||||
Vector* meters;
|
||||
ScreenManager* scr;
|
||||
} MetersPanel;
|
||||
MetersPanel* leftNeighbor;
|
||||
MetersPanel* rightNeighbor;
|
||||
bool moving;
|
||||
};
|
||||
|
||||
}*/
|
||||
|
||||
static const char* MetersFunctions[] = {"Type ", "Move ", "Delete", "Done ", NULL};
|
||||
static const char* MetersKeys[] = {"Space", "Enter", "Del", "Esc"};
|
||||
static int MetersEvents[] = {' ', 13, KEY_DC, 27};
|
||||
|
||||
static const char* MetersMovingFunctions[] = {"Up ", "Down ", "Left ", "Right ", "Confirm", "Delete", "Done ", NULL};
|
||||
static const char* MetersMovingKeys[] = {"Up", "Dn", "Lt", "Rt", "Enter", "Del", "Esc"};
|
||||
static int MetersMovingEvents[] = {KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, 13, KEY_DC, 27};
|
||||
static FunctionBar* Meters_movingBar = NULL;
|
||||
|
||||
static void MetersPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
MetersPanel* this = (MetersPanel*) object;
|
||||
@ -32,27 +47,83 @@ static void MetersPanel_delete(Object* object) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
||||
Panel* super = (Panel*) this;
|
||||
this->moving = moving;
|
||||
ListItem* selected = (ListItem*)Panel_getSelected(super);
|
||||
if (selected) {
|
||||
selected->moving = moving;
|
||||
}
|
||||
if (!moving) {
|
||||
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]);
|
||||
Panel_setDefaultBar(super);
|
||||
} else {
|
||||
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]);
|
||||
super->currentBar = Meters_movingBar;
|
||||
}
|
||||
FunctionBar_draw(this->super.currentBar, NULL);
|
||||
}
|
||||
|
||||
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
|
||||
Panel* super = (Panel*) this;
|
||||
if (this->moving) {
|
||||
if (neighbor) {
|
||||
if (selected < Vector_size(this->meters)) {
|
||||
MetersPanel_setMoving(this, false);
|
||||
|
||||
Meter* meter = (Meter*) Vector_take(this->meters, selected);
|
||||
Panel_remove(super, selected);
|
||||
Vector_insert(neighbor->meters, selected, meter);
|
||||
Panel_insert(&(neighbor->super), selected, (Object*) Meter_toListItem(meter, false));
|
||||
Panel_setSelected(&(neighbor->super), selected);
|
||||
|
||||
MetersPanel_setMoving(neighbor, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
MetersPanel* this = (MetersPanel*) super;
|
||||
|
||||
int selected = Panel_getSelectedIndex(super);
|
||||
HandlerResult result = IGNORED;
|
||||
bool sideMove = false;
|
||||
|
||||
switch(ch) {
|
||||
case 0x0a:
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
{
|
||||
if (!Vector_size(this->meters))
|
||||
break;
|
||||
MetersPanel_setMoving(this, !(this->moving));
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
case ' ':
|
||||
case KEY_F(4):
|
||||
case 't':
|
||||
{
|
||||
if (!Vector_size(this->meters))
|
||||
break;
|
||||
Meter* meter = (Meter*) Vector_get(this->meters, selected);
|
||||
int mode = meter->mode + 1;
|
||||
if (mode == LAST_METERMODE) mode = 1;
|
||||
Meter_setMode(meter, mode);
|
||||
Panel_set(super, selected, (Object*) Meter_toListItem(meter));
|
||||
Panel_set(super, selected, (Object*) Meter_toListItem(meter, this->moving));
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
case KEY_UP:
|
||||
{
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
case KEY_F(7):
|
||||
case '[':
|
||||
case '-':
|
||||
@ -62,6 +133,13 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
case KEY_DOWN:
|
||||
{
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
case KEY_F(8):
|
||||
case ']':
|
||||
case '+':
|
||||
@ -71,19 +149,41 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
case KEY_RIGHT:
|
||||
{
|
||||
sideMove = moveToNeighbor(this, this->rightNeighbor, selected);
|
||||
if (this->moving && !sideMove) {
|
||||
// lock user here until it exits positioning-mode
|
||||
result = HANDLED;
|
||||
}
|
||||
// if user is free, don't set HANDLED;
|
||||
// let ScreenManager handle focus.
|
||||
break;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
{
|
||||
sideMove = moveToNeighbor(this, this->leftNeighbor, selected);
|
||||
if (this->moving && !sideMove) {
|
||||
result = HANDLED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KEY_F(9):
|
||||
case KEY_DC:
|
||||
{
|
||||
if (!Vector_size(this->meters))
|
||||
break;
|
||||
if (selected < Vector_size(this->meters)) {
|
||||
Vector_remove(this->meters, selected);
|
||||
Panel_remove(super, selected);
|
||||
}
|
||||
MetersPanel_setMoving(this, false);
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == HANDLED) {
|
||||
Header* header = this->settings->header;
|
||||
if (result == HANDLED || sideMove) {
|
||||
Header* header = (Header*) this->scr->header;
|
||||
this->settings->changed = true;
|
||||
Header_calculateHeight(header);
|
||||
Header_draw(header);
|
||||
@ -103,15 +203,22 @@ PanelClass MetersPanel_class = {
|
||||
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) {
|
||||
MetersPanel* this = AllocThis(MetersPanel);
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
|
||||
FunctionBar* fuBar = FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents);
|
||||
if (!Meters_movingBar) {
|
||||
Meters_movingBar = FunctionBar_new(MetersMovingFunctions, MetersMovingKeys, MetersMovingEvents);
|
||||
}
|
||||
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
||||
|
||||
this->settings = settings;
|
||||
this->meters = meters;
|
||||
this->scr = scr;
|
||||
this->moving = false;
|
||||
this->rightNeighbor = NULL;
|
||||
this->leftNeighbor = NULL;
|
||||
Panel_setHeader(super, header);
|
||||
for (int i = 0; i < Vector_size(meters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
Panel_add(super, (Object*) Meter_toListItem(meter));
|
||||
Panel_add(super, (Object*) Meter_toListItem(meter, false));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -13,15 +13,23 @@ in the source distribution for its full text.
|
||||
#include "Settings.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
typedef struct MetersPanel_ {
|
||||
typedef struct MetersPanel_ MetersPanel;
|
||||
|
||||
struct MetersPanel_ {
|
||||
Panel super;
|
||||
|
||||
Settings* settings;
|
||||
Vector* meters;
|
||||
ScreenManager* scr;
|
||||
} MetersPanel;
|
||||
MetersPanel* leftNeighbor;
|
||||
MetersPanel* rightNeighbor;
|
||||
bool moving;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void MetersPanel_setMoving(MetersPanel* this, bool moving);
|
||||
|
||||
extern PanelClass MetersPanel_class;
|
||||
|
||||
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);
|
||||
|
5
Object.c
5
Object.c
@ -9,11 +9,12 @@ in the source distribution for its full text.
|
||||
|
||||
/*{
|
||||
#include "RichString.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
typedef struct Object_ Object;
|
||||
|
||||
typedef void(*Object_Display)(Object*, RichString*);
|
||||
typedef int(*Object_Compare)(const void*, const void*);
|
||||
typedef long(*Object_Compare)(const void*, const void*);
|
||||
typedef void(*Object_Delete)(Object*);
|
||||
|
||||
#define Object_getClass(obj_) ((Object*)(obj_))->klass
|
||||
@ -26,7 +27,7 @@ typedef void(*Object_Delete)(Object*);
|
||||
|
||||
#define Class(class_) ((ObjectClass*)(&(class_ ## _class)))
|
||||
|
||||
#define AllocThis(class_) (class_*) malloc(sizeof(class_)); Object_setClass(this, Class(class_));
|
||||
#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_));
|
||||
|
||||
typedef struct ObjectClass_ {
|
||||
const void* extends;
|
||||
|
5
Object.h
5
Object.h
@ -10,11 +10,12 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "RichString.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
typedef struct Object_ Object;
|
||||
|
||||
typedef void(*Object_Display)(Object*, RichString*);
|
||||
typedef int(*Object_Compare)(const void*, const void*);
|
||||
typedef long(*Object_Compare)(const void*, const void*);
|
||||
typedef void(*Object_Delete)(Object*);
|
||||
|
||||
#define Object_getClass(obj_) ((Object*)(obj_))->klass
|
||||
@ -27,7 +28,7 @@ typedef void(*Object_Delete)(Object*);
|
||||
|
||||
#define Class(class_) ((ObjectClass*)(&(class_ ## _class)))
|
||||
|
||||
#define AllocThis(class_) (class_*) malloc(sizeof(class_)); Object_setClass(this, Class(class_));
|
||||
#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_));
|
||||
|
||||
typedef struct ObjectClass_ {
|
||||
const void* extends;
|
||||
|
@ -9,9 +9,9 @@ in the source distribution for its full text.
|
||||
|
||||
#include "CRT.h"
|
||||
#include "ProcessList.h"
|
||||
#include "ListItem.h"
|
||||
#include "IncSet.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "FunctionBar.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -24,9 +24,7 @@ in the source distribution for its full text.
|
||||
#include <sys/wait.h>
|
||||
|
||||
/*{
|
||||
#include "Process.h"
|
||||
#include "Panel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "InfoScreen.h"
|
||||
|
||||
typedef struct OpenFiles_Data_ {
|
||||
char* data[256];
|
||||
@ -44,69 +42,58 @@ typedef struct OpenFiles_FileData_ {
|
||||
} OpenFiles_FileData;
|
||||
|
||||
typedef struct OpenFilesScreen_ {
|
||||
Process* process;
|
||||
InfoScreen super;
|
||||
pid_t pid;
|
||||
Panel* display;
|
||||
FunctionBar* bar;
|
||||
} OpenFilesScreen;
|
||||
|
||||
}*/
|
||||
|
||||
static const char* ofsFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
|
||||
|
||||
static const char* ofsKeys[] = {"F3", "F4", "F5", "Esc"};
|
||||
|
||||
static int ofsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};
|
||||
InfoScreenClass OpenFilesScreen_class = {
|
||||
.super = {
|
||||
.extends = Class(Object),
|
||||
.delete = OpenFilesScreen_delete
|
||||
},
|
||||
.scan = OpenFilesScreen_scan,
|
||||
.draw = OpenFilesScreen_draw
|
||||
};
|
||||
|
||||
OpenFilesScreen* OpenFilesScreen_new(Process* process) {
|
||||
OpenFilesScreen* this = (OpenFilesScreen*) malloc(sizeof(OpenFilesScreen));
|
||||
this->process = process;
|
||||
this->display = Panel_new(0, 1, COLS, LINES-3, false, Class(ListItem));
|
||||
OpenFilesScreen* this = xMalloc(sizeof(OpenFilesScreen));
|
||||
Object_setClass(this, Class(OpenFilesScreen));
|
||||
if (Process_isThread(process))
|
||||
this->pid = process->tgid;
|
||||
else
|
||||
this->pid = process->pid;
|
||||
return this;
|
||||
return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " FD TYPE DEVICE SIZE NODE NAME");
|
||||
}
|
||||
|
||||
void OpenFilesScreen_delete(OpenFilesScreen* this) {
|
||||
Panel_delete((Object*)this->display);
|
||||
free(this);
|
||||
void OpenFilesScreen_delete(Object* this) {
|
||||
free(InfoScreen_done((InfoScreen*)this));
|
||||
}
|
||||
|
||||
static void OpenFilesScreen_draw(OpenFilesScreen* this, IncSet* inc) {
|
||||
attrset(CRT_colors[METER_TEXT]);
|
||||
mvhline(0, 0, ' ', COLS);
|
||||
mvprintw(0, 0, "Snapshot of files open in process %d - %s", this->pid, this->process->comm);
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
Panel_draw(this->display, true);
|
||||
IncSet_drawBar(inc);
|
||||
void OpenFilesScreen_draw(InfoScreen* this) {
|
||||
InfoScreen_drawTitled(this, "Snapshot of files open in process %d - %s", ((OpenFilesScreen*)this)->pid, this->process->comm);
|
||||
}
|
||||
|
||||
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
char command[1025];
|
||||
snprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
||||
FILE* fd = popen(command, "r");
|
||||
OpenFiles_ProcessData* pdata = calloc(1, sizeof(OpenFiles_ProcessData));
|
||||
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
||||
OpenFiles_FileData* fdata = NULL;
|
||||
OpenFiles_Data* item = &(pdata->data);
|
||||
if (!fd) {
|
||||
pdata->error = 127;
|
||||
return pdata;
|
||||
}
|
||||
while (!feof(fd)) {
|
||||
int cmd = fgetc(fd);
|
||||
if (cmd == EOF)
|
||||
break;
|
||||
char* entry = malloc(1024);
|
||||
if (!fgets(entry, 1024, fd)) {
|
||||
free(entry);
|
||||
for (;;) {
|
||||
char* line = String_readLine(fd);
|
||||
if (!line) {
|
||||
break;
|
||||
}
|
||||
char* newline = strrchr(entry, '\n');
|
||||
*newline = '\0';
|
||||
unsigned char cmd = line[0];
|
||||
if (cmd == 'f') {
|
||||
OpenFiles_FileData* nextFile = calloc(1, sizeof(OpenFiles_FileData));
|
||||
OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData));
|
||||
if (fdata == NULL) {
|
||||
pdata->files = nextFile;
|
||||
} else {
|
||||
@ -116,46 +103,43 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
item = &(fdata->data);
|
||||
}
|
||||
assert(cmd >= 0 && cmd <= 0xff);
|
||||
item->data[cmd] = entry;
|
||||
item->data[cmd] = xStrdup(line + 1);
|
||||
free(line);
|
||||
}
|
||||
pdata->error = pclose(fd);
|
||||
return pdata;
|
||||
}
|
||||
|
||||
static inline void addLine(const char* line, Vector* lines, Panel* panel, const char* incFilter) {
|
||||
Vector_add(lines, (Object*) ListItem_new(line, 0));
|
||||
if (!incFilter || String_contains_i(line, incFilter))
|
||||
Panel_add(panel, (Object*)Vector_get(lines, Vector_size(lines)-1));
|
||||
}
|
||||
|
||||
static inline void OpenFiles_Data_clear(OpenFiles_Data* data) {
|
||||
for (int i = 0; i < 255; i++)
|
||||
if (data->data[i])
|
||||
free(data->data[i]);
|
||||
}
|
||||
|
||||
static void OpenFilesScreen_scan(OpenFilesScreen* this, Vector* lines, IncSet* inc) {
|
||||
void OpenFilesScreen_scan(InfoScreen* this) {
|
||||
Panel* panel = this->display;
|
||||
int idx = Panel_getSelectedIndex(panel);
|
||||
Panel_prune(panel);
|
||||
OpenFiles_ProcessData* pdata = OpenFilesScreen_getProcessData(this->pid);
|
||||
OpenFiles_ProcessData* pdata = OpenFilesScreen_getProcessData(((OpenFilesScreen*)this)->pid);
|
||||
if (pdata->error == 127) {
|
||||
addLine("Could not execute 'lsof'. Please make sure it is available in your $PATH.", lines, panel, IncSet_filter(inc));
|
||||
InfoScreen_addLine(this, "Could not execute 'lsof'. Please make sure it is available in your $PATH.");
|
||||
} else if (pdata->error == 1) {
|
||||
addLine("Failed listing open files.", lines, panel, IncSet_filter(inc));
|
||||
InfoScreen_addLine(this, "Failed listing open files.");
|
||||
} else {
|
||||
OpenFiles_FileData* fdata = pdata->files;
|
||||
while (fdata) {
|
||||
char entry[1024];
|
||||
char** data = fdata->data.data;
|
||||
sprintf(entry, "%5s %4s %10s %10s %10s %s",
|
||||
int lenN = data['n'] ? strlen(data['n']) : 0;
|
||||
int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/;
|
||||
char* entry = xMalloc(sizeEntry);
|
||||
snprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
|
||||
data['f'] ? data['f'] : "",
|
||||
data['t'] ? data['t'] : "",
|
||||
data['D'] ? data['D'] : "",
|
||||
data['s'] ? data['s'] : "",
|
||||
data['i'] ? data['i'] : "",
|
||||
data['n'] ? data['n'] : "");
|
||||
addLine(entry, lines, panel, IncSet_filter(inc));
|
||||
InfoScreen_addLine(this, entry);
|
||||
OpenFiles_Data_clear(&fdata->data);
|
||||
OpenFiles_FileData* old = fdata;
|
||||
fdata = fdata->next;
|
||||
@ -164,83 +148,7 @@ static void OpenFilesScreen_scan(OpenFilesScreen* this, Vector* lines, IncSet* i
|
||||
OpenFiles_Data_clear(&pdata->data);
|
||||
}
|
||||
free(pdata);
|
||||
Vector_insertionSort(lines);
|
||||
Vector_insertionSort(this->lines);
|
||||
Vector_insertionSort(panel->items);
|
||||
Panel_setSelected(panel, idx);
|
||||
}
|
||||
|
||||
void OpenFilesScreen_run(OpenFilesScreen* this) {
|
||||
Panel* panel = this->display;
|
||||
Panel_setHeader(panel, " FD TYPE DEVICE SIZE NODE NAME");
|
||||
|
||||
FunctionBar* bar = FunctionBar_new(ofsFunctions, ofsKeys, ofsEvents);
|
||||
IncSet* inc = IncSet_new(bar);
|
||||
|
||||
Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE);
|
||||
|
||||
OpenFilesScreen_scan(this, lines, inc);
|
||||
OpenFilesScreen_draw(this, inc);
|
||||
|
||||
bool looping = true;
|
||||
while (looping) {
|
||||
|
||||
Panel_draw(panel, true);
|
||||
|
||||
if (inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
int ch = getch();
|
||||
|
||||
if (ch == KEY_MOUSE) {
|
||||
MEVENT mevent;
|
||||
int ok = getmouse(&mevent);
|
||||
if (ok == OK)
|
||||
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
||||
ch = 0;
|
||||
} if (mevent.y == LINES - 1)
|
||||
ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
|
||||
}
|
||||
|
||||
if (inc->active) {
|
||||
IncSet_handleKey(inc, ch, panel, IncSet_getListItemValue, lines);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(ch) {
|
||||
case ERR:
|
||||
continue;
|
||||
case KEY_F(3):
|
||||
case '/':
|
||||
IncSet_activate(inc, INC_SEARCH);
|
||||
break;
|
||||
case KEY_F(4):
|
||||
case '\\':
|
||||
IncSet_activate(inc, INC_FILTER);
|
||||
break;
|
||||
case KEY_F(5):
|
||||
clear();
|
||||
OpenFilesScreen_scan(this, lines, inc);
|
||||
OpenFilesScreen_draw(this, inc);
|
||||
break;
|
||||
case '\014': // Ctrl+L
|
||||
clear();
|
||||
OpenFilesScreen_draw(this, inc);
|
||||
break;
|
||||
case 'q':
|
||||
case 27:
|
||||
case KEY_F(10):
|
||||
looping = false;
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
Panel_resize(panel, COLS, LINES-2);
|
||||
OpenFilesScreen_draw(this, inc);
|
||||
break;
|
||||
default:
|
||||
Panel_onKey(panel, ch);
|
||||
}
|
||||
}
|
||||
|
||||
Vector_delete(lines);
|
||||
FunctionBar_delete((Object*)bar);
|
||||
IncSet_delete(inc);
|
||||
}
|
||||
|
@ -9,9 +9,7 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include "Panel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "InfoScreen.h"
|
||||
|
||||
typedef struct OpenFiles_Data_ {
|
||||
char* data[256];
|
||||
@ -29,17 +27,19 @@ typedef struct OpenFiles_FileData_ {
|
||||
} OpenFiles_FileData;
|
||||
|
||||
typedef struct OpenFilesScreen_ {
|
||||
Process* process;
|
||||
InfoScreen super;
|
||||
pid_t pid;
|
||||
Panel* display;
|
||||
FunctionBar* bar;
|
||||
} OpenFilesScreen;
|
||||
|
||||
|
||||
extern InfoScreenClass OpenFilesScreen_class;
|
||||
|
||||
OpenFilesScreen* OpenFilesScreen_new(Process* process);
|
||||
|
||||
void OpenFilesScreen_delete(OpenFilesScreen* this);
|
||||
void OpenFilesScreen_delete(Object* this);
|
||||
|
||||
void OpenFilesScreen_run(OpenFilesScreen* this);
|
||||
void OpenFilesScreen_draw(InfoScreen* this);
|
||||
|
||||
void OpenFilesScreen_scan(InfoScreen* this);
|
||||
|
||||
#endif
|
||||
|
279
Panel.c
279
Panel.c
@ -10,7 +10,7 @@ in the source distribution for its full text.
|
||||
#include "CRT.h"
|
||||
#include "RichString.h"
|
||||
#include "ListItem.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
@ -24,16 +24,24 @@ in the source distribution for its full text.
|
||||
/*{
|
||||
#include "Object.h"
|
||||
#include "Vector.h"
|
||||
#include "FunctionBar.h"
|
||||
|
||||
typedef struct Panel_ Panel;
|
||||
|
||||
typedef enum HandlerResult_ {
|
||||
HANDLED,
|
||||
IGNORED,
|
||||
BREAK_LOOP
|
||||
HANDLED = 0x01,
|
||||
IGNORED = 0x02,
|
||||
BREAK_LOOP = 0x04,
|
||||
REDRAW = 0x08,
|
||||
RESCAN = 0x10,
|
||||
SYNTH_KEY = 0x20,
|
||||
} HandlerResult;
|
||||
|
||||
#define EVENT_SETSELECTED -1
|
||||
#define EVENT_SET_SELECTED -1
|
||||
|
||||
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
||||
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000)
|
||||
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
||||
|
||||
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
||||
|
||||
@ -48,19 +56,24 @@ typedef struct PanelClass_ {
|
||||
|
||||
struct Panel_ {
|
||||
Object super;
|
||||
PanelClass* class;
|
||||
int x, y, w, h;
|
||||
WINDOW* window;
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
char* eventHandlerBuffer;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
bool needsRedraw;
|
||||
FunctionBar* currentBar;
|
||||
FunctionBar* defaultBar;
|
||||
RichString header;
|
||||
int selectionColor;
|
||||
};
|
||||
|
||||
#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0)
|
||||
|
||||
}*/
|
||||
|
||||
#ifndef MIN
|
||||
@ -70,24 +83,21 @@ struct Panel_ {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#define KEY_CTRLN 0016 /* control-n key */
|
||||
#define KEY_CTRLP 0020 /* control-p key */
|
||||
#define KEY_CTRLF 0006 /* control-f key */
|
||||
#define KEY_CTRLB 0002 /* control-b key */
|
||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||
|
||||
PanelClass Panel_class = {
|
||||
.super = {
|
||||
.extends = Class(Object),
|
||||
.delete = Panel_delete
|
||||
},
|
||||
.eventHandler = Panel_selectByTyping
|
||||
.eventHandler = Panel_selectByTyping,
|
||||
};
|
||||
|
||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type) {
|
||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) {
|
||||
Panel* this;
|
||||
this = malloc(sizeof(Panel));
|
||||
this = xMalloc(sizeof(Panel));
|
||||
Object_setClass(this, Class(Panel));
|
||||
Panel_init(this, x, y, w, h, type, owner);
|
||||
Panel_init(this, x, y, w, h, type, owner, fuBar);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -97,12 +107,12 @@ void Panel_delete(Object* cast) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner) {
|
||||
void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->eventHandlerBuffer = NULL;
|
||||
this->eventHandlerState = NULL;
|
||||
this->items = Vector_new(type, owner, DEFAULT_SIZE);
|
||||
this->scrollV = 0;
|
||||
this->scrollH = 0;
|
||||
@ -110,15 +120,23 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
|
||||
this->oldSelected = 0;
|
||||
this->needsRedraw = true;
|
||||
RichString_beginAllocated(this->header);
|
||||
this->defaultBar = fuBar;
|
||||
this->currentBar = fuBar;
|
||||
this->selectionColor = CRT_colors[PANEL_SELECTION_FOCUS];
|
||||
}
|
||||
|
||||
void Panel_done(Panel* this) {
|
||||
assert (this != NULL);
|
||||
free(this->eventHandlerBuffer);
|
||||
free(this->eventHandlerState);
|
||||
Vector_delete(this->items);
|
||||
FunctionBar_delete(this->defaultBar);
|
||||
RichString_end(this->header);
|
||||
}
|
||||
|
||||
void Panel_setSelectionColor(Panel* this, int color) {
|
||||
this->selectionColor = color;
|
||||
}
|
||||
|
||||
RichString* Panel_getHeader(Panel* this) {
|
||||
assert (this != NULL);
|
||||
|
||||
@ -234,38 +252,26 @@ int Panel_size(Panel* this) {
|
||||
void Panel_setSelected(Panel* this, int selected) {
|
||||
assert (this != NULL);
|
||||
|
||||
selected = MAX(0, MIN(Vector_size(this->items) - 1, selected));
|
||||
int size = Vector_size(this->items);
|
||||
if (selected >= size) {
|
||||
selected = size - 1;
|
||||
}
|
||||
if (selected < 0)
|
||||
selected = 0;
|
||||
this->selected = selected;
|
||||
if (Panel_eventHandlerFn(this)) {
|
||||
Panel_eventHandler(this, EVENT_SETSELECTED);
|
||||
Panel_eventHandler(this, EVENT_SET_SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel_draw(Panel* this, bool focus) {
|
||||
assert (this != NULL);
|
||||
|
||||
int itemCount = Vector_size(this->items);
|
||||
int size = Vector_size(this->items);
|
||||
int scrollH = this->scrollH;
|
||||
int y = this->y; int x = this->x;
|
||||
int first = this->scrollV;
|
||||
if (itemCount > this->h && first > itemCount - this->h) {
|
||||
first = itemCount - this->h;
|
||||
this->scrollV = first;
|
||||
}
|
||||
int last = MIN(itemCount, first + MIN(itemCount, this->h));
|
||||
if (this->selected < first) {
|
||||
first = this->selected;
|
||||
this->scrollV = first;
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
if (this->selected >= last) {
|
||||
last = MIN(itemCount, this->selected + 1);
|
||||
first = MAX(0, last - this->h);
|
||||
this->scrollV = first;
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
assert(first >= 0);
|
||||
assert(last <= itemCount);
|
||||
int y = this->y;
|
||||
int x = this->x;
|
||||
int h = this->h;
|
||||
|
||||
int headerLen = RichString_sizeVal(this->header);
|
||||
if (headerLen > 0) {
|
||||
@ -281,14 +287,34 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
y++;
|
||||
}
|
||||
|
||||
int highlight = focus
|
||||
? CRT_colors[PANEL_HIGHLIGHT_FOCUS]
|
||||
: CRT_colors[PANEL_HIGHLIGHT_UNFOCUS];
|
||||
|
||||
// ensure scroll area is on screen
|
||||
if (this->scrollV < 0) {
|
||||
this->scrollV = 0;
|
||||
this->needsRedraw = true;
|
||||
} else if (this->scrollV >= size) {
|
||||
this->scrollV = MAX(size - 1, 0);
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
// ensure selection is on screen
|
||||
if (this->selected < this->scrollV) {
|
||||
this->scrollV = this->selected;
|
||||
this->needsRedraw = true;
|
||||
} else if (this->selected >= this->scrollV + h) {
|
||||
this->scrollV = this->selected - h + 1;
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
|
||||
int first = this->scrollV;
|
||||
int upTo = MIN(first + h, size);
|
||||
|
||||
int selectionColor = focus
|
||||
? this->selectionColor
|
||||
: CRT_colors[PANEL_SELECTION_UNFOCUS];
|
||||
|
||||
if (this->needsRedraw) {
|
||||
|
||||
for(int i = first, j = 0; j < this->h && i < last; i++, j++) {
|
||||
int line = 0;
|
||||
for(int i = first; line < h && i < upTo; i++) {
|
||||
Object* itemObj = Vector_get(this->items, i);
|
||||
assert(itemObj); if(!itemObj) continue;
|
||||
RichString_begin(item);
|
||||
@ -297,18 +323,22 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
int amt = MIN(itemLen - scrollH, this->w);
|
||||
bool selected = (i == this->selected);
|
||||
if (selected) {
|
||||
attrset(highlight);
|
||||
RichString_setAttr(&item, highlight);
|
||||
attrset(selectionColor);
|
||||
RichString_setAttr(&item, selectionColor);
|
||||
this->selectedLen = itemLen;
|
||||
}
|
||||
mvhline(y + j, x, ' ', this->w);
|
||||
mvhline(y + line, x, ' ', this->w);
|
||||
if (amt > 0)
|
||||
RichString_printoffnVal(item, y+j, x, scrollH, amt);
|
||||
RichString_printoffnVal(item, y + line, x, scrollH, amt);
|
||||
if (selected)
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
RichString_end(item);
|
||||
line++;
|
||||
}
|
||||
while (line < h) {
|
||||
mvhline(y + line, x, ' ', this->w);
|
||||
line++;
|
||||
}
|
||||
for (int i = y + (last - first); i < y + this->h; i++)
|
||||
mvhline(i, x+0, ' ', this->w);
|
||||
this->needsRedraw = false;
|
||||
|
||||
} else {
|
||||
@ -321,15 +351,16 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
RichString_begin(new);
|
||||
Object_display(newObj, &new);
|
||||
int newLen = RichString_sizeVal(new);
|
||||
mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w);
|
||||
this->selectedLen = newLen;
|
||||
mvhline(y+ this->oldSelected - first, x+0, ' ', this->w);
|
||||
if (scrollH < oldLen)
|
||||
RichString_printoffnVal(old, y+this->oldSelected - this->scrollV, x,
|
||||
RichString_printoffnVal(old, y+this->oldSelected - first, x,
|
||||
scrollH, MIN(oldLen - scrollH, this->w));
|
||||
attrset(highlight);
|
||||
mvhline(y+this->selected - this->scrollV, x+0, ' ', this->w);
|
||||
RichString_setAttr(&new, highlight);
|
||||
attrset(selectionColor);
|
||||
mvhline(y+this->selected - first, x+0, ' ', this->w);
|
||||
RichString_setAttr(&new, selectionColor);
|
||||
if (scrollH < newLen)
|
||||
RichString_printoffnVal(new, y+this->selected - this->scrollV, x,
|
||||
RichString_printoffnVal(new, y+this->selected - first, x,
|
||||
scrollH, MIN(newLen - scrollH, this->w));
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
RichString_end(new);
|
||||
@ -341,108 +372,126 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
|
||||
bool Panel_onKey(Panel* this, int key) {
|
||||
assert (this != NULL);
|
||||
|
||||
int size = Vector_size(this->items);
|
||||
switch (key) {
|
||||
case KEY_DOWN:
|
||||
case KEY_CTRLN:
|
||||
if (this->selected + 1 < Vector_size(this->items))
|
||||
this->selected++;
|
||||
return true;
|
||||
case KEY_CTRL('N'):
|
||||
this->selected++;
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_CTRLP:
|
||||
if (this->selected > 0)
|
||||
this->selected--;
|
||||
return true;
|
||||
case KEY_CTRL('P'):
|
||||
this->selected--;
|
||||
break;
|
||||
#ifdef KEY_C_DOWN
|
||||
case KEY_C_DOWN:
|
||||
if (this->selected + 1 < Vector_size(this->items)) {
|
||||
this->selected++;
|
||||
if (this->scrollV < Vector_size(this->items) - this->h) {
|
||||
this->scrollV++;
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
this->selected++;
|
||||
break;
|
||||
#endif
|
||||
#ifdef KEY_C_UP
|
||||
case KEY_C_UP:
|
||||
if (this->selected > 0) {
|
||||
this->selected--;
|
||||
if (this->scrollV > 0) {
|
||||
this->scrollV--;
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
this->selected--;
|
||||
break;
|
||||
#endif
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
case KEY_CTRL('B'):
|
||||
if (this->scrollH > 0) {
|
||||
this->scrollH -= CRT_scrollHAmount;
|
||||
this->scrollH -= MAX(CRT_scrollHAmount, 0);
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
case KEY_CTRL('F'):
|
||||
this->scrollH += CRT_scrollHAmount;
|
||||
this->needsRedraw = true;
|
||||
return true;
|
||||
break;
|
||||
case KEY_PPAGE:
|
||||
this->selected -= (this->h - 1);
|
||||
this->scrollV -= (this->h - 1);
|
||||
if (this->selected < 0)
|
||||
this->selected = 0;
|
||||
if (this->scrollV < 0)
|
||||
this->scrollV = 0;
|
||||
this->needsRedraw = true;
|
||||
return true;
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
this->selected += (this->h - 1);
|
||||
int size = Vector_size(this->items);
|
||||
if (this->selected >= size)
|
||||
this->selected = size - 1;
|
||||
this->scrollV += (this->h - 1);
|
||||
if (this->scrollV >= MAX(0, size - this->h))
|
||||
this->scrollV = MAX(0, size - this->h - 1);
|
||||
this->scrollV = MIN(MAX(0, Vector_size(this->items) - this->h), this->selected - this->h);
|
||||
this->needsRedraw = true;
|
||||
return true;
|
||||
break;
|
||||
case KEY_WHEELUP:
|
||||
this->selected -= CRT_scrollWheelVAmount;
|
||||
this->scrollV -= CRT_scrollWheelVAmount;
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_WHEELDOWN:
|
||||
{
|
||||
this->selected += CRT_scrollWheelVAmount;
|
||||
this->scrollV += CRT_scrollWheelVAmount;
|
||||
if (this->scrollV > Vector_size(this->items) - this->h) {
|
||||
this->scrollV = Vector_size(this->items) - this->h;
|
||||
}
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
}
|
||||
case KEY_HOME:
|
||||
this->selected = 0;
|
||||
return true;
|
||||
break;
|
||||
case KEY_END:
|
||||
this->selected = Vector_size(this->items) - 1;
|
||||
return true;
|
||||
this->selected = size - 1;
|
||||
break;
|
||||
case KEY_CTRL('A'):
|
||||
case '^':
|
||||
this->scrollH = 0;
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_CTRL('E'):
|
||||
case '$':
|
||||
this->scrollH = MAX(this->selectedLen - this->w, 0);
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
// ensure selection within bounds
|
||||
if (this->selected < 0 || size == 0) {
|
||||
this->selected = 0;
|
||||
this->needsRedraw = true;
|
||||
} else if (this->selected >= size) {
|
||||
this->selected = size - 1;
|
||||
this->needsRedraw = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
||||
int size = Panel_size(this);
|
||||
if (!this->eventHandlerBuffer)
|
||||
this->eventHandlerBuffer = calloc(100, 1);
|
||||
if (!this->eventHandlerState)
|
||||
this->eventHandlerState = xCalloc(100, sizeof(char));
|
||||
char* buffer = this->eventHandlerState;
|
||||
|
||||
if (isalnum(ch)) {
|
||||
int len = strlen(this->eventHandlerBuffer);
|
||||
if (ch < 255 && isalnum(ch)) {
|
||||
int len = strlen(buffer);
|
||||
if (len < 99) {
|
||||
this->eventHandlerBuffer[len] = ch;
|
||||
this->eventHandlerBuffer[len+1] = '\0';
|
||||
buffer[len] = ch;
|
||||
buffer[len+1] = '\0';
|
||||
}
|
||||
for (int try = 0; try < 2; try++) {
|
||||
len = strlen(this->eventHandlerBuffer);
|
||||
len = strlen(buffer);
|
||||
for (int i = 0; i < size; i++) {
|
||||
char* cur = ((ListItem*) Panel_get(this, i))->value;
|
||||
while (*cur == ' ') cur++;
|
||||
if (strncasecmp(cur, this->eventHandlerBuffer, len) == 0) {
|
||||
if (strncasecmp(cur, buffer, len) == 0) {
|
||||
Panel_setSelected(this, i);
|
||||
return HANDLED;
|
||||
}
|
||||
}
|
||||
this->eventHandlerBuffer[0] = ch;
|
||||
this->eventHandlerBuffer[1] = '\0';
|
||||
// if current word did not match,
|
||||
// retry considering the character the start of a new word.
|
||||
buffer[0] = ch;
|
||||
buffer[1] = '\0';
|
||||
}
|
||||
return HANDLED;
|
||||
} else if (ch != ERR) {
|
||||
this->eventHandlerBuffer[0] = '\0';
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
if (ch == 13) {
|
||||
return BREAK_LOOP;
|
||||
|
36
Panel.h
36
Panel.h
@ -13,16 +13,24 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Object.h"
|
||||
#include "Vector.h"
|
||||
#include "FunctionBar.h"
|
||||
|
||||
typedef struct Panel_ Panel;
|
||||
|
||||
typedef enum HandlerResult_ {
|
||||
HANDLED,
|
||||
IGNORED,
|
||||
BREAK_LOOP
|
||||
HANDLED = 0x01,
|
||||
IGNORED = 0x02,
|
||||
BREAK_LOOP = 0x04,
|
||||
REDRAW = 0x08,
|
||||
RESCAN = 0x10,
|
||||
SYNTH_KEY = 0x20,
|
||||
} HandlerResult;
|
||||
|
||||
#define EVENT_SETSELECTED -1
|
||||
#define EVENT_SET_SELECTED -1
|
||||
|
||||
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
||||
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000)
|
||||
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
||||
|
||||
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
||||
|
||||
@ -37,19 +45,24 @@ typedef struct PanelClass_ {
|
||||
|
||||
struct Panel_ {
|
||||
Object super;
|
||||
PanelClass* class;
|
||||
int x, y, w, h;
|
||||
WINDOW* window;
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
char* eventHandlerBuffer;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
bool needsRedraw;
|
||||
FunctionBar* currentBar;
|
||||
FunctionBar* defaultBar;
|
||||
RichString header;
|
||||
int selectionColor;
|
||||
};
|
||||
|
||||
#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0)
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
@ -58,21 +71,20 @@ struct Panel_ {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#define KEY_CTRLN 0016 /* control-n key */
|
||||
#define KEY_CTRLP 0020 /* control-p key */
|
||||
#define KEY_CTRLF 0006 /* control-f key */
|
||||
#define KEY_CTRLB 0002 /* control-b key */
|
||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||
|
||||
extern PanelClass Panel_class;
|
||||
|
||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type);
|
||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
||||
|
||||
void Panel_delete(Object* cast);
|
||||
|
||||
void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner);
|
||||
void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar);
|
||||
|
||||
void Panel_done(Panel* this);
|
||||
|
||||
void Panel_setSelectionColor(Panel* this, int color);
|
||||
|
||||
RichString* Panel_getHeader(Panel* this);
|
||||
|
||||
extern void Panel_setHeader(Panel* this, const char* header);
|
||||
|
222
Process.h
222
Process.h
@ -4,15 +4,17 @@
|
||||
#define HEADER_Process
|
||||
/*
|
||||
htop - Process.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
(C) 2004-2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#ifdef __ANDROID__
|
||||
#define SYS_ioprio_get __NR_ioprio_get
|
||||
#define SYS_ioprio_set __NR_ioprio_set
|
||||
#endif
|
||||
|
||||
// This works only with glibc 2.1+. On earlier versions
|
||||
// On Linux, this works only with glibc 2.1+. On earlier versions
|
||||
// the behavior is similar to have a hardcoded page size.
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) )
|
||||
@ -20,137 +22,88 @@ in the source distribution for its full text.
|
||||
#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K )
|
||||
|
||||
#include "Object.h"
|
||||
#include "Affinity.h"
|
||||
#include "IOPriority.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define PROCESS_FLAG_IO 1
|
||||
#define PROCESS_FLAG_IOPRIO 2
|
||||
#define PROCESS_FLAG_OPENVZ 4
|
||||
#define PROCESS_FLAG_VSERVER 8
|
||||
#define PROCESS_FLAG_CGROUP 16
|
||||
#define PROCESS_FLAG_IO 0x0001
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isThread
|
||||
#define Process_isThread(_process) (Process_isUserlandThread(_process) || Process_isKernelThread(_process))
|
||||
#endif
|
||||
|
||||
typedef enum ProcessField_ {
|
||||
PID = 1, COMM, STATE, PPID, PGRP, SESSION, TTY_NR, TPGID, FLAGS, MINFLT, CMINFLT, MAJFLT, CMAJFLT, UTIME,
|
||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
|
||||
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
|
||||
USER, TIME, NLWP, TGID,
|
||||
#ifdef HAVE_OPENVZ
|
||||
CTID, VPID,
|
||||
#endif
|
||||
#ifdef HAVE_VSERVER
|
||||
VXID,
|
||||
#endif
|
||||
#ifdef HAVE_TASKSTATS
|
||||
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
|
||||
#endif
|
||||
#ifdef HAVE_CGROUP
|
||||
CGROUP,
|
||||
#endif
|
||||
#ifdef HAVE_OOM
|
||||
OOM,
|
||||
#endif
|
||||
IO_PRIORITY,
|
||||
LAST_PROCESSFIELD
|
||||
typedef enum ProcessFields {
|
||||
NULL_PROCESSFIELD = 0,
|
||||
PID = 1,
|
||||
COMM = 2,
|
||||
STATE = 3,
|
||||
PPID = 4,
|
||||
PGRP = 5,
|
||||
SESSION = 6,
|
||||
TTY_NR = 7,
|
||||
TPGID = 8,
|
||||
MINFLT = 10,
|
||||
MAJFLT = 12,
|
||||
PRIORITY = 18,
|
||||
NICE = 19,
|
||||
STARTTIME = 21,
|
||||
PROCESSOR = 38,
|
||||
M_SIZE = 39,
|
||||
M_RESIDENT = 40,
|
||||
ST_UID = 46,
|
||||
PERCENT_CPU = 47,
|
||||
PERCENT_MEM = 48,
|
||||
USER = 49,
|
||||
TIME = 50,
|
||||
NLWP = 51,
|
||||
TGID = 52,
|
||||
} ProcessField;
|
||||
|
||||
struct ProcessList_;
|
||||
typedef struct ProcessPidColumn_ {
|
||||
int id;
|
||||
char* label;
|
||||
} ProcessPidColumn;
|
||||
|
||||
typedef struct Process_ {
|
||||
Object super;
|
||||
|
||||
struct ProcessList_ *pl;
|
||||
struct Settings_* settings;
|
||||
|
||||
unsigned long long int time;
|
||||
pid_t pid;
|
||||
pid_t ppid;
|
||||
pid_t tgid;
|
||||
char* comm;
|
||||
int commLen;
|
||||
int indent;
|
||||
|
||||
int basenameOffset;
|
||||
bool updated;
|
||||
|
||||
char state;
|
||||
bool tag;
|
||||
bool showChildren;
|
||||
bool show;
|
||||
pid_t ppid;
|
||||
unsigned int pgrp;
|
||||
unsigned int session;
|
||||
unsigned int tty_nr;
|
||||
pid_t tgid;
|
||||
int tpgid;
|
||||
unsigned long int flags;
|
||||
|
||||
uid_t st_uid;
|
||||
unsigned long int flags;
|
||||
int processor;
|
||||
|
||||
float percent_cpu;
|
||||
float percent_mem;
|
||||
char* user;
|
||||
|
||||
unsigned long long int utime;
|
||||
unsigned long long int stime;
|
||||
unsigned long long int cutime;
|
||||
unsigned long long int cstime;
|
||||
long int priority;
|
||||
long int nice;
|
||||
long int nlwp;
|
||||
IOPriority ioPriority;
|
||||
char starttime_show[8];
|
||||
time_t starttime_ctime;
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
unsigned long long io_rchar;
|
||||
unsigned long long io_wchar;
|
||||
unsigned long long io_syscr;
|
||||
unsigned long long io_syscw;
|
||||
unsigned long long io_read_bytes;
|
||||
unsigned long long io_write_bytes;
|
||||
unsigned long long io_cancelled_write_bytes;
|
||||
double io_rate_read_bps;
|
||||
unsigned long long io_rate_read_time;
|
||||
double io_rate_write_bps;
|
||||
unsigned long long io_rate_write_time;
|
||||
#endif
|
||||
|
||||
int processor;
|
||||
long m_size;
|
||||
long m_resident;
|
||||
long m_share;
|
||||
long m_trs;
|
||||
long m_drs;
|
||||
long m_lrs;
|
||||
long m_dt;
|
||||
|
||||
#ifdef HAVE_OPENVZ
|
||||
unsigned int ctid;
|
||||
unsigned int vpid;
|
||||
#endif
|
||||
#ifdef HAVE_VSERVER
|
||||
unsigned int vxid;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CGROUP
|
||||
char* cgroup;
|
||||
#endif
|
||||
#ifdef HAVE_OOM
|
||||
unsigned int oom;
|
||||
#endif
|
||||
|
||||
int exit_signal;
|
||||
int basenameOffset;
|
||||
bool updated;
|
||||
|
||||
unsigned long int minflt;
|
||||
unsigned long int cminflt;
|
||||
unsigned long int majflt;
|
||||
unsigned long int cmajflt;
|
||||
#ifdef DEBUG
|
||||
long int itrealvalue;
|
||||
unsigned long int vsize;
|
||||
@ -172,15 +125,32 @@ typedef struct Process_ {
|
||||
|
||||
} Process;
|
||||
|
||||
typedef struct ProcessFieldData_ {
|
||||
const char* name;
|
||||
const char* title;
|
||||
const char* description;
|
||||
int flags;
|
||||
} ProcessFieldData;
|
||||
|
||||
extern const char *Process_fieldNames[];
|
||||
// Implemented in platform-specific code:
|
||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||
long Process_compare(const void* v1, const void* v2);
|
||||
void Process_delete(Object* cast);
|
||||
bool Process_isThread(Process* this);
|
||||
extern ProcessFieldData Process_fields[];
|
||||
extern ProcessPidColumn Process_pidColumns[];
|
||||
extern char Process_pidFormat[20];
|
||||
|
||||
extern const int Process_fieldFlags[];
|
||||
typedef Process*(*Process_New)(struct Settings_*);
|
||||
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
|
||||
|
||||
extern const char *Process_fieldTitles[];
|
||||
typedef struct ProcessClass_ {
|
||||
const ObjectClass super;
|
||||
const Process_WriteField writeField;
|
||||
} ProcessClass;
|
||||
|
||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||
|
||||
void Process_getMaxPid();
|
||||
|
||||
#define ONE_K 1024L
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
@ -190,11 +160,27 @@ void Process_getMaxPid();
|
||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||
|
||||
void Process_delete(Object* cast);
|
||||
extern char Process_pidFormat[20];
|
||||
|
||||
extern ObjectClass Process_class;
|
||||
void Process_setupColumnWidths();
|
||||
|
||||
Process* Process_new(struct ProcessList_ *pl);
|
||||
void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
||||
|
||||
void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
||||
|
||||
void Process_printTime(RichString* str, unsigned long long totalHundredths);
|
||||
|
||||
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring);
|
||||
|
||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||
|
||||
void Process_display(Object* cast, RichString* out);
|
||||
|
||||
void Process_done(Process* this);
|
||||
|
||||
extern ProcessClass Process_class;
|
||||
|
||||
void Process_init(Process* this, struct Settings_* settings);
|
||||
|
||||
void Process_toggleTag(Process* this);
|
||||
|
||||
@ -202,38 +188,10 @@ bool Process_setPriority(Process* this, int priority);
|
||||
|
||||
bool Process_changePriorityBy(Process* this, size_t delta);
|
||||
|
||||
IOPriority Process_updateIOPriority(Process* this);
|
||||
|
||||
bool Process_setIOPriority(Process* this, IOPriority ioprio);
|
||||
|
||||
/*
|
||||
[1] Note that before kernel 2.6.26 a process that has not asked for
|
||||
an io priority formally uses "none" as scheduling class, but the
|
||||
io scheduler will treat such processes as if it were in the best
|
||||
effort class. The priority within the best effort class will be
|
||||
dynamically derived from the cpu nice level of the process:
|
||||
extern io_priority;
|
||||
*/
|
||||
#define Process_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->nice + 20) / 5) : p_->ioPriority)
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
|
||||
Affinity* Process_getAffinity(Process* this);
|
||||
|
||||
bool Process_setAffinity(Process* this, Affinity* affinity);
|
||||
|
||||
#elif HAVE_NATIVE_AFFINITY
|
||||
|
||||
Affinity* Process_getAffinity(Process* this);
|
||||
|
||||
bool Process_setAffinity(Process* this, Affinity* affinity);
|
||||
|
||||
#endif
|
||||
|
||||
void Process_sendSignal(Process* this, size_t sgn);
|
||||
|
||||
int Process_pidCompare(const void* v1, const void* v2);
|
||||
long Process_pidCompare(const void* v1, const void* v2);
|
||||
|
||||
int Process_compare(const void* v1, const void* v2);
|
||||
long Process_compare(const void* v1, const void* v2);
|
||||
|
||||
#endif
|
||||
|
938
ProcessList.c
938
ProcessList.c
File diff suppressed because it is too large
Load Diff
136
ProcessList.h
136
ProcessList.h
@ -14,17 +14,10 @@ in the source distribution for its full text.
|
||||
#include "UsersTable.h"
|
||||
#include "Panel.h"
|
||||
#include "Process.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#ifndef PROCDIR
|
||||
#define PROCDIR "/proc"
|
||||
#endif
|
||||
|
||||
#ifndef PROCSTATFILE
|
||||
#define PROCSTATFILE PROCDIR "/stat"
|
||||
#endif
|
||||
|
||||
#ifndef PROCMEMINFOFILE
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#include <hwloc.h>
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
@ -35,51 +28,9 @@ in the source distribution for its full text.
|
||||
#define MAX_READ 2048
|
||||
#endif
|
||||
|
||||
#ifndef ProcessList_cpuId
|
||||
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
|
||||
#endif
|
||||
|
||||
typedef enum TreeStr_ {
|
||||
TREE_STR_HORZ,
|
||||
TREE_STR_VERT,
|
||||
TREE_STR_RTEE,
|
||||
TREE_STR_BEND,
|
||||
TREE_STR_TEND,
|
||||
TREE_STR_OPEN,
|
||||
TREE_STR_SHUT,
|
||||
TREE_STR_COUNT
|
||||
} TreeStr;
|
||||
|
||||
typedef struct CPUData_ {
|
||||
unsigned long long int totalTime;
|
||||
unsigned long long int userTime;
|
||||
unsigned long long int systemTime;
|
||||
unsigned long long int systemAllTime;
|
||||
unsigned long long int idleAllTime;
|
||||
unsigned long long int idleTime;
|
||||
unsigned long long int niceTime;
|
||||
unsigned long long int ioWaitTime;
|
||||
unsigned long long int irqTime;
|
||||
unsigned long long int softIrqTime;
|
||||
unsigned long long int stealTime;
|
||||
unsigned long long int guestTime;
|
||||
|
||||
unsigned long long int totalPeriod;
|
||||
unsigned long long int userPeriod;
|
||||
unsigned long long int systemPeriod;
|
||||
unsigned long long int systemAllPeriod;
|
||||
unsigned long long int idleAllPeriod;
|
||||
unsigned long long int idlePeriod;
|
||||
unsigned long long int nicePeriod;
|
||||
unsigned long long int ioWaitPeriod;
|
||||
unsigned long long int irqPeriod;
|
||||
unsigned long long int softIrqPeriod;
|
||||
unsigned long long int stealPeriod;
|
||||
unsigned long long int guestPeriod;
|
||||
} CPUData;
|
||||
|
||||
typedef struct ProcessList_ {
|
||||
const char **treeStr;
|
||||
Settings* settings;
|
||||
|
||||
Vector* processes;
|
||||
Vector* processes2;
|
||||
Hashtable* processTable;
|
||||
@ -91,17 +42,15 @@ typedef struct ProcessList_ {
|
||||
const char* incFilter;
|
||||
Hashtable* pidWhiteList;
|
||||
|
||||
int cpuCount;
|
||||
int totalTasks;
|
||||
int userlandThreads;
|
||||
int kernelThreads;
|
||||
int runningTasks;
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
hwloc_topology_t topology;
|
||||
bool topologyOk;
|
||||
#endif
|
||||
CPUData* cpus;
|
||||
|
||||
int totalTasks;
|
||||
int runningTasks;
|
||||
int userlandThreads;
|
||||
int kernelThreads;
|
||||
|
||||
unsigned long long int totalMem;
|
||||
unsigned long long int usedMem;
|
||||
@ -113,76 +62,41 @@ typedef struct ProcessList_ {
|
||||
unsigned long long int usedSwap;
|
||||
unsigned long long int freeSwap;
|
||||
|
||||
int flags;
|
||||
ProcessField* fields;
|
||||
ProcessField sortKey;
|
||||
int direction;
|
||||
bool hideThreads;
|
||||
bool shadowOtherUsers;
|
||||
bool showThreadNames;
|
||||
bool showingThreadNames;
|
||||
bool hideKernelThreads;
|
||||
bool hideUserlandThreads;
|
||||
bool treeView;
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool highlightThreads;
|
||||
bool detailedCPUTime;
|
||||
bool countCPUsFromZero;
|
||||
bool updateProcessNames;
|
||||
bool accountGuestInCPUMeter;
|
||||
bool userOnly;
|
||||
int cpuCount;
|
||||
|
||||
} ProcessList;
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
|
||||
void ProcessList_delete(ProcessList* pl);
|
||||
void ProcessList_goThroughEntries(ProcessList* pl);
|
||||
|
||||
extern const char *ProcessList_treeStrAscii[TREE_STR_COUNT];
|
||||
|
||||
extern const char *ProcessList_treeStrUtf8[TREE_STR_COUNT];
|
||||
ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList);
|
||||
|
||||
void ProcessList_delete(ProcessList* this);
|
||||
void ProcessList_done(ProcessList* this);
|
||||
|
||||
void ProcessList_setPanel(ProcessList* this, Panel* panel);
|
||||
|
||||
void ProcessList_invertSortOrder(ProcessList* this);
|
||||
|
||||
void ProcessList_printHeader(ProcessList* this, RichString* header);
|
||||
|
||||
void ProcessList_add(ProcessList* this, Process* p);
|
||||
|
||||
void ProcessList_remove(ProcessList* this, Process* p);
|
||||
|
||||
Process* ProcessList_get(ProcessList* this, int idx);
|
||||
|
||||
int ProcessList_size(ProcessList* this);
|
||||
|
||||
void ProcessList_sort(ProcessList* this);
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENVZ
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CGROUP
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VSERVER
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OOM
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void ProcessList_scan(ProcessList* this);
|
||||
|
||||
ProcessField ProcessList_keyAt(ProcessList* this, int at);
|
||||
|
||||
void ProcessList_expandTree(ProcessList* this);
|
||||
|
||||
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, const char* incFilter);
|
||||
void ProcessList_rebuildPanel(ProcessList* this);
|
||||
|
||||
Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor);
|
||||
|
||||
void ProcessList_scan(ProcessList* this);
|
||||
|
||||
#endif
|
||||
|
81
README
81
README
@ -1,62 +1,61 @@
|
||||
htop
|
||||
[](https://travis-ci.org/hishamhm/htop)
|
||||
[](http://hisham.hm/htop/index.php?page=donate)
|
||||
|
||||
[htop](http://hisham.hm/htop/)
|
||||
====
|
||||
|
||||
by Hisham Muhammad <hisham@gobolinux.org>
|
||||
|
||||
May, 2004 - January, 2014
|
||||
|
||||
Note
|
||||
----
|
||||
|
||||
 **Mac users, [click here](https://www.bountysource.com/fundraisers/554-mac-os-x-support-in-the-official-htop-1-x-tree)!** The htop version you are using is a 5-year old fork -- help bring htop 1.x to the Mac!
|
||||
by Hisham Muhammad <hisham@gobolinux.org> (2004 - 2016)
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This is htop, an interactive process viewer.
|
||||
It requires ncurses. It is tested with Linux 2.6,
|
||||
but is also reported to work (and was originally developed)
|
||||
with the 2.4 series.
|
||||
This is `htop`, an interactive process viewer.
|
||||
It requires `ncurses`. It is developed primarily on Linux,
|
||||
but we also have code for running under FreeBSD and Mac OS X
|
||||
(help and testing are wanted for these platforms!)
|
||||
|
||||
Note that, while, htop is Linux specific -- it is based
|
||||
on the Linux /proc filesystem -- it is also reported to work
|
||||
with FreeBSD systems featuring a Linux-compatible /proc.
|
||||
This is, however, unsupported. Contact the packager for your
|
||||
system when reporting problems on platforms other than Linux.
|
||||
This software has evolved considerably over the years,
|
||||
and is reasonably complete, but there is always room for improvement.
|
||||
|
||||
This software has evolved considerably during the last years,
|
||||
and is reasonably complete, but there is still room for
|
||||
improvement. Read the TODO file to see what's known to be missing.
|
||||
Comparison between `htop` and classic `top`
|
||||
-------------------------------------------
|
||||
|
||||
Comparison between 'htop' and 'top'
|
||||
-----------------------------------
|
||||
|
||||
* In 'htop' you can scroll the list vertically and horizontally
|
||||
* In `htop` you can scroll the list vertically and horizontally
|
||||
to see all processes and full command lines.
|
||||
* In 'top' you are subject to a delay for each unassigned
|
||||
* In `top` you are subject to a delay for each unassigned
|
||||
key you press (especially annoying when multi-key escape
|
||||
sequences are triggered by accident).
|
||||
* 'htop' starts faster ('top' seems to collect data for a while
|
||||
* `htop` starts faster (`top` seems to collect data for a while
|
||||
before displaying anything).
|
||||
* In 'htop' you don't need to type the process number to
|
||||
kill a process, in 'top' you do.
|
||||
* In 'htop' you don't need to type the process number or
|
||||
the priority value to renice a process, in 'top' you do.
|
||||
* In 'htop' you can kill multiple processes at once.
|
||||
* 'top' is older, hence, more tested.
|
||||
* In `htop` you don't need to type the process number to
|
||||
kill a process, in `top` you do.
|
||||
* In `htop` you don't need to type the process number or
|
||||
the priority value to renice a process, in `top` you do.
|
||||
* In `htop` you can kill multiple processes at once.
|
||||
* `top` is older, hence, more tested.
|
||||
|
||||
Compilation instructions
|
||||
------------------------
|
||||
|
||||
This program is distributed as a standard autotools-based package.
|
||||
See the INSTALL file for detailed instructions, but you are
|
||||
probably used to the common `./configure`/`make`/`make install` routine.
|
||||
See the [INSTALL](/INSTALL) file for detailed instructions.
|
||||
|
||||
When fetching the code from the development repository, you need
|
||||
to run the `./autogen.sh` script, which in turn requires autotools
|
||||
to be installed.
|
||||
When compiling from a release tarball, run:
|
||||
|
||||
See the manual page (man htop) or the on-line help ('F1' or 'h'
|
||||
inside htop) for a list of supported key commands.
|
||||
./configure && make
|
||||
|
||||
if not all keys work check your curses configuration.
|
||||
For compiling sources downloaded from the Git repository, run:
|
||||
|
||||
./autogen.sh && ./configure && make
|
||||
|
||||
By default `make install` will install into `/usr/local`, for changing
|
||||
the path use `./configure --prefix=/some/path`.
|
||||
|
||||
See the manual page (`man htop`) or the on-line help ('F1' or 'h'
|
||||
inside `htop`) for a list of supported key commands.
|
||||
|
||||
If not all keys work check your curses configuration.
|
||||
|
||||
## License
|
||||
|
||||
GNU General Public License, version 2 (GPL-2.0)
|
||||
|
44
RichString.c
44
RichString.c
@ -6,11 +6,12 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "RichString.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define RICHSTRING_MAXLEN 300
|
||||
#define RICHSTRING_MAXLEN 350
|
||||
|
||||
/*{
|
||||
#include "config.h"
|
||||
@ -29,18 +30,22 @@ in the source distribution for its full text.
|
||||
#include <curses.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
|
||||
#define RichString_size(this) ((this)->chlen)
|
||||
#define RichString_sizeVal(this) ((this).chlen)
|
||||
|
||||
#define RichString_begin(this) RichString (this); (this).chlen = 0; (this).chptr = (this).chstr;
|
||||
#define RichString_beginAllocated(this) (this).chlen = 0; (this).chptr = (this).chstr;
|
||||
#define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
|
||||
#define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
|
||||
#define RichString_end(this) RichString_prune(&(this));
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
#define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr)
|
||||
#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + off, n)
|
||||
#define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255)
|
||||
#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)].chars[0] = ch; } while(0)
|
||||
#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0)
|
||||
#define CharType cchar_t
|
||||
#else
|
||||
#define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr)
|
||||
@ -52,52 +57,48 @@ in the source distribution for its full text.
|
||||
|
||||
typedef struct RichString_ {
|
||||
int chlen;
|
||||
CharType chstr[RICHSTRING_MAXLEN+1];
|
||||
CharType* chptr;
|
||||
CharType chstr[RICHSTRING_MAXLEN+1];
|
||||
} RichString;
|
||||
|
||||
}*/
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#define charBytes(n) (sizeof(CharType) * (n))
|
||||
|
||||
static inline void RichString_setLen(RichString* this, int len) {
|
||||
static void RichString_extendLen(RichString* this, int len) {
|
||||
if (this->chlen <= RICHSTRING_MAXLEN) {
|
||||
if (len > RICHSTRING_MAXLEN) {
|
||||
this->chptr = malloc(charBytes(len+1));
|
||||
memcpy(this->chptr, this->chstr, charBytes(this->chlen+1));
|
||||
this->chptr = xMalloc(charBytes(len + 1));
|
||||
memcpy(this->chptr, this->chstr, charBytes(this->chlen));
|
||||
}
|
||||
} else {
|
||||
if (len <= RICHSTRING_MAXLEN) {
|
||||
memcpy(this->chstr, this->chptr, charBytes(this->chlen));
|
||||
memcpy(this->chstr, this->chptr, charBytes(len));
|
||||
free(this->chptr);
|
||||
this->chptr = this->chstr;
|
||||
} else {
|
||||
this->chptr = realloc(this->chptr, charBytes(len+1));
|
||||
this->chptr = xRealloc(this->chptr, charBytes(len + 1));
|
||||
}
|
||||
}
|
||||
|
||||
RichString_setChar(this, len, 0);
|
||||
this->chlen = len;
|
||||
}
|
||||
|
||||
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) {
|
||||
wchar_t data[len+1];
|
||||
len = mbstowcs(data, data_c, len);
|
||||
if (len<0)
|
||||
if (len < 0)
|
||||
return;
|
||||
int newLen = from + len;
|
||||
RichString_setLen(this, newLen);
|
||||
memset(&this->chptr[from], 0, sizeof(CharType) * (newLen - from));
|
||||
for (int i = from, j = 0; i < newLen; i++, j++) {
|
||||
this->chptr[i].chars[0] = data[j];
|
||||
this->chptr[i].attr = attrs;
|
||||
this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (iswprint(data[j]) ? data[j] : '?') } };
|
||||
}
|
||||
this->chptr[newLen].chars[0] = 0;
|
||||
}
|
||||
|
||||
inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
||||
@ -125,7 +126,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
|
||||
int newLen = from + len;
|
||||
RichString_setLen(this, newLen);
|
||||
for (int i = from, j = 0; i < newLen; i++, j++)
|
||||
this->chptr[i] = (isprint(data_c[j]) ? data_c[j] : '?') | attrs;
|
||||
this->chptr[i] = (data_c[j] >= 32 ? data_c[j] : '?') | attrs;
|
||||
this->chptr[newLen] = 0;
|
||||
}
|
||||
|
||||
@ -152,9 +153,8 @@ int RichString_findChar(RichString* this, char c, int start) {
|
||||
void RichString_prune(RichString* this) {
|
||||
if (this->chlen > RICHSTRING_MAXLEN)
|
||||
free(this->chptr);
|
||||
memset(this, 0, sizeof(RichString));
|
||||
this->chptr = this->chstr;
|
||||
this->chlen = 0;
|
||||
RichString_setChar(this, 0, 0);
|
||||
}
|
||||
|
||||
void RichString_setAttr(RichString* this, int attrs) {
|
||||
|
20
RichString.h
20
RichString.h
@ -9,7 +9,7 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#define RICHSTRING_MAXLEN 300
|
||||
#define RICHSTRING_MAXLEN 350
|
||||
|
||||
#include "config.h"
|
||||
#include <ctype.h>
|
||||
@ -27,18 +27,22 @@ in the source distribution for its full text.
|
||||
#include <curses.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
|
||||
#define RichString_size(this) ((this)->chlen)
|
||||
#define RichString_sizeVal(this) ((this).chlen)
|
||||
|
||||
#define RichString_begin(this) RichString (this); (this).chlen = 0; (this).chptr = (this).chstr;
|
||||
#define RichString_beginAllocated(this) (this).chlen = 0; (this).chptr = (this).chstr;
|
||||
#define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
|
||||
#define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr;
|
||||
#define RichString_end(this) RichString_prune(&(this));
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
#define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr)
|
||||
#define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + off, n)
|
||||
#define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255)
|
||||
#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)].chars[0] = ch; } while(0)
|
||||
#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0)
|
||||
#define CharType cchar_t
|
||||
#else
|
||||
#define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr)
|
||||
@ -50,17 +54,15 @@ in the source distribution for its full text.
|
||||
|
||||
typedef struct RichString_ {
|
||||
int chlen;
|
||||
CharType chstr[RICHSTRING_MAXLEN+1];
|
||||
CharType* chptr;
|
||||
CharType chstr[RICHSTRING_MAXLEN+1];
|
||||
} RichString;
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#define charBytes(n) (sizeof(CharType) * (n))
|
||||
|
||||
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
|
||||
|
257
ScreenManager.c
257
ScreenManager.c
@ -6,9 +6,10 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ScreenManager.h"
|
||||
#include "ProcessList.h"
|
||||
|
||||
#include "Panel.h"
|
||||
#include "Object.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
@ -19,6 +20,8 @@ in the source distribution for its full text.
|
||||
#include "FunctionBar.h"
|
||||
#include "Vector.h"
|
||||
#include "Header.h"
|
||||
#include "Settings.h"
|
||||
#include "Panel.h"
|
||||
|
||||
typedef enum Orientation_ {
|
||||
VERTICAL,
|
||||
@ -32,30 +35,27 @@ typedef struct ScreenManager_ {
|
||||
int y2;
|
||||
Orientation orientation;
|
||||
Vector* panels;
|
||||
Vector* fuBars;
|
||||
int panelCount;
|
||||
const FunctionBar* fuBar;
|
||||
const Header* header;
|
||||
time_t lastScan;
|
||||
const Settings* settings;
|
||||
bool owner;
|
||||
bool allowFocusChange;
|
||||
} ScreenManager;
|
||||
|
||||
}*/
|
||||
|
||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, bool owner) {
|
||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner) {
|
||||
ScreenManager* this;
|
||||
this = malloc(sizeof(ScreenManager));
|
||||
this = xMalloc(sizeof(ScreenManager));
|
||||
this->x1 = x1;
|
||||
this->y1 = y1;
|
||||
this->x2 = x2;
|
||||
this->y2 = y2;
|
||||
this->fuBar = NULL;
|
||||
this->orientation = orientation;
|
||||
this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE);
|
||||
this->fuBars = Vector_new(Class(FunctionBar), true, DEFAULT_SIZE);
|
||||
this->panelCount = 0;
|
||||
this->header = header;
|
||||
this->settings = settings;
|
||||
this->owner = owner;
|
||||
this->allowFocusChange = true;
|
||||
return this;
|
||||
@ -63,7 +63,6 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
|
||||
|
||||
void ScreenManager_delete(ScreenManager* this) {
|
||||
Vector_delete(this->panels);
|
||||
Vector_delete(this->fuBars);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -71,27 +70,23 @@ inline int ScreenManager_size(ScreenManager* this) {
|
||||
return this->panelCount;
|
||||
}
|
||||
|
||||
void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size) {
|
||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
||||
if (this->orientation == HORIZONTAL) {
|
||||
int lastX = 0;
|
||||
if (this->panelCount > 0) {
|
||||
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1);
|
||||
lastX = last->x + last->w + 1;
|
||||
}
|
||||
int height = LINES - this->y1 + this->y2;
|
||||
if (size > 0) {
|
||||
Panel_resize(item, size, LINES-this->y1+this->y2);
|
||||
Panel_resize(item, size, height);
|
||||
} else {
|
||||
Panel_resize(item, COLS-this->x1+this->x2-lastX, LINES-this->y1+this->y2);
|
||||
Panel_resize(item, COLS-this->x1+this->x2-lastX, height);
|
||||
}
|
||||
Panel_move(item, lastX, this->y1);
|
||||
}
|
||||
// TODO: VERTICAL
|
||||
Vector_add(this->panels, item);
|
||||
if (fuBar)
|
||||
Vector_add(this->fuBars, fuBar);
|
||||
else
|
||||
Vector_add(this->fuBars, FunctionBar_new(NULL, NULL, NULL));
|
||||
if (!this->fuBar && fuBar) this->fuBar = fuBar;
|
||||
item->needsRedraw = true;
|
||||
this->panelCount++;
|
||||
}
|
||||
@ -99,8 +94,6 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
|
||||
Panel* ScreenManager_remove(ScreenManager* this, int idx) {
|
||||
assert(this->panelCount > idx);
|
||||
Panel* panel = (Panel*) Vector_remove(this->panels, idx);
|
||||
Vector_remove(this->fuBars, idx);
|
||||
this->fuBar = NULL;
|
||||
this->panelCount--;
|
||||
return panel;
|
||||
}
|
||||
@ -111,118 +104,206 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
|
||||
this->x2 = x2;
|
||||
this->y2 = y2;
|
||||
int panels = this->panelCount;
|
||||
int lastX = 0;
|
||||
for (int i = 0; i < panels - 1; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
Panel_resize(panel, panel->w, LINES-y1+y2);
|
||||
if (this->orientation == HORIZONTAL) {
|
||||
int lastX = 0;
|
||||
for (int i = 0; i < panels - 1; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
Panel_resize(panel, panel->w, LINES-y1+y2);
|
||||
Panel_move(panel, lastX, y1);
|
||||
lastX = panel->x + panel->w + 1;
|
||||
}
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, panels-1);
|
||||
Panel_resize(panel, COLS-x1+x2-lastX, LINES-y1+y2);
|
||||
Panel_move(panel, lastX, y1);
|
||||
lastX = panel->x + panel->w + 1;
|
||||
}
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, panels-1);
|
||||
Panel_resize(panel, COLS-x1+x2-lastX, LINES-y1+y2);
|
||||
Panel_move(panel, lastX, y1);
|
||||
// TODO: VERTICAL
|
||||
}
|
||||
|
||||
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool *rescan, bool *timedOut) {
|
||||
ProcessList* pl = this->header->pl;
|
||||
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
|
||||
*timedOut = (newTime - *oldTime > this->settings->delay);
|
||||
*rescan = *rescan || *timedOut;
|
||||
if (newTime < *oldTime) *rescan = true; // clock was adjusted?
|
||||
if (*rescan) {
|
||||
*oldTime = newTime;
|
||||
ProcessList_scan(pl);
|
||||
if (*sortTimeout == 0 || this->settings->treeView) {
|
||||
ProcessList_sort(pl);
|
||||
*sortTimeout = 1;
|
||||
}
|
||||
*redraw = true;
|
||||
}
|
||||
if (*redraw) {
|
||||
ProcessList_rebuildPanel(pl);
|
||||
Header_draw(this->header);
|
||||
}
|
||||
*rescan = false;
|
||||
}
|
||||
|
||||
static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
||||
int nPanels = this->panelCount;
|
||||
for (int i = 0; i < nPanels; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
Panel_draw(panel, i == focus);
|
||||
if (i < nPanels) {
|
||||
if (this->orientation == HORIZONTAL) {
|
||||
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Panel* setCurrentPanel(Panel* panel) {
|
||||
FunctionBar_draw(panel->currentBar, NULL);
|
||||
return panel;
|
||||
}
|
||||
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
bool quit = false;
|
||||
int focus = 0;
|
||||
|
||||
Panel* panelFocus = (Panel*) Vector_get(this->panels, focus);
|
||||
if (this->fuBar)
|
||||
FunctionBar_draw(this->fuBar, NULL);
|
||||
|
||||
this->lastScan = 0;
|
||||
Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
|
||||
double oldTime = 0.0;
|
||||
|
||||
int ch = ERR;
|
||||
int closeTimeout = 0;
|
||||
|
||||
bool timedOut = true;
|
||||
bool redraw = true;
|
||||
bool rescan = false;
|
||||
int sortTimeout = 0;
|
||||
int resetSortTimeout = 5;
|
||||
|
||||
int ch = 0;
|
||||
while (!quit) {
|
||||
int panels = this->panelCount;
|
||||
if (this->header) {
|
||||
time_t now = time(NULL);
|
||||
if (now > this->lastScan) {
|
||||
ProcessList_scan(this->header->pl);
|
||||
ProcessList_sort(this->header->pl);
|
||||
this->lastScan = now;
|
||||
}
|
||||
Header_draw(this->header);
|
||||
ProcessList_rebuildPanel(this->header->pl, false, false, false, false, NULL);
|
||||
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
|
||||
}
|
||||
for (int i = 0; i < panels; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
Panel_draw(panel, i == focus);
|
||||
if (i < panels) {
|
||||
if (this->orientation == HORIZONTAL) {
|
||||
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
FunctionBar* bar = (FunctionBar*) Vector_get(this->fuBars, focus);
|
||||
if (bar)
|
||||
this->fuBar = bar;
|
||||
if (this->fuBar)
|
||||
FunctionBar_draw(this->fuBar, NULL);
|
||||
|
||||
ch = getch();
|
||||
|
||||
if (redraw) {
|
||||
ScreenManager_drawPanels(this, focus);
|
||||
}
|
||||
|
||||
int prevCh = ch;
|
||||
set_escdelay(25);
|
||||
ch = getch();
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
if (ch == KEY_MOUSE) {
|
||||
ch = ERR;
|
||||
MEVENT mevent;
|
||||
int ok = getmouse(&mevent);
|
||||
if (ok == OK) {
|
||||
if (mevent.y == LINES - 1) {
|
||||
ch = FunctionBar_synthesizeEvent(this->fuBar, mevent.x);
|
||||
} else {
|
||||
for (int i = 0; i < this->panelCount; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
if (mevent.x > panel->x && mevent.x <= panel->x+panel->w &&
|
||||
mevent.y > panel->y && mevent.y <= panel->y+panel->h &&
|
||||
(this->allowFocusChange || panelFocus == panel) ) {
|
||||
focus = i;
|
||||
panelFocus = panel;
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||
break;
|
||||
if (mevent.bstate & BUTTON1_RELEASED) {
|
||||
if (mevent.y == LINES - 1) {
|
||||
ch = FunctionBar_synthesizeEvent(panelFocus->currentBar, mevent.x);
|
||||
} else {
|
||||
for (int i = 0; i < this->panelCount; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) {
|
||||
if (mevent.y == panel->y) {
|
||||
ch = EVENT_HEADER_CLICK(mevent.x - panel->x);
|
||||
break;
|
||||
} else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) {
|
||||
ch = KEY_MOUSE;
|
||||
if (panel == panelFocus || this->allowFocusChange) {
|
||||
focus = i;
|
||||
panelFocus = setCurrentPanel(panel);
|
||||
Object* oldSelection = Panel_getSelected(panel);
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||
if (Panel_getSelected(panel) == oldSelection) {
|
||||
ch = KEY_RECLICK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if NCURSES_MOUSE_VERSION > 1
|
||||
} else if (mevent.bstate & BUTTON4_PRESSED) {
|
||||
ch = KEY_WHEELUP;
|
||||
} else if (mevent.bstate & BUTTON5_PRESSED) {
|
||||
ch = KEY_WHEELDOWN;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == ERR) {
|
||||
sortTimeout--;
|
||||
if (prevCh == ch && !timedOut) {
|
||||
closeTimeout++;
|
||||
if (closeTimeout == 100) {
|
||||
break;
|
||||
}
|
||||
} else
|
||||
closeTimeout = 0;
|
||||
redraw = false;
|
||||
continue;
|
||||
}
|
||||
switch (ch) {
|
||||
case KEY_ALT('H'): ch = KEY_LEFT; break;
|
||||
case KEY_ALT('J'): ch = KEY_DOWN; break;
|
||||
case KEY_ALT('K'): ch = KEY_UP; break;
|
||||
case KEY_ALT('L'): ch = KEY_RIGHT; break;
|
||||
}
|
||||
redraw = true;
|
||||
if (Panel_eventHandlerFn(panelFocus)) {
|
||||
HandlerResult result = Panel_eventHandler(panelFocus, ch);
|
||||
if (result == HANDLED) {
|
||||
continue;
|
||||
} else if (result == BREAK_LOOP) {
|
||||
quit = true;
|
||||
continue;
|
||||
}
|
||||
result = Panel_eventHandler(panelFocus, ch);
|
||||
}
|
||||
if (result & SYNTH_KEY) {
|
||||
ch = result >> 16;
|
||||
}
|
||||
if (result & REDRAW) {
|
||||
sortTimeout = 0;
|
||||
}
|
||||
if (result & RESCAN) {
|
||||
rescan = true;
|
||||
sortTimeout = 0;
|
||||
}
|
||||
if (result & HANDLED) {
|
||||
continue;
|
||||
} else if (result & BREAK_LOOP) {
|
||||
quit = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case ERR:
|
||||
continue;
|
||||
case KEY_RESIZE:
|
||||
{
|
||||
ScreenManager_resize(this, this->x1, this->y1, this->x2, this->y2);
|
||||
continue;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
case KEY_CTRL('B'):
|
||||
if (this->panelCount < 2) {
|
||||
goto defaultHandler;
|
||||
}
|
||||
if (!this->allowFocusChange)
|
||||
break;
|
||||
tryLeft:
|
||||
if (focus > 0)
|
||||
focus--;
|
||||
panelFocus = (Panel*) Vector_get(this->panels, focus);
|
||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
if (Panel_size(panelFocus) == 0 && focus > 0)
|
||||
goto tryLeft;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
case KEY_CTRL('F'):
|
||||
case 9:
|
||||
if (this->panelCount < 2) {
|
||||
goto defaultHandler;
|
||||
}
|
||||
if (!this->allowFocusChange)
|
||||
break;
|
||||
tryRight:
|
||||
if (focus < this->panelCount - 1)
|
||||
focus++;
|
||||
panelFocus = (Panel*) Vector_get(this->panels, focus);
|
||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
|
||||
goto tryRight;
|
||||
break;
|
||||
@ -232,11 +313,15 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
quit = true;
|
||||
continue;
|
||||
default:
|
||||
defaultHandler:
|
||||
sortTimeout = resetSortTimeout;
|
||||
Panel_onKey(panelFocus, ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*lastFocus = panelFocus;
|
||||
*lastKey = ch;
|
||||
if (lastFocus)
|
||||
*lastFocus = panelFocus;
|
||||
if (lastKey)
|
||||
*lastKey = ch;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ in the source distribution for its full text.
|
||||
#include "FunctionBar.h"
|
||||
#include "Vector.h"
|
||||
#include "Header.h"
|
||||
#include "Settings.h"
|
||||
#include "Panel.h"
|
||||
|
||||
typedef enum Orientation_ {
|
||||
VERTICAL,
|
||||
@ -25,23 +27,21 @@ typedef struct ScreenManager_ {
|
||||
int y2;
|
||||
Orientation orientation;
|
||||
Vector* panels;
|
||||
Vector* fuBars;
|
||||
int panelCount;
|
||||
const FunctionBar* fuBar;
|
||||
const Header* header;
|
||||
time_t lastScan;
|
||||
const Settings* settings;
|
||||
bool owner;
|
||||
bool allowFocusChange;
|
||||
} ScreenManager;
|
||||
|
||||
|
||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, bool owner);
|
||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner);
|
||||
|
||||
void ScreenManager_delete(ScreenManager* this);
|
||||
|
||||
extern int ScreenManager_size(ScreenManager* this);
|
||||
|
||||
void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int size);
|
||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size);
|
||||
|
||||
Panel* ScreenManager_remove(ScreenManager* this, int idx);
|
||||
|
||||
|
382
Settings.c
382
Settings.c
@ -6,9 +6,11 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "Vector.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
@ -18,215 +20,338 @@ in the source distribution for its full text.
|
||||
#define DEFAULT_DELAY 15
|
||||
|
||||
/*{
|
||||
#include "ProcessList.h"
|
||||
#include "Header.h"
|
||||
#include "Process.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
int len;
|
||||
char** names;
|
||||
int* modes;
|
||||
} MeterColumnSettings;
|
||||
|
||||
typedef struct Settings_ {
|
||||
char* userSettings;
|
||||
ProcessList* pl;
|
||||
Header* header;
|
||||
char* filename;
|
||||
|
||||
MeterColumnSettings columns[2];
|
||||
|
||||
ProcessField* fields;
|
||||
int flags;
|
||||
int colorScheme;
|
||||
int delay;
|
||||
|
||||
int cpuCount;
|
||||
int direction;
|
||||
ProcessField sortKey;
|
||||
|
||||
bool countCPUsFromZero;
|
||||
bool detailedCPUTime;
|
||||
bool treeView;
|
||||
bool showProgramPath;
|
||||
bool hideThreads;
|
||||
bool shadowOtherUsers;
|
||||
bool showThreadNames;
|
||||
bool hideKernelThreads;
|
||||
bool hideUserlandThreads;
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool highlightThreads;
|
||||
bool updateProcessNames;
|
||||
bool accountGuestInCPUMeter;
|
||||
bool headerMargin;
|
||||
|
||||
bool changed;
|
||||
} Settings;
|
||||
|
||||
#ifndef Settings_cpuId
|
||||
#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromZero ? (cpu) : (cpu)+1)
|
||||
#endif
|
||||
|
||||
}*/
|
||||
|
||||
void Settings_delete(Settings* this) {
|
||||
free(this->userSettings);
|
||||
free(this->filename);
|
||||
free(this->fields);
|
||||
for (unsigned int i = 0; i < (sizeof(this->columns)/sizeof(MeterColumnSettings)); i++) {
|
||||
String_freeArray(this->columns[i].names);
|
||||
free(this->columns[i].modes);
|
||||
}
|
||||
free(this);
|
||||
}
|
||||
|
||||
static void Settings_readMeters(Settings* this, char* line, HeaderSide side) {
|
||||
static void Settings_readMeters(Settings* this, char* line, int column) {
|
||||
char* trim = String_trim(line);
|
||||
int nIds;
|
||||
char** ids = String_split(trim, ' ', &nIds);
|
||||
free(trim);
|
||||
for (int i = 0; ids[i]; i++) {
|
||||
Header_createMeter(this->header, ids[i], side);
|
||||
}
|
||||
String_freeArray(ids);
|
||||
this->columns[column].names = ids;
|
||||
}
|
||||
|
||||
static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side) {
|
||||
static void Settings_readMeterModes(Settings* this, char* line, int column) {
|
||||
char* trim = String_trim(line);
|
||||
int nIds;
|
||||
char** ids = String_split(trim, ' ', &nIds);
|
||||
free(trim);
|
||||
int len = 0;
|
||||
for (int i = 0; ids[i]; i++) {
|
||||
int mode = atoi(ids[i]);
|
||||
Header_setMode(this->header, i, mode, side);
|
||||
len++;
|
||||
}
|
||||
this->columns[column].len = len;
|
||||
int* modes = xCalloc(len, sizeof(int));
|
||||
for (int i = 0; i < len; i++) {
|
||||
modes[i] = atoi(ids[i]);
|
||||
}
|
||||
String_freeArray(ids);
|
||||
this->columns[column].modes = modes;
|
||||
}
|
||||
|
||||
static void Settings_defaultMeters(Settings* this) {
|
||||
int sizes[] = { 3, 3 };
|
||||
if (this->cpuCount > 4) {
|
||||
sizes[1]++;
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
this->columns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
|
||||
this->columns[i].modes = xCalloc(sizes[i], sizeof(int));
|
||||
this->columns[i].len = sizes[i];
|
||||
}
|
||||
|
||||
int r = 0;
|
||||
if (this->cpuCount > 8) {
|
||||
this->columns[0].names[0] = xStrdup("LeftCPUs2");
|
||||
this->columns[0].modes[0] = BAR_METERMODE;
|
||||
this->columns[1].names[r] = xStrdup("RightCPUs2");
|
||||
this->columns[1].modes[r++] = BAR_METERMODE;
|
||||
} else if (this->cpuCount > 4) {
|
||||
this->columns[0].names[0] = xStrdup("LeftCPUs");
|
||||
this->columns[0].modes[0] = BAR_METERMODE;
|
||||
this->columns[1].names[r] = xStrdup("RightCPUs");
|
||||
this->columns[1].modes[r++] = BAR_METERMODE;
|
||||
} else {
|
||||
this->columns[0].names[0] = xStrdup("AllCPUs");
|
||||
this->columns[0].modes[0] = BAR_METERMODE;
|
||||
}
|
||||
this->columns[0].names[1] = xStrdup("Memory");
|
||||
this->columns[0].modes[1] = BAR_METERMODE;
|
||||
this->columns[0].names[2] = xStrdup("Swap");
|
||||
this->columns[0].modes[2] = BAR_METERMODE;
|
||||
|
||||
this->columns[1].names[r] = xStrdup("Tasks");
|
||||
this->columns[1].modes[r++] = TEXT_METERMODE;
|
||||
this->columns[1].names[r] = xStrdup("LoadAverage");
|
||||
this->columns[1].modes[r++] = TEXT_METERMODE;
|
||||
this->columns[1].names[r] = xStrdup("Uptime");
|
||||
this->columns[1].modes[r++] = TEXT_METERMODE;
|
||||
}
|
||||
|
||||
static void readFields(ProcessField* fields, int* flags, const char* line) {
|
||||
char* trim = String_trim(line);
|
||||
int nIds;
|
||||
char** ids = String_split(trim, ' ', &nIds);
|
||||
free(trim);
|
||||
int i, j;
|
||||
*flags = 0;
|
||||
for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) {
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
int id = atoi(ids[i]) + 1;
|
||||
if (id > 0 && Process_fields[id].name && id < Platform_numberOfFields) {
|
||||
fields[j] = id;
|
||||
*flags |= Process_fields[id].flags;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
fields[j] = NULL_PROCESSFIELD;
|
||||
String_freeArray(ids);
|
||||
}
|
||||
|
||||
static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
|
||||
FILE* fd = fopen(fileName, "r");
|
||||
static bool Settings_read(Settings* this, const char* fileName) {
|
||||
FILE* fd;
|
||||
uid_t euid = geteuid();
|
||||
|
||||
(void) seteuid(getuid());
|
||||
fd = fopen(fileName, "r");
|
||||
(void) seteuid(euid);
|
||||
if (!fd)
|
||||
return false;
|
||||
|
||||
const int maxLine = 2048;
|
||||
char buffer[maxLine];
|
||||
bool readMeters = false;
|
||||
while (fgets(buffer, maxLine, fd)) {
|
||||
for (;;) {
|
||||
char* line = String_readLine(fd);
|
||||
if (!line) {
|
||||
break;
|
||||
}
|
||||
int nOptions;
|
||||
char** option = String_split(buffer, '=', &nOptions);
|
||||
char** option = String_split(line, '=', &nOptions);
|
||||
free (line);
|
||||
if (nOptions < 2) {
|
||||
String_freeArray(option);
|
||||
continue;
|
||||
}
|
||||
if (String_eq(option[0], "fields")) {
|
||||
char* trim = String_trim(option[1]);
|
||||
int nIds;
|
||||
char** ids = String_split(trim, ' ', &nIds);
|
||||
free(trim);
|
||||
int i, j;
|
||||
this->pl->flags = 0;
|
||||
for (j = 0, i = 0; i < LAST_PROCESSFIELD && ids[i]; i++) {
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
int id = atoi(ids[i]) + 1;
|
||||
if (id > 0 && id < LAST_PROCESSFIELD) {
|
||||
this->pl->fields[j] = id;
|
||||
this->pl->flags |= Process_fieldFlags[id];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
this->pl->fields[j] = (ProcessField) NULL;
|
||||
String_freeArray(ids);
|
||||
readFields(this->fields, &(this->flags), option[1]);
|
||||
} else if (String_eq(option[0], "sort_key")) {
|
||||
// This "+1" is for compatibility with the older enum format.
|
||||
this->pl->sortKey = atoi(option[1]) + 1;
|
||||
this->sortKey = atoi(option[1]) + 1;
|
||||
} else if (String_eq(option[0], "sort_direction")) {
|
||||
this->pl->direction = atoi(option[1]);
|
||||
this->direction = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view")) {
|
||||
this->pl->treeView = atoi(option[1]);
|
||||
this->treeView = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_threads")) {
|
||||
this->pl->hideThreads = atoi(option[1]);
|
||||
this->hideThreads = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
||||
this->pl->hideKernelThreads = atoi(option[1]);
|
||||
this->hideKernelThreads = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_userland_threads")) {
|
||||
this->pl->hideUserlandThreads = atoi(option[1]);
|
||||
this->hideUserlandThreads = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "shadow_other_users")) {
|
||||
this->pl->shadowOtherUsers = atoi(option[1]);
|
||||
this->shadowOtherUsers = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "show_thread_names")) {
|
||||
this->pl->showThreadNames = atoi(option[1]);
|
||||
this->showThreadNames = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "show_program_path")) {
|
||||
this->showProgramPath = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "highlight_base_name")) {
|
||||
this->pl->highlightBaseName = atoi(option[1]);
|
||||
this->highlightBaseName = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "highlight_megabytes")) {
|
||||
this->pl->highlightMegabytes = atoi(option[1]);
|
||||
this->highlightMegabytes = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "highlight_threads")) {
|
||||
this->pl->highlightThreads = atoi(option[1]);
|
||||
this->highlightThreads = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "header_margin")) {
|
||||
this->header->margin = atoi(option[1]);
|
||||
this->headerMargin = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "expand_system_time")) {
|
||||
// Compatibility option.
|
||||
this->pl->detailedCPUTime = atoi(option[1]);
|
||||
this->detailedCPUTime = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "detailed_cpu_time")) {
|
||||
this->pl->detailedCPUTime = atoi(option[1]);
|
||||
this->detailedCPUTime = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "cpu_count_from_zero")) {
|
||||
this->pl->countCPUsFromZero = atoi(option[1]);
|
||||
this->countCPUsFromZero = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "update_process_names")) {
|
||||
this->pl->updateProcessNames = atoi(option[1]);
|
||||
this->updateProcessNames = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "account_guest_in_cpu_meter")) {
|
||||
this->pl->accountGuestInCPUMeter = atoi(option[1]);
|
||||
this->accountGuestInCPUMeter = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "delay")) {
|
||||
this->delay = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "color_scheme")) {
|
||||
this->colorScheme = atoi(option[1]);
|
||||
if (this->colorScheme < 0) this->colorScheme = 0;
|
||||
if (this->colorScheme > 5) this->colorScheme = 5;
|
||||
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
||||
} else if (String_eq(option[0], "left_meters")) {
|
||||
Settings_readMeters(this, option[1], LEFT_HEADER);
|
||||
Settings_readMeters(this, option[1], 0);
|
||||
readMeters = true;
|
||||
} else if (String_eq(option[0], "right_meters")) {
|
||||
Settings_readMeters(this, option[1], RIGHT_HEADER);
|
||||
Settings_readMeters(this, option[1], 1);
|
||||
readMeters = true;
|
||||
} else if (String_eq(option[0], "left_meter_modes")) {
|
||||
Settings_readMeterModes(this, option[1], LEFT_HEADER);
|
||||
Settings_readMeterModes(this, option[1], 0);
|
||||
readMeters = true;
|
||||
} else if (String_eq(option[0], "right_meter_modes")) {
|
||||
Settings_readMeterModes(this, option[1], RIGHT_HEADER);
|
||||
Settings_readMeterModes(this, option[1], 1);
|
||||
readMeters = true;
|
||||
}
|
||||
String_freeArray(option);
|
||||
}
|
||||
fclose(fd);
|
||||
if (!readMeters) {
|
||||
Header_defaultMeters(this->header, cpuCount);
|
||||
Settings_defaultMeters(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
||||
fprintf(fd, "%s=", name);
|
||||
for (int i = 0; fields[i]; i++) {
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
fprintf(fd, "%d ", (int) fields[i]-1);
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
static void writeMeters(Settings* this, FILE* fd, int column) {
|
||||
for (int i = 0; i < this->columns[column].len; i++) {
|
||||
fprintf(fd, "%s ", this->columns[column].names[i]);
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
static void writeMeterModes(Settings* this, FILE* fd, int column) {
|
||||
for (int i = 0; i < this->columns[column].len; i++) {
|
||||
fprintf(fd, "%d ", this->columns[column].modes[i]);
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
bool Settings_write(Settings* this) {
|
||||
// TODO: implement File object and make
|
||||
// file I/O object-oriented.
|
||||
FILE* fd;
|
||||
fd = fopen(this->userSettings, "w");
|
||||
uid_t euid = geteuid();
|
||||
|
||||
(void) seteuid(getuid());
|
||||
fd = fopen(this->filename, "w");
|
||||
(void) seteuid(euid);
|
||||
if (fd == NULL) {
|
||||
return false;
|
||||
}
|
||||
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
||||
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
||||
fprintf(fd, "fields=");
|
||||
for (int i = 0; this->pl->fields[i]; i++) {
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
fprintf(fd, "%d ", (int) this->pl->fields[i]-1);
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
writeFields(fd, this->fields, "fields");
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
fprintf(fd, "sort_key=%d\n", (int) this->pl->sortKey-1);
|
||||
fprintf(fd, "sort_direction=%d\n", (int) this->pl->direction);
|
||||
fprintf(fd, "hide_threads=%d\n", (int) this->pl->hideThreads);
|
||||
fprintf(fd, "hide_kernel_threads=%d\n", (int) this->pl->hideKernelThreads);
|
||||
fprintf(fd, "hide_userland_threads=%d\n", (int) this->pl->hideUserlandThreads);
|
||||
fprintf(fd, "shadow_other_users=%d\n", (int) this->pl->shadowOtherUsers);
|
||||
fprintf(fd, "show_thread_names=%d\n", (int) this->pl->showThreadNames);
|
||||
fprintf(fd, "highlight_base_name=%d\n", (int) this->pl->highlightBaseName);
|
||||
fprintf(fd, "highlight_megabytes=%d\n", (int) this->pl->highlightMegabytes);
|
||||
fprintf(fd, "highlight_threads=%d\n", (int) this->pl->highlightThreads);
|
||||
fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView);
|
||||
fprintf(fd, "header_margin=%d\n", (int) this->header->margin);
|
||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime);
|
||||
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->pl->countCPUsFromZero);
|
||||
fprintf(fd, "update_process_names=%d\n", (int) this->pl->updateProcessNames);
|
||||
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->pl->accountGuestInCPUMeter);
|
||||
fprintf(fd, "sort_key=%d\n", (int) this->sortKey-1);
|
||||
fprintf(fd, "sort_direction=%d\n", (int) this->direction);
|
||||
fprintf(fd, "hide_threads=%d\n", (int) this->hideThreads);
|
||||
fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads);
|
||||
fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads);
|
||||
fprintf(fd, "shadow_other_users=%d\n", (int) this->shadowOtherUsers);
|
||||
fprintf(fd, "show_thread_names=%d\n", (int) this->showThreadNames);
|
||||
fprintf(fd, "show_program_path=%d\n", (int) this->showProgramPath);
|
||||
fprintf(fd, "highlight_base_name=%d\n", (int) this->highlightBaseName);
|
||||
fprintf(fd, "highlight_megabytes=%d\n", (int) this->highlightMegabytes);
|
||||
fprintf(fd, "highlight_threads=%d\n", (int) this->highlightThreads);
|
||||
fprintf(fd, "tree_view=%d\n", (int) this->treeView);
|
||||
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
||||
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->countCPUsFromZero);
|
||||
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames);
|
||||
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter);
|
||||
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
|
||||
fprintf(fd, "delay=%d\n", (int) this->delay);
|
||||
fprintf(fd, "left_meters=");
|
||||
for (int i = 0; i < Header_size(this->header, LEFT_HEADER); i++) {
|
||||
char* name = Header_readMeterName(this->header, i, LEFT_HEADER);
|
||||
fprintf(fd, "%s ", name);
|
||||
free(name);
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
fprintf(fd, "left_meter_modes=");
|
||||
for (int i = 0; i < Header_size(this->header, LEFT_HEADER); i++)
|
||||
fprintf(fd, "%d ", Header_readMeterMode(this->header, i, LEFT_HEADER));
|
||||
fprintf(fd, "\n");
|
||||
fprintf(fd, "right_meters=");
|
||||
for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++) {
|
||||
char* name = Header_readMeterName(this->header, i, RIGHT_HEADER);
|
||||
fprintf(fd, "%s ", name);
|
||||
free(name);
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
fprintf(fd, "right_meter_modes=");
|
||||
for (int i = 0; i < Header_size(this->header, RIGHT_HEADER); i++)
|
||||
fprintf(fd, "%d ", Header_readMeterMode(this->header, i, RIGHT_HEADER));
|
||||
fprintf(fd, "\n");
|
||||
fprintf(fd, "left_meters="); writeMeters(this, fd, 0);
|
||||
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
||||
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
||||
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
|
||||
Settings* this = malloc(sizeof(Settings));
|
||||
this->pl = pl;
|
||||
this->header = header;
|
||||
Settings* Settings_new(int cpuCount) {
|
||||
|
||||
Settings* this = xCalloc(1, sizeof(Settings));
|
||||
|
||||
this->sortKey = PERCENT_CPU;
|
||||
this->direction = 1;
|
||||
this->hideThreads = false;
|
||||
this->shadowOtherUsers = false;
|
||||
this->showThreadNames = false;
|
||||
this->hideKernelThreads = false;
|
||||
this->hideUserlandThreads = false;
|
||||
this->treeView = false;
|
||||
this->highlightBaseName = false;
|
||||
this->highlightMegabytes = false;
|
||||
this->detailedCPUTime = false;
|
||||
this->countCPUsFromZero = false;
|
||||
this->updateProcessNames = false;
|
||||
this->cpuCount = cpuCount;
|
||||
this->showProgramPath = true;
|
||||
this->highlightThreads = true;
|
||||
|
||||
this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
||||
// TODO: turn 'fields' into a Vector,
|
||||
// (and ProcessFields into proper objects).
|
||||
this->flags = 0;
|
||||
ProcessField* defaults = Platform_defaultFields;
|
||||
for (int i = 0; defaults[i]; i++) {
|
||||
this->fields[i] = defaults[i];
|
||||
this->flags |= Process_fields[defaults[i]].flags;
|
||||
}
|
||||
|
||||
char* legacyDotfile = NULL;
|
||||
char* rcfile = getenv("HTOPRC");
|
||||
if (rcfile) {
|
||||
this->userSettings = strdup(rcfile);
|
||||
this->filename = xStrdup(rcfile);
|
||||
} else {
|
||||
const char* home = getenv("HOME");
|
||||
if (!home) home = "";
|
||||
@ -234,15 +359,17 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
|
||||
char* configDir = NULL;
|
||||
char* htopDir = NULL;
|
||||
if (xdgConfigHome) {
|
||||
this->userSettings = String_cat(xdgConfigHome, "/htop/htoprc");
|
||||
configDir = strdup(xdgConfigHome);
|
||||
this->filename = String_cat(xdgConfigHome, "/htop/htoprc");
|
||||
configDir = xStrdup(xdgConfigHome);
|
||||
htopDir = String_cat(xdgConfigHome, "/htop");
|
||||
} else {
|
||||
this->userSettings = String_cat(home, "/.config/htop/htoprc");
|
||||
this->filename = String_cat(home, "/.config/htop/htoprc");
|
||||
configDir = String_cat(home, "/.config");
|
||||
htopDir = String_cat(home, "/.config/htop");
|
||||
}
|
||||
legacyDotfile = String_cat(home, "/.htoprc");
|
||||
uid_t euid = geteuid();
|
||||
(void) seteuid(getuid());
|
||||
(void) mkdir(configDir, 0700);
|
||||
(void) mkdir(htopDir, 0700);
|
||||
free(htopDir);
|
||||
@ -255,11 +382,12 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
|
||||
free(legacyDotfile);
|
||||
legacyDotfile = NULL;
|
||||
}
|
||||
(void) seteuid(euid);
|
||||
}
|
||||
this->colorScheme = 0;
|
||||
this->changed = false;
|
||||
this->delay = DEFAULT_DELAY;
|
||||
bool ok = Settings_read(this, legacyDotfile ? legacyDotfile : this->userSettings, cpuCount);
|
||||
bool ok = Settings_read(this, legacyDotfile ? legacyDotfile : this->filename);
|
||||
if (ok) {
|
||||
if (legacyDotfile) {
|
||||
// Transition to new location and delete old configuration file
|
||||
@ -270,15 +398,23 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
|
||||
this->changed = true;
|
||||
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
||||
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
||||
ok = Settings_read(this, systemSettings, cpuCount);
|
||||
ok = Settings_read(this, systemSettings);
|
||||
free(systemSettings);
|
||||
if (!ok) {
|
||||
Header_defaultMeters(this->header, cpuCount);
|
||||
pl->hideKernelThreads = true;
|
||||
pl->highlightMegabytes = true;
|
||||
pl->highlightThreads = false;
|
||||
Settings_defaultMeters(this);
|
||||
this->hideKernelThreads = true;
|
||||
this->highlightMegabytes = true;
|
||||
this->highlightThreads = true;
|
||||
this->headerMargin = true;
|
||||
}
|
||||
}
|
||||
free(legacyDotfile);
|
||||
return this;
|
||||
}
|
||||
|
||||
void Settings_invertSortOrder(Settings* this) {
|
||||
if (this->direction == 1)
|
||||
this->direction = -1;
|
||||
else
|
||||
this->direction = 1;
|
||||
}
|
||||
|
47
Settings.h
47
Settings.h
@ -11,24 +11,59 @@ in the source distribution for its full text.
|
||||
|
||||
#define DEFAULT_DELAY 15
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "Header.h"
|
||||
#include "Process.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
int len;
|
||||
char** names;
|
||||
int* modes;
|
||||
} MeterColumnSettings;
|
||||
|
||||
typedef struct Settings_ {
|
||||
char* userSettings;
|
||||
ProcessList* pl;
|
||||
Header* header;
|
||||
char* filename;
|
||||
|
||||
MeterColumnSettings columns[2];
|
||||
|
||||
ProcessField* fields;
|
||||
int flags;
|
||||
int colorScheme;
|
||||
int delay;
|
||||
|
||||
int cpuCount;
|
||||
int direction;
|
||||
ProcessField sortKey;
|
||||
|
||||
bool countCPUsFromZero;
|
||||
bool detailedCPUTime;
|
||||
bool treeView;
|
||||
bool showProgramPath;
|
||||
bool hideThreads;
|
||||
bool shadowOtherUsers;
|
||||
bool showThreadNames;
|
||||
bool hideKernelThreads;
|
||||
bool hideUserlandThreads;
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool highlightThreads;
|
||||
bool updateProcessNames;
|
||||
bool accountGuestInCPUMeter;
|
||||
bool headerMargin;
|
||||
|
||||
bool changed;
|
||||
} Settings;
|
||||
|
||||
#ifndef Settings_cpuId
|
||||
#define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromZero ? (cpu) : (cpu)+1)
|
||||
#endif
|
||||
|
||||
|
||||
void Settings_delete(Settings* this);
|
||||
|
||||
bool Settings_write(Settings* this);
|
||||
|
||||
Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount);
|
||||
Settings* Settings_new(int cpuCount);
|
||||
|
||||
void Settings_invertSortOrder(Settings* this);
|
||||
|
||||
#endif
|
||||
|
@ -7,12 +7,14 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Panel.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include "ListItem.h"
|
||||
#include "RichString.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
@ -25,48 +27,18 @@ typedef struct SignalItem_ {
|
||||
|
||||
}*/
|
||||
|
||||
static SignalItem signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
{ .name = " 3 SIGQUIT", .number = 3 },
|
||||
{ .name = " 4 SIGILL", .number = 4 },
|
||||
{ .name = " 5 SIGTRAP", .number = 5 },
|
||||
{ .name = " 6 SIGABRT", .number = 6 },
|
||||
{ .name = " 6 SIGIOT", .number = 6 },
|
||||
{ .name = " 7 SIGBUS", .number = 7 },
|
||||
{ .name = " 8 SIGFPE", .number = 8 },
|
||||
{ .name = " 9 SIGKILL", .number = 9 },
|
||||
{ .name = "10 SIGUSR1", .number = 10 },
|
||||
{ .name = "11 SIGSEGV", .number = 11 },
|
||||
{ .name = "12 SIGUSR2", .number = 12 },
|
||||
{ .name = "13 SIGPIPE", .number = 13 },
|
||||
{ .name = "14 SIGALRM", .number = 14 },
|
||||
{ .name = "15 SIGTERM", .number = 15 },
|
||||
{ .name = "16 SIGSTKFLT", .number = 16 },
|
||||
{ .name = "17 SIGCHLD", .number = 17 },
|
||||
{ .name = "18 SIGCONT", .number = 18 },
|
||||
{ .name = "19 SIGSTOP", .number = 19 },
|
||||
{ .name = "20 SIGTSTP", .number = 20 },
|
||||
{ .name = "21 SIGTTIN", .number = 21 },
|
||||
{ .name = "22 SIGTTOU", .number = 22 },
|
||||
{ .name = "23 SIGURG", .number = 23 },
|
||||
{ .name = "24 SIGXCPU", .number = 24 },
|
||||
{ .name = "25 SIGXFSZ", .number = 25 },
|
||||
{ .name = "26 SIGVTALRM", .number = 26 },
|
||||
{ .name = "27 SIGPROF", .number = 27 },
|
||||
{ .name = "28 SIGWINCH", .number = 28 },
|
||||
{ .name = "29 SIGIO", .number = 29 },
|
||||
{ .name = "29 SIGPOLL", .number = 29 },
|
||||
{ .name = "30 SIGPWR", .number = 30 },
|
||||
{ .name = "31 SIGSYS", .number = 31 },
|
||||
};
|
||||
|
||||
Panel* SignalsPanel_new() {
|
||||
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem));
|
||||
for(unsigned int i = 0; i < sizeof(signals)/sizeof(SignalItem); i++)
|
||||
Panel_set(this, i, (Object*) ListItem_new(signals[i].name, signals[i].number));
|
||||
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel "));
|
||||
const int defaultSignal = SIGTERM;
|
||||
int defaultPosition = 15;
|
||||
for(unsigned int 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) {
|
||||
defaultPosition = i;
|
||||
}
|
||||
}
|
||||
Panel_setHeader(this, "Send signal:");
|
||||
Panel_setSelected(this, 16); // 16th item is SIGTERM
|
||||
Panel_setSelected(this, defaultPosition);
|
||||
return this;
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
/*
|
||||
htop - String.c
|
||||
htop - StringUtils.c
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*{
|
||||
#include <stdio.h>
|
||||
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||
}*/
|
||||
@ -22,7 +24,7 @@ in the source distribution for its full text.
|
||||
char* String_cat(const char* s1, const char* s2) {
|
||||
int l1 = strlen(s1);
|
||||
int l2 = strlen(s2);
|
||||
char* out = malloc(l1 + l2 + 1);
|
||||
char* out = xMalloc(l1 + l2 + 1);
|
||||
strncpy(out, s1, l1);
|
||||
strncpy(out+l1, s2, l2+1);
|
||||
return out;
|
||||
@ -36,7 +38,7 @@ char* String_trim(const char* in) {
|
||||
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
|
||||
len--;
|
||||
}
|
||||
char* out = malloc(len+1);
|
||||
char* out = xMalloc(len+1);
|
||||
strncpy(out, in, len);
|
||||
out[len] = '\0';
|
||||
return out;
|
||||
@ -55,40 +57,31 @@ inline int String_eq(const char* s1, const char* s2) {
|
||||
char** String_split(const char* s, char sep, int* n) {
|
||||
*n = 0;
|
||||
const int rate = 10;
|
||||
char** out = (char**) malloc(sizeof(char*) * rate);
|
||||
char** out = xCalloc(rate, sizeof(char*));
|
||||
int ctr = 0;
|
||||
int blocks = rate;
|
||||
char* where;
|
||||
while ((where = strchr(s, sep)) != NULL) {
|
||||
int size = where - s;
|
||||
char* token = (char*) malloc(size + 1);
|
||||
char* token = xMalloc(size + 1);
|
||||
strncpy(token, s, size);
|
||||
token[size] = '\0';
|
||||
out[ctr] = token;
|
||||
ctr++;
|
||||
if (ctr == blocks) {
|
||||
blocks += rate;
|
||||
char** newOut = (char**) realloc(out, sizeof(char*) * blocks);
|
||||
if (newOut) {
|
||||
out = newOut;
|
||||
} else {
|
||||
blocks -= rate;
|
||||
break;
|
||||
}
|
||||
out = (char**) xRealloc(out, sizeof(char*) * blocks);
|
||||
}
|
||||
s += size + 1;
|
||||
}
|
||||
if (s[0] != '\0') {
|
||||
int size = strlen(s);
|
||||
char* token = (char*) malloc(size + 1);
|
||||
char* token = xMalloc(size + 1);
|
||||
strncpy(token, s, size + 1);
|
||||
out[ctr] = token;
|
||||
ctr++;
|
||||
}
|
||||
char** newOut = realloc(out, sizeof(char*) * (ctr + 1));
|
||||
if (newOut) {
|
||||
out = newOut;
|
||||
}
|
||||
out = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||
out[ctr] = NULL;
|
||||
*n = ctr;
|
||||
return out;
|
||||
@ -125,5 +118,31 @@ char* String_getToken(const char* line, const unsigned short int numMatch) {
|
||||
}
|
||||
|
||||
match[foundCount] = '\0';
|
||||
return((char*)strdup(match));
|
||||
return((char*)xStrdup(match));
|
||||
}
|
||||
|
||||
char* String_readLine(FILE* fd) {
|
||||
const int step = 1024;
|
||||
int bufSize = step;
|
||||
char* buffer = xMalloc(step + 1);
|
||||
char* at = buffer;
|
||||
for (;;) {
|
||||
char* ok = fgets(at, step + 1, fd);
|
||||
if (!ok) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
char* newLine = strrchr(at, '\n');
|
||||
if (newLine) {
|
||||
*newLine = '\0';
|
||||
return buffer;
|
||||
} else {
|
||||
if (feof(fd)) {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
bufSize += step;
|
||||
buffer = xRealloc(buffer, bufSize + 1);
|
||||
at = buffer + bufSize - step;
|
||||
}
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_String
|
||||
#define HEADER_String
|
||||
#ifndef HEADER_StringUtils
|
||||
#define HEADER_StringUtils
|
||||
/*
|
||||
htop - String.h
|
||||
htop - StringUtils.h
|
||||
(C) 2004-2011 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||
|
||||
@ -24,4 +26,6 @@ void String_freeArray(char** s);
|
||||
|
||||
char* String_getToken(const char* line, const unsigned short int numMatch);
|
||||
|
||||
char* String_readLine(FILE* fd);
|
||||
|
||||
#endif
|
37
SwapMeter.c
37
SwapMeter.c
@ -8,7 +8,7 @@ in the source distribution for its full text.
|
||||
#include "SwapMeter.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "ProcessList.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -20,37 +20,31 @@ in the source distribution for its full text.
|
||||
#include "Meter.h"
|
||||
}*/
|
||||
|
||||
#define KILOBYTE 1
|
||||
#define MEGABYTE 1024
|
||||
#define GIGABYTE 1048576
|
||||
|
||||
int SwapMeter_attributes[] = {
|
||||
SWAP
|
||||
};
|
||||
|
||||
/* NOTE: Value is in kilobytes */
|
||||
static void SwapMeter_humanNumber(char* buffer, const long int* value) {
|
||||
sprintf(buffer, "%ldM ", *value / MEGABYTE);
|
||||
}
|
||||
static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int written;
|
||||
Platform_setSwapValues(this);
|
||||
|
||||
static void SwapMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
long int usedSwap = this->pl->usedSwap;
|
||||
this->total = this->pl->totalSwap;
|
||||
this->values[0] = usedSwap;
|
||||
|
||||
snprintf(buffer, len, "%ld/%ldMB", (long int) usedSwap / MEGABYTE, (long int) this->total / MEGABYTE);
|
||||
written = Meter_humanUnit(buffer, this->values[0], size);
|
||||
buffer += written;
|
||||
if ((size -= written) > 0) {
|
||||
*buffer++ = '/';
|
||||
size--;
|
||||
Meter_humanUnit(buffer, this->total, size);
|
||||
}
|
||||
}
|
||||
|
||||
static void SwapMeter_display(Object* cast, RichString* out) {
|
||||
char buffer[50];
|
||||
Meter* this = (Meter*)cast;
|
||||
long int swap = (long int) this->values[0];
|
||||
long int total = (long int) this->total;
|
||||
RichString_write(out, CRT_colors[METER_TEXT], ":");
|
||||
SwapMeter_humanNumber(buffer, &total);
|
||||
Meter_humanUnit(buffer, this->total, 50);
|
||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||
SwapMeter_humanNumber(buffer, &swap);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "used:");
|
||||
Meter_humanUnit(buffer, this->values[0], 50);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " used:");
|
||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||
}
|
||||
|
||||
@ -60,8 +54,9 @@ MeterClass SwapMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = SwapMeter_display,
|
||||
},
|
||||
.setValues = SwapMeter_setValues,
|
||||
.updateValues = SwapMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = SwapMeter_attributes,
|
||||
.name = "Swap",
|
||||
|
@ -11,13 +11,8 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Meter.h"
|
||||
|
||||
#define KILOBYTE 1
|
||||
#define MEGABYTE 1024
|
||||
#define GIGABYTE 1048576
|
||||
|
||||
extern int SwapMeter_attributes[];
|
||||
|
||||
/* NOTE: Value is in kilobytes */
|
||||
extern MeterClass SwapMeter_class;
|
||||
|
||||
#endif
|
||||
|
155
TESTPLAN
Normal file
155
TESTPLAN
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
Main screen:
|
||||
|
||||
For all views, all modes:
|
||||
|
||||
Mouse click header - nothing happens.
|
||||
|
||||
Mouse click on ProcessList title bar - exit Tree view, update FunctionBar, title bar updates, sort by clicked field.
|
||||
*** FAILING: wrong FB update depending on mode; does not change sort in wip branch
|
||||
click on same entry - invert sort.
|
||||
click on another entry - sort another field.
|
||||
|
||||
Mouse click on a process - select that process.
|
||||
|
||||
for each entry in FunctionBar:
|
||||
Mouse click entry - perform action of associated key.
|
||||
|
||||
In Normal mode, Sorted view:
|
||||
|
||||
<+> or <-> - do nothing.
|
||||
|
||||
<F6> - enter SortBy screen.
|
||||
|
||||
In Normal mode, Tree view:
|
||||
|
||||
select process - update F6 in FunctionBar if subtree is collapsed or expanded.
|
||||
|
||||
<F6>, <+> or <-> - expand/collapse subtree.
|
||||
|
||||
In Normal mode, either Sorted or Tree view:
|
||||
|
||||
<F3>, </> - activate Search mode.
|
||||
|
||||
<F4>, <\> - activate Filter mode.
|
||||
|
||||
<F7>, <]> - as root only, decrease process NICE value.
|
||||
|
||||
<F8>, <[> - increase process NICE value.
|
||||
|
||||
<a> - enter Affinity screen.
|
||||
|
||||
<b> - do nothing.
|
||||
|
||||
<c> - select process and all its children.
|
||||
|
||||
<d>, <e>, <f>, <g> - do nothing.
|
||||
|
||||
<F1>, <h>, <?> - enter Help screen.
|
||||
|
||||
<i> - on Linux, enter IOPriority screen.
|
||||
|
||||
<j> - do nothing.
|
||||
|
||||
<F9>, <k> - enter Kill screen.
|
||||
|
||||
<l> - enter LSOF screen.
|
||||
|
||||
<m>, <n>, <o>, <p> - do nothing.
|
||||
|
||||
<F10>, <q> - quit program.
|
||||
|
||||
<r> - do nothing.
|
||||
|
||||
<s> - enter STrace screen.
|
||||
|
||||
<F5>, <t> - toggle between Tree and Sorted view, update F5 in FunctionBar, follow process
|
||||
|
||||
<u> - enter User screen.
|
||||
|
||||
<v>, <w>, <x>, <y>, <z> - do nothing.
|
||||
|
||||
<A>, <B> - do nothing.
|
||||
|
||||
<F2>, <C>, <S> - enter Setup screen.
|
||||
|
||||
<D>, <E> - do nothing.
|
||||
|
||||
<F> - follow process.
|
||||
|
||||
<G> - do nothing.
|
||||
|
||||
<H> - toggle show/hide userland threads.
|
||||
|
||||
<I> - invert sort order.
|
||||
|
||||
<J> - do nothing.
|
||||
|
||||
<K> - toggle show/hide kernel threads.
|
||||
|
||||
<L> - do nothing.
|
||||
|
||||
<M> - enter Sorted view, update function bar, sort by MEM%.
|
||||
|
||||
<N>, <O> - do nothing.
|
||||
|
||||
<P> - enter Sorted view, update function bar, sort by CPU%.
|
||||
|
||||
<Q>, <R> - do nothing.
|
||||
|
||||
<T> - enter Sorted view, update function bar, sort by TIME.
|
||||
|
||||
<U> - untag all processes.
|
||||
|
||||
<V>, <W>, <X>, <Y>, <Z> - do nothing.
|
||||
|
||||
<<>, <>>, <,>, <.> - enter SortBy screen.
|
||||
|
||||
space - tag current process, move down cursor.
|
||||
|
||||
numbers - incremental PID search.
|
||||
|
||||
In Search mode:
|
||||
|
||||
TODO
|
||||
|
||||
In Filter mode:
|
||||
|
||||
TODO
|
||||
|
||||
Setup screen:
|
||||
|
||||
TODO
|
||||
|
||||
SortBy screen:
|
||||
|
||||
TODO
|
||||
|
||||
User screen:
|
||||
|
||||
TODO
|
||||
|
||||
Kill screen:
|
||||
|
||||
TODO
|
||||
|
||||
Affinity screen:
|
||||
|
||||
TODO
|
||||
|
||||
Help screen:
|
||||
|
||||
any key - back to Main screen.
|
||||
|
||||
IOPriority screen:
|
||||
|
||||
TODO
|
||||
|
||||
STrace screen:
|
||||
|
||||
TODO
|
||||
|
||||
LSOF screen:
|
||||
|
||||
TODO
|
||||
|
42
TasksMeter.c
42
TasksMeter.c
@ -7,7 +7,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include "TasksMeter.h"
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "Platform.h"
|
||||
#include "CRT.h"
|
||||
|
||||
/*{
|
||||
@ -15,42 +15,53 @@ in the source distribution for its full text.
|
||||
}*/
|
||||
|
||||
int TasksMeter_attributes[] = {
|
||||
TASKS_RUNNING
|
||||
CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING
|
||||
};
|
||||
|
||||
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||
ProcessList* pl = this->pl;
|
||||
this->total = pl->totalTasks;
|
||||
this->values[0] = pl->runningTasks;
|
||||
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
|
||||
this->values[0] = pl->kernelThreads;
|
||||
this->values[1] = pl->userlandThreads;
|
||||
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
|
||||
this->values[3] = pl->runningTasks;
|
||||
if (pl->totalTasks > this->total) {
|
||||
this->total = pl->totalTasks;
|
||||
}
|
||||
if (this->pl->settings->hideKernelThreads) {
|
||||
this->values[0] = 0;
|
||||
}
|
||||
snprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
||||
}
|
||||
|
||||
static void TasksMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
ProcessList* pl = this->pl;
|
||||
Settings* settings = this->pl->settings;
|
||||
char buffer[20];
|
||||
sprintf(buffer, "%d", (int)(this->total - pl->userlandThreads - pl->kernelThreads));
|
||||
|
||||
int processes = (int) this->values[2];
|
||||
|
||||
sprintf(buffer, "%d", processes);
|
||||
RichString_write(out, CRT_colors[METER_VALUE], buffer);
|
||||
int threadValueColor = CRT_colors[METER_VALUE];
|
||||
int threadCaptionColor = CRT_colors[METER_TEXT];
|
||||
if (pl->highlightThreads) {
|
||||
if (settings->highlightThreads) {
|
||||
threadValueColor = CRT_colors[PROCESS_THREAD_BASENAME];
|
||||
threadCaptionColor = CRT_colors[PROCESS_THREAD];
|
||||
}
|
||||
if (!pl->hideUserlandThreads) {
|
||||
if (!settings->hideUserlandThreads) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
||||
sprintf(buffer, "%d", (int)pl->userlandThreads);
|
||||
sprintf(buffer, "%d", (int)this->values[1]);
|
||||
RichString_append(out, threadValueColor, buffer);
|
||||
RichString_append(out, threadCaptionColor, " thr");
|
||||
}
|
||||
if (!pl->hideKernelThreads) {
|
||||
if (!settings->hideKernelThreads) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
||||
sprintf(buffer, "%d", (int)pl->kernelThreads);
|
||||
sprintf(buffer, "%d", (int)this->values[0]);
|
||||
RichString_append(out, threadValueColor, buffer);
|
||||
RichString_append(out, threadCaptionColor, " kthr");
|
||||
}
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "; ");
|
||||
sprintf(buffer, "%d", (int)this->values[0]);
|
||||
sprintf(buffer, "%d", (int)this->values[3]);
|
||||
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
||||
}
|
||||
@ -61,8 +72,9 @@ MeterClass TasksMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = TasksMeter_display,
|
||||
},
|
||||
.setValues = TasksMeter_setValues,
|
||||
.updateValues = TasksMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 4,
|
||||
.total = 100.0,
|
||||
.attributes = TasksMeter_attributes,
|
||||
.name = "Tasks",
|
||||
|
267
TraceScreen.c
267
TraceScreen.c
@ -8,10 +8,12 @@ in the source distribution for its full text.
|
||||
#include "TraceScreen.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "InfoScreen.h"
|
||||
#include "ProcessList.h"
|
||||
#include "ListItem.h"
|
||||
#include "IncSet.h"
|
||||
#include "String.h"
|
||||
#include "StringUtils.h"
|
||||
#include "FunctionBar.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -25,205 +27,146 @@ in the source distribution for its full text.
|
||||
#include <signal.h>
|
||||
|
||||
/*{
|
||||
#include "Process.h"
|
||||
#include "Panel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "InfoScreen.h"
|
||||
|
||||
typedef struct TraceScreen_ {
|
||||
Process* process;
|
||||
Panel* display;
|
||||
InfoScreen super;
|
||||
bool tracing;
|
||||
int fdpair[2];
|
||||
int child;
|
||||
FILE* strace;
|
||||
int fd_strace;
|
||||
bool contLine;
|
||||
bool follow;
|
||||
} TraceScreen;
|
||||
|
||||
}*/
|
||||
|
||||
static const char* tsFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
|
||||
static const char* TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
|
||||
|
||||
static const char* tsKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
||||
static const char* TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
||||
|
||||
static int tsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
||||
static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
||||
|
||||
InfoScreenClass TraceScreen_class = {
|
||||
.super = {
|
||||
.extends = Class(Object),
|
||||
.delete = TraceScreen_delete
|
||||
},
|
||||
.draw = TraceScreen_draw,
|
||||
.onErr = TraceScreen_updateTrace,
|
||||
.onKey = TraceScreen_onKey,
|
||||
};
|
||||
|
||||
TraceScreen* TraceScreen_new(Process* process) {
|
||||
TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen));
|
||||
this->process = process;
|
||||
this->display = Panel_new(0, 1, COLS, LINES-2, false, Class(ListItem));
|
||||
TraceScreen* this = xMalloc(sizeof(TraceScreen));
|
||||
Object_setClass(this, Class(TraceScreen));
|
||||
this->tracing = true;
|
||||
return this;
|
||||
this->contLine = false;
|
||||
this->follow = false;
|
||||
FunctionBar* fuBar = FunctionBar_new(TraceScreenFunctions, TraceScreenKeys, TraceScreenEvents);
|
||||
CRT_disableDelay();
|
||||
return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES-2, "");
|
||||
}
|
||||
|
||||
void TraceScreen_delete(TraceScreen* this) {
|
||||
Panel_delete((Object*)this->display);
|
||||
free(this);
|
||||
void TraceScreen_delete(Object* cast) {
|
||||
TraceScreen* this = (TraceScreen*) cast;
|
||||
if (this->child > 0) {
|
||||
kill(this->child, SIGTERM);
|
||||
waitpid(this->child, NULL, 0);
|
||||
fclose(this->strace);
|
||||
}
|
||||
CRT_enableDelay();
|
||||
free(InfoScreen_done((InfoScreen*)cast));
|
||||
}
|
||||
|
||||
static void TraceScreen_draw(TraceScreen* this, IncSet* inc) {
|
||||
void TraceScreen_draw(InfoScreen* this) {
|
||||
attrset(CRT_colors[PANEL_HEADER_FOCUS]);
|
||||
mvhline(0, 0, ' ', COLS);
|
||||
mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm);
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
IncSet_drawBar(inc);
|
||||
IncSet_drawBar(this->inc);
|
||||
}
|
||||
|
||||
static inline void addLine(const char* line, Vector* lines, Panel* panel, const char* incFilter) {
|
||||
Vector_add(lines, (Object*) ListItem_new(line, 0));
|
||||
if (!incFilter || String_contains_i(line, incFilter))
|
||||
Panel_add(panel, (Object*)Vector_get(lines, Vector_size(lines)-1));
|
||||
}
|
||||
|
||||
static inline void appendLine(const char* line, Vector* lines, Panel* panel, const char* incFilter) {
|
||||
ListItem* last = (ListItem*)Vector_get(lines, Vector_size(lines)-1);
|
||||
ListItem_append(last, line);
|
||||
if (incFilter && Panel_get(panel, Panel_size(panel)-1) != (Object*)last && String_contains_i(line, incFilter))
|
||||
Panel_add(panel, (Object*)last);
|
||||
}
|
||||
|
||||
void TraceScreen_run(TraceScreen* this) {
|
||||
// if (this->process->pid == getpid()) return;
|
||||
bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||
char buffer[1001];
|
||||
int fdpair[2];
|
||||
int err = pipe(fdpair);
|
||||
if (err == -1) return;
|
||||
int child = fork();
|
||||
if (child == -1) return;
|
||||
if (child == 0) {
|
||||
dup2(fdpair[1], STDERR_FILENO);
|
||||
int ok = fcntl(fdpair[1], F_SETFL, O_NONBLOCK);
|
||||
int err = pipe(this->fdpair);
|
||||
if (err == -1) return false;
|
||||
this->child = fork();
|
||||
if (this->child == -1) return false;
|
||||
if (this->child == 0) {
|
||||
(void) seteuid(getuid());
|
||||
dup2(this->fdpair[1], STDERR_FILENO);
|
||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||
if (ok != -1) {
|
||||
sprintf(buffer, "%d", this->process->pid);
|
||||
sprintf(buffer, "%d", this->super.process->pid);
|
||||
execlp("strace", "strace", "-p", buffer, NULL);
|
||||
}
|
||||
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
||||
write(fdpair[1], message, strlen(message));
|
||||
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
||||
(void) written;
|
||||
exit(1);
|
||||
}
|
||||
fcntl(fdpair[0], F_SETFL, O_NONBLOCK);
|
||||
FILE* strace = fdopen(fdpair[0], "r");
|
||||
Panel* panel = this->display;
|
||||
int fd_strace = fileno(strace);
|
||||
CRT_disableDelay();
|
||||
bool contLine = false;
|
||||
bool follow = false;
|
||||
bool looping = true;
|
||||
fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
||||
this->strace = fdopen(this->fdpair[0], "r");
|
||||
this->fd_strace = fileno(this->strace);
|
||||
return true;
|
||||
}
|
||||
|
||||
FunctionBar* bar = FunctionBar_new(tsFunctions, tsKeys, tsEvents);
|
||||
IncSet* inc = IncSet_new(bar);
|
||||
|
||||
Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE);
|
||||
|
||||
TraceScreen_draw(this, inc);
|
||||
|
||||
while (looping) {
|
||||
|
||||
Panel_draw(panel, true);
|
||||
const char* incFilter = IncSet_filter(inc);
|
||||
|
||||
if (inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
int ch = getch();
|
||||
|
||||
if (ch == ERR) {
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
// FD_SET(STDIN_FILENO, &fds);
|
||||
FD_SET(fd_strace, &fds);
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0; tv.tv_usec = 500;
|
||||
int ready = select(fd_strace+1, &fds, NULL, NULL, &tv);
|
||||
int nread = 0;
|
||||
if (ready > 0 && FD_ISSET(fd_strace, &fds))
|
||||
nread = fread(buffer, 1, 1000, strace);
|
||||
if (nread && this->tracing) {
|
||||
char* line = buffer;
|
||||
buffer[nread] = '\0';
|
||||
for (int i = 0; i < nread; i++) {
|
||||
if (buffer[i] == '\n') {
|
||||
buffer[i] = '\0';
|
||||
if (contLine) {
|
||||
appendLine(line, lines, panel, incFilter);
|
||||
contLine = false;
|
||||
} else {
|
||||
addLine(line, lines, panel, incFilter);
|
||||
}
|
||||
line = buffer+i+1;
|
||||
}
|
||||
void TraceScreen_updateTrace(InfoScreen* super) {
|
||||
TraceScreen* this = (TraceScreen*) super;
|
||||
char buffer[1001];
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
// FD_SET(STDIN_FILENO, &fds);
|
||||
FD_SET(this->fd_strace, &fds);
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0; tv.tv_usec = 500;
|
||||
int ready = select(this->fd_strace+1, &fds, NULL, NULL, &tv);
|
||||
int nread = 0;
|
||||
if (ready > 0 && FD_ISSET(this->fd_strace, &fds))
|
||||
nread = fread(buffer, 1, 1000, this->strace);
|
||||
if (nread && this->tracing) {
|
||||
char* line = buffer;
|
||||
buffer[nread] = '\0';
|
||||
for (int i = 0; i < nread; i++) {
|
||||
if (buffer[i] == '\n') {
|
||||
buffer[i] = '\0';
|
||||
if (this->contLine) {
|
||||
InfoScreen_appendLine(&this->super, line);
|
||||
this->contLine = false;
|
||||
} else {
|
||||
InfoScreen_addLine(&this->super, line);
|
||||
}
|
||||
if (line < buffer+nread) {
|
||||
addLine(line, lines, panel, incFilter);
|
||||
buffer[nread] = '\0';
|
||||
contLine = true;
|
||||
}
|
||||
if (follow)
|
||||
Panel_setSelected(panel, Panel_size(panel)-1);
|
||||
line = buffer+i+1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == KEY_MOUSE) {
|
||||
MEVENT mevent;
|
||||
int ok = getmouse(&mevent);
|
||||
if (ok == OK)
|
||||
if (mevent.y >= panel->y && mevent.y < LINES - 1) {
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
||||
follow = false;
|
||||
ch = 0;
|
||||
} if (mevent.y == LINES - 1)
|
||||
ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
|
||||
if (line < buffer+nread) {
|
||||
InfoScreen_addLine(&this->super, line);
|
||||
buffer[nread] = '\0';
|
||||
this->contLine = true;
|
||||
}
|
||||
|
||||
if (inc->active) {
|
||||
IncSet_handleKey(inc, ch, panel, IncSet_getListItemValue, lines);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(ch) {
|
||||
case ERR:
|
||||
continue;
|
||||
case KEY_HOME:
|
||||
Panel_setSelected(panel, 0);
|
||||
break;
|
||||
case KEY_END:
|
||||
Panel_setSelected(panel, Panel_size(panel)-1);
|
||||
break;
|
||||
case KEY_F(3):
|
||||
case '/':
|
||||
IncSet_activate(inc, INC_SEARCH);
|
||||
break;
|
||||
case KEY_F(4):
|
||||
case '\\':
|
||||
IncSet_activate(inc, INC_FILTER);
|
||||
break;
|
||||
if (this->follow)
|
||||
Panel_setSelected(this->super.display, Panel_size(this->super.display)-1);
|
||||
}
|
||||
}
|
||||
|
||||
bool TraceScreen_onKey(InfoScreen* super, int ch) {
|
||||
TraceScreen* this = (TraceScreen*) super;
|
||||
switch(ch) {
|
||||
case 'f':
|
||||
case KEY_F(8):
|
||||
follow = !follow;
|
||||
if (follow)
|
||||
Panel_setSelected(panel, Panel_size(panel)-1);
|
||||
break;
|
||||
this->follow = !(this->follow);
|
||||
if (this->follow)
|
||||
Panel_setSelected(super->display, Panel_size(super->display)-1);
|
||||
return true;
|
||||
case 't':
|
||||
case KEY_F(9):
|
||||
this->tracing = !this->tracing;
|
||||
FunctionBar_setLabel(bar, KEY_F(9), this->tracing?"Stop Tracing ":"Resume Tracing ");
|
||||
TraceScreen_draw(this, inc);
|
||||
break;
|
||||
case 'q':
|
||||
case 27:
|
||||
case KEY_F(10):
|
||||
looping = false;
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
Panel_resize(panel, COLS, LINES-2);
|
||||
TraceScreen_draw(this, inc);
|
||||
break;
|
||||
default:
|
||||
follow = false;
|
||||
Panel_onKey(panel, ch);
|
||||
}
|
||||
FunctionBar_setLabel(super->display->defaultBar, KEY_F(9), this->tracing?"Stop Tracing ":"Resume Tracing ");
|
||||
InfoScreen_draw(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
IncSet_delete(inc);
|
||||
FunctionBar_delete((Object*)bar);
|
||||
Vector_delete(lines);
|
||||
|
||||
kill(child, SIGTERM);
|
||||
waitpid(child, NULL, 0);
|
||||
fclose(strace);
|
||||
CRT_enableDelay();
|
||||
this->follow = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -9,21 +9,32 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include "Panel.h"
|
||||
#include "FunctionBar.h"
|
||||
#include "InfoScreen.h"
|
||||
|
||||
typedef struct TraceScreen_ {
|
||||
Process* process;
|
||||
Panel* display;
|
||||
InfoScreen super;
|
||||
bool tracing;
|
||||
int fdpair[2];
|
||||
int child;
|
||||
FILE* strace;
|
||||
int fd_strace;
|
||||
bool contLine;
|
||||
bool follow;
|
||||
} TraceScreen;
|
||||
|
||||
|
||||
extern InfoScreenClass TraceScreen_class;
|
||||
|
||||
TraceScreen* TraceScreen_new(Process* process);
|
||||
|
||||
void TraceScreen_delete(TraceScreen* this);
|
||||
void TraceScreen_delete(Object* cast);
|
||||
|
||||
void TraceScreen_run(TraceScreen* this);
|
||||
void TraceScreen_draw(InfoScreen* this);
|
||||
|
||||
bool TraceScreen_forkTracer(TraceScreen* this);
|
||||
|
||||
void TraceScreen_updateTrace(InfoScreen* super);
|
||||
|
||||
bool TraceScreen_onKey(InfoScreen* super, int ch);
|
||||
|
||||
#endif
|
||||
|
@ -6,12 +6,9 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "UptimeMeter.h"
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "Platform.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*{
|
||||
#include "Meter.h"
|
||||
}*/
|
||||
@ -20,14 +17,12 @@ int UptimeMeter_attributes[] = {
|
||||
UPTIME
|
||||
};
|
||||
|
||||
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
double uptime = 0;
|
||||
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
||||
if (fd) {
|
||||
fscanf(fd, "%64lf", &uptime);
|
||||
fclose(fd);
|
||||
static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||
int totalseconds = Platform_getUptime();
|
||||
if (totalseconds == -1) {
|
||||
snprintf(buffer, len, "(unknown)");
|
||||
return;
|
||||
}
|
||||
int totalseconds = (int) ceil(uptime);
|
||||
int seconds = totalseconds % 60;
|
||||
int minutes = (totalseconds/60) % 60;
|
||||
int hours = (totalseconds/3600) % 24;
|
||||
@ -54,8 +49,9 @@ MeterClass UptimeMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = UptimeMeter_setValues,
|
||||
.updateValues = UptimeMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = UptimeMeter_attributes,
|
||||
.name = "Uptime",
|
||||
|
@ -6,6 +6,7 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "UsersTable.h"
|
||||
#include "XAlloc.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@ -27,7 +28,7 @@ typedef struct UsersTable_ {
|
||||
|
||||
UsersTable* UsersTable_new() {
|
||||
UsersTable* this;
|
||||
this = malloc(sizeof(UsersTable));
|
||||
this = xMalloc(sizeof(UsersTable));
|
||||
this->users = Hashtable_new(20, true);
|
||||
return this;
|
||||
}
|
||||
@ -42,7 +43,7 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
||||
if (name == NULL) {
|
||||
struct passwd* userData = getpwuid(uid);
|
||||
if (userData != NULL) {
|
||||
name = strdup(userData->pw_name);
|
||||
name = xStrdup(userData->pw_name);
|
||||
Hashtable_put(this->users, uid, name);
|
||||
}
|
||||
}
|
||||
|
11
Vector.c
11
Vector.c
@ -37,9 +37,9 @@ Vector* Vector_new(ObjectClass* type, bool owner, int size) {
|
||||
|
||||
if (size == DEFAULT_SIZE)
|
||||
size = 10;
|
||||
this = (Vector*) malloc(sizeof(Vector));
|
||||
this = xMalloc(sizeof(Vector));
|
||||
this->growthRate = size;
|
||||
this->array = (Object**) calloc(size, sizeof(Object*));
|
||||
this->array = (Object**) xCalloc(size, sizeof(Object*));
|
||||
this->arraySize = size;
|
||||
this->items = 0;
|
||||
this->type = type;
|
||||
@ -179,7 +179,7 @@ static void Vector_checkArraySize(Vector* this) {
|
||||
//int i;
|
||||
//i = this->arraySize;
|
||||
this->arraySize = this->items + this->growthRate;
|
||||
this->array = (Object**) realloc(this->array, sizeof(Object*) * this->arraySize);
|
||||
this->array = (Object**) xRealloc(this->array, sizeof(Object*) * this->arraySize);
|
||||
//for (; i < this->arraySize; i++)
|
||||
// this->array[i] = NULL;
|
||||
}
|
||||
@ -189,9 +189,12 @@ static void Vector_checkArraySize(Vector* this) {
|
||||
void Vector_insert(Vector* this, int idx, void* data_) {
|
||||
Object* data = data_;
|
||||
assert(idx >= 0);
|
||||
assert(idx <= this->items);
|
||||
assert(Object_isA(data, this->type));
|
||||
assert(Vector_isConsistent(this));
|
||||
|
||||
if (idx > this->items) {
|
||||
idx = this->items;
|
||||
}
|
||||
|
||||
Vector_checkArraySize(this);
|
||||
//assert(this->array[this->items] == NULL);
|
||||
|
69
XAlloc.c
Normal file
69
XAlloc.c
Normal file
@ -0,0 +1,69 @@
|
||||
|
||||
#include "XAlloc.h"
|
||||
#include "RichString.h"
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*{
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
}*/
|
||||
|
||||
static inline void fail() {
|
||||
curs_set(1);
|
||||
endwin();
|
||||
err(1, NULL);
|
||||
}
|
||||
|
||||
void* xMalloc(size_t size) {
|
||||
void* data = malloc(size);
|
||||
if (!data && size > 0) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void* xCalloc(size_t nmemb, size_t size) {
|
||||
void* data = calloc(nmemb, size);
|
||||
if (!data && nmemb > 0 && size > 0) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void* xRealloc(void* ptr, size_t size) {
|
||||
void* data = realloc(ptr, size);
|
||||
if (!data && size > 0) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
#undef xStrdup
|
||||
#undef xStrdup_
|
||||
#ifdef NDEBUG
|
||||
# define xStrdup_ xStrdup
|
||||
#else
|
||||
# define xStrdup(str_) (assert(str_), xStrdup_(str_))
|
||||
#endif
|
||||
|
||||
#ifndef __has_attribute // Clang's macro
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
#if (__has_attribute(nonnull) || \
|
||||
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
|
||||
char* xStrdup_(const char* str) __attribute__((nonnull));
|
||||
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
||||
|
||||
char* xStrdup_(const char* str) {
|
||||
char* data = strdup(str);
|
||||
if (!data) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
}
|
37
XAlloc.h
Normal file
37
XAlloc.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_XAlloc
|
||||
#define HEADER_XAlloc
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void* xMalloc(size_t size);
|
||||
|
||||
void* xCalloc(size_t nmemb, size_t size);
|
||||
|
||||
void* xRealloc(void* ptr, size_t size);
|
||||
|
||||
#undef xStrdup
|
||||
#undef xStrdup_
|
||||
#ifdef NDEBUG
|
||||
# define xStrdup_ xStrdup
|
||||
#else
|
||||
# define xStrdup(str_) (assert(str_), xStrdup_(str_))
|
||||
#endif
|
||||
|
||||
#ifndef __has_attribute // Clang's macro
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
#if (__has_attribute(nonnull) || \
|
||||
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
|
||||
char* xStrdup_(const char* str) __attribute__((nonnull));
|
||||
#endif // __has_attribute(nonnull) || GNU C 3.3 or later
|
||||
|
||||
char* xStrdup_(const char* str);
|
||||
|
||||
#endif
|
10
autogen.sh
10
autogen.sh
@ -1,9 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
aclocal -I m4
|
||||
autoconf
|
||||
autoheader
|
||||
libtoolize --copy --force
|
||||
automake --add-missing --copy
|
||||
|
||||
|
||||
mkdir -p m4
|
||||
autoreconf --install --force
|
||||
|
210
configure.ac
210
configure.ac
@ -2,29 +2,58 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.65)
|
||||
AC_INIT([htop],[1.0.3],[hisham@gobolinux.org])
|
||||
LT_PREREQ([2.4.2])
|
||||
AC_INIT([htop],[2.0.2],[hisham@gobolinux.org])
|
||||
|
||||
# The following two lines are required by hwloc scripts
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
||||
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
||||
|
||||
AC_CONFIG_SRCDIR([htop.c])
|
||||
AC_CONFIG_AUX_DIR([.])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# Required by hwloc scripts
|
||||
AC_CANONICAL_TARGET
|
||||
|
||||
AM_INIT_AUTOMAKE([1.11])
|
||||
AC_CONFIG_SRCDIR([htop.c])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# Checks for programs.
|
||||
# ----------------------------------------------------------------------
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
|
||||
AC_DISABLE_SHARED
|
||||
AC_ENABLE_STATIC
|
||||
AC_PROG_LIBTOOL
|
||||
# Required by hwloc scripts
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
|
||||
LT_INIT([disable-shared static])
|
||||
|
||||
# Checks for platform.
|
||||
# ----------------------------------------------------------------------
|
||||
case "$target_os" in
|
||||
linux*|gnu*)
|
||||
my_htop_platform=linux
|
||||
;;
|
||||
freebsd*|kfreebsd*)
|
||||
my_htop_platform=freebsd
|
||||
;;
|
||||
openbsd*)
|
||||
my_htop_platform=openbsd
|
||||
;;
|
||||
darwin*)
|
||||
my_htop_platform=darwin
|
||||
;;
|
||||
*)
|
||||
my_htop_platform=unsupported
|
||||
;;
|
||||
esac
|
||||
|
||||
# Checks for libraries.
|
||||
# ----------------------------------------------------------------------
|
||||
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
|
||||
|
||||
# Checks for header files.
|
||||
# ----------------------------------------------------------------------
|
||||
AC_HEADER_DIRENT
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([stdlib.h string.h strings.h sys/param.h sys/time.h unistd.h],[:],[
|
||||
@ -33,12 +62,14 @@ AC_CHECK_HEADERS([stdlib.h string.h strings.h sys/param.h sys/time.h unistd.h],[
|
||||
AC_CHECK_HEADERS([execinfo.h],[:],[:])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
# ----------------------------------------------------------------------
|
||||
AC_HEADER_STDBOOL
|
||||
AC_C_CONST
|
||||
AC_TYPE_PID_T
|
||||
AC_TYPE_UID_T
|
||||
|
||||
# Checks for library functions.
|
||||
# Checks for library functions and compiler features.
|
||||
# ----------------------------------------------------------------------
|
||||
AC_FUNC_CLOSEDIR_VOID
|
||||
AC_TYPE_SIGNAL
|
||||
AC_FUNC_STAT
|
||||
@ -47,78 +78,151 @@ AC_CHECK_FUNCS([memmove strncasecmp strstr strdup])
|
||||
save_cflags="${CFLAGS}"
|
||||
CFLAGS="${CFLAGS} -std=c99"
|
||||
AC_MSG_CHECKING([whether gcc -std=c99 option works])
|
||||
AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [char *a; a = strdup("foo"); int i = 0; i++; // C99],
|
||||
AC_MSG_RESULT([yes]),
|
||||
AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.]))
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
|
||||
[AC_INCLUDES_DEFAULT], [[char *a; a = strdup("foo"); int i = 0; i++; // C99]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_ERROR([htop is written in C99. A newer version of gcc is required.])])
|
||||
CFLAGS="$save_cflags"
|
||||
|
||||
save_cflags="${CFLAGS}"
|
||||
CFLAGS="$CFLAGS -Wextra"
|
||||
AC_MSG_CHECKING([if compiler supports -Wextra])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],[
|
||||
wextra_flag=-Wextra
|
||||
AC_MSG_RESULT([yes])
|
||||
],[
|
||||
wextra_flag=
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
CFLAGS="$save_cflags"
|
||||
AC_SUBST(wextra_flag)
|
||||
|
||||
# Checks for features and flags.
|
||||
# ----------------------------------------------------------------------
|
||||
PROCDIR=/proc
|
||||
AC_ARG_WITH(proc, [ --with-proc=DIR Location of a Linux-compatible proc filesystem (default=/proc).],
|
||||
|
||||
if test -n "$withval"; then
|
||||
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
|
||||
PROCDIR="$withval"
|
||||
fi,
|
||||
AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem]))
|
||||
AC_ARG_ENABLE(proc, [AS_HELP_STRING([--enable-proc], [use Linux-compatible proc filesystem])], enable_proc="yes", enable_proc="no")
|
||||
if test "x$enable_proc" = xyes; then
|
||||
# An enabled proc assumes we're emulating Linux.
|
||||
my_htop_platform=linux
|
||||
AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
|
||||
AC_ARG_WITH(proc, [AS_HELP_STRING([--with-proc=DIR], [Location of a Linux-compatible proc filesystem (default=/proc).])],
|
||||
|
||||
if test -n "$withval"; then
|
||||
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
|
||||
PROCDIR="$withval"
|
||||
fi,
|
||||
AC_DEFINE(PROCDIR, "/proc", [Path of proc filesystem]))
|
||||
|
||||
if test "x$cross_compiling" = xno; then
|
||||
if test "x$enable_proc" = xyes; then
|
||||
AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find $PROCDIR/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
||||
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find $PROCDIR/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(openvz, [AS_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
|
||||
if test "x$enable_openvz" = xyes; then
|
||||
AC_DEFINE(HAVE_OPENVZ, 1, [Define if openvz support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(cgroup, [AC_HELP_STRING([--enable-cgroup], [enable cgroups support])], ,enable_cgroup="no")
|
||||
AC_ARG_ENABLE(cgroup, [AS_HELP_STRING([--enable-cgroup], [enable cgroups support])], ,enable_cgroup="no")
|
||||
if test "x$enable_cgroup" = xyes; then
|
||||
AC_DEFINE(HAVE_CGROUP, 1, [Define if cgroup support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(vserver, [AC_HELP_STRING([--enable-vserver], [enable VServer support])], ,enable_vserver="no")
|
||||
AC_ARG_ENABLE(vserver, [AS_HELP_STRING([--enable-vserver], [enable VServer support])], ,enable_vserver="no")
|
||||
if test "x$enable_vserver" = xyes; then
|
||||
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(ancient_vserver, [AC_HELP_STRING([--enable-ancient-vserver], [enable ancient VServer support (implies --enable-vserver)])], ,enable_ancient_vserver="no")
|
||||
AC_ARG_ENABLE(ancient_vserver, [AS_HELP_STRING([--enable-ancient-vserver], [enable ancient VServer support (implies --enable-vserver)])], ,enable_ancient_vserver="no")
|
||||
if test "x$enable_ancient_vserver" = xyes; then
|
||||
AC_DEFINE(HAVE_VSERVER, 1, [Define if vserver support enabled.])
|
||||
AC_DEFINE(HAVE_ANCIENT_VSERVER, 1, [Define if ancient vserver support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(taskstats, [AC_HELP_STRING([--enable-taskstats], [enable per-task IO Stats (taskstats kernel sup required)])], ,enable_taskstats="yes")
|
||||
AC_ARG_ENABLE(taskstats, [AS_HELP_STRING([--enable-taskstats], [enable per-task IO Stats (taskstats kernel sup required)])], ,enable_taskstats="yes")
|
||||
if test "x$enable_taskstats" = xyes; then
|
||||
AC_DEFINE(HAVE_TASKSTATS, 1, [Define if taskstats support enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
|
||||
# HTOP_CHECK_SCRIPT(LIBNAME, FUNCTION, DEFINE, CONFIG_SCRIPT, ELSE_PART)
|
||||
m4_define([HTOP_CHECK_SCRIPT],
|
||||
[
|
||||
if test ! -z "m4_toupper($HTOP_[$1]_CONFIG_SCRIPT)"; then
|
||||
# to be used to set the path to ncurses*-config when cross-compiling
|
||||
htop_config_script=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --libs 2> /dev/null)
|
||||
else
|
||||
htop_config_script=$([$4] --libs 2> /dev/null)
|
||||
fi
|
||||
htop_script_success=no
|
||||
htop_save_LDFLAGS="$LDFLAGS"
|
||||
if test ! "x$htop_config_script" = x; then
|
||||
LDFLAGS="$htop_config_script $LDFLAGS"
|
||||
AC_CHECK_LIB([$1], [$2], [
|
||||
AC_DEFINE([$3], 1, [The library is present.])
|
||||
LIBS="$htop_config_script $LIBS "
|
||||
htop_script_success=yes
|
||||
], [])
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
fi
|
||||
if test "x$htop_script_success" = xno; then
|
||||
[$5]
|
||||
fi
|
||||
])
|
||||
|
||||
# HTOP_CHECK_LIB(LIBNAME, FUNCTION, DEFINE, ELSE_PART)
|
||||
m4_define([HTOP_CHECK_LIB],
|
||||
[
|
||||
AC_CHECK_LIB([$1], [$2], [
|
||||
AC_DEFINE([$3], 1, [The library is present.])
|
||||
LIBS="-l[$1] $LIBS "
|
||||
], [$4])
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(unicode, [AS_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
|
||||
if test "x$enable_unicode" = xyes; then
|
||||
AC_CHECK_LIB([ncursesw], [refresh], [], [
|
||||
HTOP_CHECK_SCRIPT([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw6-config",
|
||||
HTOP_CHECK_SCRIPT([ncursesw], [addnwstr], [HAVE_LIBNCURSESW], "ncursesw5-config",
|
||||
HTOP_CHECK_SCRIPT([ncurses], [addnwstr], [HAVE_LIBNCURSESW], "ncurses5-config",
|
||||
HTOP_CHECK_LIB([ncursesw6], [addnwstr], [HAVE_LIBNCURSESW],
|
||||
HTOP_CHECK_LIB([ncursesw], [addnwstr], [HAVE_LIBNCURSESW],
|
||||
HTOP_CHECK_LIB([ncurses], [addnwstr], [HAVE_LIBNCURSESW],
|
||||
missing_libraries="$missing_libraries libncursesw"
|
||||
AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.])
|
||||
])
|
||||
))))))
|
||||
|
||||
AC_CHECK_HEADERS([ncursesw/curses.h],[:],
|
||||
[AC_CHECK_HEADERS([ncurses/ncurses.h],[:],
|
||||
[AC_CHECK_HEADERS([ncurses/curses.h],[:],
|
||||
[AC_CHECK_HEADERS([ncurses.h],[:],[missing_headers="$missing_headers $ac_header"])])])])
|
||||
else
|
||||
AC_CHECK_LIB([ncurses], [refresh], [], [missing_libraries="$missing_libraries libncurses"])
|
||||
HTOP_CHECK_SCRIPT([ncurses6], [refresh], [HAVE_LIBNCURSES], "ncurses6-config",
|
||||
HTOP_CHECK_SCRIPT([ncurses], [refresh], [HAVE_LIBNCURSES], "ncurses5-config",
|
||||
HTOP_CHECK_LIB([ncurses6], [refresh], [HAVE_LIBNCURSES],
|
||||
HTOP_CHECK_LIB([ncurses], [refresh], [HAVE_LIBNCURSES],
|
||||
missing_libraries="$missing_libraries libncurses"
|
||||
))))
|
||||
|
||||
AC_CHECK_HEADERS([curses.h],[:],
|
||||
[AC_CHECK_HEADERS([ncurses/curses.h],[:],
|
||||
[AC_CHECK_HEADERS([ncurses/ncurses.h],[:],
|
||||
[AC_CHECK_HEADERS([ncurses.h],[:],[missing_headers="$missing_headers $ac_header"])])])])
|
||||
fi
|
||||
|
||||
if test ! -z "$missing_libraries"; then
|
||||
AC_MSG_ERROR([missing libraries: $missing_libraries])
|
||||
fi
|
||||
if test ! -z "$missing_headers"; then
|
||||
AC_MSG_ERROR([missing headers: $missing_headers])
|
||||
if test "$my_htop_platform" = "freebsd"; then
|
||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||
fi
|
||||
|
||||
if test "x$cross_compiling" = xno; then
|
||||
AC_CHECK_FILE($PROCDIR/stat,,AC_MSG_ERROR(Cannot find /proc/stat. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
||||
AC_CHECK_FILE($PROCDIR/meminfo,,AC_MSG_ERROR(Cannot find /proc/meminfo. Make sure you have a Linux-compatible /proc filesystem mounted. See the file README for help.))
|
||||
if test "$my_htop_platform" = "openbsd"; then
|
||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(native_affinity, [AC_HELP_STRING([--enable-native-affinity], [enable native sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_native_affinity="yes")
|
||||
if test "x$enable_native_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
||||
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||
AC_MSG_CHECKING([for usable sched_setaffinity])
|
||||
AC_RUN_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
@ -131,24 +235,38 @@ if test "x$enable_native_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||
if (errno == ENOSYS) return 1;
|
||||
]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[enable_native_affinity=no
|
||||
[enable_linux_affinity=no
|
||||
AC_MSG_RESULT([no])])
|
||||
fi
|
||||
if test "x$enable_native_affinity" = xyes; then
|
||||
AC_DEFINE(HAVE_NATIVE_AFFINITY, 1, [Define if native sched_setaffinity and sched_getaffinity are to be used.])
|
||||
if test "x$enable_linux_affinity" = xyes; then
|
||||
AC_DEFINE(HAVE_LINUX_AFFINITY, 1, [Define if Linux sched_setaffinity and sched_getaffinity are to be used.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(hwloc, [AC_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity])],, enable_hwloc="no")
|
||||
AC_ARG_ENABLE(hwloc, [AS_HELP_STRING([--enable-hwloc], [enable hwloc support for CPU affinity])],, enable_hwloc="no")
|
||||
if test "x$enable_hwloc" = xyes
|
||||
then
|
||||
AC_CHECK_LIB([hwloc], [hwloc_linux_get_tid_cpubind], [], [missing_libraries="$missing_libraries libhwloc"])
|
||||
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [missing_libraries="$missing_libraries libhwloc"])
|
||||
AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(oom, [AC_HELP_STRING([--enable-oom], [enable OOM score reporting])], ,enable_oom="no")
|
||||
if test "x$enable_oom" = xyes; then
|
||||
AC_DEFINE(HAVE_OOM, 1, [Define if OOM score support enabled.])
|
||||
# Bail out on errors.
|
||||
# ----------------------------------------------------------------------
|
||||
if test ! -z "$missing_libraries"; then
|
||||
AC_MSG_ERROR([missing libraries: $missing_libraries])
|
||||
fi
|
||||
if test ! -z "$missing_headers"; then
|
||||
AC_MSG_ERROR([missing headers: $missing_headers])
|
||||
fi
|
||||
|
||||
AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-$year Hisham Muhammad", [Copyright message.])
|
||||
|
||||
# We're done, let's go!
|
||||
# ----------------------------------------------------------------------
|
||||
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
|
||||
AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
||||
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
||||
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
||||
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
||||
AC_SUBST(my_htop_platform)
|
||||
AC_CONFIG_FILES([Makefile htop.1])
|
||||
AC_OUTPUT
|
||||
|
75
darwin/Battery.c
Normal file
75
darwin/Battery.c
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
#include "BatteryMeter.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CFString.h>
|
||||
#include <IOKit/ps/IOPowerSources.h>
|
||||
#include <IOKit/ps/IOPSKeys.h>
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
|
||||
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
|
||||
if(NULL == power_sources) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(power_sources != NULL) {
|
||||
CFArrayRef list = IOPSCopyPowerSourcesList(power_sources);
|
||||
CFDictionaryRef battery = NULL;
|
||||
int len;
|
||||
|
||||
if(NULL == list) {
|
||||
CFRelease(power_sources);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
len = CFArrayGetCount(list);
|
||||
|
||||
/* Get the battery */
|
||||
for(int i = 0; i < len && battery == NULL; ++i) {
|
||||
CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
|
||||
CFArrayGetValueAtIndex(list, i)); /* GET rule */
|
||||
CFStringRef type;
|
||||
|
||||
if(NULL != candidate) {
|
||||
type = (CFStringRef) CFDictionaryGetValue(candidate,
|
||||
CFSTR(kIOPSTransportTypeKey)); /* GET rule */
|
||||
|
||||
if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
|
||||
CFRetain(candidate);
|
||||
battery = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(NULL != battery) {
|
||||
/* Determine the AC state */
|
||||
CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
|
||||
|
||||
*isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
|
||||
? AC_PRESENT
|
||||
: AC_ABSENT;
|
||||
|
||||
/* Get the percentage remaining */
|
||||
double current;
|
||||
double max;
|
||||
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
|
||||
kCFNumberDoubleType, ¤t);
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
||||
kCFNumberDoubleType, &max);
|
||||
|
||||
*level = (current * 100.0) / max;
|
||||
|
||||
CFRelease(battery);
|
||||
}
|
||||
|
||||
CFRelease(list);
|
||||
CFRelease(power_sources);
|
||||
}
|
||||
}
|
||||
|
9
darwin/Battery.h
Normal file
9
darwin/Battery.h
Normal file
@ -0,0 +1,9 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Battery
|
||||
#define HEADER_Battery
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
|
||||
#endif
|
35
darwin/DarwinCRT.c
Normal file
35
darwin/DarwinCRT.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
htop - DarwinCRT.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "CRT.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <execinfo.h>
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn) {
|
||||
(void) sgn;
|
||||
CRT_done();
|
||||
#ifdef __APPLE__
|
||||
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||
fprintf(stderr, "\n\n otool -tvV `which htop` > ~/htop.otool");
|
||||
fprintf(stderr, "\n\nand then attach the file ~/htop.otool to your bug report.");
|
||||
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||
#endif
|
||||
#else
|
||||
fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!");
|
||||
fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n");
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
15
darwin/DarwinCRT.h
Normal file
15
darwin/DarwinCRT.h
Normal file
@ -0,0 +1,15 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_DarwinCRT
|
||||
#define HEADER_DarwinCRT
|
||||
/*
|
||||
htop - DarwinCRT.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
|
||||
#endif
|
363
darwin/DarwinProcess.c
Normal file
363
darwin/DarwinProcess.c
Normal file
@ -0,0 +1,363 @@
|
||||
/*
|
||||
htop - DarwinProcess.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include "DarwinProcess.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libproc.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mach/mach.h>
|
||||
|
||||
/*{
|
||||
#include "Settings.h"
|
||||
#include "DarwinProcessList.h"
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
typedef struct DarwinProcess_ {
|
||||
Process super;
|
||||
|
||||
uint64_t utime;
|
||||
uint64_t stime;
|
||||
bool taskAccess;
|
||||
} DarwinProcess;
|
||||
|
||||
}*/
|
||||
|
||||
ProcessClass DarwinProcess_class = {
|
||||
.super = {
|
||||
.extends = Class(Process),
|
||||
.display = Process_display,
|
||||
.delete = Process_delete,
|
||||
.compare = Process_compare
|
||||
},
|
||||
.writeField = Process_writeField,
|
||||
};
|
||||
|
||||
DarwinProcess* DarwinProcess_new(Settings* settings) {
|
||||
DarwinProcess* this = xCalloc(1, sizeof(DarwinProcess));
|
||||
Object_setClass(this, Class(DarwinProcess));
|
||||
Process_init(&this->super, settings);
|
||||
|
||||
this->utime = 0;
|
||||
this->stime = 0;
|
||||
this->taskAccess = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void Process_delete(Object* cast) {
|
||||
DarwinProcess* this = (DarwinProcess*) cast;
|
||||
Process_done(&this->super);
|
||||
// free platform-specific fields here
|
||||
free(this);
|
||||
}
|
||||
|
||||
bool Process_isThread(Process* this) {
|
||||
(void) this;
|
||||
return false;
|
||||
}
|
||||
|
||||
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) {
|
||||
struct tm date;
|
||||
|
||||
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
||||
(void) localtime_r(&proc->starttime_ctime, &date);
|
||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
||||
}
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||
/* This function is from the old Mac version of htop. Originally from ps? */
|
||||
int mib[3], argmax, nargs, c = 0;
|
||||
size_t size;
|
||||
char *procargs, *sp, *np, *cp, *retval;
|
||||
|
||||
/* Get the maximum process arguments size. */
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_ARGMAX;
|
||||
|
||||
size = sizeof( argmax );
|
||||
if ( sysctl( mib, 2, &argmax, &size, NULL, 0 ) == -1 ) {
|
||||
goto ERROR_A;
|
||||
}
|
||||
|
||||
/* Allocate space for the arguments. */
|
||||
procargs = ( char * ) xMalloc( argmax );
|
||||
if ( procargs == NULL ) {
|
||||
goto ERROR_A;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a sysctl() call to get the raw argument space of the process.
|
||||
* The layout is documented in start.s, which is part of the Csu
|
||||
* project. In summary, it looks like:
|
||||
*
|
||||
* /---------------\ 0x00000000
|
||||
* : :
|
||||
* : :
|
||||
* |---------------|
|
||||
* | argc |
|
||||
* |---------------|
|
||||
* | arg[0] |
|
||||
* |---------------|
|
||||
* : :
|
||||
* : :
|
||||
* |---------------|
|
||||
* | arg[argc - 1] |
|
||||
* |---------------|
|
||||
* | 0 |
|
||||
* |---------------|
|
||||
* | env[0] |
|
||||
* |---------------|
|
||||
* : :
|
||||
* : :
|
||||
* |---------------|
|
||||
* | env[n] |
|
||||
* |---------------|
|
||||
* | 0 |
|
||||
* |---------------| <-- Beginning of data returned by sysctl() is here.
|
||||
* | argc |
|
||||
* |---------------|
|
||||
* | exec_path |
|
||||
* |:::::::::::::::|
|
||||
* | |
|
||||
* | String area. |
|
||||
* | |
|
||||
* |---------------| <-- Top of stack.
|
||||
* : :
|
||||
* : :
|
||||
* \---------------/ 0xffffffff
|
||||
*/
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROCARGS2;
|
||||
mib[2] = k->kp_proc.p_pid;
|
||||
|
||||
size = ( size_t ) argmax;
|
||||
if ( sysctl( mib, 3, procargs, &size, NULL, 0 ) == -1 ) {
|
||||
goto ERROR_B;
|
||||
}
|
||||
|
||||
memcpy( &nargs, procargs, sizeof( nargs ) );
|
||||
cp = procargs + sizeof( nargs );
|
||||
|
||||
/* Skip the saved exec_path. */
|
||||
for ( ; cp < &procargs[size]; cp++ ) {
|
||||
if ( *cp == '\0' ) {
|
||||
/* End of exec_path reached. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( cp == &procargs[size] ) {
|
||||
goto ERROR_B;
|
||||
}
|
||||
|
||||
/* Skip trailing '\0' characters. */
|
||||
for ( ; cp < &procargs[size]; cp++ ) {
|
||||
if ( *cp != '\0' ) {
|
||||
/* Beginning of first argument reached. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( cp == &procargs[size] ) {
|
||||
goto ERROR_B;
|
||||
}
|
||||
/* Save where the argv[0] string starts. */
|
||||
sp = cp;
|
||||
|
||||
*basenameOffset = 0;
|
||||
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
|
||||
if ( *cp == '\0' ) {
|
||||
c++;
|
||||
if ( np != NULL ) {
|
||||
/* Convert previous '\0'. */
|
||||
*np = ' ';
|
||||
}
|
||||
/* Note location of current '\0'. */
|
||||
np = cp;
|
||||
if (*basenameOffset == 0) {
|
||||
*basenameOffset = cp - sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* sp points to the beginning of the arguments/environment string, and
|
||||
* np should point to the '\0' terminator for the string.
|
||||
*/
|
||||
if ( np == NULL || np == sp ) {
|
||||
/* Empty or unterminated string. */
|
||||
goto ERROR_B;
|
||||
}
|
||||
if (*basenameOffset == 0) {
|
||||
*basenameOffset = np - sp;
|
||||
}
|
||||
|
||||
/* Make a copy of the string. */
|
||||
retval = xStrdup(sp);
|
||||
|
||||
/* Clean up. */
|
||||
free( procargs );
|
||||
|
||||
return retval;
|
||||
|
||||
ERROR_B:
|
||||
free( procargs );
|
||||
ERROR_A:
|
||||
retval = xStrdup(k->kp_proc.p_comm);
|
||||
*basenameOffset = strlen(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists) {
|
||||
struct extern_proc *ep = &ps->kp_proc;
|
||||
|
||||
/* UNSET HERE :
|
||||
*
|
||||
* processor
|
||||
* user (set at ProcessList level)
|
||||
* nlwp
|
||||
* percent_cpu
|
||||
* percent_mem
|
||||
* m_size
|
||||
* m_resident
|
||||
* minflt
|
||||
* majflt
|
||||
*/
|
||||
|
||||
/* First, the "immutable" parts */
|
||||
if(!exists) {
|
||||
/* Set the PID/PGID/etc. */
|
||||
proc->pid = ep->p_pid;
|
||||
proc->ppid = ps->kp_eproc.e_ppid;
|
||||
proc->pgrp = ps->kp_eproc.e_pgid;
|
||||
proc->session = 0; /* TODO Get the session id */
|
||||
proc->tpgid = ps->kp_eproc.e_tpgid;
|
||||
proc->tgid = proc->pid;
|
||||
proc->st_uid = ps->kp_eproc.e_ucred.cr_uid;
|
||||
/* e_tdev = (major << 24) | (minor & 0xffffff) */
|
||||
/* e_tdev == -1 for "no device" */
|
||||
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
|
||||
|
||||
DarwinProcess_setStartTime(proc, ep, now);
|
||||
proc->comm = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset));
|
||||
}
|
||||
|
||||
/* Mutable information */
|
||||
proc->nice = ep->p_nice;
|
||||
proc->priority = ep->p_priority;
|
||||
|
||||
proc->state = (ep->p_stat == SZOMB) ? 'Z' : '?';
|
||||
|
||||
/* Make sure the updated flag is set */
|
||||
proc->updated = true;
|
||||
}
|
||||
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) {
|
||||
struct proc_taskinfo pti;
|
||||
|
||||
if(sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
|
||||
if(0 != proc->utime || 0 != proc->stime) {
|
||||
uint64_t diff = (pti.pti_total_system - proc->stime)
|
||||
+ (pti.pti_total_user - proc->utime);
|
||||
|
||||
proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount
|
||||
/ ((double)dpl->global_diff * 100000.0);
|
||||
|
||||
// fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu,
|
||||
// proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff);
|
||||
// exit(7);
|
||||
}
|
||||
|
||||
proc->super.time = (pti.pti_total_system + pti.pti_total_user) / 10000000;
|
||||
proc->super.nlwp = pti.pti_threadnum;
|
||||
proc->super.m_size = pti.pti_virtual_size / 1024 / PAGE_SIZE_KB;
|
||||
proc->super.m_resident = pti.pti_resident_size / 1024 / PAGE_SIZE_KB;
|
||||
proc->super.majflt = pti.pti_faults;
|
||||
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
|
||||
/ (double)dpl->host_info.max_mem;
|
||||
|
||||
proc->stime = pti.pti_total_system;
|
||||
proc->utime = pti.pti_total_user;
|
||||
|
||||
dpl->super.kernelThreads += 0; /*pti.pti_threads_system;*/
|
||||
dpl->super.userlandThreads += pti.pti_threadnum; /*pti.pti_threads_user;*/
|
||||
dpl->super.totalTasks += pti.pti_threadnum;
|
||||
dpl->super.runningTasks += pti.pti_numrunning;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan threads for process state information.
|
||||
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
|
||||
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
|
||||
*/
|
||||
void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||
Process* proc = (Process*) dp;
|
||||
kern_return_t ret;
|
||||
|
||||
if (!dp->taskAccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (proc->state == 'Z') {
|
||||
return;
|
||||
}
|
||||
|
||||
task_t port;
|
||||
ret = task_for_pid(mach_task_self(), proc->pid, &port);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
dp->taskAccess = false;
|
||||
return;
|
||||
}
|
||||
|
||||
task_info_data_t tinfo;
|
||||
mach_msg_type_number_t task_info_count = TASK_INFO_MAX;
|
||||
ret = task_info(port, TASK_BASIC_INFO, (task_info_t) tinfo, &task_info_count);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
dp->taskAccess = false;
|
||||
return;
|
||||
}
|
||||
|
||||
thread_array_t thread_list;
|
||||
mach_msg_type_number_t thread_count;
|
||||
ret = task_threads(port, &thread_list, &thread_count);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
dp->taskAccess = false;
|
||||
mach_port_deallocate(mach_task_self(), port);
|
||||
return;
|
||||
}
|
||||
|
||||
integer_t run_state = 999;
|
||||
for (unsigned int i = 0; i < thread_count; i++) {
|
||||
thread_info_data_t thinfo;
|
||||
mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT;
|
||||
ret = thread_info(thread_list[i], THREAD_BASIC_INFO, (thread_info_t)thinfo, &thread_info_count);
|
||||
if (ret == KERN_SUCCESS) {
|
||||
thread_basic_info_t basic_info_th = (thread_basic_info_t) thinfo;
|
||||
if (basic_info_th->run_state < run_state) {
|
||||
run_state = basic_info_th->run_state;
|
||||
}
|
||||
mach_port_deallocate(mach_task_self(), thread_list[i]);
|
||||
}
|
||||
}
|
||||
vm_deallocate(mach_task_self(), (vm_address_t) thread_list, sizeof(thread_port_array_t) * thread_count);
|
||||
mach_port_deallocate(mach_task_self(), port);
|
||||
|
||||
char state = '?';
|
||||
switch (run_state) {
|
||||
case TH_STATE_RUNNING: state = 'R'; break;
|
||||
case TH_STATE_STOPPED: state = 'S'; break;
|
||||
case TH_STATE_WAITING: state = 'W'; break;
|
||||
case TH_STATE_UNINTERRUPTIBLE: state = 'U'; break;
|
||||
case TH_STATE_HALTED: state = 'H'; break;
|
||||
}
|
||||
proc->state = state;
|
||||
}
|
49
darwin/DarwinProcess.h
Normal file
49
darwin/DarwinProcess.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_DarwinProcess
|
||||
#define HEADER_DarwinProcess
|
||||
/*
|
||||
htop - DarwinProcess.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
#include "DarwinProcessList.h"
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
typedef struct DarwinProcess_ {
|
||||
Process super;
|
||||
|
||||
uint64_t utime;
|
||||
uint64_t stime;
|
||||
bool taskAccess;
|
||||
} DarwinProcess;
|
||||
|
||||
|
||||
extern ProcessClass DarwinProcess_class;
|
||||
|
||||
DarwinProcess* DarwinProcess_new(Settings* settings);
|
||||
|
||||
void Process_delete(Object* cast);
|
||||
|
||||
bool Process_isThread(Process* this);
|
||||
|
||||
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now);
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset);
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists);
|
||||
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl);
|
||||
|
||||
/*
|
||||
* Scan threads for process state information.
|
||||
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
|
||||
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
|
||||
*/
|
||||
void DarwinProcess_scanThreads(DarwinProcess *dp);
|
||||
|
||||
#endif
|
186
darwin/DarwinProcessList.c
Normal file
186
darwin/DarwinProcessList.c
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
htop - DarwinProcessList.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "DarwinProcess.h"
|
||||
#include "DarwinProcessList.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <libproc.h>
|
||||
#include <sys/mman.h>
|
||||
#include <utmpx.h>
|
||||
#include <err.h>
|
||||
|
||||
/*{
|
||||
#include "ProcessList.h"
|
||||
#include <mach/mach_host.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
typedef struct DarwinProcessList_ {
|
||||
ProcessList super;
|
||||
|
||||
host_basic_info_data_t host_info;
|
||||
vm_statistics_data_t vm_stats;
|
||||
processor_cpu_load_info_t prev_load;
|
||||
processor_cpu_load_info_t curr_load;
|
||||
uint64_t kernel_threads;
|
||||
uint64_t user_threads;
|
||||
uint64_t global_diff;
|
||||
} DarwinProcessList;
|
||||
|
||||
}*/
|
||||
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||
|
||||
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve host info\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||
if(NULL != p && NULL != *p) {
|
||||
if(0 != munmap(*p, vm_page_size)) {
|
||||
CRT_fatalError("Unable to free old CPU load information\n");
|
||||
}
|
||||
}
|
||||
|
||||
*p = NULL;
|
||||
}
|
||||
|
||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||
mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t);
|
||||
unsigned cpu_count;
|
||||
|
||||
// TODO Improving the accuracy of the load counts woule help a lot.
|
||||
if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve CPU info\n");
|
||||
}
|
||||
|
||||
return cpu_count;
|
||||
}
|
||||
|
||||
void ProcessList_getVMStats(vm_statistics_t p) {
|
||||
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
||||
|
||||
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
||||
CRT_fatalError("Unable to retrieve VM statistics\n");
|
||||
}
|
||||
|
||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
|
||||
struct kinfo_proc *processes = NULL;
|
||||
|
||||
/* Note the two calls to sysctl(). One to get length and one to get the
|
||||
* data. This -does- mean that the second call could end up with a missing
|
||||
* process entry or two.
|
||||
*/
|
||||
*count = 0;
|
||||
if (sysctl(mib, 4, NULL, count, NULL, 0) < 0)
|
||||
CRT_fatalError("Unable to get size of kproc_infos");
|
||||
|
||||
processes = xMalloc(*count);
|
||||
if (processes == NULL)
|
||||
CRT_fatalError("Out of memory for kproc_infos");
|
||||
|
||||
if (sysctl(mib, 4, processes, count, NULL, 0) < 0)
|
||||
CRT_fatalError("Unable to get kinfo_procs");
|
||||
|
||||
*count = *count / sizeof(struct kinfo_proc);
|
||||
|
||||
return processes;
|
||||
}
|
||||
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
|
||||
|
||||
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
||||
|
||||
/* Initialize the CPU information */
|
||||
this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load);
|
||||
ProcessList_getHostInfo(&this->host_info);
|
||||
ProcessList_allocateCPULoadInfo(&this->curr_load);
|
||||
|
||||
/* Initialize the VM statistics */
|
||||
ProcessList_getVMStats(&this->vm_stats);
|
||||
|
||||
this->super.kernelThreads = 0;
|
||||
this->super.userlandThreads = 0;
|
||||
this->super.totalTasks = 0;
|
||||
this->super.runningTasks = 0;
|
||||
|
||||
return &this->super;
|
||||
}
|
||||
|
||||
void ProcessList_delete(ProcessList* this) {
|
||||
ProcessList_done(this);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* super) {
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
||||
bool preExisting = true;
|
||||
struct kinfo_proc *ps;
|
||||
size_t count;
|
||||
DarwinProcess *proc;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL); /* Start processing time */
|
||||
|
||||
/* Update the global data (CPU times and VM stats) */
|
||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||
dpl->prev_load = dpl->curr_load;
|
||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||
ProcessList_getVMStats(&dpl->vm_stats);
|
||||
|
||||
/* Get the time difference */
|
||||
dpl->global_diff = 0;
|
||||
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the thread counts */
|
||||
super->kernelThreads = 0;
|
||||
super->userlandThreads = 0;
|
||||
super->totalTasks = 0;
|
||||
super->runningTasks = 0;
|
||||
|
||||
/* We use kinfo_procs for initial data since :
|
||||
*
|
||||
* 1) They always succeed.
|
||||
* 2) The contain the basic information.
|
||||
*
|
||||
* We attempt to fill-in additional information with libproc.
|
||||
*/
|
||||
ps = ProcessList_getKInfoProcs(&count);
|
||||
|
||||
for(size_t i = 0; i < count; ++i) {
|
||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||
|
||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||
|
||||
DarwinProcess_scanThreads(proc);
|
||||
|
||||
super->totalTasks += 1;
|
||||
|
||||
if(!preExisting) {
|
||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||
|
||||
ProcessList_add(super, &proc->super);
|
||||
}
|
||||
}
|
||||
|
||||
free(ps);
|
||||
}
|
45
darwin/DarwinProcessList.h
Normal file
45
darwin/DarwinProcessList.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_DarwinProcessList
|
||||
#define HEADER_DarwinProcessList
|
||||
/*
|
||||
htop - DarwinProcessList.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include <mach/mach_host.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
typedef struct DarwinProcessList_ {
|
||||
ProcessList super;
|
||||
|
||||
host_basic_info_data_t host_info;
|
||||
vm_statistics_data_t vm_stats;
|
||||
processor_cpu_load_info_t prev_load;
|
||||
processor_cpu_load_info_t curr_load;
|
||||
uint64_t kernel_threads;
|
||||
uint64_t user_threads;
|
||||
uint64_t global_diff;
|
||||
} DarwinProcessList;
|
||||
|
||||
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
||||
|
||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
||||
|
||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p);
|
||||
|
||||
void ProcessList_getVMStats(vm_statistics_t p);
|
||||
|
||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count);
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
void ProcessList_delete(ProcessList* this);
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* super);
|
||||
|
||||
#endif
|
293
darwin/Platform.c
Normal file
293
darwin/Platform.c
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
htop - darwin/Platform.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2015 David C. Hunt
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Platform.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "MemoryMeter.h"
|
||||
#include "SwapMeter.h"
|
||||
#include "TasksMeter.h"
|
||||
#include "LoadAverageMeter.h"
|
||||
#include "ClockMeter.h"
|
||||
#include "HostnameMeter.h"
|
||||
#include "UptimeMeter.h"
|
||||
#include "DarwinProcessList.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/*{
|
||||
#include "Action.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "DarwinProcess.h"
|
||||
}*/
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
|
||||
SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
{ .name = " 3 SIGQUIT", .number = 3 },
|
||||
{ .name = " 4 SIGILL", .number = 4 },
|
||||
{ .name = " 5 SIGTRAP", .number = 5 },
|
||||
{ .name = " 6 SIGABRT", .number = 6 },
|
||||
{ .name = " 6 SIGIOT", .number = 6 },
|
||||
{ .name = " 7 SIGEMT", .number = 7 },
|
||||
{ .name = " 8 SIGFPE", .number = 8 },
|
||||
{ .name = " 9 SIGKILL", .number = 9 },
|
||||
{ .name = "10 SIGBUS", .number = 10 },
|
||||
{ .name = "11 SIGSEGV", .number = 11 },
|
||||
{ .name = "12 SIGSYS", .number = 12 },
|
||||
{ .name = "13 SIGPIPE", .number = 13 },
|
||||
{ .name = "14 SIGALRM", .number = 14 },
|
||||
{ .name = "15 SIGTERM", .number = 15 },
|
||||
{ .name = "16 SIGURG", .number = 16 },
|
||||
{ .name = "17 SIGSTOP", .number = 17 },
|
||||
{ .name = "18 SIGTSTP", .number = 18 },
|
||||
{ .name = "19 SIGCONT", .number = 19 },
|
||||
{ .name = "20 SIGCHLD", .number = 20 },
|
||||
{ .name = "21 SIGTTIN", .number = 21 },
|
||||
{ .name = "22 SIGTTOU", .number = 22 },
|
||||
{ .name = "23 SIGIO", .number = 23 },
|
||||
{ .name = "24 SIGXCPU", .number = 24 },
|
||||
{ .name = "25 SIGXFSZ", .number = 25 },
|
||||
{ .name = "26 SIGVTALRM", .number = 26 },
|
||||
{ .name = "27 SIGPROF", .number = 27 },
|
||||
{ .name = "28 SIGWINCH", .number = 28 },
|
||||
{ .name = "29 SIGINFO", .number = 29 },
|
||||
{ .name = "30 SIGUSR1", .number = 30 },
|
||||
{ .name = "31 SIGUSR2", .number = 31 },
|
||||
};
|
||||
|
||||
unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
ProcessFieldData Process_fields[] = {
|
||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
|
||||
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||
[SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", .flags = 0, },
|
||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
|
||||
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
|
||||
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
|
||||
|
||||
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
||||
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||
[100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||
};
|
||||
|
||||
MeterClass* Platform_meterTypes[] = {
|
||||
&CPUMeter_class,
|
||||
&ClockMeter_class,
|
||||
&LoadAverageMeter_class,
|
||||
&LoadMeter_class,
|
||||
&MemoryMeter_class,
|
||||
&SwapMeter_class,
|
||||
&TasksMeter_class,
|
||||
&BatteryMeter_class,
|
||||
&HostnameMeter_class,
|
||||
&UptimeMeter_class,
|
||||
&AllCPUsMeter_class,
|
||||
&AllCPUs2Meter_class,
|
||||
&LeftCPUsMeter_class,
|
||||
&RightCPUsMeter_class,
|
||||
&LeftCPUs2Meter_class,
|
||||
&RightCPUs2Meter_class,
|
||||
&BlankMeter_class,
|
||||
NULL
|
||||
};
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys) {
|
||||
(void) keys;
|
||||
}
|
||||
|
||||
int Platform_numberOfFields = 100;
|
||||
|
||||
int Platform_getUptime() {
|
||||
struct timeval bootTime, currTime;
|
||||
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
|
||||
size_t size = sizeof(bootTime);
|
||||
|
||||
int err = sysctl(mib, 2, &bootTime, &size, NULL, 0);
|
||||
if (err) {
|
||||
return -1;
|
||||
}
|
||||
gettimeofday(&currTime, NULL);
|
||||
|
||||
return (int) difftime(currTime.tv_sec, bootTime.tv_sec);
|
||||
}
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||
double results[3];
|
||||
|
||||
if(3 == getloadavg(results, 3)) {
|
||||
*one = results[0];
|
||||
*five = results[1];
|
||||
*fifteen = results[2];
|
||||
} else {
|
||||
*one = 0;
|
||||
*five = 0;
|
||||
*fifteen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Platform_getMaxPid() {
|
||||
/* http://opensource.apple.com/source/xnu/xnu-2782.1.97/bsd/sys/proc_internal.hh */
|
||||
return 99999;
|
||||
}
|
||||
|
||||
ProcessPidColumn Process_pidColumns[] = {
|
||||
{ .id = PID, .label = "PID" },
|
||||
{ .id = PPID, .label = "PPID" },
|
||||
{ .id = TPGID, .label = "TPGID" },
|
||||
{ .id = TGID, .label = "TGID" },
|
||||
{ .id = PGRP, .label = "PGRP" },
|
||||
{ .id = SESSION, .label = "SESN" },
|
||||
{ .id = 0, .label = NULL },
|
||||
};
|
||||
|
||||
static double Platform_setCPUAverageValues(Meter* mtr) {
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
|
||||
int cpus = dpl->super.cpuCount;
|
||||
double sumNice = 0.0;
|
||||
double sumNormal = 0.0;
|
||||
double sumKernel = 0.0;
|
||||
double sumPercent = 0.0;
|
||||
for (int i = 1; i <= cpus; i++) {
|
||||
sumPercent += Platform_setCPUValues(mtr, i);
|
||||
sumNice += mtr->values[CPU_METER_NICE];
|
||||
sumNormal += mtr->values[CPU_METER_NORMAL];
|
||||
sumKernel += mtr->values[CPU_METER_KERNEL];
|
||||
}
|
||||
mtr->values[CPU_METER_NICE] = sumNice / cpus;
|
||||
mtr->values[CPU_METER_NORMAL] = sumNormal / cpus;
|
||||
mtr->values[CPU_METER_KERNEL] = sumKernel / cpus;
|
||||
return sumPercent / cpus;
|
||||
}
|
||||
|
||||
double Platform_setCPUValues(Meter* mtr, int cpu) {
|
||||
|
||||
if (cpu == 0) {
|
||||
return Platform_setCPUAverageValues(mtr);
|
||||
}
|
||||
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
|
||||
processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1];
|
||||
processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1];
|
||||
double total = 0;
|
||||
|
||||
/* Take the sums */
|
||||
for(size_t i = 0; i < CPU_STATE_MAX; ++i) {
|
||||
total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i];
|
||||
}
|
||||
|
||||
mtr->values[CPU_METER_NICE]
|
||||
= ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total;
|
||||
mtr->values[CPU_METER_NORMAL]
|
||||
= ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total;
|
||||
mtr->values[CPU_METER_KERNEL]
|
||||
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total;
|
||||
|
||||
Meter_setItems(mtr, 3);
|
||||
|
||||
/* Convert to percent and return */
|
||||
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
||||
|
||||
return CLAMP(total, 0.0, 100.0);
|
||||
}
|
||||
|
||||
void Platform_setMemoryValues(Meter* mtr) {
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
|
||||
vm_statistics_t vm = &dpl->vm_stats;
|
||||
double page_K = (double)vm_page_size / (double)1024;
|
||||
|
||||
mtr->total = dpl->host_info.max_mem / 1024;
|
||||
mtr->values[0] = (double)(vm->active_count + vm->wire_count) * page_K;
|
||||
mtr->values[1] = (double)vm->purgeable_count * page_K;
|
||||
mtr->values[2] = (double)vm->inactive_count * page_K;
|
||||
}
|
||||
|
||||
void Platform_setSwapValues(Meter* mtr) {
|
||||
int mib[2] = {CTL_VM, VM_SWAPUSAGE};
|
||||
struct xsw_usage swapused;
|
||||
size_t swlen = sizeof(swapused);
|
||||
sysctl(mib, 2, &swapused, &swlen, NULL, 0);
|
||||
|
||||
mtr->total = swapused.xsu_total / 1024;
|
||||
mtr->values[0] = swapused.xsu_used / 1024;
|
||||
}
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid) {
|
||||
char* env = NULL;
|
||||
|
||||
int argmax;
|
||||
size_t bufsz = sizeof(argmax);
|
||||
|
||||
int mib[3];
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_ARGMAX;
|
||||
if (sysctl(mib, 2, &argmax, &bufsz, 0, 0) == 0) {
|
||||
char* buf = xMalloc(argmax);
|
||||
if (buf) {
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROCARGS2;
|
||||
mib[2] = pid;
|
||||
size_t bufsz = argmax;
|
||||
if (sysctl(mib, 3, buf, &bufsz, 0, 0) == 0) {
|
||||
if (bufsz > sizeof(int)) {
|
||||
char *p = buf, *endp = buf + bufsz;
|
||||
int argc = *(int*)p;
|
||||
p += sizeof(int);
|
||||
|
||||
// skip exe
|
||||
p = strchr(p, 0)+1;
|
||||
|
||||
// skip padding
|
||||
while(!*p && p < endp)
|
||||
++p;
|
||||
|
||||
// skip argv
|
||||
for (; argc-- && p < endp; p = strrchr(p, 0)+1)
|
||||
;
|
||||
|
||||
// skip padding
|
||||
while(!*p && p < endp)
|
||||
++p;
|
||||
|
||||
size_t size = endp - p;
|
||||
env = xMalloc(size+2);
|
||||
memcpy(env, p, size);
|
||||
env[size] = 0;
|
||||
env[size+1] = 0;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
53
darwin/Platform.h
Normal file
53
darwin/Platform.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Platform
|
||||
#define HEADER_Platform
|
||||
/*
|
||||
htop - darwin/Platform.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2015 David C. Hunt
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Action.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "DarwinProcess.h"
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern SignalItem Platform_signals[];
|
||||
|
||||
extern unsigned int Platform_numberOfSignals;
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
extern MeterClass* Platform_meterTypes[];
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
int Platform_getUptime();
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||
|
||||
int Platform_getMaxPid();
|
||||
|
||||
extern ProcessPidColumn Process_pidColumns[];
|
||||
|
||||
double Platform_setCPUValues(Meter* mtr, int cpu);
|
||||
|
||||
void Platform_setMemoryValues(Meter* mtr);
|
||||
|
||||
void Platform_setSwapValues(Meter* mtr);
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid);
|
||||
|
||||
#endif
|
25
freebsd/Battery.c
Normal file
25
freebsd/Battery.c
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
htop - freebsd/Battery.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "BatteryMeter.h"
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
int life;
|
||||
size_t life_len = sizeof(life);
|
||||
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
||||
*level = -1;
|
||||
else
|
||||
*level = life;
|
||||
|
||||
int acline;
|
||||
size_t acline_len = sizeof(acline);
|
||||
if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1)
|
||||
*isOnAC = AC_ERROR;
|
||||
else
|
||||
*isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT;
|
||||
}
|
14
freebsd/Battery.h
Normal file
14
freebsd/Battery.h
Normal file
@ -0,0 +1,14 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Battery
|
||||
#define HEADER_Battery
|
||||
/*
|
||||
htop - freebsd/Battery.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
21
freebsd/FreeBSDCRT.c
Normal file
21
freebsd/FreeBSDCRT.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
htop - UnsupportedCRT.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "CRT.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn) {
|
||||
(void) sgn;
|
||||
CRT_done();
|
||||
fprintf(stderr, "\n\nhtop " VERSION " aborting.\n");
|
||||
fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!");
|
||||
fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n");
|
||||
abort();
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user