diff options
Diffstat (limited to 'kicker-applets/ktimemon/sample.cpp')
-rw-r--r-- | kicker-applets/ktimemon/sample.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/kicker-applets/ktimemon/sample.cpp b/kicker-applets/ktimemon/sample.cpp index 5864583..80f42ef 100644 --- a/kicker-applets/ktimemon/sample.cpp +++ b/kicker-applets/ktimemon/sample.cpp @@ -33,6 +33,12 @@ #include <sys/swap.h> #endif +#ifdef __NetBSD__ +#include <sys/sysctl.h> +#include <sys/sched.h> +#include <uvm/uvm_extern.h> +#endif + #include <tqwidget.h> #include <tdelocale.h> #include <tdemessagebox.h> @@ -418,6 +424,60 @@ void KSample::readSample() free(stbl); } +#elif defined(__NetBSD__) + int mib[2]; + int ncpu; + size_t len; + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + len = sizeof(ncpu); + if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1) { + fatal(i18n("Unable to get the number of CPUs configured.\n" + "The diagnostics are '%1'.\n" + "Please contact the maintainer at http://bugs.trinitydesktop.org/ who will try to sort this out.").arg(strerror(errno))); + } else { + sample.cpus = ncpu; + } + + mib[0] = CTL_KERN; + mib[1] = KERN_CP_TIME; + uint64_t cp_time[CPUSTATES]; + len = sizeof(cp_time); + if (sysctl(mib, 2, cp_time, &len, NULL, 0) < 0) { + fatal(i18n("Unable to get CPUSTATES.\n" + "The diagnostics are '%1'.\n" + "Please contact the maintainer at http://bugs.trinitydesktop.org/ who will try to sort this out.").arg(strerror(errno))); + } else { + sample.user = cp_time[CP_USER]; + sample.nice = cp_time[CP_NICE]; + sample.kernel = cp_time[CP_SYS]; + sample.iowait = cp_time[CP_INTR]; + sample.idle = cp_time[CP_IDLE]; + } + + mib[0] = CTL_VM; + mib[1] = VM_UVMEXP2; + + struct uvmexp_sysctl u; + len = sizeof(u); + if (sysctl(mib, 2, &u, &len, NULL, 0) < 0) { + fatal(i18n("Unable to get system wide vertual memory statistics.\n" + "The diagnostics are '%1'.\n" + "Please contact the maintainer at http://bugs.trinitydesktop.org/ who will try to sort this out.").arg(strerror(errno))); + } else { + pg_to_mb_shift = 20 - u.pageshift; + sample.mtotal = u.npages; + sample.free = u.free; + sample.buffers = u.filepages; + sample.cached = u.anonpages + u.execpages; + sample.mkernel = u.wired; + sample.stotal = u.swpages; + sample.sused = u.swpginuse; + sample.sfree = u.swpages - u.swpginuse; + } + + #else #warning This type of system is not supported sample.stotal = sample.sfree = 0; @@ -443,6 +503,8 @@ inline void KSample::makeMBytes(unsigned long &v) v /= 1024; // can it be simpler ;-) #elif defined (__osf__) || defined(USE_SOLARIS) v /= pagesPerMB; +#elif defined(__NetBSD__) + v >>= pg_to_mb_shift; #endif } |