Whitespace and indentation issues

This commit is contained in:
Benny Baumann 2020-10-31 22:14:27 +01:00
parent 9a16b1079e
commit b23f8235e2
24 changed files with 347 additions and 288 deletions

View File

@ -65,7 +65,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
} else { } else {
unsigned int id; unsigned int id;
hwloc_bitmap_foreach_begin(id, cpuset); hwloc_bitmap_foreach_begin(id, cpuset);
Affinity_add(affinity, id); Affinity_add(affinity, id);
hwloc_bitmap_foreach_end(); hwloc_bitmap_foreach_end();
} }
} }

View File

@ -285,7 +285,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u
left -= len; left -= len;
} }
xSnprintf(&indent_buf[off], left, "%s", xSnprintf(&indent_buf[off], left, "%s",
obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]);
// Uncomment when further appending to indent_buf // Uncomment when further appending to indent_buf
//size_t len = strlen(&indent_buf[off]); //size_t len = strlen(&indent_buf[off]);
//off += len; //off += len;
@ -417,7 +417,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
int i; int i;
hwloc_bitmap_foreach_begin(i, this->workCpuset) hwloc_bitmap_foreach_begin(i, this->workCpuset)
Affinity_add(affinity, i); Affinity_add(affinity, i);
hwloc_bitmap_foreach_end(); hwloc_bitmap_foreach_end();
#else #else
for (int i = 0; i < this->pl->cpuCount; i++) { for (int i = 0; i < this->pl->cpuCount; i++) {

View File

@ -170,7 +170,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
doSearch = false; doSearch = false;
} }
} else if (ch == KEY_RESIZE) { } else if (ch == KEY_RESIZE) {
Panel_resize(panel, COLS, LINES-panel->y-1); Panel_resize(panel, COLS, LINES - panel->y - 1);
} else { } else {
if (mode->isFilter) { if (mode->isFilter) {
filterChanged = true; filterChanged = true;

View File

@ -31,9 +31,9 @@ static void ListItem_display(const Object* cast, RichString* out) {
if (this->moving) { if (this->moving) {
RichString_write(out, CRT_colors[DEFAULT_COLOR], RichString_write(out, CRT_colors[DEFAULT_COLOR],
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
CRT_utf8 ? "" : CRT_utf8 ? "" :
#endif #endif
"+ "); "+ ");
} else { } else {
RichString_prune(out); RichString_prune(out);
} }

View File

@ -254,8 +254,8 @@ void Panel_draw(Panel* this, bool focus) {
int upTo = MINIMUM(first + h, size); int upTo = MINIMUM(first + h, size);
int selectionColor = focus int selectionColor = focus
? this->selectionColor ? this->selectionColor
: CRT_colors[PANEL_SELECTION_UNFOCUS]; : CRT_colors[PANEL_SELECTION_UNFOCUS];
if (this->needsRedraw) { if (this->needsRedraw) {
int line = 0; int line = 0;

View File

@ -287,8 +287,8 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
if (indent & (1U << i)) if (indent & (1U << i))
maxIndent = i+1; maxIndent = i + 1;
for (int i = 0; i < maxIndent - 1; i++) { for (int i = 0; i < maxIndent - 1; i++) {
int written, ret; int written, ret;
if (indent & (1 << i)) if (indent & (1 << i))
ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);

View File

@ -182,8 +182,9 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
this->delay = atoi(option[1]); this->delay = atoi(option[1]);
} else if (String_eq(option[0], "color_scheme")) { } else if (String_eq(option[0], "color_scheme")) {
this->colorScheme = atoi(option[1]); this->colorScheme = atoi(option[1]);
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0; if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME)
} else if (String_eq(option[0], "enable_mouse")) { this->colorScheme = 0;
} else if (String_eq(option[0], "enable_mouse")) {
this->enableMouse = atoi(option[1]); this->enableMouse = atoi(option[1]);
} else if (String_eq(option[0], "left_meters")) { } else if (String_eq(option[0], "left_meters")) {
Settings_readMeters(this, option[1], 0); Settings_readMeters(this, option[1], 0);

View File

@ -32,12 +32,12 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
/* Get the battery */ /* Get the battery */
for (int i = 0; i < len && battery == NULL; ++i) { for (int i = 0; i < len && battery == NULL; ++i) {
CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFArrayGetValueAtIndex(list, i)); /* GET rule */
CFStringRef type; CFStringRef type;
if (NULL != candidate) { if (NULL != candidate) {
type = (CFStringRef) CFDictionaryGetValue(candidate, type = (CFStringRef) CFDictionaryGetValue(candidate,
CFSTR(kIOPSTransportTypeKey)); /* GET rule */ CFSTR(kIOPSTransportTypeKey)); /* GET rule */
if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
CFRetain(candidate); CFRetain(candidate);
@ -51,17 +51,17 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
*isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
? AC_PRESENT ? AC_PRESENT
: AC_ABSENT; : AC_ABSENT;
/* Get the percentage remaining */ /* Get the percentage remaining */
double current; double current;
double max; double max;
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
kCFNumberDoubleType, &current); kCFNumberDoubleType, &current);
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
kCFNumberDoubleType, &max); kCFNumberDoubleType, &max);
*level = (current * 100.0) / max; *level = (current * 100.0) / max;

View File

@ -158,12 +158,12 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
/* Convert previous '\0'. */ /* Convert previous '\0'. */
*np = ' '; *np = ' ';
} }
/* Note location of current '\0'. */ /* Note location of current '\0'. */
np = cp; np = cp;
if (*basenameOffset == 0) { if (*basenameOffset == 0) {
*basenameOffset = cp - sp; *basenameOffset = cp - sp;
} }
} }
} }
/* /*
@ -247,10 +247,10 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
if (0 != proc->utime || 0 != proc->stime) { if (0 != proc->utime || 0 != proc->stime) {
uint64_t diff = (pti.pti_total_system - proc->stime) uint64_t diff = (pti.pti_total_system - proc->stime)
+ (pti.pti_total_user - proc->utime); + (pti.pti_total_user - proc->utime);
proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount
/ ((double)dpl->global_diff * 100000.0); / ((double)dpl->global_diff * 100000.0);
// fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu, // fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu,
// proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff); // proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff);
@ -263,7 +263,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
proc->super.m_resident = pti.pti_resident_size / CRT_pageSize; proc->super.m_resident = pti.pti_resident_size / CRT_pageSize;
proc->super.majflt = pti.pti_faults; proc->super.majflt = pti.pti_faults;
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0 proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
/ (double)dpl->host_info.max_mem; / (double)dpl->host_info.max_mem;
proc->stime = pti.pti_total_system; proc->stime = pti.pti_total_system;
proc->utime = pti.pti_total_user; proc->utime = pti.pti_total_user;

View File

@ -24,7 +24,7 @@ in the source distribution for its full text.
#include <stdbool.h> #include <stdbool.h>
struct kern { struct kern {
short int version[3]; short int version[3];
}; };
void GetKernelVersion(struct kern *k) { void GetKernelVersion(struct kern *k) {
@ -35,9 +35,11 @@ void GetKernelVersion(struct kern *k) {
char str[256] = {0}; char str[256] = {0};
size_t size = sizeof(str); size_t size = sizeof(str);
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0); int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]); if (ret == 0) {
} sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
memcpy(k->version, version_, sizeof(version_)); }
}
memcpy(k->version, version_, sizeof(version_));
} }
/* compare the given os version with the one installed returns: /* compare the given os version with the one installed returns:
@ -46,28 +48,36 @@ positive value if less than the installed version
negative value if more than the installed version negative value if more than the installed version
*/ */
int CompareKernelVersion(short int major, short int minor, short int component) { int CompareKernelVersion(short int major, short int minor, short int component) {
struct kern k; struct kern k;
GetKernelVersion(&k); GetKernelVersion(&k);
if ( k.version[0] != major) return k.version[0] - major;
if ( k.version[1] != minor) return k.version[1] - minor; if (k.version[0] != major) {
if ( k.version[2] != component) return k.version[2] - component; return k.version[0] - major;
return 0; }
if (k.version[1] != minor) {
return k.version[1] - minor;
}
if (k.version[2] != component) {
return k.version[2] - component;
}
return 0;
} }
void ProcessList_getHostInfo(host_basic_info_data_t *p) { void ProcessList_getHostInfo(host_basic_info_data_t *p) {
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
CRT_fatalError("Unable to retrieve host info\n"); CRT_fatalError("Unable to retrieve host info\n");
} }
} }
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
if (NULL != p && NULL != *p) { if (NULL != p && NULL != *p) {
if (0 != munmap(*p, vm_page_size)) { if (0 != munmap(*p, vm_page_size)) {
CRT_fatalError("Unable to free old CPU load information\n"); CRT_fatalError("Unable to free old CPU load information\n");
} }
*p = NULL; *p = NULL;
} }
} }
@ -76,18 +86,19 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
unsigned cpu_count; unsigned cpu_count;
// TODO Improving the accuracy of the load counts woule help a lot. // TODO Improving the accuracy of the load counts woule help a lot.
if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t*)p, &info_size)) {
CRT_fatalError("Unable to retrieve CPU info\n"); CRT_fatalError("Unable to retrieve CPU info\n");
} }
return cpu_count; return cpu_count;
} }
void ProcessList_getVMStats(vm_statistics_t p) { void ProcessList_getVMStats(vm_statistics_t p) {
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) {
CRT_fatalError("Unable to retrieve VM statistics\n"); CRT_fatalError("Unable to retrieve VM statistics\n");
}
} }
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
@ -145,67 +156,68 @@ void ProcessList_delete(ProcessList* this) {
} }
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
DarwinProcessList *dpl = (DarwinProcessList *)super; DarwinProcessList* dpl = (DarwinProcessList*)super;
bool preExisting = true; bool preExisting = true;
struct kinfo_proc *ps; struct kinfo_proc* ps;
size_t count; size_t count;
DarwinProcess *proc; DarwinProcess* proc;
/* Update the global data (CPU times and VM stats) */ /* Update the global data (CPU times and VM stats) */
ProcessList_freeCPULoadInfo(&dpl->prev_load); ProcessList_freeCPULoadInfo(&dpl->prev_load);
dpl->prev_load = dpl->curr_load; dpl->prev_load = dpl->curr_load;
ProcessList_allocateCPULoadInfo(&dpl->curr_load); ProcessList_allocateCPULoadInfo(&dpl->curr_load);
ProcessList_getVMStats(&dpl->vm_stats); ProcessList_getVMStats(&dpl->vm_stats);
openzfs_sysctl_updateArcStats(&dpl->zfs); openzfs_sysctl_updateArcStats(&dpl->zfs);
// in pause mode only gather global data for meters (CPU/memory/...) // in pause mode only gather global data for meters (CPU/memory/...)
if (pauseProcessUpdate) if (pauseProcessUpdate) {
return; return;
}
/* Get the time difference */ /* Get the time difference */
dpl->global_diff = 0; dpl->global_diff = 0;
for (int i = 0; i < dpl->super.cpuCount; ++i) { for (int i = 0; i < dpl->super.cpuCount; ++i) {
for (size_t j = 0; j < CPU_STATE_MAX; ++j) { for (size_t j = 0; j < CPU_STATE_MAX; ++j) {
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
} }
} }
/* Clear the thread counts */ /* Clear the thread counts */
super->kernelThreads = 0; super->kernelThreads = 0;
super->userlandThreads = 0; super->userlandThreads = 0;
super->totalTasks = 0; super->totalTasks = 0;
super->runningTasks = 0; super->runningTasks = 0;
/* We use kinfo_procs for initial data since : /* We use kinfo_procs for initial data since :
* *
* 1) They always succeed. * 1) They always succeed.
* 2) The contain the basic information. * 2) The contain the basic information.
* *
* We attempt to fill-in additional information with libproc. * We attempt to fill-in additional information with libproc.
*/ */
ps = ProcessList_getKInfoProcs(&count); ps = ProcessList_getKInfoProcs(&count);
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); proc = (DarwinProcess*)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl); DarwinProcess_setFromLibprocPidinfo(proc, dpl);
// Disabled for High Sierra due to bug in macOS High Sierra // Disabled for High Sierra due to bug in macOS High Sierra
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0); bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);
if (isScanThreadSupported){ if (isScanThreadSupported) {
DarwinProcess_scanThreads(proc); DarwinProcess_scanThreads(proc);
} }
super->totalTasks += 1; super->totalTasks += 1;
if (!preExisting) { if (!preExisting) {
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
ProcessList_add(super, &proc->super); ProcessList_add(super, &proc->super);
} }
} }
free(ps); free(ps);
} }

