OpenBSD update

- compilation failures like `return &this->this;` -> `return &this->super;`
- iwyu update
- misc cleanup
This commit is contained in:
Christian Göttsche 2020-12-05 22:57:07 +01:00 committed by BenBE
parent 3d15ba5197
commit 57d9ecc551
6 changed files with 147 additions and 176 deletions

View File

@ -6,26 +6,15 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Process.h"
#include "ProcessList.h"
#include "OpenBSDProcess.h" #include "OpenBSDProcess.h"
#include "Platform.h"
#include "CRT.h"
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
#include "CRT.h"
#include "Process.h"
#include "RichString.h"
#include "XUtils.h"
const ProcessClass OpenBSDProcess_class = {
.super = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
.compare = OpenBSDProcess_compare
},
.writeField = OpenBSDProcess_writeField,
};
ProcessFieldData Process_fields[] = { ProcessFieldData Process_fields[] = {
[0] = { [0] = {
@ -200,7 +189,7 @@ Process* OpenBSDProcess_new(const Settings* settings) {
OpenBSDProcess* this = xCalloc(sizeof(OpenBSDProcess), 1); OpenBSDProcess* this = xCalloc(sizeof(OpenBSDProcess), 1);
Object_setClass(this, Class(OpenBSDProcess)); Object_setClass(this, Class(OpenBSDProcess));
Process_init(&this->super, settings); Process_init(&this->super, settings);
return &this->this; return &this->super;
} }
void Process_delete(Object* cast) { void Process_delete(Object* cast) {
@ -209,8 +198,8 @@ void Process_delete(Object* cast) {
free(this); free(this);
} }
void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { static void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) {
//OpenBSDProcess* fp = (OpenBSDProcess*) this; //const OpenBSDProcess* op = (const OpenBSDProcess*) this;
char buffer[256]; buffer[255] = '\0'; char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR]; int attr = CRT_colors[DEFAULT_COLOR];
//int n = sizeof(buffer) - 1; //int n = sizeof(buffer) - 1;
@ -223,7 +212,7 @@ void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessFiel
RichString_append(str, attr, buffer); RichString_append(str, attr, buffer);
} }
long OpenBSDProcess_compare(const void* v1, const void* v2) { static long OpenBSDProcess_compare(const void* v1, const void* v2) {
const OpenBSDProcess *p1, *p2; const OpenBSDProcess *p1, *p2;
const Settings *settings = ((const Process*)v1)->settings; const Settings *settings = ((const Process*)v1)->settings;
@ -235,6 +224,9 @@ long OpenBSDProcess_compare(const void* v1, const void* v2) {
p1 = (const OpenBSDProcess*)v2; p1 = (const OpenBSDProcess*)v2;
} }
// remove if actually used
(void)p1; (void)p2;
switch (settings->sortKey) { switch (settings->sortKey) {
// add OpenBSD-specific fields here // add OpenBSD-specific fields here
default: default:
@ -242,6 +234,16 @@ long OpenBSDProcess_compare(const void* v1, const void* v2) {
} }
} }
const ProcessClass OpenBSDProcess_class = {
.super = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
.compare = OpenBSDProcess_compare
},
.writeField = OpenBSDProcess_writeField,
};
bool Process_isThread(const Process* this) { bool Process_isThread(const Process* this) {
return (Process_isKernelThread(this)); return Process_isKernelThread(this) || Process_isUserlandThread(this);
} }

View File

@ -8,6 +8,13 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include <stdbool.h>
#include "Object.h"
#include "Process.h"
#include "Settings.h"
typedef enum OpenBSDProcessFields_ { typedef enum OpenBSDProcessFields_ {
// Add platform-specific fields here, with ids >= 100 // Add platform-specific fields here, with ids >= 100
LAST_PROCESSFIELD = 100, LAST_PROCESSFIELD = 100,
@ -31,10 +38,6 @@ Process* OpenBSDProcess_new(const Settings* settings);
void Process_delete(Object* cast); void Process_delete(Object* cast);
void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessField field);
long OpenBSDProcess_compare(const void* v1, const void* v2);
bool Process_isThread(const Process* this); bool Process_isThread(const Process* this);
#endif #endif

View File

@ -6,46 +6,49 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "CRT.h"
#include "ProcessList.h"
#include "OpenBSDProcessList.h" #include "OpenBSDProcessList.h"
#include "OpenBSDProcess.h"
#include "Macros.h"
#include <err.h> #include <err.h>
#include <errno.h> #include <kvm.h>
#include <fcntl.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/resource.h>
#include <sys/sched.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/user.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/swap.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <uvm/uvmexp.h>
#include "CRT.h"
#include "Macros.h"
#include "Object.h"
#include "OpenBSDProcess.h"
#include "Process.h"
#include "ProcessList.h"
#include "Settings.h"
#include "XUtils.h"
static long fscale; static long fscale;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
int mib[] = { CTL_HW, HW_NCPU }; const int mib[] = { CTL_HW, HW_NCPU };
int fmib[] = { CTL_KERN, KERN_FSCALE }; const int fmib[] = { CTL_KERN, KERN_FSCALE };
int i, e; int r;
OpenBSDProcessList* opl;
ProcessList* pl;
size_t size; size_t size;
char errbuf[_POSIX2_LINE_MAX]; char errbuf[_POSIX2_LINE_MAX];
opl = xCalloc(1, sizeof(OpenBSDProcessList)); OpenBSDProcessList* opl = xCalloc(1, sizeof(OpenBSDProcessList));
pl = (ProcessList*) opl; ProcessList* pl = (ProcessList*) opl;
size = sizeof(pl->cpuCount);
ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidMatchList, userId); ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidMatchList, userId);
e = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0); size = sizeof(pl->cpuCount);
if (e == -1 || pl->cpuCount < 1) { r = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0);
if (r < 0 || pl->cpuCount < 1) {
pl->cpuCount = 1; pl->cpuCount = 1;
} }
opl->cpus = xCalloc(pl->cpuCount + 1, sizeof(CPUData)); opl->cpus = xCalloc(pl->cpuCount + 1, sizeof(CPUData));
@ -55,7 +58,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
err(1, "fscale sysctl call failed"); err(1, "fscale sysctl call failed");
} }
for (i = 0; i <= pl->cpuCount; i++) { for (int i = 0; i <= pl->cpuCount; i++) {
CPUData* d = opl->cpus + i; CPUData* d = opl->cpus + i;
d->totalTime = 1; d->totalTime = 1;
d->totalPeriod = 1; d->totalPeriod = 1;
@ -70,7 +73,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
} }
void ProcessList_delete(ProcessList* this) { void ProcessList_delete(ProcessList* this) {
const OpenBSDProcessList* opl = (OpenBSDProcessList*) this; OpenBSDProcessList* opl = (OpenBSDProcessList*) this;
if (opl->kd) { if (opl->kd) {
kvm_close(opl->kd); kvm_close(opl->kd);
@ -82,8 +85,8 @@ void ProcessList_delete(ProcessList* this) {
free(this); free(this);
} }
static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { static void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP}; const int uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
struct uvmexp uvmexp; struct uvmexp uvmexp;
size_t size_uvmexp = sizeof(uvmexp); size_t size_uvmexp = sizeof(uvmexp);
@ -92,9 +95,10 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
} }
pl->totalMem = uvmexp.npages * CRT_pageSizeKB; pl->totalMem = uvmexp.npages * CRT_pageSizeKB;
pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * CRT_pageSizeKB;
// Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9) // Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9)
static int bcache_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; const int bcache_mib[] = { CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT };
struct bcachestats bcstats; struct bcachestats bcstats;
size_t size_bcstats = sizeof(bcstats); size_t size_bcstats = sizeof(bcstats);
@ -103,52 +107,55 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
} }
pl->cachedMem = bcstats.numbufpages * CRT_pageSizeKB; pl->cachedMem = bcstats.numbufpages * CRT_pageSizeKB;
pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * CRT_pageSizeKB;
/* /*
const OpenBSDProcessList* opl = (OpenBSDProcessList*) pl; * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
* All rights reserved.
*
* Taken almost directly from OpenBSD's top(1)
*
* Originally released under a BSD-3 license
* Modified through htop developers applying GPL-2
*/
int nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap > 0) {
struct swapent swdev[nswap];
int rnswap = swapctl(SWAP_STATS, swdev, nswap);
size_t len = sizeof(pl->totalMem); /* Total things up */
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); unsigned long long int total = 0, used = 0;
pl->totalMem /= 1024; for (int i = 0; i < rnswap; i++) {
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(pl->usedMem), &len, NULL, 0); if (swdev[i].se_flags & SWF_ENABLE) {
pl->usedMem *= CRT_pageSizeKB; used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0); total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
pl->cachedMem *= CRT_pageSizeKB; }
}
struct kvm_swap swap[16]; pl->totalSwap = total;
int nswap = kvm_getswapinfo(opl->kd, swap, ARRAYSIZE(swap), 0); pl->usedSwap = used;
pl->totalSwap = 0; } else {
pl->usedSwap = 0; pl->totalSwap = pl->usedSwap = 0;
for (int i = 0; i < nswap; i++) {
pl->totalSwap += swap[i].ksw_total;
pl->usedSwap += swap[i].ksw_used;
} }
pl->totalSwap *= CRT_pageSizeKB;
pl->usedSwap *= CRT_pageSizeKB;
pl->buffersMem = 0; // not exposed to userspace
*/
} }
char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { static char* OpenBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_proc* kproc, int* basenameEnd) {
char *s, **arg;
size_t len = 0;
int i;
/* /*
* Like OpenBSD's top(1), we try to fall back to the command name * Like OpenBSD's top(1), we try to fall back to the command name
* (argv[0]) if we fail to construct the full command. * (argv[0]) if we fail to construct the full command.
*/ */
arg = kvm_getargv(kd, kproc, 500); char** arg = kvm_getargv(kd, kproc, 500);
if (arg == NULL || *arg == NULL) { if (arg == NULL || *arg == NULL) {
*basenameEnd = strlen(kproc->p_comm); *basenameEnd = strlen(kproc->p_comm);
return xStrdup(kproc->p_comm); return xStrdup(kproc->p_comm);
} }
for (i = 0; arg[i] != NULL; i++) {
size_t len = 0;
for (int i = 0; arg[i] != NULL; i++) {
len += strlen(arg[i]) + 1; /* room for arg and trailing space or NUL */ len += strlen(arg[i]) + 1; /* room for arg and trailing space or NUL */
} }
/* don't use xMalloc here - we want to handle huge argv's gracefully */ /* don't use xMalloc here - we want to handle huge argv's gracefully */
char* s;
if ((s = malloc(len)) == NULL) { if ((s = malloc(len)) == NULL) {
*basenameEnd = strlen(kproc->p_comm); *basenameEnd = strlen(kproc->p_comm);
return xStrdup(kproc->p_comm); return xStrdup(kproc->p_comm);
@ -156,10 +163,9 @@ char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
*s = '\0'; *s = '\0';
for (i = 0; arg[i] != NULL; i++) { for (int i = 0; arg[i] != NULL; i++) {
size_t n = strlcat(s, arg[i], len); size_t n = strlcat(s, arg[i], len);
if (i == 0) { 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 */ /* the trailing space should get truncated anyway */
@ -176,30 +182,25 @@ static double getpcpu(const struct kinfo_proc* kp) {
if (fscale == 0) if (fscale == 0)
return 0.0; return 0.0;
#define fxtofl(fixpt) ((double)(fixpt) / fscale) return 100.0 * (double)kp->p_pctcpu / fscale;
return (100.0 * fxtofl(kp->p_pctcpu));
} }
static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
const Settings* settings = this->super.settings; const Settings* settings = this->super.settings;
bool hideKernelThreads = settings->hideKernelThreads; bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads; bool hideUserlandThreads = settings->hideUserlandThreads;
int count = 0; int count = 0;
// use KERN_PROC_KTHREAD to also include kernel threads const struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_KTHREAD, 0, sizeof(struct kinfo_proc), &count);
struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
struct kinfo_proc* kproc = &kprocs[i]; const struct kinfo_proc* kproc = &kprocs[i];
bool preExisting = false; bool preExisting = false;
Process* proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new); Process* proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
OpenBSDProcess* fp = (OpenBSDProcess*) proc; //OpenBSDProcess* fp = (OpenBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
|| (hideUserlandThreads && Process_isUserlandThread(proc)));
if (!preExisting) { if (!preExisting) {
proc->ppid = kproc->p_ppid; proc->ppid = kproc->p_ppid;
@ -226,10 +227,8 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->super.totalMem) * 100.0; 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->nlwp = kproc->p_numthreads;
//proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10);
proc->nice = kproc->p_nice - 20; proc->nice = kproc->p_nice - 20;
proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000); proc->time = 100 * (kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000));
proc->time *= 100;
proc->priority = kproc->p_priority - PZERO; proc->priority = kproc->p_priority - PZERO;
switch (kproc->p_stat) { switch (kproc->p_stat) {
@ -261,10 +260,9 @@ static unsigned long long saturatingSub(unsigned long long a, unsigned long long
} }
static void getKernelCPUTimes(int cpuId, u_int64_t* times) { static void getKernelCPUTimes(int cpuId, u_int64_t* times) {
int mib[] = { CTL_KERN, KERN_CPTIME2, cpuId }; const int mib[] = { CTL_KERN, KERN_CPTIME2, cpuId };
size_t length = sizeof(u_int64_t) * CPUSTATES; size_t length = sizeof(*times) * CPUSTATES;
if (sysctl(mib, 3, times, &length, NULL, 0) == -1 || if (sysctl(mib, 3, times, &length, NULL, 0) == -1 || length != sizeof(*times) * CPUSTATES) {
length != sizeof(u_int64_t) * CPUSTATES) {
CRT_fatalError("sysctl kern.cp_time2 failed"); CRT_fatalError("sysctl kern.cp_time2 failed");
} }
} }

View File

@ -9,6 +9,13 @@ in the source distribution for its full text.
*/ */
#include <kvm.h> #include <kvm.h>
#include <stdbool.h>
#include <sys/types.h>
#include "Hashtable.h"
#include "ProcessList.h"
#include "UsersTable.h"
typedef struct CPUData_ { typedef struct CPUData_ {
unsigned long long int totalTime; unsigned long long int totalTime;
@ -43,8 +50,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
void ProcessList_delete(ProcessList* this); void ProcessList_delete(ProcessList* this);
char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd);
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate);
#endif #endif

View File

@ -7,40 +7,39 @@ in the source distribution for its full text.
*/ */
#include "Platform.h" #include "Platform.h"
#include "Macros.h"
#include "Meter.h" #include <errno.h>
#include <kvm.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/resource.h>
#include <sys/sensors.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <uvm/uvmexp.h>
#include "CPUMeter.h" #include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "UptimeMeter.h"
#include "ClockMeter.h" #include "ClockMeter.h"
#include "DateMeter.h" #include "DateMeter.h"
#include "DateTimeMeter.h" #include "DateTimeMeter.h"
#include "HostnameMeter.h" #include "HostnameMeter.h"
#include "SignalsPanel.h" #include "LoadAverageMeter.h"
#include "Macros.h"
#include "MemoryMeter.h"
#include "Meter.h"
#include "OpenBSDProcess.h" #include "OpenBSDProcess.h"
#include "OpenBSDProcessList.h" #include "OpenBSDProcessList.h"
#include "ProcessList.h"
#include <sys/param.h> #include "Settings.h"
#include <sys/sysctl.h> #include "SignalsPanel.h"
#include <sys/sensors.h> #include "SwapMeter.h"
#include <sys/swap.h> #include "TasksMeter.h"
#include "UptimeMeter.h"
#include <unistd.h> #include "XUtils.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
#include <errno.h>
#include <math.h>
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
@ -131,10 +130,9 @@ void Platform_setBindings(Htop_Action* keys) {
(void) keys; (void) keys;
} }
// preserved from FreeBSD port
int Platform_getUptime() { int Platform_getUptime() {
struct timeval bootTime, currTime; struct timeval bootTime, currTime;
int mib[2] = { CTL_KERN, KERN_BOOTTIME }; const int mib[2] = { CTL_KERN, KERN_BOOTTIME };
size_t size = sizeof(bootTime); size_t size = sizeof(bootTime);
int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); int err = sysctl(mib, 2, &bootTime, &size, NULL, 0);
@ -148,7 +146,7 @@ int Platform_getUptime() {
void Platform_getLoadAverage(double* one, double* five, double* fifteen) { void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
struct loadavg loadAverage; struct loadavg loadAverage;
int mib[2] = { CTL_VM, VM_LOADAVG }; const int mib[2] = { CTL_VM, VM_LOADAVG };
size_t size = sizeof(loadAverage); size_t size = sizeof(loadAverage);
int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0);
@ -164,12 +162,12 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
} }
int Platform_getMaxPid() { int Platform_getMaxPid() {
// this is hard-coded in sys/sys/proc.h - no sysctl exists // this is hard-coded in sys/proc.h - no sysctl exists
return 99999; return 99999;
} }
double Platform_setCPUValues(Meter* this, int cpu) { double Platform_setCPUValues(Meter* this, int cpu) {
const OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl; const OpenBSDProcessList* pl = (const OpenBSDProcessList*) this->pl;
const CPUData* cpuData = &(pl->cpus[cpu]); const CPUData* cpuData = &(pl->cpus[cpu]);
double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod;
double totalPercent; double totalPercent;
@ -195,9 +193,6 @@ double Platform_setCPUValues(Meter* this, int cpu) {
} }
totalPercent = CLAMP(totalPercent, 0.0, 100.0); totalPercent = CLAMP(totalPercent, 0.0, 100.0);
if (isnan(totalPercent)) {
totalPercent = 0.0;
}
v[CPU_METER_TEMPERATURE] = NAN; v[CPU_METER_TEMPERATURE] = NAN;
@ -216,45 +211,10 @@ void Platform_setMemoryValues(Meter* this) {
this->values[2] = cachedMem; this->values[2] = cachedMem;
} }
/*
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
* All rights reserved.
*
* Taken almost directly from OpenBSD's top(1)
*/
void Platform_setSwapValues(Meter* this) { void Platform_setSwapValues(Meter* this) {
const ProcessList* pl = this->pl; const ProcessList* pl = this->pl;
struct swapent* swdev; this->total = pl->totalSwap;
unsigned long long int total, used; this->values[0] = pl->usedSwap;
int nswap, rnswap, i;
nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap == 0) {
return;
}
swdev = xCalloc(nswap, sizeof(*swdev));
rnswap = swapctl(SWAP_STATS, swdev, nswap);
if (rnswap == -1) {
free(swdev);
return;
}
// if rnswap != nswap, then what?
/* Total things up */
total = used = 0;
for (i = 0; i < nswap; i++) {
if (swdev[i].se_flags & SWF_ENABLE) {
used += (swdev[i].se_inuse / (1024 / DEV_BSIZE));
total += (swdev[i].se_nblks / (1024 / DEV_BSIZE));
}
}
this->total = pl->totalSwap = total;
this->values[0] = pl->usedSwap = used;
free(swdev);
} }
char* Platform_getProcessEnv(pid_t pid) { char* Platform_getProcessEnv(pid_t pid) {
@ -350,7 +310,7 @@ static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, si
} }
void Platform_getBattery(double* percent, ACPresence* isOnAC) { void Platform_getBattery(double* percent, ACPresence* isOnAC) {
static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0}; int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
struct sensor s; struct sensor s;
size_t slen = sizeof(struct sensor); size_t slen = sizeof(struct sensor);
struct sensordev snsrdev; struct sensordev snsrdev;

View File

@ -14,9 +14,12 @@ in the source distribution for its full text.
#include "Action.h" #include "Action.h"
#include "BatteryMeter.h" #include "BatteryMeter.h"
#include "DiskIOMeter.h" #include "DiskIOMeter.h"
#include "Meter.h"
#include "Process.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
extern ProcessFieldData Process_fields[]; extern ProcessFieldData Process_fields[];
extern ProcessField Platform_defaultFields[]; extern ProcessField Platform_defaultFields[];