3 --- sysdeps/bsd/proctime.c.orig 2007-04-27 00:27:34.000000000 +0200
4 +++ sysdeps/bsd/proctime.c
5 @@ -40,11 +40,25 @@ static const unsigned long _glibtop_sysd
7 #define tv2sec(tv) (((guint64) tv.tv_sec * 1000000) + (guint64) tv.tv_usec)
9 +#if defined(__NetBSD__)
10 +static unsigned int clockrate;
11 +static const int mib [] = { CTL_KERN, KERN_CLOCKRATE };
17 _glibtop_init_proc_time_p (glibtop *server)
19 +#if defined(__NetBSD__)
20 + struct clockinfo ci;
22 + length = sizeof (ci);
23 + if (sysctl (mib, 2, &ci, &length, NULL, 0) == 0)
26 + clockrate = 1; /* XXX avoid div by 0 later */
28 server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
29 _glibtop_sysdeps_proc_time_user;
31 @@ -56,7 +70,7 @@ _glibtop_init_proc_time_p (glibtop *serv
32 * system, and interrupt time usage.
35 -#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__))
36 +#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__))
40 @@ -114,13 +128,17 @@ void
41 glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
44 +#if defined (__NetBSD__)
45 + struct kinfo_proc2 *pinfo;
47 struct kinfo_proc *pinfo;
48 -#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
49 +#if (defined(OpenBSD) && (OpenBSD >= 199912))
50 register struct rusage *rup;
52 struct user *u_addr = (struct user *)USRSTACK;
58 glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
59 @@ -136,7 +154,12 @@ glibtop_get_proc_time_p (glibtop *server
62 /* Get the process information */
63 +#if defined (__NetBSD__)
64 + pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
65 + sizeof (*pinfo), &count);
67 pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
69 if ((pinfo == NULL) || (count != 1)) {
70 glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
72 @@ -146,14 +169,31 @@ glibtop_get_proc_time_p (glibtop *server
73 buf->rtime = pinfo [0].ki_runtime;
74 #elif (defined __FreeBSD__) && (__FreeBSD_version <= 500013)
75 buf->rtime = pinfo [0].kp_proc.p_runtime;
76 +#elif defined (__NetBSD__)
77 + buf->rtime = pinfo[0].p_rtime_sec * clockrate
78 + + pinfo[0].p_rtime_usec * clockrate / 1000000;
79 + buf->frequency = clockrate;
81 buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
82 + buf->frequency = 1000000;
85 - buf->frequency = 1000000;
86 buf->flags = _glibtop_sysdeps_proc_time;
88 -#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
89 +#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
91 + buf->utime = pinfo[0].p_uutime_sec * 1000000
92 + + pinfo[0].p_uutime_usec;
93 + buf->stime = pinfo[0].p_ustime_sec * 1000000
94 + + pinfo[0].p_ustime_usec;
95 + buf->cutime = pinfo[0].p_uctime_sec * 1000000
96 + + pinfo[0].p_uctime_usec; /* XXX is u+s */
97 + buf->cstime = 0; /* XXX */
98 + buf->start_time = pinfo[0].p_ustart_sec;
100 + buf->flags |= _glibtop_sysdeps_proc_time_user;
102 +#elif (defined(OpenBSD) && (OpenBSD >= 199912))
103 glibtop_suid_enter (server);
105 if (kvm_read (server->machine.kd,