Skip to content

Commit

Permalink
Whitespace and indentation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed Nov 2, 2020
1 parent 9a16b10 commit b23f823
Show file tree
Hide file tree
Showing 24 changed files with 368 additions and 309 deletions.
2 changes: 1 addition & 1 deletion Affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) {
} else {
unsigned int id;
hwloc_bitmap_foreach_begin(id, cpuset);
Affinity_add(affinity, id);
Affinity_add(affinity, id);
hwloc_bitmap_foreach_end();
}
}
Expand Down
4 changes: 2 additions & 2 deletions AffinityPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u
left -= len;
}
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
//size_t len = strlen(&indent_buf[off]);
//off += len;
Expand Down Expand Up @@ -417,7 +417,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
#ifdef HAVE_LIBHWLOC
int i;
hwloc_bitmap_foreach_begin(i, this->workCpuset)
Affinity_add(affinity, i);
Affinity_add(affinity, i);
hwloc_bitmap_foreach_end();
#else
for (int i = 0; i < this->pl->cpuCount; i++) {
Expand Down
2 changes: 1 addition & 1 deletion IncSet.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
doSearch = false;
}
} else if (ch == KEY_RESIZE) {
Panel_resize(panel, COLS, LINES-panel->y-1);
Panel_resize(panel, COLS, LINES - panel->y - 1);
} else {
if (mode->isFilter) {
filterChanged = true;
Expand Down
4 changes: 2 additions & 2 deletions ListItem.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ static void ListItem_display(const Object* cast, RichString* out) {
if (this->moving) {
RichString_write(out, CRT_colors[DEFAULT_COLOR],
#ifdef HAVE_LIBNCURSESW
CRT_utf8 ? "↕ " :
CRT_utf8 ? "↕ " :
#endif
"+ ");
"+ ");
} else {
RichString_prune(out);
}
Expand Down
4 changes: 2 additions & 2 deletions Panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void Panel_draw(Panel* this, bool focus) {
int upTo = MINIMUM(first + h, size);

int selectionColor = focus
? this->selectionColor
: CRT_colors[PANEL_SELECTION_UNFOCUS];
? this->selectionColor
: CRT_colors[PANEL_SELECTION_UNFOCUS];

if (this->needsRedraw) {
int line = 0;
Expand Down
4 changes: 2 additions & 2 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field

for (int i = 0; i < 32; i++)
if (indent & (1U << i))
maxIndent = i+1;
for (int i = 0; i < maxIndent - 1; i++) {
maxIndent = i + 1;
for (int i = 0; i < maxIndent - 1; i++) {
int written, ret;
if (indent & (1 << i))
ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
Expand Down
5 changes: 3 additions & 2 deletions Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
this->delay = atoi(option[1]);
} else if (String_eq(option[0], "color_scheme")) {
this->colorScheme = atoi(option[1]);
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
} else if (String_eq(option[0], "enable_mouse")) {
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME)
this->colorScheme = 0;
} else if (String_eq(option[0], "enable_mouse")) {
this->enableMouse = atoi(option[1]);
} else if (String_eq(option[0], "left_meters")) {
Settings_readMeters(this, option[1], 0);
Expand Down
12 changes: 6 additions & 6 deletions darwin/Battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
/* Get the battery */
for (int i = 0; i < len && battery == NULL; ++i) {
CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
CFArrayGetValueAtIndex(list, i)); /* GET rule */
CFArrayGetValueAtIndex(list, i)); /* GET rule */
CFStringRef type;

if (NULL != candidate) {
type = (CFStringRef) CFDictionaryGetValue(candidate,
CFSTR(kIOPSTransportTypeKey)); /* GET rule */
CFSTR(kIOPSTransportTypeKey)); /* GET rule */

if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
CFRetain(candidate);
Expand All @@ -51,17 +51,17 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));

*isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
? AC_PRESENT
: AC_ABSENT;
? AC_PRESENT
: AC_ABSENT;

/* Get the percentage remaining */
double current;
double max;

CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
kCFNumberDoubleType, &current);
kCFNumberDoubleType, &current);
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
kCFNumberDoubleType, &max);
kCFNumberDoubleType, &max);

*level = (current * 100.0) / max;

Expand Down
18 changes: 9 additions & 9 deletions darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
/* Convert previous '\0'. */
*np = ' ';
}
/* Note location of current '\0'. */
np = cp;
if (*basenameOffset == 0) {
*basenameOffset = cp - sp;
}
}
/* Note location of current '\0'. */
np = cp;
if (*basenameOffset == 0) {
*basenameOffset = cp - sp;
}
}
}

