1 /* 2 * Copyright (c) 1983, 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)mbuf.c 5.12 (Berkeley) 07/07/92"; 10 #endif /* not lint */ 11 12 #include <sys/param.h> 13 #include <sys/protosw.h> 14 #include <sys/socket.h> 15 #include <sys/mbuf.h> 16 17 #include <stdio.h> 18 #include "netstat.h" 19 20 #define YES 1 21 typedef int bool; 22 23 struct mbstat mbstat; 24 25 static struct mbtypes { 26 int mt_type; 27 char *mt_name; 28 } mbtypes[] = { 29 { MT_DATA, "data" }, 30 { MT_OOBDATA, "oob data" }, 31 { MT_CONTROL, "ancillary data" }, 32 { MT_HEADER, "packet headers" }, 33 { MT_SOCKET, "socket structures" }, /* XXX */ 34 { MT_PCB, "protocol control blocks" }, /* XXX */ 35 { MT_RTABLE, "routing table entries" }, /* XXX */ 36 { MT_HTABLE, "IMP host table entries" }, /* XXX */ 37 { MT_ATABLE, "address resolution tables" }, 38 { MT_FTABLE, "fragment reassembly queue headers" }, /* XXX */ 39 { MT_SONAME, "socket names and addresses" }, 40 { MT_SOOPTS, "socket options" }, 41 { MT_RIGHTS, "access rights" }, 42 { MT_IFADDR, "interface addresses" }, /* XXX */ 43 { 0, 0 } 44 }; 45 46 int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); 47 bool seen[256]; /* "have we seen this type yet?" */ 48 49 /* 50 * Print mbuf statistics. 51 */ 52 void 53 mbpr(mbaddr) 54 u_long mbaddr; 55 { 56 register int totmem, totfree, totmbufs; 57 register int i; 58 register struct mbtypes *mp; 59 60 if (nmbtypes != 256) { 61 fprintf(stderr, 62 "%s: unexpected change to mbstat; check source\n", prog); 63 return; 64 } 65 if (mbaddr == 0) { 66 fprintf(stderr, "%s: mbstat: symbol not in namelist\n", prog); 67 return; 68 } 69 if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat))) 70 return; 71 totmbufs = 0; 72 for (mp = mbtypes; mp->mt_name; mp++) 73 totmbufs += mbstat.m_mtypes[mp->mt_type]; 74 printf("%u mbufs in use:\n", totmbufs); 75 for (mp = mbtypes; mp->mt_name; mp++) 76 if (mbstat.m_mtypes[mp->mt_type]) { 77 seen[mp->mt_type] = YES; 78 printf("\t%u mbufs allocated to %s\n", 79 mbstat.m_mtypes[mp->mt_type], mp->mt_name); 80 } 81 seen[MT_FREE] = YES; 82 for (i = 0; i < nmbtypes; i++) 83 if (!seen[i] && mbstat.m_mtypes[i]) { 84 printf("\t%u mbufs allocated to <mbuf type %d>\n", 85 mbstat.m_mtypes[i], i); 86 } 87 printf("%u/%u mapped pages in use\n", 88 mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); 89 totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES; 90 totfree = mbstat.m_clfree * MCLBYTES; 91 printf("%u Kbytes allocated to network (%d%% in use)\n", 92 totmem / 1024, (totmem - totfree) * 100 / totmem); 93 printf("%u requests for memory denied\n", mbstat.m_drops); 94 printf("%u requests for memory delayed\n", mbstat.m_wait); 95 printf("%u calls to protocol drain routines\n", mbstat.m_drain); 96 } 97