$NetBSD: patch-ab,v 1.3 2006/06/12 16:30:33 joerg Exp $

--- src/libstatgrab/cpu_stats.c.orig	2006-06-12 16:09:20.000000000 +0000
+++ src/libstatgrab/cpu_stats.c
@@ -35,7 +35,10 @@
 #if defined(LINUX) || defined(CYGWIN)
 #include <stdio.h>
 #endif
-#if defined(FREEBSD) || defined(DFBSD)
+#if defined(DFBSD)
+#include <sys/param.h>
+#include <kinfo.h>
+#elif defined(FREEBSD)
 #include <sys/sysctl.h>
 #include <sys/dkstat.h>
 #endif
@@ -79,6 +82,8 @@ sg_cpu_stats *sg_get_cpu_stats(){
 #endif
 #ifdef NETBSD
 	u_int64_t cp_time[CPUSTATES];
+#elif defined(DFBSD)
+	struct kinfo_cputime cp_time;
 #else
 	long cp_time[CPUSTATES];
 #endif
@@ -152,7 +157,12 @@ sg_cpu_stats *sg_get_cpu_stats(){
 	cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle;
 #endif
 #ifdef ALLBSD
-#if defined(FREEBSD) || defined(DFBSD)
+#if defined(DFBSD)
+	if (kinfo_get_sched_cputime(&cp_time)) {
+		sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "kern.cp_time");
+		return NULL;
+  	}
+#elif defined(FREEBSD)
 	size = sizeof cp_time;
 	if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0){
 		sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "kern.cp_time");
@@ -178,12 +188,21 @@ sg_cpu_stats *sg_get_cpu_stats(){
 	}
 #endif
 
+#ifdef DFBSD
+	cpu_now.user=cp_time.cp_user;
+	cpu_now.nice=cp_time.cp_nice;
+	cpu_now.kernel=cp_time.cp_sys + cp_time.cp_intr;
+	cpu_now.idle=cp_time.cp_idle;
+	
+	cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle;
+#else
 	cpu_now.user=cp_time[CP_USER];
 	cpu_now.nice=cp_time[CP_NICE];
 	cpu_now.kernel=cp_time[CP_SYS];
 	cpu_now.idle=cp_time[CP_IDLE];
 	
 	cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle;
+#endif
 
 #endif
 
