mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-14 13:04:35 +03:00
Add columns for process autogroup identifier and nice value
Adds AGRP (autogroup) and ANI (autogroup nice) columns that report the information from /proc/PID/autogroup, as well as handlers for '{' and '}' to change the autogroup nice value. This is guarded by /proc/sys/kernel/sched_autogroup_enabled such that sampling and/or changing values wont be attempted unless the kernel feature is enabled. Fixes: #720
This commit is contained in:
@ -82,6 +82,8 @@ const ProcessFieldData Process_fields[] = {
|
||||
[PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process", .flags = 0, },
|
||||
[PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process", .flags = 0, },
|
||||
[CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, },
|
||||
[AUTOGROUP_ID] = { .name = "AUTOGROUP_ID", .title = "AGRP", .description = "The autogroup identifier of the process", .flags = PROCESS_FLAG_LINUX_AUTOGROUP, },
|
||||
[AUTOGROUP_NICE] = { .name = "AUTOGROUP_NICE", .title = " ANI", .description = "Nice value (the higher the value, the more other processes take priority) associated with the process autogroup", .flags = PROCESS_FLAG_LINUX_AUTOGROUP, },
|
||||
};
|
||||
|
||||
Process* PCPProcess_new(const Settings* settings) {
|
||||
@ -168,6 +170,25 @@ static void PCPProcess_writeField(const Process* this, RichString* str, ProcessF
|
||||
xSnprintf(buffer, n, "%5lu ", pp->ctxt_diff);
|
||||
break;
|
||||
case SECATTR: snprintf(buffer, n, "%-30s ", pp->secattr ? pp->secattr : "?"); break;
|
||||
case AUTOGROUP_ID:
|
||||
if (pp->autogroup_id != -1) {
|
||||
xSnprintf(buffer, n, "%4ld ", pp->autogroup_id);
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
xSnprintf(buffer, n, " N/A ");
|
||||
}
|
||||
break;
|
||||
case AUTOGROUP_NICE:
|
||||
if (pp->autogroup_id != -1) {
|
||||
xSnprintf(buffer, n, "%3d ", pp->autogroup_nice);
|
||||
attr = pp->autogroup_nice < 0 ? CRT_colors[PROCESS_HIGH_PRIORITY]
|
||||
: pp->autogroup_nice > 0 ? CRT_colors[PROCESS_LOW_PRIORITY]
|
||||
: CRT_colors[PROCESS_SHADOW];
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
xSnprintf(buffer, n, "N/A ");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Process_writeField(this, str, field);
|
||||
return;
|
||||
@ -245,6 +266,10 @@ static int PCPProcess_compareByKey(const Process* v1, const Process* v2, Process
|
||||
return SPACESHIP_NUMBER(p1->ctxt_diff, p2->ctxt_diff);
|
||||
case SECATTR:
|
||||
return SPACESHIP_NULLSTR(p1->secattr, p2->secattr);
|
||||
case AUTOGROUP_ID:
|
||||
return SPACESHIP_NUMBER(p1->autogroup_id, p2->autogroup_id);
|
||||
case AUTOGROUP_NICE:
|
||||
return SPACESHIP_NUMBER(p1->autogroup_nice, p2->autogroup_nice);
|
||||
default:
|
||||
return Process_compareByKey_Base(v1, v2, key);
|
||||
}
|
||||
|
@ -20,11 +20,12 @@ in the source distribution for its full text.
|
||||
#include "Settings.h"
|
||||
|
||||
|
||||
#define PROCESS_FLAG_LINUX_CGROUP 0x0800
|
||||
#define PROCESS_FLAG_LINUX_OOM 0x1000
|
||||
#define PROCESS_FLAG_LINUX_SMAPS 0x2000
|
||||
#define PROCESS_FLAG_LINUX_CTXT 0x4000
|
||||
#define PROCESS_FLAG_LINUX_SECATTR 0x8000
|
||||
#define PROCESS_FLAG_LINUX_CGROUP 0x00000800
|
||||
#define PROCESS_FLAG_LINUX_OOM 0x00001000
|
||||
#define PROCESS_FLAG_LINUX_SMAPS 0x00002000
|
||||
#define PROCESS_FLAG_LINUX_CTXT 0x00004000
|
||||
#define PROCESS_FLAG_LINUX_SECATTR 0x00008000
|
||||
#define PROCESS_FLAG_LINUX_AUTOGROUP 0x00080000
|
||||
|
||||
typedef struct PCPProcess_ {
|
||||
Process super;
|
||||
@ -70,6 +71,8 @@ typedef struct PCPProcess_ {
|
||||
double io_rate_read_bps;
|
||||
double io_rate_write_bps;
|
||||
char* cgroup;
|
||||
long int autogroup_id;
|
||||
int autogroup_nice;
|
||||
unsigned int oom;
|
||||
unsigned long long int delay_read_time;
|
||||
unsigned long long cpu_delay_total;
|
||||
|
@ -89,13 +89,20 @@ void ProcessList_delete(ProcessList* pl) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
static inline unsigned long Metric_instance_s32(int metric, int pid, int offset, unsigned long fallback) {
|
||||
static inline long Metric_instance_s32(int metric, int pid, int offset, long fallback) {
|
||||
pmAtomValue value;
|
||||
if (Metric_instance(metric, pid, offset, &value, PM_TYPE_32))
|
||||
return value.l;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static inline long long Metric_instance_s64(int metric, int pid, int offset, long long fallback) {
|
||||
pmAtomValue value;
|
||||
if (Metric_instance(metric, pid, offset, &value, PM_TYPE_64))
|
||||
return value.l;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static inline unsigned long Metric_instance_u32(int metric, int pid, int offset, unsigned long fallback) {
|
||||
pmAtomValue value;
|
||||
if (Metric_instance(metric, pid, offset, &value, PM_TYPE_U32))
|
||||
@ -222,6 +229,11 @@ static void PCPProcessList_readOomData(PCPProcess* pp, int pid, int offset) {
|
||||
pp->oom = Metric_instance_u32(PCP_PROC_OOMSCORE, pid, offset, 0);
|
||||
}
|
||||
|
||||
static void PCPProcessList_readAutogroup(PCPProcess* pp, int pid, int offset) {
|
||||
pp->autogroup_id = Metric_instance_s64(PCP_PROC_AUTOGROUP_ID, pid, offset, -1);
|
||||
pp->autogroup_nice = Metric_instance_s32(PCP_PROC_AUTOGROUP_NICE, pid, offset, 0);
|
||||
}
|
||||
|
||||
static void PCPProcessList_readCtxtData(PCPProcess* pp, int pid, int offset) {
|
||||
pmAtomValue value;
|
||||
unsigned long ctxt = 0;
|
||||
@ -403,6 +415,9 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period,
|
||||
if (settings->flags & PROCESS_FLAG_CWD)
|
||||
PCPProcessList_readCwd(pp, pid, offset);
|
||||
|
||||
if (settings->flags & PROCESS_FLAG_LINUX_AUTOGROUP)
|
||||
PCPProcessList_readAutogroup(pp, pid, offset);
|
||||
|
||||
if (proc->state == 'Z' && !proc->cmdline && command[0]) {
|
||||
Process_updateCmdline(proc, command, 0, strlen(command));
|
||||
} else if (Process_isThread(proc)) {
|
||||
@ -651,6 +666,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
|
||||
Metric_enable(PCP_PROC_NVCTXSW, flagged && enabled);
|
||||
flagged = settings->flags & PROCESS_FLAG_LINUX_SECATTR;
|
||||
Metric_enable(PCP_PROC_LABELS, flagged && enabled);
|
||||
flagged = settings->flags & PROCESS_FLAG_LINUX_AUTOGROUP;
|
||||
Metric_enable(PCP_PROC_AUTOGROUP_ID, flagged && enabled);
|
||||
Metric_enable(PCP_PROC_AUTOGROUP_NICE, flagged && enabled);
|
||||
|
||||
/* Sample smaps metrics on every second pass to improve performance */
|
||||
static int smaps_flag;
|
||||
|
@ -224,6 +224,8 @@ static const char* Platform_metricNames[] = {
|
||||
[PCP_PROC_TTYNAME] = "proc.psinfo.ttyname",
|
||||
[PCP_PROC_EXE] = "proc.psinfo.exe",
|
||||
[PCP_PROC_CWD] = "proc.psinfo.cwd",
|
||||
[PCP_PROC_AUTOGROUP_ID] = "proc.autogroup.id",
|
||||
[PCP_PROC_AUTOGROUP_NICE] = "proc.autogroup.nice",
|
||||
[PCP_PROC_ID_UID] = "proc.id.uid",
|
||||
[PCP_PROC_ID_USER] = "proc.id.uid_nm",
|
||||
[PCP_PROC_IO_RCHAR] = "proc.io.rchar",
|
||||
|
@ -210,6 +210,9 @@ typedef enum Metric_ {
|
||||
PCP_PROC_EXE, /* proc.psinfo.exe */
|
||||
PCP_PROC_CWD, /* proc.psinfo.cwd */
|
||||
|
||||
PCP_PROC_AUTOGROUP_ID, /* proc.autogroup.id */
|
||||
PCP_PROC_AUTOGROUP_NICE, /* proc.autogroup.nice */
|
||||
|
||||
PCP_PROC_ID_UID, /* proc.id.uid */
|
||||
PCP_PROC_ID_USER, /* proc.id.uid_nm */
|
||||
|
||||
|
@ -43,8 +43,8 @@ in the source distribution for its full text.
|
||||
M_PSSWP = 121, \
|
||||
CTXT = 122, \
|
||||
SECATTR = 123, \
|
||||
\
|
||||
DUMMY_BUMP_FIELD = CWD, \
|
||||
AUTOGROUP_ID = 127, \
|
||||
AUTOGROUP_NICE = 128, \
|
||||
// End of list
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user