View File

@ -211,11 +211,11 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
} }
mtr->values[CPU_METER_NICE] mtr->values[CPU_METER_NICE]
= ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total; = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE]) * 100.0 / total;
mtr->values[CPU_METER_NORMAL] mtr->values[CPU_METER_NORMAL]
= ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total; = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER]) * 100.0 / total;
mtr->values[CPU_METER_KERNEL] mtr->values[CPU_METER_KERNEL]
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total; = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM]) * 100.0 / total;
mtr->curItems = 3; mtr->curItems = 3;
@ -239,13 +239,13 @@ void Platform_setMemoryValues(Meter* mtr) {
} }
void Platform_setSwapValues(Meter* mtr) { void Platform_setSwapValues(Meter* mtr) {
int mib[2] = {CTL_VM, VM_SWAPUSAGE}; int mib[2] = {CTL_VM, VM_SWAPUSAGE};
struct xsw_usage swapused; struct xsw_usage swapused;
size_t swlen = sizeof(swapused); size_t swlen = sizeof(swapused);
sysctl(mib, 2, &swapused, &swlen, NULL, 0); sysctl(mib, 2, &swapused, &swlen, NULL, 0);
mtr->total = swapused.xsu_total / 1024; mtr->total = swapused.xsu_total / 1024;
mtr->values[0] = swapused.xsu_used / 1024; mtr->values[0] = swapused.xsu_used / 1024;
} }
void Platform_setZfsArcValues(Meter* this) { void Platform_setZfsArcValues(Meter* this) {

View File

@ -101,10 +101,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
pl->cpuCount = MAXIMUM(cpus, 1); pl->cpuCount = MAXIMUM(cpus, 1);
if (cpus == 1 ) { if (cpus == 1 ) {
dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData));
} else { } else {
// on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well)
dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
} }
len = sizeof(kernelFScale); len = sizeof(kernelFScale);
@ -161,12 +161,12 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
// get rest of CPUs // get rest of CPUs
if (cpus > 1) { if (cpus > 1) {
// on smp systems DragonFlyBSD kernel concats all CPU states into one long array in // on smp systems DragonFlyBSD kernel concats all CPU states into one long array in
// kern.cp_times sysctl OID // kern.cp_times sysctl OID
// we store averages in dfpl->cpus[0], and actual cores after that // we store averages in dfpl->cpus[0], and actual cores after that
maxcpu = cpus + 1; maxcpu = cpus + 1;
sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES;
sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0);
} }
for (int i = 0; i < maxcpu; i++) { for (int i = 0; i < maxcpu; i++) {
@ -176,14 +176,14 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
cp_time_o = dfpl->cp_time_o; cp_time_o = dfpl->cp_time_o;
} else { } else {
if (i == 0 ) { if (i == 0 ) {
// average // average
cp_time_n = dfpl->cp_time_n; cp_time_n = dfpl->cp_time_n;
cp_time_o = dfpl->cp_time_o; cp_time_o = dfpl->cp_time_o;
} else { } else {
// specific smp cores // specific smp cores
cp_times_offset = i - 1; cp_times_offset = i - 1;
cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES);
cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES);
} }
} }
@ -192,9 +192,9 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
unsigned long long total_n = 0; unsigned long long total_n = 0;
unsigned long long total_d = 0; unsigned long long total_d = 0;
for (int s = 0; s < CPUSTATES; s++) { for (int s = 0; s < CPUSTATES; s++) {
cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; cp_time_d[s] = cp_time_n[s] - cp_time_o[s];
total_o += cp_time_o[s]; total_o += cp_time_o[s];
total_n += cp_time_n[s]; total_n += cp_time_n[s];
} }
// totals // totals
@ -203,8 +203,8 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
// save current state as old and calc percentages // save current state as old and calc percentages
for (int s = 0; s < CPUSTATES; ++s) { for (int s = 0; s < CPUSTATES; ++s) {
cp_time_o[s] = cp_time_n[s]; cp_time_o[s] = cp_time_n[s];
cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100;
} }
CPUData* cpuData = &(dfpl->cpus[i]); CPUData* cpuData = &(dfpl->cpus[i]);
@ -344,8 +344,9 @@ retry:
} }
curpos = nextpos; curpos = nextpos;
} }
free(jls);
free(jls);
} }
char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) { char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) {

View File

@ -154,10 +154,10 @@ double Platform_setCPUValues(Meter* this, int cpu) {
const CPUData* cpuData; const CPUData* cpuData;
if (cpus == 1) { if (cpus == 1) {
// single CPU box has everything in fpl->cpus[0] // single CPU box has everything in fpl->cpus[0]
cpuData = &(fpl->cpus[0]); cpuData = &(fpl->cpus[0]);
} else { } else {
cpuData = &(fpl->cpus[cpu]); cpuData = &(fpl->cpus[cpu]);
} }
double percent; double percent;

View File

@ -124,10 +124,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
pl->cpuCount = MAXIMUM(cpus, 1); pl->cpuCount = MAXIMUM(cpus, 1);
if (cpus == 1 ) { if (cpus == 1 ) {
fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData)); fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData));
} else { } else {
// on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well)
fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
} }
@ -187,12 +187,12 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) {
// get rest of CPUs // get rest of CPUs
if (cpus > 1) { if (cpus > 1) {
// on smp systems FreeBSD kernel concats all CPU states into one long array in // on smp systems FreeBSD kernel concats all CPU states into one long array in
// kern.cp_times sysctl OID // kern.cp_times sysctl OID
// we store averages in fpl->cpus[0], and actual cores after that // we store averages in fpl->cpus[0], and actual cores after that
maxcpu = cpus + 1; maxcpu = cpus + 1;
sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES;
sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0);
} }
for (int i = 0; i < maxcpu; i++) { for (int i = 0; i < maxcpu; i++) {
@ -202,14 +202,14 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) {
cp_time_o = fpl->cp_time_o; cp_time_o = fpl->cp_time_o;
} else { } else {
if (i == 0 ) { if (i == 0 ) {
// average // average
cp_time_n = fpl->cp_time_n; cp_time_n = fpl->cp_time_n;
cp_time_o = fpl->cp_time_o; cp_time_o = fpl->cp_time_o;
} else { } else {
// specific smp cores // specific smp cores
cp_times_offset = i - 1; cp_times_offset = i - 1;
cp_time_n = fpl->cp_times_n + (cp_times_offset * CPUSTATES); cp_time_n = fpl->cp_times_n + (cp_times_offset * CPUSTATES);
cp_time_o = fpl->cp_times_o + (cp_times_offset * CPUSTATES); cp_time_o = fpl->cp_times_o + (cp_times_offset * CPUSTATES);
} }
} }
@ -218,9 +218,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) {
unsigned long long total_n = 0; unsigned long long total_n = 0;
unsigned long long total_d = 0; unsigned long long total_d = 0;
for (int s = 0; s < CPUSTATES; s++) { for (int s = 0; s < CPUSTATES; s++) {
cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; cp_time_d[s] = cp_time_n[s] - cp_time_o[s];
total_o += cp_time_o[s]; total_o += cp_time_o[s];
total_n += cp_time_n[s]; total_n += cp_time_n[s];
} }
// totals // totals
@ -229,8 +229,8 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) {
// save current state as old and calc percentages // save current state as old and calc percentages
for (int s = 0; s < CPUSTATES; ++s) { for (int s = 0; s < CPUSTATES; ++s) {
cp_time_o[s] = cp_time_n[s]; cp_time_o[s] = cp_time_n[s];
cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100;
} }
CPUData* cpuData = &(fpl->cpus[i]); CPUData* cpuData = &(fpl->cpus[i]);

View File

@ -165,10 +165,10 @@ double Platform_setCPUValues(Meter* this, int cpu) {
const CPUData* cpuData; const CPUData* cpuData;
if (cpus == 1) { if (cpus == 1) {
// single CPU box has everything in fpl->cpus[0] // single CPU box has everything in fpl->cpus[0]
cpuData = &(fpl->cpus[0]); cpuData = &(fpl->cpus[0]);
} else { } else {
cpuData = &(fpl->cpus[cpu]); cpuData = &(fpl->cpus[cpu]);
} }
double percent; double percent;

View File

@ -194,11 +194,11 @@ bool LinuxProcess_setIOPriority(Process* this, Arg ioprio) {
#ifdef HAVE_DELAYACCT #ifdef HAVE_DELAYACCT
void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) { void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) {
if (isnan(delay_percent)) { if (isnan(delay_percent)) {
xSnprintf(buffer, n, " N/A "); xSnprintf(buffer, n, " N/A ");
} else { } else {
xSnprintf(buffer, n, "%4.1f ", delay_percent); xSnprintf(buffer, n, "%4.1f ", delay_percent);
} }
} }
#endif #endif
@ -379,7 +379,8 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
default: default:
return Process_compare(v1, v2); return Process_compare(v1, v2);
} }
test_diff:
test_diff:
return (diff > 0) ? 1 : (diff < 0 ? -1 : 0); return (diff > 0) ? 1 : (diff < 0 ? -1 : 0);
} }

