mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 21:44:36 +03:00
Compare commits
226 Commits
Author | SHA1 | Date | |
---|---|---|---|
c50440f165 | |||
b0588d90ff | |||
b84ebfd4e8 | |||
b86e14d3cf | |||
b34d76cd41 | |||
87be623eac | |||
b27712181a | |||
ad99187680 | |||
b7b66b76a5 | |||
52831955c7 | |||
ef34a83c54 | |||
4c1230b03b | |||
e3f65c8ec2 | |||
b9934ffa08 | |||
65ec0bd6a6 | |||
584a9bceab | |||
9487bda330 | |||
4300a19592 | |||
60acda0bce | |||
09e241fb12 | |||
3975e9ce5c | |||
821d50f0b4 | |||
543d65c6ab | |||
f205f7004c | |||
ef7817c17a | |||
33fda93271 | |||
ce0cf3c457 | |||
d5faf64374 | |||
18b3e5d255 | |||
143a7de6b2 | |||
e940aecfb9 | |||
1a178ad581 | |||
c39f18a7be | |||
978c9e1698 | |||
e70f447d54 | |||
71785e2ded | |||
e9ecbd05bc | |||
89d15399c5 | |||
e03e45d819 | |||
45f3769887 | |||
2d8dd0b29e | |||
b1028e03c5 | |||
0c168471b6 | |||
68b8efb83f | |||
418fea33f4 | |||
975e22144e | |||
50f03f5950 | |||
cb7a06379d | |||
cba695961a | |||
49af12e7c6 | |||
b258d6e53e | |||
e0e84401e4 | |||
5570748dd2 | |||
3c09082422 | |||
53d7c66ac3 | |||
3b1260ac3d | |||
fa30938247 | |||
bb8dec1582 | |||
aa813c7561 | |||
3f6d1262c0 | |||
84bc00a275 | |||
6141edc74b | |||
2b5c1b4b13 | |||
8af4d9f453 | |||
8a147dd5b4 | |||
5df425867c | |||
46d8f2eef2 | |||
8fd6228bc1 | |||
0ce4835f95 | |||
823481ae22 | |||
96157870af | |||
5a5a7c8d6b | |||
07086fcf77 | |||
6d4df3d138 | |||
d4a8023b72 | |||
99f7ff9bd2 | |||
1f3d85b617 | |||
cceab15b9d | |||
bd5d37f297 | |||
16406ea330 | |||
d3f575264b | |||
bf35921abb | |||
b269eb24b0 | |||
3d9868833e | |||
3cd0339423 | |||
ef879b4a22 | |||
f161365d72 | |||
6b9b6db655 | |||
f80e577c59 | |||
81552d4ab5 | |||
0108117d0b | |||
a41c9b3925 | |||
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 |
8
.gitignore
vendored
8
.gitignore
vendored
@ -4,6 +4,12 @@ htop
|
||||
# all object files
|
||||
*.o
|
||||
|
||||
# skip all backups
|
||||
*.bak
|
||||
*~
|
||||
.*.sw?
|
||||
|
||||
# skip coverage files
|
||||
*.gcda
|
||||
*/*.gcda
|
||||
*.gcno
|
||||
@ -22,6 +28,7 @@ config.h
|
||||
config.h.in
|
||||
config.log
|
||||
config.status
|
||||
config.cache
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
@ -32,4 +39,3 @@ ltmain.sh
|
||||
m4/
|
||||
missing
|
||||
stamp-h1
|
||||
|
||||
|
25
Action.c
25
Action.c
@ -142,7 +142,7 @@ static void tagAllChildren(Panel* panel, Process* parent) {
|
||||
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) {
|
||||
if (!p->tag && Process_isChildOf(p, ppid)) {
|
||||
tagAllChildren(panel, p);
|
||||
}
|
||||
}
|
||||
@ -271,7 +271,7 @@ static Htop_Reaction actionQuit() {
|
||||
static Htop_Reaction actionSetAffinity(State* st) {
|
||||
if (st->pl->cpuCount == 1)
|
||||
return HTOP_OK;
|
||||
#if (HAVE_LIBHWLOC || HAVE_NATIVE_AFFINITY)
|
||||
#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY)
|
||||
Panel* panel = st->panel;
|
||||
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
@ -328,7 +328,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionFollow(State* st) {
|
||||
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;
|
||||
@ -381,12 +381,13 @@ static Htop_Reaction actionRedraw() {
|
||||
return HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
|
||||
static struct { const char* key; const char* info; } helpLeft[] = {
|
||||
static const 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" },
|
||||
@ -394,26 +395,26 @@ static struct { const char* key; const char* info; } helpLeft[] = {
|
||||
{ .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 = " F6 > .: ", .info = "select sort column" },
|
||||
{ .key = NULL, .info = NULL }
|
||||
};
|
||||
|
||||
static struct { const char* key; const char* info; } helpRight[] = {
|
||||
static const 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_NATIVE_AFFINITY)
|
||||
#if (HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY)
|
||||
{ .key = " a: ", .info = "set CPU affinity" },
|
||||
#endif
|
||||
{ .key = " e: ", .info = "show process environment" },
|
||||
{ .key = " i: ", .info = "set IO prority" },
|
||||
{ .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 = " F2 C S: ", .info = "setup" },
|
||||
{ .key = " F1 h: ", .info = "show this help screen" },
|
||||
{ .key = " F10 q: ", .info = "quit" },
|
||||
{ .key = NULL, .info = NULL }
|
||||
@ -479,8 +480,8 @@ static Htop_Reaction actionHelp(State* st) {
|
||||
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(15, 32, "threads");
|
||||
mvaddstr(16, 26, "threads");
|
||||
mvaddstr(16, 32, "threads");
|
||||
mvaddstr(17, 26, "threads");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
@ -556,7 +557,7 @@ void Action_setBindings(Htop_Action* keys) {
|
||||
keys['='] = actionExpandOrCollapse;
|
||||
keys['-'] = actionExpandOrCollapse;
|
||||
keys['u'] = actionFilterByUser;
|
||||
keys['F'] = actionFollow;
|
||||
keys['F'] = Action_follow;
|
||||
keys['S'] = actionSetup;
|
||||
keys['C'] = actionSetup;
|
||||
keys[KEY_F(2)] = actionSetup;
|
||||
|
2
Action.h
2
Action.h
@ -49,6 +49,8 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
Htop_Reaction Action_follow(State* st);
|
||||
|
||||
|
||||
void Action_setBindings(Htop_Action* keys);
|
||||
|
||||
|
19
Affinity.c
19
Affinity.c
@ -10,8 +10,13 @@ in the source distribution for its full text.
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#include <hwloc/linux.h>
|
||||
#elif HAVE_NATIVE_AFFINITY
|
||||
#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
|
||||
|
||||
@ -55,7 +60,7 @@ void Affinity_add(Affinity* this, int id) {
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||
bool ok = (hwloc_linux_get_tid_cpubind(pl->topology, proc->pid, cpuset) == 0);
|
||||
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);
|
||||
@ -76,15 +81,15 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||
|
||||
bool Affinity_set(Process* proc, Affinity* this) {
|
||||
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
|
||||
for (int i = 0; i < affinity->used; i++) {
|
||||
hwloc_bitmap_set(cpuset, affinity->cpus[i]);
|
||||
for (int i = 0; i < this->used; i++) {
|
||||
hwloc_bitmap_set(cpuset, this->cpus[i]);
|
||||
}
|
||||
bool ok = (hwloc_linux_set_tid_cpubind(this->pl->topology, proc->pid, cpuset) == 0);
|
||||
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_NATIVE_AFFINITY
|
||||
#elif HAVE_LINUX_AFFINITY
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl) {
|
||||
cpu_set_t cpuset;
|
||||
|
@ -10,7 +10,12 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#elif HAVE_NATIVE_AFFINITY
|
||||
#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"
|
||||
@ -36,7 +41,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||
|
||||
bool Affinity_set(Process* proc, Affinity* this);
|
||||
|
||||
#elif HAVE_NATIVE_AFFINITY
|
||||
#elif HAVE_LINUX_AFFINITY
|
||||
|
||||
Affinity* Affinity_get(Process* proc, ProcessList* pl);
|
||||
|
||||
|
@ -52,7 +52,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
||||
int curCpu = 0;
|
||||
for (int i = 0; i < pl->cpuCount; i++) {
|
||||
char number[10];
|
||||
snprintf(number, 9, "%d", Settings_cpuId(pl->settings, i));
|
||||
xSnprintf(number, 9, "%d", Settings_cpuId(pl->settings, i));
|
||||
bool mode;
|
||||
if (curCpu < affinity->used && affinity->cpus[curCpu] == i) {
|
||||
mode = true;
|
||||
|
@ -26,7 +26,7 @@ typedef struct AvailableColumnsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
|
||||
static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static void AvailableColumnsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
@ -81,7 +81,7 @@ AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) {
|
||||
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);
|
||||
xSnprintf(description, sizeof(description), "%s - %s", Process_fields[i].name, Process_fields[i].description);
|
||||
Panel_add(super, (Object*) ListItem_new(description, i));
|
||||
}
|
||||
}
|
||||
|
@ -112,20 +112,22 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
|
||||
this->scr = scr;
|
||||
|
||||
Panel_setHeader(super, "Available meters");
|
||||
// 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];
|
||||
if (type != &CPUMeter_class) {
|
||||
const char* label = type->description ? type->description : type->uiName;
|
||||
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
||||
}
|
||||
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 = 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);
|
||||
xSnprintf(buffer, 50, "%s %d", type->uiName, i);
|
||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||
}
|
||||
} else {
|
||||
|
@ -32,7 +32,7 @@ int BatteryMeter_attributes[] = {
|
||||
BATTERY
|
||||
};
|
||||
|
||||
static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
||||
static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) {
|
||||
ACPresence isOnAC;
|
||||
double percent;
|
||||
|
||||
@ -40,7 +40,7 @@ static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
||||
|
||||
if (percent == -1) {
|
||||
this->values[0] = 0;
|
||||
snprintf(buffer, len, "n/a");
|
||||
xSnprintf(buffer, len, "n/a");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -58,11 +58,11 @@ static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
|
||||
}
|
||||
|
||||
if (isOnAC == AC_PRESENT) {
|
||||
snprintf(buffer, len, onAcText, percent);
|
||||
xSnprintf(buffer, len, onAcText, percent);
|
||||
} else if (isOnAC == AC_ABSENT) {
|
||||
snprintf(buffer, len, onBatteryText, percent);
|
||||
xSnprintf(buffer, len, onBatteryText, percent);
|
||||
} else {
|
||||
snprintf(buffer, len, unknownText, percent);
|
||||
xSnprintf(buffer, len, unknownText, percent);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -73,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",
|
||||
|
34
CPUMeter.c
34
CPUMeter.c
@ -48,22 +48,22 @@ static void CPUMeter_init(Meter* this) {
|
||||
int cpu = this->param;
|
||||
if (this->pl->cpuCount > 1) {
|
||||
char caption[10];
|
||||
sprintf(caption, "%-3d", Settings_cpuId(this->pl->settings, cpu - 1));
|
||||
xSnprintf(caption, sizeof(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) {
|
||||
static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int cpu = this->param;
|
||||
if (cpu > this->pl->cpuCount) {
|
||||
snprintf(buffer, size, "absent");
|
||||
xSnprintf(buffer, size, "absent");
|
||||
return;
|
||||
}
|
||||
memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT);
|
||||
double percent = Platform_setCPUValues(this, cpu);
|
||||
snprintf(buffer, size, "%5.1f%%", percent);
|
||||
xSnprintf(buffer, size, "%5.1f%%", percent);
|
||||
}
|
||||
|
||||
static void CPUMeter_display(Object* cast, RichString* out) {
|
||||
@ -74,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[CPU_METER_NORMAL]);
|
||||
xSnprintf(buffer, sizeof(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->settings->detailedCPUTime) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
|
||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "ni:");
|
||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||
xSnprintf(buffer, sizeof(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[CPU_METER_SOFTIRQ]);
|
||||
xSnprintf(buffer, sizeof(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[CPU_METER_STEAL]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_STEAL]);
|
||||
xSnprintf(buffer, sizeof(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[CPU_METER_GUEST]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_GUEST]);
|
||||
xSnprintf(buffer, sizeof(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[CPU_METER_IOWAIT]);
|
||||
xSnprintf(buffer, sizeof(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[CPU_METER_KERNEL]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_KERNEL]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
|
||||
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "low:");
|
||||
RichString_append(out, CRT_colors[CPU_NICE_TEXT], buffer);
|
||||
if (this->values[CPU_METER_IRQ]) {
|
||||
sprintf(buffer, "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_IRQ]);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "vir:");
|
||||
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
|
||||
}
|
||||
@ -215,7 +215,7 @@ MeterClass CPUMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = CPUMeter_display
|
||||
},
|
||||
.setValues = CPUMeter_setValues,
|
||||
.updateValues = CPUMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = CPU_METER_ITEMCOUNT,
|
||||
.total = 100.0,
|
||||
@ -312,8 +312,8 @@ MeterClass LeftCPUs2Meter_class = {
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "LeftCPUs2",
|
||||
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
||||
.uiName = "CPUs (1&2/4)",
|
||||
.description = "CPUs (1&2/4): first half in 2 shorter columns",
|
||||
.caption = "CPU",
|
||||
.draw = DualColCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
|
92
CRT.c
92
CRT.c
@ -5,6 +5,7 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
@ -17,8 +18,14 @@ in the source distribution for its full text.
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <langinfo.h>
|
||||
#if HAVE_SETUID_ENABLED
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||
#define ColorIndex(i,j) ((7-i)*8+j)
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j))
|
||||
|
||||
#define Black COLOR_BLACK
|
||||
#define Red COLOR_RED
|
||||
@ -29,6 +36,8 @@ in the source distribution for its full text.
|
||||
#define Cyan COLOR_CYAN
|
||||
#define White COLOR_WHITE
|
||||
|
||||
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
||||
|
||||
#define KEY_WHEELUP KEY_F(20)
|
||||
#define KEY_WHEELDOWN KEY_F(21)
|
||||
#define KEY_RECLICK KEY_F(22)
|
||||
@ -125,6 +134,8 @@ void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||
|
||||
}*/
|
||||
|
||||
const char *CRT_treeStrAscii[TREE_STR_COUNT] = {
|
||||
@ -181,7 +192,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[LED_COLOR] = ColorPair(Green,Black),
|
||||
[TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
|
||||
[PROCESS] = A_NORMAL,
|
||||
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
||||
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
|
||||
[PROCESS_MEGABYTES] = ColorPair(Cyan,Black),
|
||||
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black),
|
||||
@ -193,7 +204,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_THREAD] = ColorPair(Green,Black),
|
||||
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black),
|
||||
[BAR_BORDER] = A_BOLD,
|
||||
[BAR_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
||||
[BAR_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||
[SWAP] = ColorPair(Red,Black),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan,Black),
|
||||
[GRAPH_2] = ColorPair(Cyan,Black),
|
||||
@ -358,7 +369,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[LED_COLOR] = ColorPair(Green,Black),
|
||||
[TASKS_RUNNING] = ColorPair(Green,Black),
|
||||
[PROCESS] = ColorPair(Black,Black),
|
||||
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
||||
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||
[PROCESS_TAG] = ColorPair(White,Blue),
|
||||
[PROCESS_MEGABYTES] = ColorPair(Blue,Black),
|
||||
[PROCESS_BASENAME] = ColorPair(Green,Black),
|
||||
@ -370,7 +381,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[PROCESS_THREAD] = ColorPair(Blue,Black),
|
||||
[PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black),
|
||||
[BAR_BORDER] = ColorPair(Blue,Black),
|
||||
[BAR_SHADOW] = ColorPair(Black,Black),
|
||||
[BAR_SHADOW] = ColorPairGrayBlack,
|
||||
[SWAP] = ColorPair(Red,Black),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan,Black),
|
||||
[GRAPH_2] = ColorPair(Cyan,Black),
|
||||
@ -476,7 +487,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
||||
[LED_COLOR] = ColorPair(Green,Black),
|
||||
[TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
|
||||
[PROCESS] = ColorPair(Cyan,Black),
|
||||
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
|
||||
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
|
||||
[PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black),
|
||||
[PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black),
|
||||
@ -539,6 +550,48 @@ static void CRT_handleSIGTERM(int sgn) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#if HAVE_SETUID_ENABLED
|
||||
|
||||
static int CRT_euid = -1;
|
||||
|
||||
static int CRT_egid = -1;
|
||||
|
||||
#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
|
||||
|
||||
void CRT_dropPrivileges() {
|
||||
CRT_egid = getegid();
|
||||
CRT_euid = geteuid();
|
||||
if (setegid(getgid()) == -1) {
|
||||
DIE("Fatal error: failed dropping group privileges.\n");
|
||||
}
|
||||
if (seteuid(getuid()) == -1) {
|
||||
DIE("Fatal error: failed dropping user privileges.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void CRT_restorePrivileges() {
|
||||
if (CRT_egid == -1 || CRT_euid == -1) {
|
||||
DIE("Fatal error: internal inconsistency.\n");
|
||||
}
|
||||
if (setegid(CRT_egid) == -1) {
|
||||
DIE("Fatal error: failed restoring group privileges.\n");
|
||||
}
|
||||
if (seteuid(CRT_euid) == -1) {
|
||||
DIE("Fatal error: failed restoring user privileges.\n");
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Turn setuid operations into NOPs */
|
||||
|
||||
#ifndef CRT_dropPrivileges
|
||||
#define CRT_dropPrivileges()
|
||||
#define CRT_restorePrivileges()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// TODO: pass an instance of Settings instead.
|
||||
|
||||
void CRT_init(int delay, int colorScheme) {
|
||||
@ -553,7 +606,7 @@ void CRT_init(int delay, int colorScheme) {
|
||||
|
||||
for (int i = 0; i < LAST_COLORELEMENT; i++) {
|
||||
unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i];
|
||||
CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPair(Black,Black)) ? ColorPair(White,Black) : color;
|
||||
CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White,Black) : color;
|
||||
}
|
||||
|
||||
halfdelay(CRT_delay);
|
||||
@ -573,7 +626,7 @@ void CRT_init(int delay, int colorScheme) {
|
||||
CRT_scrollHAmount = 20;
|
||||
else
|
||||
CRT_scrollHAmount = 5;
|
||||
if (String_eq(CRT_termType, "xterm") || String_eq(CRT_termType, "xterm-color") || String_eq(CRT_termType, "vt220")) {
|
||||
if (String_startsWith(CRT_termType, "xterm") || String_eq(CRT_termType, "vt220")) {
|
||||
define_key("\033[H", KEY_HOME);
|
||||
define_key("\033[F", KEY_END);
|
||||
define_key("\033[7~", KEY_HOME);
|
||||
@ -587,11 +640,17 @@ void CRT_init(int delay, int colorScheme) {
|
||||
define_key("\033[13~", KEY_F(3));
|
||||
define_key("\033[14~", KEY_F(4));
|
||||
define_key("\033[17;2~", KEY_F(18));
|
||||
char sequence[3] = "\033a";
|
||||
for (char c = 'a'; c <= 'z'; c++) {
|
||||
sequence[1] = c;
|
||||
define_key(sequence, KEY_ALT('A' + (c - 'a')));
|
||||
}
|
||||
}
|
||||
#ifndef DEBUG
|
||||
signal(11, CRT_handleSIGSEGV);
|
||||
#endif
|
||||
signal(SIGTERM, CRT_handleSIGTERM);
|
||||
signal(SIGQUIT, CRT_handleSIGTERM);
|
||||
use_default_colors();
|
||||
if (!has_colors())
|
||||
CRT_colorScheme = 1;
|
||||
@ -618,6 +677,7 @@ void CRT_init(int delay, int colorScheme) {
|
||||
#else
|
||||
mousemask(BUTTON1_RELEASED, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void CRT_done() {
|
||||
@ -655,12 +715,20 @@ void CRT_setColors(int colorScheme) {
|
||||
CRT_colorScheme = colorScheme;
|
||||
if (colorScheme == COLORSCHEME_BLACKNIGHT) {
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 8; j++)
|
||||
init_pair((7-i)*8+j, i, j);
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if (ColorIndex(i,j) != ColorIndex(Magenta,Magenta)) {
|
||||
init_pair(ColorIndex(i,j), i, j);
|
||||
}
|
||||
}
|
||||
init_pair(ColorIndex(Magenta,Magenta), 8, 0);
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 8; j++)
|
||||
init_pair((7-i)*8+j, i, (j==0?-1:j));
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if (ColorIndex(i,j) != ColorIndex(Magenta,Magenta)) {
|
||||
init_pair(ColorIndex(i,j), i, (j==0?-1:j));
|
||||
}
|
||||
}
|
||||
init_pair(ColorIndex(Magenta,Magenta), 8, -1);
|
||||
}
|
||||
CRT_colors = CRT_colorSchemes[colorScheme];
|
||||
}
|
||||
|
30
CRT.h
30
CRT.h
@ -9,7 +9,12 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR((7-i)*8+j)
|
||||
#if HAVE_SETUID_ENABLED
|
||||
#endif
|
||||
|
||||
#define ColorIndex(i,j) ((7-i)*8+j)
|
||||
|
||||
#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j))
|
||||
|
||||
#define Black COLOR_BLACK
|
||||
#define Red COLOR_RED
|
||||
@ -20,6 +25,8 @@ in the source distribution for its full text.
|
||||
#define Cyan COLOR_CYAN
|
||||
#define White COLOR_WHITE
|
||||
|
||||
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
||||
|
||||
#define KEY_WHEELUP KEY_F(20)
|
||||
#define KEY_WHEELDOWN KEY_F(21)
|
||||
#define KEY_RECLICK KEY_F(22)
|
||||
@ -115,6 +122,8 @@ void CRT_fatalError(const char* note) __attribute__ ((noreturn));
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))
|
||||
|
||||
|
||||
extern const char *CRT_treeStrAscii[TREE_STR_COUNT];
|
||||
|
||||
@ -148,6 +157,25 @@ extern int CRT_colorScheme;
|
||||
|
||||
void *backtraceArray[128];
|
||||
|
||||
#if HAVE_SETUID_ENABLED
|
||||
|
||||
#define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0)
|
||||
|
||||
void CRT_dropPrivileges();
|
||||
|
||||
void CRT_restorePrivileges();
|
||||
|
||||
#else
|
||||
|
||||
/* Turn setuid operations into NOPs */
|
||||
|
||||
#ifndef CRT_dropPrivileges
|
||||
#define CRT_dropPrivileges()
|
||||
#define CRT_restorePrivileges()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// TODO: pass an instance of Settings instead.
|
||||
|
||||
void CRT_init(int delay, int colorScheme);
|
||||
|
@ -34,7 +34,7 @@ typedef struct CategoriesPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static void CategoriesPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
@ -82,9 +82,9 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
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:
|
||||
|
64
ChangeLog
64
ChangeLog
@ -1,4 +1,68 @@
|
||||
|
||||
What's new in version 2.1.0
|
||||
|
||||
* Linux: Delay accounting metrics
|
||||
(thanks to André Carvalho)
|
||||
* DragonFlyBSD support
|
||||
(thanks to Diederik de Groot)
|
||||
* Support for real-time signals
|
||||
(thanks to Kang-Che Sung)
|
||||
* 'c' key now works with threads as well
|
||||
* Session column renamed from SESN to SID
|
||||
(thanks to Kamyar Rasta)
|
||||
* Improved UI for meter style selection
|
||||
(thanks to Kang-Che Sung)
|
||||
* Improved code for constructing process tree
|
||||
(thanks to wangqr)
|
||||
* Compile-time option to disable setuid
|
||||
* Error checking of various standard library operations
|
||||
* Replacement of sprintf with snprintf
|
||||
(thanks to Tomasz Kramkowski)
|
||||
* Linux: performance improvements in battery meter
|
||||
* Linux: update process TTY device
|
||||
* Linux: add support for sorting TASK_IDLE
|
||||
(thanks to Vladimir Panteleev)
|
||||
* Linux: add upper-bound to running process counter
|
||||
(thanks to Lucas Correia Villa Real)
|
||||
* BUGFIX: avoid crash when battery is removed
|
||||
(thanks to Jan Chren)
|
||||
* BUGFIX: macOS: fix infinite loop in tree view
|
||||
(thanks to Wataru Ashihara)
|
||||
|
||||
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
|
||||
|
@ -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,8 +32,9 @@ MeterClass ClockMeter_class = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete
|
||||
},
|
||||
.setValues = ClockMeter_setValues,
|
||||
.updateValues = ClockMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 1440, /* 24*60 */
|
||||
.attributes = ClockMeter_attributes,
|
||||
.name = "Clock",
|
||||
|
@ -34,9 +34,9 @@ typedef struct ColorsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static const char* ColorSchemeNames[] = {
|
||||
static const char* const ColorSchemeNames[] = {
|
||||
"Default",
|
||||
"Monochromatic",
|
||||
"Black on White",
|
||||
|
@ -29,7 +29,7 @@ typedef struct ColumnsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||
static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
|
||||
|
||||
static void ColumnsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
@ -65,8 +65,8 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
/* else fallthrough */
|
||||
case KEY_F(7):
|
||||
case '[':
|
||||
case '-':
|
||||
@ -81,8 +81,8 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
/* else fallthrough */
|
||||
case KEY_F(8):
|
||||
case ']':
|
||||
case '+':
|
||||
|
@ -28,7 +28,7 @@ typedef struct DisplayOptionsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
||||
|
||||
static void DisplayOptionsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
|
@ -48,10 +48,9 @@ void EnvScreen_scan(InfoScreen* this) {
|
||||
|
||||
Panel_prune(panel);
|
||||
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
char *env = Platform_getProcessEnv(this->process->pid);
|
||||
seteuid(euid);
|
||||
CRT_dropPrivileges();
|
||||
char* env = Platform_getProcessEnv(this->process->pid);
|
||||
CRT_restorePrivileges();
|
||||
if (env) {
|
||||
for (char *p = env; *p; p = strrchr(p, 0)+1)
|
||||
InfoScreen_addLine(this, p);
|
||||
|
@ -28,21 +28,21 @@ typedef struct FunctionBar_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};
|
||||
static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};
|
||||
|
||||
static const char* FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL};
|
||||
static const char* const FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL};
|
||||
|
||||
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)};
|
||||
|
||||
static const char* FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
|
||||
static int FunctionBar_EnterEscEvents[] = {13, 27};
|
||||
static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
|
||||
static const 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* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events) {
|
||||
FunctionBar* this = xCalloc(1, sizeof(FunctionBar));
|
||||
this->functions = xCalloc(16, sizeof(char*));
|
||||
if (!functions) {
|
||||
|
@ -24,7 +24,7 @@ typedef struct FunctionBar_ {
|
||||
|
||||
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
|
||||
|
||||
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events);
|
||||
FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events);
|
||||
|
||||
void FunctionBar_delete(FunctionBar* this);
|
||||
|
||||
|
8
Header.c
8
Header.c
@ -37,7 +37,7 @@ typedef struct Header_ {
|
||||
#endif
|
||||
|
||||
#ifndef Header_forEachColumn
|
||||
#define Header_forEachColumn(this_, i_) for (int i_=0; i_ < this->nrColumns; i_++)
|
||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||
#endif
|
||||
|
||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) {
|
||||
@ -91,9 +91,9 @@ void Header_writeBackToSettings(const Header* this) {
|
||||
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);
|
||||
xSnprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param);
|
||||
} else {
|
||||
snprintf(name, 63, "%s", As_Meter(meter)->name);
|
||||
xSnprintf(name, 63, "%s", As_Meter(meter)->name);
|
||||
}
|
||||
colSettings->names[i] = name;
|
||||
colSettings->modes[i] = meter->mode;
|
||||
@ -155,7 +155,7 @@ char* Header_readMeterName(Header* this, int i, int column) {
|
||||
strncpy(name, Meter_name(meter), nameLen);
|
||||
name[nameLen] = '\0';
|
||||
if (meter->param)
|
||||
snprintf(name + nameLen, len - nameLen, "(%d)", meter->param);
|
||||
xSnprintf(name + nameLen, len - nameLen, "(%d)", meter->param);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
2
Header.h
2
Header.h
@ -28,7 +28,7 @@ typedef struct Header_ {
|
||||
#endif
|
||||
|
||||
#ifndef Header_forEachColumn
|
||||
#define Header_forEachColumn(this_, i_) for (int i_=0; i_ < this->nrColumns; i_++)
|
||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||
#endif
|
||||
|
||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
||||
|
@ -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.
|
||||
|
||||
|
52
IncSet.c
52
IncSet.c
@ -40,6 +40,7 @@ typedef struct IncSet_ {
|
||||
IncMode* active;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
} IncSet;
|
||||
|
||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
@ -51,8 +52,8 @@ static void IncMode_reset(IncMode* mode) {
|
||||
mode->buffer[0] = 0;
|
||||
}
|
||||
|
||||
static const char* searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
||||
static const char* searchKeys[] = {"F3", "Esc", " "};
|
||||
static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
||||
static const char* const searchKeys[] = {"F3", "Esc", " "};
|
||||
static int searchEvents[] = {KEY_F(3), 27, ERR};
|
||||
|
||||
static inline void IncMode_initSearch(IncMode* search) {
|
||||
@ -61,8 +62,8 @@ static inline void IncMode_initSearch(IncMode* search) {
|
||||
search->isFilter = false;
|
||||
}
|
||||
|
||||
static const char* filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL};
|
||||
static const char* filterKeys[] = {"Enter", "Esc", " "};
|
||||
static const char* const filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL};
|
||||
static const char* const filterKeys[] = {"Enter", "Esc", " "};
|
||||
static int filterEvents[] = {13, 27, ERR};
|
||||
|
||||
static inline void IncMode_initFilter(IncMode* filter) {
|
||||
@ -114,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++) {
|
||||
@ -128,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) {
|
||||
@ -151,24 +153,30 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
}
|
||||
}
|
||||
doSearch = false;
|
||||
} else if (ch < 255 && isprint((char)ch) && (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) && (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 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 {
|
||||
@ -187,7 +195,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
||||
doSearch = false;
|
||||
}
|
||||
if (doSearch) {
|
||||
search(mode, panel, getPanelValue);
|
||||
this->found = search(mode, panel, getPanelValue);
|
||||
}
|
||||
if (filterChanged && lines) {
|
||||
updateWeakPanel(this, panel, lines);
|
||||
|
1
IncSet.h
1
IncSet.h
@ -35,6 +35,7 @@ typedef struct IncSet_ {
|
||||
IncMode* active;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
} IncSet;
|
||||
|
||||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
|
@ -50,9 +50,9 @@ struct InfoScreen_ {
|
||||
};
|
||||
}*/
|
||||
|
||||
static const char* InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
|
||||
static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
|
||||
|
||||
static const char* InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"};
|
||||
static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"};
|
||||
|
||||
static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};
|
||||
|
||||
@ -83,6 +83,7 @@ void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) {
|
||||
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);
|
||||
@ -116,6 +117,7 @@ void InfoScreen_run(InfoScreen* this) {
|
||||
|
||||
if (this->inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
set_escdelay(25);
|
||||
int ch = getch();
|
||||
|
||||
if (ch == ERR) {
|
||||
|
@ -39,7 +39,7 @@ static void ListItem_display(Object* cast, RichString* out) {
|
||||
/*
|
||||
int len = strlen(this->value)+1;
|
||||
char buffer[len+1];
|
||||
snprintf(buffer, len, "%s", this->value);
|
||||
xSnprintf(buffer, len, "%s", this->value);
|
||||
*/
|
||||
if (this->moving) {
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR],
|
||||
|
@ -20,35 +20,35 @@ int LoadAverageMeter_attributes[] = {
|
||||
|
||||
int LoadMeter_attributes[] = { LOAD };
|
||||
|
||||
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
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]);
|
||||
xSnprintf(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[0]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
||||
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[1]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[1]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[2]);
|
||||
xSnprintf(buffer, sizeof(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;
|
||||
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
|
||||
if (this->values[0] > this->total) {
|
||||
this->total = this->values[0];
|
||||
}
|
||||
snprintf(buffer, size, "%.2f", this->values[0]);
|
||||
xSnprintf(buffer, size, "%.2f", this->values[0]);
|
||||
}
|
||||
|
||||
static void LoadMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
char buffer[20];
|
||||
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%.2f ", ((Meter*)this)->values[0]);
|
||||
RichString_write(out, CRT_colors[LOAD], buffer);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ MeterClass LoadAverageMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = LoadAverageMeter_display,
|
||||
},
|
||||
.setValues = LoadAverageMeter_setValues,
|
||||
.updateValues = LoadAverageMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 3,
|
||||
.total = 100.0,
|
||||
@ -75,8 +75,9 @@ 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",
|
||||
|
23
MainPanel.c
23
MainPanel.c
@ -31,7 +31,7 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
|
||||
}*/
|
||||
|
||||
static const char* MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
||||
static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||
@ -87,7 +87,10 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
if (this->inc->found) {
|
||||
reaction |= Action_follow(this->state);
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
result = HANDLED;
|
||||
} else if (ch == 27) {
|
||||
return HANDLED;
|
||||
@ -102,20 +105,6 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
} else {
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
switch (ch) {
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
if (super->scrollH > 0) {
|
||||
super->scrollH -= CRT_scrollHAmount;
|
||||
super->needsRedraw = true;
|
||||
}
|
||||
return HANDLED;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
super->scrollH += CRT_scrollHAmount;
|
||||
super->needsRedraw = true;
|
||||
return HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (reaction & HTOP_REDRAW_BAR) {
|
||||
@ -159,7 +148,7 @@ const char* MainPanel_getValue(MainPanel* this, int i) {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged) {
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged) {
|
||||
Panel* super = (Panel*) this;
|
||||
bool ok = true;
|
||||
bool anyTagged = false;
|
||||
|
@ -34,7 +34,7 @@ int MainPanel_selectedPid(MainPanel* this);
|
||||
|
||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
||||
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged);
|
||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged);
|
||||
|
||||
extern PanelClass MainPanel_class;
|
||||
|
||||
|
11
Makefile.am
11
Makefile.am
@ -53,6 +53,15 @@ myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
|
||||
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
|
||||
endif
|
||||
|
||||
if HTOP_DRAGONFLYBSD
|
||||
htop_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
||||
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
||||
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
||||
|
||||
myhtopplatheaders = dragonflybsd/Platform.h dragonflybsd/DragonFlyBSDProcessList.h \
|
||||
dragonflybsd/DragonFlyBSDProcess.h dragonflybsd/DragonFlyBSDCRT.h dragonflybsd/Battery.h
|
||||
endif
|
||||
|
||||
if HTOP_OPENBSD
|
||||
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
||||
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
||||
@ -95,7 +104,7 @@ debug:
|
||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG"
|
||||
|
||||
coverage:
|
||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" AM_LDFLAGS="-lgcov"
|
||||
$(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov"
|
||||
|
||||
.c.h:
|
||||
@srcdir@/scripts/MakeHeader.py $<
|
||||
|
@ -24,7 +24,7 @@ int MemoryMeter_attributes[] = {
|
||||
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
|
||||
};
|
||||
|
||||
static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int written;
|
||||
Platform_setMemoryValues(this);
|
||||
|
||||
@ -60,7 +60,7 @@ MeterClass MemoryMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = MemoryMeter_display,
|
||||
},
|
||||
.setValues = MemoryMeter_setValues,
|
||||
.updateValues = MemoryMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 3,
|
||||
.total = 100.0,
|
||||
|
65
Meter.c
65
Meter.c
@ -37,7 +37,7 @@ 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_ {
|
||||
@ -46,7 +46,7 @@ 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;
|
||||
@ -66,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_)
|
||||
@ -132,12 +133,8 @@ Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
|
||||
this->h = 1;
|
||||
this->param = param;
|
||||
this->pl = pl;
|
||||
char maxItems = type->maxItems;
|
||||
if (maxItems == 0) {
|
||||
maxItems = 1;
|
||||
}
|
||||
type->curItems = maxItems;
|
||||
this->values = xCalloc(maxItems, sizeof(double));
|
||||
type->curItems = type->maxItems;
|
||||
this->values = xCalloc(type->maxItems, sizeof(double));
|
||||
this->total = type->total;
|
||||
this->caption = xStrdup(type->caption);
|
||||
if (Meter_initFn(this))
|
||||
@ -155,7 +152,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) {
|
||||
if (value / 1024 < powi)
|
||||
break;
|
||||
|
||||
if (prefix[1] == 0)
|
||||
if (prefix[1] == '\0')
|
||||
break;
|
||||
|
||||
powi *= 1024;
|
||||
@ -184,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);
|
||||
@ -216,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];
|
||||
@ -230,16 +225,16 @@ void Meter_setMode(Meter* this, int modeIndex) {
|
||||
ListItem* Meter_toListItem(Meter* this, bool moving) {
|
||||
char mode[21];
|
||||
if (this->mode)
|
||||
snprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName);
|
||||
xSnprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName);
|
||||
else
|
||||
mode[0] = '\0';
|
||||
char number[11];
|
||||
if (this->param > 0)
|
||||
snprintf(number, 10, " %d", this->param);
|
||||
xSnprintf(number, 10, " %d", this->param);
|
||||
else
|
||||
number[0] = '\0';
|
||||
char buffer[51];
|
||||
snprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode);
|
||||
xSnprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode);
|
||||
ListItem* li = ListItem_new(buffer, 0);
|
||||
li->moving = moving;
|
||||
return li;
|
||||
@ -249,7 +244,7 @@ ListItem* Meter_toListItem(Meter* this, bool moving) {
|
||||
|
||||
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]);
|
||||
@ -265,11 +260,11 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
/* ---------- BarMeterMode ---------- */
|
||||
|
||||
static char BarMeterMode_characters[] = "|#*@$%&.";
|
||||
static const 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]);
|
||||
@ -291,11 +286,8 @@ 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);
|
||||
xSnprintf(bar, w + 1, "%*s", w, buffer);
|
||||
|
||||
// First draw in the bar[] buffer...
|
||||
int offset = 0;
|
||||
@ -344,7 +336,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
#define PIXPERROW_UTF8 4
|
||||
static const char* GraphMeterMode_dotsUtf8[] = {
|
||||
static const char* const GraphMeterMode_dotsUtf8[] = {
|
||||
/*00*/" ", /*01*/"⢀", /*02*/"⢠", /*03*/"⢰", /*04*/ "⢸",
|
||||
/*10*/"⡀", /*11*/"⣀", /*12*/"⣠", /*13*/"⣰", /*14*/ "⣸",
|
||||
/*20*/"⡄", /*21*/"⣄", /*22*/"⣤", /*23*/"⣴", /*24*/ "⣼",
|
||||
@ -355,13 +347,13 @@ static const char* GraphMeterMode_dotsUtf8[] = {
|
||||
#endif
|
||||
|
||||
#define PIXPERROW_ASCII 2
|
||||
static const char* GraphMeterMode_dotsAscii[] = {
|
||||
static const char* const GraphMeterMode_dotsAscii[] = {
|
||||
/*00*/" ", /*01*/".", /*02*/":",
|
||||
/*10*/".", /*11*/".", /*12*/":",
|
||||
/*20*/":", /*21*/":", /*22*/":"
|
||||
};
|
||||
|
||||
static const char** GraphMeterMode_dots;
|
||||
static const char* const* GraphMeterMode_dots;
|
||||
static int GraphMeterMode_pixPerRow;
|
||||
|
||||
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
@ -397,7 +389,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
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);
|
||||
@ -414,8 +406,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
}
|
||||
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 v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix);
|
||||
int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix);
|
||||
|
||||
int colorIdx = GRAPH_1;
|
||||
for (int line = 0; line < GRAPH_HEIGHT; line++) {
|
||||
@ -432,7 +424,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
/* ---------- LEDMeterMode ---------- */
|
||||
|
||||
static const char* LEDMeterMode_digitsAscii[] = {
|
||||
static const char* const LEDMeterMode_digitsAscii[] = {
|
||||
" __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ",
|
||||
"| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|",
|
||||
"|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"
|
||||
@ -440,7 +432,7 @@ static const char* LEDMeterMode_digitsAscii[] = {
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
static const char* LEDMeterMode_digitsUtf8[] = {
|
||||
static const char* const LEDMeterMode_digitsUtf8[] = {
|
||||
"┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐",
|
||||
"│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤",
|
||||
"└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"
|
||||
@ -448,7 +440,7 @@ static const char* LEDMeterMode_digitsUtf8[] = {
|
||||
|
||||
#endif
|
||||
|
||||
static const char** LEDMeterMode_digits;
|
||||
static const char* const* LEDMeterMode_digits;
|
||||
|
||||
static void LEDMeterMode_drawDigit(int x, int y, int n) {
|
||||
for (int i = 0; i < 3; i++)
|
||||
@ -466,7 +458,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
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);
|
||||
@ -529,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;
|
||||
}
|
||||
|
||||
@ -548,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",
|
||||
|
7
Meter.h
7
Meter.h
@ -24,7 +24,7 @@ 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_ {
|
||||
@ -33,7 +33,7 @@ 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;
|
||||
@ -53,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_)
|
||||
|
@ -31,13 +31,19 @@ struct MetersPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* MetersFunctions[] = {"Type ", "Move ", "Delete", "Done ", NULL};
|
||||
static const char* MetersKeys[] = {"Space", "Enter", "Del", "Esc"};
|
||||
static int MetersEvents[] = {' ', 13, KEY_DC, 27};
|
||||
// Note: In code the meters are known to have bar/text/graph "Modes", but in UI
|
||||
// we call them "Styles".
|
||||
static const char* const MetersFunctions[] = {"Style ", "Move ", " ", "Delete", "Done ", NULL};
|
||||
static const char* const MetersKeys[] = {"Space", "Enter", " ", "Del", "F10"};
|
||||
static int MetersEvents[] = {' ', 13, ERR, KEY_DC, KEY_F(10)};
|
||||
|
||||
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};
|
||||
// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese
|
||||
// terminals, breaking our aligning.
|
||||
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
|
||||
// considered "Ambiguous characters".
|
||||
static const char* const MetersMovingFunctions[] = {"Style ", "Lock ", "Up ", "Down ", "Left ", "Right ", " ", "Delete", "Done ", NULL};
|
||||
static const char* const MetersMovingKeys[] = {"Space", "Enter", "Up", "Dn", "<-", "->", " ", "Del", "F10"};
|
||||
static int MetersMovingEvents[] = {' ', 13, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, ERR, KEY_DC, KEY_F(10)};
|
||||
static FunctionBar* Meters_movingBar = NULL;
|
||||
|
||||
static void MetersPanel_delete(Object* object) {
|
||||
@ -50,7 +56,10 @@ static void MetersPanel_delete(Object* object) {
|
||||
void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
||||
Panel* super = (Panel*) this;
|
||||
this->moving = moving;
|
||||
((ListItem*)Panel_getSelected(super))->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);
|
||||
@ -58,6 +67,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
|
||||
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) {
|
||||
@ -96,7 +106,6 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
if (!Vector_size(this->meters))
|
||||
break;
|
||||
MetersPanel_setMoving(this, !(this->moving));
|
||||
FunctionBar_draw(this->super.currentBar, NULL);
|
||||
result = HANDLED;
|
||||
break;
|
||||
}
|
||||
@ -119,8 +128,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
/* else fallthrough */
|
||||
case KEY_F(7):
|
||||
case '[':
|
||||
case '-':
|
||||
@ -135,8 +144,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
|
||||
if (!this->moving) {
|
||||
break;
|
||||
}
|
||||
/* else fallthrough */
|
||||
}
|
||||
/* else fallthrough */
|
||||
case KEY_F(8):
|
||||
case ']':
|
||||
case '+':
|
||||
|
@ -27,6 +27,12 @@ struct MetersPanel_ {
|
||||
};
|
||||
|
||||
|
||||
// Note: In code the meters are known to have bar/text/graph "Modes", but in UI
|
||||
// we call them "Styles".
|
||||
// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese
|
||||
// terminals, breaking our aligning.
|
||||
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
|
||||
// considered "Ambiguous characters".
|
||||
|
||||
void MetersPanel_setMoving(MetersPanel* this, bool moving);
|
||||
|
||||
|
@ -77,7 +77,7 @@ void OpenFilesScreen_draw(InfoScreen* this) {
|
||||
|
||||
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
char command[1025];
|
||||
snprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
||||
xSnprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
||||
FILE* fd = popen(command, "r");
|
||||
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
||||
OpenFiles_FileData* fdata = NULL;
|
||||
@ -86,17 +86,12 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
pdata->error = 127;
|
||||
return pdata;
|
||||
}
|
||||
while (!feof(fd)) {
|
||||
int cmd = fgetc(fd);
|
||||
if (cmd == EOF)
|
||||
break;
|
||||
char* entry = xMalloc(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 = xCalloc(1, sizeof(OpenFiles_FileData));
|
||||
if (fdata == NULL) {
|
||||
@ -107,8 +102,8 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
fdata = nextFile;
|
||||
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;
|
||||
@ -132,9 +127,11 @@ void OpenFilesScreen_scan(InfoScreen* this) {
|
||||
} 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);
|
||||
xSnprintf(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'] : "",
|
||||
|
35
Panel.c
35
Panel.c
@ -61,6 +61,7 @@ struct Panel_ {
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
@ -82,10 +83,7 @@ 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 = {
|
||||
@ -327,6 +325,7 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
if (selected) {
|
||||
attrset(selectionColor);
|
||||
RichString_setAttr(&item, selectionColor);
|
||||
this->selectedLen = itemLen;
|
||||
}
|
||||
mvhline(y + line, x, ' ', this->w);
|
||||
if (amt > 0)
|
||||
@ -352,6 +351,7 @@ void Panel_draw(Panel* this, bool focus) {
|
||||
RichString_begin(new);
|
||||
Object_display(newObj, &new);
|
||||
int newLen = RichString_sizeVal(new);
|
||||
this->selectedLen = newLen;
|
||||
mvhline(y+ this->oldSelected - first, x+0, ' ', this->w);
|
||||
if (scrollH < oldLen)
|
||||
RichString_printoffnVal(old, y+this->oldSelected - first, x,
|
||||
@ -376,11 +376,11 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
int size = Vector_size(this->items);
|
||||
switch (key) {
|
||||
case KEY_DOWN:
|
||||
case KEY_CTRLN:
|
||||
case KEY_CTRL('N'):
|
||||
this->selected++;
|
||||
break;
|
||||
case KEY_UP:
|
||||
case KEY_CTRLP:
|
||||
case KEY_CTRL('P'):
|
||||
this->selected--;
|
||||
break;
|
||||
#ifdef KEY_C_DOWN
|
||||
@ -394,25 +394,26 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
case KEY_CTRLF:
|
||||
case KEY_CTRL('F'):
|
||||
this->scrollH += CRT_scrollHAmount;
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_PPAGE:
|
||||
this->selected -= (this->h - 1);
|
||||
this->scrollV -= (this->h - 1);
|
||||
this->scrollV = MAX(0, this->scrollV - this->h + 1);
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
this->selected += (this->h - 1);
|
||||
this->scrollV += (this->h - 1);
|
||||
this->scrollV = MAX(0, MIN(Vector_size(this->items) - this->h,
|
||||
this->scrollV + this->h - 1));
|
||||
this->needsRedraw = true;
|
||||
break;
|
||||
case KEY_WHEELUP:
|
||||
@ -436,12 +437,22 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
case KEY_END:
|
||||
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;
|
||||
}
|
||||
|
||||
// ensure selection within bounds
|
||||
if (this->selected < 0) {
|
||||
if (this->selected < 0 || size == 0) {
|
||||
this->selected = 0;
|
||||
this->needsRedraw = true;
|
||||
} else if (this->selected >= size) {
|
||||
|
6
Panel.h
6
Panel.h
@ -50,6 +50,7 @@ struct Panel_ {
|
||||
Vector* items;
|
||||
int selected;
|
||||
int oldSelected;
|
||||
int selectedLen;
|
||||
void* eventHandlerState;
|
||||
int scrollV;
|
||||
short scrollH;
|
||||
@ -70,10 +71,7 @@ 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;
|
||||
|
||||
|
96
Process.c
96
Process.c
@ -18,6 +18,7 @@ in the source distribution for its full text.
|
||||
#include <sys/resource.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
@ -48,6 +49,7 @@ in the source distribution for its full text.
|
||||
#define PROCESS_FLAG_IO 0x0001
|
||||
|
||||
typedef enum ProcessFields {
|
||||
NULL_PROCESSFIELD = 0,
|
||||
PID = 1,
|
||||
COMM = 2,
|
||||
STATE = 3,
|
||||
@ -170,6 +172,10 @@ typedef struct ProcessClass_ {
|
||||
|
||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||
|
||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||
|
||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||
|
||||
}*/
|
||||
|
||||
static int Process_getuid = -1;
|
||||
@ -193,10 +199,10 @@ void Process_setupColumnWidths() {
|
||||
assert(digits < 20);
|
||||
for (int i = 0; Process_pidColumns[i].label; i++) {
|
||||
assert(i < 20);
|
||||
sprintf(Process_titleBuffer[i], "%*s ", digits, Process_pidColumns[i].label);
|
||||
xSnprintf(Process_titleBuffer[i], 20, "%*s ", digits, Process_pidColumns[i].label);
|
||||
Process_fields[Process_pidColumns[i].id].title = Process_titleBuffer[i];
|
||||
}
|
||||
sprintf(Process_pidFormat, "%%%dd ", digits);
|
||||
xSnprintf(Process_pidFormat, sizeof(Process_pidFormat), "%%%dd ", digits);
|
||||
}
|
||||
|
||||
void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
||||
@ -260,13 +266,16 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori
|
||||
processShadowColor = CRT_colors[PROCESS];
|
||||
}
|
||||
|
||||
if (number > 10000000000) {
|
||||
snprintf(buffer, 13, "%11lld ", number / 1000);
|
||||
if ((long long) number == -1LL) {
|
||||
int len = snprintf(buffer, 13, " no perm ");
|
||||
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
|
||||
} else if (number > 10000000000) {
|
||||
xSnprintf(buffer, 13, "%11lld ", number / 1000);
|
||||
RichString_appendn(str, largeNumberColor, buffer, 5);
|
||||
RichString_appendn(str, processMegabytesColor, buffer+5, 3);
|
||||
RichString_appendn(str, processColor, buffer+8, 4);
|
||||
} else {
|
||||
snprintf(buffer, 13, "%11llu ", number);
|
||||
xSnprintf(buffer, 13, "%11llu ", number);
|
||||
RichString_appendn(str, largeNumberColor, buffer, 2);
|
||||
RichString_appendn(str, processMegabytesColor, buffer+2, 3);
|
||||
RichString_appendn(str, processColor, buffer+5, 3);
|
||||
@ -283,15 +292,15 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) {
|
||||
int hundredths = totalHundredths - (totalSeconds * 100);
|
||||
char buffer[11];
|
||||
if (hours >= 100) {
|
||||
snprintf(buffer, 10, "%7lluh ", hours);
|
||||
xSnprintf(buffer, 10, "%7lluh ", hours);
|
||||
RichString_append(str, CRT_colors[LARGE_NUMBER], buffer);
|
||||
} else {
|
||||
if (hours) {
|
||||
snprintf(buffer, 10, "%2lluh", hours);
|
||||
xSnprintf(buffer, 10, "%2lluh", hours);
|
||||
RichString_append(str, CRT_colors[LARGE_NUMBER], buffer);
|
||||
snprintf(buffer, 10, "%02d:%02d ", minutes, seconds);
|
||||
xSnprintf(buffer, 10, "%02d:%02d ", minutes, seconds);
|
||||
} else {
|
||||
snprintf(buffer, 10, "%2d:%02d.%02d ", minutes, seconds, hundredths);
|
||||
xSnprintf(buffer, 10, "%2d:%02d.%02d ", minutes, seconds, hundredths);
|
||||
}
|
||||
RichString_append(str, CRT_colors[DEFAULT_COLOR], buffer);
|
||||
}
|
||||
@ -335,7 +344,10 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
|
||||
largeNumberColor = CRT_colors[PROCESS];
|
||||
processMegabytesColor = CRT_colors[PROCESS];
|
||||
}
|
||||
if (rate < ONE_K) {
|
||||
if (rate == -1) {
|
||||
int len = snprintf(buffer, n, " no perm ");
|
||||
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
|
||||
} else if (rate < ONE_K) {
|
||||
int len = snprintf(buffer, n, "%7.2f B/s ", rate);
|
||||
RichString_appendn(str, processColor, buffer, len);
|
||||
} else if (rate < ONE_K * ONE_K) {
|
||||
@ -360,19 +372,19 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
switch (field) {
|
||||
case PERCENT_CPU: {
|
||||
if (this->percent_cpu > 999.9) {
|
||||
snprintf(buffer, n, "%4d ", (unsigned int)this->percent_cpu);
|
||||
xSnprintf(buffer, n, "%4d ", (unsigned int)this->percent_cpu);
|
||||
} else if (this->percent_cpu > 99.9) {
|
||||
snprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu);
|
||||
xSnprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu);
|
||||
} else {
|
||||
snprintf(buffer, n, "%4.1f ", this->percent_cpu);
|
||||
xSnprintf(buffer, n, "%4.1f ", this->percent_cpu);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PERCENT_MEM: {
|
||||
if (this->percent_mem > 99.9) {
|
||||
snprintf(buffer, n, "100. ");
|
||||
xSnprintf(buffer, n, "100. ");
|
||||
} else {
|
||||
snprintf(buffer, n, "%4.1f ", this->percent_mem);
|
||||
xSnprintf(buffer, n, "%4.1f ", this->percent_mem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -391,7 +403,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
int indent = (this->indent < 0 ? -this->indent : this->indent);
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (indent & (1 << i))
|
||||
if (indent & (1U << i))
|
||||
maxIndent = i+1;
|
||||
for (int i = 0; i < maxIndent - 1; i++) {
|
||||
int written;
|
||||
@ -403,7 +415,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
n -= written;
|
||||
}
|
||||
const char* draw = CRT_treeStr[lastItem ? (this->settings->direction == 1 ? TREE_STR_BEND : TREE_STR_TEND) : TREE_STR_RTEE];
|
||||
snprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] );
|
||||
xSnprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] );
|
||||
RichString_append(str, CRT_colors[PROCESS_TREE], buffer);
|
||||
Process_writeCommand(this, attr, baseattr, str);
|
||||
return;
|
||||
@ -414,28 +426,28 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
case M_RESIDENT: Process_humanNumber(str, this->m_resident * PAGE_SIZE_KB, coloring); return;
|
||||
case M_SIZE: Process_humanNumber(str, this->m_size * PAGE_SIZE_KB, coloring); return;
|
||||
case NICE: {
|
||||
snprintf(buffer, n, "%3ld ", this->nice);
|
||||
xSnprintf(buffer, n, "%3ld ", this->nice);
|
||||
attr = this->nice < 0 ? CRT_colors[PROCESS_HIGH_PRIORITY]
|
||||
: this->nice > 0 ? CRT_colors[PROCESS_LOW_PRIORITY]
|
||||
: attr;
|
||||
break;
|
||||
}
|
||||
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
|
||||
case PGRP: snprintf(buffer, n, Process_pidFormat, this->pgrp); break;
|
||||
case PID: snprintf(buffer, n, Process_pidFormat, this->pid); break;
|
||||
case PPID: snprintf(buffer, n, Process_pidFormat, this->ppid); break;
|
||||
case NLWP: xSnprintf(buffer, n, "%4ld ", this->nlwp); break;
|
||||
case PGRP: xSnprintf(buffer, n, Process_pidFormat, this->pgrp); break;
|
||||
case PID: xSnprintf(buffer, n, Process_pidFormat, this->pid); break;
|
||||
case PPID: xSnprintf(buffer, n, Process_pidFormat, this->ppid); break;
|
||||
case PRIORITY: {
|
||||
if(this->priority == -100)
|
||||
snprintf(buffer, n, " RT ");
|
||||
if(this->priority <= -100)
|
||||
xSnprintf(buffer, n, " RT ");
|
||||
else
|
||||
snprintf(buffer, n, "%3ld ", this->priority);
|
||||
xSnprintf(buffer, n, "%3ld ", this->priority);
|
||||
break;
|
||||
}
|
||||
case PROCESSOR: snprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, this->processor)); break;
|
||||
case SESSION: snprintf(buffer, n, Process_pidFormat, this->session); break;
|
||||
case STARTTIME: snprintf(buffer, n, "%s", this->starttime_show); break;
|
||||
case PROCESSOR: xSnprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, this->processor)); break;
|
||||
case SESSION: xSnprintf(buffer, n, Process_pidFormat, this->session); break;
|
||||
case STARTTIME: xSnprintf(buffer, n, "%s", this->starttime_show); break;
|
||||
case STATE: {
|
||||
snprintf(buffer, n, "%c ", this->state);
|
||||
xSnprintf(buffer, n, "%c ", this->state);
|
||||
switch(this->state) {
|
||||
case 'R':
|
||||
attr = CRT_colors[PROCESS_R_STATE];
|
||||
@ -446,18 +458,18 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
|
||||
case ST_UID: xSnprintf(buffer, n, "%4d ", this->st_uid); break;
|
||||
case TIME: Process_printTime(str, this->time); return;
|
||||
case TGID: snprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
||||
case TPGID: snprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
||||
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
||||
case TGID: xSnprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
||||
case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
||||
case TTY_NR: xSnprintf(buffer, n, "%3u:%3u ", major(this->tty_nr), minor(this->tty_nr)); break;
|
||||
case USER: {
|
||||
if (Process_getuid != (int) this->st_uid)
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
if (this->user) {
|
||||
snprintf(buffer, n, "%-9s ", this->user);
|
||||
xSnprintf(buffer, n, "%-9s ", this->user);
|
||||
} else {
|
||||
snprintf(buffer, n, "%-9d ", this->st_uid);
|
||||
xSnprintf(buffer, n, "%-9d ", this->st_uid);
|
||||
}
|
||||
if (buffer[9] != '\0') {
|
||||
buffer[9] = ' ';
|
||||
@ -466,7 +478,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
snprintf(buffer, n, "- ");
|
||||
xSnprintf(buffer, n, "- ");
|
||||
}
|
||||
RichString_append(str, attr, buffer);
|
||||
}
|
||||
@ -514,11 +526,10 @@ void Process_toggleTag(Process* this) {
|
||||
}
|
||||
|
||||
bool Process_setPriority(Process* this, int priority) {
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
CRT_dropPrivileges();
|
||||
int old_prio = getpriority(PRIO_PROCESS, this->pid);
|
||||
int err = setpriority(PRIO_PROCESS, this->pid, priority);
|
||||
seteuid(euid);
|
||||
CRT_restorePrivileges();
|
||||
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
|
||||
this->nice = priority;
|
||||
}
|
||||
@ -530,10 +541,9 @@ bool Process_changePriorityBy(Process* this, size_t delta) {
|
||||
}
|
||||
|
||||
void Process_sendSignal(Process* this, size_t sgn) {
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
CRT_dropPrivileges();
|
||||
kill(this->pid, (int) sgn);
|
||||
seteuid(euid);
|
||||
CRT_restorePrivileges();
|
||||
}
|
||||
|
||||
long Process_pidCompare(const void* v1, const void* v2) {
|
||||
@ -590,7 +600,7 @@ long Process_compare(const void* v1, const void* v2) {
|
||||
return (p1->starttime_ctime - p2->starttime_ctime);
|
||||
}
|
||||
case STATE:
|
||||
return (p1->state - p2->state);
|
||||
return (Process_sortState(p1->state) - Process_sortState(p2->state));
|
||||
case ST_UID:
|
||||
return (p1->st_uid - p2->st_uid);
|
||||
case TIME:
|
||||
|
@ -28,6 +28,7 @@ in the source distribution for its full text.
|
||||
#define PROCESS_FLAG_IO 0x0001
|
||||
|
||||
typedef enum ProcessFields {
|
||||
NULL_PROCESSFIELD = 0,
|
||||
PID = 1,
|
||||
COMM = 2,
|
||||
STATE = 3,
|
||||
@ -150,6 +151,10 @@ typedef struct ProcessClass_ {
|
||||
|
||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||
|
||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||
|
||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||
|
||||
|
||||
#define ONE_K 1024L
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
|
@ -22,6 +22,10 @@ in the source distribution for its full text.
|
||||
#include "Process.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#include <hwloc.h>
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
#define MAX_NAME 128
|
||||
#endif
|
||||
@ -104,6 +108,11 @@ ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable*
|
||||
}
|
||||
|
||||
void ProcessList_done(ProcessList* this) {
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
if (this->topologyOk) {
|
||||
hwloc_topology_destroy(this->topology);
|
||||
}
|
||||
#endif
|
||||
Hashtable_delete(this->processTable);
|
||||
Vector_delete(this->processes);
|
||||
Vector_delete(this->processes2);
|
||||
@ -164,7 +173,7 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
|
||||
|
||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
||||
Process* process = (Process*) (Vector_get(this->processes, i));
|
||||
if (process->show && (process->tgid == pid || (process->tgid == process->pid && process->ppid == pid))) {
|
||||
if (process->show && Process_isChildOf(process, pid)) {
|
||||
process = (Process*) (Vector_take(this->processes, i));
|
||||
Vector_add(children, process);
|
||||
}
|
||||
@ -204,23 +213,51 @@ void ProcessList_sort(ProcessList* this) {
|
||||
// Restore settings
|
||||
this->settings->sortKey = sortKey;
|
||||
this->settings->direction = direction;
|
||||
// Take PID 1 as root and add to the new listing
|
||||
int vsize = Vector_size(this->processes);
|
||||
Process* init = (Process*) (Vector_take(this->processes, 0));
|
||||
if (!init) return;
|
||||
// This assertion crashes on hardened kernels.
|
||||
// I wonder how well tree view works on those systems.
|
||||
// assert(init->pid == 1);
|
||||
init->indent = 0;
|
||||
Vector_add(this->processes2, init);
|
||||
// Recursively empty list
|
||||
ProcessList_buildTree(this, init->pid, 0, 0, direction, true);
|
||||
// Add leftovers
|
||||
while (Vector_size(this->processes)) {
|
||||
Process* p = (Process*) (Vector_take(this->processes, 0));
|
||||
p->indent = 0;
|
||||
Vector_add(this->processes2, p);
|
||||
ProcessList_buildTree(this, p->pid, 0, 0, direction, p->showChildren);
|
||||
// Find all processes whose parent is not visible
|
||||
int size;
|
||||
while ((size = Vector_size(this->processes))) {
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
Process* process = (Process*)(Vector_get(this->processes, i));
|
||||
// Immediately consume not shown processes
|
||||
if (!process->show) {
|
||||
process = (Process*)(Vector_take(this->processes, i));
|
||||
process->indent = 0;
|
||||
Vector_add(this->processes2, process);
|
||||
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
||||
break;
|
||||
}
|
||||
pid_t ppid = process->tgid == process->pid ? process->ppid : process->tgid;
|
||||
// Bisect the process vector to find parent
|
||||
int l = 0, r = size;
|
||||
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
||||
// on Mac OS X 10.11.6) cancel bisecting and regard this process as
|
||||
// root.
|
||||
if (process->pid == ppid)
|
||||
r = 0;
|
||||
while (l < r) {
|
||||
int c = (l + r) / 2;
|
||||
pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid;
|
||||
if (ppid == pid) {
|
||||
break;
|
||||
} else if (ppid < pid) {
|
||||
r = c;
|
||||
} else {
|
||||
l = c + 1;
|
||||
}
|
||||
}
|
||||
// If parent not found, then construct the tree with this root
|
||||
if (l >= r) {
|
||||
process = (Process*)(Vector_take(this->processes, i));
|
||||
process->indent = 0;
|
||||
Vector_add(this->processes2, process);
|
||||
ProcessList_buildTree(this, process->pid, 0, 0, direction, process->showChildren);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// There should be no loop in the process tree
|
||||
assert(i < size);
|
||||
}
|
||||
assert(Vector_size(this->processes2) == vsize); (void)vsize;
|
||||
assert(Vector_size(this->processes) == 0);
|
||||
@ -307,6 +344,7 @@ void ProcessList_scan(ProcessList* this) {
|
||||
for (int i = 0; i < Vector_size(this->processes); i++) {
|
||||
Process* p = (Process*) Vector_get(this->processes, i);
|
||||
p->updated = false;
|
||||
p->show = true;
|
||||
}
|
||||
|
||||
this->totalTasks = 0;
|
||||
|
@ -16,6 +16,10 @@ in the source distribution for its full text.
|
||||
#include "Process.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#ifdef HAVE_LIBHWLOC
|
||||
#include <hwloc.h>
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
#define MAX_NAME 128
|
||||
#endif
|
||||
|
59
README
59
README
@ -1,50 +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>
|
||||
|
||||
2004 - 2015
|
||||
by Hisham Muhammad <hisham@gobolinux.org> (2004 - 2016)
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This is htop, an interactive process viewer.
|
||||
It requires ncurses. It is developed primarily on Linux,
|
||||
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!)
|
||||
|
||||
This software has evolved considerably over the years,
|
||||
and is reasonably complete, but there is always room for improvement.
|
||||
|
||||
Comparison between 'htop' and classic 'top'
|
||||
Comparison between `htop` and classic `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](https://hisham.hm/htop/releases/), 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)
|
||||
|
@ -189,6 +189,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
}
|
||||
|
||||
int prevCh = ch;
|
||||
set_escdelay(25);
|
||||
ch = getch();
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
@ -244,28 +245,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
redraw = false;
|
||||
continue;
|
||||
}
|
||||
else if (ch == 27) {
|
||||
int ch2 = getch();
|
||||
if (ch2 != ERR) {
|
||||
switch(ch2)
|
||||
{
|
||||
case 'h':
|
||||
ch = KEY_LEFT;
|
||||
break;
|
||||
case 'j':
|
||||
ch = KEY_DOWN;
|
||||
break;
|
||||
case 'k':
|
||||
ch = KEY_UP;
|
||||
break;
|
||||
case 'l':
|
||||
ch = KEY_RIGHT;
|
||||
break;
|
||||
default:
|
||||
ungetch(ch2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
@ -295,7 +279,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
continue;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
case KEY_CTRLB:
|
||||
case KEY_CTRL('B'):
|
||||
if (this->panelCount < 2) {
|
||||
goto defaultHandler;
|
||||
}
|
||||
if (!this->allowFocusChange)
|
||||
break;
|
||||
tryLeft:
|
||||
@ -306,8 +293,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
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:
|
||||
@ -323,6 +313,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
quit = true;
|
||||
continue;
|
||||
default:
|
||||
defaultHandler:
|
||||
sortTimeout = resetSortTimeout;
|
||||
Panel_onKey(panelFocus, ch);
|
||||
break;
|
||||
|
44
Settings.c
44
Settings.c
@ -159,26 +159,28 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
fields[j] = (ProcessField) NULL;
|
||||
fields[j] = NULL_PROCESSFIELD;
|
||||
String_freeArray(ids);
|
||||
}
|
||||
|
||||
static bool Settings_read(Settings* this, const char* fileName) {
|
||||
FILE* fd;
|
||||
uid_t euid = geteuid();
|
||||
|
||||
seteuid(getuid());
|
||||
|
||||
CRT_dropPrivileges();
|
||||
fd = fopen(fileName, "r");
|
||||
seteuid(euid);
|
||||
CRT_restorePrivileges();
|
||||
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;
|
||||
@ -252,34 +254,40 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
||||
|
||||
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
||||
fprintf(fd, "%s=", name);
|
||||
const char* sep = "";
|
||||
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, "%s%d", sep, (int) fields[i]-1);
|
||||
sep = " ";
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
static void writeMeters(Settings* this, FILE* fd, int column) {
|
||||
const char* sep = "";
|
||||
for (int i = 0; i < this->columns[column].len; i++) {
|
||||
fprintf(fd, "%s ", this->columns[column].names[i]);
|
||||
fprintf(fd, "%s%s", sep, this->columns[column].names[i]);
|
||||
sep = " ";
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
static void writeMeterModes(Settings* this, FILE* fd, int column) {
|
||||
const char* sep = "";
|
||||
for (int i = 0; i < this->columns[column].len; i++) {
|
||||
fprintf(fd, "%d ", this->columns[column].modes[i]);
|
||||
fprintf(fd, "%s%d", sep, this->columns[column].modes[i]);
|
||||
sep = " ";
|
||||
}
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
bool Settings_write(Settings* this) {
|
||||
FILE* fd;
|
||||
uid_t euid = geteuid();
|
||||
|
||||
seteuid(getuid());
|
||||
CRT_dropPrivileges();
|
||||
fd = fopen(this->filename, "w");
|
||||
seteuid(euid);
|
||||
CRT_restorePrivileges();
|
||||
|
||||
if (fd == NULL) {
|
||||
return false;
|
||||
}
|
||||
@ -365,8 +373,8 @@ Settings* Settings_new(int cpuCount) {
|
||||
htopDir = String_cat(home, "/.config/htop");
|
||||
}
|
||||
legacyDotfile = String_cat(home, "/.htoprc");
|
||||
uid_t euid = geteuid();
|
||||
seteuid(getuid());
|
||||
|
||||
CRT_dropPrivileges();
|
||||
(void) mkdir(configDir, 0700);
|
||||
(void) mkdir(htopDir, 0700);
|
||||
free(htopDir);
|
||||
@ -379,7 +387,7 @@ Settings* Settings_new(int cpuCount) {
|
||||
free(legacyDotfile);
|
||||
legacyDotfile = NULL;
|
||||
}
|
||||
seteuid(euid);
|
||||
CRT_restorePrivileges();
|
||||
}
|
||||
this->colorScheme = 0;
|
||||
this->changed = false;
|
||||
|
@ -31,13 +31,27 @@ Panel* SignalsPanel_new() {
|
||||
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++) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < Platform_numberOfSignals; i++) {
|
||||
Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
|
||||
// signal 15 is not always the 15th signal in the table
|
||||
if (Platform_signals[i].number == defaultSignal) {
|
||||
defaultPosition = i;
|
||||
}
|
||||
}
|
||||
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
||||
if (SIGRTMAX - SIGRTMIN <= 100) {
|
||||
static char buf[15];
|
||||
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
||||
int n = sig - SIGRTMIN;
|
||||
xSnprintf(buf, 15, "%2d SIGRTMIN%-+3d", sig, n);
|
||||
if (n == 0) {
|
||||
buf[11] = '\0';
|
||||
}
|
||||
Panel_set(this, i, (Object*) ListItem_new(buf, sig));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Panel_setHeader(this, "Send signal:");
|
||||
Panel_setSelected(this, defaultPosition);
|
||||
return this;
|
||||
|
@ -13,13 +13,19 @@ in the source distribution for its full text.
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*{
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
#include <stdio.h>
|
||||
|
||||
#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0)
|
||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||
}*/
|
||||
|
||||
/*
|
||||
* String_startsWith gives better performance if strlen(match) can be computed
|
||||
* at compile time (e.g. when they are immutable string literals). :)
|
||||
*/
|
||||
|
||||
char* String_cat(const char* s1, const char* s2) {
|
||||
int l1 = strlen(s1);
|
||||
int l2 = strlen(s2);
|
||||
@ -69,13 +75,7 @@ char** String_split(const char* s, char sep, int* n) {
|
||||
ctr++;
|
||||
if (ctr == blocks) {
|
||||
blocks += rate;
|
||||
char** newOut = (char**) xRealloc(out, sizeof(char*) * blocks);
|
||||
if (newOut) {
|
||||
out = newOut;
|
||||
} else {
|
||||
blocks -= rate;
|
||||
break;
|
||||
}
|
||||
out = (char**) xRealloc(out, sizeof(char*) * blocks);
|
||||
}
|
||||
s += size + 1;
|
||||
}
|
||||
@ -86,16 +86,16 @@ char** String_split(const char* s, char sep, int* n) {
|
||||
out[ctr] = token;
|
||||
ctr++;
|
||||
}
|
||||
char** newOut = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||
if (newOut) {
|
||||
out = newOut;
|
||||
}
|
||||
out = xRealloc(out, sizeof(char*) * (ctr + 1));
|
||||
out[ctr] = NULL;
|
||||
*n = ctr;
|
||||
return out;
|
||||
}
|
||||
|
||||
void String_freeArray(char** s) {
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; s[i] != NULL; i++) {
|
||||
free(s[i]);
|
||||
}
|
||||
@ -128,3 +128,29 @@ char* String_getToken(const char* line, const unsigned short int numMatch) {
|
||||
match[foundCount] = '\0';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,16 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
#include <stdio.h>
|
||||
|
||||
#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0)
|
||||
#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
|
||||
|
||||
/*
|
||||
* String_startsWith gives better performance if strlen(match) can be computed
|
||||
* at compile time (e.g. when they are immutable string literals). :)
|
||||
*/
|
||||
|
||||
char* String_cat(const char* s1, const char* s2);
|
||||
|
||||
char* String_trim(const char* in);
|
||||
@ -24,4 +31,6 @@ void String_freeArray(char** s);
|
||||
|
||||
char* String_getToken(const char* line, const unsigned short int numMatch);
|
||||
|
||||
char* String_readLine(FILE* fd);
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@ int SwapMeter_attributes[] = {
|
||||
SWAP
|
||||
};
|
||||
|
||||
static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||
int written;
|
||||
Platform_setSwapValues(this);
|
||||
|
||||
@ -54,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",
|
||||
|
18
TasksMeter.c
18
TasksMeter.c
@ -18,19 +18,19 @@ int TasksMeter_attributes[] = {
|
||||
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->values[0] = pl->kernelThreads;
|
||||
this->values[1] = pl->userlandThreads;
|
||||
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
|
||||
this->values[3] = pl->runningTasks;
|
||||
this->values[3] = MIN(pl->runningTasks, pl->cpuCount);
|
||||
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);
|
||||
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
||||
}
|
||||
|
||||
static void TasksMeter_display(Object* cast, RichString* out) {
|
||||
@ -40,7 +40,7 @@ static void TasksMeter_display(Object* cast, RichString* out) {
|
||||
|
||||
int processes = (int) this->values[2];
|
||||
|
||||
sprintf(buffer, "%d", processes);
|
||||
xSnprintf(buffer, sizeof(buffer), "%d", processes);
|
||||
RichString_write(out, CRT_colors[METER_VALUE], buffer);
|
||||
int threadValueColor = CRT_colors[METER_VALUE];
|
||||
int threadCaptionColor = CRT_colors[METER_TEXT];
|
||||
@ -50,18 +50,18 @@ static void TasksMeter_display(Object* cast, RichString* out) {
|
||||
}
|
||||
if (!settings->hideUserlandThreads) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
||||
sprintf(buffer, "%d", (int)this->values[1]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[1]);
|
||||
RichString_append(out, threadValueColor, buffer);
|
||||
RichString_append(out, threadCaptionColor, " thr");
|
||||
}
|
||||
if (!settings->hideKernelThreads) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
||||
sprintf(buffer, "%d", (int)this->values[0]);
|
||||
xSnprintf(buffer, sizeof(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[3]);
|
||||
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[3]);
|
||||
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
||||
}
|
||||
@ -72,10 +72,10 @@ MeterClass TasksMeter_class = {
|
||||
.delete = Meter_delete,
|
||||
.display = TasksMeter_display,
|
||||
},
|
||||
.setValues = TasksMeter_setValues,
|
||||
.updateValues = TasksMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.total = 100.0,
|
||||
.maxItems = 4,
|
||||
.total = 100.0,
|
||||
.attributes = TasksMeter_attributes,
|
||||
.name = "Tasks",
|
||||
.uiName = "Task counter",
|
||||
|
@ -22,6 +22,7 @@ in the source distribution for its full text.
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
@ -42,9 +43,9 @@ typedef struct TraceScreen_ {
|
||||
|
||||
}*/
|
||||
|
||||
static const char* TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
|
||||
static const char* const TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
|
||||
|
||||
static const char* TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
||||
static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
|
||||
|
||||
static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
|
||||
|
||||
@ -90,16 +91,16 @@ void TraceScreen_draw(InfoScreen* this) {
|
||||
|
||||
bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||
char buffer[1001];
|
||||
int err = pipe(this->fdpair);
|
||||
if (err == -1) return false;
|
||||
int error = pipe(this->fdpair);
|
||||
if (error == -1) return false;
|
||||
this->child = fork();
|
||||
if (this->child == -1) return false;
|
||||
if (this->child == 0) {
|
||||
seteuid(getuid());
|
||||
CRT_dropPrivileges();
|
||||
dup2(this->fdpair[1], STDERR_FILENO);
|
||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||
if (ok != -1) {
|
||||
sprintf(buffer, "%d", this->super.process->pid);
|
||||
xSnprintf(buffer, sizeof(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.";
|
||||
|
@ -17,10 +17,10 @@ int UptimeMeter_attributes[] = {
|
||||
UPTIME
|
||||
};
|
||||
|
||||
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) {
|
||||
int totalseconds = Platform_getUptime();
|
||||
if (totalseconds == -1) {
|
||||
snprintf(buffer, len, "(unknown)");
|
||||
xSnprintf(buffer, len, "(unknown)");
|
||||
return;
|
||||
}
|
||||
int seconds = totalseconds % 60;
|
||||
@ -31,17 +31,17 @@ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
if (days > this->total) {
|
||||
this->total = days;
|
||||
}
|
||||
char daysbuf[15];
|
||||
char daysbuf[32];
|
||||
if (days > 100) {
|
||||
sprintf(daysbuf, "%d days(!), ", days);
|
||||
xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
|
||||
} else if (days > 1) {
|
||||
sprintf(daysbuf, "%d days, ", days);
|
||||
xSnprintf(daysbuf, sizeof(daysbuf), "%d days, ", days);
|
||||
} else if (days == 1) {
|
||||
sprintf(daysbuf, "1 day, ");
|
||||
xSnprintf(daysbuf, sizeof(daysbuf), "1 day, ");
|
||||
} else {
|
||||
daysbuf[0] = '\0';
|
||||
}
|
||||
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
||||
xSnprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
MeterClass UptimeMeter_class = {
|
||||
@ -49,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",
|
||||
|
27
XAlloc.c
27
XAlloc.c
@ -5,11 +5,12 @@
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*{
|
||||
#include <err.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
}*/
|
||||
|
||||
@ -29,7 +30,7 @@ void* xMalloc(size_t size) {
|
||||
|
||||
void* xCalloc(size_t nmemb, size_t size) {
|
||||
void* data = calloc(nmemb, size);
|
||||
if (!data) {
|
||||
if (!data && nmemb > 0 && size > 0) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
@ -43,9 +44,27 @@ void* xRealloc(void* ptr, size_t size) {
|
||||
return data;
|
||||
}
|
||||
|
||||
char* xStrdup(const char* str) {
|
||||
#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
|
||||
|
||||
#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 && str) {
|
||||
if (!data) {
|
||||
fail();
|
||||
}
|
||||
return data;
|
||||
|
22
XAlloc.h
22
XAlloc.h
@ -7,6 +7,8 @@
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void* xMalloc(size_t size);
|
||||
@ -15,6 +17,24 @@ void* xCalloc(size_t nmemb, size_t size);
|
||||
|
||||
void* xRealloc(void* ptr, size_t size);
|
||||
|
||||
char* xStrdup(const char* str);
|
||||
#define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0)
|
||||
|
||||
#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
|
||||
|
14
autogen.sh
14
autogen.sh
@ -1,15 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
glibtoolize=$(which glibtoolize 2> /dev/null)
|
||||
if [ ${#glibtoolize} -gt 0 ]
|
||||
then libtoolize=glibtoolize
|
||||
else libtoolize=libtoolize
|
||||
fi
|
||||
|
||||
mkdir -p m4
|
||||
aclocal -I m4
|
||||
autoconf
|
||||
autoheader
|
||||
$libtoolize --copy --force
|
||||
automake --add-missing --copy
|
||||
|
||||
autoreconf --install --force
|
||||
|
129
configure.ac
129
configure.ac
@ -2,41 +2,45 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.65)
|
||||
AC_INIT([htop],[2.0.0],[hisham@gobolinux.org])
|
||||
AC_INIT([htop],[2.1.0],[hisham@gobolinux.org])
|
||||
|
||||
year=$(date +%Y)
|
||||
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")
|
||||
|
||||
# The following two lines are required by hwloc scripts
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
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
|
||||
|
||||
# Checks for platform.
|
||||
# ----------------------------------------------------------------------
|
||||
case "$target" in
|
||||
*linux*)
|
||||
case "$target_os" in
|
||||
linux*|gnu*)
|
||||
my_htop_platform=linux
|
||||
;;
|
||||
*freebsd*)
|
||||
freebsd*|kfreebsd*)
|
||||
my_htop_platform=freebsd
|
||||
;;
|
||||
*openbsd*)
|
||||
openbsd*)
|
||||
my_htop_platform=openbsd
|
||||
;;
|
||||
*darwin*)
|
||||
dragonfly*)
|
||||
my_htop_platform=dragonflybsd
|
||||
;;
|
||||
darwin*)
|
||||
my_htop_platform=darwin
|
||||
;;
|
||||
*)
|
||||
@ -74,15 +78,16 @@ 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_TRY_COMPILE([], [], [
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],[
|
||||
wextra_flag=-Wextra
|
||||
AC_MSG_RESULT([yes])
|
||||
],[
|
||||
@ -96,14 +101,14 @@ AC_SUBST(wextra_flag)
|
||||
# ----------------------------------------------------------------------
|
||||
PROCDIR=/proc
|
||||
|
||||
AC_ARG_ENABLE(proc, [AC_HELP_STRING([--enable-proc], [use Linux-compatible proc filesystem])], enable_proc="yes", enable_proc="no")
|
||||
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_WITH(proc, [AC_HELP_STRING([--with-proc=DIR], [Location of a Linux-compatible proc filesystem (default=/proc).])],
|
||||
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])
|
||||
@ -118,28 +123,28 @@ if test "x$cross_compiling" = xno; then
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(openvz, [AC_HELP_STRING([--enable-openvz], [enable OpenVZ support])], ,enable_openvz="no")
|
||||
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
|
||||
@ -147,7 +152,12 @@ fi
|
||||
# HTOP_CHECK_SCRIPT(LIBNAME, FUNCTION, DEFINE, CONFIG_SCRIPT, ELSE_PART)
|
||||
m4_define([HTOP_CHECK_SCRIPT],
|
||||
[
|
||||
htop_config_script=$([$4] --libs 2> /dev/null)
|
||||
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
|
||||
@ -173,17 +183,18 @@ m4_define([HTOP_CHECK_LIB],
|
||||
], [$4])
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
|
||||
AC_ARG_ENABLE(unicode, [AS_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
|
||||
if test "x$enable_unicode" = xyes; then
|
||||
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.])
|
||||
))))))
|
||||
HTOP_CHECK_SCRIPT([ncursesw], [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],[:],
|
||||
@ -211,8 +222,8 @@ 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([[
|
||||
@ -225,20 +236,37 @@ 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(setuid, [AS_HELP_STRING([--enable-setuid], [enable setuid support for platforms that need it])],, enable_setuid="no")
|
||||
if test "x$enable_setuid" = xyes
|
||||
then
|
||||
AC_DEFINE(HAVE_SETUID_ENABLED, 1, [Define if setuid support should be enabled.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable linux delay accounting])],, enable_delayacct="no")
|
||||
if test "x$enable_delayacct" = xyes
|
||||
then
|
||||
PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [missing_libraries="$missing_libraries libnl-3"])
|
||||
PKG_CHECK_MODULES(LIBNL3GENL, libnl-genl-3.0, [], [missing_libraries="$missing_libraries libnl-genl-3"])
|
||||
CFLAGS+=" $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
||||
LIBS+=" $LIBNL3_LIBS $LIBNL3GENL_LIBS"
|
||||
AC_DEFINE(HAVE_DELAYACCT, 1, [Define if delay accounting support should be enabled.])
|
||||
fi
|
||||
|
||||
|
||||
# Bail out on errors.
|
||||
# ----------------------------------------------------------------------
|
||||
if test ! -z "$missing_libraries"; then
|
||||
@ -254,9 +282,24 @@ AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-$year Hisham Muhammad", [Copyright messa
|
||||
# ----------------------------------------------------------------------
|
||||
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
|
||||
AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
||||
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
||||
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
|
||||
|
||||
if test "$my_htop_platform" = "unsupported"
|
||||
then
|
||||
echo ""
|
||||
echo "****************************************************************"
|
||||
echo "WARNING! This platform is not currently supported by htop."
|
||||
echo ""
|
||||
echo "The code will build, but it will produce a dummy version of htop"
|
||||
echo "which shows no processes, using the files from the unsupported/"
|
||||
echo "directory. This is meant to be a skeleton, to be used as a"
|
||||
echo "starting point if you are porting htop to a new platform."
|
||||
echo "****************************************************************"
|
||||
echo ""
|
||||
fi
|
||||
|
@ -13,6 +13,8 @@ in the source distribution for its full text.
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mach/mach.h>
|
||||
|
||||
/*{
|
||||
#include "Settings.h"
|
||||
#include "DarwinProcessList.h"
|
||||
@ -24,6 +26,7 @@ typedef struct DarwinProcess_ {
|
||||
|
||||
uint64_t utime;
|
||||
uint64_t stime;
|
||||
bool taskAccess;
|
||||
} DarwinProcess;
|
||||
|
||||
}*/
|
||||
@ -45,6 +48,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings) {
|
||||
|
||||
this->utime = 0;
|
||||
this->stime = 0;
|
||||
this->taskAccess = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -69,7 +73,7 @@ void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t no
|
||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
||||
}
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
||||
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;
|
||||
@ -167,13 +171,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
||||
/* Save where the argv[0] string starts. */
|
||||
sp = cp;
|
||||
|
||||
/*
|
||||
* Iterate through the '\0'-terminated strings and convert '\0' to ' '
|
||||
* until a string is found that has a '=' character in it (or there are
|
||||
* no more strings in procargs). There is no way to deterministically
|
||||
* know where the command arguments end and the environment strings
|
||||
* start, which is why the '=' character is searched for as a heuristic.
|
||||
*/
|
||||
*basenameOffset = 0;
|
||||
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
|
||||
if ( *cp == '\0' ) {
|
||||
c++;
|
||||
@ -183,49 +181,11 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
||||
}
|
||||
/* Note location of current '\0'. */
|
||||
np = cp;
|
||||
|
||||
if ( !show_args ) {
|
||||
/*
|
||||
* Don't convert '\0' characters to ' '.
|
||||
* However, we needed to know that the
|
||||
* command name was terminated, which we
|
||||
* now know.
|
||||
*/
|
||||
break;
|
||||
if (*basenameOffset == 0) {
|
||||
*basenameOffset = cp - sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
/*
|
||||
* If eflg is non-zero, continue converting '\0' characters to ' '
|
||||
* characters until no more strings that look like environment settings
|
||||
* follow.
|
||||
*/
|
||||
if ( ( eflg != 0 )
|
||||
&& ( ( getuid( ) == 0 )
|
||||
|| ( k->kp_eproc.e_pcred.p_ruid == getuid( ) ) ) ) {
|
||||
for ( ; cp < &procargs[size]; cp++ ) {
|
||||
if ( *cp == '\0' ) {
|
||||
if ( np != NULL ) {
|
||||
if ( &np[1] == cp ) {
|
||||
/*
|
||||
* Two '\0' characters in a row.
|
||||
* This should normally only
|
||||
* happen after all the strings
|
||||
* have been seen, but in any
|
||||
* case, stop parsing.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
/* Convert previous '\0'. */
|
||||
*np = ' ';
|
||||
}
|
||||
/* Note location of current '\0'. */
|
||||
np = cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* sp points to the beginning of the arguments/environment string, and
|
||||
@ -235,6 +195,9 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
||||
/* Empty or unterminated string. */
|
||||
goto ERROR_B;
|
||||
}
|
||||
if (*basenameOffset == 0) {
|
||||
*basenameOffset = np - sp;
|
||||
}
|
||||
|
||||
/* Make a copy of the string. */
|
||||
retval = xStrdup(sp);
|
||||
@ -248,7 +211,8 @@ ERROR_B:
|
||||
free( procargs );
|
||||
ERROR_A:
|
||||
retval = xStrdup(k->kp_proc.p_comm);
|
||||
|
||||
*basenameOffset = strlen(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -275,35 +239,22 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
|
||||
proc->ppid = ps->kp_eproc.e_ppid;
|
||||
proc->pgrp = ps->kp_eproc.e_pgid;
|
||||
proc->session = 0; /* TODO Get the session id */
|
||||
proc->tgid = ps->kp_eproc.e_tpgid;
|
||||
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);
|
||||
|
||||
/* The command is from the old Mac htop */
|
||||
char *slash;
|
||||
|
||||
proc->comm = DarwinProcess_getCmdLine(ps, false);
|
||||
slash = strrchr(proc->comm, '/');
|
||||
proc->basenameOffset = (NULL != slash) ? (slash - proc->comm) : 0;
|
||||
proc->comm = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset));
|
||||
}
|
||||
|
||||
/* Mutable information */
|
||||
proc->nice = ep->p_nice;
|
||||
proc->priority = ep->p_priority;
|
||||
|
||||
/* Set the state */
|
||||
switch(ep->p_stat) {
|
||||
case SIDL: proc->state = 'I'; break;
|
||||
case SRUN: proc->state = 'R'; break;
|
||||
case SSLEEP: proc->state = 'S'; break;
|
||||
case SSTOP: proc->state = 'T'; break;
|
||||
case SZOMB: proc->state = 'Z'; break;
|
||||
default: proc->state = '?'; break;
|
||||
}
|
||||
proc->state = (ep->p_stat == SZOMB) ? 'Z' : '?';
|
||||
|
||||
/* Make sure the updated flag is set */
|
||||
proc->updated = true;
|
||||
@ -327,8 +278,8 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
|
||||
|
||||
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;
|
||||
proc->super.m_resident = pti.pti_resident_size / 1024;
|
||||
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;
|
||||
@ -342,3 +293,71 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
|
||||
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;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ typedef struct DarwinProcess_ {
|
||||
|
||||
uint64_t utime;
|
||||
uint64_t stime;
|
||||
bool taskAccess;
|
||||
} DarwinProcess;
|
||||
|
||||
|
||||
@ -32,10 +33,17 @@ 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 show_args );
|
||||
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
|
||||
|
@ -168,8 +168,11 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
||||
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_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||
|
||||
// Disabled due to bug in macOS High Sierra
|
||||
// DarwinProcess_scanThreads(proc);
|
||||
|
||||
super->totalTasks += 1;
|
||||
|
||||
|
@ -33,7 +33,7 @@ in the source distribution for its full text.
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
|
||||
SignalItem Platform_signals[] = {
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
@ -69,7 +69,7 @@ SignalItem Platform_signals[] = {
|
||||
{ .name = "31 SIGUSR2", .number = 31 },
|
||||
};
|
||||
|
||||
unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
ProcessFieldData Process_fields[] = {
|
||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||
@ -78,8 +78,8 @@ ProcessFieldData Process_fields[] = {
|
||||
[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, },
|
||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||
@ -166,7 +166,7 @@ ProcessPidColumn Process_pidColumns[] = {
|
||||
{ .id = TPGID, .label = "TPGID" },
|
||||
{ .id = TGID, .label = "TGID" },
|
||||
{ .id = PGRP, .label = "PGRP" },
|
||||
{ .id = SESSION, .label = "SESN" },
|
||||
{ .id = SESSION, .label = "SID" },
|
||||
{ .id = 0, .label = NULL },
|
||||
};
|
||||
|
||||
@ -280,11 +280,9 @@ char* Platform_getProcessEnv(pid_t pid) {
|
||||
|
||||
size_t size = endp - p;
|
||||
env = xMalloc(size+2);
|
||||
if (env) {
|
||||
memcpy(env, p, size);
|
||||
env[size] = 0;
|
||||
env[size+1] = 0;
|
||||
}
|
||||
memcpy(env, p, size);
|
||||
env[size] = 0;
|
||||
env[size+1] = 0;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
|
@ -22,9 +22,9 @@ in the source distribution for its full text.
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern SignalItem Platform_signals[];
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern unsigned int Platform_numberOfSignals;
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
|
26
dragonflybsd/Battery.c
Normal file
26
dragonflybsd/Battery.c
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
htop - dragonflybsd/Battery.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
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;
|
||||
}
|
15
dragonflybsd/Battery.h
Normal file
15
dragonflybsd/Battery.h
Normal file
@ -0,0 +1,15 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Battery
|
||||
#define HEADER_Battery
|
||||
/*
|
||||
htop - dragonflybsd/Battery.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
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
|
35
dragonflybsd/DragonFlyBSDCRT.c
Normal file
35
dragonflybsd/DragonFlyBSDCRT.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
htop - dragonflybsd/DragonFlyBSDCRT.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "CRT.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn) {
|
||||
(void) sgn;
|
||||
CRT_done();
|
||||
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||
fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump");
|
||||
fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report.");
|
||||
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||
#else
|
||||
fprintf(stderr, "\nPlease contact your DragonFlyBSD package maintainer!\n\n");
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
19
dragonflybsd/DragonFlyBSDCRT.h
Normal file
19
dragonflybsd/DragonFlyBSDCRT.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_DragonFlyBSDCRT
|
||||
#define HEADER_DragonFlyBSDCRT
|
||||
/*
|
||||
htop - dragonflybsd/DragonFlyBSDCRT.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
|
||||
#endif
|
166
dragonflybsd/DragonFlyBSDProcess.c
Normal file
166
dragonflybsd/DragonFlyBSDProcess.c
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
htop - dragonflybsd/DragonFlyBSDProcess.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include "ProcessList.h"
|
||||
#include "DragonFlyBSDProcess.h"
|
||||
#include "Platform.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
/*{
|
||||
|
||||
typedef enum DragonFlyBSDProcessFields {
|
||||
// Add platform-specific fields here, with ids >= 100
|
||||
JID = 100,
|
||||
JAIL = 101,
|
||||
LAST_PROCESSFIELD = 102,
|
||||
} DragonFlyBSDProcessField;
|
||||
|
||||
|
||||
typedef struct DragonFlyBSDProcess_ {
|
||||
Process super;
|
||||
int kernel;
|
||||
int jid;
|
||||
char* jname;
|
||||
} DragonFlyBSDProcess;
|
||||
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
//#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||
#define Process_isUserlandThread(_process) (_process->nlwp > 1)
|
||||
#endif
|
||||
|
||||
}*/
|
||||
|
||||
ProcessClass DragonFlyBSDProcess_class = {
|
||||
.super = {
|
||||
.extends = Class(Process),
|
||||
.display = Process_display,
|
||||
.delete = Process_delete,
|
||||
.compare = DragonFlyBSDProcess_compare
|
||||
},
|
||||
.writeField = (Process_WriteField) DragonFlyBSDProcess_writeField,
|
||||
};
|
||||
|
||||
ProcessFieldData Process_fields[] = {
|
||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping (<20s), I Idle, Q Queued for Run, R running, D disk, Z zombie, T traced, W paging, B Blocked, A AskedPage, C Core, J Jailed)", .flags = 0, },
|
||||
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
|
||||
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
|
||||
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
|
||||
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
||||
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||
[JID] = { .name = "JID", .title = " JID ", .description = "Jail prison ID", .flags = 0, },
|
||||
[JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, },
|
||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||
};
|
||||
|
||||
ProcessPidColumn Process_pidColumns[] = {
|
||||
{ .id = JID, .label = "JID" },
|
||||
{ .id = PID, .label = "PID" },
|
||||
{ .id = PPID, .label = "PPID" },
|
||||
{ .id = TPGID, .label = "TPGID" },
|
||||
{ .id = TGID, .label = "TGID" },
|
||||
{ .id = PGRP, .label = "PGRP" },
|
||||
{ .id = SESSION, .label = "SID" },
|
||||
{ .id = 0, .label = NULL },
|
||||
};
|
||||
|
||||
DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings) {
|
||||
DragonFlyBSDProcess* this = xCalloc(1, sizeof(DragonFlyBSDProcess));
|
||||
Object_setClass(this, Class(DragonFlyBSDProcess));
|
||||
Process_init(&this->super, settings);
|
||||
return this;
|
||||
}
|
||||
|
||||
void Process_delete(Object* cast) {
|
||||
DragonFlyBSDProcess* this = (DragonFlyBSDProcess*) cast;
|
||||
Process_done((Process*)cast);
|
||||
free(this->jname);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this;
|
||||
char buffer[256]; buffer[255] = '\0';
|
||||
int attr = CRT_colors[DEFAULT_COLOR];
|
||||
int n = sizeof(buffer) - 1;
|
||||
switch ((int) field) {
|
||||
// add Platform-specific fields here
|
||||
case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break;
|
||||
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
||||
case JAIL:{
|
||||
xSnprintf(buffer, n, "%-11s ", fp->jname); break;
|
||||
if (buffer[11] != '\0') {
|
||||
buffer[11] = ' ';
|
||||
buffer[12] = '\0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Process_writeField(this, str, field);
|
||||
return;
|
||||
}
|
||||
RichString_append(str, attr, buffer);
|
||||
}
|
||||
|
||||
long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
|
||||
DragonFlyBSDProcess *p1, *p2;
|
||||
Settings *settings = ((Process*)v1)->settings;
|
||||
if (settings->direction == 1) {
|
||||
p1 = (DragonFlyBSDProcess*)v1;
|
||||
p2 = (DragonFlyBSDProcess*)v2;
|
||||
} else {
|
||||
p2 = (DragonFlyBSDProcess*)v1;
|
||||
p1 = (DragonFlyBSDProcess*)v2;
|
||||
}
|
||||
switch ((int) settings->sortKey) {
|
||||
// add Platform-specific fields here
|
||||
case JID:
|
||||
return (p1->jid - p2->jid);
|
||||
case JAIL:
|
||||
return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : "");
|
||||
default:
|
||||
return Process_compare(v1, v2);
|
||||
}
|
||||
}
|
||||
|
||||
bool Process_isThread(Process* this) {
|
||||
DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this;
|
||||
|
||||
if (fp->kernel == 1 )
|
||||
return 1;
|
||||
else
|
||||
return (Process_isUserlandThread(this));
|
||||
}
|
56
dragonflybsd/DragonFlyBSDProcess.h
Normal file
56
dragonflybsd/DragonFlyBSDProcess.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_DragonFlyBSDProcess
|
||||
#define HEADER_DragonFlyBSDProcess
|
||||
/*
|
||||
htop - dragonflybsd/DragonFlyBSDProcess.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
||||
typedef enum DragonFlyBSDProcessFields {
|
||||
// Add platform-specific fields here, with ids >= 100
|
||||
JID = 100,
|
||||
JAIL = 101,
|
||||
LAST_PROCESSFIELD = 102,
|
||||
} DragonFlyBSDProcessField;
|
||||
|
||||
|
||||
typedef struct DragonFlyBSDProcess_ {
|
||||
Process super;
|
||||
int kernel;
|
||||
int jid;
|
||||
char* jname;
|
||||
} DragonFlyBSDProcess;
|
||||
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
//#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||
#define Process_isUserlandThread(_process) (_process->nlwp > 1)
|
||||
#endif
|
||||
|
||||
|
||||
extern ProcessClass DragonFlyBSDProcess_class;
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
extern ProcessPidColumn Process_pidColumns[];
|
||||
|
||||
DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings);
|
||||
|
||||
void Process_delete(Object* cast);
|
||||
|
||||
void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field);
|
||||
|
||||
long DragonFlyBSDProcess_compare(const void* v1, const void* v2);
|
||||
|
||||
bool Process_isThread(Process* this);
|
||||
|
||||
#endif
|
578
dragonflybsd/DragonFlyBSDProcessList.c
Normal file
578
dragonflybsd/DragonFlyBSDProcessList.c
Normal file
@ -0,0 +1,578 @@
|
||||
/*
|
||||
htop - DragonFlyBSDProcessList.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "DragonFlyBSDProcessList.h"
|
||||
#include "DragonFlyBSDProcess.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
/*{
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <osreldate.h>
|
||||
#include <sys/kinfo.h>
|
||||
#include <kinfo.h>
|
||||
#include <sys/jail.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/resource.h>
|
||||
#include "Hashtable.h"
|
||||
#include "DragonFlyBSDProcess.h"
|
||||
|
||||
#define JAIL_ERRMSGLEN 1024
|
||||
char jail_errmsg[JAIL_ERRMSGLEN];
|
||||
|
||||
typedef struct CPUData_ {
|
||||
|
||||
double userPercent;
|
||||
double nicePercent;
|
||||
double systemPercent;
|
||||
double irqPercent;
|
||||
double idlePercent;
|
||||
double systemAllPercent;
|
||||
|
||||
} CPUData;
|
||||
|
||||
typedef struct DragonFlyBSDProcessList_ {
|
||||
ProcessList super;
|
||||
kvm_t* kd;
|
||||
|
||||
unsigned long long int memWire;
|
||||
unsigned long long int memActive;
|
||||
unsigned long long int memInactive;
|
||||
unsigned long long int memFree;
|
||||
|
||||
CPUData* cpus;
|
||||
|
||||
unsigned long *cp_time_o;
|
||||
unsigned long *cp_time_n;
|
||||
|
||||
unsigned long *cp_times_o;
|
||||
unsigned long *cp_times_n;
|
||||
|
||||
Hashtable *jails;
|
||||
} DragonFlyBSDProcessList;
|
||||
|
||||
}*/
|
||||
|
||||
#define _UNUSED_ __attribute__((unused))
|
||||
|
||||
static int MIB_hw_physmem[2];
|
||||
static int MIB_vm_stats_vm_v_page_count[4];
|
||||
static int pageSize;
|
||||
static int pageSizeKb;
|
||||
|
||||
static int MIB_vm_stats_vm_v_wire_count[4];
|
||||
static int MIB_vm_stats_vm_v_active_count[4];
|
||||
static int MIB_vm_stats_vm_v_cache_count[4];
|
||||
static int MIB_vm_stats_vm_v_inactive_count[4];
|
||||
static int MIB_vm_stats_vm_v_free_count[4];
|
||||
|
||||
static int MIB_vfs_bufspace[2];
|
||||
|
||||
static int MIB_kern_cp_time[2];
|
||||
static int MIB_kern_cp_times[2];
|
||||
static int kernelFScale;
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||
size_t len;
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
DragonFlyBSDProcessList* dfpl = xCalloc(1, sizeof(DragonFlyBSDProcessList));
|
||||
ProcessList* pl = (ProcessList*) dfpl;
|
||||
ProcessList_init(pl, Class(DragonFlyBSDProcess), usersTable, pidWhiteList, userId);
|
||||
|
||||
// physical memory in system: hw.physmem
|
||||
// physical page size: hw.pagesize
|
||||
// usable pagesize : vm.stats.vm.v_page_size
|
||||
len = 2; sysctlnametomib("hw.physmem", MIB_hw_physmem, &len);
|
||||
|
||||
len = sizeof(pageSize);
|
||||
if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) {
|
||||
pageSize = PAGE_SIZE;
|
||||
pageSizeKb = PAGE_SIZE_KB;
|
||||
} else {
|
||||
pageSizeKb = pageSize / ONE_K;
|
||||
}
|
||||
|
||||
// usable page count vm.stats.vm.v_page_count
|
||||
// actually usable memory : vm.stats.vm.v_page_count * vm.stats.vm.v_page_size
|
||||
len = 4; sysctlnametomib("vm.stats.vm.v_page_count", MIB_vm_stats_vm_v_page_count, &len);
|
||||
|
||||
len = 4; sysctlnametomib("vm.stats.vm.v_wire_count", MIB_vm_stats_vm_v_wire_count, &len);
|
||||
len = 4; sysctlnametomib("vm.stats.vm.v_active_count", MIB_vm_stats_vm_v_active_count, &len);
|
||||
len = 4; sysctlnametomib("vm.stats.vm.v_cache_count", MIB_vm_stats_vm_v_cache_count, &len);
|
||||
len = 4; sysctlnametomib("vm.stats.vm.v_inactive_count", MIB_vm_stats_vm_v_inactive_count, &len);
|
||||
len = 4; sysctlnametomib("vm.stats.vm.v_free_count", MIB_vm_stats_vm_v_free_count, &len);
|
||||
|
||||
len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len);
|
||||
|
||||
int cpus = 1;
|
||||
len = sizeof(cpus);
|
||||
if (sysctlbyname("hw.ncpu", &cpus, &len, NULL, 0) != 0) {
|
||||
cpus = 1;
|
||||
}
|
||||
|
||||
size_t sizeof_cp_time_array = sizeof(unsigned long) * CPUSTATES;
|
||||
len = 2; sysctlnametomib("kern.cp_time", MIB_kern_cp_time, &len);
|
||||
dfpl->cp_time_o = xCalloc(cpus, sizeof_cp_time_array);
|
||||
dfpl->cp_time_n = xCalloc(cpus, sizeof_cp_time_array);
|
||||
len = sizeof_cp_time_array;
|
||||
|
||||
// fetch initial single (or average) CPU clicks from kernel
|
||||
sysctl(MIB_kern_cp_time, 2, dfpl->cp_time_o, &len, NULL, 0);
|
||||
|
||||
// on smp box, fetch rest of initial CPU's clicks
|
||||
if (cpus > 1) {
|
||||
len = 2; sysctlnametomib("kern.cp_times", MIB_kern_cp_times, &len);
|
||||
dfpl->cp_times_o = xCalloc(cpus, sizeof_cp_time_array);
|
||||
dfpl->cp_times_n = xCalloc(cpus, sizeof_cp_time_array);
|
||||
len = cpus * sizeof_cp_time_array;
|
||||
sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_o, &len, NULL, 0);
|
||||
}
|
||||
|
||||
pl->cpuCount = MAX(cpus, 1);
|
||||
|
||||
if (cpus == 1 ) {
|
||||
dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData));
|
||||
} else {
|
||||
// on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well)
|
||||
dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
|
||||
}
|
||||
|
||||
len = sizeof(kernelFScale);
|
||||
if (sysctlbyname("kern.fscale", &kernelFScale, &len, NULL, 0) == -1) {
|
||||
//sane default for kernel provided CPU percentage scaling, at least on x86 machines, in case this sysctl call failed
|
||||
kernelFScale = 2048;
|
||||
}
|
||||
|
||||
dfpl->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf);
|
||||
if (dfpl->kd == NULL) {
|
||||
errx(1, "kvm_open: %s", errbuf);
|
||||
}
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
void ProcessList_delete(ProcessList* this) {
|
||||
const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this;
|
||||
if (dfpl->kd) kvm_close(dfpl->kd);
|
||||
|
||||
if (dfpl->jails) {
|
||||
Hashtable_delete(dfpl->jails);
|
||||
}
|
||||
free(dfpl->cp_time_o);
|
||||
free(dfpl->cp_time_n);
|
||||
free(dfpl->cp_times_o);
|
||||
free(dfpl->cp_times_n);
|
||||
free(dfpl->cpus);
|
||||
|
||||
ProcessList_done(this);
|
||||
free(this);
|
||||
}
|
||||
|
||||
static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
|
||||
const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) pl;
|
||||
|
||||
int cpus = pl->cpuCount; // actual CPU count
|
||||
int maxcpu = cpus; // max iteration (in case we have average + smp)
|
||||
int cp_times_offset;
|
||||
|
||||
assert(cpus > 0);
|
||||
|
||||
size_t sizeof_cp_time_array;
|
||||
|
||||
unsigned long *cp_time_n; // old clicks state
|
||||
unsigned long *cp_time_o; // current clicks state
|
||||
|
||||
unsigned long cp_time_d[CPUSTATES];
|
||||
double cp_time_p[CPUSTATES];
|
||||
|
||||
// get averages or single CPU clicks
|
||||
sizeof_cp_time_array = sizeof(unsigned long) * CPUSTATES;
|
||||
sysctl(MIB_kern_cp_time, 2, dfpl->cp_time_n, &sizeof_cp_time_array, NULL, 0);
|
||||
|
||||
// get rest of CPUs
|
||||
if (cpus > 1) {
|
||||
// on smp systems DragonFlyBSD kernel concats all CPU states into one long array in
|
||||
// kern.cp_times sysctl OID
|
||||
// we store averages in dfpl->cpus[0], and actual cores after that
|
||||
maxcpu = cpus + 1;
|
||||
sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES;
|
||||
sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxcpu; i++) {
|
||||
if (cpus == 1) {
|
||||
// single CPU box
|
||||
cp_time_n = dfpl->cp_time_n;
|
||||
cp_time_o = dfpl->cp_time_o;
|
||||
} else {
|
||||
if (i == 0 ) {
|
||||
// average
|
||||
cp_time_n = dfpl->cp_time_n;
|
||||
cp_time_o = dfpl->cp_time_o;
|
||||
} else {
|
||||
// specific smp cores
|
||||
cp_times_offset = i - 1;
|
||||
cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES);
|
||||
cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES);
|
||||
}
|
||||
}
|
||||
|
||||
// diff old vs new
|
||||
unsigned long long total_o = 0;
|
||||
unsigned long long total_n = 0;
|
||||
unsigned long long total_d = 0;
|
||||
for (int s = 0; s < CPUSTATES; s++) {
|
||||
cp_time_d[s] = cp_time_n[s] - cp_time_o[s];
|
||||
total_o += cp_time_o[s];
|
||||
total_n += cp_time_n[s];
|
||||
}
|
||||
|
||||
// totals
|
||||
total_d = total_n - total_o;
|
||||
if (total_d < 1 ) total_d = 1;
|
||||
|
||||
// save current state as old and calc percentages
|
||||
for (int s = 0; s < CPUSTATES; ++s) {
|
||||
cp_time_o[s] = cp_time_n[s];
|
||||
cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100;
|
||||
}
|
||||
|
||||
CPUData* cpuData = &(dfpl->cpus[i]);
|
||||
cpuData->userPercent = cp_time_p[CP_USER];
|
||||
cpuData->nicePercent = cp_time_p[CP_NICE];
|
||||
cpuData->systemPercent = cp_time_p[CP_SYS];
|
||||
cpuData->irqPercent = cp_time_p[CP_INTR];
|
||||
cpuData->systemAllPercent = cp_time_p[CP_SYS] + cp_time_p[CP_INTR];
|
||||
// this one is not really used, but we store it anyway
|
||||
cpuData->idlePercent = cp_time_p[CP_IDLE];
|
||||
}
|
||||
}
|
||||
|
||||
static inline void DragonFlyBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||
DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) pl;
|
||||
|
||||
// @etosan:
|
||||
// memory counter relationships seem to be these:
|
||||
// total = active + wired + inactive + cache + free
|
||||
// htop_used (unavail to anybody) = active + wired
|
||||
// htop_cache (for cache meter) = buffers + cache
|
||||
// user_free (avail to procs) = buffers + inactive + cache + free
|
||||
size_t len = sizeof(pl->totalMem);
|
||||
|
||||
//disabled for now, as it is always smaller than phycal amount of memory...
|
||||
//...to avoid "where is my memory?" questions
|
||||
//sysctl(MIB_vm_stats_vm_v_page_count, 4, &(pl->totalMem), &len, NULL, 0);
|
||||
//pl->totalMem *= pageSizeKb;
|
||||
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0);
|
||||
pl->totalMem /= 1024;
|
||||
|
||||
sysctl(MIB_vm_stats_vm_v_active_count, 4, &(dfpl->memActive), &len, NULL, 0);
|
||||
dfpl->memActive *= pageSizeKb;
|
||||
|
||||
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(dfpl->memWire), &len, NULL, 0);
|
||||
dfpl->memWire *= pageSizeKb;
|
||||
|
||||
sysctl(MIB_vfs_bufspace, 2, &(pl->buffersMem), &len, NULL, 0);
|
||||
pl->buffersMem /= 1024;
|
||||
|
||||
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0);
|
||||
pl->cachedMem *= pageSizeKb;
|
||||
pl->usedMem = dfpl->memActive + dfpl->memWire;
|
||||
|
||||
//currently unused, same as with arc, custom meter perhaps
|
||||
//sysctl(MIB_vm_stats_vm_v_inactive_count, 4, &(dfpl->memInactive), &len, NULL, 0);
|
||||
//sysctl(MIB_vm_stats_vm_v_free_count, 4, &(dfpl->memFree), &len, NULL, 0);
|
||||
//pl->freeMem = dfpl->memInactive + dfpl->memFree;
|
||||
//pl->freeMem *= pageSizeKb;
|
||||
|
||||
struct kvm_swap swap[16];
|
||||
int nswap = kvm_getswapinfo(dfpl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0);
|
||||
pl->totalSwap = 0;
|
||||
pl->usedSwap = 0;
|
||||
for (int i = 0; i < nswap; i++) {
|
||||
pl->totalSwap += swap[i].ksw_total;
|
||||
pl->usedSwap += swap[i].ksw_used;
|
||||
}
|
||||
pl->totalSwap *= pageSizeKb;
|
||||
pl->usedSwap *= pageSizeKb;
|
||||
|
||||
pl->sharedMem = 0; // currently unused
|
||||
}
|
||||
|
||||
char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) {
|
||||
char** argv = kvm_getargv(kd, kproc, 0);
|
||||
if (!argv) {
|
||||
return xStrdup(kproc->kp_comm);
|
||||
}
|
||||
int len = 0;
|
||||
for (int i = 0; argv[i]; i++) {
|
||||
len += strlen(argv[i]) + 1;
|
||||
}
|
||||
char* comm = xMalloc(len);
|
||||
char* at = comm;
|
||||
*basenameEnd = 0;
|
||||
for (int i = 0; argv[i]; i++) {
|
||||
at = stpcpy(at, argv[i]);
|
||||
if (!*basenameEnd) {
|
||||
*basenameEnd = at - comm;
|
||||
}
|
||||
*at = ' ';
|
||||
at++;
|
||||
}
|
||||
at--;
|
||||
*at = '\0';
|
||||
return comm;
|
||||
}
|
||||
|
||||
static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* dfpl) {
|
||||
size_t len;
|
||||
char *jls; /* Jail list */
|
||||
char *curpos;
|
||||
char *nextpos;
|
||||
|
||||
if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) {
|
||||
fprintf(stderr, "initial sysctlbyname / jail.list failed\n");
|
||||
exit(3);
|
||||
}
|
||||
retry:
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
jls = xMalloc(len);
|
||||
if (jls == NULL) {
|
||||
fprintf(stderr, "xMalloc failed\n");
|
||||
exit(4);
|
||||
}
|
||||
if (sysctlbyname("jail.list", jls, &len, NULL, 0) == -1) {
|
||||
if (errno == ENOMEM) {
|
||||
free(jls);
|
||||
goto retry;
|
||||
}
|
||||
fprintf(stderr, "sysctlbyname / jail.list failed\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
if (dfpl->jails) {
|
||||
Hashtable_delete(dfpl->jails);
|
||||
}
|
||||
dfpl->jails = Hashtable_new(20, true);
|
||||
curpos = jls;
|
||||
while (curpos) {
|
||||
int jailid;
|
||||
char *str_hostname;
|
||||
nextpos = strchr(curpos, '\n');
|
||||
if (nextpos)
|
||||
*nextpos++ = 0;
|
||||
|
||||
jailid = atoi(strtok(curpos, " "));
|
||||
str_hostname = strtok(NULL, " ");
|
||||
|
||||
char *jname = (char *) (Hashtable_get(dfpl->jails, jailid));
|
||||
if (jname == NULL) {
|
||||
jname = xStrdup(str_hostname);
|
||||
Hashtable_put(dfpl->jails, jailid, jname);
|
||||
}
|
||||
|
||||
curpos = nextpos;
|
||||
}
|
||||
free(jls);
|
||||
}
|
||||
|
||||
char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) {
|
||||
char* hostname;
|
||||
char* jname;
|
||||
|
||||
if (jailid != 0 && dfpl->jails && (hostname = (char *)Hashtable_get(dfpl->jails, jailid))) {
|
||||
jname = xStrdup(hostname);
|
||||
} else {
|
||||
jname = xStrdup("-");
|
||||
}
|
||||
return jname;
|
||||
}
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this;
|
||||
Settings* settings = this->settings;
|
||||
bool hideKernelThreads = settings->hideKernelThreads;
|
||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||
|
||||
DragonFlyBSDProcessList_scanMemoryInfo(this);
|
||||
DragonFlyBSDProcessList_scanCPUTime(this);
|
||||
DragonFlyBSDProcessList_scanJails(dfpl);
|
||||
|
||||
int count = 0;
|
||||
|
||||
// TODO Kernel Threads seem to be skipped, need to figure out the correct flag
|
||||
struct kinfo_proc* kprocs = kvm_getprocs(dfpl->kd, KERN_PROC_ALL | (!hideUserlandThreads ? KERN_PROC_FLAG_LWP : 0), 0, &count);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
struct kinfo_proc* kproc = &kprocs[i];
|
||||
bool preExisting = false;
|
||||
bool _UNUSED_ isIdleProcess = false;
|
||||
|
||||
// note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier
|
||||
Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new);
|
||||
DragonFlyBSDProcess* dfp = (DragonFlyBSDProcess*) proc;
|
||||
|
||||
proc->show = ! ((hideKernelThreads && Process_isKernelThread(dfp)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
|
||||
|
||||
if (!preExisting) {
|
||||
dfp->jid = kproc->kp_jailid;
|
||||
if (kproc->kp_ktaddr && kproc->kp_flags & P_SYSTEM) {
|
||||
// dfb kernel threads all have the same pid, so we misuse the kernel thread address to give them a unique identifier
|
||||
proc->pid = (pid_t)kproc->kp_ktaddr;
|
||||
dfp->kernel = 1;
|
||||
} else {
|
||||
proc->pid = kproc->kp_pid; // process ID
|
||||
dfp->kernel = 0;
|
||||
}
|
||||
proc->ppid = kproc->kp_ppid; // parent process id
|
||||
proc->tpgid = kproc->kp_tpgid; // tty process group id
|
||||
//proc->tgid = kproc->kp_lwp.kl_tid; // thread group id
|
||||
proc->tgid = kproc->kp_pid; // thread group id
|
||||
proc->pgrp = kproc->kp_pgid; // process group id
|
||||
proc->session = kproc->kp_sid;
|
||||
proc->tty_nr = kproc->kp_tdev; // control terminal device number
|
||||
proc->st_uid = kproc->kp_uid; // user ID
|
||||
proc->processor = kproc->kp_lwp.kl_origcpu;
|
||||
proc->starttime_ctime = kproc->kp_start.tv_sec;
|
||||
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
|
||||
|
||||
ProcessList_add((ProcessList*)this, proc);
|
||||
proc->comm = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->basenameOffset);
|
||||
dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid);
|
||||
} else {
|
||||
proc->processor = kproc->kp_lwp.kl_cpuid;
|
||||
if(dfp->jid != kproc->kp_jailid) { // process can enter jail anytime
|
||||
dfp->jid = kproc->kp_jailid;
|
||||
free(dfp->jname);
|
||||
dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid);
|
||||
}
|
||||
if (proc->ppid != kproc->kp_ppid) { // if there are reapers in the system, process can get reparented anytime
|
||||
proc->ppid = kproc->kp_ppid;
|
||||
}
|
||||
if(proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs)
|
||||
proc->st_uid = kproc->kp_uid;
|
||||
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
|
||||
}
|
||||
if (settings->updateProcessNames) {
|
||||
free(proc->comm);
|
||||
proc->comm = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->basenameOffset);
|
||||
}
|
||||
}
|
||||
|
||||
proc->m_size = kproc->kp_vm_map_size / 1024 / pageSizeKb;
|
||||
proc->m_resident = kproc->kp_vm_rssize;
|
||||
proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0;
|
||||
proc->nlwp = kproc->kp_nthreads; // number of lwp thread
|
||||
proc->time = (kproc->kp_swtime + 5000) / 10000;
|
||||
|
||||
proc->percent_cpu = 100.0 * ((double)kproc->kp_lwp.kl_pctcpu / (double)kernelFScale);
|
||||
proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem);
|
||||
|
||||
if (proc->percent_cpu > 0.1) {
|
||||
// system idle process should own all CPU time left regardless of CPU count
|
||||
if ( strcmp("idle", kproc->kp_comm) == 0 ) {
|
||||
isIdleProcess = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (kproc->kp_lwp.kl_pid != -1)
|
||||
proc->priority = kproc->kp_lwp.kl_prio;
|
||||
else
|
||||
proc->priority = -kproc->kp_lwp.kl_tdprio;
|
||||
|
||||
switch(kproc->kp_lwp.kl_rtprio.type) {
|
||||
case RTP_PRIO_REALTIME:
|
||||
proc->nice = PRIO_MIN - 1 - RTP_PRIO_MAX + kproc->kp_lwp.kl_rtprio.prio;
|
||||
break;
|
||||
case RTP_PRIO_IDLE:
|
||||
proc->nice = PRIO_MAX + 1 + kproc->kp_lwp.kl_rtprio.prio;
|
||||
break;
|
||||
case RTP_PRIO_THREAD:
|
||||
proc->nice = PRIO_MIN - 1 - RTP_PRIO_MAX - kproc->kp_lwp.kl_rtprio.prio;
|
||||
break;
|
||||
default:
|
||||
proc->nice = kproc->kp_nice;
|
||||
break;
|
||||
}
|
||||
|
||||
// would be nice if we could store multiple states in proc->state (as enum) and have writeField render them
|
||||
switch (kproc->kp_stat) {
|
||||
case SIDL: proc->state = 'I'; isIdleProcess = true; break;
|
||||
case SACTIVE:
|
||||
switch (kproc->kp_lwp.kl_stat) {
|
||||
case LSSLEEP:
|
||||
if (kproc->kp_lwp.kl_flags & LWP_SINTR) // interruptable wait short/long
|
||||
if (kproc->kp_lwp.kl_slptime >= MAXSLP) {
|
||||
proc->state = 'I';
|
||||
isIdleProcess = true;
|
||||
} else {
|
||||
proc->state = 'S';
|
||||
}
|
||||
else if (kproc->kp_lwp.kl_tdflags & TDF_SINTR) // interruptable lwkt wait
|
||||
proc->state = 'S';
|
||||
else if (kproc->kp_paddr) // uninterruptable wait
|
||||
proc->state = 'D';
|
||||
else // uninterruptable lwkt wait
|
||||
proc->state = 'B';
|
||||
break;
|
||||
case LSRUN:
|
||||
if (kproc->kp_lwp.kl_stat == LSRUN) {
|
||||
if (!(kproc->kp_lwp.kl_tdflags & (TDF_RUNNING | TDF_RUNQ)))
|
||||
proc->state = 'Q';
|
||||
else
|
||||
proc->state = 'R';
|
||||
}
|
||||
break;
|
||||
case LSSTOP:
|
||||
proc->state = 'T';
|
||||
break;
|
||||
default:
|
||||
proc->state = 'A';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SSTOP: proc->state = 'T'; break;
|
||||
case SZOMB: proc->state = 'Z'; break;
|
||||
case SCORE: proc->state = 'C'; break;
|
||||
default: proc->state = '?';
|
||||
}
|
||||
|
||||
if (kproc->kp_flags & P_SWAPPEDOUT) {
|
||||
proc->state = 'W';
|
||||
}
|
||||
if (kproc->kp_flags & P_TRACED) {
|
||||
proc->state = 'T';
|
||||
}
|
||||
if (kproc->kp_flags & P_JAILED) {
|
||||
proc->state = 'J';
|
||||
}
|
||||
|
||||
if (Process_isKernelThread(dfp)) {
|
||||
this->kernelThreads++;
|
||||
}
|
||||
|
||||
this->totalTasks++;
|
||||
if (proc->state == 'R')
|
||||
this->runningTasks++;
|
||||
proc->updated = true;
|
||||
}
|
||||
}
|
73
dragonflybsd/DragonFlyBSDProcessList.h
Normal file
73
dragonflybsd/DragonFlyBSDProcessList.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_DragonFlyBSDProcessList
|
||||
#define HEADER_DragonFlyBSDProcessList
|
||||
/*
|
||||
htop - DragonFlyBSDProcessList.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <osreldate.h>
|
||||
#include <sys/kinfo.h>
|
||||
#include <kinfo.h>
|
||||
#include <sys/jail.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/resource.h>
|
||||
#include "Hashtable.h"
|
||||
#include "DragonFlyBSDProcess.h"
|
||||
|
||||
#define JAIL_ERRMSGLEN 1024
|
||||
char jail_errmsg[JAIL_ERRMSGLEN];
|
||||
|
||||
typedef struct CPUData_ {
|
||||
|
||||
double userPercent;
|
||||
double nicePercent;
|
||||
double systemPercent;
|
||||
double irqPercent;
|
||||
double idlePercent;
|
||||
double systemAllPercent;
|
||||
|
||||
} CPUData;
|
||||
|
||||
typedef struct DragonFlyBSDProcessList_ {
|
||||
ProcessList super;
|
||||
kvm_t* kd;
|
||||
|
||||
unsigned long long int memWire;
|
||||
unsigned long long int memActive;
|
||||
unsigned long long int memInactive;
|
||||
unsigned long long int memFree;
|
||||
|
||||
CPUData* cpus;
|
||||
|
||||
unsigned long *cp_time_o;
|
||||
unsigned long *cp_time_n;
|
||||
|
||||
unsigned long *cp_times_o;
|
||||
unsigned long *cp_times_n;
|
||||
|
||||
Hashtable *jails;
|
||||
} DragonFlyBSDProcessList;
|
||||
|
||||
|
||||
#define _UNUSED_ __attribute__((unused))
|
||||
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
void ProcessList_delete(ProcessList* this);
|
||||
|
||||
char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd);
|
||||
|
||||
char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid);
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* this);
|
||||
|
||||
#endif
|
210
dragonflybsd/Platform.c
Normal file
210
dragonflybsd/Platform.c
Normal file
@ -0,0 +1,210 @@
|
||||
/*
|
||||
htop - dragonflybsd/Platform.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Platform.h"
|
||||
#include "Meter.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "MemoryMeter.h"
|
||||
#include "SwapMeter.h"
|
||||
#include "TasksMeter.h"
|
||||
#include "LoadAverageMeter.h"
|
||||
#include "UptimeMeter.h"
|
||||
#include "ClockMeter.h"
|
||||
#include "HostnameMeter.h"
|
||||
#include "DragonFlyBSDProcess.h"
|
||||
#include "DragonFlyBSDProcessList.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
/*{
|
||||
#include "Action.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "SignalsPanel.h"
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
}*/
|
||||
|
||||
#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 };
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
{ .name = " 3 SIGQUIT", .number = 3 },
|
||||
{ .name = " 4 SIGILL", .number = 4 },
|
||||
{ .name = " 5 SIGTRAP", .number = 5 },
|
||||
{ .name = " 6 SIGABRT", .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 },
|
||||
{ .name = "32 SIGTHR", .number = 32 },
|
||||
{ .name = "33 SIGLIBRT", .number = 33 },
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys) {
|
||||
(void) keys;
|
||||
}
|
||||
|
||||
MeterClass* Platform_meterTypes[] = {
|
||||
&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
|
||||
};
|
||||
|
||||
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) {
|
||||
struct loadavg loadAverage;
|
||||
int mib[2] = { CTL_VM, VM_LOADAVG };
|
||||
size_t size = sizeof(loadAverage);
|
||||
|
||||
int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0);
|
||||
if (err) {
|
||||
*one = 0;
|
||||
*five = 0;
|
||||
*fifteen = 0;
|
||||
return;
|
||||
}
|
||||
*one = (double) loadAverage.ldavg[0] / loadAverage.fscale;
|
||||
*five = (double) loadAverage.ldavg[1] / loadAverage.fscale;
|
||||
*fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale;
|
||||
}
|
||||
|
||||
int Platform_getMaxPid() {
|
||||
int maxPid;
|
||||
size_t size = sizeof(maxPid);
|
||||
int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0);
|
||||
if (err) {
|
||||
return 999999;
|
||||
}
|
||||
return maxPid;
|
||||
}
|
||||
|
||||
double Platform_setCPUValues(Meter* this, int cpu) {
|
||||
DragonFlyBSDProcessList* fpl = (DragonFlyBSDProcessList*) this->pl;
|
||||
int cpus = this->pl->cpuCount;
|
||||
CPUData* cpuData;
|
||||
|
||||
if (cpus == 1) {
|
||||
// single CPU box has everything in fpl->cpus[0]
|
||||
cpuData = &(fpl->cpus[0]);
|
||||
} else {
|
||||
cpuData = &(fpl->cpus[cpu]);
|
||||
}
|
||||
|
||||
double percent;
|
||||
double* v = this->values;
|
||||
|
||||
v[CPU_METER_NICE] = cpuData->nicePercent;
|
||||
v[CPU_METER_NORMAL] = cpuData->userPercent;
|
||||
if (this->pl->settings->detailedCPUTime) {
|
||||
v[CPU_METER_KERNEL] = cpuData->systemPercent;
|
||||
v[CPU_METER_IRQ] = cpuData->irqPercent;
|
||||
Meter_setItems(this, 4);
|
||||
percent = v[0]+v[1]+v[2]+v[3];
|
||||
} else {
|
||||
v[2] = cpuData->systemAllPercent;
|
||||
Meter_setItems(this, 3);
|
||||
percent = v[0]+v[1]+v[2];
|
||||
}
|
||||
|
||||
percent = CLAMP(percent, 0.0, 100.0);
|
||||
if (isnan(percent)) percent = 0.0;
|
||||
return percent;
|
||||
}
|
||||
|
||||
void Platform_setMemoryValues(Meter* this) {
|
||||
// TODO
|
||||
ProcessList* pl = (ProcessList*) this->pl;
|
||||
|
||||
this->total = pl->totalMem;
|
||||
this->values[0] = pl->usedMem;
|
||||
this->values[1] = pl->buffersMem;
|
||||
this->values[2] = pl->cachedMem;
|
||||
}
|
||||
|
||||
void Platform_setSwapValues(Meter* this) {
|
||||
ProcessList* pl = (ProcessList*) this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
}
|
||||
|
||||
void Platform_setTasksValues(Meter* this) {
|
||||
// TODO
|
||||
(void)this; // prevent unused warning
|
||||
}
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid) {
|
||||
// TODO
|
||||
(void)pid; // prevent unused warning
|
||||
return NULL;
|
||||
}
|
52
dragonflybsd/Platform.h
Normal file
52
dragonflybsd/Platform.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Platform
|
||||
#define HEADER_Platform
|
||||
/*
|
||||
htop - dragonflybsd/Platform.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017 Diederik de Groot
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Action.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "SignalsPanel.h"
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
||||
extern MeterClass* Platform_meterTypes[];
|
||||
|
||||
int Platform_getUptime();
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||
|
||||
int Platform_getMaxPid();
|
||||
|
||||
double Platform_setCPUValues(Meter* this, int cpu);
|
||||
|
||||
void Platform_setMemoryValues(Meter* this);
|
||||
|
||||
void Platform_setSwapValues(Meter* this);
|
||||
|
||||
void Platform_setTasksValues(Meter* this);
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid);
|
||||
|
||||
#endif
|
@ -6,10 +6,20 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "BatteryMeter.h"
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
// TODO
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -11,5 +11,4 @@ in the source distribution for its full text.
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -61,8 +61,8 @@ ProcessFieldData Process_fields[] = {
|
||||
[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, },
|
||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||
@ -92,7 +92,7 @@ ProcessPidColumn Process_pidColumns[] = {
|
||||
{ .id = TPGID, .label = "TPGID" },
|
||||
{ .id = TGID, .label = "TGID" },
|
||||
{ .id = PGRP, .label = "PGRP" },
|
||||
{ .id = SESSION, .label = "SESN" },
|
||||
{ .id = SESSION, .label = "SID" },
|
||||
{ .id = 0, .label = NULL },
|
||||
};
|
||||
|
||||
@ -115,11 +115,11 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel
|
||||
char buffer[256]; buffer[255] = '\0';
|
||||
int attr = CRT_colors[DEFAULT_COLOR];
|
||||
int n = sizeof(buffer) - 1;
|
||||
switch (field) {
|
||||
switch ((int) field) {
|
||||
// add FreeBSD-specific fields here
|
||||
case JID: snprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
||||
case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
|
||||
case JAIL:{
|
||||
snprintf(buffer, n, "%-11s ", fp->jname); break;
|
||||
xSnprintf(buffer, n, "%-11s ", fp->jname); break;
|
||||
if (buffer[11] != '\0') {
|
||||
buffer[11] = ' ';
|
||||
buffer[12] = '\0';
|
||||
@ -143,7 +143,7 @@ long FreeBSDProcess_compare(const void* v1, const void* v2) {
|
||||
p2 = (FreeBSDProcess*)v1;
|
||||
p1 = (FreeBSDProcess*)v2;
|
||||
}
|
||||
switch (settings->sortKey) {
|
||||
switch ((int) settings->sortKey) {
|
||||
// add FreeBSD-specific fields here
|
||||
case JID:
|
||||
return (p1->jid - p2->jid);
|
||||
|
@ -14,7 +14,9 @@ in the source distribution for its full text.
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
/*{
|
||||
@ -84,14 +86,13 @@ static int MIB_kern_cp_time[2];
|
||||
static int MIB_kern_cp_times[2];
|
||||
static int kernelFScale;
|
||||
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||
size_t len;
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList));
|
||||
ProcessList* pl = (ProcessList*) fpl;
|
||||
ProcessList_init(pl, Class(FreeBSDProcess), usersTable, pidWhiteList, userId);
|
||||
|
||||
size_t len;
|
||||
|
||||
// physical memory in system: hw.physmem
|
||||
// physical page size: hw.pagesize
|
||||
// usable pagesize : vm.stats.vm.v_page_size
|
||||
@ -150,10 +151,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
||||
fpl->cp_time_n = xCalloc(cpus, sizeof_cp_time_array);
|
||||
len = sizeof_cp_time_array;
|
||||
|
||||
// fetch intial single (or average) CPU clicks from kernel
|
||||
// fetch initial single (or average) CPU clicks from kernel
|
||||
sysctl(MIB_kern_cp_time, 2, fpl->cp_time_o, &len, NULL, 0);
|
||||
|
||||
// on smp box, fetch rest of intial CPU's clicks
|
||||
// on smp box, fetch rest of initial CPU's clicks
|
||||
if (cpus > 1) {
|
||||
len = 2; sysctlnametomib("kern.cp_times", MIB_kern_cp_times, &len);
|
||||
fpl->cp_times_o = xCalloc(cpus, sizeof_cp_time_array);
|
||||
@ -174,12 +175,14 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
||||
|
||||
len = sizeof(kernelFScale);
|
||||
if (sysctlbyname("kern.fscale", &kernelFScale, &len, NULL, 0) == -1) {
|
||||
//sane default for kernel provded CPU precentage scaling, at least on x86 machines, in case this sysctl call failed
|
||||
//sane default for kernel provided CPU percentage scaling, at least on x86 machines, in case this sysctl call failed
|
||||
kernelFScale = 2048;
|
||||
}
|
||||
|
||||
fpl->kd = kvm_open(NULL, "/dev/null", NULL, 0, NULL);
|
||||
assert(fpl->kd);
|
||||
fpl->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf);
|
||||
if (fpl->kd == NULL) {
|
||||
errx(1, "kvm_open: %s", errbuf);
|
||||
}
|
||||
|
||||
return pl;
|
||||
}
|
||||
@ -212,9 +215,6 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) {
|
||||
unsigned long *cp_time_n; // old clicks state
|
||||
unsigned long *cp_time_o; // current clicks state
|
||||
|
||||
unsigned long long total_o = 0;
|
||||
unsigned long long total_n = 0;
|
||||
unsigned long long total_d = 0;
|
||||
unsigned long cp_time_d[CPUSTATES];
|
||||
double cp_time_p[CPUSTATES];
|
||||
|
||||
@ -251,6 +251,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) {
|
||||
}
|
||||
|
||||
// diff old vs new
|
||||
unsigned long long total_o = 0;
|
||||
unsigned long long total_n = 0;
|
||||
unsigned long long total_d = 0;
|
||||
for (int s = 0; s < CPUSTATES; s++) {
|
||||
cp_time_d[s] = cp_time_n[s] - cp_time_o[s];
|
||||
total_o += cp_time_o[s];
|
||||
@ -395,7 +398,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) {
|
||||
jid = jail_get(jiov, 6, 0);
|
||||
if (jid < 0) {
|
||||
if (!jail_errmsg[0])
|
||||
snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno));
|
||||
xSnprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno));
|
||||
return NULL;
|
||||
} else if (jid == kproc->ki_jid) {
|
||||
jname = xStrdup(jnamebuf);
|
||||
@ -424,7 +427,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
|
||||
int cpus = this->cpuCount;
|
||||
int count = 0;
|
||||
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_ALL, 0, &count);
|
||||
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
struct kinfo_proc* kproc = &kprocs[i];
|
||||
@ -456,17 +459,17 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
fp->jname = FreeBSDProcessList_readJailName(kproc);
|
||||
} else {
|
||||
if(fp->jid != kproc->ki_jid) {
|
||||
// proces can enter jail anytime
|
||||
// process can enter jail anytime
|
||||
fp->jid = kproc->ki_jid;
|
||||
free(fp->jname);
|
||||
fp->jname = FreeBSDProcessList_readJailName(kproc);
|
||||
}
|
||||
if (proc->ppid != kproc->ki_ppid) {
|
||||
// if there are reapers in the system, proces can get reparented anytime
|
||||
// if there are reapers in the system, process can get reparented anytime
|
||||
proc->ppid = kproc->ki_ppid;
|
||||
}
|
||||
if(proc->st_uid != kproc->ki_uid) {
|
||||
// some proceses change users (eg. to lower privs)
|
||||
// some processes change users (eg. to lower privs)
|
||||
proc->st_uid = kproc->ki_uid;
|
||||
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
|
||||
}
|
||||
@ -477,25 +480,21 @@ void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
}
|
||||
|
||||
// from FreeBSD source /src/usr.bin/top/machine.c
|
||||
proc->m_size = kproc->ki_size / 1024;
|
||||
proc->m_resident = kproc->ki_rssize * pageSizeKb;
|
||||
proc->m_size = kproc->ki_size / 1024 / pageSizeKb;
|
||||
proc->m_resident = kproc->ki_rssize;
|
||||
proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0;
|
||||
proc->nlwp = kproc->ki_numthreads;
|
||||
proc->time = (kproc->ki_runtime + 5000) / 10000;
|
||||
|
||||
proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale);
|
||||
proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem);
|
||||
|
||||
if (proc->percent_cpu > 0.1) {
|
||||
// system idle process should own all CPU time left regardless of CPU count
|
||||
if ( strcmp("idle", kproc->ki_comm) == 0 ) {
|
||||
isIdleProcess = true;
|
||||
} else {
|
||||
if (cpus > 1)
|
||||
proc->percent_cpu = proc->percent_cpu / (double) cpus;
|
||||
}
|
||||
}
|
||||
if (isIdleProcess == false && proc->percent_cpu >= 99.8) {
|
||||
// don't break formatting
|
||||
proc->percent_cpu = 99.8;
|
||||
}
|
||||
|
||||
proc->priority = kproc->ki_pri.pri_level - PZERO;
|
||||
|
||||
|
@ -55,7 +55,6 @@ typedef struct FreeBSDProcessList_ {
|
||||
|
||||
|
||||
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
void ProcessList_delete(ProcessList* this);
|
||||
|
@ -24,6 +24,7 @@ in the source distribution for its full text.
|
||||
#include <sys/resource.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
/*{
|
||||
#include "Action.h"
|
||||
@ -42,7 +43,7 @@ ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_R
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
SignalItem Platform_signals[] = {
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
@ -79,7 +80,7 @@ SignalItem Platform_signals[] = {
|
||||
{ .name = "33 SIGLIBRT", .number = 33 },
|
||||
};
|
||||
|
||||
unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys) {
|
||||
(void) keys;
|
||||
|
@ -24,9 +24,9 @@ extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
extern SignalItem Platform_signals[];
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern unsigned int Platform_numberOfSignals;
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
||||
|
43
htop.1.in
43
htop.1.in
@ -10,7 +10,7 @@ Htop is a free (GPL) ncurses-based process viewer for Linux.
|
||||
.LP
|
||||
It is similar to top, but allows you to scroll vertically and horizontally,
|
||||
so you can see all the processes running on the system, along with their full
|
||||
command lines, as well as viewing them as a process tree, selecting mutiple
|
||||
command lines, as well as viewing them as a process tree, selecting multiple
|
||||
processes and acting on them all at once.
|
||||
.LP
|
||||
Tasks related to processes (killing, renicing) can be done without
|
||||
@ -48,8 +48,34 @@ Output version information and exit
|
||||
The following commands are supported while in htop:
|
||||
.LP
|
||||
.TP 5
|
||||
.B Arrows, PgUP, PgDn, Home, End
|
||||
Scroll the process list.
|
||||
.B Up, Alt-k
|
||||
Select (highlight) the previous process in the process list. Scroll the list
|
||||
if necessary.
|
||||
.TP
|
||||
.B Down, Alt-j
|
||||
Select (highlight) the next process in the process list. Scroll the list if
|
||||
necessary.
|
||||
.TP
|
||||
.B Left, Alt-h
|
||||
Scroll the process list left.
|
||||
.TP
|
||||
.B Right, Alt-l
|
||||
Scroll the process list right.
|
||||
.TP
|
||||
.B PgUp, PgDn
|
||||
Scroll the process list up or down one window.
|
||||
.TP
|
||||
.B Home
|
||||
Scroll to the top of the process list and select the first process.
|
||||
.TP
|
||||
.B End
|
||||
Scroll to the bottom of the process list and select the last process.
|
||||
.TP
|
||||
.B Ctrl-A, ^
|
||||
Scroll left to the beginning of the process entry (i.e. beginning of line).
|
||||
.TP
|
||||
.B Ctrl-E, $
|
||||
Scroll right to the end of the process entry (i.e. end of line).
|
||||
.TP
|
||||
.B Space
|
||||
Tag or untag a process. Commands that can operate on multiple processes,
|
||||
@ -191,7 +217,7 @@ The parent process ID.
|
||||
.B PGRP
|
||||
The process's group ID.
|
||||
.TP
|
||||
.B SESSION (SESN)
|
||||
.B SESSION (SID)
|
||||
The process's session ID.
|
||||
.TP
|
||||
.B TTY_NR (TTY)
|
||||
@ -344,6 +370,15 @@ The I/O scheduling class followed by the priority if the class supports it:
|
||||
\fBB\fR for Best-effort
|
||||
\fBid\fR for Idle
|
||||
.TP
|
||||
.B PERCENT_CPU_DELAY (CPUD%)
|
||||
The percentage of time spent waiting for a CPU (while runnable). Requires CAP_NET_ADMIN.
|
||||
.TP
|
||||
.B PERCENT_IO_DELAY (IOD%)
|
||||
The percentage of time spent waiting for the completion of synchronous block I/O. Requires CAP_NET_ADMIN.
|
||||
.TP
|
||||
.B PERCENT_SWAP_DELAY (SWAPD%)
|
||||
The percentage of time spent swapping in pages. Requires CAP_NET_ADMIN.
|
||||
.TP
|
||||
.B All other flags
|
||||
Currently unsupported (always displays '-').
|
||||
|
||||
|
196
htop.c
196
htop.c
@ -176,7 +176,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
#ifdef HAVE_PROC
|
||||
if (access(PROCDIR, R_OK) != 0) {
|
||||
fprintf("Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
|
||||
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -229,194 +230,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
ScreenManager_run(scr, NULL, NULL);
|
||||
|
||||
/*
|
||||
FunctionBar_draw(defaultBar, NULL);
|
||||
|
||||
int acc = 0;
|
||||
bool follow = false;
|
||||
|
||||
struct timeval tv;
|
||||
double oldTime = 0.0;
|
||||
|
||||
int ch = ERR;
|
||||
int closeTimeout = 0;
|
||||
|
||||
bool drawPanel = true;
|
||||
|
||||
bool collapsed = false;
|
||||
|
||||
Htop_Action keys[KEY_MAX] = { NULL };
|
||||
setBindings(keys);
|
||||
Platform_setBindings(keys);
|
||||
|
||||
bool quit = false;
|
||||
int sortTimeout = 0;
|
||||
int resetSortTimeout = 5;
|
||||
bool doRefresh = true;
|
||||
bool forceRecalculate = false;
|
||||
|
||||
while (!quit) {
|
||||
gettimeofday(&tv, NULL);
|
||||
double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
|
||||
bool timeToRecalculate = (newTime - oldTime > settings->delay);
|
||||
if (newTime < oldTime) timeToRecalculate = true; // clock was adjusted?
|
||||
int following = follow ? MainPanel_selectedPid((MainPanel*)panel) : -1;
|
||||
if (timeToRecalculate) {
|
||||
Header_draw(header);
|
||||
oldTime = newTime;
|
||||
}
|
||||
if (doRefresh) {
|
||||
if (timeToRecalculate || forceRecalculate) {
|
||||
ProcessList_scan(pl);
|
||||
forceRecalculate = false;
|
||||
}
|
||||
if (sortTimeout == 0 || settings->treeView) {
|
||||
ProcessList_sort(pl);
|
||||
sortTimeout = 1;
|
||||
}
|
||||
ProcessList_rebuildPanel(pl, true, following, IncSet_filter(inc));
|
||||
drawPanel = true;
|
||||
}
|
||||
doRefresh = true;
|
||||
|
||||
if (settings->treeView) {
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (p) {
|
||||
if (!p->showChildren && !collapsed) {
|
||||
FunctionBar_setLabel(defaultBar, KEY_F(6), "Expand");
|
||||
FunctionBar_draw(defaultBar, NULL);
|
||||
} else if (p->showChildren && collapsed) {
|
||||
FunctionBar_setLabel(defaultBar, KEY_F(6), "Collap");
|
||||
FunctionBar_draw(defaultBar, NULL);
|
||||
}
|
||||
collapsed = !p->showChildren;
|
||||
}
|
||||
} else {
|
||||
collapsed = false;
|
||||
}
|
||||
|
||||
if (drawPanel) {
|
||||
Panel_draw(panel, true);
|
||||
}
|
||||
|
||||
int prev = ch;
|
||||
if (inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
ch = getch();
|
||||
|
||||
if (ch == ERR) {
|
||||
if (!inc->active)
|
||||
sortTimeout--;
|
||||
if (prev == ch && !timeToRecalculate) {
|
||||
closeTimeout++;
|
||||
if (closeTimeout == 100) {
|
||||
break;
|
||||
}
|
||||
} else
|
||||
closeTimeout = 0;
|
||||
drawPanel = false;
|
||||
continue;
|
||||
}
|
||||
drawPanel = true;
|
||||
|
||||
Htop_Reaction reaction = HTOP_OK;
|
||||
|
||||
if (ch == KEY_MOUSE) {
|
||||
MEVENT mevent;
|
||||
int ok = getmouse(&mevent);
|
||||
if (ok == OK) {
|
||||
if (mevent.bstate & BUTTON1_CLICKED) {
|
||||
if (mevent.y == panel->y) {
|
||||
int x = panel->scrollH + mevent.x + 1;
|
||||
ProcessField field = ProcessList_keyAt(pl, x);
|
||||
if (field == settings->sortKey) {
|
||||
Settings_invertSortOrder(settings);
|
||||
settings->treeView = false;
|
||||
reaction |= HTOP_REDRAW_BAR;
|
||||
} else {
|
||||
reaction |= setSortKey(settings, field);
|
||||
}
|
||||
sortTimeout = 0;
|
||||
ch = ERR;
|
||||
} else if (mevent.y >= panel->y + 1 && mevent.y < LINES - 1) {
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||
follow = true;
|
||||
ch = ERR;
|
||||
} if (mevent.y == LINES - 1) {
|
||||
ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
|
||||
}
|
||||
} else if (mevent.bstate & BUTTON4_CLICKED) {
|
||||
ch = KEY_UP;
|
||||
#if NCURSES_MOUSE_VERSION > 1
|
||||
} else if (mevent.bstate & BUTTON5_CLICKED) {
|
||||
ch = KEY_DOWN;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inc->active) {
|
||||
doRefresh = IncSet_handleKey(inc, ch, panel, getMainPanelValue, NULL);
|
||||
if (!inc->active) {
|
||||
follow = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch < 255 && isdigit((char)ch)) {
|
||||
if (Panel_size(panel) == 0) continue;
|
||||
pid_t pid = ch-48 + acc;
|
||||
for (int i = 0; i < ProcessList_size(pl); i++) {
|
||||
Panel_setSelected(panel, i);
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (p && p->pid == pid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
acc = pid * 10;
|
||||
if (acc > 10000000)
|
||||
acc = 0;
|
||||
continue;
|
||||
} else {
|
||||
acc = 0;
|
||||
}
|
||||
|
||||
if(ch != ERR && keys[ch]) {
|
||||
reaction |= (keys[ch])(&state);
|
||||
} else {
|
||||
doRefresh = false;
|
||||
sortTimeout = resetSortTimeout;
|
||||
Panel_onKey(panel, ch);
|
||||
}
|
||||
|
||||
// Reaction handlers:
|
||||
|
||||
if (reaction & HTOP_REDRAW_BAR) {
|
||||
updateTreeFunctions(defaultBar, settings->treeView);
|
||||
IncSet_drawBar(inc);
|
||||
}
|
||||
if (reaction & HTOP_UPDATE_PANELHDR) {
|
||||
ProcessList_printHeader(pl, Panel_getHeader(panel));
|
||||
}
|
||||
if (reaction & HTOP_REFRESH) {
|
||||
doRefresh = true;
|
||||
sortTimeout = 0;
|
||||
}
|
||||
if (reaction & HTOP_RECALCULATE) {
|
||||
forceRecalculate = true;
|
||||
sortTimeout = 0;
|
||||
}
|
||||
if (reaction & HTOP_SAVE_SETTINGS) {
|
||||
settings->changed = true;
|
||||
}
|
||||
if (reaction & HTOP_QUIT) {
|
||||
quit = true;
|
||||
}
|
||||
follow = (reaction & HTOP_KEEP_FOLLOWING);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
attron(CRT_colors[RESET_COLOR]);
|
||||
mvhline(LINES-1, 0, ' ', COLS);
|
||||
attroff(CRT_colors[RESET_COLOR]);
|
||||
@ -428,11 +241,6 @@ int main(int argc, char** argv) {
|
||||
Header_delete(header);
|
||||
ProcessList_delete(pl);
|
||||
|
||||
/*
|
||||
FunctionBar_delete((Object*)defaultBar);
|
||||
Panel_delete((Object*)panel);
|
||||
*/
|
||||
|
||||
ScreenManager_delete(scr);
|
||||
|
||||
UsersTable_delete(ut);
|
||||
|
@ -28,6 +28,7 @@ Comment[sr@latin]=Prikaz sistemskih procesa
|
||||
Comment[sv]=Visa systemprocesser
|
||||
Comment[tr]=Sistem Süreçlerini Göster
|
||||
Comment[uk]=Перегляд системних процесів
|
||||
Comment[zh_CN]=显示系统进程
|
||||
Comment[zh_TW]=顯示系統行程
|
||||
Terminal=true
|
||||
Exec=htop
|
||||
@ -59,4 +60,6 @@ GenericName[sr@latin]=Prikazivač procesa
|
||||
GenericName[sv]=Processvisning
|
||||
GenericName[tr]=Süreç Görüntüleyici
|
||||
GenericName[uk]=Перегляд процесів
|
||||
GenericName[zh_CN]=进程查看器
|
||||
GenericName[zh_TW]=行程檢視器
|
||||
Keywords=system;process;task
|
||||
|
@ -41,11 +41,9 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
|
||||
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)
|
||||
struct dirent* dirEntry = readdir(batteryDir);
|
||||
if (!dirEntry)
|
||||
break;
|
||||
char* entryName = dirEntry->d_name;
|
||||
if (strncmp(entryName, "BAT", 3))
|
||||
@ -58,25 +56,29 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
|
||||
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);
|
||||
xSnprintf(infoPath, sizeof infoPath, "%s%s/%s", batteryPath, batteries[i], fileName);
|
||||
|
||||
FILE* file = fopen(infoPath, "r");
|
||||
if (!file) {
|
||||
break;
|
||||
}
|
||||
|
||||
char line[50] = "";
|
||||
char* line = NULL;
|
||||
for (unsigned short int i = 0; i < lineNum; i++) {
|
||||
char* ok = fgets(line, sizeof line, file);
|
||||
if (!ok) break;
|
||||
free(line);
|
||||
line = String_readLine(file);
|
||||
if (!line) break;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
if (!line) break;
|
||||
|
||||
char *foundNumStr = String_getToken(line, wordNum);
|
||||
const unsigned long int foundNum = atoi(foundNumStr);
|
||||
free(foundNumStr);
|
||||
|
||||
free(line);
|
||||
|
||||
total += foundNum;
|
||||
}
|
||||
|
||||
@ -95,11 +97,9 @@ static ACPresence procAcpiCheck() {
|
||||
return AC_ERROR;
|
||||
}
|
||||
|
||||
struct dirent result;
|
||||
struct dirent* dirEntry;
|
||||
for (;;) {
|
||||
int err = readdir_r((DIR *) dir, &result, &dirEntry);
|
||||
if (err || !dirEntry)
|
||||
struct dirent* dirEntry = readdir((DIR *) dir);
|
||||
if (!dirEntry)
|
||||
break;
|
||||
|
||||
char* entryName = (char *) dirEntry->d_name;
|
||||
@ -108,7 +108,7 @@ static ACPresence procAcpiCheck() {
|
||||
continue;
|
||||
|
||||
char statePath[50];
|
||||
snprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
|
||||
xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
|
||||
FILE* file = fopen(statePath, "r");
|
||||
|
||||
if (!file) {
|
||||
@ -116,14 +116,13 @@ static ACPresence procAcpiCheck() {
|
||||
continue;
|
||||
}
|
||||
|
||||
char line[100];
|
||||
char* ok = fgets(line, sizeof line, file);
|
||||
if (!ok) continue;
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
char* line = String_readLine(file);
|
||||
if (!line) continue;
|
||||
|
||||
fclose(file);
|
||||
|
||||
const char *isOnline = String_getToken(line, 2);
|
||||
free(line);
|
||||
|
||||
if (strcmp(isOnline, "on-line") == 0) {
|
||||
isOn = AC_PRESENT;
|
||||
@ -178,25 +177,6 @@ static inline ssize_t xread(int fd, void *buf, size_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the suffix of `str` if its beginning matches `prefix`.
|
||||
* Returns NULL if the prefix does not match.
|
||||
* Examples:
|
||||
* match("hello world", "hello "); -> "world"
|
||||
* match("hello world", "goodbye "); -> NULL
|
||||
*/
|
||||
static inline const char* match(const char* str, const char* prefix) {
|
||||
for (;;) {
|
||||
if (*prefix == '\0') {
|
||||
return str;
|
||||
}
|
||||
if (*prefix != *str) {
|
||||
return NULL;
|
||||
}
|
||||
prefix++; str++;
|
||||
}
|
||||
}
|
||||
|
||||
static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
|
||||
*level = 0;
|
||||
@ -209,18 +189,16 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
unsigned long int totalFull = 0;
|
||||
unsigned long int totalRemain = 0;
|
||||
|
||||
struct dirent result;
|
||||
struct dirent* dirEntry;
|
||||
for (;;) {
|
||||
int err = readdir_r((DIR *) dir, &result, &dirEntry);
|
||||
if (err || !dirEntry)
|
||||
struct dirent* dirEntry = readdir((DIR *) dir);
|
||||
if (!dirEntry)
|
||||
break;
|
||||
char* entryName = (char *) dirEntry->d_name;
|
||||
const char filePath[50];
|
||||
|
||||
if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') {
|
||||
|
||||
snprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName);
|
||||
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName);
|
||||
int fd = open(filePath, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
closedir(dir);
|
||||
@ -239,6 +217,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
bool full = false;
|
||||
bool now = false;
|
||||
while ((line = strsep(&buf, "\n")) != NULL) {
|
||||
#define match(str,prefix) \
|
||||
(String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL)
|
||||
const char* ps = match(line, "POWER_SUPPLY_");
|
||||
if (!ps) {
|
||||
continue;
|
||||
@ -265,12 +245,13 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#undef match
|
||||
} else if (entryName[0] == 'A') {
|
||||
if (*isOnAC != AC_ERROR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
snprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName);
|
||||
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/online", entryName);
|
||||
int fd = open(filePath, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
closedir(dir);
|
||||
@ -325,6 +306,9 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
}
|
||||
if (*level > 100.0) {
|
||||
*level = 100.0;
|
||||
}
|
||||
Battery_cacheLevel = *level;
|
||||
Battery_cacheIsOnAC = *isOnAC;
|
||||
Battery_cacheTime = now;
|
||||
|
@ -29,13 +29,6 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat
|
||||
// READ FROM /sys
|
||||
// ----------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a pointer to the suffix of `str` if its beginning matches `prefix`.
|
||||
* Returns NULL if the prefix does not match.
|
||||
* Examples:
|
||||
* match("hello world", "hello "); -> "world"
|
||||
* match("hello world", "goodbye "); -> NULL
|
||||
*/
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
||||
|
@ -35,7 +35,7 @@ typedef int IOPriority;
|
||||
#define IOPriority_error 0xffffffff
|
||||
|
||||
#define IOPriority_None IOPriority_tuple(IOPRIO_CLASS_NONE, 0)
|
||||
#define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 0)
|
||||
#define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7)
|
||||
|
||||
}*/
|
||||
|
||||
|
@ -36,7 +36,7 @@ typedef int IOPriority;
|
||||
#define IOPriority_error 0xffffffff
|
||||
|
||||
#define IOPriority_None IOPriority_tuple(IOPRIO_CLASS_NONE, 0)
|
||||
#define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 0)
|
||||
#define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7)
|
||||
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) {
|
||||
Panel_setHeader(this, "IO Priority:");
|
||||
Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None));
|
||||
if (currPrio == IOPriority_None) Panel_setSelected(this, 0);
|
||||
struct { int klass; const char* name; } classes[] = {
|
||||
static const struct { int klass; const char* name; } classes[] = {
|
||||
{ .klass = IOPRIO_CLASS_RT, .name = "Realtime" },
|
||||
{ .klass = IOPRIO_CLASS_BE, .name = "Best-effort" },
|
||||
{ .klass = 0, .name = NULL }
|
||||
@ -27,7 +27,7 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) {
|
||||
for (int c = 0; classes[c].name; c++) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
char name[50];
|
||||
snprintf(name, sizeof(name)-1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : ""));
|
||||
xSnprintf(name, sizeof(name)-1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : ""));
|
||||
IOPriority ioprio = IOPriority_tuple(classes[c].klass, i);
|
||||
Panel_add(this, (Object*) ListItem_new(name, ioprio));
|
||||
if (currPrio == ioprio) Panel_setSelected(this, Panel_size(this) - 1);
|
||||
|
@ -81,7 +81,12 @@ typedef enum LinuxProcessFields {
|
||||
#endif
|
||||
OOM = 114,
|
||||
IO_PRIORITY = 115,
|
||||
LAST_PROCESSFIELD = 116,
|
||||
#ifdef HAVE_DELAYACCT
|
||||
PERCENT_CPU_DELAY = 116,
|
||||
PERCENT_IO_DELAY = 117,
|
||||
PERCENT_SWAP_DELAY = 118,
|
||||
#endif
|
||||
LAST_PROCESSFIELD = 119,
|
||||
} LinuxProcessField;
|
||||
|
||||
#include "IOPriority.h"
|
||||
@ -124,6 +129,16 @@ typedef struct LinuxProcess_ {
|
||||
char* cgroup;
|
||||
#endif
|
||||
unsigned int oom;
|
||||
char* ttyDevice;
|
||||
#ifdef HAVE_DELAYACCT
|
||||
unsigned long long int delay_read_time;
|
||||
unsigned long long cpu_delay_total;
|
||||
unsigned long long blkio_delay_total;
|
||||
unsigned long long swapin_delay_total;
|
||||
float cpu_delay_percent;
|
||||
float blkio_delay_percent;
|
||||
float swapin_delay_percent;
|
||||
#endif
|
||||
} LinuxProcess;
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
@ -140,11 +155,11 @@ 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, },
|
||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging, I idle)", .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, },
|
||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||
[TTY_NR] = { .name = "TTY_NR", .title = "TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||
[FLAGS] = { .name = "FLAGS", .title = NULL, .description = NULL, .flags = 0, },
|
||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||
@ -214,6 +229,11 @@ ProcessFieldData Process_fields[] = {
|
||||
#endif
|
||||
[OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, },
|
||||
[IO_PRIORITY] = { .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, },
|
||||
#ifdef HAVE_DELAYACCT
|
||||
[PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPUD% ", .description = "CPU delay %", .flags = 0, },
|
||||
[PERCENT_IO_DELAY] = { .name = "PERCENT_IO_DELAY", .title = "IOD% ", .description = "Block I/O delay %", .flags = 0, },
|
||||
[PERCENT_SWAP_DELAY] = { .name = "PERCENT_SWAP_DELAY", .title = "SWAPD% ", .description = "Swapin delay %", .flags = 0, },
|
||||
#endif
|
||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||
};
|
||||
|
||||
@ -226,7 +246,7 @@ ProcessPidColumn Process_pidColumns[] = {
|
||||
{ .id = TPGID, .label = "TPGID" },
|
||||
{ .id = TGID, .label = "TGID" },
|
||||
{ .id = PGRP, .label = "PGRP" },
|
||||
{ .id = SESSION, .label = "SESN" },
|
||||
{ .id = SESSION, .label = "SID" },
|
||||
{ .id = OOM, .label = "OOM" },
|
||||
{ .id = 0, .label = NULL },
|
||||
};
|
||||
@ -254,6 +274,7 @@ void Process_delete(Object* cast) {
|
||||
#ifdef HAVE_CGROUP
|
||||
free(this->cgroup);
|
||||
#endif
|
||||
free(this->ttyDevice);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -268,16 +289,33 @@ io_priority = (cpu_nice + 20) / 5. -- From ionice(1) man page
|
||||
#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority)
|
||||
|
||||
IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) {
|
||||
IOPriority ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, this->super.pid);
|
||||
IOPriority ioprio = 0;
|
||||
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
|
||||
#ifdef SYS_ioprio_get
|
||||
ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, this->super.pid);
|
||||
#endif
|
||||
this->ioPriority = ioprio;
|
||||
return ioprio;
|
||||
}
|
||||
|
||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) {
|
||||
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
|
||||
#ifdef SYS_ioprio_set
|
||||
syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio);
|
||||
#endif
|
||||
return (LinuxProcess_updateIOPriority(this) == ioprio);
|
||||
}
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) {
|
||||
if (delay_percent == -1LL) {
|
||||
xSnprintf(buffer, n, " N/A ");
|
||||
} else {
|
||||
xSnprintf(buffer, n, "%4.1f ", delay_percent);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
LinuxProcess* lp = (LinuxProcess*) this;
|
||||
bool coloring = this->settings->highlightMegabytes;
|
||||
@ -285,6 +323,15 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
||||
int attr = CRT_colors[DEFAULT_COLOR];
|
||||
int n = sizeof(buffer) - 1;
|
||||
switch ((int)field) {
|
||||
case TTY_NR: {
|
||||
if (lp->ttyDevice) {
|
||||
xSnprintf(buffer, n, "%-9s", lp->ttyDevice + 5 /* skip "/dev/" */);
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
xSnprintf(buffer, n, "? ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CMINFLT: Process_colorNumber(str, lp->cminflt, coloring); return;
|
||||
case CMAJFLT: Process_colorNumber(str, lp->cmajflt, coloring); return;
|
||||
case M_DRS: Process_humanNumber(str, lp->m_drs * PAGE_SIZE_KB, coloring); return;
|
||||
@ -306,37 +353,47 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
||||
case CNCLWB: Process_colorNumber(str, lp->io_cancelled_write_bytes, coloring); return;
|
||||
case IO_READ_RATE: Process_outputRate(str, buffer, n, lp->io_rate_read_bps, coloring); return;
|
||||
case IO_WRITE_RATE: Process_outputRate(str, buffer, n, lp->io_rate_write_bps, coloring); return;
|
||||
case IO_RATE: Process_outputRate(str, buffer, n, lp->io_rate_read_bps + lp->io_rate_write_bps, coloring); return;
|
||||
case IO_RATE: {
|
||||
double totalRate = (lp->io_rate_read_bps != -1)
|
||||
? (lp->io_rate_read_bps + lp->io_rate_write_bps)
|
||||
: -1;
|
||||
Process_outputRate(str, buffer, n, totalRate, coloring); return;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_OPENVZ
|
||||
case CTID: snprintf(buffer, n, "%7u ", lp->ctid); break;
|
||||
case VPID: snprintf(buffer, n, Process_pidFormat, lp->vpid); break;
|
||||
case CTID: xSnprintf(buffer, n, "%7u ", lp->ctid); break;
|
||||
case VPID: xSnprintf(buffer, n, Process_pidFormat, lp->vpid); break;
|
||||
#endif
|
||||
#ifdef HAVE_VSERVER
|
||||
case VXID: snprintf(buffer, n, "%5u ", lp->vxid); break;
|
||||
case VXID: xSnprintf(buffer, n, "%5u ", lp->vxid); break;
|
||||
#endif
|
||||
#ifdef HAVE_CGROUP
|
||||
case CGROUP: snprintf(buffer, n, "%-10s ", lp->cgroup); break;
|
||||
case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup); break;
|
||||
#endif
|
||||
case OOM: snprintf(buffer, n, Process_pidFormat, lp->oom); break;
|
||||
case OOM: xSnprintf(buffer, n, Process_pidFormat, lp->oom); break;
|
||||
case IO_PRIORITY: {
|
||||
int klass = IOPriority_class(lp->ioPriority);
|
||||
if (klass == IOPRIO_CLASS_NONE) {
|
||||
// see note [1] above
|
||||
snprintf(buffer, n, "B%1d ", (int) (this->nice + 20) / 5);
|
||||
xSnprintf(buffer, n, "B%1d ", (int) (this->nice + 20) / 5);
|
||||
} else if (klass == IOPRIO_CLASS_BE) {
|
||||
snprintf(buffer, n, "B%1d ", IOPriority_data(lp->ioPriority));
|
||||
xSnprintf(buffer, n, "B%1d ", IOPriority_data(lp->ioPriority));
|
||||
} else if (klass == IOPRIO_CLASS_RT) {
|
||||
attr = CRT_colors[PROCESS_HIGH_PRIORITY];
|
||||
snprintf(buffer, n, "R%1d ", IOPriority_data(lp->ioPriority));
|
||||
} else if (lp->ioPriority == IOPriority_Idle) {
|
||||
xSnprintf(buffer, n, "R%1d ", IOPriority_data(lp->ioPriority));
|
||||
} else if (klass == IOPRIO_CLASS_IDLE) {
|
||||
attr = CRT_colors[PROCESS_LOW_PRIORITY];
|
||||
snprintf(buffer, n, "id ");
|
||||
xSnprintf(buffer, n, "id ");
|
||||
} else {
|
||||
snprintf(buffer, n, "?? ");
|
||||
xSnprintf(buffer, n, "?? ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_DELAYACCT
|
||||
case PERCENT_CPU_DELAY: LinuxProcess_printDelay(lp->cpu_delay_percent, buffer, n); break;
|
||||
case PERCENT_IO_DELAY: LinuxProcess_printDelay(lp->blkio_delay_percent, buffer, n); break;
|
||||
case PERCENT_SWAP_DELAY: LinuxProcess_printDelay(lp->swapin_delay_percent, buffer, n); break;
|
||||
#endif
|
||||
default:
|
||||
Process_writeField((Process*)this, str, field);
|
||||
return;
|
||||
@ -398,6 +455,14 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
||||
#endif
|
||||
case OOM:
|
||||
return (p2->oom - p1->oom);
|
||||
#ifdef HAVE_DELAYACCT
|
||||
case PERCENT_CPU_DELAY:
|
||||
return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1);
|
||||
case PERCENT_IO_DELAY:
|
||||
return (p2->blkio_delay_percent > p1->blkio_delay_percent ? 1 : -1);
|
||||
case PERCENT_SWAP_DELAY:
|
||||
return (p2->swapin_delay_percent > p1->swapin_delay_percent ? 1 : -1);
|
||||
#endif
|
||||
case IO_PRIORITY:
|
||||
return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2);
|
||||
default:
|
||||
|
@ -73,7 +73,12 @@ typedef enum LinuxProcessFields {
|
||||
#endif
|
||||
OOM = 114,
|
||||
IO_PRIORITY = 115,
|
||||
LAST_PROCESSFIELD = 116,
|
||||
#ifdef HAVE_DELAYACCT
|
||||
PERCENT_CPU_DELAY = 116,
|
||||
PERCENT_IO_DELAY = 117,
|
||||
PERCENT_SWAP_DELAY = 118,
|
||||
#endif
|
||||
LAST_PROCESSFIELD = 119,
|
||||
} LinuxProcessField;
|
||||
|
||||
#include "IOPriority.h"
|
||||
@ -116,6 +121,16 @@ typedef struct LinuxProcess_ {
|
||||
char* cgroup;
|
||||
#endif
|
||||
unsigned int oom;
|
||||
char* ttyDevice;
|
||||
#ifdef HAVE_DELAYACCT
|
||||
unsigned long long int delay_read_time;
|
||||
unsigned long long cpu_delay_total;
|
||||
unsigned long long blkio_delay_total;
|
||||
unsigned long long swapin_delay_total;
|
||||
float cpu_delay_percent;
|
||||
float blkio_delay_percent;
|
||||
float swapin_delay_percent;
|
||||
#endif
|
||||
} LinuxProcess;
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
@ -151,6 +166,10 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
|
||||
|
||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio);
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n);
|
||||
#endif
|
||||
|
||||
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field);
|
||||
|
||||
long LinuxProcess_compare(const void* v1, const void* v2);
|
||||
|
@ -27,6 +27,16 @@ in the source distribution for its full text.
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
#include <netlink/attr.h>
|
||||
#include <netlink/netlink.h>
|
||||
#include <netlink/genl/genl.h>
|
||||
#include <netlink/genl/ctrl.h>
|
||||
#include <netlink/socket.h>
|
||||
#include <netlink/msg.h>
|
||||
#include <linux/taskstats.h>
|
||||
#endif
|
||||
|
||||
/*{
|
||||
|
||||
#include "ProcessList.h"
|
||||
@ -59,11 +69,23 @@ typedef struct CPUData_ {
|
||||
unsigned long long int guestPeriod;
|
||||
} CPUData;
|
||||
|
||||
typedef struct TtyDriver_ {
|
||||
char* path;
|
||||
unsigned int major;
|
||||
unsigned int minorFrom;
|
||||
unsigned int minorTo;
|
||||
} TtyDriver;
|
||||
|
||||
typedef struct LinuxProcessList_ {
|
||||
ProcessList super;
|
||||
|
||||
|
||||
CPUData* cpus;
|
||||
|
||||
TtyDriver* ttyDrivers;
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
struct nl_sock *netlink_socket;
|
||||
int netlink_family;
|
||||
#endif
|
||||
} LinuxProcessList;
|
||||
|
||||
#ifndef PROCDIR
|
||||
@ -78,6 +100,10 @@ typedef struct LinuxProcessList_ {
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#endif
|
||||
|
||||
#ifndef PROCTTYDRIVERSFILE
|
||||
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
|
||||
#endif
|
||||
|
||||
#ifndef PROC_LINE_LENGTH
|
||||
#define PROC_LINE_LENGTH 512
|
||||
#endif
|
||||
@ -87,11 +113,124 @@ typedef struct LinuxProcessList_ {
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
|
||||
static ssize_t xread(int fd, void *buf, size_t count) {
|
||||
// Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested.
|
||||
size_t alreadyRead = 0;
|
||||
for(;;) {
|
||||
ssize_t res = read(fd, buf, count);
|
||||
if (res == -1 && errno == EINTR) continue;
|
||||
if (res > 0) {
|
||||
buf = ((char*)buf)+res;
|
||||
count -= res;
|
||||
alreadyRead += res;
|
||||
}
|
||||
if (res == -1) return -1;
|
||||
if (count == 0 || res == 0) return alreadyRead;
|
||||
}
|
||||
}
|
||||
|
||||
static int sortTtyDrivers(const void* va, const void* vb) {
|
||||
TtyDriver* a = (TtyDriver*) va;
|
||||
TtyDriver* b = (TtyDriver*) vb;
|
||||
return (a->major == b->major) ? (a->minorFrom - b->minorFrom) : (a->major - b->major);
|
||||
}
|
||||
|
||||
static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) {
|
||||
TtyDriver* ttyDrivers;
|
||||
int fd = open(PROCTTYDRIVERSFILE, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return;
|
||||
char* buf = NULL;
|
||||
int bufSize = MAX_READ;
|
||||
int bufLen = 0;
|
||||
for(;;) {
|
||||
buf = realloc(buf, bufSize);
|
||||
int size = xread(fd, buf + bufLen, MAX_READ);
|
||||
if (size <= 0) {
|
||||
buf[bufLen] = '\0';
|
||||
close(fd);
|
||||
break;
|
||||
}
|
||||
bufLen += size;
|
||||
bufSize += MAX_READ;
|
||||
}
|
||||
if (bufLen == 0) {
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
int numDrivers = 0;
|
||||
int allocd = 10;
|
||||
ttyDrivers = malloc(sizeof(TtyDriver) * allocd);
|
||||
char* at = buf;
|
||||
while (*at != '\0') {
|
||||
at = strchr(at, ' '); // skip first token
|
||||
while (*at == ' ') at++; // skip spaces
|
||||
char* token = at; // mark beginning of path
|
||||
at = strchr(at, ' '); // find end of path
|
||||
*at = '\0'; at++; // clear and skip
|
||||
ttyDrivers[numDrivers].path = strdup(token); // save
|
||||
while (*at == ' ') at++; // skip spaces
|
||||
token = at; // mark beginning of major
|
||||
at = strchr(at, ' '); // find end of major
|
||||
*at = '\0'; at++; // clear and skip
|
||||
ttyDrivers[numDrivers].major = atoi(token); // save
|
||||
while (*at == ' ') at++; // skip spaces
|
||||
token = at; // mark beginning of minorFrom
|
||||
while (*at >= '0' && *at <= '9') at++; //find end of minorFrom
|
||||
if (*at == '-') { // if has range
|
||||
*at = '\0'; at++; // clear and skip
|
||||
ttyDrivers[numDrivers].minorFrom = atoi(token); // save
|
||||
token = at; // mark beginning of minorTo
|
||||
at = strchr(at, ' '); // find end of minorTo
|
||||
*at = '\0'; at++; // clear and skip
|
||||
ttyDrivers[numDrivers].minorTo = atoi(token); // save
|
||||
} else { // no range
|
||||
*at = '\0'; at++; // clear and skip
|
||||
ttyDrivers[numDrivers].minorFrom = atoi(token); // save
|
||||
ttyDrivers[numDrivers].minorTo = atoi(token); // save
|
||||
}
|
||||
at = strchr(at, '\n'); // go to end of line
|
||||
at++; // skip
|
||||
numDrivers++;
|
||||
if (numDrivers == allocd) {
|
||||
allocd += 10;
|
||||
ttyDrivers = realloc(ttyDrivers, sizeof(TtyDriver) * allocd);
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
numDrivers++;
|
||||
ttyDrivers = realloc(ttyDrivers, sizeof(TtyDriver) * numDrivers);
|
||||
ttyDrivers[numDrivers - 1].path = NULL;
|
||||
qsort(ttyDrivers, numDrivers - 1, sizeof(TtyDriver), sortTtyDrivers);
|
||||
this->ttyDrivers = ttyDrivers;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
|
||||
static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) {
|
||||
this->netlink_socket = nl_socket_alloc();
|
||||
if (this->netlink_socket == NULL) {
|
||||
return;
|
||||
}
|
||||
if (nl_connect(this->netlink_socket, NETLINK_GENERIC) < 0) {
|
||||
return;
|
||||
}
|
||||
this->netlink_family = genl_ctrl_resolve(this->netlink_socket, TASKSTATS_GENL_NAME);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||
LinuxProcessList* this = xCalloc(1, sizeof(LinuxProcessList));
|
||||
ProcessList* pl = &(this->super);
|
||||
ProcessList_init(pl, Class(LinuxProcess), usersTable, pidWhiteList, userId);
|
||||
|
||||
LinuxProcessList_initTtyDrivers(this);
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
LinuxProcessList_initNetlinkSocket(this);
|
||||
#endif
|
||||
|
||||
// Update CPU count:
|
||||
FILE* file = fopen(PROCSTATFILE, "r");
|
||||
@ -122,25 +261,21 @@ void ProcessList_delete(ProcessList* pl) {
|
||||
LinuxProcessList* this = (LinuxProcessList*) pl;
|
||||
ProcessList_done(pl);
|
||||
free(this->cpus);
|
||||
if (this->ttyDrivers) {
|
||||
for(int i = 0; this->ttyDrivers[i].path; i++) {
|
||||
free(this->ttyDrivers[i].path);
|
||||
}
|
||||
free(this->ttyDrivers);
|
||||
}
|
||||
#ifdef HAVE_DELAYACCT
|
||||
if (this->netlink_socket) {
|
||||
nl_close(this->netlink_socket);
|
||||
nl_socket_free(this->netlink_socket);
|
||||
}
|
||||
#endif
|
||||
free(this);
|
||||
}
|
||||
|
||||
static ssize_t xread(int fd, void *buf, size_t count) {
|
||||
// Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested.
|
||||
size_t alreadyRead = 0;
|
||||
for(;;) {
|
||||
ssize_t res = read(fd, buf, count);
|
||||
if (res == -1 && errno == EINTR) continue;
|
||||
if (res > 0) {
|
||||
buf = ((char*)buf)+res;
|
||||
count -= res;
|
||||
alreadyRead += res;
|
||||
}
|
||||
if (res == -1) return -1;
|
||||
if (count == 0 || res == 0) return alreadyRead;
|
||||
}
|
||||
}
|
||||
|
||||
static double jiffy = 0.0;
|
||||
|
||||
static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) {
|
||||
@ -152,7 +287,7 @@ static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) {
|
||||
static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, const char* name, char* command, int* commLen) {
|
||||
LinuxProcess* lp = (LinuxProcess*) process;
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name);
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return false;
|
||||
@ -221,7 +356,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
|
||||
process->processor = strtol(location, &location, 10);
|
||||
|
||||
process->time = lp->utime + lp->stime;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -230,7 +365,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam
|
||||
char filename[MAX_NAME+1];
|
||||
filename[MAX_NAME] = '\0';
|
||||
|
||||
snprintf(filename, MAX_NAME, "%s/%s", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s", dirname, name);
|
||||
struct stat sstat;
|
||||
int statok = stat(filename, &sstat);
|
||||
if (statok == -1)
|
||||
@ -252,11 +387,20 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
|
||||
char filename[MAX_NAME+1];
|
||||
filename[MAX_NAME] = '\0';
|
||||
|
||||
snprintf(filename, MAX_NAME, "%s/%s/io", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/io", dirname, name);
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
process->io_rate_read_bps = -1;
|
||||
process->io_rate_write_bps = -1;
|
||||
process->io_rchar = -1LL;
|
||||
process->io_wchar = -1LL;
|
||||
process->io_syscr = -1LL;
|
||||
process->io_syscw = -1LL;
|
||||
process->io_read_bytes = -1LL;
|
||||
process->io_write_bytes = -1LL;
|
||||
process->io_cancelled_write_bytes = -1LL;
|
||||
process->io_rate_read_time = -1LL;
|
||||
process->io_rate_write_time = -1LL;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -292,15 +436,16 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (line[5] == 'r' && strncmp(line+1, "yscr: ", 6) == 0)
|
||||
if (line[5] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) {
|
||||
process->io_syscr = strtoull(line+7, NULL, 10);
|
||||
else if (strncmp(line+1, "yscw: ", 6) == 0)
|
||||
sscanf(line, "syscw: %32llu", &process->io_syscw);
|
||||
} else if (strncmp(line+1, "yscw: ", 6) == 0) {
|
||||
process->io_syscw = strtoull(line+7, NULL, 10);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
if (strncmp(line+1, "ancelled_write_bytes: ", 22) == 0)
|
||||
if (strncmp(line+1, "ancelled_write_bytes: ", 22) == 0) {
|
||||
process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -311,7 +456,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
|
||||
|
||||
static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name) {
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/statm", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/statm", dirname, name);
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return false;
|
||||
@ -341,7 +486,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d
|
||||
return;
|
||||
}
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name);
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (!file)
|
||||
return;
|
||||
@ -364,7 +509,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d
|
||||
|
||||
static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* dirname, const char* name) {
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name);
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (!file) {
|
||||
process->cgroup = xStrdup("");
|
||||
@ -399,7 +544,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d
|
||||
|
||||
static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* dirname, const char* name) {
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/status", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name);
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (!file)
|
||||
return;
|
||||
@ -430,10 +575,11 @@ static void LinuxProcessList_readVServerData(LinuxProcess* process, const char*
|
||||
|
||||
static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirname, const char* name) {
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name);
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (!file)
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
char buffer[PROC_LINE_LENGTH + 1];
|
||||
if (fgets(buffer, PROC_LINE_LENGTH, file)) {
|
||||
unsigned int oom;
|
||||
@ -445,8 +591,77 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
|
||||
static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) {
|
||||
struct nlmsghdr *nlhdr;
|
||||
struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1];
|
||||
struct nlattr *nlattr;
|
||||
struct taskstats *stats;
|
||||
int rem;
|
||||
unsigned long long int timeDelta;
|
||||
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
||||
|
||||
nlhdr = nlmsg_hdr(nlmsg);
|
||||
|
||||
if (genlmsg_parse(nlhdr, 0, nlattrs, TASKSTATS_TYPE_MAX, NULL) < 0) {
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
||||
if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) {
|
||||
stats = nla_data(nla_next(nla_data(nlattr), &rem));
|
||||
assert(lp->super.pid == stats->ac_pid);
|
||||
timeDelta = (stats->ac_etime*1000 - lp->delay_read_time);
|
||||
#define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x;
|
||||
#define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100);
|
||||
lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total);
|
||||
lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total);
|
||||
lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total);
|
||||
#undef DELTAPERC
|
||||
#undef BOUNDS
|
||||
lp->swapin_delay_total = stats->swapin_delay_total;
|
||||
lp->blkio_delay_total = stats->blkio_delay_total;
|
||||
lp->cpu_delay_total = stats->cpu_delay_total;
|
||||
lp->delay_read_time = stats->ac_etime*1000;
|
||||
}
|
||||
return NL_OK;
|
||||
}
|
||||
|
||||
static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProcess* process) {
|
||||
struct nl_msg *msg;
|
||||
|
||||
if (nl_socket_modify_cb(this->netlink_socket, NL_CB_VALID, NL_CB_CUSTOM, handleNetlinkMsg, process) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! (msg = nlmsg_alloc())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, this->netlink_family, 0, NLM_F_REQUEST, TASKSTATS_CMD_GET, TASKSTATS_VERSION)) {
|
||||
nlmsg_free(msg);
|
||||
}
|
||||
|
||||
if (nla_put_u32(msg, TASKSTATS_CMD_ATTR_PID, process->super.pid) < 0) {
|
||||
nlmsg_free(msg);
|
||||
}
|
||||
|
||||
if (nl_send_sync(this->netlink_socket, msg) < 0) {
|
||||
process->swapin_delay_percent = -1LL;
|
||||
process->blkio_delay_percent = -1LL;
|
||||
process->cpu_delay_percent = -1LL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nl_recvmsgs_default(this->netlink_socket) < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void setCommand(Process* process, const char* command, int len) {
|
||||
if (process->comm && process->commLen <= len) {
|
||||
if (process->comm && process->commLen >= len) {
|
||||
strncpy(process->comm, command, len + 1);
|
||||
} else {
|
||||
free(process->comm);
|
||||
@ -460,7 +675,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
||||
return true;
|
||||
|
||||
char filename[MAX_NAME+1];
|
||||
snprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return false;
|
||||
@ -469,25 +684,72 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
||||
int amtRead = xread(fd, command, sizeof(command) - 1);
|
||||
close(fd);
|
||||
int tokenEnd = 0;
|
||||
if (amtRead > 0) {
|
||||
for (int i = 0; i < amtRead; i++)
|
||||
if (command[i] == '\0' || command[i] == '\n') {
|
||||
if (tokenEnd == 0) {
|
||||
tokenEnd = i;
|
||||
}
|
||||
command[i] = ' ';
|
||||
int lastChar = 0;
|
||||
if (amtRead <= 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < amtRead; i++) {
|
||||
if (command[i] == '\0' || command[i] == '\n') {
|
||||
if (tokenEnd == 0) {
|
||||
tokenEnd = i;
|
||||
}
|
||||
command[i] = ' ';
|
||||
} else {
|
||||
lastChar = i;
|
||||
}
|
||||
}
|
||||
if (tokenEnd == 0) {
|
||||
tokenEnd = amtRead;
|
||||
}
|
||||
command[amtRead] = '\0';
|
||||
command[lastChar + 1] = '\0';
|
||||
process->basenameOffset = tokenEnd;
|
||||
setCommand(process, command, amtRead);
|
||||
setCommand(process, command, lastChar);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned int tty_nr) {
|
||||
unsigned int maj = major(tty_nr);
|
||||
unsigned int min = minor(tty_nr);
|
||||
|
||||
int i = -1;
|
||||
for (;;) {
|
||||
i++;
|
||||
if ((!ttyDrivers[i].path) || maj < ttyDrivers[i].major) {
|
||||
break;
|
||||
}
|
||||
if (maj > ttyDrivers[i].major) {
|
||||
continue;
|
||||
}
|
||||
if (min < ttyDrivers[i].minorFrom) {
|
||||
break;
|
||||
}
|
||||
if (min > ttyDrivers[i].minorTo) {
|
||||
continue;
|
||||
}
|
||||
unsigned int idx = min - ttyDrivers[i].minorFrom;
|
||||
struct stat sstat;
|
||||
char* fullPath;
|
||||
for(;;) {
|
||||
asprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx);
|
||||
int err = stat(fullPath, &sstat);
|
||||
if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath;
|
||||
free(fullPath);
|
||||
asprintf(&fullPath, "%s%d", ttyDrivers[i].path, idx);
|
||||
err = stat(fullPath, &sstat);
|
||||
if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath;
|
||||
free(fullPath);
|
||||
if (idx == min) break;
|
||||
idx = min;
|
||||
}
|
||||
int err = stat(ttyDrivers[i].path, &sstat);
|
||||
if (err == 0 && tty_nr == sstat.st_rdev) return strdup(ttyDrivers[i].path);
|
||||
}
|
||||
char* out;
|
||||
asprintf(&out, "/dev/%u:%u", maj, min);
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) {
|
||||
ProcessList* pl = (ProcessList*) this;
|
||||
DIR* dir;
|
||||
@ -534,7 +796,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
||||
LinuxProcess* lp = (LinuxProcess*) proc;
|
||||
|
||||
char subdirname[MAX_NAME+1];
|
||||
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
|
||||
xSnprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
|
||||
LinuxProcessList_recurseProcTree(this, subdirname, proc, period, tv);
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
@ -550,8 +812,13 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
||||
char command[MAX_NAME+1];
|
||||
unsigned long long int lasttimes = (lp->utime + lp->stime);
|
||||
int commLen = 0;
|
||||
unsigned int tty_nr = proc->tty_nr;
|
||||
if (! LinuxProcessList_readStatFile(proc, dirname, name, command, &commLen))
|
||||
goto errorReadingProcess;
|
||||
if (tty_nr != proc->tty_nr && this->ttyDrivers) {
|
||||
free(lp->ttyDevice);
|
||||
lp->ttyDevice = LinuxProcessList_updateTtyDevice(this->ttyDrivers, proc->tty_nr);
|
||||
}
|
||||
if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO)
|
||||
LinuxProcess_updateIOPriority(lp);
|
||||
float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0;
|
||||
@ -584,13 +851,17 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
||||
|
||||
ProcessList_add(pl, proc);
|
||||
} else {
|
||||
if (settings->updateProcessNames) {
|
||||
if (settings->updateProcessNames && proc->state != 'Z') {
|
||||
if (! LinuxProcessList_readCmdlineFile(proc, dirname, name)) {
|
||||
goto errorReadingProcess;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
LinuxProcessList_readDelayAcctData(this, lp);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CGROUP
|
||||
if (settings->flags & PROCESS_FLAG_LINUX_CGROUP)
|
||||
LinuxProcessList_readCGroupFile(lp, dirname, name);
|
||||
@ -599,11 +870,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
||||
if (settings->flags & PROCESS_FLAG_LINUX_OOM)
|
||||
LinuxProcessList_readOomData(lp, dirname, name);
|
||||
|
||||
if (proc->state == 'Z') {
|
||||
if (proc->state == 'Z' && (proc->basenameOffset == 0)) {
|
||||
proc->basenameOffset = -1;
|
||||
setCommand(proc, command, commLen);
|
||||
} else if (Process_isThread(proc)) {
|
||||
if (settings->showThreadNames || Process_isKernelThread(proc) || proc->state == 'Z') {
|
||||
if (settings->showThreadNames || Process_isKernelThread(proc) || (proc->state == 'Z' && proc->basenameOffset == 0)) {
|
||||
proc->basenameOffset = -1;
|
||||
setCommand(proc, command, commLen);
|
||||
} else if (settings->showThreadNames) {
|
||||
@ -720,31 +991,23 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||
unsigned long long int virtalltime = guest + guestnice;
|
||||
unsigned long long int totaltime = usertime + nicetime + systemalltime + idlealltime + steal + virtalltime;
|
||||
CPUData* cpuData = &(this->cpus[i]);
|
||||
assert (systemtime >= cpuData->systemTime);
|
||||
assert (idletime >= cpuData->idleTime);
|
||||
assert (totaltime >= cpuData->totalTime);
|
||||
assert (systemalltime >= cpuData->systemAllTime);
|
||||
assert (idlealltime >= cpuData->idleAllTime);
|
||||
assert (ioWait >= cpuData->ioWaitTime);
|
||||
assert (irq >= cpuData->irqTime);
|
||||
assert (softIrq >= cpuData->softIrqTime);
|
||||
assert (steal >= cpuData->stealTime);
|
||||
assert (virtalltime >= cpuData->guestTime);
|
||||
// Since we do a subtraction (usertime - guest) and cputime64_to_clock_t()
|
||||
// used in /proc/stat rounds down numbers, it can lead to a case where the
|
||||
// integer overflow.
|
||||
cpuData->userPeriod = (usertime > cpuData->userTime) ? usertime - cpuData->userTime : 0;
|
||||
cpuData->nicePeriod = (nicetime > cpuData->niceTime) ? nicetime - cpuData->niceTime : 0;
|
||||
cpuData->systemPeriod = systemtime - cpuData->systemTime;
|
||||
cpuData->systemAllPeriod = systemalltime - cpuData->systemAllTime;
|
||||
cpuData->idleAllPeriod = idlealltime - cpuData->idleAllTime;
|
||||
cpuData->idlePeriod = idletime - cpuData->idleTime;
|
||||
cpuData->ioWaitPeriod = ioWait - cpuData->ioWaitTime;
|
||||
cpuData->irqPeriod = irq - cpuData->irqTime;
|
||||
cpuData->softIrqPeriod = softIrq - cpuData->softIrqTime;
|
||||
cpuData->stealPeriod = steal - cpuData->stealTime;
|
||||
cpuData->guestPeriod = virtalltime - cpuData->guestTime;
|
||||
cpuData->totalPeriod = totaltime - cpuData->totalTime;
|
||||
#define WRAP_SUBTRACT(a,b) (a > b) ? a - b : 0
|
||||
cpuData->userPeriod = WRAP_SUBTRACT(usertime, cpuData->userTime);
|
||||
cpuData->nicePeriod = WRAP_SUBTRACT(nicetime, cpuData->niceTime);
|
||||
cpuData->systemPeriod = WRAP_SUBTRACT(systemtime, cpuData->systemTime);
|
||||
cpuData->systemAllPeriod = WRAP_SUBTRACT(systemalltime, cpuData->systemAllTime);
|
||||
cpuData->idleAllPeriod = WRAP_SUBTRACT(idlealltime, cpuData->idleAllTime);
|
||||
cpuData->idlePeriod = WRAP_SUBTRACT(idletime, cpuData->idleTime);
|
||||
cpuData->ioWaitPeriod = WRAP_SUBTRACT(ioWait, cpuData->ioWaitTime);
|
||||
cpuData->irqPeriod = WRAP_SUBTRACT(irq, cpuData->irqTime);
|
||||
cpuData->softIrqPeriod = WRAP_SUBTRACT(softIrq, cpuData->softIrqTime);
|
||||
cpuData->stealPeriod = WRAP_SUBTRACT(steal, cpuData->stealTime);
|
||||
cpuData->guestPeriod = WRAP_SUBTRACT(virtalltime, cpuData->guestTime);
|
||||
cpuData->totalPeriod = WRAP_SUBTRACT(totaltime, cpuData->totalTime);
|
||||
#undef WRAP_SUBTRACT
|
||||
cpuData->userTime = usertime;
|
||||
cpuData->niceTime = nicetime;
|
||||
cpuData->systemTime = systemtime;
|
||||
|
@ -9,6 +9,9 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
#endif
|
||||
|
||||
|
||||
#include "ProcessList.h"
|
||||
|
||||
@ -40,11 +43,23 @@ typedef struct CPUData_ {
|
||||
unsigned long long int guestPeriod;
|
||||
} CPUData;
|
||||
|
||||
typedef struct TtyDriver_ {
|
||||
char* path;
|
||||
unsigned int major;
|
||||
unsigned int minorFrom;
|
||||
unsigned int minorTo;
|
||||
} TtyDriver;
|
||||
|
||||
typedef struct LinuxProcessList_ {
|
||||
ProcessList super;
|
||||
|
||||
|
||||
CPUData* cpus;
|
||||
|
||||
TtyDriver* ttyDrivers;
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
struct nl_sock *netlink_socket;
|
||||
int netlink_family;
|
||||
#endif
|
||||
} LinuxProcessList;
|
||||
|
||||
#ifndef PROCDIR
|
||||
@ -59,6 +74,10 @@ typedef struct LinuxProcessList_ {
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#endif
|
||||
|
||||
#ifndef PROCTTYDRIVERSFILE
|
||||
#define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers"
|
||||
#endif
|
||||
|
||||
#ifndef PROC_LINE_LENGTH
|
||||
#define PROC_LINE_LENGTH 512
|
||||
#endif
|
||||
@ -67,7 +86,11 @@ typedef struct LinuxProcessList_ {
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
|
||||
#endif
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
void ProcessList_delete(ProcessList* pl);
|
||||
@ -89,6 +112,10 @@ void ProcessList_delete(ProcessList* pl);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
|
||||
#endif
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* super);
|
||||
|
||||
#endif
|
||||
|
@ -47,7 +47,7 @@ ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_R
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
SignalItem Platform_signals[] = {
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
@ -84,7 +84,7 @@ SignalItem Platform_signals[] = {
|
||||
{ .name = "31 SIGSYS", .number = 31 },
|
||||
};
|
||||
|
||||
unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||
Panel* panel = st->panel;
|
||||
@ -215,7 +215,7 @@ void Platform_setSwapValues(Meter* this) {
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid) {
|
||||
char procname[32+1];
|
||||
snprintf(procname, 32, "/proc/%d/environ", pid);
|
||||
xSnprintf(procname, 32, "/proc/%d/environ", pid);
|
||||
FILE* fd = fopen(procname, "r");
|
||||
char *env = NULL;
|
||||
if (fd) {
|
||||
|
@ -23,9 +23,9 @@ extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
extern SignalItem Platform_signals[];
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern unsigned int Platform_numberOfSignals;
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
||||
|
@ -85,7 +85,7 @@ ProcessFieldData Process_fields[] = {
|
||||
.flags = 0, },
|
||||
[TTY_NR] = {
|
||||
.name = "TTY_NR",
|
||||
.title = " TTY ",
|
||||
.title = " TTY ",
|
||||
.description = "Controlling terminal",
|
||||
.flags = 0, },
|
||||
[TPGID] = {
|
||||
|
@ -10,18 +10,20 @@ in the source distribution for its full text.
|
||||
#include "OpenBSDProcessList.h"
|
||||
#include "OpenBSDProcess.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/user.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*{
|
||||
|
||||
@ -42,22 +44,37 @@ typedef struct OpenBSDProcessList_ {
|
||||
|
||||
}*/
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
/*
|
||||
* avoid relying on or conflicting with MIN() and MAX() in sys/param.h
|
||||
*/
|
||||
#ifndef MINIMUM
|
||||
#define MINIMUM(x, y) ((x) > (y) ? (y) : (x))
|
||||
#endif
|
||||
|
||||
#ifndef MAXIMUM
|
||||
#define MAXIMUM(x, y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low))
|
||||
#endif
|
||||
|
||||
static int pageSizeKb;
|
||||
static long fscale;
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||
int mib[] = { CTL_HW, HW_NCPU };
|
||||
int fmib[] = { CTL_KERN, KERN_FSCALE };
|
||||
int i, e;
|
||||
OpenBSDProcessList* opl = xCalloc(1, sizeof(OpenBSDProcessList));
|
||||
ProcessList* pl = (ProcessList*) opl;
|
||||
size_t size = sizeof(pl->cpuCount);
|
||||
OpenBSDProcessList* opl;
|
||||
ProcessList* pl;
|
||||
size_t size;
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
|
||||
opl = xCalloc(1, sizeof(OpenBSDProcessList));
|
||||
pl = (ProcessList*) opl;
|
||||
size = sizeof(pl->cpuCount);
|
||||
ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidWhiteList, userId);
|
||||
|
||||
e = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0);
|
||||
if (e == -1 || pl->cpuCount < 1) {
|
||||
pl->cpuCount = 1;
|
||||
@ -65,26 +82,29 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
||||
opl->cpus = xRealloc(opl->cpus, pl->cpuCount * sizeof(CPUData));
|
||||
|
||||
size = sizeof(fscale);
|
||||
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0)
|
||||
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) {
|
||||
err(1, "fscale sysctl call failed");
|
||||
}
|
||||
|
||||
for (i = 0; i < pl->cpuCount; i++) {
|
||||
opl->cpus[i].totalTime = 1;
|
||||
opl->cpus[i].totalPeriod = 1;
|
||||
}
|
||||
|
||||
pageSizeKb = PAGE_SIZE_KB;
|
||||
|
||||
// XXX: last arg should eventually be an errbuf
|
||||
opl->kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
|
||||
assert(opl->kd);
|
||||
opl->kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
|
||||
if (opl->kd == NULL) {
|
||||
errx(1, "kvm_open: %s", errbuf);
|
||||
}
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
void ProcessList_delete(ProcessList* this) {
|
||||
const OpenBSDProcessList* opl = (OpenBSDProcessList*) this;
|
||||
if (opl->kd) kvm_close(opl->kd);
|
||||
|
||||
if (opl->kd) {
|
||||
kvm_close(opl->kd);
|
||||
}
|
||||
|
||||
free(opl->cpus);
|
||||
|
||||
@ -95,15 +115,26 @@ void ProcessList_delete(ProcessList* this) {
|
||||
static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||
static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
|
||||
struct uvmexp uvmexp;
|
||||
size_t size = sizeof(uvmexp);
|
||||
size_t size_uvmexp = sizeof(uvmexp);
|
||||
|
||||
if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
||||
if (sysctl(uvmexp_mib, 2, &uvmexp, &size_uvmexp, NULL, 0) < 0) {
|
||||
err(1, "uvmexp sysctl call failed");
|
||||
}
|
||||
|
||||
//kb_pagesize = uvmexp.pagesize / 1024;
|
||||
pl->usedMem = uvmexp.active * pageSizeKb;
|
||||
pl->totalMem = uvmexp.npages * pageSizeKb;
|
||||
pl->totalMem = uvmexp.npages * PAGE_SIZE_KB;
|
||||
|
||||
// Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9)
|
||||
static int bcache_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};
|
||||
struct bcachestats bcstats;
|
||||
size_t size_bcstats = sizeof(bcstats);
|
||||
|
||||
if (sysctl(bcache_mib, 3, &bcstats, &size_bcstats, NULL, 0) < 0) {
|
||||
err(1, "cannot get vfs.bcachestat");
|
||||
}
|
||||
|
||||
pl->cachedMem = bcstats.numbufpages * PAGE_SIZE_KB;
|
||||
pl->freeMem = uvmexp.free * PAGE_SIZE_KB;
|
||||
pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * PAGE_SIZE_KB;
|
||||
|
||||
/*
|
||||
const OpenBSDProcessList* opl = (OpenBSDProcessList*) pl;
|
||||
@ -112,10 +143,10 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0);
|
||||
pl->totalMem /= 1024;
|
||||
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(pl->usedMem), &len, NULL, 0);
|
||||
pl->usedMem *= pageSizeKb;
|
||||
pl->usedMem *= PAGE_SIZE_KB;
|
||||
pl->freeMem = pl->totalMem - pl->usedMem;
|
||||
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0);
|
||||
pl->cachedMem *= pageSizeKb;
|
||||
pl->cachedMem *= PAGE_SIZE_KB;
|
||||
|
||||
struct kvm_swap swap[16];
|
||||
int nswap = kvm_getswapinfo(opl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0);
|
||||
@ -125,8 +156,8 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||
pl->totalSwap += swap[i].ksw_total;
|
||||
pl->usedSwap += swap[i].ksw_used;
|
||||
}
|
||||
pl->totalSwap *= pageSizeKb;
|
||||
pl->usedSwap *= pageSizeKb;
|
||||
pl->totalSwap *= PAGE_SIZE_KB;
|
||||
pl->usedSwap *= PAGE_SIZE_KB;
|
||||
|
||||
pl->sharedMem = 0; // currently unused
|
||||
pl->buffersMem = 0; // not exposed to userspace
|
||||
@ -134,40 +165,40 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||
}
|
||||
|
||||
char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) {
|
||||
char *s, *buf, **arg;
|
||||
size_t cpsz, len = 0, n;
|
||||
char *s, **arg;
|
||||
size_t len = 0, n;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* We attempt to fall back to just the command name (argv[0]) if we
|
||||
* fail to construct the full command at any point.
|
||||
* Like OpenBSD's top(1), we try to fall back to the command name
|
||||
* (argv[0]) if we fail to construct the full command.
|
||||
*/
|
||||
arg = kvm_getargv(kd, kproc, 500);
|
||||
if (arg == NULL) {
|
||||
if ((s = xStrdup(kproc->p_comm)) == NULL) {
|
||||
err(1, NULL);
|
||||
}
|
||||
return s;
|
||||
if (arg == NULL || *arg == NULL) {
|
||||
*basenameEnd = strlen(kproc->p_comm);
|
||||
return xStrdup(kproc->p_comm);
|
||||
}
|
||||
for (i = 0; arg[i] != NULL; i++) {
|
||||
len += strlen(arg[i]) + 1;
|
||||
len += strlen(arg[i]) + 1; /* room for arg and trailing space or NUL */
|
||||
}
|
||||
if ((buf = s = xMalloc(len)) == NULL) {
|
||||
if ((s = xStrdup(kproc->p_comm)) == NULL) {
|
||||
err(1, NULL);
|
||||
}
|
||||
return s;
|
||||
/* don't use xMalloc here - we want to handle huge argv's gracefully */
|
||||
if ((s = malloc(len)) == NULL) {
|
||||
*basenameEnd = strlen(kproc->p_comm);
|
||||
return xStrdup(kproc->p_comm);
|
||||
}
|
||||
|
||||
*s = '\0';
|
||||
|
||||
for (i = 0; arg[i] != NULL; i++) {
|
||||
n = strlcpy(buf, arg[i], (s + len) - buf);
|
||||
buf += n;
|
||||
n = strlcat(s, arg[i], len);
|
||||
if (i == 0) {
|
||||
*basenameEnd = n;
|
||||
/* TODO: rename all basenameEnd to basenameLen, make size_t */
|
||||
*basenameEnd = MINIMUM(n, len-1);
|
||||
}
|
||||
*buf = ' ';
|
||||
buf++;
|
||||
/* the trailing space should get truncated anyway */
|
||||
strlcat(s, " ", len);
|
||||
}
|
||||
*(buf - 1) = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,20 @@ typedef struct OpenBSDProcessList_ {
|
||||
} OpenBSDProcessList;
|
||||
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
/*
|
||||
* avoid relying on or conflicting with MIN() and MAX() in sys/param.h
|
||||
*/
|
||||
#ifndef MINIMUM
|
||||
#define MINIMUM(x, y) ((x) > (y) ? (y) : (x))
|
||||
#endif
|
||||
|
||||
#ifndef MAXIMUM
|
||||
#define MAXIMUM(x, y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low))
|
||||
#endif
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
|
@ -99,7 +99,7 @@ int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
/*
|
||||
* See /usr/include/sys/signal.h
|
||||
*/
|
||||
SignalItem Platform_signals[] = {
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
@ -136,7 +136,7 @@ SignalItem Platform_signals[] = {
|
||||
{ .name = "32 SIGTHR", .number = 32 },
|
||||
};
|
||||
|
||||
unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys) {
|
||||
(void) keys;
|
||||
@ -265,9 +265,6 @@ void Platform_setSwapValues(Meter* this) {
|
||||
}
|
||||
|
||||
swdev = xCalloc(nswap, sizeof(*swdev));
|
||||
if (swdev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
rnswap = swapctl(SWAP_STATS, swdev, nswap);
|
||||
if (rnswap == -1) {
|
||||
|
@ -39,9 +39,9 @@ extern int Platform_numberOfFields;
|
||||
/*
|
||||
* See /usr/include/sys/signal.h
|
||||
*/
|
||||
extern SignalItem Platform_signals[];
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern unsigned int Platform_numberOfSignals;
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user