From 65357c8c46154de4e4eca14075bfe5523bb5fc14 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 7 Dec 2020 10:26:01 +0100 Subject: New upstream version 3.0.3 --- dragonflybsd/Battery.c | 26 ------ dragonflybsd/Battery.h | 13 --- dragonflybsd/DragonFlyBSDCRT.c | 34 -------- dragonflybsd/DragonFlyBSDCRT.h | 13 --- dragonflybsd/DragonFlyBSDProcess.c | 46 ++++++----- dragonflybsd/DragonFlyBSDProcess.h | 10 +-- dragonflybsd/DragonFlyBSDProcessList.c | 146 +++++++++++++++++---------------- dragonflybsd/DragonFlyBSDProcessList.h | 18 ++-- dragonflybsd/Platform.c | 114 +++++++++++++++++++------ dragonflybsd/Platform.h | 34 ++++++-- 10 files changed, 226 insertions(+), 228 deletions(-) delete mode 100644 dragonflybsd/Battery.c delete mode 100644 dragonflybsd/Battery.h delete mode 100644 dragonflybsd/DragonFlyBSDCRT.c delete mode 100644 dragonflybsd/DragonFlyBSDCRT.h (limited to 'dragonflybsd') diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c deleted file mode 100644 index f17efb5..0000000 --- a/dragonflybsd/Battery.c +++ /dev/null @@ -1,26 +0,0 @@ -/* -htop - dragonflybsd/Battery.c -(C) 2015 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -#include "BatteryMeter.h" -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - int life; - size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) - *level = -1; - else - *level = 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/Battery.h b/dragonflybsd/Battery.h deleted file mode 100644 index f764a2d..0000000 --- a/dragonflybsd/Battery.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery -/* -htop - dragonflybsd/Battery.h -(C) 2015 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/dragonflybsd/DragonFlyBSDCRT.c b/dragonflybsd/DragonFlyBSDCRT.c deleted file mode 100644 index a092083..0000000 --- a/dragonflybsd/DragonFlyBSDCRT.c +++ /dev/null @@ -1,34 +0,0 @@ -/* -htop - dragonflybsd/DragonFlyBSDCRT.c -(C) 2014 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" -#include "CRT.h" -#include -#include -#ifdef HAVE_EXECINFO_H -#include -#endif - -void CRT_handleSIGSEGV(int sgn) { - (void) sgn; - CRT_done(); - fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at https://htop.dev\n"); - #ifdef HAVE_EXECINFO_H - size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); - fprintf(stderr, "\n Please include in your report the following backtrace: \n"); - backtrace_symbols_fd(backtraceArray, size, 2); - fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); - fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); - fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); - fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); - fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); - #else - fprintf(stderr, "\nPlease contact your DragonFlyBSD package maintainer!\n\n"); - #endif - abort(); -} diff --git a/dragonflybsd/DragonFlyBSDCRT.h b/dragonflybsd/DragonFlyBSDCRT.h deleted file mode 100644 index 2bf85f7..0000000 --- a/dragonflybsd/DragonFlyBSDCRT.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef HEADER_DragonFlyBSDCRT -#define HEADER_DragonFlyBSDCRT -/* -htop - dragonflybsd/DragonFlyBSDCRT.h -(C) 2014 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file -in the source distribution for its full text. -*/ - -void CRT_handleSIGSEGV(int sgn); - -#endif diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 770143b..9311f03 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -2,7 +2,7 @@ htop - dragonflybsd/DragonFlyBSDProcess.c (C) 2015 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ @@ -18,14 +18,14 @@ in the source distribution for its full text. #include -ProcessClass DragonFlyBSDProcess_class = { +const ProcessClass DragonFlyBSDProcess_class = { .super = { .extends = Class(Process), .display = Process_display, .delete = Process_delete, .compare = DragonFlyBSDProcess_compare }, - .writeField = (Process_WriteField) DragonFlyBSDProcess_writeField, + .writeField = DragonFlyBSDProcess_writeField, }; ProcessFieldData Process_fields[] = { @@ -44,10 +44,11 @@ ProcessFieldData Process_fields[] = { [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, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, - [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, + [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .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, }, [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, }, + [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, }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, [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, }, @@ -69,11 +70,11 @@ ProcessPidColumn Process_pidColumns[] = { { .id = 0, .label = NULL }, }; -DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings) { +Process* DragonFlyBSDProcess_new(const Settings* settings) { DragonFlyBSDProcess* this = xCalloc(1, sizeof(DragonFlyBSDProcess)); Object_setClass(this, Class(DragonFlyBSDProcess)); Process_init(&this->super, settings); - return this; + return &this->super; } void Process_delete(Object* cast) { @@ -83,8 +84,8 @@ void Process_delete(Object* cast) { free(this); } -void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field) { - DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this; +void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { + const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; @@ -92,7 +93,7 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField // add Platform-specific fields here case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break; case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; - case JAIL:{ + case JAIL: { xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; @@ -108,31 +109,34 @@ void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField } long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { - DragonFlyBSDProcess *p1, *p2; - Settings *settings = ((Process*)v1)->settings; + const DragonFlyBSDProcess *p1, *p2; + const Settings *settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { - p1 = (DragonFlyBSDProcess*)v1; - p2 = (DragonFlyBSDProcess*)v2; + p1 = (const DragonFlyBSDProcess*)v1; + p2 = (const DragonFlyBSDProcess*)v2; } else { - p2 = (DragonFlyBSDProcess*)v1; - p1 = (DragonFlyBSDProcess*)v2; + p2 = (const DragonFlyBSDProcess*)v1; + p1 = (const DragonFlyBSDProcess*)v2; } + switch ((int) settings->sortKey) { // add Platform-specific fields here case JID: - return (p1->jid - p2->jid); + return SPACESHIP_NUMBER(p1->jid, p2->jid); case JAIL: - return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : ""); + return SPACESHIP_NULLSTR(p1->jname, p2->jname); default: return Process_compare(v1, v2); } } -bool Process_isThread(Process* this) { - DragonFlyBSDProcess* fp = (DragonFlyBSDProcess*) this; +bool Process_isThread(const Process* this) { + const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; - if (fp->kernel == 1 ) + if (fp->kernel == 1 ) { return 1; - else + } else { return (Process_isUserlandThread(this)); + } } diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index d5e5a6e..1befd94 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -4,7 +4,7 @@ htop - dragonflybsd/DragonFlyBSDProcess.h (C) 2015 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ @@ -27,20 +27,20 @@ typedef struct DragonFlyBSDProcess_ { //#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) #define Process_isUserlandThread(_process) (_process->nlwp > 1) -extern ProcessClass DragonFlyBSDProcess_class; +extern const ProcessClass DragonFlyBSDProcess_class; extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; -DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings); +Process* DragonFlyBSDProcess_new(const Settings* settings); void Process_delete(Object* cast); -void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field); +void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field); long DragonFlyBSDProcess_compare(const void* v1, const void* v2); -bool Process_isThread(Process* this); +bool Process_isThread(const Process* this); #endif diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index cd5526a..940ec03 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -2,7 +2,7 @@ htop - DragonFlyBSDProcessList.c (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ @@ -21,8 +21,9 @@ in the source distribution for its full text. #include #include +#include "CRT.h" +#include "Macros.h" -#define _UNUSED_ __attribute__((unused)) static int MIB_hw_physmem[2]; static int MIB_vm_stats_vm_v_page_count[4]; @@ -55,8 +56,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui len = sizeof(pageSize); if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) { - pageSize = PAGE_SIZE; - pageSizeKb = PAGE_SIZE_KB; + pageSize = CRT_pageSize; + pageSizeKb = CRT_pageSizeKB; } else { pageSizeKb = pageSize / ONE_K; } @@ -100,10 +101,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { - dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); + dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); } else { - // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) - dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); + // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) + dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); } len = sizeof(kernelFScale); @@ -122,7 +123,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this) { const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; - if (dfpl->kd) kvm_close(dfpl->kd); + if (dfpl->kd) { + kvm_close(dfpl->kd); + } if (dfpl->jails) { Hashtable_delete(dfpl->jails); @@ -148,8 +151,8 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { 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_n; // old clicks state + unsigned long* cp_time_o; // current clicks state unsigned long cp_time_d[CPUSTATES]; double cp_time_p[CPUSTATES]; @@ -160,12 +163,12 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // 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, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); + // 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, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); } for (int i = 0; i < maxcpu; i++) { @@ -175,14 +178,14 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { cp_time_o = dfpl->cp_time_o; } else { if (i == 0 ) { - // average - cp_time_n = dfpl->cp_time_n; - cp_time_o = dfpl->cp_time_o; + // average + cp_time_n = dfpl->cp_time_n; + cp_time_o = dfpl->cp_time_o; } else { - // specific smp cores - cp_times_offset = i - 1; - cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); - cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); + // specific smp cores + cp_times_offset = i - 1; + cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); + cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); } } @@ -191,19 +194,21 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { 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]; + 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; + 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; + cp_time_o[s] = cp_time_n[s]; + cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; } CPUData* cpuData = &(dfpl->cpus[i]); @@ -248,14 +253,8 @@ static inline void DragonFlyBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->cachedMem *= pageSizeKb; pl->usedMem = dfpl->memActive + dfpl->memWire; - //currently unused, same as with arc, custom meter perhaps - //sysctl(MIB_vm_stats_vm_v_inactive_count, 4, &(dfpl->memInactive), &len, NULL, 0); - //sysctl(MIB_vm_stats_vm_v_free_count, 4, &(dfpl->memFree), &len, NULL, 0); - //pl->freeMem = dfpl->memInactive + dfpl->memFree; - //pl->freeMem *= pageSizeKb; - struct kvm_swap swap[16]; - int nswap = kvm_getswapinfo(dfpl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); + int nswap = kvm_getswapinfo(dfpl->kd, swap, ARRAYSIZE(swap), 0); pl->totalSwap = 0; pl->usedSwap = 0; for (int i = 0; i < nswap; i++) { @@ -264,8 +263,6 @@ static inline void DragonFlyBSDProcessList_scanMemoryInfo(ProcessList* pl) { } pl->totalSwap *= pageSizeKb; pl->usedSwap *= pageSizeKb; - - pl->sharedMem = 0; // currently unused } char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { @@ -295,9 +292,9 @@ char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kpro static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* dfpl) { size_t len; - char *jls; /* Jail list */ - char *curpos; - char *nextpos; + char* jls; /* Jail list */ + char* curpos; + char* nextpos; if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) { fprintf(stderr, "initial sysctlbyname / jail.list failed\n"); @@ -328,30 +325,32 @@ retry: curpos = jls; while (curpos) { int jailid; - char *str_hostname; + char* str_hostname; nextpos = strchr(curpos, '\n'); - if (nextpos) + if (nextpos) { *nextpos++ = 0; + } jailid = atoi(strtok(curpos, " ")); str_hostname = strtok(NULL, " "); - char *jname = (char *) (Hashtable_get(dfpl->jails, jailid)); + char* jname = (char*) (Hashtable_get(dfpl->jails, jailid)); if (jname == NULL) { jname = xStrdup(str_hostname); Hashtable_put(dfpl->jails, jailid, jname); } curpos = nextpos; - } - free(jls); + } + + free(jls); } char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) { char* hostname; char* jname; - if (jailid != 0 && dfpl->jails && (hostname = (char *)Hashtable_get(dfpl->jails, jailid))) { + if (jailid != 0 && dfpl->jails && (hostname = (char*)Hashtable_get(dfpl->jails, jailid))) { jname = xStrdup(hostname); } else { jname = xStrdup("-"); @@ -359,16 +358,21 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja return jname; } -void ProcessList_goThroughEntries(ProcessList* this) { - DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; - Settings* settings = this->settings; +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) super; + const Settings* settings = super->settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; - DragonFlyBSDProcessList_scanMemoryInfo(this); - DragonFlyBSDProcessList_scanCPUTime(this); + DragonFlyBSDProcessList_scanMemoryInfo(super); + DragonFlyBSDProcessList_scanCPUTime(super); DragonFlyBSDProcessList_scanJails(dfpl); + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) { + return; + } + int count = 0; // TODO Kernel Threads seem to be skipped, need to figure out the correct flag @@ -377,10 +381,10 @@ void ProcessList_goThroughEntries(ProcessList* this) { for (int i = 0; i < count; i++) { struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; - bool _UNUSED_ isIdleProcess = 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 = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new); + Process* proc = ProcessList_getProcess(super, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, DragonFlyBSDProcess_new); DragonFlyBSDProcess* dfp = (DragonFlyBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(dfp)) || (hideUserlandThreads && Process_isUserlandThread(proc))); @@ -405,24 +409,23 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->st_uid = kproc->kp_uid; // user ID proc->processor = kproc->kp_lwp.kl_origcpu; proc->starttime_ctime = kproc->kp_start.tv_sec; - proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); + proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); - ProcessList_add((ProcessList*)this, proc); + ProcessList_add(super, proc); proc->comm = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->basenameOffset); dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); } else { proc->processor = kproc->kp_lwp.kl_cpuid; - if(dfp->jid != kproc->kp_jailid) { // process can enter jail anytime + if (dfp->jid != kproc->kp_jailid) { // process can enter jail anytime dfp->jid = kproc->kp_jailid; free(dfp->jname); dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); } - if (proc->ppid != kproc->kp_ppid) { // if there are reapers in the system, process can get reparented anytime - proc->ppid = kproc->kp_ppid; - } - if(proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) + // if there are reapers in the system, process can get reparented anytime + proc->ppid = 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(this->usersTable, proc->st_uid); + proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); } if (settings->updateProcessNames) { free(proc->comm); @@ -430,14 +433,13 @@ void ProcessList_goThroughEntries(ProcessList* this) { } } - proc->m_size = kproc->kp_vm_map_size / 1024 / pageSizeKb; + proc->m_virt = kproc->kp_vm_map_size / pageSize; proc->m_resident = kproc->kp_vm_rssize; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0; proc->nlwp = kproc->kp_nthreads; // number of lwp thread proc->time = (kproc->kp_swtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->kp_lwp.kl_pctcpu / (double)kernelFScale); - proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem); + proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(super->totalMem); if (proc->percent_cpu > 0.1) { // system idle process should own all CPU time left regardless of CPU count @@ -472,18 +474,18 @@ void ProcessList_goThroughEntries(ProcessList* this) { case SACTIVE: switch (kproc->kp_lwp.kl_stat) { case LSSLEEP: - if (kproc->kp_lwp.kl_flags & LWP_SINTR) // interruptable wait short/long + if (kproc->kp_lwp.kl_flags & LWP_SINTR) // interruptible wait short/long if (kproc->kp_lwp.kl_slptime >= MAXSLP) { proc->state = 'I'; isIdleProcess = true; } else { proc->state = 'S'; } - else if (kproc->kp_lwp.kl_tdflags & TDF_SINTR) // interruptable lwkt wait + else if (kproc->kp_lwp.kl_tdflags & TDF_SINTR) // interruptible lwkt wait proc->state = 'S'; - else if (kproc->kp_paddr) // uninterruptable wait + else if (kproc->kp_paddr) // uninterruptible wait proc->state = 'D'; - else // uninterruptable lwkt wait + else // uninterruptible lwkt wait proc->state = 'B'; break; case LSRUN: @@ -519,12 +521,12 @@ void ProcessList_goThroughEntries(ProcessList* this) { } if (Process_isKernelThread(dfp)) { - this->kernelThreads++; + super->kernelThreads++; } - this->totalTasks++; + super->totalTasks++; if (proc->state == 'R') - this->runningTasks++; + super->runningTasks++; proc->updated = true; } } diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 84ab1c5..682971e 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -4,7 +4,7 @@ htop - DragonFlyBSDProcessList.h (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ @@ -19,7 +19,7 @@ in the source distribution for its full text. #include "Hashtable.h" #include "DragonFlyBSDProcess.h" -#define JAIL_ERRMSGLEN 1024 +#define JAIL_ERRMSGLEN 1024 extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { @@ -42,17 +42,15 @@ typedef struct DragonFlyBSDProcessList_ { CPUData* cpus; - unsigned long *cp_time_o; - unsigned long *cp_time_n; + unsigned long* cp_time_o; + unsigned long* cp_time_n; - unsigned long *cp_times_o; - unsigned long *cp_times_n; + unsigned long* cp_times_o; + unsigned long* cp_times_n; - Hashtable *jails; + Hashtable* jails; } DragonFlyBSDProcessList; -#define _UNUSED_ __attribute__((unused)) - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* this); @@ -61,6 +59,6 @@ char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kpro char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid); -void ProcessList_goThroughEntries(ProcessList* this); +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 3b8e1a0..40a7348 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -2,11 +2,12 @@ htop - dragonflybsd/Platform.c (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ #include "Platform.h" +#include "Macros.h" #include "Meter.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -15,6 +16,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "DragonFlyBSDProcess.h" #include "DragonFlyBSDProcessList.h" @@ -28,7 +31,7 @@ in the source distribution for its full text. #include -ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, 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 }; int Platform_numberOfFields = LAST_PROCESSFIELD; @@ -69,15 +72,13 @@ const SignalItem Platform_signals[] = { { .name = "33 SIGLIBRT", .number = 33 }, }; -const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); +const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); -void Platform_setBindings(Htop_Action* keys) { - (void) keys; -} - -MeterClass* Platform_meterTypes[] = { +const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, @@ -88,14 +89,33 @@ MeterClass* Platform_meterTypes[] = { &HostnameMeter_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, &BlankMeter_class, NULL }; +void Platform_init(void) { + /* no platform-specific setup needed */ +} + +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() { struct timeval bootTime, currTime; int mib[2] = { CTL_KERN, KERN_BOOTTIME }; @@ -138,15 +158,15 @@ int Platform_getMaxPid() { } double Platform_setCPUValues(Meter* this, int cpu) { - DragonFlyBSDProcessList* fpl = (DragonFlyBSDProcessList*) this->pl; + const DragonFlyBSDProcessList* fpl = (const DragonFlyBSDProcessList*) this->pl; int cpus = this->pl->cpuCount; - CPUData* cpuData; + const CPUData* cpuData; if (cpus == 1) { - // single CPU box has everything in fpl->cpus[0] - cpuData = &(fpl->cpus[0]); + // single CPU box has everything in fpl->cpus[0] + cpuData = &(fpl->cpus[0]); } else { - cpuData = &(fpl->cpus[cpu]); + cpuData = &(fpl->cpus[cpu]); } double percent; @@ -157,25 +177,25 @@ double Platform_setCPUValues(Meter* this, int cpu) { if (this->pl->settings->detailedCPUTime) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; - Meter_setItems(this, 4); - percent = v[0]+v[1]+v[2]+v[3]; + this->curItems = 4; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; - Meter_setItems(this, 3); - percent = v[0]+v[1]+v[2]; + this->curItems = 3; + percent = v[0] + v[1] + v[2]; } - percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; + v[CPU_METER_TEMPERATURE] = NAN; return percent; } void Platform_setMemoryValues(Meter* this) { // TODO - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalMem; this->values[0] = pl->usedMem; @@ -184,18 +204,58 @@ void Platform_setMemoryValues(Meter* this) { } void Platform_setSwapValues(Meter* this) { - ProcessList* pl = (ProcessList*) this->pl; + const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; } -void Platform_setTasksValues(Meter* this) { +char* Platform_getProcessEnv(pid_t pid) { + // TODO + (void)pid; // prevent unused warning + return NULL; +} + +char* Platform_getInodeFilename(pid_t pid, ino_t inode) { + (void)pid; + (void)inode; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + +bool Platform_getDiskIO(DiskIOData* data) { // TODO - (void)this; // prevent unused warning + (void)data; + return false; } -char* Platform_getProcessEnv(pid_t pid) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO - (void)pid; // prevent unused warning - return NULL; + *bytesReceived = 0; + *packetsReceived = 0; + *bytesTransmitted = 0; + *packetsTransmitted = 0; + 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 index 83c14f5..5456539 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -4,12 +4,17 @@ htop - dragonflybsd/Platform.h (C) 2014 Hisham H. Muhammad (C) 2017 Diederik de Groot -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include +#include + #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" +#include "ProcessLocksScreen.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -22,15 +27,19 @@ extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; -void Platform_setBindings(Htop_Action* keys); +extern const MeterClass* const Platform_meterTypes[]; + +void Platform_init(void); -extern MeterClass* Platform_meterTypes[]; +void Platform_done(void); -int Platform_getUptime(); +void Platform_setBindings(Htop_Action* keys); + +int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(); +int Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, int cpu); @@ -38,8 +47,19 @@ void Platform_setMemoryValues(Meter* this); void Platform_setSwapValues(Meter* this); -void Platform_setTasksValues(Meter* this); - char* Platform_getProcessEnv(pid_t pid); +char* Platform_getInodeFilename(pid_t pid, ino_t inode); + +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); + +void Platform_getBattery(double* percent, ACPresence* isOnAC); + #endif -- cgit v1.2.3