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 |
f7c99b06 | 8 | static char sccsid[] = "@(#)mbuf.c 5.2 (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" }, | |
33 | { MT_ZOMBIE, "zombie process information" }, | |
34 | { MT_SOOPTS, "socket options" }, | |
1ab9ab56 | 35 | { MT_RIGHTS, "access rights" }, |
7c69b0a9 | 36 | { MT_IFADDR, "interface addresses" }, |
02c6746b SL |
37 | { 0, 0 } |
38 | }; | |
39 | ||
7c69b0a9 MK |
40 | int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); |
41 | bool seen[256]; /* "have we seen this type yet?" */ | |
42 | ||
bad4305f SL |
43 | /* |
44 | * Print mbuf statistics. | |
45 | */ | |
46 | mbpr(mbaddr) | |
47 | off_t mbaddr; | |
48 | { | |
02c6746b | 49 | register int totmem, totfree, totmbufs; |
7c69b0a9 | 50 | register int i; |
02c6746b | 51 | register struct mbtypes *mp; |
24bf5f10 | 52 | |
7c69b0a9 MK |
53 | if (nmbtypes != 256) { |
54 | fprintf(stderr, "unexpected change to mbstat; check source\n"); | |
55 | return; | |
56 | } | |
bad4305f SL |
57 | if (mbaddr == 0) { |
58 | printf("mbstat: symbol not in namelist\n"); | |
59 | return; | |
60 | } | |
bad4305f | 61 | klseek(kmem, mbaddr, 0); |
f7c99b06 | 62 | if (read(kmem, (char *)&mbstat, sizeof (mbstat)) != sizeof (mbstat)) { |
24bf5f10 SL |
63 | printf("mbstat: bad read\n"); |
64 | return; | |
65 | } | |
02c6746b | 66 | printf("%d/%d mbufs in use:\n", |
1ab9ab56 | 67 | mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs); |
02c6746b SL |
68 | totmbufs = 0; |
69 | for (mp = mbtypes; mp->mt_name; mp++) | |
70 | if (mbstat.m_mtypes[mp->mt_type]) { | |
7c69b0a9 | 71 | seen[mp->mt_type] = YES; |
02c6746b | 72 | printf("\t%d mbufs allocated to %s\n", |
7c69b0a9 | 73 | mbstat.m_mtypes[mp->mt_type], mp->mt_name); |
02c6746b SL |
74 | totmbufs += mbstat.m_mtypes[mp->mt_type]; |
75 | } | |
7c69b0a9 MK |
76 | seen[MT_FREE] = YES; |
77 | for (i = 0; i < nmbtypes; i++) | |
78 | if (!seen[i] && mbstat.m_mtypes[i]) { | |
79 | printf("\t%d mbufs allocated to <mbuf type %d>\n", | |
80 | mbstat.m_mtypes[i], i); | |
81 | totmbufs += mbstat.m_mtypes[i]; | |
82 | } | |
1ab9ab56 | 83 | if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) |
02c6746b | 84 | printf("*** %d mbufs missing ***\n", |
1ab9ab56 | 85 | (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs); |
84f2241b | 86 | printf("%d/%d mapped pages in use\n", |
24bf5f10 | 87 | mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); |
c7d38858 MK |
88 | totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES; |
89 | totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES; | |
02c6746b | 90 | printf("%d Kbytes allocated to network (%d%% in use)\n", |
c1567c4d | 91 | totmem / 1024, (totmem - totfree) * 100 / totmem); |
02c6746b | 92 | printf("%d requests for memory denied\n", mbstat.m_drops); |
bad4305f | 93 | } |