mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-13 04:34:35 +03:00
Move kernel/userland thread handling to platform-independent implementation
This commit is contained in:
@ -121,18 +121,6 @@ static int SolarisProcess_compareByKey(const Process* v1, const Process* v2, Pro
|
||||
}
|
||||
}
|
||||
|
||||
bool Process_isThread(const Process* this) {
|
||||
const SolarisProcess* fp = (const SolarisProcess*) this;
|
||||
|
||||
if (fp->kernel == 1 ) {
|
||||
return 1;
|
||||
} else if (fp->is_lwp) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const ProcessClass SolarisProcess_class = {
|
||||
.super = {
|
||||
.extends = Class(Process),
|
||||
|
@ -26,24 +26,18 @@ in the source distribution for its full text.
|
||||
|
||||
typedef struct SolarisProcess_ {
|
||||
Process super;
|
||||
int kernel;
|
||||
zoneid_t zoneid;
|
||||
char* zname;
|
||||
taskid_t taskid;
|
||||
projid_t projid;
|
||||
poolid_t poolid;
|
||||
ctid_t contid;
|
||||
bool is_lwp;
|
||||
pid_t realpid;
|
||||
pid_t realppid;
|
||||
pid_t realtgid;
|
||||
pid_t lwpid;
|
||||
} SolarisProcess;
|
||||
|
||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||
|
||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||
|
||||
extern const ProcessClass SolarisProcess_class;
|
||||
|
||||
extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
|
||||
@ -52,6 +46,4 @@ Process* SolarisProcess_new(const Settings* settings);
|
||||
|
||||
void Process_delete(Object* cast);
|
||||
|
||||
bool Process_isThread(const Process* this);
|
||||
|
||||
#endif
|
||||
|
@ -322,6 +322,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
|
||||
} else {
|
||||
getpid = lwpid;
|
||||
}
|
||||
|
||||
Process* proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new);
|
||||
SolarisProcess* sproc = (SolarisProcess*) proc;
|
||||
|
||||
@ -376,18 +377,18 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
|
||||
proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu / (double)32768) * (double)100.0;
|
||||
proc->time = _psinfo->pr_time.tv_sec;
|
||||
if (!preExisting) { // Tasks done only for NEW processes
|
||||
sproc->is_lwp = false;
|
||||
proc->isUserlandThread = false;
|
||||
proc->starttime_ctime = _psinfo->pr_start.tv_sec;
|
||||
}
|
||||
|
||||
// Update proc and thread counts based on settings
|
||||
if (sproc->kernel && !pl->settings->hideKernelThreads) {
|
||||
if (proc->isKernelThread && !pl->settings->hideKernelThreads) {
|
||||
pl->kernelThreads += proc->nlwp;
|
||||
pl->totalTasks += proc->nlwp + 1;
|
||||
if (proc->state == 'O') {
|
||||
pl->runningTasks++;
|
||||
}
|
||||
} else if (!sproc->kernel) {
|
||||
} else if (!proc->isKernelThread) {
|
||||
if (proc->state == 'O') {
|
||||
pl->runningTasks++;
|
||||
}
|
||||
@ -398,12 +399,12 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
|
||||
pl->totalTasks += proc->nlwp + 1;
|
||||
}
|
||||
}
|
||||
proc->show = !(pl->settings->hideKernelThreads && sproc->kernel);
|
||||
proc->show = !(pl->settings->hideKernelThreads && proc->isKernelThread);
|
||||
} else { // We are not in the master LWP, so jump to the LWP handling code
|
||||
proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu / (double)32768) * (double)100.0;
|
||||
proc->time = _lwpsinfo->pr_time.tv_sec;
|
||||
if (!preExisting) { // Tasks done only for NEW LWPs
|
||||
sproc->is_lwp = true;
|
||||
proc->isUserlandThread = true;
|
||||
proc->cmdlineBasenameEnd = -1;
|
||||
proc->ppid = _psinfo->pr_pid * 1024;
|
||||
proc->tgid = _psinfo->pr_pid * 1024;
|
||||
@ -413,10 +414,10 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
|
||||
}
|
||||
|
||||
// Top-level process only gets this for the representative LWP
|
||||
if (sproc->kernel && !pl->settings->hideKernelThreads) {
|
||||
if (proc->isKernelThread && !pl->settings->hideKernelThreads) {
|
||||
proc->show = true;
|
||||
}
|
||||
if (!sproc->kernel && !pl->settings->hideUserlandThreads) {
|
||||
if (!proc->isKernelThread && !pl->settings->hideUserlandThreads) {
|
||||
proc->show = true;
|
||||
}
|
||||
} // Top-level LWP or subordinate LWP
|
||||
@ -425,10 +426,11 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
|
||||
|
||||
if (!preExisting) {
|
||||
if ((sproc->realppid <= 0) && !(sproc->realpid <= 1)) {
|
||||
sproc->kernel = true;
|
||||
proc->isKernelThread = true;
|
||||
} else {
|
||||
sproc->kernel = false;
|
||||
proc->isKernelThread = false;
|
||||
}
|
||||
|
||||
Process_fillStarttimeBuffer(proc);
|
||||
ProcessList_add(pl, proc);
|
||||
}
|
||||
|
Reference in New Issue
Block a user