diff options
Diffstat (limited to 'dragonflybsd')
-rw-r--r-- | dragonflybsd/DragonFlyBSDMachine.c | 341 | ||||
-rw-r--r-- | dragonflybsd/DragonFlyBSDMachine.h | 61 | ||||
-rw-r--r-- | dragonflybsd/DragonFlyBSDProcess.c | 121 | ||||
-rw-r--r-- | dragonflybsd/DragonFlyBSDProcess.h | 32 | ||||
-rw-r--r-- | dragonflybsd/DragonFlyBSDProcessTable.c | 322 | ||||
-rw-r--r-- | dragonflybsd/DragonFlyBSDProcessTable.h | 21 | ||||
-rw-r--r-- | dragonflybsd/Platform.c | 275 | ||||
-rw-r--r-- | dragonflybsd/Platform.h | 134 | ||||
-rw-r--r-- | dragonflybsd/ProcessField.h | 19 |
9 files changed, 1326 insertions, 0 deletions
diff --git a/dragonflybsd/DragonFlyBSDMachine.c b/dragonflybsd/DragonFlyBSDMachine.c new file mode 100644 index 0000000..fd5b58b --- /dev/null +++ b/dragonflybsd/DragonFlyBSDMachine.c @@ -0,0 +1,341 @@ +/* +htop - DragonFlyBSDMachine.c +(C) 2014 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "dragonflybsd/DragonFlyBSDMachine.h" + +#include <fcntl.h> +#include <limits.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/sysctl.h> +#include <sys/user.h> +#include <sys/param.h> + +#include "CRT.h" +#include "Macros.h" + +#include "dragonflybsd/DragonFlyBSDProcess.h" + + +static int MIB_hw_physmem[2]; +static int MIB_vm_stats_vm_v_page_count[4]; + +static int MIB_vm_stats_vm_v_wire_count[4]; +static int MIB_vm_stats_vm_v_active_count[4]; +static int MIB_vm_stats_vm_v_cache_count[4]; +static int MIB_vm_stats_vm_v_inactive_count[4]; +static int MIB_vm_stats_vm_v_free_count[4]; + +static int MIB_vfs_bufspace[2]; + +static int MIB_kern_cp_time[2]; +static int MIB_kern_cp_times[2]; + +Machine* Machine_new(UsersTable* usersTable, uid_t userId) { + size_t len; + char errbuf[_POSIX2_LINE_MAX]; + DragonFlyBSDMachine* this = xCalloc(1, sizeof(DragonFlyBSDMachine)); + Machine* super = &this->super; + + Machine_init(super, usersTable, userId); + + // physical memory in system: hw.physmem + // physical page size: hw.pagesize + // usable pagesize : vm.stats.vm.v_page_size + len = 2; sysctlnametomib("hw.physmem", MIB_hw_physmem, &len); + + len = sizeof(this->pageSize); + if (sysctlbyname("vm.stats.vm.v_page_size", &this->pageSize, &len, NULL, 0) == -1) + CRT_fatalError("Cannot get pagesize by sysctl"); + this->pageSizeKb = this->pageSize / ONE_K; + + // usable page count vm.stats.vm.v_page_count + // actually usable memory : vm.stats.vm.v_page_count * vm.stats.vm.v_page_size + len = 4; sysctlnametomib("vm.stats.vm.v_page_count", MIB_vm_stats_vm_v_page_count, &len); + + len = 4; sysctlnametomib("vm.stats.vm.v_wire_count", MIB_vm_stats_vm_v_wire_count, &len); + len = 4; sysctlnametomib("vm.stats.vm.v_active_count", MIB_vm_stats_vm_v_active_count, &len); + len = 4; sysctlnametomib("vm.stats.vm.v_cache_count", MIB_vm_stats_vm_v_cache_count, &len); + len = 4; sysctlnametomib("vm.stats.vm.v_inactive_count", MIB_vm_stats_vm_v_inactive_count, &len); + len = 4; sysctlnametomib("vm.stats.vm.v_free_count", MIB_vm_stats_vm_v_free_count, &len); + + len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len); + + int cpus = 1; + len = sizeof(cpus); + if (sysctlbyname("hw.ncpu", &cpus, &len, NULL, 0) != 0) { + cpus = 1; + } + + size_t sizeof_cp_time_array = sizeof(unsigned long) * CPUSTATES; + len = 2; sysctlnametomib("kern.cp_time", MIB_kern_cp_time, &len); + this->cp_time_o = xCalloc(CPUSTATES, sizeof(unsigned long)); + this->cp_time_n = xCalloc(CPUSTATES, sizeof(unsigned long)); + len = sizeof_cp_time_array; + + // fetch initial single (or average) CPU clicks from kernel + sysctl(MIB_kern_cp_time, 2, this->cp_time_o, &len, NULL, 0); + + // on smp box, fetch rest of initial CPU's clicks + if (cpus > 1) { + len = 2; sysctlnametomib("kern.cp_times", MIB_kern_cp_times, &len); + this->cp_times_o = xCalloc(cpus, sizeof_cp_time_array); + this->cp_times_n = xCalloc(cpus, sizeof_cp_time_array); + len = cpus * sizeof_cp_time_array; + sysctl(MIB_kern_cp_times, 2, this->cp_times_o, &len, NULL, 0); + } + + super->existingCPUs = MAXIMUM(cpus, 1); + // TODO: support offline CPUs and hot swapping + super->activeCPUs = super->existingCPUs; + + if (cpus == 1 ) { + this->cpus = xRealloc(this->cpus, sizeof(CPUData)); + } else { + // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) + this->cpus = xRealloc(this->cpus, (super->existingCPUs + 1) * sizeof(CPUData)); + } + + len = sizeof(this->kernelFScale); + if (sysctlbyname("kern.fscale", &this->kernelFScale, &len, NULL, 0) == -1 || this->kernelFScale <= 0) { + //sane default for kernel provided CPU percentage scaling, at least on x86 machines, in case this sysctl call failed + this->kernelFScale = 2048; + } + + this->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf); + if (this->kd == NULL) { + CRT_fatalError("kvm_openfiles() failed"); + } + + return super; +} + +void Machine_delete(Machine* super) { + const DragonFlyBSDMachine* this = (const DragonFlyBSDMachine*) super; + + Machine_done(super); + + if (this->kd) { + kvm_close(this->kd); + } + + if (this->jails) { + Hashtable_delete(this->jails); + } + + free(this->cp_time_o); + free(this->cp_time_n); + free(this->cp_times_o); + free(this->cp_times_n); + free(this->cpus); + + free(this); +} + +static void DragonFlyBSDMachine_scanCPUTime(Machine* super) { + const DragonFlyBSDMachine* this = (DragonFlyBSDMachine*) super; + + unsigned int cpus = super->existingCPUs; // actual CPU count + unsigned int maxcpu = cpus; // max iteration (in case we have average + smp) + int cp_times_offset; + + assert(cpus > 0); + + size_t sizeof_cp_time_array; + + unsigned long* cp_time_n; // old clicks state + unsigned long* cp_time_o; // current clicks state + + unsigned long cp_time_d[CPUSTATES]; + double cp_time_p[CPUSTATES]; + + // get averages or single CPU clicks + sizeof_cp_time_array = sizeof(unsigned long) * CPUSTATES; + sysctl(MIB_kern_cp_time, 2, this->cp_time_n, &sizeof_cp_time_array, NULL, 0); + + // get rest of CPUs + if (cpus > 1) { + // on smp systems DragonFlyBSD kernel concats all CPU states into one long array in + // kern.cp_times sysctl OID + // we store averages in dfpl->cpus[0], and actual cores after that + maxcpu = cpus + 1; + sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; + sysctl(MIB_kern_cp_times, 2, this->cp_times_n, &sizeof_cp_time_array, NULL, 0); + } + + for (unsigned int i = 0; i < maxcpu; i++) { + if (cpus == 1) { + // single CPU box + cp_time_n = this->cp_time_n; + cp_time_o = this->cp_time_o; + } else { + if (i == 0 ) { + // average + cp_time_n = this->cp_time_n; + cp_time_o = this->cp_time_o; + } else { + // specific smp cores + cp_times_offset = i - 1; + cp_time_n = this->cp_times_n + (cp_times_offset * CPUSTATES); + cp_time_o = this->cp_times_o + (cp_times_offset * CPUSTATES); + } + } + + // diff old vs new + unsigned long long total_o = 0; + unsigned long long total_n = 0; + unsigned long long total_d = 0; + for (int s = 0; s < CPUSTATES; s++) { + cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; + total_o += cp_time_o[s]; + total_n += cp_time_n[s]; + } + + // totals + total_d = total_n - total_o; + if (total_d < 1 ) { + total_d = 1; + } + + // save current state as old and calc percentages + for (int s = 0; s < CPUSTATES; ++s) { + cp_time_o[s] = cp_time_n[s]; + cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; + } + + CPUData* cpuData = &(this->cpus[i]); + cpuData->userPercent = cp_time_p[CP_USER]; + cpuData->nicePercent = cp_time_p[CP_NICE]; + cpuData->systemPercent = cp_time_p[CP_SYS]; + cpuData->irqPercent = cp_time_p[CP_INTR]; + cpuData->systemAllPercent = cp_time_p[CP_SYS] + cp_time_p[CP_INTR]; + // this one is not really used, but we store it anyway + cpuData->idlePercent = cp_time_p[CP_IDLE]; + } +} + +static void DragonFlyBSDMachine_scanMemoryInfo(Machine* super) { + DragonFlyBSDMachine* this = (DragonFlyBSDProcessTable*) super; + + // @etosan: + // memory counter relationships seem to be these: + // total = active + wired + inactive + cache + free + // htop_used (unavail to anybody) = active + wired + // htop_cache (for cache meter) = buffers + cache + // user_free (avail to procs) = buffers + inactive + cache + free + size_t len = sizeof(super->totalMem); + + //disabled for now, as it is always smaller than phycal amount of memory... + //...to avoid "where is my memory?" questions + //sysctl(MIB_vm_stats_vm_v_page_count, 4, &(this->totalMem), &len, NULL, 0); + //this->totalMem *= pageSizeKb; + sysctl(MIB_hw_physmem, 2, &(super->totalMem), &len, NULL, 0); + super->totalMem /= 1024; + + sysctl(MIB_vm_stats_vm_v_active_count, 4, &(this->memActive), &len, NULL, 0); + this->memActive *= this->pageSizeKb; + + sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(this->memWire), &len, NULL, 0); + this->memWire *= this->pageSizeKb; + + sysctl(MIB_vfs_bufspace, 2, &(super->buffersMem), &len, NULL, 0); + super->buffersMem /= 1024; + + sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(super->cachedMem), &len, NULL, 0); + super->cachedMem *= this->pageSizeKb; + super->usedMem = this->memActive + this->memWire; + + struct kvm_swap swap[16]; + int nswap = kvm_getswapinfo(this->kd, swap, ARRAYSIZE(swap), 0); + super->totalSwap = 0; + super->usedSwap = 0; + for (int i = 0; i < nswap; i++) { + super->totalSwap += swap[i].ksw_total; + super->usedSwap += swap[i].ksw_used; + } + super->totalSwap *= this->pageSizeKb; + super->usedSwap *= this->pageSizeKb; +} + +static void DragonFlyBSDMachine_scanJails(DragonFlyBSDMachine* this) { + size_t len; + char* jails; /* Jail list */ + char* curpos; + char* nextpos; + + if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) { + CRT_fatalError("initial sysctlbyname / jail.list failed"); + } + +retry: + if (len == 0) + return; + + jails = xMalloc(len); + + if (sysctlbyname("jail.list", jails, &len, NULL, 0) == -1) { + if (errno == ENOMEM) { + free(jails); + goto retry; + } + CRT_fatalError("sysctlbyname / jail.list failed"); + } + + if (this->jails) { + Hashtable_delete(this->jails); + } + + this->jails = Hashtable_new(20, true); + curpos = jails; + while (curpos) { + int jailid; + char* str_hostname; + + nextpos = strchr(curpos, '\n'); + if (nextpos) { + *nextpos++ = 0; + } + + jailid = atoi(strtok(curpos, " ")); + str_hostname = strtok(NULL, " "); + + char* jname = (char*) (Hashtable_get(this->jails, jailid)); + if (jname == NULL) { + jname = xStrdup(str_hostname); + Hashtable_put(this->jails, jailid, jname); + } + + curpos = nextpos; + } + + free(jails); +} + +char* DragonFlyBSDMachine_readJailName(DragonFlyBSDMachine* host, int jailid) { + char* hostname; + char* jname; + + if (jailid != 0 && host->jails && (hostname = (char*)Hashtable_get(host->jails, jailid))) { + jname = xStrdup(hostname); + } else { + jname = xStrdup("-"); + } + + return jname; +} + +void Machine_scan(Machine* super) { + DragonFlyBSDMachine* this = (DragonFlyBSDMachine*) super; + + DragonFlyBSDMachine_scanMemoryInfo(super); + DragonFlyBSDMachine_scanCPUTime(super); + DragonFlyBSDMachine_scanJails(this); +} diff --git a/dragonflybsd/DragonFlyBSDMachine.h b/dragonflybsd/DragonFlyBSDMachine.h new file mode 100644 index 0000000..0d4d8ef --- /dev/null +++ b/dragonflybsd/DragonFlyBSDMachine.h @@ -0,0 +1,61 @@ +#ifndef HEADER_DragonFlyBSDMachine +#define HEADER_DragonFlyBSDMachine +/* +htop - DragonFlyBSDMachine.h +(C) 2014 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include <sys/types.h> // required for kvm.h +#include <kvm.h> +#include <osreldate.h> +#include <stdbool.h> +#include <sys/jail.h> +#include <sys/param.h> +#include <sys/resource.h> +#include <sys/uio.h> + +#include "Hashtable.h" +#include "Machine.h" +#include "ProcessTable.h" +#include "UsersTable.h" + + +typedef struct CPUData_ { + double userPercent; + double nicePercent; + double systemPercent; + double irqPercent; + double idlePercent; + double systemAllPercent; +} CPUData; + +typedef struct DragonFlyBSDMachine_ { + Machine super; + kvm_t* kd; + + Hashtable* jails; + + int pageSize; + int pageSizeKb; + int kernelFScale; + + unsigned long long int memWire; + unsigned long long int memActive; + unsigned long long int memInactive; + unsigned long long int memFree; + + CPUData* cpus; + + unsigned long* cp_time_o; + unsigned long* cp_time_n; + + unsigned long* cp_times_o; + unsigned long* cp_times_n; +} DragonFlyBSDMachine; + +char* DragonFlyBSDMachine_readJailName(DragonFlyBSDMachine* host, int jailid); + +#endif diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c new file mode 100644 index 0000000..4be2198 --- /dev/null +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -0,0 +1,121 @@ +/* +htop - dragonflybsd/DragonFlyBSDProcess.c +(C) 2015 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "dragonflybsd/DragonFlyBSDProcess.h" + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/syscall.h> + +#include "CRT.h" + +#include "dragonflybsd/Platform.h" + + +const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { + [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, + [PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, }, + [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, }, + [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping (<20s), I Idle, Q Queued for Run, R running, D disk, Z zombie, T traced, W paging, B Blocked, A AskedPage, C Core, J Jailed)", .flags = 0, }, + [PPID] = { .name = "PPID", .title = "PPID", .description = "Parent process ID", .flags = 0, .pidColumn = true, }, + [PGRP] = { .name = "PGRP", .title = "PGRP", .description = "Process group ID", .flags = 0, .pidColumn = true, }, + [SESSION] = { .name = "SESSION", .title = "SID", .description = "Process's session ID", .flags = 0, .pidColumn = true, }, + [TTY] = { .name = "TTY", .title = "TTY ", .description = "Controlling terminal", .flags = 0, }, + [TPGID] = { .name = "TPGID", .title = "TPGID", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, .pidColumn = true, }, + [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, .defaultSortDesc = true, }, + [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, .defaultSortDesc = true, }, + [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, + [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, + [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, + [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, + [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, + [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, + [ST_UID] = { .name = "ST_UID", .title = "UID", .description = "User ID of the process owner", .flags = 0, }, + [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = " CPU%", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, .defaultSortDesc = true, .autoWidth = true, }, + [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, .defaultSortDesc = true, .autoWidth = true, }, + [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, }, + [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, + [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, .defaultSortDesc = true, }, + [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, }, + [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, }, + [PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process", .flags = 0, }, + [PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process", .flags = 0, }, + [CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, }, + [JID] = { .name = "JID", .title = "JID", .description = "Jail prison ID", .flags = 0, .pidColumn = true, }, + [JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, }, +}; + +Process* DragonFlyBSDProcess_new(const Machine* host) { + DragonFlyBSDProcess* this = xCalloc(1, sizeof(DragonFlyBSDProcess)); + Object_setClass(this, Class(DragonFlyBSDProcess)); + Process_init(&this->super, host); + return &this->super; +} + +void Process_delete(Object* cast) { + DragonFlyBSDProcess* this = (DragonFlyBSDProcess*) cast; + Process_done((Process*)cast); + free(this->jname); + free(this); +} + +static void DragonFlyBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) { + const Process* this = (const Process*) super; + const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) super; + + char buffer[256]; buffer[255] = '\0'; + int attr = CRT_colors[DEFAULT_COLOR]; + size_t n = sizeof(buffer) - 1; + + switch (field) { + // add Platform-specific fields here + case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, Process_isKernelThread(this) ? -1 : Process_getPid(this)); break; + case JID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, fp->jid); break; + case JAIL: Row_printLeftAlignedField(str, attr, fp->jname, 11); return; + default: + Process_writeField(&fp->super, str, field); + return; + } + + RichString_appendWide(str, attr, buffer); +} + +static int DragonFlyBSDProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { + const DragonFlyBSDProcess* p1 = (const DragonFlyBSDProcess*)v1; + const DragonFlyBSDProcess* p2 = (const DragonFlyBSDProcess*)v2; + + switch (key) { + // add Platform-specific fields here + case JID: + return SPACESHIP_NUMBER(p1->jid, p2->jid); + case JAIL: + return SPACESHIP_NULLSTR(p1->jname, p2->jname); + default: + return Process_compareByKey_Base(v1, v2, key); + } +} + +const ProcessClass DragonFlyBSDProcess_class = { + .super = { + .super = { + .extends = Class(Process), + .display = Row_display, + .delete = Process_delete, + .compare = Process_compare + }, + .isHighlighted = Process_rowIsHighlighted, + .isVisible = Process_rowIsVisible, + .matchesFilter = Process_rowMatchesFilter, + .compareByParent = Process_compareByParent, + .sortKeyString = Process_rowGetSortKey, + .writeField = DragonFlyBSDProcess_rowWriteField + }, + .compareByKey = DragonFlyBSDProcess_compareByKey +}; diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h new file mode 100644 index 0000000..92747b1 --- /dev/null +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -0,0 +1,32 @@ +#ifndef HEADER_DragonFlyBSDProcess +#define HEADER_DragonFlyBSDProcess +/* +htop - dragonflybsd/DragonFlyBSDProcess.h +(C) 2015 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include <stdbool.h> + +#include "Object.h" +#include "Process.h" +#include "Machine.h" + + +typedef struct DragonFlyBSDProcess_ { + Process super; + int jid; + char* jname; +} DragonFlyBSDProcess; + +extern const ProcessClass DragonFlyBSDProcess_class; + +extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD]; + +Process* DragonFlyBSDProcess_new(const Machine* host); + +void Process_delete(Object* cast); + +#endif diff --git a/dragonflybsd/DragonFlyBSDProcessTable.c b/dragonflybsd/DragonFlyBSDProcessTable.c new file mode 100644 index 0000000..e36086f --- /dev/null +++ b/dragonflybsd/DragonFlyBSDProcessTable.c @@ -0,0 +1,322 @@ +/* +htop - DragonFlyBSDProcessTable.c +(C) 2014 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "dragonflybsd/DragonFlyBSDProcessTable.h" + +#include <fcntl.h> +#include <limits.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/sysctl.h> +#include <sys/user.h> +#include <sys/param.h> + +#include "CRT.h" +#include "Macros.h" + +#include "dragonflybsd/DragonFlyBSDMachine.h" +#include "dragonflybsd/DragonFlyBSDProcess.h" + + +ProcessTable* ProcessTable_new(Machine* host, Hashtable* pidMatchList) { + DragonFlyBSDProcessTable* this = xCalloc(1, sizeof(DragonFlyBSDProcessTable)); + Object_setClass(this, Class(ProcessTable)); + + ProcessTable* super = (ProcessTable*) this; + ProcessTable_init(super, Class(DragonFlyBSDProcess), host, pidMatchList); + + return super; +} + +void ProcessTable_delete(Object* cast) { + const DragonFlyBSDProcessTable* this = (DragonFlyBSDProcessTable*) cast; + ProcessTable_done(&this->super); + free(this); +} + +//static void DragonFlyBSDProcessTable_updateExe(const struct kinfo_proc* kproc, Process* proc) { +// const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, kproc->kp_pid }; +// char buffer[2048]; +// size_t size = sizeof(buffer); +// if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) { +// Process_updateExe(proc, NULL); +// return; +// } +// +// /* Kernel threads return an empty buffer */ +// if (buffer[0] == '\0') { +// Process_updateExe(proc, NULL); +// return; +// } +// +// Process_updateExe(proc, buffer); +//} + +static void DragonFlyBSDProcessTable_updateExe(const struct kinfo_proc* kproc, Process* proc) { + if (Process_isKernelThread(proc)) + return; + + char path[32]; + xSnprintf(path, sizeof(path), "/proc/%d/file", kproc->kp_pid); + + char target[PATH_MAX]; + ssize_t ret = readlink(path, target, sizeof(target) - 1); + if (ret <= 0) + return; + + target[ret] = '\0'; + Process_updateExe(proc, target); +} + +static void DragonFlyBSDProcessTable_updateCwd(const struct kinfo_proc* kproc, Process* proc) { + const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_CWD, kproc->kp_pid }; + char buffer[2048]; + size_t size = sizeof(buffer); + if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) { + free(proc->procCwd); + proc->procCwd = NULL; + return; + } + + /* Kernel threads return an empty buffer */ + if (buffer[0] == '\0') { + free(proc->procCwd); + proc->procCwd = NULL; + return; + } + + free_and_xStrdup(&proc->procCwd, buffer); +} + +static void DragonFlyBSDProcessTable_updateProcessName(kvm_t* kd, const struct kinfo_proc* kproc, Process* proc) { + Process_updateComm(proc, kproc->kp_comm); + + char** argv = kvm_getargv(kd, kproc, 0); + if (!argv || !argv[0]) { + Process_updateCmdline(proc, kproc->kp_comm, 0, strlen(kproc->kp_comm)); + return; + } + + size_t len = 0; + for (int i = 0; argv[i]; i++) { + len += strlen(argv[i]) + 1; + } + + char* cmdline = xMalloc(len); + + char* at = cmdline; + int end = 0; + for (int i = 0; argv[i]; i++) { + at = stpcpy(at, argv[i]); + if (end == 0) { + end = at - cmdline; + } + *at++ = ' '; + } + at--; + *at = '\0'; + + Process_updateCmdline(proc, cmdline, 0, end); + + free(cmdline); +} + +void ProcessTable_goThroughEntries(ProcessTable* super) { + const Machine* host = super->host; + const DragonFlyMachine* dhost = (const DragonFlyMachine*) host; + const Settings* settings = host->settings; + + bool hideKernelThreads = settings->hideKernelThreads; + bool hideUserlandThreads = settings->hideUserlandThreads; + + int count = 0; + + const struct kinfo_proc* kprocs = kvm_getprocs(dhost->kd, KERN_PROC_ALL | (!hideUserlandThreads ? KERN_PROC_FLAG_LWP : 0), 0, &count); + + for (int i = 0; i < count; i++) { + const struct kinfo_proc* kproc = &kprocs[i]; + bool preExisting = false; + bool ATTR_UNUSED isIdleProcess = false; + + // note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier + Process* proc = ProcessTable_getProcess(super, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, DragonFlyBSDProcess_new); + DragonFlyBSDProcess* dfp = (DragonFlyBSDProcess*) proc; + + if (!preExisting) { + dfp->jid = kproc->kp_jailid; + if (kproc->kp_ktaddr && kproc->kp_flags & P_SYSTEM) { + // dfb kernel threads all have the same pid, so we misuse the kernel thread address to give them a unique identifier + Process_setPid(proc, (pid_t)kproc->kp_ktaddr); + proc->isKernelThread = true; + } else { + Process_setPid(proc, kproc->kp_pid); // process ID + proc->isKernelThread = false; + } + proc->isUserlandThread = kproc->kp_nthreads > 1; + Process_setParent(proc, kproc->kp_ppid); // parent process id + proc->tpgid = kproc->kp_tpgid; // tty process group id + //Process_setThreadGroup(proc, kproc->kp_lwp.kl_tid); // thread group id + Process_setThreadGroup(proc, kproc->kp_pid); + proc->pgrp = kproc->kp_pgid; // process group id + proc->session = kproc->kp_sid; + proc->st_uid = kproc->kp_uid; // user ID + proc->processor = kproc->kp_lwp.kl_origcpu; + proc->starttime_ctime = kproc->kp_start.tv_sec; + Process_fillStarttimeBuffer(proc); + proc->user = UsersTable_getRef(host->usersTable, proc->st_uid); + + proc->tty_nr = kproc->kp_tdev; // control terminal device number + const char* name = (kproc->kp_tdev != NODEV) ? devname(kproc->kp_tdev, S_IFCHR) : NULL; + if (!name) { + free(proc->tty_name); + proc->tty_name = NULL; + } else { + free_and_xStrdup(&proc->tty_name, name); + } + + DragonFlyBSDProcessTable_updateExe(kproc, proc); + DragonFlyBSDProcessTable_updateProcessName(dhost->kd, kproc, proc); + + if (settings->ss->flags & PROCESS_FLAG_CWD) { + DragonFlyBSDProcessTable_updateCwd(kproc, proc); + } + + ProcessTable_add(super, proc); + + dfp->jname = DragonFlyBSDMachine_readJailName(dhost, kproc->kp_jailid); + } else { + proc->processor = kproc->kp_lwp.kl_cpuid; + if (dfp->jid != kproc->kp_jailid) { // process can enter jail anytime + dfp->jid = kproc->kp_jailid; + free(dfp->jname); + dfp->jname = DragonFlyBSDMachine_readJailName(dhost, kproc->kp_jailid); + } + // if there are reapers in the system, process can get reparented anytime + Process_setParent(proc, kproc->kp_ppid); + if (proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) + proc->st_uid = kproc->kp_uid; + proc->user = UsersTable_getRef(host->usersTable, proc->st_uid); + } + if (settings->updateProcessNames) { + DragonFlyBSDProcessTable_updateProcessName(dhost->kd, kproc, proc); + } + } + + proc->m_virt = kproc->kp_vm_map_size / ONE_K; + proc->m_resident = kproc->kp_vm_rssize * dhost->pageSizeKb; + proc->nlwp = kproc->kp_nthreads; // number of lwp thread + proc->time = (kproc->kp_lwp.kl_uticks + kproc->kp_lwp.kl_sticks + kproc->kp_lwp.kl_iticks) / 10000; + + proc->percent_cpu = 100.0 * ((double)kproc->kp_lwp.kl_pctcpu / (double)dhost->kernelFScale); + proc->percent_mem = 100.0 * proc->m_resident / (double)(super->totalMem); + Process_updateCPUFieldWidths(proc->percent_cpu); + + if (proc->percent_cpu > 0.1) { + // system idle process should own all CPU time left regardless of CPU count + if (String_eq("idle", kproc->kp_comm)) { + isIdleProcess = true; + } + } + + if (kproc->kp_lwp.kl_pid != -1) + proc->priority = kproc->kp_lwp.kl_prio; + else + proc->priority = -kproc->kp_lwp.kl_tdprio; + + switch (kproc->kp_lwp.kl_rtprio.type) { + case RTP_PRIO_REALTIME: + proc->nice = PRIO_MIN - 1 - RTP_PRIO_MAX + kproc->kp_lwp.kl_rtprio.prio; + break; + case RTP_PRIO_IDLE: + proc->nice = PRIO_MAX + 1 + kproc->kp_lwp.kl_rtprio.prio; + break; + case RTP_PRIO_THREAD: + proc->nice = PRIO_MIN - 1 - RTP_PRIO_MAX - kproc->kp_lwp.kl_rtprio.prio; + break; + default: + proc->nice = kproc->kp_nice; + break; + } + + // would be nice if we could store multiple states in proc->state (as enum) and have writeField render them + /* Taken from: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/c163a4d7ee9c6857ee4e04a3a2cbb50c3de29da1/sys/sys/proc_common.h */ + switch (kproc->kp_stat) { + case SIDL: + proc->state = IDLE; + isIdleProcess = true; + break; + case SACTIVE: + switch (kproc->kp_lwp.kl_stat) { + case LSSLEEP: + if (kproc->kp_lwp.kl_flags & LWP_SINTR) { // interruptible wait short/long + if (kproc->kp_lwp.kl_slptime >= MAXSLP) { + proc->state = IDLE; + isIdleProcess = true; + } else { + proc->state = SLEEPING; + } + } else if (kproc->kp_lwp.kl_tdflags & TDF_SINTR) { // interruptible lwkt wait + proc->state = SLEEPING; + } else if (kproc->kp_paddr) { // uninterruptible wait + proc->state = UNINTERRUPTIBLE_WAIT; + } else { // uninterruptible lwkt wait + proc->state = UNINTERRUPTIBLE_WAIT; + } + break; + case LSRUN: + if (kproc->kp_lwp.kl_stat == LSRUN) { + if (!(kproc->kp_lwp.kl_tdflags & (TDF_RUNNING | TDF_RUNQ))) { + proc->state = QUEUED; + } else { + proc->state = RUNNING; + } + } + break; + case LSSTOP: + proc->state = STOPPED; + break; + default: + proc->state = PAGING; + break; + } + break; + case SSTOP: + proc->state = STOPPED; + break; + case SZOMB: + proc->state = ZOMBIE; + break; + case SCORE: + proc->state = BLOCKED; + break; + default: + proc->state = UNKNOWN; + } + + if (kproc->kp_flags & P_SWAPPEDOUT) + proc->state = SLEEPING; + if (kproc->kp_flags & P_TRACED) + proc->state = TRACED; + if (kproc->kp_flags & P_JAILED) + proc->state = TRACED; + + if (Process_isKernelThread(proc)) + super->kernelThreads++; + + super->totalTasks++; + + if (proc->state == RUNNING) + super->runningTasks++; + + proc->super.show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); + proc->super.updated = true; + } +} diff --git a/dragonflybsd/DragonFlyBSDProcessTable.h b/dragonflybsd/DragonFlyBSDProcessTable.h new file mode 100644 index 0000000..e8ff1af --- /dev/null +++ b/dragonflybsd/DragonFlyBSDProcessTable.h @@ -0,0 +1,21 @@ +#ifndef HEADER_DragonFlyBSDProcessTable +#define HEADER_DragonFlyBSDProcessTable +/* +htop - DragonFlyBSDProcessTable.h +(C) 2014 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include <stdbool.h> +#include <sys/param.h> + +#include "ProcessTable.h" + + +typedef struct DragonFlyBSDProcessTable_ { + ProcessTable super; +} DragonFlyBSDProcessTable; + +#endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c new file mode 100644 index 0000000..25afa8b --- /dev/null +++ b/dragonflybsd/Platform.c @@ -0,0 +1,275 @@ +/* +htop - dragonflybsd/Platform.c +(C) 2014 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "dragonflybsd/Platform.h" + +#include <math.h> +#include <time.h> +#include <sys/resource.h> +#include <sys/sysctl.h> +#include <sys/time.h> +#include <sys/types.h> +#include <vm/vm_param.h> + +#include "ClockMeter.h" +#include "CPUMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" +#include "FileDescriptorMeter.h" +#include "HostnameMeter.h" +#include "LoadAverageMeter.h" +#include "Macros.h" +#include "MemoryMeter.h" +#include "MemorySwapMeter.h" +#include "ProcessTable.h" +#include "SwapMeter.h" +#include "SysArchMeter.h" +#include "TasksMeter.h" +#include "UptimeMeter.h" +#include "XUtils.h" +#include "dragonflybsd/DragonFlyBSDProcess.h" +#include "dragonflybsd/DragonFlyBSDProcessTable.h" +#include "generic/fdstat_sysctl.h" + + +const ScreenDefaults Platform_defaultScreens[] = { + { + .name = "Main", + .columns = "PID USER PRIORITY NICE M_VIRT M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command", + .sortKey = "PERCENT_CPU", + }, +}; + +const unsigned int Platform_numberOfDefaultScreens = ARRAYSIZE(Platform_defaultScreens); + +const SignalItem Platform_signals[] = { + { .name = " 0 Cancel", .number = 0 }, + { .name = " 1 SIGHUP", .number = 1 }, + { .name = " 2 SIGINT", .number = 2 }, + { .name = " 3 SIGQUIT", .number = 3 }, + { .name = " 4 SIGILL", .number = 4 }, + { .name = " 5 SIGTRAP", .number = 5 }, + { .name = " 6 SIGABRT", .number = 6 }, + { .name = " 7 SIGEMT", .number = 7 }, + { .name = " 8 SIGFPE", .number = 8 }, + { .name = " 9 SIGKILL", .number = 9 }, + { .name = "10 SIGBUS", .number = 10 }, + { .name = "11 SIGSEGV", .number = 11 }, + { .name = "12 SIGSYS", .number = 12 }, + { .name = "13 SIGPIPE", .number = 13 }, + { .name = "14 SIGALRM", .number = 14 }, + { .name = "15 SIGTERM", .number = 15 }, + { .name = "16 SIGURG", .number = 16 }, + { .name = "17 SIGSTOP", .number = 17 }, + { .name = "18 SIGTSTP", .number = 18 }, + { .name = "19 SIGCONT", .number = 19 }, + { .name = "20 SIGCHLD", .number = 20 }, + { .name = "21 SIGTTIN", .number = 21 }, + { .name = "22 SIGTTOU", .number = 22 }, + { .name = "23 SIGIO", .number = 23 }, + { .name = "24 SIGXCPU", .number = 24 }, + { .name = "25 SIGXFSZ", .number = 25 }, + { .name = "26 SIGVTALRM", .number = 26 }, + { .name = "27 SIGPROF", .number = 27 }, + { .name = "28 SIGWINCH", .number = 28 }, + { .name = "29 SIGINFO", .number = 29 }, + { .name = "30 SIGUSR1", .number = 30 }, + { .name = "31 SIGUSR2", .number = 31 }, + { .name = "32 SIGTHR", .number = 32 }, + { .name = "33 SIGLIBRT", .number = 33 }, +}; + +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); + +const MeterClass* const Platform_meterTypes[] = { + &CPUMeter_class, + &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, + &LoadAverageMeter_class, + &LoadMeter_class, + &MemoryMeter_class, + &MemorySwapMeter_class, + &SwapMeter_class, + &TasksMeter_class, + &UptimeMeter_class, + &BatteryMeter_class, + &HostnameMeter_class, + &SysArchMeter_class, + &AllCPUsMeter_class, + &AllCPUs2Meter_class, + &AllCPUs4Meter_class, + &AllCPUs8Meter_class, + &LeftCPUsMeter_class, + &RightCPUsMeter_class, + &LeftCPUs2Meter_class, + &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, + &FileDescriptorMeter_class, + &BlankMeter_class, + NULL +}; + +bool Platform_init(void) { + /* no platform-specific setup needed */ + return true; +} + +void Platform_done(void) { + /* no platform-specific cleanup needed */ +} + +void Platform_setBindings(Htop_Action* keys) { + /* no platform-specific key bindings */ + (void) keys; +} + +int Platform_getUptime(void) { + struct timeval bootTime, currTime; + int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + size_t size = sizeof(bootTime); + + int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); + if (err) { + return -1; + } + gettimeofday(&currTime, NULL); + + return (int) difftime(currTime.tv_sec, bootTime.tv_sec); +} + +void Platform_getLoadAverage(double* one, double* five, double* fifteen) { + struct loadavg loadAverage; + int mib[2] = { CTL_VM, VM_LOADAVG }; + size_t size = sizeof(loadAverage); + + int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); + if (err) { + *one = 0; + *five = 0; + *fifteen = 0; + return; + } + *one = (double) loadAverage.ldavg[0] / loadAverage.fscale; + *five = (double) loadAverage.ldavg[1] / loadAverage.fscale; + *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; +} + +pid_t Platform_getMaxPid(void) { + int maxPid; + size_t size = sizeof(maxPid); + int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0); + if (err) { + return 999999; + } + return maxPid; +} + +double Platform_setCPUValues(Meter* this, unsigned int cpu) { + const Machine* host = this->host; + const DragonFlyBSDMachine* dhost = (const DragonFlyBSDMachine*) host; + unsigned int cpus = host->activeCPUs; + const CPUData* cpuData; + + if (cpus == 1) { + // single CPU box has everything in fpl->cpus[0] + cpuData = &(dhost->cpus[0]); + } else { + cpuData = &(dhost->cpus[cpu]); + } + + double percent; + double* v = this->values; + + v[CPU_METER_NICE] = cpuData->nicePercent; + v[CPU_METER_NORMAL] = cpuData->userPercent; + if (super->settings->detailedCPUTime) { + v[CPU_METER_KERNEL] = cpuData->systemPercent; + v[CPU_METER_IRQ] = cpuData->irqPercent; + this->curItems = 4; + } else { + v[CPU_METER_KERNEL] = cpuData->systemAllPercent; + this->curItems = 3; + } + + percent = sumPositiveValues(v, this->curItems); + percent = MINIMUM(percent, 100.0); + + v[CPU_METER_FREQUENCY] = NAN; + v[CPU_METER_TEMPERATURE] = NAN; + + return percent; +} + +void Platform_setMemoryValues(Meter* this) { + const Machine* host = this->host; + + this->total = host->totalMem; + this->values[MEMORY_METER_USED] = host->usedMem; + // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" + this->values[MEMORY_METER_BUFFERS] = host->buffersMem; + this->values[MEMORY_METER_CACHE] = host->cachedMem; + // this->values[MEMORY_METER_AVAILABLE] = "available memory" +} + +void Platform_setSwapValues(Meter* this) { + const Machine* host = this->host; + this->total = host->totalSwap; + this->values[SWAP_METER_USED] = host->usedSwap; + // mtr->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // mtr->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" +} + +char* Platform_getProcessEnv(pid_t pid) { + // TODO + (void)pid; // prevent unused warning + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + +void Platform_getFileDescriptors(double* used, double* max) { + Generic_getFileDescriptors_sysctl(used, max); +} + +bool Platform_getDiskIO(DiskIOData* data) { + // TODO + (void)data; + return false; +} + +bool Platform_getNetworkIO(NetworkIOData* data) { + // TODO + (void)data; + return false; +} + +void Platform_getBattery(double* percent, ACPresence* isOnAC) { + int life; + size_t life_len = sizeof(life); + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + *percent = NAN; + else + *percent = life; + + int acline; + size_t acline_len = sizeof(acline); + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + *isOnAC = AC_ERROR; + else + *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; +} diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h new file mode 100644 index 0000000..606b004 --- /dev/null +++ b/dragonflybsd/Platform.h @@ -0,0 +1,134 @@ +#ifndef HEADER_Platform +#define HEADER_Platform +/* +htop - dragonflybsd/Platform.h +(C) 2014 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <sys/types.h> + +#include "Action.h" +#include "BatteryMeter.h" +#include "DiskIOMeter.h" +#include "Hashtable.h" +#include "Macros.h" +#include "Meter.h" +#include "NetworkIOMeter.h" +#include "Process.h" +#include "ProcessLocksScreen.h" +#include "SignalsPanel.h" +#include "CommandLine.h" +#include "generic/gettime.h" +#include "generic/hostname.h" +#include "generic/uname.h" + + +extern const ScreenDefaults Platform_defaultScreens[]; + +extern const unsigned int Platform_numberOfDefaultScreens; + +extern const SignalItem Platform_signals[]; + +extern const unsigned int Platform_numberOfSignals; + +extern const MeterClass* const Platform_meterTypes[]; + +bool Platform_init(void); + +void Platform_done(void); + +void Platform_setBindings(Htop_Action* keys); + +int Platform_getUptime(void); + +void Platform_getLoadAverage(double* one, double* five, double* fifteen); + +pid_t Platform_getMaxPid(void); + +double Platform_setCPUValues(Meter* this, unsigned int cpu); + +void Platform_setMemoryValues(Meter* this); + +void Platform_setSwapValues(Meter* this); + +char* Platform_getProcessEnv(pid_t pid); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + +void Platform_getFileDescriptors(double* used, double* max); + +bool Platform_getDiskIO(DiskIOData* data); + +bool Platform_getNetworkIO(NetworkIOData* data); + +void Platform_getBattery(double* percent, ACPresence* isOnAC); + +static inline void Platform_getHostname(char* buffer, size_t size) { + Generic_hostname(buffer, size); +} + +static inline void Platform_getRelease(char** string) { + *string = Generic_uname(); +} + +#define PLATFORM_LONG_OPTIONS + +static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } + +static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { + return STATUS_ERROR_EXIT; +} + +static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { + Generic_gettime_realtime(tv, msec); +} + +static inline void Platform_gettime_monotonic(uint64_t* msec) { + Generic_gettime_monotonic(msec); +} + +static inline Hashtable* Platform_dynamicMeters(void) { + return NULL; +} + +static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable* table) { } + +static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter* meter) { } + +static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter* meter) { } + +static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter* meter, ATTR_UNUSED RichString* out) { } + +static inline Hashtable* Platform_dynamicColumns(void) { + return NULL; +} + +static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { } + +static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) { + return NULL; +} + +static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* proc, ATTR_UNUSED RichString* str, ATTR_UNUSED unsigned int key) { + return false; +} + +static inline Hashtable* Platform_dynamicScreens(void) { + return NULL; +} + +static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { } + +static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { } + +static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { } + +static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { } + +#endif diff --git a/dragonflybsd/ProcessField.h b/dragonflybsd/ProcessField.h new file mode 100644 index 0000000..1409675 --- /dev/null +++ b/dragonflybsd/ProcessField.h @@ -0,0 +1,19 @@ +#ifndef HEADER_DragonFlyBSDProcessField +#define HEADER_DragonFlyBSDProcessField +/* +htop - dragonflybsd/ProcessField.h +(C) 2020 htop dev team +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + + +#define PLATFORM_PROCESS_FIELDS \ + JID = 100, \ + JAIL = 101, \ + \ + DUMMY_BUMP_FIELD = CWD, \ + // End of list + + +#endif /* HEADER_DragonFlyBSDProcessField */ |