diff options
-rw-r--r-- | usr.bin/netstat/mbuf.c | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index 91e1be3d2c6..ccd1856d153 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.c,v 1.26 2007/12/19 01:47:00 deraadt Exp $ */ +/* $OpenBSD: mbuf.c,v 1.27 2008/12/04 05:59:57 deraadt Exp $ */ /* $NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $ */ /* @@ -36,6 +36,7 @@ #include <sys/mbuf.h> #include <sys/pool.h> #include <sys/sysctl.h> +#include <net/if.h> #include <errno.h> #include <kvm.h> @@ -49,7 +50,12 @@ typedef int bool; struct mbstat mbstat; -struct pool mbpool, mclpool; +struct pool mbpool, mclpools[MCLPOOLS]; +int mclp; +char *mclnames[] = { + "mcl2k", "mcl4k", "mcl8k", "mcl9k", "mcl12k", "mcl16k", "mcl64k" +}; +char **mclnamep = mclnames; extern kvm_t *kvmd; @@ -77,7 +83,7 @@ void mbpr(void) { int totmem, totused, totmbufs, totpct; - int i, mib[4], npools, flag = 0; + int i, mib[4], npools; struct pool pool; struct mbtypes *mp; size_t size; @@ -135,19 +141,15 @@ mbpr(void) return; } - if (!strncmp(name, "mbpl", strlen("mbpl"))) { + if (!strncmp(name, "mbpl", strlen("mbpl"))) bcopy(&pool, &mbpool, sizeof(struct pool)); - flag++; - } else { - if (!strncmp(name, "mclpl", strlen("mclpl"))) { - bcopy(&pool, &mclpool, - sizeof(struct pool)); - flag++; - } + else if (mclp < nitems(mclpools) && + !strncmp(name, *mclnamep, strlen(*mclnamep))) { + printf("%s\n", name); + bcopy(&pool, &mclpools[mclp++], + sizeof(struct pool)); + mclnamep++; } - - if (flag == 2) - break; } totmbufs = 0; @@ -169,14 +171,18 @@ mbpr(void) mbstat.m_mtypes[i], plural((int)mbstat.m_mtypes[i]), i); } - printf("%lu/%lu/%lu mbuf clusters in use (current/peak/max)\n", - (u_long)(mclpool.pr_nout), - (u_long)(mclpool.pr_hiwat * mclpool.pr_itemsperpage), - (u_long)(mclpool.pr_maxpages * mclpool.pr_itemsperpage)); - totmem = (mbpool.pr_npages * page_size) + - (mclpool.pr_npages * page_size); - totused = mbpool.pr_nout * mbpool.pr_size + - mclpool.pr_nout * mclpool.pr_size; + totmem = (mbpool.pr_npages * page_size); + totused = mbpool.pr_nout * mbpool.pr_size; + for (i = 0; i < mclp; i++) { + printf("%lu/%lu/%lu mbuf %d byte clusters in use (current/peak/max)\n", + (u_long)(mclpools[i].pr_nout), + (u_long)(mclpools[i].pr_hiwat * mclpools[i].pr_itemsperpage), + (u_long)(mclpools[i].pr_maxpages * mclpools[i].pr_itemsperpage), + mclpools[i].pr_size); + totmem += (mclpools[i].pr_npages * page_size); + totused += mclpools[i].pr_nout * mclpools[i].pr_size; + } + totpct = (totmem == 0)? 0 : ((totused * 100)/totmem); printf("%u Kbytes allocated to network (%d%% in use)\n", totmem / 1024, totpct); |