From d0d14da8d91bc9a73856852be1a0a6d42b24a30d Mon Sep 17 00:00:00 2001 From: Bernard Spil Date: Fri, 12 Feb 2016 14:37:24 +0100 Subject: [PATCH 1/4] Fix implicit define isnan() --- freebsd/Platform.c | 1 + 1 file changed, 1 insertion(+) diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 9e0c25b0..f02daa5a 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" From d753996b967166b351dd1bffbc65c8c3a3b703a6 Mon Sep 17 00:00:00 2001 From: Bernard Spil Date: Sun, 14 Feb 2016 21:48:36 +0100 Subject: [PATCH 2/4] Fix memory percentage display on FreeBSD --- freebsd/FreeBSDProcessList.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index b9359e54..e6ef4528 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -84,6 +84,8 @@ static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; static int kernelFScale; +// XXX hack +static unsigned long long int Global_totalMem; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList)); @@ -301,6 +303,8 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { //pl->totalMem *= pageSizeKb; sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); pl->totalMem /= 1024; + // XXX hack + Global_totalMem = pl->totalMem; sysctl(MIB_vm_stats_vm_v_active_count, 4, &(fpl->memActive), &len, NULL, 0); fpl->memActive *= pageSizeKb; @@ -479,6 +483,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { // from FreeBSD source /src/usr.bin/top/machine.c proc->m_size = kproc->ki_size / 1024 / pageSizeKb; proc->m_resident = kproc->ki_rssize; + proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(Global_totalMem) * 100.0; proc->nlwp = kproc->ki_numthreads; proc->time = (kproc->ki_runtime + 5000) / 10000; @@ -487,9 +492,6 @@ void ProcessList_goThroughEntries(ProcessList* this) { // 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) { From f554f08fa92f8440faa853b5fa4d588829959c8a Mon Sep 17 00:00:00 2001 From: Bernard Spil Date: Sun, 14 Feb 2016 22:21:11 +0100 Subject: [PATCH 3/4] Fix FreeBSD CPU% calculation --- freebsd/Platform.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/freebsd/Platform.c b/freebsd/Platform.c index f02daa5a..4185a8b5 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -163,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]; } From db80f202f2b264ecbc979661c48204ec97a849af Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 7 Mar 2016 16:57:56 -0300 Subject: [PATCH 4/4] Avoid global, as done by @gaod in #387. --- freebsd/FreeBSDProcessList.c | 7 +------ freebsd/FreeBSDProcessList.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 9d921d9e..241bee23 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -86,9 +86,6 @@ static int MIB_kern_cp_time[2]; static int MIB_kern_cp_times[2]; static int kernelFScale; -// XXX hack -static unsigned long long int Global_totalMem; - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { size_t len; char errbuf[_POSIX2_LINE_MAX]; @@ -307,8 +304,6 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { //pl->totalMem *= pageSizeKb; sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); pl->totalMem /= 1024; - // XXX hack - Global_totalMem = pl->totalMem; sysctl(MIB_vm_stats_vm_v_active_count, 4, &(fpl->memActive), &len, NULL, 0); fpl->memActive *= pageSizeKb; @@ -487,7 +482,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { // from FreeBSD source /src/usr.bin/top/machine.c proc->m_size = kproc->ki_size / 1024 / pageSizeKb; proc->m_resident = kproc->ki_rssize; - proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(Global_totalMem) * 100.0; + 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; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 2267379e..af343fb0 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);