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