|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)mbuf.c 4.5 82/12/18";
3: #endif
4:
5: #include <sys/param.h>
6: #include <sys/mbuf.h>
7: #include <nlist.h>
8: #include "nstat.h"
9:
10: struct nlist mbufnl[] = {
11: # define N_MBSTAT 0
12: { "_mbstat" },
13: { "" },
14: };
15: struct mbstat mbstat;
16:
17:
18: static struct mbtypes {
19: int mt_type;
20: char *mt_name;
21: } mbtypes[] = {
22: { MT_DATA, "data" },
23: { MT_HEADER, "packet headers" },
24: { MT_SOCKET, "socket structures" },
25: { MT_PCB, "protocol control blocks" },
26: { MT_RTABLE, "routing table entries" },
27: { MT_HTABLE, "IMP host table entries" },
28: #ifdef notdef
29: { MT_ATABLE, "address resolution tables" },
30: #endif
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" },
35: { 0, 0 }
36: };
37:
38: extern int kmem;
39: extern char *system;
40: /*
41: * Print mbuf statistics.
42: */
43: mbpr()
44: {
45: off_t mbaddr;
46: register int totmem, totfree, totmbufs;
47: register struct mbtypes *mp;
48:
49: static int getvm;
50:
51: if (!getvm) {
52: nlist(system, mbufnl);
53: ++getvm;
54: }
55: mbaddr = mbufnl[N_MBSTAT].n_value;
56: if (mbaddr == 0) {
57: printf("mbstat: symbol not in namelist\n");
58: return;
59: }
60:
61: klseek(kmem, mbaddr, 0);
62: if (read(kmem, &mbstat, sizeof (mbstat)) != sizeof (mbstat)) {
63: printf("mbstat: bad read\n");
64: return;
65: }
66: printf("%d/%d mbufs in use:\n",
67: mbstat.m_mbufs - mbstat.m_mbfree, mbstat.m_mbufs);
68: totmbufs = 0;
69: for (mp = mbtypes; mp->mt_name; mp++)
70: if (mbstat.m_mtypes[mp->mt_type]) {
71: printf("\t%d 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: if (totmbufs != mbstat.m_mbufs - mbstat.m_mbfree)
76: printf("*** %d mbufs missing ***\n",
77: (mbstat.m_mbufs - mbstat.m_mbfree) - totmbufs);
78: printf("%d/%d mapped pages in use\n",
79: mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters);
80: totmem = mbstat.m_mbufs * MSIZE + mbstat.m_clusters * CLBYTES;
81: totfree = mbstat.m_mbfree * MSIZE + mbstat.m_clusters * CLBYTES;
82: printf("%d Kbytes allocated to network (%d%% in use)\n",
83: totmem / 1024, (totmem - totfree) * 100 / totmem);
84: printf("%d requests for memory denied\n", mbstat.m_drops);
85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.