Commit 96b57ea8 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Merge pull request #10 from simpleigh/master

Added additional column to monitor OOM killer score of each process
parents 558b001e da236ca3
......@@ -81,6 +81,9 @@ typedef enum ProcessField_ {
#ifdef HAVE_CGROUP
CGROUP,
#endif
#ifdef HAVE_OOM
OOM,
#endif
IO_PRIORITY,
LAST_PROCESSFIELD
} ProcessField;
......@@ -177,6 +180,9 @@ typedef struct Process_ {
#ifdef HAVE_CGROUP
char* cgroup;
#endif
#ifdef HAVE_OOM
unsigned int oom;
#endif
} Process;
}*/
......@@ -202,6 +208,9 @@ const char *Process_fieldNames[] = {
#endif
#ifdef HAVE_CGROUP
"CGROUP",
#endif
#ifdef HAVE_OOM
"OOM",
#endif
"IO_PRIORITY",
"*** report bug! ***"
......@@ -228,6 +237,9 @@ const int Process_fieldFlags[] = {
#endif
#ifdef HAVE_CGROUP
PROCESS_FLAG_CGROUP,
#endif
#ifdef HAVE_OOM
0,
#endif
PROCESS_FLAG_IOPRIO
};
......@@ -253,6 +265,9 @@ const char *Process_fieldTitles[] = {
#endif
#ifdef HAVE_CGROUP
" CGROUP ",
#endif
#ifdef HAVE_OOM
" OOM ",
#endif
"IO ",
"*** report bug! ***"
......@@ -276,6 +291,9 @@ void Process_getMaxPid() {
Process_fieldTitles[TGID] = " TGID ";
Process_fieldTitles[PGRP] = " PGRP ";
Process_fieldTitles[SESSION] = " SESN ";
#ifdef HAVE_OOM
Process_fieldTitles[OOM] = " OOM ";
#endif
Process_pidFormat = "%7u ";
Process_tpgidFormat = "%7d ";
} else {
......@@ -285,6 +303,9 @@ void Process_getMaxPid() {
Process_fieldTitles[TGID] = " TGID ";
Process_fieldTitles[PGRP] = " PGRP ";
Process_fieldTitles[SESSION] = " SESN ";
#ifdef HAVE_OOM
Process_fieldTitles[OOM] = " OOM ";
#endif
Process_pidFormat = "%5u ";
Process_tpgidFormat = "%5d ";
}
......@@ -545,6 +566,9 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
#ifdef HAVE_CGROUP
case CGROUP: snprintf(buffer, n, "%-10s ", this->cgroup); break;
#endif
#ifdef HAVE_OOM
case OOM: snprintf(buffer, n, Process_pidFormat, this->oom); break;
#endif
case IO_PRIORITY: {
int klass = IOPriority_class(this->ioPriority);
if (klass == IOPRIO_CLASS_NONE) {
......@@ -814,6 +838,10 @@ int Process_compare(const void* v1, const void* v2) {
case CGROUP:
return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : "");
#endif
#ifdef HAVE_OOM
case OOM:
return (p1->oom - p2->oom);
#endif
case IO_PRIORITY:
return Process_effectiveIOPriority(p1) - Process_effectiveIOPriority(p2);
default:
......
......@@ -60,6 +60,9 @@ typedef enum ProcessField_ {
#ifdef HAVE_CGROUP
CGROUP,
#endif
#ifdef HAVE_OOM
OOM,
#endif
IO_PRIORITY,
LAST_PROCESSFIELD
} ProcessField;
......@@ -156,6 +159,9 @@ typedef struct Process_ {
#ifdef HAVE_CGROUP
char* cgroup;
#endif
#ifdef HAVE_OOM
unsigned int oom;
#endif
} Process;
......
......@@ -660,6 +660,28 @@ static void ProcessList_readVServerData(Process* process, const char* dirname, c
#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) {
if (Process_isKernelThread(process))
return true;
......@@ -784,6 +806,10 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
ProcessList_readVServerData(process, dirname, name);
#endif
#ifdef HAVE_OOM
ProcessList_readOomData(process, dirname, name);
#endif
if (! ProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess;
......
......@@ -172,6 +172,10 @@ void ProcessList_sort(ProcessList* this);
#endif
#ifdef HAVE_OOM
#endif
void ProcessList_scan(ProcessList* this);
......
......@@ -145,5 +145,10 @@ then
AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"])
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_OUTPUT
......@@ -313,6 +313,9 @@ OpenVZ process ID.
.B VXID
VServer process ID.
.TP
.B OOM
OOM killer score.
.TP
.B All other flags
Currently unsupported (always displays '-').
......
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