From 8c82a38002ce09db2a0b83dab8b598cf1ab0596c Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:01:17 +0200 Subject: Imported Upstream version 2.0.1 --- freebsd/Battery.c | 18 ++++++++++++++---- freebsd/Battery.h | 1 - freebsd/FreeBSDProcess.c | 4 ++-- freebsd/FreeBSDProcessList.c | 29 ++++++++++++++++------------- freebsd/FreeBSDProcessList.h | 1 - freebsd/Platform.c | 11 ++++++----- 6 files changed, 38 insertions(+), 26 deletions(-) (limited to 'freebsd') diff --git a/freebsd/Battery.c b/freebsd/Battery.c index ab63aa1..b8c5e31 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -6,10 +6,20 @@ in the source distribution for its full text. */ #include "BatteryMeter.h" +#include void Battery_getData(double* level, ACPresence* isOnAC) { - // TODO - *level = -1; - *isOnAC = AC_ERROR; -} + 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/freebsd/Battery.h b/freebsd/Battery.h index 2b4a9a8..cc5b1fe 100644 --- a/freebsd/Battery.h +++ b/freebsd/Battery.h @@ -11,5 +11,4 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC); - #endif diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 70cfb95..b0d2c37 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -115,7 +115,7 @@ void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField fiel char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; - switch (field) { + switch ((int) field) { // add FreeBSD-specific fields here case JID: snprintf(buffer, n, Process_pidFormat, fp->jid); break; case JAIL:{ @@ -143,7 +143,7 @@ long FreeBSDProcess_compare(const void* v1, const void* v2) { p2 = (FreeBSDProcess*)v1; p1 = (FreeBSDProcess*)v2; } - switch (settings->sortKey) { + switch ((int) settings->sortKey) { // add FreeBSD-specific fields here case JID: return (p1->jid - p2->jid); diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 7c4a6db..241bee2 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -14,7 +14,9 @@ in the source distribution for its full text. #include #include #include +#include #include +#include #include /*{ @@ -84,14 +86,13 @@ static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; static int kernelFScale; - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { + size_t len; + char errbuf[_POSIX2_LINE_MAX]; FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList)); ProcessList* pl = (ProcessList*) fpl; ProcessList_init(pl, Class(FreeBSDProcess), usersTable, pidWhiteList, userId); - size_t len; - // physical memory in system: hw.physmem // physical page size: hw.pagesize // usable pagesize : vm.stats.vm.v_page_size @@ -178,8 +179,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui kernelFScale = 2048; } - fpl->kd = kvm_open(NULL, "/dev/null", NULL, 0, NULL); - assert(fpl->kd); + fpl->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf); + if (fpl->kd == NULL) { + errx(1, "kvm_open: %s", errbuf); + } return pl; } @@ -212,9 +215,6 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { unsigned long *cp_time_n; // old clicks state unsigned long *cp_time_o; // current clicks state - unsigned long long total_o = 0; - unsigned long long total_n = 0; - unsigned long long total_d = 0; unsigned long cp_time_d[CPUSTATES]; double cp_time_p[CPUSTATES]; @@ -251,6 +251,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { } // 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]; @@ -477,19 +480,19 @@ void ProcessList_goThroughEntries(ProcessList* this) { } // from FreeBSD source /src/usr.bin/top/machine.c - proc->m_size = kproc->ki_size / 1024; - proc->m_resident = kproc->ki_rssize * pageSizeKb; + proc->m_size = kproc->ki_size / 1024 / pageSizeKb; + proc->m_resident = kproc->ki_rssize; + proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0; proc->nlwp = kproc->ki_numthreads; proc->time = (kproc->ki_runtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale); + proc->percent_mem = 100.0 * (proc->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem); + if (proc->percent_cpu > 0.1) { // system idle process should own all CPU time left regardless of CPU count if ( strcmp("idle", kproc->ki_comm) == 0 ) { isIdleProcess = true; - } else { - if (cpus > 1) - proc->percent_cpu = proc->percent_cpu / (double) cpus; } } if (isIdleProcess == false && proc->percent_cpu >= 99.8) { diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 2267379..af343fb 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -55,7 +55,6 @@ typedef struct FreeBSDProcessList_ { - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 9e0c25b..4185a8b 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -24,6 +24,7 @@ in the source distribution for its full text. #include #include #include +#include /*{ #include "Action.h" @@ -162,15 +163,15 @@ double Platform_setCPUValues(Meter* this, int cpu) { double percent; double* v = this->values; - v[CPU_METER_NICE] = cpuData->nicePercent; - v[CPU_METER_NORMAL] = cpuData->userPercent; + v[CPU_METER_NICE] = cpuData->nicePercent * cpus; + v[CPU_METER_NORMAL] = cpuData->userPercent * cpus; if (this->pl->settings->detailedCPUTime) { - v[CPU_METER_KERNEL] = cpuData->systemPercent; - v[CPU_METER_IRQ] = cpuData->irqPercent; + v[CPU_METER_KERNEL] = cpuData->systemPercent * cpus; + v[CPU_METER_IRQ] = cpuData->irqPercent * cpus; Meter_setItems(this, 4); percent = v[0]+v[1]+v[2]+v[3]; } else { - v[2] = cpuData->systemAllPercent; + v[2] = cpuData->systemAllPercent * cpus; Meter_setItems(this, 3); percent = v[0]+v[1]+v[2]; } -- cgit v1.2.3