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 |
b36fc510 KB |
19 | static char sccsid[] = "@(#)mbuf.c 5.6 (Berkeley) %G%"; |
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" }, | |
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" }, | |
02c6746b | 41 | { MT_ATABLE, "address resolution tables" }, |
02c6746b SL |
42 | { MT_FTABLE, "fragment reassembly queue headers" }, |
43 | { MT_SONAME, "socket names and addresses" }, | |
02c6746b | 44 | { MT_SOOPTS, "socket options" }, |
1ab9ab56 | 45 | { MT_RIGHTS, "access rights" }, |
7c69b0a9 | 46 | { MT_IFADDR, "interface addresses" }, |
02c6746b SL |
47 | { 0, 0 } |
48 | }; | |
49 | ||
7c69b0a9 MK |
50 | int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); |
51 | bool seen[256]; /* "have we seen this type yet?" */ | |
52 | ||
bad4305f SL |
53 | /* |
54 | * Print mbuf statistics. | |
55 | */ | |
56 | mbpr(mbaddr) | |
57 | off_t mbaddr; | |
58 | { | |
02c6746b | 59 | register int totmem, totfree, totmbufs; |
7c69b0a9 | 60 | register int i; |
02c6746b | 61 | register struct mbtypes *mp; |
24bf5f10 | 62 | |
7c69b0a9 MK |
63 | if (nmbtypes != 256) { |
64 | fprintf(stderr, "unexpected change to mbstat; check source\n"); | |
65 | return; | |
66 | } | |
bad4305f SL |
67 | if (mbaddr == 0) { |
68 | printf("mbstat: symbol not in namelist\n"); | |
69 | return; | |
70 | } | |
bad4305f | 71 | klseek(kmem, mbaddr, 0); |
f7c99b06 | 72 | if (read(kmem, (char *)&mbstat, sizeof (mbstat)) != sizeof (mbstat)) { |
24bf5f10 SL |
73 | printf("mbstat: bad read\n"); |
74 | return; | |
75 | } | |
f9ae784a | 76 | printf("%u/%u mbufs in use:\n", |
1ab9ab56 | 77 | mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs); |
02c6746b SL |
78 | totmbufs = 0; |
79 | for (mp = mbtypes; mp->mt_name; mp++) | |
80 | if (mbstat.m_mtypes[mp->mt_type]) { | |
7c69b0a9 | 81 | seen[mp->mt_type] = YES; |
f9ae784a | 82 | printf("\t%u mbufs allocated to %s\n", |
7c69b0a9 | 83 | mbstat.m_mtypes[mp->mt_type], mp->mt_name); |
02c6746b SL |
84 | totmbufs += mbstat.m_mtypes[mp->mt_type]; |
85 | } | |
7c69b0a9 MK |
86 | seen[MT_FREE] = YES; |
87 | for (i = 0; i < nmbtypes; i++) | |
88 | if (!seen[i] && mbstat.m_mtypes[i]) { | |
f9ae784a | 89 | printf("\t%u mbufs allocated to <mbuf type %d>\n", |
7c69b0a9 MK |
90 | mbstat.m_mtypes[i], i); |
91 | totmbufs += mbstat.m_mtypes[i]; | |
92 | } | |
1ab9ab56 | 93 | if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) |
f9ae784a | 94 | printf("*** %u mbufs missing ***\n", |
1ab9ab56 | 95 | (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs); |
f9ae784a | 96 | printf("%u/%u mapped pages in use\n", |
24bf5f10 | 97 | mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); |
3a23a111 | 98 | totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES; |
c7d38858 | 99 | totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES; |
f9ae784a | 100 | printf("%u Kbytes allocated to network (%d%% in use)\n", |
c1567c4d | 101 | totmem / 1024, (totmem - totfree) * 100 / totmem); |
f9ae784a MK |
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); | |
bad4305f | 105 | } |