Commit 3383d8e5 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Sorry about the mega-patch.

This is a work-in-progress, code is currently broken.
(Some actions, and notably, the header, are missing.)
parent 36b78328
...@@ -7,7 +7,7 @@ in the source distribution for its full text. ...@@ -7,7 +7,7 @@ in the source distribution for its full text.
#include "TasksMeter.h" #include "TasksMeter.h"
#include "ProcessList.h" #include "Platform.h"
#include "CRT.h" #include "CRT.h"
/*{ /*{
...@@ -15,42 +15,43 @@ in the source distribution for its full text. ...@@ -15,42 +15,43 @@ in the source distribution for its full text.
}*/ }*/
int TasksMeter_attributes[] = { int TasksMeter_attributes[] = {
TASKS_RUNNING CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING
}; };
static void TasksMeter_setValues(Meter* this, char* buffer, int len) { static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
ProcessList* pl = this->pl; Platform_setTasksValues(this);
this->total = pl->totalTasks;
this->values[0] = pl->runningTasks;
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total); snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
} }
static void TasksMeter_display(Object* cast, RichString* out) { static void TasksMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
ProcessList* pl = this->pl; Settings* settings = this->pl->settings;
char buffer[20]; char buffer[20];
sprintf(buffer, "%d", (int)(this->total - pl->userlandThreads - pl->kernelThreads));
int processes = (int) this->values[2];
sprintf(buffer, "%d", processes);
RichString_write(out, CRT_colors[METER_VALUE], buffer); RichString_write(out, CRT_colors[METER_VALUE], buffer);
int threadValueColor = CRT_colors[METER_VALUE]; int threadValueColor = CRT_colors[METER_VALUE];
int threadCaptionColor = CRT_colors[METER_TEXT]; int threadCaptionColor = CRT_colors[METER_TEXT];
if (pl->highlightThreads) { if (settings->highlightThreads) {
threadValueColor = CRT_colors[PROCESS_THREAD_BASENAME]; threadValueColor = CRT_colors[PROCESS_THREAD_BASENAME];
threadCaptionColor = CRT_colors[PROCESS_THREAD]; threadCaptionColor = CRT_colors[PROCESS_THREAD];
} }
if (!pl->hideUserlandThreads) { if (!settings->hideUserlandThreads) {
RichString_append(out, CRT_colors[METER_TEXT], ", "); RichString_append(out, CRT_colors[METER_TEXT], ", ");
sprintf(buffer, "%d", (int)pl->userlandThreads); sprintf(buffer, "%d", (int)this->values[1]);
RichString_append(out, threadValueColor, buffer); RichString_append(out, threadValueColor, buffer);
RichString_append(out, threadCaptionColor, " thr"); RichString_append(out, threadCaptionColor, " thr");
} }
if (!pl->hideKernelThreads) { if (!settings->hideKernelThreads) {
RichString_append(out, CRT_colors[METER_TEXT], ", "); RichString_append(out, CRT_colors[METER_TEXT], ", ");
sprintf(buffer, "%d", (int)pl->kernelThreads); sprintf(buffer, "%d", (int)this->values[0]);
RichString_append(out, threadValueColor, buffer); RichString_append(out, threadValueColor, buffer);
RichString_append(out, threadCaptionColor, " kthr"); RichString_append(out, threadCaptionColor, " kthr");
} }
RichString_append(out, CRT_colors[METER_TEXT], "; "); RichString_append(out, CRT_colors[METER_TEXT], "; ");
sprintf(buffer, "%d", (int)this->values[0]); sprintf(buffer, "%d", (int)this->values[3]);
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer); RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " running"); RichString_append(out, CRT_colors[METER_TEXT], " running");
} }
...@@ -64,6 +65,7 @@ MeterClass TasksMeter_class = { ...@@ -64,6 +65,7 @@ MeterClass TasksMeter_class = {
.setValues = TasksMeter_setValues, .setValues = TasksMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.total = 100.0, .total = 100.0,
.maxItems = 4,
.attributes = TasksMeter_attributes, .attributes = TasksMeter_attributes,
.name = "Tasks", .name = "Tasks",
.uiName = "Task counter", .uiName = "Task counter",
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
AC_PREREQ(2.65) AC_PREREQ(2.65)
AC_INIT([htop],[1.0.3],[hisham@gobolinux.org]) AC_INIT([htop],[1.0.3],[hisham@gobolinux.org])
year=$(date +%Y)
# The following two lines are required by hwloc scripts # The following two lines are required by hwloc scripts
AC_USE_SYSTEM_EXTENSIONS AC_USE_SYSTEM_EXTENSIONS
AC_CANONICAL_TARGET AC_CANONICAL_TARGET
...@@ -180,6 +182,8 @@ if test ! -z "$missing_headers"; then ...@@ -180,6 +182,8 @@ if test ! -z "$missing_headers"; then
AC_MSG_ERROR([missing headers: $missing_headers]) AC_MSG_ERROR([missing headers: $missing_headers])
fi fi
AC_DEFINE_UNQUOTED(COPYRIGHT, "(C) 2004-$year Hisham Muhammad", [Copyright message.])
# We're done, let's go! # We're done, let's go!
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux]) AM_CONDITIONAL([HTOP_LINUX], [test "$my_htop_platform" = linux])
......
This diff is collapsed.
...@@ -11,11 +11,8 @@ in the source distribution for its full text. ...@@ -11,11 +11,8 @@ in the source distribution for its full text.
//#link m //#link m
#define COPYRIGHT "(C) 2004-2014 Hisham Muhammad"
// ---------------------------------------- // ----------------------------------------
// ----------------------------------------
int main(int argc, char** argv); int main(int argc, char** argv);
......
...@@ -45,22 +45,23 @@ bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) { ...@@ -45,22 +45,23 @@ bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) {
return (LinuxProcess_updateIOPriority(this) == ioprio); return (LinuxProcess_updateIOPriority(this) == ioprio);
} }
void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField field) { void Process_writeField(Process* this, RichString* str, ProcessField field) {
LinuxProcess* lp = (LinuxProcess*) this;
char buffer[256]; buffer[255] = '\0'; char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR]; int attr = CRT_colors[DEFAULT_COLOR];
int n = sizeof(buffer) - 1; int n = sizeof(buffer) - 1;
switch (field) { switch (field) {
case IO_PRIORITY: { case IO_PRIORITY: {
int klass = IOPriority_class(this->ioPriority); int klass = IOPriority_class(lp->ioPriority);
if (klass == IOPRIO_CLASS_NONE) { if (klass == IOPRIO_CLASS_NONE) {
// see note [1] above // see note [1] above
snprintf(buffer, n, "B%1d ", (int) (this->super.nice + 20) / 5); snprintf(buffer, n, "B%1d ", (int) (this->nice + 20) / 5);
} else if (klass == IOPRIO_CLASS_BE) { } else if (klass == IOPRIO_CLASS_BE) {
snprintf(buffer, n, "B%1d ", IOPriority_data(this->ioPriority)); snprintf(buffer, n, "B%1d ", IOPriority_data(lp->ioPriority));
} else if (klass == IOPRIO_CLASS_RT) { } else if (klass == IOPRIO_CLASS_RT) {
attr = CRT_colors[PROCESS_HIGH_PRIORITY]; attr = CRT_colors[PROCESS_HIGH_PRIORITY];
snprintf(buffer, n, "R%1d ", IOPriority_data(this->ioPriority)); snprintf(buffer, n, "R%1d ", IOPriority_data(lp->ioPriority));
} else if (this->ioPriority == IOPriority_Idle) { } else if (lp->ioPriority == IOPriority_Idle) {
attr = CRT_colors[PROCESS_LOW_PRIORITY]; attr = CRT_colors[PROCESS_LOW_PRIORITY];
snprintf(buffer, n, "id "); snprintf(buffer, n, "id ");
} else { } else {
...@@ -69,25 +70,26 @@ void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField f ...@@ -69,25 +70,26 @@ void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField f
break; break;
} }
default: default:
snprintf(buffer, n, "- "); Process_writeDefaultField(this, str, field);
return;
} }
RichString_append(str, attr, buffer); RichString_append(str, attr, buffer);
} }
long LinuxProcess_compare(const void* v1, const void* v2) { long Process_compare(const void* v1, const void* v2) {
LinuxProcess *p1, *p2; LinuxProcess *p1, *p2;
ProcessList *pl = ((Process*)v1)->pl; Settings *settings = ((Process*)v1)->settings;
if (pl->direction == 1) { if (settings->direction == 1) {
p1 = (LinuxProcess*)v1; p1 = (LinuxProcess*)v1;
p2 = (LinuxProcess*)v2; p2 = (LinuxProcess*)v2;
} else { } else {
p2 = (LinuxProcess*)v1; p2 = (LinuxProcess*)v1;
p1 = (LinuxProcess*)v2; p1 = (LinuxProcess*)v2;
} }
switch (pl->sortKey) { switch (settings->sortKey) {
case IO_PRIORITY: case IO_PRIORITY:
return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2); return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2);
default: default:
return (p1->super.pid - p2->super.pid); return Process_defaultCompare(v1, v2);
} }
} }
...@@ -32,8 +32,8 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); ...@@ -32,8 +32,8 @@ IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this);
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio); bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio);
void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField field); void Process_writeField(Process* this, RichString* str, ProcessField field);
long LinuxProcess_compare(const void* v1, const void* v2); long Process_compare(const void* v1, const void* v2);
#endif #endif
...@@ -31,6 +31,56 @@ in the source distribution for its full text. ...@@ -31,6 +31,56 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int userTime;
unsigned long long int systemTime;
unsigned long long int systemAllTime;
unsigned long long int idleAllTime;
unsigned long long int idleTime;
unsigned long long int niceTime;
unsigned long long int ioWaitTime;
unsigned long long int irqTime;
unsigned long long int softIrqTime;
unsigned long long int stealTime;
unsigned long long int guestTime;
unsigned long long int totalPeriod;
unsigned long long int userPeriod;
unsigned long long int systemPeriod;
unsigned long long int systemAllPeriod;
unsigned long long int idleAllPeriod;
unsigned long long int idlePeriod;
unsigned long long int nicePeriod;
unsigned long long int ioWaitPeriod;
unsigned long long int irqPeriod;
unsigned long long int softIrqPeriod;
unsigned long long int stealPeriod;
unsigned long long int guestPeriod;
} CPUData;
typedef struct LinuxProcessList_ {
ProcessList super;
int totalTasks;
int userlandThreads;
int kernelThreads;
int runningTasks;
CPUData* cpus;
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
} LinuxProcessList;
#ifndef PROCDIR #ifndef PROCDIR
#define PROCDIR "/proc" #define PROCDIR "/proc"
#endif #endif
...@@ -45,9 +95,10 @@ in the source distribution for its full text. ...@@ -45,9 +95,10 @@ in the source distribution for its full text.
}*/ }*/
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
ProcessList* this = calloc(1, sizeof(ProcessList)); LinuxProcessList* this = calloc(1, sizeof(LinuxProcessList));
ProcessList_init(this, usersTable, pidWhiteList); ProcessList* pl = &(this->super);
ProcessList_init(pl, usersTable, pidWhiteList, userId);
// Update CPU count: // Update CPU count:
FILE* file = fopen(PROCSTATFILE, "r"); FILE* file = fopen(PROCSTATFILE, "r");
...@@ -62,7 +113,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { ...@@ -62,7 +113,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
} while (String_startsWith(buffer, "cpu")); } while (String_startsWith(buffer, "cpu"));
fclose(file); fclose(file);
this->cpuCount = MAX(cpus - 1, 1); pl->cpuCount = MAX(cpus - 1, 1);
this->cpus = calloc(cpus, sizeof(CPUData)); this->cpus = calloc(cpus, sizeof(CPUData));
for (int i = 0; i < cpus; i++) { for (int i = 0; i < cpus; i++) {
...@@ -74,11 +125,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { ...@@ -74,11 +125,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
this->flags |= PROCESS_FLAG_OPENVZ; this->flags |= PROCESS_FLAG_OPENVZ;
#endif #endif
return this; return pl;
} }
void ProcessList_delete(ProcessList* this) { void ProcessList_delete(ProcessList* pl) {
ProcessList_done(this); LinuxProcessList* this = (LinuxProcessList*) pl;
ProcessList_done(pl);
free(this->cpus);
free(this); free(this);
} }
...@@ -166,7 +219,6 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, ...@@ -166,7 +219,6 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
location += 1; location += 1;
assert(location != NULL); assert(location != NULL);
process->processor = strtol(location, &location, 10); process->processor = strtol(location, &location, 10);
assert(location == NULL);
return true; return true;
} }
...@@ -200,8 +252,11 @@ static void LinuxProcessList_readIoFile(Process* process, const char* dirname, c ...@@ -200,8 +252,11 @@ static void LinuxProcessList_readIoFile(Process* process, const char* dirname, c
snprintf(filename, MAX_NAME, "%s/%s/io", dirname, name); snprintf(filename, MAX_NAME, "%s/%s/io", dirname, name);
int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY);
if (fd == -1) if (fd == -1) {
process->io_rate_read_bps = -1;
process->io_rate_write_bps = -1;
return; return;
}
char buffer[1024]; char buffer[1024];
ssize_t buflen = xread(fd, buffer, 1023); ssize_t buflen = xread(fd, buffer, 1023);
...@@ -420,9 +475,10 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna ...@@ -420,9 +475,10 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
return true; return true;
} }
static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) { static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) {
DIR* dir; DIR* dir;
struct dirent* entry; struct dirent* entry;
Settings* settings = this->super.settings;
time_t curTime = tv.tv_sec; time_t curTime = tv.tv_sec;
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
...@@ -431,15 +487,15 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -431,15 +487,15 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
dir = opendir(dirname); dir = opendir(dirname);
if (!dir) return false; if (!dir) return false;
int cpus = this->cpuCount; int cpus = this->super.cpuCount;
bool hideKernelThreads = this->hideKernelThreads; bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = this->hideUserlandThreads; bool hideUserlandThreads = settings->hideUserlandThreads;
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
char* name = entry->d_name; char* name = entry->d_name;
// The RedHat kernel hides threads with a dot. // The RedHat kernel hides threads with a dot.
// I believe this is non-standard. // I believe this is non-standard.
if ((!this->hideThreads) && name[0] == '.') { if ((!settings->hideThreads) && name[0] == '.') {
name++; name++;
} }
...@@ -458,14 +514,14 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -458,14 +514,14 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
continue; continue;
Process* process = NULL; Process* process = NULL;
Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid); Process* existingProcess = (Process*) Hashtable_get(this->super.processTable, pid);
if (existingProcess) { if (existingProcess) {
assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1); assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1);
process = existingProcess; process = existingProcess;
assert(process->pid == pid); assert(process->pid == pid);
} else { } else {
process = Process_new(this); process = Process_new(settings);
assert(process->comm == NULL); assert(process->comm == NULL);
process->pid = pid; process->pid = pid;
process->tgid = parent ? parent->pid : pid; process->tgid = parent ? parent->pid : pid;
...@@ -476,7 +532,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -476,7 +532,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
LinuxProcessList_processEntries(this, subdirname, process, period, tv); LinuxProcessList_processEntries(this, subdirname, process, period, tv);
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
if (this->flags & PROCESS_FLAG_IO) if (settings->flags & PROCESS_FLAG_IO)
LinuxProcessList_readIoFile(process, dirname, name, now); LinuxProcessList_readIoFile(process, dirname, name, now);
#endif #endif
...@@ -489,7 +545,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -489,7 +545,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
unsigned long long int lasttimes = (process->utime + process->stime); unsigned long long int lasttimes = (process->utime + process->stime);
if (! LinuxProcessList_readStatFile(process, dirname, name, command)) if (! LinuxProcessList_readStatFile(process, dirname, name, command))
goto errorReadingProcess; goto errorReadingProcess;
if (this->flags & PROCESS_FLAG_IOPRIO) if (settings->flags & PROCESS_FLAG_IOPRIO)
LinuxProcess_updateIOPriority((LinuxProcess*)process); LinuxProcess_updateIOPriority((LinuxProcess*)process);
float percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0; float percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0;
process->percent_cpu = MAX(MIN(percent_cpu, cpus*100.0), 0.0); process->percent_cpu = MAX(MIN(percent_cpu, cpus*100.0), 0.0);
...@@ -501,30 +557,30 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -501,30 +557,30 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
if (! LinuxProcessList_statProcessDir(process, dirname, name, curTime)) if (! LinuxProcessList_statProcessDir(process, dirname, name, curTime))
goto errorReadingProcess; goto errorReadingProcess;
process->user = UsersTable_getRef(this->usersTable, process->st_uid); process->user = UsersTable_getRef(this->super.usersTable, process->st_uid);
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
LinuxProcessList_readOpenVZData(this, process, dirname, name); LinuxProcessList_readOpenVZData(this, process, dirname, name);
#endif #endif
#ifdef HAVE_VSERVER #ifdef HAVE_VSERVER
if (this->flags & PROCESS_FLAG_VSERVER) if (settings->flags & PROCESS_FLAG_VSERVER)
LinuxProcessList_readVServerData(process, dirname, name); LinuxProcessList_readVServerData(process, dirname, name);
#endif #endif
if (! LinuxProcessList_readCmdlineFile(process, dirname, name)) if (! LinuxProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
ProcessList_add(this, process); ProcessList_add((ProcessList*)this, process);
} else { } else {
if (this->updateProcessNames) { if (settings->updateProcessNames) {
if (! LinuxProcessList_readCmdlineFile(process, dirname, name)) if (! LinuxProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
} }
} }
#ifdef HAVE_CGROUP #ifdef HAVE_CGROUP
if (this->flags & PROCESS_FLAG_CGROUP) if (settings->flags & PROCESS_FLAG_CGROUP)
LinuxProcessList_readCGroupFile(process, dirname, name); LinuxProcessList_readCGroupFile(process, dirname, name);
#endif #endif
...@@ -537,11 +593,11 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -537,11 +593,11 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
process->basenameOffset = -1; process->basenameOffset = -1;
process->comm = strdup(command); process->comm = strdup(command);
} else if (Process_isThread(process)) { } else if (Process_isThread(process)) {
if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') { if (settings->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') {
free(process->comm); free(process->comm);
process->basenameOffset = -1; process->basenameOffset = -1;
process->comm = strdup(command); process->comm = strdup(command);
} else if (this->showingThreadNames) { } else if (settings->showThreadNames) {
if (! LinuxProcessList_readCmdlineFile(process, dirname, name)) if (! LinuxProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
} }
...@@ -567,7 +623,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -567,7 +623,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
process->comm = NULL; process->comm = NULL;
} }
if (existingProcess) if (existingProcess)
ProcessList_remove(this, process); ProcessList_remove((ProcessList*)this, process);
else else
Process_delete((Object*)process); Process_delete((Object*)process);
} }
...@@ -576,7 +632,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -576,7 +632,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
return true; return true;
} }
static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { static inline void LinuxProcessList_scanMemoryInfo(LinuxProcessList* this) {
unsigned long long int swapFree = 0; unsigned long long int swapFree = 0;
FILE* file = fopen(PROCMEMINFOFILE, "r"); FILE* file = fopen(PROCMEMINFOFILE, "r");
...@@ -617,14 +673,14 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { ...@@ -617,14 +673,14 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
fclose(file); fclose(file);
} }
static inline double LinuxProcessList_scanCPUTime(ProcessList* this) { static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
unsigned long long int usertime, nicetime, systemtime, idletime; unsigned long long int usertime, nicetime, systemtime, idletime;
FILE* file = fopen(PROCSTATFILE, "r"); FILE* file = fopen(PROCSTATFILE, "r");
if (file == NULL) { if (file == NULL) {
CRT_fatalError("Cannot open " PROCSTATFILE); CRT_fatalError("Cannot open " PROCSTATFILE);
} }
int cpus = this->cpuCount; int cpus = this->super.cpuCount;
assert(cpus > 0); assert(cpus > 0);
for (int i = 0; i <= cpus; i++) { for (int i = 0; i <= cpus; i++) {
char buffer[256]; char buffer[256];
...@@ -693,15 +749,16 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* this) { ...@@ -693,15 +749,16 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* this) {
return period; return period;
} }
void ProcessList_scan(ProcessList* this) { void ProcessList_scan(ProcessList* super) {
LinuxProcessList* this = (LinuxProcessList*) super;
LinuxProcessList_scanMemoryInfo(this); LinuxProcessList_scanMemoryInfo(this);
double period = LinuxProcessList_scanCPUTime(this); double period = LinuxProcessList_scanCPUTime(this);
// mark all process as "dirty" // mark all process as "dirty"
for (int i = 0; i < Vector_size(this->processes); i++) { for (int i = 0; i < Vector_size(super->processes); i++) {
Process* p = (Process*) Vector_get(this->processes, i); Process* p = (Process*) Vector_get(super->processes, i);
p->updated = false; p->updated = false;
} }
...@@ -714,12 +771,10 @@ void ProcessList_scan(ProcessList* this) { ...@@ -714,12 +771,10 @@ void ProcessList_scan(ProcessList* this) {
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
LinuxProcessList_processEntries(this, PROCDIR, NULL, period, tv); LinuxProcessList_processEntries(this, PROCDIR, NULL, period, tv);
this->showingThreadNames = this->showThreadNames; for (int i = Vector_size(this->super.processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->super.processes, i);
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i);
if (p->updated == false) if (p->updated == false)
ProcessList_remove(this, p); ProcessList_remove(super, p);
else else
p->updated = false; p->updated = false;
} }
......
...@@ -12,6 +12,56 @@ in the source distribution for its full text. ...@@ -12,6 +12,56 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int userTime;
unsigned long long int systemTime;
unsigned long long int systemAllTime;
unsigned long long int idleAllTime;
unsigned long long int idleTime;
unsigned long long int niceTime;
unsigned long long int ioWaitTime;
unsigned long long int irqTime;
unsigned long long int softIrqTime;
unsigned long long int stealTime;
unsigned long long int guestTime;
unsigned long long int totalPeriod;
unsigned long long int userPeriod;
unsigned long long int systemPeriod;
unsigned long long int systemAllPeriod;
unsigned long long int idleAllPeriod;
unsigned long long int idlePeriod;
unsigned long long int nicePeriod;
unsigned long long int ioWaitPeriod;
unsigned long long int irqPeriod;
unsigned long long int softIrqPeriod;
unsigned long long int stealPeriod;
unsigned long long int guestPeriod;
} CPUData;
typedef struct LinuxProcessList_ {
ProcessList super;
int totalTasks;
int userlandThreads;
int kernelThreads;
int runningTasks;
CPUData* cpus;
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
} LinuxProcessList;
#ifndef PROCDIR #ifndef PROCDIR
#define PROCDIR "/proc" #define PROCDIR "/proc"
#endif #endif
...@@ -25,9 +75,9 @@ in the source distribution for its full text. ...@@ -25,9 +75,9 @@ in the source distribution for its full text.
#endif #endif
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* this); void ProcessList_delete(ProcessList* pl);
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
...@@ -50,7 +100,7 @@ void ProcessList_delete(ProcessList* this); ...@@ -50,7 +100,7 @@ void ProcessList_delete(ProcessList* this);
#endif #endif
void ProcessList_scan(ProcessList* this); void ProcessList_scan(ProcessList* super);
#endif #endif
...@@ -9,6 +9,7 @@ in the source distribution for its full text. ...@@ -9,6 +9,7 @@ in the source distribution for its full text.
#include "IOPriority.h" #include "IOPriority.h"
#include "IOPriorityPanel.h" #include "IOPriorityPanel.h"
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "LinuxProcessList.h"
#include "Battery.h" #include "Battery.h"
#include "Meter.h" #include "Meter.h"
...@@ -29,14 +30,15 @@ in the source distribution for its full text. ...@@ -29,14 +30,15 @@ in the source distribution for its full text.
#include "BatteryMeter.h" #include "BatteryMeter.h"
}*/ }*/
static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) { static Htop_Reaction Platform_actionSetIOPriority(State* st) {
(void) panel, (void) pl; Panel* panel = st->panel;
LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel); LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel);
if (!p) return HTOP_OK; if (!p) return HTOP_OK;
IOPriority ioprio = p->ioPriority; IOPriority ioprio = p->ioPriority;
Panel* ioprioPanel = IOPriorityPanel_new(ioprio); Panel* ioprioPanel = IOPriorityPanel_new(ioprio);
const char* fuFunctions[] = {"Set ", "Cancel ", NULL}; const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
void* set = Action_pickFromVector(panel, ioprioPanel, 21, fuFunctions, header); void* set = Action_pickFromVector(st, ioprioPanel, 21, fuFunctions);
if (set) { if (set) {
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel); IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL); bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL);
...@@ -120,3 +122,63 @@ void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) { ...@@ -120,3 +122,63 @@ void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) {
*isOnAC = Battery_isOnAC(); *isOnAC = Battery_isOnAC();
*level = percent; *level = percent;
} }
double Platform_setCPUValues(Meter* this, int cpu) {
LinuxProcessList* pl = (LinuxProcessList*) this->pl;
CPUData* cpuData = &(pl->cpus[cpu]);
double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);
double percent;
double* v = this->values;
v[0] = cpuData->nicePeriod / total * 100.0;
v[1] = cpuData->userPeriod / total * 100.0;
if (this->pl->settings->detailedCPUTime) {
v[2] = cpuData->systemPeriod / total * 100.0;
v[3] = cpuData->irqPeriod / total * 100.0;
v[4] = cpuData->softIrqPeriod / total * 100.0;
v[5] = cpuData->stealPeriod / total * 100.0;
v[6] = cpuData->guestPeriod / total * 100.0;
v[7] = cpuData->ioWaitPeriod / total * 100.0;
Meter_setItems(this, 8);
if (this->pl->settings->accountGuestInCPUMeter) {
percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6];
} else {
percent = v[0]+v[1]+v[2]+v[3]+v[4];
}
} else {
v[2] = cpuData->systemAllPeriod / total * 100.0;
v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
Meter_setItems(this, 4);
percent = v[0]+v[1]+v[2]+v[3];
}
percent = MIN(100.0, MAX(0.0, percent));
if (isnan(percent)) percent = 0.0;
return percent;
}
void Platform_setMemoryValues(Meter* this) {
LinuxProcessList* pl = (LinuxProcessList*) this->pl;
long int usedMem = pl->usedMem;
long int buffersMem = pl->buffersMem;
long int cachedMem = pl->cachedMem;
usedMem -= buffersMem + cachedMem;
this->total = pl->totalMem;
this->values[0] = usedMem;
this->values[1] = buffersMem;
this->values[2] = cachedMem;
}
void Platform_setSwapValues(Meter* this) {
LinuxProcessList* pl = (LinuxProcessList*) this->pl;
this->total = pl->totalSwap;
this->values[0] = pl->usedSwap;
}
void Platform_setTasksValues(Meter* this) {
LinuxProcessList* pl = (LinuxProcessList*) this->pl;
this->values[0] = pl->kernelThreads;
this->values[1] = pl->userlandThreads;
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
this->values[3] = pl->runningTasks;
if (pl->totalTasks > this->total)
this->total = pl->totalTasks;
}
...@@ -24,4 +24,12 @@ int Platform_getMaxPid(); ...@@ -24,4 +24,12 @@ int Platform_getMaxPid();
void Platform_getBatteryLevel(double* level, ACPresence* isOnAC); void Platform_getBatteryLevel(double* level, ACPresence* isOnAC);
double Platform_setCPUValues(Meter* this, int cpu);
void Platform_setMemoryValues(Meter* this);
void Platform_setSwapValues(Meter* this);
void Platform_setTasksValues(Meter* this);
#endif #endif
...@@ -56,6 +56,8 @@ for line in file.readlines(): ...@@ -56,6 +56,8 @@ for line in file.readlines():
state = SKIP state = SKIP
elif equals != -1: elif equals != -1:
out.write("extern " + line[:equals] + ";" ) out.write("extern " + line[:equals] + ";" )
elif line.startswith("typedef struct"):
state = SKIP
elif line[-1] == "{": elif line[-1] == "{":
out.write( line[:-2].replace("inline", "extern") + ";" ) out.write( line[:-2].replace("inline", "extern") + ";" )
state = SKIP state = SKIP
......
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