summaryrefslogtreecommitdiff
path: root/sysutils/xfce4-systemload-plugin/patches/patch-ab
blob: 5f5da767e921ac7f70976a6b97fd2b3a02fb98e3 (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
$NetBSD: patch-ab,v 1.2 2007/04/12 09:55:17 martti Exp $

--- panel-plugin/cpu.c.orig	2007-01-17 18:01:09.000000000 +0000
+++ panel-plugin/cpu.c	2007-01-23 21:46:41.000000000 +0000
@@ -78,6 +78,31 @@
     return cpu_used;
 }
 
+#elif defined(__DragonFly__)
+#include <kinfo.h>
+
+static struct kinfo_cputime old_cp_time;
+
+gulong read_cpuload()
+{
+    gulong used, total;
+    struct kinfo_cputime cp_time;
+
+    if (kinfo_get_sched_cputime(&cp_time) < 0) {
+	g_warning("kinfo_get_sched_cputime failed");
+	return 0;
+    }
+    used = cp_time.cp_user + cp_time.cp_nice + cp_time.cp_sys;
+    used -= old_cp_time.cp_user + old_cp_time.cp_nice + old_cp_time.cp_sys;
+    total = used + cp_time.cp_idle - old_cp_time.cp_idle;
+    old_cp_time = cp_time;
+
+    if (total)
+        return 100 * (used + used / 2) / total;
+    else
+	return 0;
+}
+
 #elif defined(__FreeBSD__)
 
 #include <osreldate.h>