summaryrefslogtreecommitdiff
path: root/net/upclient/patches/patch-ac
blob: a2de2c3e4cc059bc9f4394a4c1af38b2a1ec2db0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$NetBSD: patch-ac,v 1.7 2006/01/25 17:00:25 joerg Exp $

--- src/stats-bsd.c.orig	2001-06-16 19:12:53.000000000 +0000
+++ src/stats-bsd.c
@@ -18,9 +18,16 @@
 #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
   }
 }