summaryrefslogtreecommitdiffstats
path: root/freebsd
diff options
context:
space:
mode:
authorMartin "eto" Misuth <et.code@ethome.sk>2015-12-13 01:39:54 +0100
committerMartin "eto" Misuth <et.code@ethome.sk>2015-12-13 01:39:54 +0100
commit80f594f3145eea6345657be1a86d208b9401341b (patch)
tree1f0ba0497e7fab4d12d9775d30d738d18e815efb /freebsd
parentc2769985ccea4894a6fb9fbfa9588ef520e907db (diff)
added CPU% for processes in process list
Diffstat (limited to 'freebsd')
-rw-r--r--freebsd/FreeBSDProcessList.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index a8e1af09..4531a7b1 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -63,7 +63,7 @@ static int MIB_kern_cp_time[2];
static int MIB_kern_cp_times[2];
static int pageSizeKb;
-
+static int kernelFScale;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
FreeBSDProcessList* fpl = calloc(1, sizeof(FreeBSDProcessList));
@@ -79,6 +79,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
fpl->kd = kvm_open(NULL, "/dev/null", NULL, 0, NULL);
assert(fpl->kd);
+ size_t sizeof_kernelFScale = sizeof(kernelFScale);
+ if (sysctlbyname("kern.fscale", &kernelFScale, &sizeof_kernelFScale, NULL, 0) == -1) {
+ //sane default on x86 machines, in case this sysctl call failed
+ kernelFScale = 2048;
+ }
+
int smp = 0;
size_t sizeof_smp = sizeof(smp);
@@ -322,6 +328,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
FreeBSDProcessList_scanMemoryInfo(this);
FreeBSDProcessList_scanCPUTime(this);
+ int cpus = this->cpuCount;
int count = 0;
struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_ALL, 0, &count);
@@ -379,6 +386,15 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->nlwp = kproc->ki_numthreads;
proc->time = (kproc->ki_runtime + 5000) / 10000;
+ proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale);
+ if (cpus > 1 ) {
+ proc->percent_cpu = proc->percent_cpu / (double) cpus;
+ }
+ if (proc->percent_cpu >= 99.8) {
+ // don't break formatting
+ proc->percent_cpu = 99.8;
+ }
+
proc->priority = kproc->ki_pri.pri_level - PZERO;
if (strcmp("intr", kproc->ki_comm) == 0 && kproc->ki_flag & P_SYSTEM) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy