$NetBSD: patch-ae,v 1.1 2006/02/28 23:48:11 joerg Exp $ --- sysdeps/freebsd/cpu.c.orig 2005-07-08 19:49:56.000000000 +0000 +++ sysdeps/freebsd/cpu.c @@ -27,16 +27,73 @@ #include -#ifdef __NetBSD__ -#include -#endif - static const unsigned long _glibtop_sysdeps_cpu = (1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) + (1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) + (1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY) + (1L << GLIBTOP_CPU_IOWAIT); +#if defined(__DragonFly__) +#include + +/* Init function. */ + +void +glibtop_init_cpu_p (glibtop *server) +{ + server->sysdeps.cpu = _glibtop_sysdeps_cpu; +} + +/* Provides information about cpu usage. */ +void +glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf) +{ + struct kinfo_cputime cp_time; + int hz; + + glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_CPU), 0); + + memset (buf, 0, sizeof (glibtop_cpu)); + + /* If this fails, the module was not setuped. */ + if (server->sysdeps.cpu == 0) + return; + + if (kinfo_get_sched_cputime(&cp_time)) { + glibtop_warn_io_r (server, "kinfo_get_sched_cputime"); + return; + } + if (kinfo_get_sched_hz(&hz)) { + glibtop_warn_io_r (server, "kinfo_get_sched hz"); + return; + } + /* set user time */ + buf->user = cp_time.cp_user; + /* set nice time */ + buf->nice = cp_time.cp_nice; + /* set sys time */ + buf->sys = cp_time.cp_sys; + /* set idle time */ + buf->idle = cp_time.cp_idle; + /* set iowait (really just interrupt) time */ + buf->iowait = cp_time.cp_idle; + + /* set frequency */ + buf->frequency = hz; + /* set total */ + buf->total = cp_time.cp_user + cp_time.cp_sys + cp_time.cp_nice + + cp_time.cp_idle; + + /* Set the flags last. */ + buf->flags = _glibtop_sysdeps_cpu; +} + +#else + +#ifdef __NetBSD__ +#include +#endif + #ifndef KERN_CP_TIME /* nlist structure for kernel access */ static struct nlist nlst [] = { @@ -141,3 +198,4 @@ glibtop_get_cpu_p (glibtop *server, glib /* Set the flags last. */ buf->flags = _glibtop_sysdeps_cpu; } +#endif