mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Major advances in FreeBSD port.
This commit is contained in:
@ -51,7 +51,6 @@ typedef enum LinuxProcessFields {
|
||||
STIME = 15,
|
||||
CUTIME = 16,
|
||||
CSTIME = 17,
|
||||
PROCESSOR = 38,
|
||||
M_SHARE = 41,
|
||||
M_TRS = 42,
|
||||
M_DRS = 43,
|
||||
@ -97,7 +96,6 @@ typedef struct LinuxProcess_ {
|
||||
unsigned long long int stime;
|
||||
unsigned long long int cutime;
|
||||
unsigned long long int cstime;
|
||||
int processor;
|
||||
long m_share;
|
||||
long m_trs;
|
||||
long m_drs;
|
||||
@ -309,7 +307,6 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
switch ((int)field) {
|
||||
case CMINFLT: Process_colorNumber(str, lp->cminflt, coloring); return;
|
||||
case CMAJFLT: Process_colorNumber(str, lp->cmajflt, coloring); return;
|
||||
case PROCESSOR: snprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, lp->processor)); break;
|
||||
case M_DRS: Process_humanNumber(str, lp->m_drs * PAGE_SIZE_KB, coloring); return;
|
||||
case M_DT: Process_humanNumber(str, lp->m_dt * PAGE_SIZE_KB, coloring); return;
|
||||
case M_LRS: Process_humanNumber(str, lp->m_lrs * PAGE_SIZE_KB, coloring); return;
|
||||
@ -381,8 +378,6 @@ long Process_compare(const void* v1, const void* v2) {
|
||||
}
|
||||
long long diff;
|
||||
switch ((int)settings->sortKey) {
|
||||
case PROCESSOR:
|
||||
return (p1->processor - p2->processor);
|
||||
case M_DRS:
|
||||
return (p2->m_drs - p1->m_drs);
|
||||
case M_DT:
|
||||
|
@ -61,11 +61,6 @@ typedef struct CPUData_ {
|
||||
|
||||
typedef struct LinuxProcessList_ {
|
||||
ProcessList super;
|
||||
|
||||
int totalTasks;
|
||||
int userlandThreads;
|
||||
int kernelThreads;
|
||||
int runningTasks;
|
||||
|
||||
CPUData* cpus;
|
||||
|
||||
@ -141,6 +136,14 @@ static ssize_t xread(int fd, void *buf, size_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
static double jiffy = 0.0;
|
||||
|
||||
static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) {
|
||||
if(jiffy == 0.0) jiffy = sysconf(_SC_CLK_TCK);
|
||||
double jiffytime = 1.0 / jiffy;
|
||||
return (unsigned long long) t * jiffytime * 100;
|
||||
}
|
||||
|
||||
static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, const char* name, char* command) {
|
||||
LinuxProcess* lp = (LinuxProcess*) process;
|
||||
char filename[MAX_NAME+1];
|
||||
@ -191,13 +194,13 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
|
||||
location += 1;
|
||||
lp->cmajflt = strtoull(location, &location, 10);
|
||||
location += 1;
|
||||
lp->utime = strtoull(location, &location, 10);
|
||||
lp->utime = LinuxProcess_adjustTime(strtoull(location, &location, 10));
|
||||
location += 1;
|
||||
lp->stime = strtoull(location, &location, 10);
|
||||
lp->stime = LinuxProcess_adjustTime(strtoull(location, &location, 10));
|
||||
location += 1;
|
||||
lp->cutime = strtoull(location, &location, 10);
|
||||
lp->cutime = LinuxProcess_adjustTime(strtoull(location, &location, 10));
|
||||
location += 1;
|
||||
lp->cstime = strtoull(location, &location, 10);
|
||||
lp->cstime = LinuxProcess_adjustTime(strtoull(location, &location, 10));
|
||||
location += 1;
|
||||
process->priority = strtol(location, &location, 10);
|
||||
location += 1;
|
||||
@ -474,11 +477,11 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) {
|
||||
static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) {
|
||||
ProcessList* pl = (ProcessList*) this;
|
||||
DIR* dir;
|
||||
struct dirent* entry;
|
||||
Settings* settings = this->super.settings;
|
||||
Settings* settings = pl->settings;
|
||||
|
||||
time_t curTime = tv.tv_sec;
|
||||
#ifdef HAVE_TASKSTATS
|
||||
@ -487,7 +490,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
|
||||
|
||||
dir = opendir(dirname);
|
||||
if (!dir) return false;
|
||||
int cpus = this->super.cpuCount;
|
||||
int cpus = pl->cpuCount;
|
||||
bool hideKernelThreads = settings->hideKernelThreads;
|
||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
@ -513,25 +516,15 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
|
||||
if (pid <= 0)
|
||||
continue;
|
||||
|
||||
Process* proc = NULL;
|
||||
Process* existingProc = (Process*) Hashtable_get(this->super.processTable, pid);
|
||||
|
||||
if (existingProc) {
|
||||
assert(Vector_indexOf(this->processes, existingProc, Process_pidCompare) != -1);
|
||||
proc = existingProc;
|
||||
assert(proc->pid == pid);
|
||||
} else {
|
||||
proc = (Process*) LinuxProcess_new(settings);
|
||||
assert(proc->comm == NULL);
|
||||
proc->pid = pid;
|
||||
proc->tgid = parent ? parent->pid : pid;
|
||||
}
|
||||
bool preExisting = false;
|
||||
Process* proc = ProcessList_getProcess(pl, pid, &preExisting, (Process_new_fn) LinuxProcess_new);
|
||||
proc->tgid = parent ? parent->pid : pid;
|
||||
|
||||
LinuxProcess* lp = (LinuxProcess*) proc;
|
||||
|
||||
char subdirname[MAX_NAME+1];
|
||||
snprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name);
|
||||
LinuxProcessList_processEntries(this, subdirname, proc, period, tv);
|
||||
LinuxProcessList_recurseProcTree(this, subdirname, proc, period, tv);
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
if (settings->flags & PROCESS_FLAG_IO)
|
||||
@ -554,12 +547,12 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
|
||||
if (isnan(proc->percent_cpu)) proc->percent_cpu = 0.0;
|
||||
proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(pl->totalMem) * 100.0;
|
||||
|
||||
if(!existingProc) {
|
||||
if(!preExisting) {
|
||||
|
||||
if (! LinuxProcessList_statProcessDir(proc, dirname, name, curTime))
|
||||
goto errorReadingProcess;
|
||||
|
||||
proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
|
||||
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
||||
|
||||
#ifdef HAVE_OPENVZ
|
||||
LinuxProcessList_readOpenVZData(this, lp, dirname, name);
|
||||
@ -573,7 +566,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
|
||||
if (! LinuxProcessList_readCmdlineFile(proc, dirname, name))
|
||||
goto errorReadingProcess;
|
||||
|
||||
ProcessList_add((ProcessList*)this, proc);
|
||||
ProcessList_add(pl, proc);
|
||||
} else {
|
||||
if (settings->updateProcessNames) {
|
||||
if (! LinuxProcessList_readCmdlineFile(proc, dirname, name))
|
||||
@ -614,20 +607,15 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char*
|
||||
if (proc->state == 'R')
|
||||
this->runningTasks++;
|
||||
proc->updated = true;
|
||||
|
||||
continue;
|
||||
|
||||
// Exception handler.
|
||||
errorReadingProcess: {
|
||||
if (proc->comm) {
|
||||
free(proc->comm);
|
||||
proc->basenameOffset = -1;
|
||||
proc->comm = NULL;
|
||||
}
|
||||
if (existingProc)
|
||||
ProcessList_remove((ProcessList*)this, proc);
|
||||
else
|
||||
if (preExisting) {
|
||||
ProcessList_remove((pl, proc);
|
||||
} else {
|
||||
Process_delete((Object*)proc);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
@ -752,35 +740,13 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||
return period;
|
||||
}
|
||||
|
||||
void ProcessList_scan(ProcessList* super) {
|
||||
void ProcessList_goThroughEntries(ProcessList* super) {
|
||||
LinuxProcessList* this = (LinuxProcessList*) super;
|
||||
|
||||
LinuxProcessList_scanMemoryInfo(super);
|
||||
|
||||
double period = LinuxProcessList_scanCPUTime(this);
|
||||
|
||||
// mark all process as "dirty"
|
||||
for (int i = 0; i < Vector_size(super->processes); i++) {
|
||||
Process* p = (Process*) Vector_get(super->processes, i);
|
||||
p->updated = false;
|
||||
}
|
||||
|
||||
this->totalTasks = 0;
|
||||
this->userlandThreads = 0;
|
||||
this->kernelThreads = 0;
|
||||
this->runningTasks = 0;
|
||||
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
LinuxProcessList_processEntries(this, PROCDIR, NULL, period, tv);
|
||||
|
||||
for (int i = Vector_size(this->super.processes) - 1; i >= 0; i--) {
|
||||
Process* p = (Process*) Vector_get(this->super.processes, i);
|
||||
if (p->updated == false)
|
||||
ProcessList_remove(super, p);
|
||||
else
|
||||
p->updated = false;
|
||||
}
|
||||
|
||||
LinuxProcessList_recurseProcTree(this, PROCDIR, NULL, period, tv);
|
||||
}
|
||||
|
||||
|
@ -165,13 +165,3 @@ void Platform_setSwapValues(Meter* this) {
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user