/*
Expand Down Expand Up @@ -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 (0 != proc->utime || 0 != 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
/ ((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,
// proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff);
Expand All @@ -263,7 +263,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
proc->super.m_resident = pti.pti_resident_size / CRT_pageSize;
proc->super.majflt = pti.pti_faults;
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->utime = pti.pti_total_user;
Expand Down
178 changes: 95 additions & 83 deletions darwin/DarwinProcessList.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ in the source distribution for its full text.
#include <stdbool.h>

struct kern {
short int version[3];
short int version[3];
};

void GetKernelVersion(struct kern *k) {
Expand All @@ -35,9 +35,11 @@ void GetKernelVersion(struct kern *k) {
char str[256] = {0};
size_t size = sizeof(str);
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
}
memcpy(k->version, version_, sizeof(version_));
if (ret == 0) {
sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
}
}
memcpy(k->version, version_, sizeof(version_));
}

/* compare the given os version with the one installed returns:
Expand All @@ -46,28 +48,36 @@ positive value if less than the installed version
negative value if more than the installed version
*/
int CompareKernelVersion(short int major, short int minor, short int component) {
struct kern 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[2] != component) return k.version[2] - component;
return 0;
struct kern 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[2] != component) {
return k.version[2] - component;
}

return 0;
}

void ProcessList_getHostInfo(host_basic_info_data_t *p) {
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)) {
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) {
if (NULL != p && NULL != *p) {
if (0 != munmap(*p, vm_page_size)) {
CRT_fatalError("Unable to free old CPU load information\n");
}
*p = NULL;
if (0 != munmap(*p, vm_page_size)) {
CRT_fatalError("Unable to free old CPU load information\n");
}
*p = NULL;
}
}

Expand All @@ -76,18 +86,19 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
unsigned cpu_count;

// 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)) {
CRT_fatalError("Unable to retrieve CPU info\n");
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");
}

return cpu_count;
}

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)
CRT_fatalError("Unable to retrieve VM statistics\n");
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) {
CRT_fatalError("Unable to retrieve VM statistics\n");
}
}

struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
Expand Down Expand Up @@ -145,67 +156,68 @@ void ProcessList_delete(ProcessList* this) {
}

void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
DarwinProcessList *dpl = (DarwinProcessList *)super;
bool preExisting = true;
struct kinfo_proc *ps;
size_t count;
DarwinProcess *proc;

/* Update the global data (CPU times and VM stats) */
ProcessList_freeCPULoadInfo(&dpl->prev_load);
dpl->prev_load = dpl->curr_load;
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
ProcessList_getVMStats(&dpl->vm_stats);
openzfs_sysctl_updateArcStats(&dpl->zfs);

// in pause mode only gather global data for meters (CPU/memory/...)
if (pauseProcessUpdate)
return;

/* Get the time difference */
dpl->global_diff = 0;
for (int i = 0; i < dpl->super.cpuCount; ++i) {
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];
}
}

/* Clear the thread counts */
super->kernelThreads = 0;
super->userlandThreads = 0;
super->totalTasks = 0;
super->runningTasks = 0;

/* We use kinfo_procs for initial data since :
*
* 1) They always succeed.
* 2) The contain the basic information.
*
* We attempt to fill-in additional information with libproc.
*/
ps = ProcessList_getKInfoProcs(&count);

for (size_t i = 0; i < count; ++i) {
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);

DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl);

// Disabled for High Sierra due to bug in macOS High Sierra
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);

if (isScanThreadSupported){
DarwinProcess_scanThreads(proc);
}

super->totalTasks += 1;

if (!preExisting) {
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);

ProcessList_add(super, &proc->super);
}
}

free(ps);
DarwinProcessList* dpl = (DarwinProcessList*)super;
bool preExisting = true;
struct kinfo_proc* ps;
size_t count;
DarwinProcess* proc;

/* Update the global data (CPU times and VM stats) */
ProcessList_freeCPULoadInfo(&dpl->prev_load);
dpl->prev_load = dpl->curr_load;
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
ProcessList_getVMStats(&dpl->vm_stats);
openzfs_sysctl_updateArcStats(&dpl->zfs);

// in pause mode only gather global data for meters (CPU/memory/...)
if (pauseProcessUpdate) {
return;
}

/* Get the time difference */
dpl->global_diff = 0;
for (int i = 0; i < dpl->super.cpuCount; ++i) {
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];
}
}

/* Clear the thread counts */
super->kernelThreads = 0;
super->userlandThreads = 0;
super->totalTasks = 0;
super->runningTasks = 0;

/* We use kinfo_procs for initial data since :
*
* 1) They always succeed.
* 2) The contain the basic information.
*
* We attempt to fill-in additional information with libproc.
*/
ps = ProcessList_getKInfoProcs(&count);

for (size_t i = 0; i < count; ++i) {
proc = (DarwinProcess*)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);

DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl);

// Disabled for High Sierra due to bug in macOS High Sierra
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);

if (isScanThreadSupported) {
DarwinProcess_scanThreads(proc);
}

super->totalTasks += 1;

if (!preExisting) {
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);

ProcessList_add(super, &proc->super);
}
}

free(ps);
}
Loading

0 comments on commit b23f823

Please sign in to comment.