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