From 1b5025e6f52fbfd792a674ead1dfe59f3d1866b0 Mon Sep 17 00:00:00 2001 From: Juan Francisco Cantero Hurtado Date: Fri, 12 Feb 2016 01:28:22 +0100 Subject: [PATCH] Add support for cachedMem and fix usedMem on OpenBSD. --- openbsd/OpenBSDProcessList.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 97e40cb8..57c3abbb 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -10,18 +10,19 @@ in the source distribution for its full text. #include "OpenBSDProcessList.h" #include "OpenBSDProcess.h" -#include -#include #include #include -#include +#include +#include #include #include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include /*{ @@ -95,16 +96,28 @@ void ProcessList_delete(ProcessList* this) { static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP}; struct uvmexp uvmexp; - size_t size = sizeof(uvmexp); + size_t size_uvmexp = sizeof(uvmexp); - if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) { + if (sysctl(uvmexp_mib, 2, &uvmexp, &size_uvmexp, NULL, 0) < 0) { err(1, "uvmexp sysctl call failed"); } //kb_pagesize = uvmexp.pagesize / 1024; - pl->usedMem = uvmexp.active * pageSizeKb; pl->totalMem = uvmexp.npages * pageSizeKb; + // Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9) + static int bcache_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT}; + struct bcachestats bcstats; + size_t size_bcstats = sizeof(bcstats); + + if (sysctl(bcache_mib, 3, &bcstats, &size_bcstats, NULL, 0) < 0) { + err(1, "cannot get vfs.bcachestat"); + } + + pl->cachedMem = bcstats.numbufpages * pageSizeKb; + pl->freeMem = uvmexp.free * pageSizeKb; + pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * pageSizeKb; + /* const OpenBSDProcessList* opl = (OpenBSDProcessList*) pl;