From b50af4cbafd5ac24aa48d8cd0dcb38b940ff658c Mon Sep 17 00:00:00 2001 From: OBATA Akio Date: Tue, 11 Jan 2022 18:51:50 +0900 Subject: kicker-applets: Add NetBSD support for KTimemon Signed-off-by: OBATA Akio --- kicker-applets/ktimemon/sample.cpp | 62 ++++++++++++++++++++++++++++++++++++++ kicker-applets/ktimemon/sample.h | 7 +++++ 2 files changed, 69 insertions(+) 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 #endif +#ifdef __NetBSD__ +#include +#include +#include +#endif + #include #include #include @@ -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 } diff --git a/kicker-applets/ktimemon/sample.h b/kicker-applets/ktimemon/sample.h index 6ebe77d..e01965f 100644 --- a/kicker-applets/ktimemon/sample.h +++ b/kicker-applets/ktimemon/sample.h @@ -47,10 +47,12 @@ public: void fill(unsigned scale); // fill sample with some fake values }; +#ifdef __linux__ struct MemStats { const char *name; unsigned long *stat; }; +#endif KSample(KTimeMon *timemon, bool autoScale, unsigned pageScale, unsigned swapScale, unsigned ctxScale); @@ -82,11 +84,16 @@ private: #endif #if defined(USE_SOLARIS) || defined(__osf__) unsigned long pagesPerMB; +#endif +#ifdef __NetBSD__ + int pg_to_mb_shift; #endif Sample sample, oldSample; unsigned pageScale, swapScale, cxScale; bool autoscale; +#ifdef __linux__ struct MemStats memstats[7]; +#endif }; #endif // SAMPLE_H -- cgit v1.2.1