Change some tabs to three spaces

This commit is contained in:
Michael McConville 2015-09-19 12:08:34 -04:00
parent a9a5a539cf
commit e2bbd5cfa4
3 changed files with 210 additions and 209 deletions

View File

@ -49,130 +49,130 @@ ProcessClass OpenBSDProcess_class = {
ProcessFieldData Process_fields[] = { ProcessFieldData Process_fields[] = {
[0] = { [0] = {
.name = "", .name = "",
.title = NULL, .title = NULL,
.description = NULL, .description = NULL,
.flags = 0, }, .flags = 0, },
[PID] = { [PID] = {
.name = "PID", .name = "PID",
.title = " PID ", .title = " PID ",
.description = "Process/thread ID", .description = "Process/thread ID",
.flags = 0, }, .flags = 0, },
[COMM] = { [COMM] = {
.name = "Command", .name = "Command",
.title = "Command ", .title = "Command ",
.description = "Command line", .description = "Command line",
.flags = 0, }, .flags = 0, },
[STATE] = { [STATE] = {
.name = "STATE", .name = "STATE",
.title = "S ", .title = "S ",
.description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)",
.flags = 0, }, .flags = 0, },
[PPID] = { [PPID] = {
.name = "PPID", .name = "PPID",
.title = " PPID ", .title = " PPID ",
.description = "Parent process ID", .description = "Parent process ID",
.flags = 0, }, .flags = 0, },
[PGRP] = { [PGRP] = {
.name = "PGRP", .name = "PGRP",
.title = " PGRP ", .title = " PGRP ",
.description = "Process group ID", .description = "Process group ID",
.flags = 0, }, .flags = 0, },
[SESSION] = { [SESSION] = {
.name = "SESSION", .name = "SESSION",
.title = " SESN ", .title = " SESN ",
.description = "Process's session ID", .description = "Process's session ID",
.flags = 0, }, .flags = 0, },
[TTY_NR] = { [TTY_NR] = {
.name = "TTY_NR", .name = "TTY_NR",
.title = " TTY ", .title = " TTY ",
.description = "Controlling terminal", .description = "Controlling terminal",
.flags = 0, }, .flags = 0, },
[TPGID] = { [TPGID] = {
.name = "TPGID", .name = "TPGID",
.title = " TPGID ", .title = " TPGID ",
.description = "Process ID of the fg process group of the controlling terminal", .description = "Process ID of the fg process group of the controlling terminal",
.flags = 0, }, .flags = 0, },
[MINFLT] = { [MINFLT] = {
.name = "MINFLT", .name = "MINFLT",
.title = " MINFLT ", .title = " MINFLT ",
.description = "Number of minor faults which have not required loading a memory page from disk", .description = "Number of minor faults which have not required loading a memory page from disk",
.flags = 0, }, .flags = 0, },
[MAJFLT] = { [MAJFLT] = {
.name = "MAJFLT", .name = "MAJFLT",
.title = " MAJFLT ", .title = " MAJFLT ",
.description = "Number of major faults which have required loading a memory page from disk", .description = "Number of major faults which have required loading a memory page from disk",
.flags = 0, }, .flags = 0, },
[PRIORITY] = { [PRIORITY] = {
.name = "PRIORITY", .name = "PRIORITY",
.title = "PRI ", .title = "PRI ",
.description = "Kernel's internal priority for the process", .description = "Kernel's internal priority for the process",
.flags = 0, }, .flags = 0, },
[NICE] = { [NICE] = {
.name = "NICE", .name = "NICE",
.title = " NI ", .title = " NI ",
.description = "Nice value (the higher the value, the more it lets other processes take priority)", .description = "Nice value (the higher the value, the more it lets other processes take priority)",
.flags = 0, }, .flags = 0, },
[STARTTIME] = { [STARTTIME] = {
.name = "STARTTIME", .name = "STARTTIME",
.title = "START ", .title = "START ",
.description = "Time the process was started", .description = "Time the process was started",
.flags = 0, }, .flags = 0, },
[PROCESSOR] = { [PROCESSOR] = {
.name = "PROCESSOR", .name = "PROCESSOR",
.title = "CPU ", .title = "CPU ",
.description = "Id of the CPU the process last executed on", .description = "Id of the CPU the process last executed on",
.flags = 0, }, .flags = 0, },
[M_SIZE] = { [M_SIZE] = {
.name = "M_SIZE", .name = "M_SIZE",
.title = " VIRT ", .title = " VIRT ",
.description = "Total program size in virtual memory", .description = "Total program size in virtual memory",
.flags = 0, }, .flags = 0, },
[M_RESIDENT] = { [M_RESIDENT] = {
.name = "M_RESIDENT", .name = "M_RESIDENT",
.title = " RES ", .title = " RES ",
.description = "Resident set size, size of the text and data sections, plus stack usage", .description = "Resident set size, size of the text and data sections, plus stack usage",
.flags = 0, }, .flags = 0, },
[ST_UID] = { [ST_UID] = {
.name = "ST_UID", .name = "ST_UID",
.title = " UID ", .title = " UID ",
.description = "User ID of the process owner", .description = "User ID of the process owner",
.flags = 0, }, .flags = 0, },
[PERCENT_CPU] = { [PERCENT_CPU] = {
.name = "PERCENT_CPU", .name = "PERCENT_CPU",
.title = "CPU% ", .title = "CPU% ",
.description = "Percentage of the CPU time the process used in the last sampling", .description = "Percentage of the CPU time the process used in the last sampling",
.flags = 0, }, .flags = 0, },
[PERCENT_MEM] = { [PERCENT_MEM] = {
.name = "PERCENT_MEM", .name = "PERCENT_MEM",
.title = "MEM% ", .title = "MEM% ",
.description = "Percentage of the memory the process is using, based on resident memory size", .description = "Percentage of the memory the process is using, based on resident memory size",
.flags = 0, }, .flags = 0, },
[USER] = { [USER] = {
.name = "USER", .name = "USER",
.title = "USER ", .title = "USER ",
.description = "Username of the process owner (or user ID if name cannot be determined)", .description = "Username of the process owner (or user ID if name cannot be determined)",
.flags = 0, }, .flags = 0, },
[TIME] = { [TIME] = {
.name = "TIME", .name = "TIME",
.title = " TIME+ ", .title = " TIME+ ",
.description = "Total time the process has spent in user and system time", .description = "Total time the process has spent in user and system time",
.flags = 0, }, .flags = 0, },
[NLWP] = { [NLWP] = {
.name = "NLWP", .name = "NLWP",
.title = "NLWP ", .title = "NLWP ",
.description = "Number of threads in the process", .description = "Number of threads in the process",
.flags = 0, }, .flags = 0, },
[TGID] = { [TGID] = {
.name = "TGID", .name = "TGID",
.title = " TGID ", .title = " TGID ",
.description = "Thread group ID (i.e. process ID)", .description = "Thread group ID (i.e. process ID)",
.flags = 0, }, .flags = 0, },
[LAST_PROCESSFIELD] = { [LAST_PROCESSFIELD] = {
.name = "*** report bug! ***", .name = "*** report bug! ***",
.title = NULL, .title = NULL,
.description = NULL, .description = NULL,
.flags = 0, }, .flags = 0, },
}; };
ProcessPidColumn Process_pidColumns[] = { ProcessPidColumn Process_pidColumns[] = {

View File

@ -60,7 +60,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
size = sizeof(fscale); size = sizeof(fscale);
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0)
err(1, "fscale sysctl call failed"); err(1, "fscale sysctl call failed");
for (i = 0; i < pl->cpuCount; i++) { for (i = 0; i < pl->cpuCount; i++) {
fpl->cpus[i].totalTime = 1; fpl->cpus[i].totalTime = 1;
@ -90,14 +90,14 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
size_t size = sizeof(uvmexp); size_t size = sizeof(uvmexp);
if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) { if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) {
err(1, "uvmexp sysctl call failed"); err(1, "uvmexp sysctl call failed");
} }
//kb_pagesize = uvmexp.pagesize / 1024; //kb_pagesize = uvmexp.pagesize / 1024;
pl->usedMem = uvmexp.active * pageSizeKb; pl->usedMem = uvmexp.active * pageSizeKb;
pl->totalMem = uvmexp.npages * pageSizeKb; pl->totalMem = uvmexp.npages * pageSizeKb;
/* /*
const OpenBSDProcessList* fpl = (OpenBSDProcessList*) pl; const OpenBSDProcessList* fpl = (OpenBSDProcessList*) pl;
size_t len = sizeof(pl->totalMem); size_t len = sizeof(pl->totalMem);
@ -142,14 +142,14 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
while (*argv != NULL) { while (*argv != NULL) {
cpsz = MIN(len, strlen(*argv)); cpsz = MIN(len, strlen(*argv));
strncpy(buf, *argv, cpsz); strncpy(buf, *argv, cpsz);
buf += cpsz; buf += cpsz;
len -= cpsz; len -= cpsz;
argv++; argv++;
if (len > 0) { if (len > 0) {
*buf = ' '; *buf = ' ';
buf++; buf++;
len--; len--;
} }
} }
*buf = '\0'; *buf = '\0';
@ -160,12 +160,12 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
* Taken from OpenBSD's ps(1). * Taken from OpenBSD's ps(1).
*/ */
double getpcpu(const struct kinfo_proc *kp) { double getpcpu(const struct kinfo_proc *kp) {
if (fscale == 0) if (fscale == 0)
return (0.0); return (0.0);
#define fxtofl(fixpt) ((double)(fixpt) / fscale) #define fxtofl(fixpt) ((double)(fixpt) / fscale)
return (100.0 * fxtofl(kp->p_pctcpu)); return (100.0 * fxtofl(kp->p_pctcpu));
} }
void ProcessList_goThroughEntries(ProcessList* this) { void ProcessList_goThroughEntries(ProcessList* this) {
@ -194,7 +194,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
fp = (OpenBSDProcess*) proc; fp = (OpenBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc))
|| (hideUserlandThreads && Process_isUserlandThread(proc))); || (hideUserlandThreads && Process_isUserlandThread(proc)));
if (!preExisting) { if (!preExisting) {
proc->ppid = kproc->p_ppid; proc->ppid = kproc->p_ppid;
@ -217,24 +217,24 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->m_size = kproc->p_vm_dsize; proc->m_size = kproc->p_vm_dsize;
proc->m_resident = kproc->p_vm_rssize; proc->m_resident = kproc->p_vm_rssize;
proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0; proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0;
proc->percent_cpu = MAX(MIN(getpcpu(kproc), this->cpuCount*100.0), 0.0); proc->percent_cpu = MAX(MIN(getpcpu(kproc), this->cpuCount*100.0), 0.0);
//proc->nlwp = kproc->p_numthreads; //proc->nlwp = kproc->p_numthreads;
//proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10); //proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10);
proc->nice = kproc->p_nice - 20; proc->nice = kproc->p_nice - 20;
proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000); proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000);
proc->time *= 100; proc->time *= 100;
proc->priority = kproc->p_priority - PZERO; proc->priority = kproc->p_priority - PZERO;
switch (kproc->p_stat) { switch (kproc->p_stat) {
case SIDL: proc->state = 'I'; break; case SIDL: proc->state = 'I'; break;
case SRUN: proc->state = 'R'; break; case SRUN: proc->state = 'R'; break;
case SSLEEP: proc->state = 'S'; break; case SSLEEP: proc->state = 'S'; break;
case SSTOP: proc->state = 'T'; break; case SSTOP: proc->state = 'T'; break;
case SZOMB: proc->state = 'Z'; break; case SZOMB: proc->state = 'Z'; break;
case SDEAD: proc->state = 'D'; break; case SDEAD: proc->state = 'D'; break;
case SONPROC: proc->state = 'P'; break; case SONPROC: proc->state = 'P'; break;
default: proc->state = '?'; default: proc->state = '?';
} }
if (Process_isKernelThread(proc)) { if (Process_isKernelThread(proc)) {
@ -242,8 +242,9 @@ void ProcessList_goThroughEntries(ProcessList* this) {
} }
this->totalTasks++; this->totalTasks++;
if (proc->state == 'R') if (proc->state == 'R') {
this->runningTasks++; this->runningTasks++;
}
proc->updated = true; proc->updated = true;
} }
} }

