From a01db679885244fa10a3d05ee0193477edf35be4 Mon Sep 17 00:00:00 2001 From: Bosko Milekic Date: Sun, 15 Oct 2000 06:29:22 +0000 Subject: [PATCH] Change the "in use" percentage metric to actually display a real "in use" percentage. In other words, show how much of mb_map is in use. --- usr.bin/netstat/mbuf.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index 32c0751bc246..f07da0094be2 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -98,11 +98,11 @@ static struct mbtypenames { void mbpr() { - register int totmem, totfree, totmbufs; + u_long totmem, totpossible, totmbufs; register int i; struct mbtypenames *mp; - int name[3], nmbclusters, nmbufs, nmbtypes; - size_t nmbclen, nmbuflen, mbstatlen, mbtypeslen; + int name[3], nmbclusters, nmbufs, nmbcnt, nmbtypes; + size_t nmbclen, nmbuflen, nmbcntlen, mbstatlen, mbtypeslen; u_long *mbtypes; bool *seen; /* "have we seen this type yet?" */ @@ -151,6 +151,12 @@ mbpr() goto err; } + nmbcntlen = sizeof(int); + if (sysctlbyname("kern.ipc.nmbcnt", &nmbcnt, &nmbcntlen, 0, 0) < 0) { + warn("sysctl: retrieving nmbcnt"); + goto err; + } + #undef MSIZE #define MSIZE (mbstat.m_msize) #undef MCLBYTES @@ -159,7 +165,7 @@ mbpr() totmbufs = 0; for (mp = mbtypenames; mp->mt_name; mp++) totmbufs += mbtypes[mp->mt_type]; - printf("%u/%lu/%u mbufs in use (current/peak/max):\n", totmbufs, + printf("%lu/%lu/%u mbufs in use (current/peak/max):\n", totmbufs, mbstat.m_mbufs, nmbufs); for (mp = mbtypenames; mp->mt_name; mp++) if (mbtypes[mp->mt_type]) { @@ -180,11 +186,10 @@ mbpr() mbstat.m_refcnt - mbstat.m_refree, mbstat.m_refcnt); totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * MCLBYTES + mbstat.m_refcnt * sizeof(union mext_refcnt); - totfree = mbstat.m_clfree * MCLBYTES + - MSIZE * (mbstat.m_mbufs - totmbufs) + mbstat.m_refree * - sizeof(union mext_refcnt); - printf("%u Kbytes allocated to network (%d%% in use)\n", - totmem / 1024, (unsigned) (totmem - totfree) * 100 / totmem); + totpossible = nmbclusters * MCLBYTES + nmbufs * MSIZE + + nmbcnt * sizeof(union mext_refcnt); + printf("%lu Kbytes allocated to network (%lu%% of mb_map in use)\n", + totmem / 1024, (totmem * 100) / totpossible); printf("%lu requests for memory denied\n", mbstat.m_drops); printf("%lu requests for memory delayed\n", mbstat.m_wait); printf("%lu calls to protocol drain routines\n", mbstat.m_drain);