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