new IMP stuff
[unix-history] / usr / src / usr.bin / netstat / mbuf.c
... / ...
CommitLineData
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
7#ifndef lint
8static char sccsid[] = "@(#)mbuf.c 5.4 (Berkeley) %G%";
9#endif not lint
10
11#include <stdio.h>
12#include <sys/param.h>
13#include <sys/mbuf.h>
14#define YES 1
15typedef int bool;
16
17struct mbstat mbstat;
18extern int kmem;
19
20static 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" },
30 { MT_ATABLE, "address resolution tables" },
31 { MT_FTABLE, "fragment reassembly queue headers" },
32 { MT_SONAME, "socket names and addresses" },
33 { MT_SOOPTS, "socket options" },
34 { MT_RIGHTS, "access rights" },
35 { MT_IFADDR, "interface addresses" },
36 { 0, 0 }
37};
38
39int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short);
40bool seen[256]; /* "have we seen this type yet?" */
41
42/*
43 * Print mbuf statistics.
44 */
45mbpr(mbaddr)
46 off_t mbaddr;
47{
48 register int totmem, totfree, totmbufs;
49 register int i;
50 register struct mbtypes *mp;
51
52 if (nmbtypes != 256) {
53 fprintf(stderr, "unexpected change to mbstat; check source\n");
54 return;
55 }
56 if (mbaddr == 0) {
57 printf("mbstat: symbol not in namelist\n");
58 return;
59 }
60 klseek(kmem, mbaddr, 0);
61 if (read(kmem, (char *)&mbstat, sizeof (mbstat)) != sizeof (mbstat)) {
62 printf("mbstat: bad read\n");
63 return;
64 }
65 printf("%u/%u mbufs in use:\n",
66 mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE], mbstat.m_mbufs);
67 totmbufs = 0;
68 for (mp = mbtypes; mp->mt_name; mp++)
69 if (mbstat.m_mtypes[mp->mt_type]) {
70 seen[mp->mt_type] = YES;
71 printf("\t%u mbufs allocated to %s\n",
72 mbstat.m_mtypes[mp->mt_type], mp->mt_name);
73 totmbufs += mbstat.m_mtypes[mp->mt_type];
74 }
75 seen[MT_FREE] = YES;
76 for (i = 0; i < nmbtypes; i++)
77 if (!seen[i] && mbstat.m_mtypes[i]) {
78 printf("\t%u mbufs allocated to <mbuf type %d>\n",
79 mbstat.m_mtypes[i], i);
80 totmbufs += mbstat.m_mtypes[i];
81 }
82 if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE])
83 printf("*** %u mbufs missing ***\n",
84 (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs);
85 printf("%u/%u mapped pages in use\n",
86 mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters);
87 totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES;
88 totfree = mbstat.m_mtypes[MT_FREE]*MSIZE + mbstat.m_clfree * CLBYTES;
89 printf("%u Kbytes allocated to network (%d%% in use)\n",
90 totmem / 1024, (totmem - totfree) * 100 / totmem);
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);
94}