View File

@ -60,34 +60,34 @@ static int64_t old_v[MAXCPU][5];
* useful on BSD machines for calculating cpu state percentages. * useful on BSD machines for calculating cpu state percentages.
*/ */
static int percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_t *diffs) { static int percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_t *diffs) {
int64_t change, total_change, *dp, half_total; int64_t change, total_change, *dp, half_total;
int i; int i;
/* initialization */ /* initialization */
total_change = 0; total_change = 0;
dp = diffs; dp = diffs;
/* calculate changes for each state and the overall change */ /* calculate changes for each state and the overall change */
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
if ((change = *new - *old) < 0) { if ((change = *new - *old) < 0) {
/* this only happens when the counter wraps */ /* this only happens when the counter wraps */
change = INT64_MAX - *old + *new; change = INT64_MAX - *old + *new;
} }
total_change += (*dp++ = change); total_change += (*dp++ = change);
*old++ = *new++; *old++ = *new++;
} }
/* avoid divide by zero potential */ /* avoid divide by zero potential */
if (total_change == 0) if (total_change == 0)
total_change = 1; total_change = 1;
/* calculate percentages based on overall change, rounding up */ /* calculate percentages based on overall change, rounding up */
half_total = total_change / 2l; half_total = total_change / 2l;
for (i = 0; i < cnt; i++) for (i = 0; i < cnt; i++)
*out++ = ((*diffs++ * 1000 + half_total) / total_change); *out++ = ((*diffs++ * 1000 + half_total) / total_change);
/* return the total in case the caller wants to use it */ /* return the total in case the caller wants to use it */
return (total_change); return (total_change);
} }
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
@ -157,40 +157,40 @@ int Platform_getMaxPid() {
} }
double Platform_setCPUValues(Meter* this, int cpu) { double Platform_setCPUValues(Meter* this, int cpu) {
int i; int i;
double perc; double perc;
OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl; OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl;
CPUData* cpuData = &(pl->cpus[cpu]); CPUData* cpuData = &(pl->cpus[cpu]);
int64_t new_v[CPUSTATES], diff_v[CPUSTATES], scratch_v[CPUSTATES]; int64_t new_v[CPUSTATES], diff_v[CPUSTATES], scratch_v[CPUSTATES];
double *v = this->values; double *v = this->values;
size_t size = sizeof(double) * CPUSTATES; size_t size = sizeof(double) * CPUSTATES;
int mib[] = { CTL_KERN, KERN_CPTIME2, cpu-1 }; int mib[] = { CTL_KERN, KERN_CPTIME2, cpu-1 };
if (sysctl(mib, 3, new_v, &size, NULL, 0) == -1) { if (sysctl(mib, 3, new_v, &size, NULL, 0) == -1) {
puts("err!"); puts("err!");
//return 0.; //return 0.;
} }
// XXX: why? // XXX: why?
cpuData->totalPeriod = 1; cpuData->totalPeriod = 1;
percentages(CPUSTATES, diff_v, new_v, percentages(CPUSTATES, diff_v, new_v,
(int64_t *)old_v[cpu-1], scratch_v); (int64_t *)old_v[cpu-1], scratch_v);
for (i = 0; i < CPUSTATES; i++) { for (i = 0; i < CPUSTATES; i++) {
old_v[cpu-1][i] = new_v[i]; old_v[cpu-1][i] = new_v[i];
v[i] = diff_v[i] / 10.; v[i] = diff_v[i] / 10.;
} }
Meter_setItems(this, 4); Meter_setItems(this, 4);
perc = v[0] + v[1] + v[2] + v[3]; perc = v[0] + v[1] + v[2] + v[3];
if (perc <= 100. && perc >= 0.) { if (perc <= 100. && perc >= 0.) {
return perc; return perc;
} else { } else {
return 12.34; return 12.34;
} }
} }
void Platform_setMemoryValues(Meter* this) { void Platform_setMemoryValues(Meter* this) {
@ -212,41 +212,41 @@ void Platform_setMemoryValues(Meter* this) {
* Taken almost directly from OpenBSD's top(1) * Taken almost directly from OpenBSD's top(1)
*/ */
void Platform_setSwapValues(Meter* this) { void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl; ProcessList* pl = (ProcessList*) this->pl;
struct swapent *swdev; struct swapent *swdev;
unsigned long long int total, used; unsigned long long int total, used;
int nswap, rnswap, i; int nswap, rnswap, i;
nswap = swapctl(SWAP_NSWAP, 0, 0); nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap == 0) { if (nswap == 0) {
return; return;
} }
swdev = calloc(nswap, sizeof(*swdev)); swdev = calloc(nswap, sizeof(*swdev));
if (swdev == NULL) { if (swdev == NULL) {
return; return;
} }
rnswap = swapctl(SWAP_STATS, swdev, nswap); rnswap = swapctl(SWAP_STATS, swdev, nswap);
if (rnswap == -1) { if (rnswap == -1) {
free(swdev); free(swdev);
return; return;
} }
// if rnswap != nswap, then what? // if rnswap != nswap, then what?
/* Total things up */ /* Total things up */
total = used = 0; total = used = 0;
for (i = 0; i < nswap; i++) { for (i = 0; i < nswap; i++) {
if (swdev[i].se_flags & SWF_ENABLE) { if (swdev[i].se_flags & SWF_ENABLE) {
used += (swdev[i].se_inuse / (1024 / DEV_BSIZE)); used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
total += (swdev[i].se_nblks / (1024 / DEV_BSIZE)); total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
} }
} }
this->total = pl->totalSwap = total; this->total = pl->totalSwap = total;
this->values[0] = pl->usedSwap = used; this->values[0] = pl->usedSwap = used;
free(swdev); free(swdev);
} }
void Platform_setTasksValues(Meter* this) { void Platform_setTasksValues(Meter* this) {