macros for different classes of network
[unix-history] / .ref-BSD-3 / usr / src / cmd / vmstat.c
CommitLineData
3714775d
BJ
1#include <stdio.h>
2#include <sys/param.h>
3#include <sys/vm.h>
4
5struct
6{
7 char name[8];
8 int type;
9 unsigned value;
10} nl[] = {
11 "_dk_busy", 0, 0,
12 "_dk_time", 0, 0,
13 "_dk_numb", 0, 0,
14 "_rate", 0, 0,
15 "_total", 0, 0,
16 "_deficit", 0, 0,
17#define X_FORKSTAT 6
18 "_forksta", 0, 0,
19#define X_SUM 7
20 "_sum", 0, 0,
21#define X_FIRSTFREE 8
22 "_firstfr", 0, 0,
23#define X_MAXFREE 9
24 "_maxfree", 0, 0,
25#ifdef ERNIE
26#define X_REC 10
27 "_rectime", 0, 0,
28#define X_PGIN 11
29 "_pgintim", 0, 0,
30#endif
31 "\0\0\0\0\0\0\0\0", 0, 0
32};
33
34int firstfree, maxfree;
35char version[128];
36struct
37{
38 int busy;
39 long etime[32];
40 long numb[3];
41 struct vmmeter Rate;
42 struct vmtotal Total;
43 struct vmmeter Sum;
44 struct forkstat Forkstat;
45#ifdef ERNIE
46 unsigned rectime;
47 unsigned pgintime;
48#endif
49} s, s1, z;
50#define rate s.Rate
51#define total s.Total
52#define sum s.Sum
53#define forkstat s.Forkstat
54
55int zero;
56int deficit;
57double etime;
58int mf;
59
60main(argc, argv)
61char **argv;
62{
63 int lines;
64 extern char *ctime();
65 register i;
66 int iter;
67 double f1, f2;
68 long t;
69 extern char _sobuf[];
70
71 setbuf(stdout, _sobuf);
72 nlist("/vmunix", nl);
73 if(nl[0].type == -1) {
74 printf("no /vmunix namelist\n");
75 exit(1);
76 }
77 mf = open("/dev/kmem", 0);
78 if(mf < 0) {
79 printf("cannot open /dev/kmem\n");
80 exit(1);
81 }
82 iter = 0;
83 argc--, argv++;
84 while (argc>0 && argv[0][0]=='-') {
85 char *cp = *argv++;
86 argc--;
87 while (*++cp) switch (*cp) {
88
89#ifdef ERNIE
90 case 't':
91 dotimes();
92 exit(0);
93#endif
94 case 'z':
95 close(mf);
96 mf = open("/dev/kmem", 2);
97 lseek(mf, (long)nl[X_SUM].value, 0);
98 write(mf, &z.Sum, sizeof z.Sum);
99 exit(0);
100
101 case 'f':
102 doforkst();
103 exit(0);
104
105 case 's':
106 dosum();
107 exit(0);
108
109 default:
110 fprintf(stderr, "usage: vmstat [ -fs ] [ interval ] [ count]\n");
111 exit(1);
112 }
113 }
114 if(argc > 1)
115 iter = atoi(argv[1]);
116 lseek(mf, (long)nl[X_FIRSTFREE].value, 0);
117 read(mf, &firstfree, sizeof firstfree);
118 lseek(mf, (long)nl[X_MAXFREE].value, 0);
119 read(mf, &maxfree, sizeof maxfree);
120reprint:
121 lines = 20;
122 /* s1 = z; */
123printf("\
124 Procs Virtual Real Page Swap Disk Cpu\n\
125RQ DW PW SL SW AVM TX FRE RE PI PO FR DE SR I O D0 D1 D2 CS US NI SY ID\n\
126");
127loop:
128 lseek(mf, (long)nl[0].value, 0);
129 read(mf, &s.busy, sizeof s.busy);
130 lseek(mf, (long)nl[1].value, 0);
131 read(mf, s.etime, sizeof s.etime);
132 lseek(mf, (long)nl[2].value, 0);
133 read(mf, s.numb, sizeof s.numb);
134 lseek(mf, (long)nl[3].value, 0);
135 read(mf, &rate, sizeof rate);
136 lseek(mf, (long)nl[4].value, 0);
137 read(mf, &total, sizeof total);
138 lseek(mf, (long)nl[5].value, 0);
139 read(mf, &deficit, sizeof deficit);
140 for(i=0; i<35; i++) {
141 t = s.etime[i];
142 s.etime[i] -= s1.etime[i];
143 s1.etime[i] = t;
144 }
145 t = 0;
146 for(i=0; i<32; i++)
147 t += s.etime[i];
148 etime = t;
149 if(etime == 0.)
150 etime = 1.;
151/*
152 Procs Virtual Real Page Swap Disk Cpu
153RQ DW PW SL SW AVM TX FRE RE PI PO FR DE SR I O D0 D1 D2 CS US NI SY ID
154*/
155 printf("%2d%3d%3d%3d%3d", total.t_rq, total.t_dw, total.t_pw,
156 total.t_sl, total.t_sw);
157 printf("%6d%3d%5d", total.t_avm, pct(total.t_avmtxt, total.t_avm),
158 total.t_free);
159 printf("%4d%3d", rate.v_pgrec, rate.v_pgin);
160 printf("%3d%3d%4d%4.1f%2d%2d",
161 rate.v_pgout, rate.v_dfree, deficit,
162 (60.0 * rate.v_scan) / LOOPSIZ,
163 rate.v_swpin, rate.v_swpout);
164 etime /= 60.;
165 printf(" ");
166 for(i=0; i<3; i++)
167 stats(i);
168 printf("%4d", rate.v_swtch);
169 for(i=0; i<4; i++)
170 stat1(i*8);
171 printf("\n");
172 fflush(stdout);
173contin:
174 --iter;
175 if(iter)
176 if(argc > 0) {
177 sleep(atoi(argv[0]));
178 if (--lines <= 0)
179 goto reprint;
180 goto loop;
181 }
182}
183
184#ifdef ERNIE
185dotimes()
186{
187
188 lseek(mf, (long)nl[X_REC].value, 0);
189 read(mf, &s.rectime, sizeof s.rectime);
190 lseek(mf, (long)nl[X_PGIN].value, 0);
191 read(mf, &s.pgintime, sizeof s.pgintime);
192 lseek(mf, (long)nl[X_SUM].value, 0);
193 read(mf, &sum, sizeof sum);
194 printf("%d reclaims, %d total time (usec)\n", sum.v_pgrec, s.rectime);
195 printf("average: %d usec / reclaim\n", s.rectime/sum.v_pgrec);
196 printf("\n");
197 printf("%d page ins, %d total time (msec)\n",sum.v_pgin, s.pgintime/10);
198 printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0));
199}
200#endif
201
202dosum()
203{
204
205 lseek(mf, (long)nl[X_SUM].value, 0);
206 read(mf, &sum, sizeof sum);
207 printf("%8d swap ins\n", sum.v_swpin);
208 printf("%8d swap outs\n", sum.v_swpout);
209 printf("%8d pages swapped in\n", sum.v_pswpin);
210 printf("%8d pages swapped out\n", sum.v_pswpout);
211 printf("%8d total address trans. faults taken\n", sum.v_faults);
212 printf("%8d page ins\n", sum.v_pgin);
213 printf("%8d page outs\n", sum.v_pgout);
214 printf("%8d total reclaims\n", sum.v_pgrec);
215 printf("%8d reclaims from free list\n", sum.v_pgfrec);
216 printf("%8d intransit blocking page faults\n", sum.v_intrans);
217 printf("%8d zero fill on demand page faults\n", sum.v_zfod / CLSIZE);
218 printf("%8d total zero fill pages created\n", sum.v_nzfod);
219 printf("%8d executable fill on demand page faults\n", sum.v_exfod / CLSIZE);
220 printf("%8d total executable fill pages created\n", sum.v_nexfod);
221 printf("%8d file fill on demand page faults\n", sum.v_vrfod / CLSIZE);
222 printf("%8d total pages set up for fill on demand with vread\n", sum.v_nvrfod);
223 printf("%8d pages examined by the clock daemon\n", sum.v_scan);
224 printf("%8d revolutions of the clock hand\n", sum.v_rev);
225 printf("%8d pages freed by the clock daemon\n", sum.v_dfree);
226 printf("%8d cpu context switches\n", sum.v_swtch);
227}
228
229
230doforkst()
231{
232
233 lseek(mf, (long)nl[X_FORKSTAT].value, 0);
234 read(mf, &forkstat, sizeof forkstat);
235 printf("%d forks, %d pages, average=%.2f\n",
236 forkstat.cntfork, forkstat.sizfork,
237 (float) forkstat.sizfork / forkstat.cntfork);
238 printf("%d vforks, %d pages, average=%.2f\n",
239 forkstat.cntvfork, forkstat.sizvfork,
240 (float)forkstat.sizvfork / forkstat.cntvfork);
241}
242
243stats(dn)
244{
245 register i;
246 double f1, f2;
247 long t;
248
249 t = 0;
250 for(i=0; i<32; i++)
251 if(i & (1<<dn))
252 t += s.etime[i];
253 f1 = t;
254 f1 = f1/60.;
255 f2 = s.numb[dn];
256 if(f2 == 0. && dn) {
257 printf("%3.0f", 0.0);
258 return;
259 }
260 printf("%3.0f", f2/etime);
261}
262
263stat1(o)
264{
265 register i;
266 long t;
267 double f1, f2;
268
269 t = 0;
270 for(i=0; i<32; i++)
271 t += s.etime[i];
272 f1 = t;
273 if(f1 == 0.)
274 f1 = 1.;
275 t = 0;
276 for(i=0; i<8; i++)
277 t += s.etime[o+i];
278 f2 = t;
279 printf("%3.0f", f2*100./f1);
280}
281pct(top, bot)
282{
283
284 if (bot == 0)
285 return (0);
286 return ((top * 100) / bot);
287}