| 1 | /* |
| 2 | * Copyright (c) 1983, 1988 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms are permitted |
| 6 | * provided that the above copyright notice and this paragraph are |
| 7 | * duplicated in all such forms and that any documentation, |
| 8 | * advertising materials, and other materials related to such |
| 9 | * distribution and use acknowledge that the software was developed |
| 10 | * by the University of California, Berkeley. The name of the |
| 11 | * University may not be used to endorse or promote products derived |
| 12 | * from this software without specific prior written permission. |
| 13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 16 | */ |
| 17 | |
| 18 | #ifndef lint |
| 19 | static char sccsid[] = "@(#)mbuf.c 5.6 (Berkeley) %G%"; |
| 20 | #endif /* not lint */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <sys/param.h> |
| 24 | #include <sys/mbuf.h> |
| 25 | #define YES 1 |
| 26 | typedef int bool; |
| 27 | |
| 28 | struct mbstat mbstat; |
| 29 | extern int kmem; |
| 30 | |
| 31 | static struct mbtypes { |
| 32 | int mt_type; |
| 33 | char *mt_name; |
| 34 | } mbtypes[] = { |
| 35 | { MT_DATA, "data" }, |
| 36 | { MT_HEADER, "packet headers" }, |
| 37 | { MT_SOCKET, "socket structures" }, |
| 38 | { MT_PCB, "protocol control blocks" }, |
| 39 | { MT_RTABLE, "routing table entries" }, |
| 40 | { MT_HTABLE, "IMP host table entries" }, |
| 41 | { MT_ATABLE, "address resolution tables" }, |
| 42 | { MT_FTABLE, "fragment reassembly queue headers" }, |
| 43 | { MT_SONAME, "socket names and addresses" }, |
| 44 | { MT_SOOPTS, "socket options" }, |
| 45 | { MT_RIGHTS, "access rights" }, |
| 46 | { MT_IFADDR, "interface addresses" }, |
| 47 | { 0, 0 } |
| 48 | }; |
| 49 | |
| 50 | int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); |
| 51 | bool seen[256]; /* "have we seen this type yet?" */ |
| 52 | |
| 53 | /* |
| 54 | * Print mbuf statistics. |
| 55 | */ |
| 56 | mbpr(mbaddr) |
| 57 | off_t mbaddr; |
| 58 | { |
| 59 | register int totmem, totfree, totmbufs; |
| 60 | register int i; |
| 61 | register struct mbtypes *mp; |
| 62 | |
| 63 | if (nmbtypes != 256) { |
| 64 | fprintf(stderr, "unexpected change to mbstat; check source\n"); |
| 65 | return; |
| 66 | } |
| 67 | if (mbaddr == 0) { |
| 68 | printf("mbstat: symbol not in namelist\n"); |
| 69 | return; |
| 70 | } |
| 71 | klseek(kmem, mbaddr, 0); |
| 72 | if (read(kmem, (char *)&mbstat, sizeof (mbstat)) != sizeof (mbstat)) { |
| 73 | printf("mbstat: bad read\n"); |
| 74 | return; |
| 75 | } |
| 76 | printf("%u/%u mbufs in use:\n", |
| 77 | mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs); |
| 78 | totmbufs = 0; |
| 79 | for (mp = mbtypes; mp->mt_name; mp++) |
| 80 | if (mbstat.m_mtypes[mp->mt_type]) { |
| 81 | seen[mp->mt_type] = YES; |
| 82 | printf("\t%u mbufs allocated to %s\n", |
| 83 | mbstat.m_mtypes[mp->mt_type], mp->mt_name); |
| 84 | totmbufs += mbstat.m_mtypes[mp->mt_type]; |
| 85 | } |
| 86 | seen[MT_FREE] = YES; |
| 87 | for (i = 0; i < nmbtypes; i++) |
| 88 | if (!seen[i] && mbstat.m_mtypes[i]) { |
| 89 | printf("\t%u mbufs allocated to <mbuf type %d>\n", |
| 90 | mbstat.m_mtypes[i], i); |
| 91 | totmbufs += mbstat.m_mtypes[i]; |
| 92 | } |
| 93 | if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) |
| 94 | printf("*** %u mbufs missing ***\n", |
| 95 | (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs); |
| 96 | printf("%u/%u mapped pages in use\n", |
| 97 | mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); |
| 98 | totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES; |
| 99 | totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES; |
| 100 | printf("%u Kbytes allocated to network (%d%% in use)\n", |
| 101 | totmem / 1024, (totmem - totfree) * 100 / totmem); |
| 102 | printf("%u requests for memory denied\n", mbstat.m_drops); |
| 103 | printf("%u requests for memory delayed\n", mbstat.m_wait); |
| 104 | printf("%u calls to protocol drain routines\n", mbstat.m_drain); |
| 105 | } |