diff options
author | OBATA Akio <obache@wizdas.com> | 2022-01-11 18:51:50 +0900 |
---|---|---|
committer | OBATA Akio <obache@wizdas.com> | 2022-01-11 18:51:50 +0900 |
commit | b50af4cbafd5ac24aa48d8cd0dcb38b940ff658c (patch) | |
tree | cfae549be7bcb3d81576a3092165f49de0918e4b | |
parent | ecd978360d79ba71df598f372be65cc1c0e34d80 (diff) | |
download | tdeaddons-b50af4cbafd5ac24aa48d8cd0dcb38b940ff658c.tar.gz tdeaddons-b50af4cbafd5ac24aa48d8cd0dcb38b940ff658c.zip |
kicker-applets: Add NetBSD support for KTimemonfeat/ktimemon-netbsd
Signed-off-by: OBATA Akio <obache@wizdas.com>
-rw-r--r-- | kicker-applets/ktimemon/sample.cpp | 62 | ||||
-rw-r--r-- | kicker-applets/ktimemon/sample.h | 7 |
2 files changed, 69 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 } 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); @@ -83,10 +85,15 @@ private: #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 |