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