summaryrefslogtreecommitdiff
path: root/usr.bin/vmstat/vmstat.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2003-01-13 06:06:14 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2003-01-13 06:06:14 +0000
commit59e17b4b66b5d87be0a76da0422fe43257ca2975 (patch)
tree59743d167bc16b4420341b0d7b783f38bd396150 /usr.bin/vmstat/vmstat.c
parent21d25482d2965ab0b066f34ab793a1a228e116c3 (diff)
Half-done conversion of vmstat -i to sysctls.
The evcnt stuff is left just like in the kvm version.
Diffstat (limited to 'usr.bin/vmstat/vmstat.c')
-rw-r--r--usr.bin/vmstat/vmstat.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index d341878c388..704cd136ba9 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -1,5 +1,5 @@
/* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */
-/* $OpenBSD: vmstat.c,v 1.73 2002/12/16 01:57:04 tdeval Exp $ */
+/* $OpenBSD: vmstat.c,v 1.74 2003/01/13 06:06:13 art Exp $ */
/*
* Copyright (c) 1980, 1986, 1991, 1993
@@ -830,9 +830,96 @@ dointr(void)
printf("Total %10lu %8lu\n", inttotal, inttotal / uptime);
}
#else
+static void dointr_sysctl(void);
+static void dointr_kvm(void);
+
void
dointr(void)
{
+ if (nlistf == NULL && memf == NULL)
+ dointr_sysctl();
+ else
+ dointr_kvm();
+}
+
+static void
+dointr_sysctl(void)
+{
+ struct evcntlist allevents;
+ struct evcnt evcnt, *evptr;
+ struct device dev;
+
+ time_t uptime;
+ long inttotal;
+ int nintr;
+ char intrname[128];
+ int mib[4];
+ size_t siz;
+ int i;
+
+ uptime = getuptime();
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_INTRCNT;
+ mib[2] = KERN_INTRCNT_NUM;
+ siz = sizeof(nintr);
+ if (sysctl(mib, 3, &nintr, &siz, NULL, 0) < 0) {
+ warnx("could not read kern.intrcnt.nintrcnt");
+ return;
+ }
+
+ inttotal = 0;
+ for (i = 0; i < nintr; i++) {
+ int cnt;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_INTRCNT;
+ mib[2] = KERN_INTRCNT_NAME;
+ mib[3] = i;
+ siz = sizeof(intrname);
+ if (sysctl(mib, 4, intrname, &siz, NULL, 0) < 0) {
+ warnx("could not read kern.intrcnt.name.%d", i);
+ return ;
+ }
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_INTRCNT;
+ mib[2] = KERN_INTRCNT_CNT;
+ mib[3] = i;
+ siz = sizeof(cnt);
+ if (sysctl(mib, 4, &cnt, &siz, NULL, 0) < 0) {
+ warnx("could not read kern.intrcnt.name.%d", i);
+ return ;
+ }
+ if (cnt)
+ (void)printf("%-14s %12ld %8ld\n", intrname,
+ cnt, cnt / uptime);
+ inttotal += cnt;
+ }
+
+ kread(X_ALLEVENTS, &allevents, sizeof allevents);
+ evptr = allevents.tqh_first;
+ while (evptr) {
+ if (kvm_read(kd, (long)evptr, (void *)&evcnt,
+ sizeof evcnt) != sizeof evcnt)
+ errx(1, "event chain trashed: %s", kvm_geterr(kd));
+ if (strcmp(evcnt.ev_name, "intr") == 0) {
+ if (kvm_read(kd, (long)evcnt.ev_dev, (void *)&dev,
+ sizeof dev) != sizeof dev)
+ errx(1, "event chain trashed: %s", kvm_geterr(kd));
+ if (evcnt.ev_count)
+ (void)printf("%-14s %12d %8ld\n", dev.dv_xname,
+ evcnt.ev_count, (long)(evcnt.ev_count / uptime));
+ inttotal += evcnt.ev_count++;
+ }
+ evptr = evcnt.ev_list.tqe_next;
+ }
+ (void)printf("Total %12ld %8ld\n", inttotal, inttotal / uptime);
+}
+
+static void
+dointr_kvm(void)
+{
long *intrcnt, inttotal;
time_t uptime;
int nintr, inamlen;