View File

@ -419,20 +419,20 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
while ((line = strsep(&buf, "\n")) != NULL) { while ((line = strsep(&buf, "\n")) != NULL) {
switch (line[0]) { switch (line[0]) {
case 'r': case 'r':
if (line[1] == 'c' && String_startsWith(line+2, "har: ")) if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
process->io_rchar = strtoull(line+7, NULL, 10); process->io_rchar = strtoull(line + 7, NULL, 10);
else if (String_startsWith(line+1, "ead_bytes: ")) { } else if (String_startsWith(line + 1, "ead_bytes: ")) {
process->io_read_bytes = strtoull(line+12, NULL, 10); process->io_read_bytes = strtoull(line + 12, NULL, 10);
process->io_rate_read_bps = process->io_rate_read_bps =
((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000);
process->io_rate_read_time = now; process->io_rate_read_time = now;
} }
break; break;
case 'w': case 'w':
if (line[1] == 'c' && String_startsWith(line+2, "har: ")) if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
process->io_wchar = strtoull(line+7, NULL, 10); process->io_wchar = strtoull(line + 7, NULL, 10);
else if (String_startsWith(line+1, "rite_bytes: ")) { } else if (String_startsWith(line + 1, "rite_bytes: ")) {
process->io_write_bytes = strtoull(line+13, NULL, 10); process->io_write_bytes = strtoull(line + 13, NULL, 10);
process->io_rate_write_bps = process->io_rate_write_bps =
((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000);
process->io_rate_write_time = now; process->io_rate_write_time = now;
@ -446,8 +446,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
} }
break; break;
case 'c': case 'c':
if (String_startsWith(line+1, "ancelled_write_bytes: ")) { if (String_startsWith(line + 1, "ancelled_write_bytes: ")) {
process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10); process->io_cancelled_write_bytes = strtoull(line + 23, NULL, 10);
} }
} }
} }
@ -1087,7 +1087,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
continue; continue;
// Exception handler. // Exception handler.
errorReadingProcess: {
errorReadingProcess:
{
if (preExisting) { if (preExisting) {
ProcessList_remove(pl, proc); ProcessList_remove(pl, proc);
} else { } else {

View File

@ -24,24 +24,24 @@ static const int PressureStallMeter_attributes[] = {
}; };
static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) { static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) {
const char *file; const char* file;
if (strstr(Meter_name(this), "CPU")) { if (strstr(Meter_name(this), "CPU")) {
file = "cpu"; file = "cpu";
} else if (strstr(Meter_name(this), "IO")) { } else if (strstr(Meter_name(this), "IO")) {
file = "io"; file = "io";
} else { } else {
file = "memory"; file = "memory";
} }
bool some; bool some;
if (strstr(Meter_name(this), "Some")) { if (strstr(Meter_name(this), "Some")) {
some = true; some = true;
} else { } else {
some = false; some = false;
} }
Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
} }
static void PressureStallMeter_display(const Object* cast, RichString* out) { static void PressureStallMeter_display(const Object* cast, RichString* out) {

View File

@ -32,127 +32,152 @@ ProcessFieldData Process_fields[] = {
.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

@ -254,7 +254,7 @@ char* Platform_getProcessEnv(pid_t pid) {
return NULL; return NULL;
if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid, if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid,
sizeof(struct kinfo_proc), &count)) == NULL) {\ sizeof(struct kinfo_proc), &count)) == NULL) {
(void) kvm_close(kt); (void) kvm_close(kt);
return NULL; return NULL;
} }
@ -278,10 +278,10 @@ char* Platform_getProcessEnv(pid_t pid) {
} }
if (size < 2 || env[size - 1] || env[size - 2]) { if (size < 2 || env[size - 1] || env[size - 2]) {
if (size + 2 < capacity) if (size + 2 < capacity)
env = xRealloc(env, capacity + 2); env = xRealloc(env, capacity + 2);
env[size] = 0; env[size] = 0;
env[size+1] = 0; env[size + 1] = 0;
} }
(void) kvm_close(kt); (void) kvm_close(kt);

