From 0a51eae11fdd741c295d7b0390c6d9dbf04468d8 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:39:01 +0100 Subject: Spacing after keywords (while) --- darwin/Platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'darwin') diff --git a/darwin/Platform.c b/darwin/Platform.c index b1f9283d..17be92b2 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -286,7 +286,7 @@ char* Platform_getProcessEnv(pid_t pid) { p = strchr(p, 0)+1; // skip padding - while(!*p && p < endp) + while (!*p && p < endp) ++p; // skip argv @@ -294,7 +294,7 @@ char* Platform_getProcessEnv(pid_t pid) { ; // skip padding - while(!*p && p < endp) + while (!*p && p < endp) ++p; size_t size = endp - p; -- cgit v1.2.3 From 374edb9ed5e9d5fa24cfe358258d82f69d9d430d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:52:20 +0100 Subject: Spacing after keywords (if) --- darwin/Battery.c | 10 +++++----- darwin/DarwinProcess.c | 6 +++--- darwin/DarwinProcessList.c | 10 +++++----- darwin/Platform.c | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'darwin') diff --git a/darwin/Battery.c b/darwin/Battery.c index d82d0ffd..df644643 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -13,7 +13,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { *level = NAN; *isOnAC = AC_ERROR; - if(NULL == power_sources) { + if (NULL == power_sources) { return; } @@ -21,7 +21,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFDictionaryRef battery = NULL; int len; - if(NULL == list) { + if (NULL == list) { CFRelease(power_sources); return; @@ -35,18 +35,18 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; - if(NULL != candidate) { + if (NULL != candidate) { type = (CFStringRef) CFDictionaryGetValue(candidate, CFSTR(kIOPSTransportTypeKey)); /* GET rule */ - if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { + if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { CFRetain(candidate); battery = candidate; } } } - if(NULL != battery) { + if (NULL != battery) { /* Determine the AC state */ CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 73214836..8ad7a6d8 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -212,7 +212,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e */ /* First, the "immutable" parts */ - if(!exists) { + if (!exists) { /* Set the PID/PGID/etc. */ proc->pid = ep->p_pid; proc->ppid = ps->kp_eproc.e_ppid; @@ -244,8 +244,8 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) { struct proc_taskinfo pti; - if(sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { - if(0 != proc->utime || 0 != proc->stime) { + 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); diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index bae8e222..59ec9d31 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -57,14 +57,14 @@ int CompareKernelVersion(short int major, short int minor, short int component) 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)) { + if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { 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)) { + if (NULL != p && NULL != *p) { + if (0 != munmap(*p, vm_page_size)) { CRT_fatalError("Unable to free old CPU load information\n"); } *p = NULL; @@ -76,7 +76,7 @@ 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)) { + 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"); } @@ -200,7 +200,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { super->totalTasks += 1; - if(!preExisting) { + if (!preExisting) { proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); ProcessList_add(super, &proc->super); diff --git a/darwin/Platform.c b/darwin/Platform.c index 17be92b2..a7adaeee 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -149,7 +149,7 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { double results[3]; - if(3 == getloadavg(results, 3)) { + if (3 == getloadavg(results, 3)) { *one = results[0]; *five = results[1]; *fifteen = results[2]; -- cgit v1.2.3 From adf797c295db2e0b24cc49efc7af70dafc3f10c2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:55:36 +0100 Subject: Spacing after keywords (for) --- darwin/Battery.c | 2 +- darwin/DarwinProcessList.c | 6 +++--- darwin/Platform.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'darwin') diff --git a/darwin/Battery.c b/darwin/Battery.c index df644643..854425b3 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -30,7 +30,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { len = CFArrayGetCount(list); /* 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, CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 59ec9d31..3f72a3a7 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -164,8 +164,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { /* 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) { + 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]; } } @@ -185,7 +185,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { */ 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); DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); diff --git a/darwin/Platform.c b/darwin/Platform.c index a7adaeee..9086c6de 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -206,7 +206,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { double total = 0; /* Take the sums */ - for(size_t i = 0; i < CPU_STATE_MAX; ++i) { + for (size_t i = 0; i < CPU_STATE_MAX; ++i) { total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i]; } -- cgit v1.2.3 From b23f8235e28472c410dcb00893e0e3d403892673 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 22:14:27 +0100 Subject: Whitespace and indentation issues --- darwin/Battery.c | 12 +-- darwin/DarwinProcess.c | 18 ++--- darwin/DarwinProcessList.c | 178 ++++++++++++++++++++++++--------------------- darwin/Platform.c | 18 ++--- 4 files changed, 119 insertions(+), 107 deletions(-) (limited to 'darwin') diff --git a/darwin/Battery.c b/darwin/Battery.c index 854425b3..c89f5b30 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -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); @@ -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, ¤t); + kCFNumberDoubleType, ¤t); CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), - kCFNumberDoubleType, &max); + kCFNumberDoubleType, &max); *level = (current * 100.0) / max; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 8ad7a6d8..a92f2661 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -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; + } + } } /* @@ -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); @@ -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; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 3f72a3a7..bb7c56db 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -24,7 +24,7 @@ in the source distribution for its full text. #include struct kern { - short int version[3]; + short int version[3]; }; void GetKernelVersion(struct kern *k) { @@ -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: @@ -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; } } @@ -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) { @@ -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); } diff --git a/darwin/Platform.c b/darwin/Platform.c index 9086c6de..c5a22da4 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -211,11 +211,11 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } 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] - = ((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] - = ((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; @@ -239,13 +239,13 @@ void Platform_setMemoryValues(Meter* mtr) { } void Platform_setSwapValues(Meter* mtr) { - int mib[2] = {CTL_VM, VM_SWAPUSAGE}; - struct xsw_usage swapused; - size_t swlen = sizeof(swapused); - sysctl(mib, 2, &swapused, &swlen, NULL, 0); + int mib[2] = {CTL_VM, VM_SWAPUSAGE}; + struct xsw_usage swapused; + size_t swlen = sizeof(swapused); + sysctl(mib, 2, &swapused, &swlen, NULL, 0); - mtr->total = swapused.xsu_total / 1024; - mtr->values[0] = swapused.xsu_used / 1024; + mtr->total = swapused.xsu_total / 1024; + mtr->values[0] = swapused.xsu_used / 1024; } void Platform_setZfsArcValues(Meter* this) { -- cgit v1.2.3 From 61e14d4bb25268593019e6df3eb02264b4ac8e0e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 23:28:02 +0100 Subject: Spacing around operators --- darwin/DarwinProcess.c | 12 ++++++------ darwin/DarwinProcess.h | 8 ++++---- darwin/DarwinProcessList.c | 12 ++++++------ darwin/DarwinProcessList.h | 10 +++++----- darwin/Platform.c | 26 +++++++++++++------------- darwin/Platform.h | 8 ++++---- 6 files changed, 38 insertions(+), 38 deletions(-) (limited to 'darwin') diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index a92f2661..c06ec4a6 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -52,7 +52,7 @@ bool Process_isThread(const Process* this) { return false; } -char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { +char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { /* This function is from the old Mac version of htop. Originally from ps? */ int mib[3], argmax, nargs, c = 0; size_t size; @@ -68,7 +68,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { } /* Allocate space for the arguments. */ - procargs = ( char * ) xMalloc( argmax ); + procargs = (char*)xMalloc(argmax); if ( procargs == NULL ) { goto ERROR_A; } @@ -195,8 +195,8 @@ ERROR_A: return retval; } -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists) { - struct extern_proc *ep = &ps->kp_proc; +void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists) { + struct extern_proc* ep = &ps->kp_proc; /* UNSET HERE : * @@ -241,7 +241,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e proc->updated = true; } -void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) { +void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl) { struct proc_taskinfo pti; if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { @@ -280,7 +280,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c */ -void DarwinProcess_scanThreads(DarwinProcess *dp) { +void DarwinProcess_scanThreads(DarwinProcess* dp) { Process* proc = (Process*) dp; kern_return_t ret; diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index 1d9dc34a..627a6bcb 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -28,17 +28,17 @@ void Process_delete(Object* cast); bool Process_isThread(const Process* this); -char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); +char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists); +void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists); -void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl); +void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl); /* * Scan threads for process state information. * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c */ -void DarwinProcess_scanThreads(DarwinProcess *dp); +void DarwinProcess_scanThreads(DarwinProcess* dp); #endif diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index bb7c56db..673d9e61 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -27,7 +27,7 @@ struct kern { short int version[3]; }; -void GetKernelVersion(struct kern *k) { +void GetKernelVersion(struct kern* k) { static short int version_[3] = {0}; if (!version_[0]) { // just in case it fails someday @@ -64,7 +64,7 @@ int CompareKernelVersion(short int major, short int minor, short int 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; if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { @@ -72,7 +72,7 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) { } } -void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { +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"); @@ -81,7 +81,7 @@ void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { } } -unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { +unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p) { mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t); unsigned cpu_count; @@ -101,9 +101,9 @@ void ProcessList_getVMStats(vm_statistics_t p) { } } -struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { +struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; - struct kinfo_proc *processes = NULL; + struct kinfo_proc* processes = NULL; /* Note the two calls to sysctl(). One to get length and one to get the * data. This -does- mean that the second call could end up with a missing diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 44a847dc..bdcbb183 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -9,7 +9,7 @@ in the source distribution for its full text. struct kern; -void GetKernelVersion(struct kern *k); +void GetKernelVersion(struct kern* k); /* compare the given os version with the one installed returns: 0 if equals the installed version @@ -37,15 +37,15 @@ typedef struct DarwinProcessList_ { ZfsArcStats zfs; } DarwinProcessList; -void ProcessList_getHostInfo(host_basic_info_data_t *p); +void ProcessList_getHostInfo(host_basic_info_data_t* p); -void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p); +void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t* p); -unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p); +unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p); void ProcessList_getVMStats(vm_statistics_t p); -struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count); +struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/darwin/Platform.c b/darwin/Platform.c index c5a22da4..e48fbbd3 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -176,7 +176,7 @@ ProcessPidColumn Process_pidColumns[] = { }; static double Platform_setCPUAverageValues(Meter* mtr) { - const ProcessList *dpl = mtr->pl; + const ProcessList* dpl = mtr->pl; int cpus = dpl->cpuCount; double sumNice = 0.0; double sumNormal = 0.0; @@ -200,9 +200,9 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { return Platform_setCPUAverageValues(mtr); } - const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; - const processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; - const processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; + const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl; + const processor_cpu_load_info_t prev = &dpl->prev_load[cpu - 1]; + const processor_cpu_load_info_t curr = &dpl->curr_load[cpu - 1]; double total = 0; /* Take the sums */ @@ -228,7 +228,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } void Platform_setMemoryValues(Meter* mtr) { - const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; + const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl; const struct vm_statistics* vm = &dpl->vm_stats; double page_K = (double)vm_page_size / (double)1024; @@ -283,14 +283,14 @@ char* Platform_getProcessEnv(pid_t pid) { p += sizeof(int); // skip exe - p = strchr(p, 0)+1; + p = strchr(p, 0) + 1; // skip padding while (!*p && p < endp) ++p; // skip argv - for (; argc-- && p < endp; p = strrchr(p, 0)+1) + for (; argc-- && p < endp; p = strrchr(p, 0) + 1) ; // skip padding @@ -298,10 +298,10 @@ char* Platform_getProcessEnv(pid_t pid) { ++p; size_t size = endp - p; - env = xMalloc(size+2); + env = xMalloc(size + 2); memcpy(env, p, size); env[size] = 0; - env[size+1] = 0; + env[size + 1] = 0; } } free(buf); @@ -317,10 +317,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/darwin/Platform.h b/darwin/Platform.h index 471b38a9..7d3f4197 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -51,9 +51,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif -- cgit v1.2.3 From 45869513bfebba80cc2ab42e4218f68b34b1e6ac Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 1 Nov 2020 01:09:51 +0100 Subject: Embracing branches --- darwin/DarwinProcessList.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'darwin') diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 673d9e61..99f49d5c 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -110,15 +110,18 @@ struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) { * process entry or two. */ *count = 0; - if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) + if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) { CRT_fatalError("Unable to get size of kproc_infos"); + } processes = xMalloc(*count); - if (processes == NULL) + if (processes == NULL) { CRT_fatalError("Out of memory for kproc_infos"); + } - if (sysctl(mib, 4, processes, count, NULL, 0) < 0) + if (sysctl(mib, 4, processes, count, NULL, 0) < 0) { CRT_fatalError("Unable to get kinfo_procs"); + } *count = *count / sizeof(struct kinfo_proc); -- cgit v1.2.3