diff options
author | Daniel Lange <DLange@git.local> | 2020-11-15 14:32:41 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-11-15 14:33:09 +0100 |
commit | bb908f3dc4ac5847592e9698dec150658067e84e (patch) | |
tree | fb0d7b03602de14f4ba6efbdd9f8a9f3cf7cc067 /openbsd | |
parent | da2dcf9505299eae607e29cc85691b8163c1a36e (diff) | |
parent | e7b95feee4f375738cb339a58337fdab83f6abbf (diff) |
Resolve merge conflicts, merge #298 "Macro cleanup" from @BenBE
Diffstat (limited to 'openbsd')
-rw-r--r-- | openbsd/Battery.c | 2 | ||||
-rw-r--r-- | openbsd/OpenBSDProcess.c | 75 | ||||
-rw-r--r-- | openbsd/OpenBSDProcessList.c | 15 | ||||
-rw-r--r-- | openbsd/OpenBSDProcessList.h | 2 | ||||
-rw-r--r-- | openbsd/Platform.c | 43 | ||||
-rw-r--r-- | openbsd/Platform.h | 8 |
6 files changed, 87 insertions, 58 deletions
diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 232b1255..b72253e0 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -53,7 +53,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { mib[4] = 3; if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { double charge = s.value; - *level = 100*(charge / last_full_capacity); + *level = 100 * (charge / last_full_capacity); if (charge >= last_full_capacity) { *level = 100; } diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index c43fe2fc..5eb61b16 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -32,127 +32,152 @@ ProcessFieldData Process_fields[] = { .name = "", .title = NULL, .description = NULL, - .flags = 0, }, + .flags = 0, + }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", - .flags = 0, }, + .flags = 0, + }, [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", - .flags = 0, }, + .flags = 0, + }, [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", - .flags = 0, }, + .flags = 0, + }, [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", - .flags = 0, }, + .flags = 0, + }, [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", - .flags = 0, }, + .flags = 0, + }, [SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", - .flags = 0, }, + .flags = 0, + }, [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", - .flags = 0, }, + .flags = 0, + }, [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", - .flags = 0, }, + .flags = 0, + }, [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", - .flags = 0, }, + .flags = 0, + }, [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", - .flags = 0, }, + .flags = 0, + }, [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", - .flags = 0, }, + .flags = 0, + }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", - .flags = 0, }, + .flags = 0, + }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", - .flags = 0, }, + .flags = 0, + }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", - .flags = 0, }, + .flags = 0, + }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", - .flags = 0, }, + .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, }, + .flags = 0, + }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", - .flags = 0, }, + .flags = 0, + }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", - .flags = 0, }, + .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, }, + .flags = 0, + }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", - .flags = 0, }, + .flags = 0, + }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", - .flags = 0, }, + .flags = 0, + }, [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", - .flags = 0, }, + .flags = 0, + }, [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", - .flags = 0, }, + .flags = 0, + }, [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, - .flags = 0, }, + .flags = 0, + }, }; ProcessPidColumn Process_pidColumns[] = { diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 86e2dca6..aec13477 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -56,7 +56,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui } for (i = 0; i <= pl->cpuCount; i++) { - CPUData *d = opl->cpus + i; + CPUData* d = opl->cpus + i; d->totalTime = 1; d->totalPeriod = 1; } @@ -134,7 +134,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { */ } -char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { +char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { char *s, **arg; size_t len = 0, n; int i; @@ -163,7 +163,7 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in n = strlcat(s, arg[i], len); if (i == 0) { /* TODO: rename all basenameEnd to basenameLen, make size_t */ - *basenameEnd = MINIMUM(n, len-1); + *basenameEnd = MINIMUM(n, len - 1); } /* the trailing space should get truncated anyway */ strlcat(s, " ", len); @@ -175,9 +175,9 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in /* * Taken from OpenBSD's ps(1). */ -static double getpcpu(const struct kinfo_proc *kp) { +static double getpcpu(const struct kinfo_proc* kp) { if (fscale == 0) - return (0.0); + return 0.0; #define fxtofl(fixpt) ((double)(fixpt) / fscale) @@ -232,7 +232,7 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { proc->m_size = kproc->p_vm_dsize; proc->m_resident = kproc->p_vm_rssize; proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->super.totalMem) * 100.0; - proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount*100.0); + proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount * 100.0); //proc->nlwp = kproc->p_numthreads; //proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10); proc->nice = kproc->p_nice - 20; @@ -347,8 +347,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { OpenBSDProcessList_scanCPUTime(opl); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } OpenBSDProcessList_scanProcs(opl); } diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 7ee48c63..1b40faf1 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -43,7 +43,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); +char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index a24d6a2d..8e2a5822 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -162,7 +162,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData = &(pl->cpus[cpu]); double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; double totalPercent; - double *v = this->values; + double* v = this->values; v[CPU_METER_NICE] = cpuData->nicePeriod / total * 100.0; v[CPU_METER_NORMAL] = cpuData->userPeriod / total * 100.0; @@ -175,16 +175,18 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_IOWAIT] = 0.0; v[CPU_METER_FREQUENCY] = NAN; this->curItems = 8; - totalPercent = v[0]+v[1]+v[2]+v[3]; + totalPercent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->sysAllPeriod / total * 100.0; v[3] = 0.0; // No steal nor guest on OpenBSD - totalPercent = v[0]+v[1]+v[2]; + totalPercent = v[0] + v[1] + v[2]; this->curItems = 4; } totalPercent = CLAMP(totalPercent, 0.0, 100.0); - if (isnan(totalPercent)) totalPercent = 0.0; + if (isnan(totalPercent)) { + totalPercent = 0.0; + } return totalPercent; } @@ -208,7 +210,7 @@ void Platform_setMemoryValues(Meter* this) { */ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; - struct swapent *swdev; + struct swapent* swdev; unsigned long long int total, used; int nswap, rnswap, i; nswap = swapctl(SWAP_NSWAP, 0, 0); @@ -243,18 +245,19 @@ void Platform_setSwapValues(Meter* this) { char* Platform_getProcessEnv(pid_t pid) { char errbuf[_POSIX2_LINE_MAX]; - char *env; - char **ptr; + char* env; + char** ptr; int count; - kvm_t *kt; - struct kinfo_proc *kproc; + kvm_t* kt; + struct kinfo_proc* kproc; size_t capacity = 4096, size = 0; - if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) + if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) { return NULL; + } 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); return NULL; } @@ -265,7 +268,7 @@ char* Platform_getProcessEnv(pid_t pid) { } env = xMalloc(capacity); - for (char **p = ptr; *p; p++) { + for (char** p = ptr; *p; p++) { size_t len = strlen(*p) + 1; if (size + len > capacity) { @@ -278,10 +281,10 @@ char* Platform_getProcessEnv(pid_t pid) { } if (size < 2 || env[size - 1] || env[size - 2]) { - if (size + 2 < capacity) - env = xRealloc(env, capacity + 2); - env[size] = 0; - env[size+1] = 0; + if (size + 2 < capacity) + env = xRealloc(env, capacity + 2); + env[size] = 0; + env[size + 1] = 0; } (void) kvm_close(kt); @@ -305,10 +308,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/openbsd/Platform.h b/openbsd/Platform.h index c7f4e4d7..9d2701dc 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -52,9 +52,9 @@ FileLocks_ProcessData* Platform_getProcessLocks(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 |