View File

@ -172,10 +172,10 @@ double Platform_setCPUValues(Meter* this, int cpu) {
const CPUData* cpuData = NULL; const CPUData* cpuData = NULL;
if (cpus == 1) { if (cpus == 1) {
// single CPU box has everything in spl->cpus[0] // single CPU box has everything in spl->cpus[0]
cpuData = &(spl->cpus[0]); cpuData = &(spl->cpus[0]);
} else { } else {
cpuData = &(spl->cpus[cpu]); cpuData = &(spl->cpus[cpu]);
} }
double percent; double percent;

View File

@ -29,16 +29,18 @@ in the source distribution for its full text.
#define MAXCMDLINE 255 #define MAXCMDLINE 255
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
char* zname; char* zname;
if ( sproc->zoneid == 0 ) {
zname = xStrdup(GZONE); if ( sproc->zoneid == 0 ) {
} else if ( kd == NULL ) { zname = xStrdup(GZONE);
zname = xStrdup(UZONE); } else if ( kd == NULL ) {
} else { zname = xStrdup(UZONE);
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); } else {
zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
} zname = xStrdup(ks == NULL ? UZONE : ks->ks_name);
return zname; }
return zname;
} }
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
@ -78,15 +80,19 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
assert(cpus > 0); assert(cpus > 0);
if (cpus > 1) { if (cpus > 1) {
// Store values for the stats loop one extra element up in the array // Store values for the stats loop one extra element up in the array
// to leave room for the average to be calculated afterwards // to leave room for the average to be calculated afterwards
arrskip++; arrskip++;
} }
// Calculate per-CPU statistics first // Calculate per-CPU statistics first
for (int i = 0; i < cpus; i++) { for (int i = 0; i < cpus; i++) {
if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); } if (spl->kd != NULL) {
if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); } cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys");
}
if (cpuinfo != NULL) {
kchain = kstat_read(spl->kd, cpuinfo, NULL);
}
if (kchain != -1 ) { if (kchain != -1 ) {
idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle"); idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle");
intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr"); intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr");
@ -170,7 +176,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
// Not really "buffers" but the best Solaris analogue that I can find to // Not really "buffers" but the best Solaris analogue that I can find to
// "memory in use but not by programs or the kernel itself" // "memory in use but not by programs or the kernel itself"
pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB; pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB;
} else { } else {
// Fall back to basic sysconf if kstat isn't working // Fall back to basic sysconf if kstat isn't working
pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize; pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize;
pl->buffersMem = 0; pl->buffersMem = 0;
@ -180,8 +186,12 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
// Part 2 - swap // Part 2 - swap
nswap = swapctl(SC_GETNSWP, NULL); nswap = swapctl(SC_GETNSWP, NULL);
if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); } if (nswap > 0) {
if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); } sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int));
}
if (sl != NULL) {
spathbase = xMalloc( nswap * MAXPATHLEN );
}
if (spathbase != NULL) { if (spathbase != NULL) {
spath = spathbase; spath = spathbase;
swapdev = sl->swt_ent; swapdev = sl->swt_ent;
@ -211,8 +221,12 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) {
int ksrphyserr = -1; int ksrphyserr = -1;
kstat_named_t *cur_kstat = NULL; kstat_named_t *cur_kstat = NULL;
if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); } if (spl->kd != NULL) {
if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd, arcstats, NULL); } arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats");
}
if (arcstats != NULL) {
ksrphyserr = kstat_read(spl->kd, arcstats, NULL);
}
if (ksrphyserr != -1) { if (ksrphyserr != -1) {
cur_kstat = kstat_data_lookup( arcstats, "size" ); cur_kstat = kstat_data_lookup( arcstats, "size" );
spl->zfs.size = cur_kstat->value.ui64 / 1024; spl->zfs.size = cur_kstat->value.ui64 / 1024;

View File

@ -30,43 +30,43 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
if (pauseProcessUpdate) if (pauseProcessUpdate)
return; return;
bool preExisting = true; bool preExisting = true;
Process *proc; Process* proc;
proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new);
/* Empty values */ /* Empty values */
proc->time = proc->time + 10; proc->time = proc->time + 10;
proc->pid = 1; proc->pid = 1;
proc->ppid = 1; proc->ppid = 1;
proc->tgid = 0; proc->tgid = 0;
proc->comm = "<unsupported architecture>"; proc->comm = "<unsupported architecture>";
proc->basenameOffset = 0; proc->basenameOffset = 0;
proc->updated = true; proc->updated = true;
proc->state = 'R'; proc->state = 'R';
proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */
proc->pgrp = 0; proc->pgrp = 0;
proc->session = 0; proc->session = 0;
proc->tty_nr = 0; proc->tty_nr = 0;
proc->tpgid = 0; proc->tpgid = 0;
proc->st_uid = 0; proc->st_uid = 0;
proc->flags = 0; proc->flags = 0;
proc->processor = 0; proc->processor = 0;
proc->percent_cpu = 2.5; proc->percent_cpu = 2.5;
proc->percent_mem = 2.5; proc->percent_mem = 2.5;
proc->user = "nobody"; proc->user = "nobody";
proc->priority = 0; proc->priority = 0;
proc->nice = 0; proc->nice = 0;
proc->nlwp = 1; proc->nlwp = 1;
proc->starttime_ctime = 1433116800; // Jun 01, 2015 proc->starttime_ctime = 1433116800; // Jun 01, 2015
Process_fillStarttimeBuffer(proc); Process_fillStarttimeBuffer(proc);
proc->m_size = 100; proc->m_size = 100;
proc->m_resident = 100; proc->m_resident = 100;
proc->minflt = 20; proc->minflt = 20;
proc->majflt = 20; proc->majflt = 20;
} }

View File

@ -33,21 +33,24 @@ void openzfs_sysctl_init(ZfsArcStats *stats) {
len = sizeof(arcSize); len = sizeof(arcSize);
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) { if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) {
stats->enabled = 1; stats->enabled = 1;
len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); len = 5;
sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len);
if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) { sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len);
stats->isCompressed = 1; sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len);
} else {
stats->isCompressed = 0; if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) {
} stats->isCompressed = 1;
sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len);
} else {
stats->isCompressed = 0;
}
} else { } else {
stats->enabled = 0; stats->enabled = 0;
} }