mirror of https://github.com/xzeldon/htop.git
Merge pull request #10 from simpleigh/master
Added additional column to monitor OOM killer score of each process
This commit is contained in:
commit
96b57ea812
28
Process.c
28
Process.c
|
@ -81,6 +81,9 @@ typedef enum ProcessField_ {
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
CGROUP,
|
CGROUP,
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
OOM,
|
||||||
|
#endif
|
||||||
IO_PRIORITY,
|
IO_PRIORITY,
|
||||||
LAST_PROCESSFIELD
|
LAST_PROCESSFIELD
|
||||||
} ProcessField;
|
} ProcessField;
|
||||||
|
@ -177,6 +180,9 @@ typedef struct Process_ {
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
char* cgroup;
|
char* cgroup;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
unsigned int oom;
|
||||||
|
#endif
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
@ -202,6 +208,9 @@ const char *Process_fieldNames[] = {
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
"CGROUP",
|
"CGROUP",
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
"OOM",
|
||||||
#endif
|
#endif
|
||||||
"IO_PRIORITY",
|
"IO_PRIORITY",
|
||||||
"*** report bug! ***"
|
"*** report bug! ***"
|
||||||
|
@ -228,6 +237,9 @@ const int Process_fieldFlags[] = {
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
PROCESS_FLAG_CGROUP,
|
PROCESS_FLAG_CGROUP,
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
0,
|
||||||
#endif
|
#endif
|
||||||
PROCESS_FLAG_IOPRIO
|
PROCESS_FLAG_IOPRIO
|
||||||
};
|
};
|
||||||
|
@ -253,6 +265,9 @@ const char *Process_fieldTitles[] = {
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
" CGROUP ",
|
" CGROUP ",
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
" OOM ",
|
||||||
#endif
|
#endif
|
||||||
"IO ",
|
"IO ",
|
||||||
"*** report bug! ***"
|
"*** report bug! ***"
|
||||||
|
@ -276,6 +291,9 @@ void Process_getMaxPid() {
|
||||||
Process_fieldTitles[TGID] = " TGID ";
|
Process_fieldTitles[TGID] = " TGID ";
|
||||||
Process_fieldTitles[PGRP] = " PGRP ";
|
Process_fieldTitles[PGRP] = " PGRP ";
|
||||||
Process_fieldTitles[SESSION] = " SESN ";
|
Process_fieldTitles[SESSION] = " SESN ";
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
Process_fieldTitles[OOM] = " OOM ";
|
||||||
|
#endif
|
||||||
Process_pidFormat = "%7u ";
|
Process_pidFormat = "%7u ";
|
||||||
Process_tpgidFormat = "%7d ";
|
Process_tpgidFormat = "%7d ";
|
||||||
} else {
|
} else {
|
||||||
|
@ -285,6 +303,9 @@ void Process_getMaxPid() {
|
||||||
Process_fieldTitles[TGID] = " TGID ";
|
Process_fieldTitles[TGID] = " TGID ";
|
||||||
Process_fieldTitles[PGRP] = " PGRP ";
|
Process_fieldTitles[PGRP] = " PGRP ";
|
||||||
Process_fieldTitles[SESSION] = " SESN ";
|
Process_fieldTitles[SESSION] = " SESN ";
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
Process_fieldTitles[OOM] = " OOM ";
|
||||||
|
#endif
|
||||||
Process_pidFormat = "%5u ";
|
Process_pidFormat = "%5u ";
|
||||||
Process_tpgidFormat = "%5d ";
|
Process_tpgidFormat = "%5d ";
|
||||||
}
|
}
|
||||||
|
@ -545,6 +566,9 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
case CGROUP: snprintf(buffer, n, "%-10s ", this->cgroup); break;
|
case CGROUP: snprintf(buffer, n, "%-10s ", this->cgroup); break;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
case OOM: snprintf(buffer, n, Process_pidFormat, this->oom); break;
|
||||||
|
#endif
|
||||||
case IO_PRIORITY: {
|
case IO_PRIORITY: {
|
||||||
int klass = IOPriority_class(this->ioPriority);
|
int klass = IOPriority_class(this->ioPriority);
|
||||||
if (klass == IOPRIO_CLASS_NONE) {
|
if (klass == IOPRIO_CLASS_NONE) {
|
||||||
|
@ -814,6 +838,10 @@ int Process_compare(const void* v1, const void* v2) {
|
||||||
case CGROUP:
|
case CGROUP:
|
||||||
return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : "");
|
return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : "");
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
case OOM:
|
||||||
|
return (p1->oom - p2->oom);
|
||||||
|
#endif
|
||||||
case IO_PRIORITY:
|
case IO_PRIORITY:
|
||||||
return Process_effectiveIOPriority(p1) - Process_effectiveIOPriority(p2);
|
return Process_effectiveIOPriority(p1) - Process_effectiveIOPriority(p2);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -60,6 +60,9 @@ typedef enum ProcessField_ {
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
CGROUP,
|
CGROUP,
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
OOM,
|
||||||
|
#endif
|
||||||
IO_PRIORITY,
|
IO_PRIORITY,
|
||||||
LAST_PROCESSFIELD
|
LAST_PROCESSFIELD
|
||||||
} ProcessField;
|
} ProcessField;
|
||||||
|
@ -156,6 +159,9 @@ typedef struct Process_ {
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
char* cgroup;
|
char* cgroup;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
unsigned int oom;
|
||||||
|
#endif
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -660,6 +660,28 @@ static void ProcessList_readVServerData(Process* process, const char* dirname, c
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
|
||||||
|
static void ProcessList_readOomData(Process* process, const char* dirname, const char* name) {
|
||||||
|
char filename[MAX_NAME+1];
|
||||||
|
snprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name);
|
||||||
|
FILE* file = fopen(filename, "r");
|
||||||
|
if (!file)
|
||||||
|
return;
|
||||||
|
char buffer[256];
|
||||||
|
if (!fgets(buffer, 255, file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsigned int oom;
|
||||||
|
int ok = sscanf(buffer, "%u", &oom);
|
||||||
|
if (ok >= 1) {
|
||||||
|
process->oom = oom;
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
||||||
if (Process_isKernelThread(process))
|
if (Process_isKernelThread(process))
|
||||||
return true;
|
return true;
|
||||||
|
@ -784,6 +806,10 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
|
||||||
ProcessList_readVServerData(process, dirname, name);
|
ProcessList_readVServerData(process, dirname, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
ProcessList_readOomData(process, dirname, name);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (! ProcessList_readCmdlineFile(process, dirname, name))
|
if (! ProcessList_readCmdlineFile(process, dirname, name))
|
||||||
goto errorReadingProcess;
|
goto errorReadingProcess;
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,10 @@ void ProcessList_sort(ProcessList* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_OOM
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ProcessList_scan(ProcessList* this);
|
void ProcessList_scan(ProcessList* this);
|
||||||
|
|
||||||
|
|
|
@ -145,5 +145,10 @@ then
|
||||||
AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"])
|
AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(oom, [AC_HELP_STRING([--enable-oom], [enable OOM score reporting])], ,enable_oom="no")
|
||||||
|
if test "x$enable_oom" = xyes; then
|
||||||
|
AC_DEFINE(HAVE_OOM, 1, [Define if OOM score support enabled.])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile htop.1])
|
AC_CONFIG_FILES([Makefile htop.1])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
Loading…
Reference in New Issue