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

View File

@ -60,7 +60,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
size = sizeof(fscale);
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++) {
fpl->cpus[i].totalTime = 1;
@ -90,14 +90,14 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
size_t size = sizeof(uvmexp);
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;
pl->usedMem = uvmexp.active * pageSizeKb;
pl->totalMem = uvmexp.npages * pageSizeKb;
/*
/*
const OpenBSDProcessList* fpl = (OpenBSDProcessList*) pl;
size_t len = sizeof(pl->totalMem);
@ -142,14 +142,14 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
while (*argv != NULL) {
cpsz = MIN(len, strlen(*argv));
strncpy(buf, *argv, cpsz);
buf += cpsz;
len -= cpsz;
argv++;
if (len > 0) {
*buf = ' ';
buf++;
len--;
}
buf += cpsz;
len -= cpsz;
argv++;
if (len > 0) {
*buf = ' ';
buf++;
len--;
}
}
*buf = '\0';
@ -160,12 +160,12 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
* Taken from OpenBSD's ps(1).
*/
double getpcpu(const struct kinfo_proc *kp) {
if (fscale == 0)
return (0.0);
if (fscale == 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) {
@ -194,7 +194,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
fp = (OpenBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc))
|| (hideUserlandThreads && Process_isUserlandThread(proc)));
|| (hideUserlandThreads && Process_isUserlandThread(proc)));
if (!preExisting) {
proc->ppid = kproc->p_ppid;
@ -217,24 +217,24 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->m_size = kproc->p_vm_dsize;
proc->m_resident = kproc->p_vm_rssize;
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_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->nlwp = kproc->p_numthreads;
//proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10);
proc->nice = kproc->p_nice - 20;
proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000);
proc->time *= 100;
proc->nice = kproc->p_nice - 20;
proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000);
proc->time *= 100;
proc->priority = kproc->p_priority - PZERO;
switch (kproc->p_stat) {
case SIDL: proc->state = 'I'; break;
case SRUN: proc->state = 'R'; break;
case SSLEEP: proc->state = 'S'; break;
case SSTOP: proc->state = 'T'; break;
case SZOMB: proc->state = 'Z'; break;
case SDEAD: proc->state = 'D'; break;
case SONPROC: proc->state = 'P'; break;
default: proc->state = '?';
case SIDL: proc->state = 'I'; break;
case SRUN: proc->state = 'R'; break;
case SSLEEP: proc->state = 'S'; break;
case SSTOP: proc->state = 'T'; break;
case SZOMB: proc->state = 'Z'; break;
case SDEAD: proc->state = 'D'; break;
case SONPROC: proc->state = 'P'; break;
default: proc->state = '?';
}
if (Process_isKernelThread(proc)) {
@ -242,8 +242,9 @@ void ProcessList_goThroughEntries(ProcessList* this) {
}
this->totalTasks++;
if (proc->state == 'R')
if (proc->state == 'R') {
this->runningTasks++;
}
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.
*/
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;
int i;
int64_t change, total_change, *dp, half_total;
int i;
/* initialization */
total_change = 0;
dp = diffs;
/* initialization */
total_change = 0;
dp = diffs;
/* calculate changes for each state and the overall change */
for (i = 0; i < cnt; i++) {
if ((change = *new - *old) < 0) {
/* this only happens when the counter wraps */
change = INT64_MAX - *old + *new;
}
total_change += (*dp++ = change);
*old++ = *new++;
}
/* calculate changes for each state and the overall change */
for (i = 0; i < cnt; i++) {
if ((change = *new - *old) < 0) {
/* this only happens when the counter wraps */
change = INT64_MAX - *old + *new;
}
total_change += (*dp++ = change);
*old++ = *new++;
}
/* avoid divide by zero potential */
if (total_change == 0)
total_change = 1;
/* avoid divide by zero potential */
if (total_change == 0)
total_change = 1;
/* calculate percentages based on overall change, rounding up */
half_total = total_change / 2l;
for (i = 0; i < cnt; i++)
*out++ = ((*diffs++ * 1000 + half_total) / total_change);
/* calculate percentages based on overall change, rounding up */
half_total = total_change / 2l;
for (i = 0; i < cnt; i++)
*out++ = ((*diffs++ * 1000 + half_total) / total_change);
/* return the total in case the caller wants to use it */
return (total_change);
/* return the total in case the caller wants to use it */
return (total_change);
}
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) {
int i;
double perc;
int i;
double perc;
OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl;
CPUData* cpuData = &(pl->cpus[cpu]);
int64_t new_v[CPUSTATES], diff_v[CPUSTATES], scratch_v[CPUSTATES];
double *v = this->values;
size_t size = sizeof(double) * CPUSTATES;
int mib[] = { CTL_KERN, KERN_CPTIME2, cpu-1 };
if (sysctl(mib, 3, new_v, &size, NULL, 0) == -1) {
puts("err!");
//return 0.;
}
OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl;
CPUData* cpuData = &(pl->cpus[cpu]);
int64_t new_v[CPUSTATES], diff_v[CPUSTATES], scratch_v[CPUSTATES];
double *v = this->values;
size_t size = sizeof(double) * CPUSTATES;
int mib[] = { CTL_KERN, KERN_CPTIME2, cpu-1 };
if (sysctl(mib, 3, new_v, &size, NULL, 0) == -1) {
puts("err!");
//return 0.;
}
// XXX: why?
cpuData->totalPeriod = 1;
// XXX: why?
cpuData->totalPeriod = 1;
percentages(CPUSTATES, diff_v, new_v,
(int64_t *)old_v[cpu-1], scratch_v);
percentages(CPUSTATES, diff_v, new_v,
(int64_t *)old_v[cpu-1], scratch_v);
for (i = 0; i < CPUSTATES; i++) {
old_v[cpu-1][i] = new_v[i];
v[i] = diff_v[i] / 10.;
}
for (i = 0; i < CPUSTATES; i++) {
old_v[cpu-1][i] = new_v[i];
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.) {
return perc;
} else {
return 12.34;
}
if (perc <= 100. && perc >= 0.) {
return perc;
} else {
return 12.34;
}
}
void Platform_setMemoryValues(Meter* this) {
@ -212,41 +212,41 @@ void Platform_setMemoryValues(Meter* this) {
* Taken almost directly from OpenBSD's top(1)
*/
void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
struct swapent *swdev;
unsigned long long int total, used;
int nswap, rnswap, i;
nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap == 0) {
return;
}
ProcessList* pl = (ProcessList*) this->pl;
struct swapent *swdev;
unsigned long long int total, used;
int nswap, rnswap, i;
nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap == 0) {
return;
}
swdev = calloc(nswap, sizeof(*swdev));
if (swdev == NULL) {
return;
}
swdev = calloc(nswap, sizeof(*swdev));
if (swdev == NULL) {
return;
}
rnswap = swapctl(SWAP_STATS, swdev, nswap);
if (rnswap == -1) {
free(swdev);
return;
}
rnswap = swapctl(SWAP_STATS, swdev, nswap);
if (rnswap == -1) {
free(swdev);
return;
}
// if rnswap != nswap, then what?
// if rnswap != nswap, then what?
/* Total things up */
total = used = 0;
for (i = 0; i < nswap; i++) {
if (swdev[i].se_flags & SWF_ENABLE) {
used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
}
}
/* Total things up */
total = used = 0;
for (i = 0; i < nswap; i++) {
if (swdev[i].se_flags & SWF_ENABLE) {
used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
}
}
this->total = pl->totalSwap = total;
this->values[0] = pl->usedSwap = used;
this->total = pl->totalSwap = total;
this->values[0] = pl->usedSwap = used;
free(swdev);
free(swdev);
}
void Platform_setTasksValues(Meter* this) {