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