(no message)
[unix-history] / usr / src / usr.bin / systat / mbufs.c
CommitLineData
4376ba29 1#ifndef lint
d830bff6 2static char sccsid[] = "@(#)mbufs.c 1.2 (Lucasfilm) %G%";
4376ba29
SL
3#endif
4
5#include "systat.h"
6#include <sys/mbuf.h>
7
d830bff6
SL
8WINDOW *
9openmbufs()
4376ba29 10{
d830bff6 11 static WINDOW *w = NULL;
4376ba29 12
d830bff6
SL
13 if (w == NULL)
14 w = newwin(20, 70, 3, 5);
15 return (w);
4376ba29
SL
16}
17
d830bff6
SL
18closembufs(w)
19 WINDOW *w;
4376ba29
SL
20{
21
d830bff6
SL
22 if (w == NULL)
23 return;
24 move(5, 0);
25 clrtobot();
26 wclear(w);
27 wrefresh(w);
4376ba29
SL
28}
29
d830bff6
SL
30struct mbstat *mb;
31
4376ba29
SL
32labelmbufs()
33{
34
d830bff6 35 move(5, 0); clrtoeol();
4376ba29
SL
36 mvaddstr(5, 20,
37 "/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50");
38}
39
40char *mtnames[] = {
41 "free",
42 "data",
43 "headers",
44 "sockets",
45 "pcbs",
46 "routes",
47 "hosts",
48 "arps",
49 "socknames",
50 "zombies",
51 "sockopts",
52 "frags",
53};
54
55showmbufs()
56{
57 register int i, j, max, index;
58 char buf[10];
59
60 if (mb == 0)
61 return;
62 for (j = 0; j < 15; j++) {
63 max = 0, index = -1;
64 for (i = 0; i < 15; i++)
65 if (mb->m_mtypes[i] > max) {
66 max = mb->m_mtypes[i];
67 index = i;
68 }
69 if (max == 0)
70 break;
71 wmove(wnd, 3 + j, 0);
72 waddstr(wnd, mtnames[index]);
73 wmove(wnd, 3 + j, 15);
74 if (max > 50) {
75 sprintf(buf, " %d", max);
76 max = 50;
77 while (max--)
78 waddch(wnd, 'X');
79 waddstr(wnd, buf);
80 } else {
81 while (max--)
82 waddch(wnd, 'X');
83 wclrtoeol(wnd);
84 }
85 mb->m_mtypes[index] = 0;
86 }
87 while (j++ < 15) {
88 wmove(wnd, 3 + j, 0);
89 wclrtoeol(wnd);
90 }
91}
d830bff6
SL
92
93static struct nlist nlst[] = {
94#define X_MBSTAT 0
95 { "_mbstat" },
96 { "" }
97};
98
99initmbufs()
100{
101
102 if (nlst[X_MBSTAT].n_type == 0) {
103 nlist("/vmunix", nlst);
104 if (nlst[X_MBSTAT].n_type == 0) {
105 error("namelist on /vmunix failed");
106 return;
107 }
108 }
109 if (mb == 0)
110 mb = (struct mbstat *)calloc(1, sizeof (*mb));
111}
112
113fetchmbufs()
114{
115
116 if (nlst[X_MBSTAT].n_type == 0)
117 return;
118 lseek(kmem, nlst[X_MBSTAT].n_value, L_SET);
119 read(kmem, mb, sizeof (*mb));
120}