vmstat.c revision 1.39 1 1.39 sommerfe /* $NetBSD: vmstat.c,v 1.39 2002/06/30 00:10:34 sommerfeld Exp $ */
2 1.2 jtc
3 1.1 jtc /*-
4 1.1 jtc * Copyright (c) 1983, 1989, 1992, 1993
5 1.1 jtc * The Regents of the University of California. All rights reserved.
6 1.1 jtc *
7 1.1 jtc * Redistribution and use in source and binary forms, with or without
8 1.1 jtc * modification, are permitted provided that the following conditions
9 1.1 jtc * are met:
10 1.1 jtc * 1. Redistributions of source code must retain the above copyright
11 1.1 jtc * notice, this list of conditions and the following disclaimer.
12 1.1 jtc * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jtc * notice, this list of conditions and the following disclaimer in the
14 1.1 jtc * documentation and/or other materials provided with the distribution.
15 1.1 jtc * 3. All advertising materials mentioning features or use of this software
16 1.1 jtc * must display the following acknowledgement:
17 1.1 jtc * This product includes software developed by the University of
18 1.1 jtc * California, Berkeley and its contributors.
19 1.1 jtc * 4. Neither the name of the University nor the names of its contributors
20 1.1 jtc * may be used to endorse or promote products derived from this software
21 1.1 jtc * without specific prior written permission.
22 1.1 jtc *
23 1.1 jtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 jtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 jtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 jtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 jtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 jtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 jtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 jtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 jtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 jtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 jtc * SUCH DAMAGE.
34 1.1 jtc */
35 1.1 jtc
36 1.8 mrg #include <sys/cdefs.h>
37 1.1 jtc #ifndef lint
38 1.2 jtc #if 0
39 1.1 jtc static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
40 1.2 jtc #endif
41 1.39 sommerfe __RCSID("$NetBSD: vmstat.c,v 1.39 2002/06/30 00:10:34 sommerfeld Exp $");
42 1.1 jtc #endif /* not lint */
43 1.1 jtc
44 1.1 jtc /*
45 1.1 jtc * Cursed vmstat -- from Robert Elz.
46 1.1 jtc */
47 1.1 jtc
48 1.1 jtc #include <sys/param.h>
49 1.1 jtc #include <sys/dkstat.h>
50 1.1 jtc #include <sys/user.h>
51 1.1 jtc #include <sys/namei.h>
52 1.1 jtc #include <sys/sysctl.h>
53 1.1 jtc
54 1.11 mrg #include <uvm/uvm_extern.h>
55 1.11 mrg
56 1.3 mycroft #include <stdlib.h>
57 1.1 jtc #include <string.h>
58 1.3 mycroft #include <utmp.h>
59 1.3 mycroft
60 1.1 jtc #include "systat.h"
61 1.1 jtc #include "extern.h"
62 1.35 simonb #include "dkstats.h"
63 1.1 jtc
64 1.1 jtc static struct Info {
65 1.34 simonb struct uvmexp_sysctl uvmexp;
66 1.1 jtc struct vmtotal Total;
67 1.1 jtc struct nchstats nchstats;
68 1.1 jtc long nchcount;
69 1.1 jtc long *intrcnt;
70 1.1 jtc } s, s1, s2, z;
71 1.1 jtc
72 1.1 jtc #define cnt s.Cnt
73 1.1 jtc #define oldcnt s1.Cnt
74 1.1 jtc #define total s.Total
75 1.1 jtc #define nchtotal s.nchstats
76 1.1 jtc #define oldnchtotal s1.nchstats
77 1.1 jtc
78 1.1 jtc static enum state { BOOT, TIME, RUN } state = TIME;
79 1.1 jtc
80 1.33 ad static void allocinfo(struct Info *);
81 1.33 ad static void copyinfo(struct Info *, struct Info *);
82 1.33 ad static float cputime(int);
83 1.33 ad static void dinfo(int, int);
84 1.33 ad static void getinfo(struct Info *, enum state);
85 1.33 ad static void putint(int, int, int, int);
86 1.33 ad static void putfloat(double, int, int, int, int, int);
87 1.33 ad static int ucount(void);
88 1.1 jtc
89 1.1 jtc static int ut;
90 1.1 jtc static char buf[26];
91 1.25 simonb static u_int64_t t;
92 1.1 jtc static double etime;
93 1.1 jtc static float hertz;
94 1.1 jtc static int nintr;
95 1.1 jtc static long *intrloc;
96 1.1 jtc static char **intrname;
97 1.1 jtc static int nextintsrow;
98 1.1 jtc
99 1.1 jtc struct utmp utmp;
100 1.1 jtc
101 1.1 jtc WINDOW *
102 1.33 ad openvmstat(void)
103 1.1 jtc {
104 1.1 jtc
105 1.1 jtc ut = open(_PATH_UTMP, O_RDONLY);
106 1.1 jtc if (ut < 0)
107 1.1 jtc error("No utmp");
108 1.1 jtc return (stdscr);
109 1.1 jtc }
110 1.1 jtc
111 1.1 jtc void
112 1.33 ad closevmstat(WINDOW *w)
113 1.1 jtc {
114 1.1 jtc
115 1.1 jtc (void) close(ut);
116 1.1 jtc if (w == NULL)
117 1.1 jtc return;
118 1.1 jtc wclear(w);
119 1.1 jtc wrefresh(w);
120 1.1 jtc }
121 1.1 jtc
122 1.1 jtc
123 1.1 jtc static struct nlist namelist[] = {
124 1.38 kleink #define X_NCHSTATS 0
125 1.1 jtc { "_nchstats" },
126 1.38 kleink #define X_INTRNAMES 1
127 1.1 jtc { "_intrnames" },
128 1.38 kleink #define X_EINTRNAMES 2
129 1.1 jtc { "_eintrnames" },
130 1.38 kleink #define X_INTRCNT 3
131 1.1 jtc { "_intrcnt" },
132 1.38 kleink #define X_EINTRCNT 4
133 1.1 jtc { "_eintrcnt" },
134 1.1 jtc { "" },
135 1.1 jtc };
136 1.1 jtc
137 1.1 jtc /*
138 1.1 jtc * These constants define where the major pieces are laid out
139 1.1 jtc */
140 1.1 jtc #define STATROW 0 /* uses 1 row and 68 cols */
141 1.1 jtc #define STATCOL 2
142 1.1 jtc #define MEMROW 2 /* uses 4 rows and 31 cols */
143 1.1 jtc #define MEMCOL 0
144 1.1 jtc #define PAGEROW 2 /* uses 4 rows and 26 cols */
145 1.1 jtc #define PAGECOL 36
146 1.1 jtc #define INTSROW 2 /* uses all rows to bottom and 17 cols */
147 1.1 jtc #define INTSCOL 63
148 1.1 jtc #define PROCSROW 7 /* uses 2 rows and 20 cols */
149 1.1 jtc #define PROCSCOL 0
150 1.1 jtc #define GENSTATROW 7 /* uses 2 rows and 30 cols */
151 1.36 augustss #define GENSTATCOL 18
152 1.1 jtc #define VMSTATROW 7 /* uses 17 rows and 12 cols */
153 1.1 jtc #define VMSTATCOL 48
154 1.1 jtc #define GRAPHROW 10 /* uses 3 rows and 51 cols */
155 1.1 jtc #define GRAPHCOL 0
156 1.1 jtc #define NAMEIROW 14 /* uses 3 rows and 38 cols */
157 1.1 jtc #define NAMEICOL 0
158 1.1 jtc #define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */
159 1.1 jtc #define DISKCOL 0
160 1.1 jtc
161 1.1 jtc #define DRIVESPACE 9 /* max # for space */
162 1.1 jtc
163 1.1 jtc #if DK_NDRIVE > DRIVESPACE
164 1.1 jtc #define MAXDRIVES DRIVESPACE /* max # to display */
165 1.1 jtc #else
166 1.1 jtc #define MAXDRIVES DK_NDRIVE /* max # to display */
167 1.1 jtc #endif
168 1.1 jtc
169 1.1 jtc int
170 1.33 ad initvmstat(void)
171 1.1 jtc {
172 1.1 jtc char *intrnamebuf, *cp;
173 1.1 jtc int i;
174 1.1 jtc static int once = 0;
175 1.1 jtc
176 1.1 jtc if (namelist[0].n_type == 0) {
177 1.1 jtc if (kvm_nlist(kd, namelist)) {
178 1.1 jtc nlisterr(namelist);
179 1.1 jtc return(0);
180 1.1 jtc }
181 1.1 jtc if (namelist[0].n_type == 0) {
182 1.1 jtc error("No namelist");
183 1.1 jtc return(0);
184 1.1 jtc }
185 1.1 jtc }
186 1.1 jtc hertz = stathz ? stathz : hz;
187 1.37 augustss if (! dkinit(1))
188 1.1 jtc return(0);
189 1.1 jtc if (dk_ndrive && !once) {
190 1.1 jtc #define allocate(e, t) \
191 1.7 scottr s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
192 1.7 scottr s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
193 1.7 scottr s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
194 1.7 scottr z./**/e = (t *)calloc(dk_ndrive, sizeof (t));
195 1.1 jtc once = 1;
196 1.1 jtc #undef allocate
197 1.1 jtc }
198 1.1 jtc if (nintr == 0) {
199 1.1 jtc nintr = (namelist[X_EINTRCNT].n_value -
200 1.1 jtc namelist[X_INTRCNT].n_value) / sizeof (long);
201 1.1 jtc intrloc = calloc(nintr, sizeof (long));
202 1.1 jtc intrname = calloc(nintr, sizeof (long));
203 1.1 jtc intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
204 1.1 jtc namelist[X_INTRNAMES].n_value);
205 1.23 jwise if (intrnamebuf == NULL || intrname == 0 || intrloc == 0) {
206 1.1 jtc error("Out of memory\n");
207 1.1 jtc if (intrnamebuf)
208 1.1 jtc free(intrnamebuf);
209 1.1 jtc if (intrname)
210 1.1 jtc free(intrname);
211 1.1 jtc if (intrloc)
212 1.1 jtc free(intrloc);
213 1.1 jtc nintr = 0;
214 1.1 jtc return(0);
215 1.1 jtc }
216 1.1 jtc NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
217 1.1 jtc NVAL(X_INTRNAMES));
218 1.1 jtc for (cp = intrnamebuf, i = 0; i < nintr; i++) {
219 1.1 jtc intrname[i] = cp;
220 1.1 jtc cp += strlen(cp) + 1;
221 1.1 jtc }
222 1.1 jtc nextintsrow = INTSROW + 2;
223 1.1 jtc allocinfo(&s);
224 1.1 jtc allocinfo(&s1);
225 1.1 jtc allocinfo(&s2);
226 1.1 jtc allocinfo(&z);
227 1.1 jtc }
228 1.1 jtc getinfo(&s2, RUN);
229 1.1 jtc copyinfo(&s2, &s1);
230 1.1 jtc return(1);
231 1.1 jtc }
232 1.1 jtc
233 1.1 jtc void
234 1.33 ad fetchvmstat(void)
235 1.1 jtc {
236 1.1 jtc time_t now;
237 1.1 jtc
238 1.1 jtc time(&now);
239 1.1 jtc strcpy(buf, ctime(&now));
240 1.18 marc buf[19] = '\0';
241 1.1 jtc getinfo(&s, state);
242 1.1 jtc }
243 1.1 jtc
244 1.1 jtc void
245 1.33 ad labelvmstat(void)
246 1.1 jtc {
247 1.10 lukem int i, j;
248 1.1 jtc
249 1.1 jtc clear();
250 1.1 jtc mvprintw(STATROW, STATCOL + 4, "users Load");
251 1.13 mrg mvprintw(MEMROW, MEMCOL, " memory totals (in KB)");
252 1.13 mrg mvprintw(MEMROW + 1, MEMCOL, " real virtual free");
253 1.13 mrg mvprintw(MEMROW + 2, MEMCOL, "Active");
254 1.13 mrg mvprintw(MEMROW + 3, MEMCOL, "All");
255 1.13 mrg
256 1.13 mrg mvprintw(PAGEROW, PAGECOL, " PAGING SWAPPING ");
257 1.13 mrg mvprintw(PAGEROW + 1, PAGECOL, " in out in out ");
258 1.13 mrg mvprintw(PAGEROW + 2, PAGECOL, "ops");
259 1.13 mrg mvprintw(PAGEROW + 3, PAGECOL, "pages");
260 1.1 jtc
261 1.1 jtc mvprintw(INTSROW, INTSCOL + 3, " Interrupts");
262 1.1 jtc mvprintw(INTSROW + 1, INTSCOL + 9, "total");
263 1.1 jtc
264 1.12 mrg mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "forks");
265 1.12 mrg mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "fkppw");
266 1.12 mrg mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "fksvm");
267 1.12 mrg mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "pwait");
268 1.12 mrg mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "relck");
269 1.12 mrg mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "rlkok");
270 1.12 mrg mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "noram");
271 1.12 mrg mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "ndcpy");
272 1.12 mrg mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "fltcp");
273 1.12 mrg mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "zfod");
274 1.12 mrg mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "cow");
275 1.12 mrg mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "fmin");
276 1.12 mrg mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "ftarg");
277 1.12 mrg mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "itarg");
278 1.12 mrg mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "wired");
279 1.12 mrg mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "pdfre");
280 1.12 mrg if (LINES - 1 > VMSTATROW + 16)
281 1.12 mrg mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "pdscn");
282 1.1 jtc
283 1.36 augustss mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt");
284 1.1 jtc
285 1.1 jtc mvprintw(GRAPHROW, GRAPHCOL,
286 1.28 mycroft " . %% Sy . %% Us . %% Ni . %% In . %% Id");
287 1.13 mrg mvprintw(PROCSROW, PROCSCOL, "Proc:r d s w");
288 1.1 jtc mvprintw(GRAPHROW + 1, GRAPHCOL,
289 1.1 jtc "| | | | | | | | | | |");
290 1.1 jtc
291 1.1 jtc mvprintw(NAMEIROW, NAMEICOL, "Namei Sys-cache Proc-cache");
292 1.1 jtc mvprintw(NAMEIROW + 1, NAMEICOL,
293 1.1 jtc " Calls hits %% hits %%");
294 1.1 jtc mvprintw(DISKROW, DISKCOL, "Discs");
295 1.1 jtc mvprintw(DISKROW + 1, DISKCOL, "seeks");
296 1.1 jtc mvprintw(DISKROW + 2, DISKCOL, "xfers");
297 1.5 thorpej mvprintw(DISKROW + 3, DISKCOL, "Kbyte");
298 1.31 mycroft mvprintw(DISKROW + 4, DISKCOL, "%%busy");
299 1.1 jtc j = 0;
300 1.1 jtc for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)
301 1.1 jtc if (dk_select[i]) {
302 1.1 jtc mvprintw(DISKROW, DISKCOL + 5 + 5 * j,
303 1.20 soren " %4.4s", dr_name[j]);
304 1.1 jtc j++;
305 1.1 jtc }
306 1.1 jtc for (i = 0; i < nintr; i++) {
307 1.1 jtc if (intrloc[i] == 0)
308 1.1 jtc continue;
309 1.1 jtc mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", intrname[i]);
310 1.1 jtc }
311 1.1 jtc }
312 1.1 jtc
313 1.1 jtc #define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
314 1.1 jtc #define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
315 1.1 jtc #define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
316 1.1 jtc if(state == TIME) s1.nchstats.fld = t;}
317 1.16 mycroft #define PUTRATE(fld, l, c, w) {Y(fld); putint((int)((float)s.fld/etime + 0.5), l, c, w);}
318 1.1 jtc #define MAXFAIL 5
319 1.1 jtc
320 1.25 simonb static char cpuchar[CPUSTATES] = { '=' , '>', '-', '%', ' ' };
321 1.25 simonb static char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_INTR, CP_IDLE };
322 1.1 jtc
323 1.1 jtc void
324 1.33 ad showvmstat(void)
325 1.1 jtc {
326 1.1 jtc float f1, f2;
327 1.1 jtc int psiz, inttotal;
328 1.1 jtc int i, l, c;
329 1.1 jtc static int failcnt = 0;
330 1.39 sommerfe
331 1.5 thorpej if (state == TIME)
332 1.5 thorpej dkswap();
333 1.39 sommerfe etime = cur.cp_etime;
334 1.39 sommerfe if ((etime * hertz) < 1.0) { /* < 5 ticks - ignore this trash */
335 1.1 jtc if (failcnt++ >= MAXFAIL) {
336 1.1 jtc clear();
337 1.1 jtc mvprintw(2, 10, "The alternate system clock has died!");
338 1.1 jtc mvprintw(3, 10, "Reverting to ``pigs'' display.");
339 1.1 jtc move(CMDLINE, 0);
340 1.1 jtc refresh();
341 1.1 jtc failcnt = 0;
342 1.1 jtc sleep(5);
343 1.1 jtc command("pigs");
344 1.1 jtc }
345 1.1 jtc return;
346 1.1 jtc }
347 1.1 jtc failcnt = 0;
348 1.1 jtc inttotal = 0;
349 1.1 jtc for (i = 0; i < nintr; i++) {
350 1.1 jtc if (s.intrcnt[i] == 0)
351 1.1 jtc continue;
352 1.1 jtc if (intrloc[i] == 0) {
353 1.1 jtc if (nextintsrow == LINES)
354 1.1 jtc continue;
355 1.1 jtc intrloc[i] = nextintsrow++;
356 1.1 jtc mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s",
357 1.1 jtc intrname[i]);
358 1.1 jtc }
359 1.1 jtc X(intrcnt);
360 1.1 jtc l = (int)((float)s.intrcnt[i]/etime + 0.5);
361 1.1 jtc inttotal += l;
362 1.1 jtc putint(l, intrloc[i], INTSCOL, 8);
363 1.1 jtc }
364 1.1 jtc putint(inttotal, INTSROW + 1, INTSCOL, 8);
365 1.1 jtc Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss);
366 1.1 jtc Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes);
367 1.1 jtc s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits +
368 1.1 jtc nchtotal.ncs_miss + nchtotal.ncs_long;
369 1.1 jtc if (state == TIME)
370 1.1 jtc s1.nchcount = s.nchcount;
371 1.1 jtc
372 1.1 jtc psiz = 0;
373 1.1 jtc f2 = 0.0;
374 1.1 jtc
375 1.39 sommerfe /*
376 1.1 jtc * Last CPU state not calculated yet.
377 1.1 jtc */
378 1.28 mycroft for (c = 0; c < CPUSTATES; c++) {
379 1.1 jtc i = cpuorder[c];
380 1.1 jtc f1 = cputime(i);
381 1.1 jtc f2 += f1;
382 1.1 jtc l = (int) ((f2 + 1.0) / 2.0) - psiz;
383 1.1 jtc if (c == 0)
384 1.1 jtc putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);
385 1.1 jtc else
386 1.28 mycroft putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c + 1, 5, 1, 0);
387 1.28 mycroft mvhline(GRAPHROW + 2, psiz, cpuchar[c], l);
388 1.1 jtc psiz += l;
389 1.1 jtc }
390 1.1 jtc
391 1.1 jtc putint(ucount(), STATROW, STATCOL, 3);
392 1.1 jtc putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
393 1.1 jtc putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
394 1.1 jtc putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
395 1.1 jtc mvaddstr(STATROW, STATCOL + 53, buf);
396 1.17 drochner #define pgtokb(pg) ((pg) * (s.uvmexp.pagesize / 1024))
397 1.11 mrg
398 1.13 mrg putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7);
399 1.12 mrg putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse), /* XXX */
400 1.13 mrg MEMROW + 2, MEMCOL + 16, 7);
401 1.13 mrg putint(pgtokb(s.uvmexp.npages - s.uvmexp.free), MEMROW + 3, MEMCOL + 6, 7);
402 1.12 mrg putint(pgtokb(s.uvmexp.npages - s.uvmexp.free + s.uvmexp.swpginuse),
403 1.13 mrg MEMROW + 3, MEMCOL + 16, 7);
404 1.13 mrg putint(pgtokb(s.uvmexp.free), MEMROW + 2, MEMCOL + 24, 7);
405 1.12 mrg putint(pgtokb(s.uvmexp.free + s.uvmexp.swpages - s.uvmexp.swpginuse),
406 1.13 mrg MEMROW + 3, MEMCOL + 24, 7);
407 1.1 jtc putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
408 1.13 mrg putint(total.t_dw, PROCSROW + 1, PROCSCOL + 6, 3);
409 1.13 mrg putint(total.t_sl, PROCSROW + 1, PROCSCOL + 9, 3);
410 1.13 mrg putint(total.t_sw, PROCSROW + 1, PROCSCOL + 12, 3);
411 1.12 mrg PUTRATE(uvmexp.forks, VMSTATROW + 0, VMSTATCOL + 3, 6);
412 1.12 mrg PUTRATE(uvmexp.forks_ppwait, VMSTATROW + 1, VMSTATCOL + 3, 6);
413 1.12 mrg PUTRATE(uvmexp.forks_sharevm, VMSTATROW + 2, VMSTATCOL + 3, 6);
414 1.12 mrg PUTRATE(uvmexp.fltpgwait, VMSTATROW + 3, VMSTATCOL + 4, 5);
415 1.12 mrg PUTRATE(uvmexp.fltrelck, VMSTATROW + 4, VMSTATCOL + 3, 6);
416 1.12 mrg PUTRATE(uvmexp.fltrelckok, VMSTATROW + 5, VMSTATCOL + 3, 6);
417 1.12 mrg PUTRATE(uvmexp.fltnoram, VMSTATROW + 6, VMSTATCOL + 3, 6);
418 1.12 mrg PUTRATE(uvmexp.fltamcopy, VMSTATROW + 7, VMSTATCOL + 3, 6);
419 1.12 mrg PUTRATE(uvmexp.flt_prcopy, VMSTATROW + 8, VMSTATCOL + 3, 6);
420 1.12 mrg PUTRATE(uvmexp.flt_przero, VMSTATROW + 9, VMSTATCOL + 3, 6);
421 1.12 mrg PUTRATE(uvmexp.flt_acow, VMSTATROW + 10, VMSTATCOL, 9);
422 1.12 mrg putint(s.uvmexp.freemin, VMSTATROW + 11, VMSTATCOL, 9);
423 1.12 mrg putint(s.uvmexp.freetarg, VMSTATROW + 12, VMSTATCOL, 9);
424 1.12 mrg putint(s.uvmexp.inactarg, VMSTATROW + 13, VMSTATCOL, 9);
425 1.12 mrg putint(s.uvmexp.wired, VMSTATROW + 14, VMSTATCOL, 9);
426 1.12 mrg PUTRATE(uvmexp.pdfreed, VMSTATROW + 15, VMSTATCOL, 9);
427 1.11 mrg if (LINES - 1 > VMSTATROW + 16)
428 1.12 mrg PUTRATE(uvmexp.pdscans, VMSTATROW + 16, VMSTATCOL, 9);
429 1.12 mrg
430 1.12 mrg PUTRATE(uvmexp.pageins, PAGEROW + 2, PAGECOL + 5, 5);
431 1.11 mrg PUTRATE(uvmexp.pdpageouts, PAGEROW + 2, PAGECOL + 10, 5);
432 1.12 mrg PUTRATE(uvmexp.swapins, PAGEROW + 2, PAGECOL + 15, 5);
433 1.12 mrg PUTRATE(uvmexp.swapouts, PAGEROW + 2, PAGECOL + 20, 5);
434 1.12 mrg PUTRATE(uvmexp.pgswapin, PAGEROW + 3, PAGECOL + 5, 5);
435 1.12 mrg PUTRATE(uvmexp.pgswapout, PAGEROW + 3, PAGECOL + 10, 5);
436 1.12 mrg
437 1.36 augustss PUTRATE(uvmexp.swtch, GENSTATROW + 1, GENSTATCOL, 4);
438 1.36 augustss PUTRATE(uvmexp.traps, GENSTATROW + 1, GENSTATCOL + 4, 6);
439 1.36 augustss PUTRATE(uvmexp.syscalls, GENSTATROW + 1, GENSTATCOL + 10, 6);
440 1.36 augustss PUTRATE(uvmexp.intrs, GENSTATROW + 1, GENSTATCOL + 16, 5);
441 1.36 augustss PUTRATE(uvmexp.softs, GENSTATROW + 1, GENSTATCOL + 21, 5);
442 1.36 augustss PUTRATE(uvmexp.faults, GENSTATROW + 1, GENSTATCOL + 26, 6);
443 1.1 jtc mvprintw(DISKROW, DISKCOL + 5, " ");
444 1.1 jtc for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++)
445 1.1 jtc if (dk_select[i]) {
446 1.1 jtc mvprintw(DISKROW, DISKCOL + 5 + 5 * c,
447 1.20 soren " %4.4s", dr_name[i]);
448 1.1 jtc dinfo(i, ++c);
449 1.1 jtc }
450 1.1 jtc putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
451 1.1 jtc putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 9, 9);
452 1.1 jtc #define nz(x) ((x) ? (x) : 1)
453 1.1 jtc putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount),
454 1.1 jtc NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
455 1.1 jtc putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
456 1.1 jtc putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
457 1.1 jtc NAMEIROW + 2, NAMEICOL + 34, 4, 0, 1);
458 1.1 jtc #undef nz
459 1.1 jtc }
460 1.1 jtc
461 1.22 jwise void
462 1.33 ad vmstat_boot(char *args)
463 1.22 jwise {
464 1.22 jwise copyinfo(&z, &s1);
465 1.22 jwise state = BOOT;
466 1.22 jwise }
467 1.22 jwise
468 1.22 jwise void
469 1.33 ad vmstat_run(char *args)
470 1.22 jwise {
471 1.22 jwise copyinfo(&s1, &s2);
472 1.22 jwise state = RUN;
473 1.22 jwise }
474 1.22 jwise
475 1.22 jwise void
476 1.22 jwise vmstat_time (args)
477 1.22 jwise char * args;
478 1.1 jtc {
479 1.22 jwise state = TIME;
480 1.22 jwise }
481 1.1 jtc
482 1.22 jwise void
483 1.33 ad vmstat_zero(char *args)
484 1.22 jwise {
485 1.22 jwise if (state == RUN)
486 1.22 jwise getinfo(&s1, RUN);
487 1.1 jtc }
488 1.1 jtc
489 1.1 jtc /* calculate number of users on the system */
490 1.1 jtc static int
491 1.33 ad ucount(void)
492 1.1 jtc {
493 1.21 mrg int nusers = 0, onusers = -1;
494 1.1 jtc
495 1.1 jtc if (ut < 0)
496 1.1 jtc return (0);
497 1.1 jtc while (read(ut, &utmp, sizeof(utmp)))
498 1.1 jtc if (utmp.ut_name[0] != '\0')
499 1.1 jtc nusers++;
500 1.1 jtc
501 1.21 mrg if (nusers != onusers) {
502 1.21 mrg if (nusers == 1)
503 1.21 mrg mvprintw(STATROW, STATCOL + 8, " ");
504 1.21 mrg else
505 1.21 mrg mvprintw(STATROW, STATCOL + 8, "s");
506 1.21 mrg }
507 1.9 kleink lseek(ut, (off_t)0, SEEK_SET);
508 1.21 mrg onusers = nusers;
509 1.1 jtc return (nusers);
510 1.1 jtc }
511 1.1 jtc
512 1.1 jtc static float
513 1.33 ad cputime(int indx)
514 1.1 jtc {
515 1.1 jtc double t;
516 1.10 lukem int i;
517 1.1 jtc
518 1.1 jtc t = 0;
519 1.1 jtc for (i = 0; i < CPUSTATES; i++)
520 1.39 sommerfe t += cur.cp_time[i];
521 1.1 jtc if (t == 0.0)
522 1.1 jtc t = 1.0;
523 1.39 sommerfe return (cur.cp_time[indx] * 100.0 / t);
524 1.1 jtc }
525 1.1 jtc
526 1.1 jtc static void
527 1.33 ad putint(int n, int l, int c, int w)
528 1.1 jtc {
529 1.1 jtc char b[128];
530 1.1 jtc
531 1.1 jtc move(l, c);
532 1.1 jtc if (n == 0) {
533 1.30 mycroft hline(' ', w);
534 1.1 jtc return;
535 1.1 jtc }
536 1.14 mrg (void)snprintf(b, sizeof b, "%*d", w, n);
537 1.1 jtc if (strlen(b) > w) {
538 1.30 mycroft hline('*', w);
539 1.1 jtc return;
540 1.1 jtc }
541 1.1 jtc addstr(b);
542 1.1 jtc }
543 1.1 jtc
544 1.1 jtc static void
545 1.33 ad putfloat(double f, int l, int c, int w, int d, int nz)
546 1.1 jtc {
547 1.1 jtc char b[128];
548 1.1 jtc
549 1.1 jtc move(l, c);
550 1.1 jtc if (nz && f == 0.0) {
551 1.30 mycroft hline(' ', w);
552 1.1 jtc return;
553 1.1 jtc }
554 1.14 mrg (void)snprintf(b, sizeof b, "%*.*f", w, d, f);
555 1.1 jtc if (strlen(b) > w) {
556 1.30 mycroft hline('*', w);
557 1.1 jtc return;
558 1.1 jtc }
559 1.1 jtc addstr(b);
560 1.1 jtc }
561 1.1 jtc
562 1.1 jtc static void
563 1.33 ad getinfo(struct Info *s, enum state st)
564 1.1 jtc {
565 1.4 cgd int mib[2];
566 1.4 cgd size_t size;
567 1.1 jtc
568 1.5 thorpej dkreadstats();
569 1.1 jtc NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
570 1.1 jtc NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
571 1.11 mrg size = sizeof(s->uvmexp);
572 1.11 mrg mib[0] = CTL_VM;
573 1.34 simonb mib[1] = VM_UVMEXP2;
574 1.11 mrg if (sysctl(mib, 2, &s->uvmexp, &size, NULL, 0) < 0) {
575 1.11 mrg error("can't get uvmexp: %s\n", strerror(errno));
576 1.11 mrg memset(&s->uvmexp, 0, sizeof(s->uvmexp));
577 1.11 mrg }
578 1.1 jtc size = sizeof(s->Total);
579 1.1 jtc mib[0] = CTL_VM;
580 1.1 jtc mib[1] = VM_METER;
581 1.1 jtc if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) {
582 1.1 jtc error("Can't get kernel info: %s\n", strerror(errno));
583 1.10 lukem memset(&s->Total, 0, sizeof(s->Total));
584 1.1 jtc }
585 1.1 jtc }
586 1.1 jtc
587 1.1 jtc static void
588 1.33 ad allocinfo(struct Info *s)
589 1.1 jtc {
590 1.1 jtc
591 1.23 jwise if ((s->intrcnt = malloc(nintr * sizeof(long))) == NULL) {
592 1.23 jwise error("malloc failed");
593 1.23 jwise die(0);
594 1.23 jwise }
595 1.1 jtc }
596 1.1 jtc
597 1.1 jtc static void
598 1.33 ad copyinfo(struct Info *from, struct Info *to)
599 1.1 jtc {
600 1.1 jtc long *intrcnt;
601 1.1 jtc
602 1.5 thorpej intrcnt = to->intrcnt;
603 1.1 jtc *to = *from;
604 1.10 lukem memmove(to->intrcnt = intrcnt, from->intrcnt, nintr * sizeof (int));
605 1.1 jtc }
606 1.1 jtc
607 1.1 jtc static void
608 1.33 ad dinfo(int dn, int c)
609 1.1 jtc {
610 1.5 thorpej double words, atime;
611 1.1 jtc
612 1.1 jtc c = DISKCOL + c * 5;
613 1.5 thorpej
614 1.5 thorpej /* time busy in disk activity */
615 1.5 thorpej atime = (double)cur.dk_time[dn].tv_sec +
616 1.5 thorpej ((double)cur.dk_time[dn].tv_usec / (double)1000000);
617 1.5 thorpej
618 1.5 thorpej words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */
619 1.5 thorpej
620 1.5 thorpej putint((int)((float)cur.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5);
621 1.5 thorpej putint((int)((float)cur.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5);
622 1.5 thorpej putint((int)(words/etime + 0.5), DISKROW + 3, c, 5);
623 1.31 mycroft putfloat(atime*100.0/etime, DISKROW + 4, c, 5, 1, 1);
624 1.1 jtc }
625