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