Rework enum ProcessField

Use only one enum instead of a global and a platform specific one.
Drop Platform_numberOfFields global variable.
Set known size of Process_fields array
This commit is contained in:
Christian Göttsche
2020-12-15 19:44:48 +01:00
committed by cgzones
parent d872e36308
commit 89473cc9ae
41 changed files with 208 additions and 175 deletions

View File

@ -30,7 +30,7 @@ int pageSizeKB;
/* Used to identify kernel threads in Comm and Exe columns */
static const char *const kthreadID = "KTHREAD";
ProcessFieldData Process_fields[] = {
ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[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, },
@ -100,7 +100,6 @@ ProcessFieldData Process_fields[] = {
[PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process from /proc/[pid]/comm", .flags = 0, },
[PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process from /proc/[pid]/exe", .flags = 0, },
[CWD] = { .name ="CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_LINUX_CWD, },
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
};
ProcessPidColumn Process_pidColumns[] = {
@ -608,7 +607,7 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
size_t n = sizeof(buffer) - 1;
switch ((int)field) {
switch (field) {
case TTY_NR: {
if (lp->ttyDevice) {
xSnprintf(buffer, n, "%-9s", lp->ttyDevice + 5 /* skip "/dev/" */);
@ -753,7 +752,7 @@ static long LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proc
const LinuxProcess* p1 = (const LinuxProcess*)v1;
const LinuxProcess* p2 = (const LinuxProcess*)v2;
switch ((int) key) {
switch (key) {
case M_DRS:
return SPACESHIP_NUMBER(p2->m_drs, p1->m_drs);
case M_DT:

View File

@ -30,54 +30,6 @@ in the source distribution for its full text.
#define PROCESS_FLAG_LINUX_CWD 0x00020000
typedef enum LinuxProcessField_ {
CMINFLT = 11,
CMAJFLT = 13,
UTIME = 14,
STIME = 15,
CUTIME = 16,
CSTIME = 17,
M_SHARE = 41,
M_TRS = 42,
M_DRS = 43,
M_LRS = 44,
M_DT = 45,
#ifdef HAVE_OPENVZ
CTID = 100,
VPID = 101,
#endif
#ifdef HAVE_VSERVER
VXID = 102,
#endif
RCHAR = 103,
WCHAR = 104,
SYSCR = 105,
SYSCW = 106,
RBYTES = 107,
WBYTES = 108,
CNCLWB = 109,
IO_READ_RATE = 110,
IO_WRITE_RATE = 111,
IO_RATE = 112,
CGROUP = 113,
OOM = 114,
IO_PRIORITY = 115,
#ifdef HAVE_DELAYACCT
PERCENT_CPU_DELAY = 116,
PERCENT_IO_DELAY = 117,
PERCENT_SWAP_DELAY = 118,
#endif
M_PSS = 119,
M_SWAP = 120,
M_PSSWP = 121,
CTXT = 122,
SECATTR = 123,
PROC_COMM = 124,
PROC_EXE = 125,
CWD = 126,
LAST_PROCESSFIELD = 127,
} LinuxProcessField;
/* LinuxProcessMergedCommand is populated by LinuxProcess_makeCommandStr: It
* contains the merged Command string, and the information needed by
* LinuxProcess_writeCommand to color the string. str will be NULL for kernel
@ -175,7 +127,7 @@ extern int pageSize;
extern int pageSizeKB;
extern ProcessFieldData Process_fields[];
extern ProcessFieldData Process_fields[LAST_PROCESSFIELD];
extern ProcessPidColumn Process_pidColumns[];

View File

@ -65,9 +65,7 @@ in the source distribution for its full text.
#endif
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, (int)M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
int Platform_numberOfFields = LAST_PROCESSFIELD;
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
const SignalItem Platform_signals[] = {
{ .name = " 0 Cancel", .number = 0 },

View File

@ -20,8 +20,6 @@ in the source distribution for its full text.
extern ProcessField Platform_defaultFields[];
extern int Platform_numberOfFields;
extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals;

53
linux/ProcessField.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef HEADER_LinuxProcessField
#define HEADER_LinuxProcessField
/*
htop - linux/ProcessField.h
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
#define PLATFORM_PROCESS_FIELDS \
CMINFLT = 11, \
CMAJFLT = 13, \
UTIME = 14, \
STIME = 15, \
CUTIME = 16, \
CSTIME = 17, \
M_SHARE = 41, \
M_TRS = 42, \
M_DRS = 43, \
M_LRS = 44, \
M_DT = 45, \
CTID = 100, \
VPID = 101, \
VXID = 102, \
RCHAR = 103, \
WCHAR = 104, \
SYSCR = 105, \
SYSCW = 106, \
RBYTES = 107, \
WBYTES = 108, \
CNCLWB = 109, \
IO_READ_RATE = 110, \
IO_WRITE_RATE = 111, \
IO_RATE = 112, \
CGROUP = 113, \
OOM = 114, \
IO_PRIORITY = 115, \
PERCENT_CPU_DELAY = 116, \
PERCENT_IO_DELAY = 117, \
PERCENT_SWAP_DELAY = 118, \
M_PSS = 119, \
M_SWAP = 120, \
M_PSSWP = 121, \
CTXT = 122, \
SECATTR = 123, \
PROC_COMM = 124, \
PROC_EXE = 125, \
CWD = 126, \
// End of list
#endif /* HEADER_LinuxProcessField */