Cache PAGE_SIZE

man:sysconf(3) states:
    The values obtained from these functions are system configuration constants.
    They do not change during the lifetime of a process.
This commit is contained in:
Christian Göttsche
2020-10-15 22:37:02 +02:00
parent 0db398d4c3
commit 361877454f
11 changed files with 60 additions and 49 deletions

View File

@ -19,6 +19,7 @@ in the source distribution for its full text.
#include <sys/sysctl.h>
#include <sys/user.h>
#include "CRT.h"
#include "FreeBSDProcess.h"
#include "Macros.h"
#include "ProcessList.h"
@ -60,8 +61,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_pageSize;
} else {
pageSizeKb = pageSize / ONE_K;
}
@ -446,12 +447,12 @@ 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)(this->totalMem) * 100.0;
proc->percent_mem = (proc->m_resident * pageSizeKb) / (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);
proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(this->totalMem);
/*
* TODO