Commit e3fe3962 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Move more Linux-specific code into Linux subdir.

parent e7d6eb6a
......@@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "SignalsPanel.h"
#include "String.h"
#include "TraceScreen.h"
#include "Platform.h"
#include <ctype.h>
#include <math.h>
......
......@@ -6,6 +6,7 @@ in the source distribution for its full text.
*/
#include "AvailableColumnsPanel.h"
#include "Platform.h"
#include "Header.h"
#include "ColumnsPanel.h"
......
......@@ -6,6 +6,7 @@ in the source distribution for its full text.
*/
#include "ColumnsPanel.h"
#include "Platform.h"
#include "String.h"
#include "ListItem.h"
......
......@@ -39,11 +39,7 @@ in the source distribution for its full text.
#include <sys/types.h>
#define PROCESS_FLAG_IO 1
#define PROCESS_FLAG_IOPRIO 2
#define PROCESS_FLAG_OPENVZ 4
#define PROCESS_FLAG_VSERVER 8
#define PROCESS_FLAG_CGROUP 16
#define PROCESS_FLAG_IO 0x0001
#ifndef Process_isKernelThread
#define Process_isKernelThread(_process) (_process->pgrp == 0)
......@@ -57,30 +53,7 @@ in the source distribution for its full text.
#define Process_isThread(_process) (Process_isUserlandThread(_process) || Process_isKernelThread(_process))
#endif
typedef enum ProcessField_ {
PID = 1, COMM, STATE, PPID, PGRP, SESSION, TTY_NR, TPGID, FLAGS, MINFLT, CMINFLT, MAJFLT, CMAJFLT, UTIME,
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, TGID,
#ifdef HAVE_OPENVZ
CTID, VPID,
#endif
#ifdef HAVE_VSERVER
VXID,
#endif
#ifdef HAVE_TASKSTATS
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
#endif
#ifdef HAVE_CGROUP
CGROUP,
#endif
#ifdef HAVE_OOM
OOM,
#endif
IO_PRIORITY,
LAST_PROCESSFIELD
} ProcessField;
typedef int ProcessField;
typedef struct Process_ {
Object super;
......@@ -90,6 +63,10 @@ typedef struct Process_ {
pid_t pid;
char* comm;
int indent;
int basenameOffset;
bool updated;
char state;
bool tag;
bool showChildren;
......@@ -156,8 +133,6 @@ typedef struct Process_ {
#endif
int exit_signal;
int basenameOffset;
bool updated;
unsigned long int minflt;
unsigned long int cminflt;
......@@ -196,130 +171,8 @@ long Process_compare(const void* v1, const void* v2);
}*/
ProcessFieldData Process_fields[] = {
{ .name = "", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
{ .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
{ .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
{ .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
{ .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
{ .name = "SESSION", .title = " SESN ", .description = "Process's session ID", .flags = 0, },
{ .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
{ .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
{ .name = "FLAGS", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
{ .name = "CMINFLT", .title = " CMINFLT ", .description = "Children processes' minor faults", .flags = 0, },
{ .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
{ .name = "CMAJFLT", .title = " CMAJFLT ", .description = "Children processes' major faults", .flags = 0, },
{ .name = "UTIME", .title = " UTIME+ ", .description = "User CPU time - time the process spent executing in user mode", .flags = 0, },
{ .name = "STIME", .title = " STIME+ ", .description = "System CPU time - time the kernel spent running system calls for this process", .flags = 0, },
{ .name = "CUTIME", .title = " CUTIME+ ", .description = "Children processes' user CPU time", .flags = 0, },
{ .name = "CSTIME", .title = " CSTIME+ ", .description = "Children processes' system CPU time", .flags = 0, },
{ .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
{ .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
{ .name = "ITREALVALUE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
{ .name = "VSIZE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "RSS", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "RLIM", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "STARTCODE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "ENDCODE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "STARTSTACK", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "KSTKESP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "KSTKEIP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "SIGNAL", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "BLOCKED", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "SIGIGNORE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "SIGCATCH", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "WCHAN", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "NSWAP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "CNSWAP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "EXIT_SIGNAL", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
{ .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
{ .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
{ .name = "M_SHARE", .title = " SHR ", .description = "Size of the process's shared pages", .flags = 0, },
{ .name = "M_TRS", .title = " CODE ", .description = "Size of the text segment of the process", .flags = 0, },
{ .name = "M_DRS", .title = " DATA ", .description = "Size of the data segment plus stack usage of the process", .flags = 0, },
{ .name = "M_LRS", .title = " LIB ", .description = "The library size of the process", .flags = 0, },
{ .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process", .flags = 0, },
{ .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
{ .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
{ .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
{ .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
{ .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
{ .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
{ .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
#ifdef HAVE_OPENVZ
{ .name = "CTID", .title = " CTID ", .description = "OpenVZ container ID (a.k.a. virtual environment ID)", .flags = PROCESS_FLAG_OPENVZ, },
{ .name = "VPID", .title = " VPID ", .description = "OpenVZ process ID", .flags = PROCESS_FLAG_OPENVZ, },
#endif
#ifdef HAVE_VSERVER
{ .name = "VXID", .title = " VXID ", .description = "VServer process ID", .flags = PROCESS_FLAG_VSERVER, },
#endif
#ifdef HAVE_TASKSTATS
{ .name = "RCHAR", .title = " RD_CHAR ", .description = "Number of bytes the process has read", .flags = PROCESS_FLAG_IO, },
{ .name = "WCHAR", .title = " WR_CHAR ", .description = "Number of bytes the process has written", .flags = PROCESS_FLAG_IO, },
{ .name = "SYSCR", .title = " RD_SYSC ", .description = "Number of read(2) syscalls for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "SYSCW", .title = " WR_SYSC ", .description = "Number of write(2) syscalls for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "RBYTES", .title = " IO_RBYTES ", .description = "Bytes of read(2) I/O for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "WBYTES", .title = " IO_WBYTES ", .description = "Bytes of write(2) I/O for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "CNCLWB", .title = " IO_CANCEL ", .description = "Bytes of cancelled write(2) I/O", .flags = PROCESS_FLAG_IO, },
{ .name = "IO_READ_RATE", .title = " DISK READ ", .description = "The I/O rate of read(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "IO_WRITE_RATE", .title = " DISK WRITE ", .description = "The I/O rate of write(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "IO_RATE", .title = " DISK R/W ", .description = "Total I/O rate in bytes per second", .flags = PROCESS_FLAG_IO, },
#endif
#ifdef HAVE_CGROUP
{ .name = "CGROUP", .title = " CGROUP ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_CGROUP, },
#endif
#ifdef HAVE_OOM
{ .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = 0, },
#endif
{ .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_IOPRIO, },
{ .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
};
static int Process_getuid = -1;
static char* Process_pidFormat = "%7u ";
static char* Process_tpgidFormat = "%7u ";
void Process_setupColumnWidths() {
int maxPid = Platform_getMaxPid();
if (maxPid == -1) return;
if (maxPid > 99999) {
Process_fields[PID].title = " PID ";
Process_fields[PPID].title = " PPID ";
#ifdef HAVE_OPENVZ
Process_fields[VPID].title = " VPID ";
#endif
Process_fields[TPGID].title = " TPGID ";
Process_fields[TGID].title = " TGID ";
Process_fields[PGRP].title = " PGRP ";
Process_fields[SESSION].title = " SESN ";
#ifdef HAVE_OOM
Process_fields[OOM].title = " OOM ";
#endif
Process_pidFormat = "%7u ";
Process_tpgidFormat = "%7d ";
} else {
Process_fields[PID].title = " PID ";
Process_fields[PPID].title = " PPID ";
#ifdef HAVE_OPENVZ
Process_fields[VPID].title = " VPID ";
#endif
Process_fields[TPGID].title = "TPGID ";
Process_fields[TGID].title = " TGID ";
Process_fields[PGRP].title = " PGRP ";
Process_fields[SESSION].title = " SESN ";
#ifdef HAVE_OOM
Process_fields[OOM].title = " OOM ";
#endif
Process_pidFormat = "%5u ";
Process_tpgidFormat = "%5d ";
}
}
#define ONE_K 1024L
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
......
......@@ -20,11 +20,7 @@ in the source distribution for its full text.
#include <sys/types.h>
#define PROCESS_FLAG_IO 1
#define PROCESS_FLAG_IOPRIO 2
#define PROCESS_FLAG_OPENVZ 4
#define PROCESS_FLAG_VSERVER 8
#define PROCESS_FLAG_CGROUP 16
#define PROCESS_FLAG_IO 0x0001
#ifndef Process_isKernelThread
#define Process_isKernelThread(_process) (_process->pgrp == 0)
......@@ -38,30 +34,7 @@ in the source distribution for its full text.
#define Process_isThread(_process) (Process_isUserlandThread(_process) || Process_isKernelThread(_process))
#endif
typedef enum ProcessField_ {
PID = 1, COMM, STATE, PPID, PGRP, SESSION, TTY_NR, TPGID, FLAGS, MINFLT, CMINFLT, MAJFLT, CMAJFLT, UTIME,
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, TGID,
#ifdef HAVE_OPENVZ
CTID, VPID,
#endif
#ifdef HAVE_VSERVER
VXID,
#endif
#ifdef HAVE_TASKSTATS
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
#endif
#ifdef HAVE_CGROUP
CGROUP,
#endif
#ifdef HAVE_OOM
OOM,
#endif
IO_PRIORITY,
LAST_PROCESSFIELD
} ProcessField;
typedef int ProcessField;
typedef struct Process_ {
Object super;
......@@ -71,6 +44,10 @@ typedef struct Process_ {
pid_t pid;
char* comm;
int indent;
int basenameOffset;
bool updated;
char state;
bool tag;
bool showChildren;
......@@ -137,8 +114,6 @@ typedef struct Process_ {
#endif
int exit_signal;
int basenameOffset;
bool updated;
unsigned long int minflt;
unsigned long int cminflt;
......@@ -176,11 +151,6 @@ void Process_writeField(Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
extern ProcessFieldData Process_fields[];
void Process_setupColumnWidths();
#define ONE_K 1024L
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
......
......@@ -6,6 +6,7 @@ in the source distribution for its full text.
*/
#include "ProcessList.h"
#include "Platform.h"
#include "CRT.h"
#include "String.h"
......
......@@ -6,6 +6,7 @@ in the source distribution for its full text.
*/
#include "Settings.h"
#include "Platform.h"
#include "String.h"
#include "Vector.h"
......@@ -139,10 +140,10 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
free(trim);
int i, j;
*flags = 0;
for (j = 0, i = 0; i < LAST_PROCESSFIELD && ids[i]; i++) {
for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) {
// This "+1" is for compatibility with the older enum format.
int id = atoi(ids[i]) + 1;
if (id > 0 && id < LAST_PROCESSFIELD) {
if (id > 0 && id < Platform_numberOfFields) {
fields[j] = id;
*flags |= Process_fields[id].flags;
j++;
......@@ -310,7 +311,7 @@ Settings* Settings_new(int cpuCount) {
this->countCPUsFromZero = false;
this->updateProcessNames = false;
this->fields = calloc(LAST_PROCESSFIELD+1, sizeof(ProcessField));
this->fields = calloc(Platform_numberOfFields+1, sizeof(ProcessField));
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
this->flags = 0;
......
......@@ -16,6 +16,7 @@ in the source distribution for its full text.
#include "ScreenManager.h"
#include "Settings.h"
#include "UsersTable.h"
#include "Platform.h"
#include <getopt.h>
#include <locale.h>
......@@ -101,7 +102,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
break;
case 's':
if (strcmp(optarg, "help") == 0) {
for (int j = 1; j < LAST_PROCESSFIELD; j++) {
for (int j = 1; j < Platform_numberOfFields; j++) {
const char* name = Process_fields[j].name;
if (name) printf ("%s\n", name);
}
......
......@@ -8,6 +8,7 @@ in the source distribution for its full text.
#include "Process.h"
#include "ProcessList.h"
#include "LinuxProcess.h"
#include "Platform.h"
#include "CRT.h"
#include <stdlib.h>
......@@ -16,6 +17,36 @@ in the source distribution for its full text.
/*{
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
typedef enum LinuxProcessFields {
PID = 1, COMM, STATE, PPID, PGRP, SESSION, TTY_NR, TPGID, FLAGS, MINFLT, CMINFLT, MAJFLT, CMAJFLT, UTIME,
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, TGID,
#ifdef HAVE_OPENVZ
CTID, VPID,
#endif
#ifdef HAVE_VSERVER
VXID,
#endif
#ifdef HAVE_TASKSTATS
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
#endif
#ifdef HAVE_CGROUP
CGROUP,
#endif
#ifdef HAVE_OOM
OOM,
#endif
IO_PRIORITY,
LAST_PROCESSFIELD
} LinuxProcessField;
#include "IOPriority.h"
typedef struct LinuxProcess_ {
......@@ -27,6 +58,128 @@ typedef struct LinuxProcess_ {
}*/
ProcessFieldData Process_fields[] = {
{ .name = "", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
{ .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
{ .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
{ .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
{ .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
{ .name = "SESSION", .title = " SESN ", .description = "Process's session ID", .flags = 0, },
{ .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
{ .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
{ .name = "FLAGS", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
{ .name = "CMINFLT", .title = " CMINFLT ", .description = "Children processes' minor faults", .flags = 0, },
{ .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
{ .name = "CMAJFLT", .title = " CMAJFLT ", .description = "Children processes' major faults", .flags = 0, },
{ .name = "UTIME", .title = " UTIME+ ", .description = "User CPU time - time the process spent executing in user mode", .flags = 0, },
{ .name = "STIME", .title = " STIME+ ", .description = "System CPU time - time the kernel spent running system calls for this process", .flags = 0, },
{ .name = "CUTIME", .title = " CUTIME+ ", .description = "Children processes' user CPU time", .flags = 0, },
{ .name = "CSTIME", .title = " CSTIME+ ", .description = "Children processes' system CPU time", .flags = 0, },
{ .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
{ .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
{ .name = "ITREALVALUE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
{ .name = "VSIZE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "RSS", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "RLIM", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "STARTCODE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "ENDCODE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "STARTSTACK", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "KSTKESP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "KSTKEIP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "SIGNAL", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "BLOCKED", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "SIGIGNORE", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "SIGCATCH", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "WCHAN", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "NSWAP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "CNSWAP", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "EXIT_SIGNAL", .title = NULL, .description = NULL, .flags = 0, },
{ .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
{ .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
{ .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
{ .name = "M_SHARE", .title = " SHR ", .description = "Size of the process's shared pages", .flags = 0, },
{ .name = "M_TRS", .title = " CODE ", .description = "Size of the text segment of the process", .flags = 0, },
{ .name = "M_DRS", .title = " DATA ", .description = "Size of the data segment plus stack usage of the process", .flags = 0, },
{ .name = "M_LRS", .title = " LIB ", .description = "The library size of the process", .flags = 0, },
{ .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process", .flags = 0, },
{ .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
{ .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
{ .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
{ .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
{ .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
{ .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
{ .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
#ifdef HAVE_OPENVZ
{ .name = "CTID", .title = " CTID ", .description = "OpenVZ container ID (a.k.a. virtual environment ID)", .flags = PROCESS_FLAG_LINUX_OPENVZ, },
{ .name = "VPID", .title = " VPID ", .description = "OpenVZ process ID", .flags = PROCESS_FLAG_LINUX_OPENVZ, },
#endif
#ifdef HAVE_VSERVER
{ .name = "VXID", .title = " VXID ", .description = "VServer process ID", .flags = PROCESS_FLAG_LINUX_VSERVER, },
#endif
#ifdef HAVE_TASKSTATS
{ .name = "RCHAR", .title = " RD_CHAR ", .description = "Number of bytes the process has read", .flags = PROCESS_FLAG_IO, },
{ .name = "WCHAR", .title = " WR_CHAR ", .description = "Number of bytes the process has written", .flags = PROCESS_FLAG_IO, },
{ .name = "SYSCR", .title = " RD_SYSC ", .description = "Number of read(2) syscalls for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "SYSCW", .title = " WR_SYSC ", .description = "Number of write(2) syscalls for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "RBYTES", .title = " IO_RBYTES ", .description = "Bytes of read(2) I/O for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "WBYTES", .title = " IO_WBYTES ", .description = "Bytes of write(2) I/O for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "CNCLWB", .title = " IO_CANCEL ", .description = "Bytes of cancelled write(2) I/O", .flags = PROCESS_FLAG_IO, },
{ .name = "IO_READ_RATE", .title = " DISK READ ", .description = "The I/O rate of read(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "IO_WRITE_RATE", .title = " DISK WRITE ", .description = "The I/O rate of write(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, },
{ .name = "IO_RATE", .title = " DISK R/W ", .description = "Total I/O rate in bytes per second", .flags = PROCESS_FLAG_IO, },
#endif
#ifdef HAVE_CGROUP
{ .name = "CGROUP", .title = " CGROUP ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_LINUX_CGROUP, },
#endif
#ifdef HAVE_OOM
{ .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = 0, },
#endif
{ .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, },
{ .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
};
char* Process_pidFormat = "%7u ";
char* Process_tpgidFormat = "%7u ";
void Process_setupColumnWidths() {
int maxPid = Platform_getMaxPid();
if (maxPid == -1) return;
if (maxPid > 99999) {
Process_fields[PID].title = " PID ";
Process_fields[PPID].title = " PPID ";
#ifdef HAVE_OPENVZ
Process_fields[VPID].title = " VPID ";
#endif
Process_fields[TPGID].title = " TPGID ";
Process_fields[TGID].title = " TGID ";
Process_fields[PGRP].title = " PGRP ";
Process_fields[SESSION].title = " SESN ";
#ifdef HAVE_OOM
Process_fields[OOM].title = " OOM ";
#endif
Process_pidFormat = "%7u ";
Process_tpgidFormat = "%7d ";
} else {
Process_fields[PID].title = " PID ";
Process_fields[PPID].title = " PPID ";
#ifdef HAVE_OPENVZ
Process_fields[VPID].title = " VPID ";
#endif
Process_fields[TPGID].title = "TPGID ";
Process_fields[TGID].title = " TGID ";
Process_fields[PGRP].title = " PGRP ";
Process_fields[SESSION].title = " SESN ";
#ifdef HAVE_OOM
Process_fields[OOM].title = " OOM ";
#endif
Process_pidFormat = "%5u ";
Process_tpgidFormat = "%5d ";
}
}
LinuxProcess* LinuxProcess_new(Settings* settings) {
LinuxProcess* this = calloc(sizeof(LinuxProcess), 1);
Object_setClass(this, Class(Process));
......
......@@ -10,6 +10,36 @@ in the source distribution for its full text.
*/
#define PROCESS_FLAG_LINUX_IOPRIO 0x0100
#define PROCESS_FLAG_LINUX_OPENVZ 0x0200
#define PROCESS_FLAG_LINUX_VSERVER 0x0400
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
typedef enum LinuxProcessFields {
PID = 1, COMM, STATE, PPID, PGRP, SESSION, TTY_NR, TPGID, FLAGS, MINFLT, CMINFLT, MAJFLT, CMAJFLT, UTIME,
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, TGID,
#ifdef HAVE_OPENVZ
CTID, VPID,
#endif
#ifdef HAVE_VSERVER
VXID,
#endif
#ifdef HAVE_TASKSTATS
RCHAR, WCHAR, SYSCR, SYSCW, RBYTES, WBYTES, CNCLWB, IO_READ_RATE, IO_WRITE_RATE, IO_RATE,
#endif
#ifdef HAVE_CGROUP
CGROUP,
#endif
#ifdef HAVE_OOM
OOM,
#endif
IO_PRIORITY,
LAST_PROCESSFIELD
} LinuxProcessField;
#include "IOPriority.h"
typedef struct LinuxProcess_ {
......@@ -20,6 +50,13 @@ typedef struct LinuxProcess_ {
#define Process_delete LinuxProcess_delete
extern ProcessFieldData Process_fields[];
extern char* Process_pidFormat;
extern char* Process_tpgidFormat;
void Process_setupColumnWidths();
LinuxProcess* LinuxProcess_new(Settings* settings);
void LinuxProcess_delete(Object* cast);
......
......@@ -122,7 +122,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
}
#ifdef HAVE_OPENVZ
this->flags |= PROCESS_FLAG_OPENVZ;
this->flags |= PROCESS_FLAG_LINUX_OPENVZ;
#endif
return pl;
......@@ -333,10 +333,10 @@ static bool LinuxProcessList_readStatmFile(Process* process, const char* dirname
#ifdef HAVE_OPENVZ
static void LinuxProcessList_readOpenVZData(ProcessList* this, Process* process, const char* dirname, const char* name) {
if ( (!(this->flags & PROCESS_FLAG_OPENVZ)) || (access("/proc/vz", R_OK) != 0)) {
if ( (!(this->flags & PROCESS_FLAG_LINUX_OPENVZ)) || (access("/proc/vz", R_OK) != 0)) {
process->vpid = process->pid;
process->ctid = 0;
this->flags |= ~PROCESS_FLAG_OPENVZ;
this->flags |= ~PROCESS_FLAG_LINUX_OPENVZ;
return;
}
char filename[MAX_NAME+1];
......@@ -546,7 +546,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
unsigned long long int lasttimes = (process->utime + process->stime);
if (! LinuxProcessList_readStatFile(process, dirname, name, command))
goto errorReadingProcess;
if (settings->flags & PROCESS_FLAG_IOPRIO)
if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO)
LinuxProcess_updateIOPriority((LinuxProcess*)process);
float percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0;
process->percent_cpu = MAX(MIN(percent_cpu, cpus*100.0), 0.0);
......@@ -565,7 +565,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
#endif
#ifdef HAVE_VSERVER
if (settings->flags & PROCESS_FLAG_VSERVER)
if (settings->flags & PROCESS_FLAG_LINUX_VSERVER)
LinuxProcessList_readVServerData(process, dirname, name);
#endif
......@@ -581,7 +581,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
}
#ifdef HAVE_CGROUP
if (settings->flags & PROCESS_FLAG_CGROUP)
if (settings->flags & PROCESS_FLAG_LINUX_CGROUP)
LinuxProcessList_readCGroupFile(process, dirname, name);
#endif
......
......@@ -30,8 +30,11 @@ in the source distribution for its full text.
#include "MainPanel.h"
#include "BatteryMeter.h"
#include "LinuxProcess.h"
}*/
int Platform_numberOfFields = LAST_PROCESSFIELD;
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
Panel* panel = st->panel;
......
......@@ -14,6 +14,9 @@ in the source distribution for its full text.
#include "BatteryMeter.h"
#include "LinuxProcess.h"
extern int Platform_numberOfFields;
void Platform_setBindings(Htop_Action* keys);
extern MeterClass* Platform_meterTypes[];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment