73 lines
1.7 KiB
Text
73 lines
1.7 KiB
Text
$NetBSD: patch-ac,v 1.8 2006/09/19 22:25:48 joerg Exp $
|
|
|
|
--- src/stats-bsd.c.orig 2001-06-16 19:12:53.000000000 +0000
|
|
+++ src/stats-bsd.c
|
|
@@ -10,6 +10,7 @@
|
|
#include "stats.h"
|
|
|
|
/* System includes */
|
|
+#include <sys/param.h>
|
|
#include <kvm.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
@@ -17,10 +18,16 @@
|
|
#include <limits.h>
|
|
#include <syslog.h>
|
|
#include <sys/time.h>
|
|
-#include <sys/param.h>
|
|
+#if defined(__DragonFly__)
|
|
+#include <kinfo.h>
|
|
+#else
|
|
#include <sys/dkstat.h>
|
|
+#endif
|
|
#include <sys/sysctl.h>
|
|
#include <sys/utsname.h>
|
|
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 104000000
|
|
+#include <sys/sched.h>
|
|
+#endif
|
|
|
|
/**
|
|
* @desc Get statistics
|
|
@@ -75,6 +82,35 @@ void getstats(unsigned long *puptime, do
|
|
}
|
|
|
|
if(cfg_sendidle) {
|
|
+#if defined(__DragonFly__)
|
|
+ static int first_time = 1;
|
|
+ static struct kinfo_cputime scp;
|
|
+ struct kinfo_cputime cp;
|
|
+
|
|
+ if (first_time) {
|
|
+ first_time = 0;
|
|
+ if (kinfo_get_sched_cputime(&scp))
|
|
+ warn("kinfo_get_sched_cputime");
|
|
+ else
|
|
+ sleep(1); /* to avoid the initial 0 idle value */
|
|
+ }
|
|
+ if (kinfo_get_sched_cputime(&cp))
|
|
+ warn("kinfo_get_sched_cputime");
|
|
+ else {
|
|
+ double time = 0.0;
|
|
+ time += cp.cp_user - scp.cp_user;
|
|
+ time += cp.cp_nice - scp.cp_nice;
|
|
+ time += cp.cp_sys - scp.cp_sys;
|
|
+ time += cp.cp_intr - scp.cp_intr;
|
|
+ time += cp.cp_idle - scp.cp_idle;
|
|
+
|
|
+ if (time == 0.0)
|
|
+ time = 1.0;
|
|
+
|
|
+ *pidle = (cp.cp_idle - scp.cp_idle) * 100.0 / time;
|
|
+ scp = cp;
|
|
+ }
|
|
+#else
|
|
static kvm_t *kp;
|
|
static int initialized = 0;
|
|
static struct nlist namelist [] = {
|
|
@@ -131,5 +167,6 @@ void getstats(unsigned long *puptime, do
|
|
} else {
|
|
cfg_sendidle = 0;
|
|
}
|
|
+#endif
|
|
}
|
|
}
|