2 * Copyright (c) 1983, 1989, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)vmstat.c 8.2 (Berkeley) 1/12/94
34 * $FreeBSD: src/usr.bin/systat/vmstat.c,v 1.38.2.4 2002/03/12 19:50:23 phantom Exp $
35 * $DragonFly: src/usr.bin/systat/vmstat.c,v 1.4 2003/07/12 03:09:50 dillon Exp $
39 * Cursed vmstat -- from Robert Elz.
42 #include <sys/param.h>
47 #include <sys/namei.h>
48 #include <sys/sysctl.h>
49 #include <sys/dkstat.h>
50 #include <sys/vmmeter.h>
52 #include <vm/vm_param.h>
76 struct nchstats nchstats;
86 struct statinfo cur, last, run;
93 #define nchtotal s.nchstats
94 #define oldnchtotal s1.nchstats
96 static enum state { BOOT, TIME, RUN } state = TIME;
98 static void allocinfo __P((struct Info *));
99 static void copyinfo __P((struct Info *, struct Info *));
100 static float cputime __P((int));
101 static void dinfo __P((int, int, struct statinfo *, struct statinfo *));
102 static void getinfo __P((struct Info *, enum state));
103 static void putint __P((int, int, int, int));
104 static void putfloat __P((double, int, int, int, int, int));
105 static void putlongdouble __P((long double, int, int, int, int, int));
106 static int ucount __P((void));
114 static long *intrloc;
115 static char **intrname;
116 static int nextintsrow;
117 static int extended_vm_stats;
126 ut = open(_PATH_UTMP, O_RDONLY);
145 static struct nlist namelist[] = {
148 #define X_BUFFERSPACE 1
152 #define X_INTRNAMES 3
154 #define X_EINTRNAMES 4
160 #define X_DESIREDVNODES 7
161 { "_desiredvnodes" },
162 #define X_NUMVNODES 8
164 #define X_FREEVNODES 9
166 #define X_NUMDIRTYBUFFERS 10
167 { "_numdirtybuffers" },
172 * These constants define where the major pieces are laid out
174 #define STATROW 0 /* uses 1 row and 68 cols */
176 #define MEMROW 2 /* uses 4 rows and 31 cols */
178 #define PAGEROW 2 /* uses 4 rows and 26 cols */
180 #define INTSROW 6 /* uses all rows to bottom and 17 cols */
182 #define PROCSROW 7 /* uses 2 rows and 20 cols */
184 #define GENSTATROW 7 /* uses 2 rows and 30 cols */
185 #define GENSTATCOL 20
186 #define VMSTATROW 6 /* uses 17 rows and 12 cols */
188 #define GRAPHROW 10 /* uses 3 rows and 51 cols */
190 #define NAMEIROW 14 /* uses 3 rows and 38 cols */
192 #define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */
195 #define DRIVESPACE 7 /* max # for space */
197 #define MAXDRIVES DRIVESPACE /* max # to display */
202 char *intrnamebuf, *cp;
205 if (namelist[0].n_type == 0) {
206 if (kvm_nlist(kd, namelist)) {
210 if (namelist[0].n_type == 0) {
211 error("No namelist");
216 if (num_devices = getnumdevs() < 0) {
217 warnx("%s", devstat_errbuf);
221 cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
222 last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
223 run.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
224 bzero(cur.dinfo, sizeof(struct devinfo));
225 bzero(last.dinfo, sizeof(struct devinfo));
226 bzero(run.dinfo, sizeof(struct devinfo));
228 if (dsinit(MAXDRIVES, &cur, &last, &run) != 1)
232 nintr = (namelist[X_EINTRCNT].n_value -
233 namelist[X_INTRCNT].n_value) / sizeof (long);
234 intrloc = calloc(nintr, sizeof (long));
235 intrname = calloc(nintr, sizeof (long));
236 intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
237 namelist[X_INTRNAMES].n_value);
238 if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
239 error("Out of memory\n");
249 NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
251 for (cp = intrnamebuf, i = 0; i < nintr; i++) {
253 cp += strlen(cp) + 1;
255 nextintsrow = INTSROW + 2;
271 static int d_first = -1;
274 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
277 tp = localtime(&now);
278 (void) strftime(buf, sizeof(buf),
279 d_first ? "%e %b %R" : "%b %e %R", tp);
289 mvprintw(STATROW, STATCOL + 4, "users Load");
290 mvprintw(MEMROW, MEMCOL, "Mem:KB REAL VIRTUAL");
291 mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share");
292 mvprintw(MEMROW + 2, MEMCOL, "Act");
293 mvprintw(MEMROW + 3, MEMCOL, "All");
295 mvprintw(MEMROW + 1, MEMCOL + 41, "Free");
297 mvprintw(PAGEROW, PAGECOL, " VN PAGER SWAP PAGER ");
298 mvprintw(PAGEROW + 1, PAGECOL, " in out in out ");
299 mvprintw(PAGEROW + 2, PAGECOL, "count");
300 mvprintw(PAGEROW + 3, PAGECOL, "pages");
302 mvprintw(INTSROW, INTSCOL + 3, " Interrupts");
303 mvprintw(INTSROW + 1, INTSCOL + 9, "total");
305 mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "cow");
306 mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "wire");
307 mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "act");
308 mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "inact");
309 mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "cache");
310 mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "free");
311 mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "daefr");
312 mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "prcfr");
313 mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "react");
314 mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "pdwake");
315 mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "pdpgs");
316 mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "intrn");
317 mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "buf");
318 mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "dirtybuf");
320 mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "desiredvnodes");
321 mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "numvnodes");
322 mvprintw(VMSTATROW + 17, VMSTATCOL + 10, "freevnodes");
324 mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt");
326 mvprintw(GRAPHROW, GRAPHCOL,
327 " . %%Sys . %%Intr . %%User . %%Nice . %%Idle");
328 mvprintw(PROCSROW, PROCSCOL, "Proc:r p d s w");
329 mvprintw(GRAPHROW + 1, GRAPHCOL,
330 "| | | | | | | | | | |");
332 mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache");
333 mvprintw(NAMEIROW + 1, NAMEICOL,
334 " Calls hits %% hits %%");
335 mvprintw(DISKROW, DISKCOL, "Disks");
336 mvprintw(DISKROW + 1, DISKCOL, "KB/t");
337 mvprintw(DISKROW + 2, DISKCOL, "tps");
338 mvprintw(DISKROW + 3, DISKCOL, "MB/s");
339 mvprintw(DISKROW + 4, DISKCOL, "%% busy");
341 * For now, we don't support a fourth disk statistic. So there's
342 * no point in providing a label for it. If someone can think of a
343 * fourth useful disk statistic, there is room to add it.
345 /* mvprintw(DISKROW + 4, DISKCOL, " msps"); */
347 for (i = 0; i < num_devices && j < MAXDRIVES; i++)
348 if (dev_select[i].selected) {
350 sprintf(tmpstr, "%s%d", dev_select[i].device_name,
351 dev_select[i].unit_number);
352 mvprintw(DISKROW, DISKCOL + 5 + 6 * j,
359 * room for extended VM stats
361 mvprintw(VMSTATROW + 11, VMSTATCOL - 6, "zfod");
362 mvprintw(VMSTATROW + 12, VMSTATCOL - 6, "ofod");
363 mvprintw(VMSTATROW + 13, VMSTATCOL - 6, "%%slo-z");
364 mvprintw(VMSTATROW + 14, VMSTATCOL - 6, "tfree");
365 extended_vm_stats = 1;
367 extended_vm_stats = 0;
368 mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "zfod");
371 for (i = 0; i < nintr; i++) {
374 mvprintw(intrloc[i], INTSCOL + 9, "%-10.10s", intrname[i]);
378 #define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
379 #define Q(fld) {t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;}
380 #define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
381 #define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
382 if(state == TIME) s1.nchstats.fld = t;}
383 #define PUTRATE(fld, l, c, w) \
385 putint((int)((float)s.fld/etime + 0.5), l, c, w)
388 static char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' };
389 static char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE,
398 static int failcnt = 0;
401 for(i = 0; i < CPUSTATES; i++) {
406 if (etime < 100000.0) { /* < 100ms ignore this trash */
407 if (failcnt++ >= MAXFAIL) {
409 mvprintw(2, 10, "The alternate system clock has died!");
410 mvprintw(3, 10, "Reverting to ``pigs'' display.");
423 for (i = 0; i < nintr; i++) {
424 if (s.intrcnt[i] == 0)
426 if (intrloc[i] == 0) {
427 if (nextintsrow == LINES)
429 intrloc[i] = nextintsrow++;
430 mvprintw(intrloc[i], INTSCOL + 9, "%-10.10s",
434 l = (int)((float)s.intrcnt[i]/etime + 0.5);
436 putint(l, intrloc[i], INTSCOL + 2, 6);
438 putint(inttotal, INTSROW + 1, INTSCOL + 2, 6);
439 Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss);
440 Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes); Z(ncs_neghits);
441 s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits +
442 nchtotal.ncs_miss + nchtotal.ncs_long + nchtotal.ncs_neghits;
444 s1.nchcount = s.nchcount;
448 for (c = 0; c < CPUSTATES; c++) {
452 l = (int) ((f2 + 1.0) / 2.0) - psiz;
454 f1 = 99.9; /* no room to display 100.0 */
455 putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c, 4, 1, 0);
456 move(GRAPHROW + 2, psiz);
462 putint(ucount(), STATROW, STATCOL, 3);
463 putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
464 putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
465 putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
466 mvaddstr(STATROW, STATCOL + 53, buf);
467 #define pgtokb(pg) ((pg) * vms.v_page_size / 1024)
468 putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 8);
469 putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 11, 8);
470 putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 19, 9);
471 putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 28, 9);
472 putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 8);
473 putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 11, 8);
474 putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 19, 9);
475 putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 28, 9);
476 putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 37, 8);
477 putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
478 putint(total.t_pw, PROCSROW + 1, PROCSCOL + 6, 3);
479 putint(total.t_dw, PROCSROW + 1, PROCSCOL + 9, 3);
480 putint(total.t_sl, PROCSROW + 1, PROCSCOL + 12, 3);
481 putint(total.t_sw, PROCSROW + 1, PROCSCOL + 15, 3);
482 if (extended_vm_stats == 0) {
483 PUTRATE(Vmm.v_zfod, VMSTATROW + 0, VMSTATCOL + 4, 5);
485 PUTRATE(Vmm.v_cow_faults, VMSTATROW + 1, VMSTATCOL + 3, 6);
486 putint(pgtokb(vms.v_wire_count), VMSTATROW + 2, VMSTATCOL, 9);
487 putint(pgtokb(vms.v_active_count), VMSTATROW + 3, VMSTATCOL, 9);
488 putint(pgtokb(vms.v_inactive_count), VMSTATROW + 4, VMSTATCOL, 9);
489 putint(pgtokb(vms.v_cache_count), VMSTATROW + 5, VMSTATCOL, 9);
490 putint(pgtokb(vms.v_free_count), VMSTATROW + 6, VMSTATCOL, 9);
491 PUTRATE(Vmm.v_dfree, VMSTATROW + 7, VMSTATCOL, 9);
492 PUTRATE(Vmm.v_pfree, VMSTATROW + 8, VMSTATCOL, 9);
493 PUTRATE(Vmm.v_reactivated, VMSTATROW + 9, VMSTATCOL, 9);
494 PUTRATE(Vmm.v_pdwakeups, VMSTATROW + 10, VMSTATCOL, 9);
495 PUTRATE(Vmm.v_pdpages, VMSTATROW + 11, VMSTATCOL, 9);
496 PUTRATE(Vmm.v_intrans, VMSTATROW + 12, VMSTATCOL, 9);
498 if (extended_vm_stats) {
499 PUTRATE(Vmm.v_zfod, VMSTATROW + 11, VMSTATCOL - 16, 9);
500 PUTRATE(Vmm.v_ozfod, VMSTATROW + 12, VMSTATCOL - 16, 9);
502 ((s.Vmm.v_ozfod < s.Vmm.v_zfod) ?
503 s.Vmm.v_ozfod * 100 / s.Vmm.v_zfod :
510 PUTRATE(Vmm.v_tfree, VMSTATROW + 14, VMSTATCOL - 16, 9);
513 putint(s.bufspace/1024, VMSTATROW + 13, VMSTATCOL, 9);
514 putint(s.numdirtybuffers, VMSTATROW + 14, VMSTATCOL, 9);
515 putint(s.desiredvnodes, VMSTATROW + 15, VMSTATCOL, 9);
516 putint(s.numvnodes, VMSTATROW + 16, VMSTATCOL, 9);
517 putint(s.freevnodes, VMSTATROW + 17, VMSTATCOL, 9);
518 PUTRATE(Vmm.v_vnodein, PAGEROW + 2, PAGECOL + 5, 5);
519 PUTRATE(Vmm.v_vnodeout, PAGEROW + 2, PAGECOL + 10, 5);
520 PUTRATE(Vmm.v_swapin, PAGEROW + 2, PAGECOL + 17, 5);
521 PUTRATE(Vmm.v_swapout, PAGEROW + 2, PAGECOL + 22, 5);
522 PUTRATE(Vmm.v_vnodepgsin, PAGEROW + 3, PAGECOL + 5, 5);
523 PUTRATE(Vmm.v_vnodepgsout, PAGEROW + 3, PAGECOL + 10, 5);
524 PUTRATE(Vmm.v_swappgsin, PAGEROW + 3, PAGECOL + 17, 5);
525 PUTRATE(Vmm.v_swappgsout, PAGEROW + 3, PAGECOL + 22, 5);
526 PUTRATE(Vmm.v_swtch, GENSTATROW + 1, GENSTATCOL, 5);
527 PUTRATE(Vmm.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5);
528 PUTRATE(Vmm.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5);
529 PUTRATE(Vmm.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5);
530 PUTRATE(Vmm.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5);
531 PUTRATE(Vmm.v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 5);
532 mvprintw(DISKROW, DISKCOL + 5, " ");
533 for (i = 0, c = 0; i < num_devices && c < MAXDRIVES; i++)
534 if (dev_select[i].selected) {
536 sprintf(tmpstr, "%s%d", dev_select[i].device_name,
537 dev_select[i].unit_number);
538 mvprintw(DISKROW, DISKCOL + 5 + 6 * c,
542 dinfo(i, ++c, &cur, &last);
545 dinfo(i, ++c, &cur, &run);
548 dinfo(i, ++c, &cur, NULL);
552 putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
553 putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits),
554 NAMEIROW + 2, NAMEICOL + 9, 9);
555 #define nz(x) ((x) ? (x) : 1)
556 putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) *
557 100.0 / nz(s.nchcount),
558 NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
559 putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
560 putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
561 NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1);
571 if (prefix(cmd, "run")) {
574 switch (getdevs(&run)) {
576 errx(1, "%s", devstat_errbuf);
579 num_devices = run.dinfo->numdevs;
580 generation = run.dinfo->generation;
581 retval = dscmd("refresh", NULL, MAXDRIVES, &cur);
591 if (prefix(cmd, "boot")) {
596 if (prefix(cmd, "time")) {
600 if (prefix(cmd, "zero")) {
604 switch (getdevs(&run)) {
606 errx(1, "%s", devstat_errbuf);
609 num_devices = run.dinfo->numdevs;
610 generation = run.dinfo->generation;
611 retval = dscmd("refresh",NULL, MAXDRIVES, &cur);
621 retval = dscmd(cmd, args, MAXDRIVES, &cur);
629 /* calculate number of users on the system */
633 register int nusers = 0;
637 while (read(ut, &utmp, sizeof(utmp)))
638 if (utmp.ut_name[0] != '\0')
641 lseek(ut, 0L, L_SET);
653 for (i = 0; i < CPUSTATES; i++)
657 return (s.time[indx] * 100.0 / t);
672 snprintf(b, sizeof(b), "%*d", w, n);
682 putfloat(f, l, c, w, d, nz)
689 if (nz && f == 0.0) {
694 snprintf(b, sizeof(b), "%*.*f", w, d, f);
696 snprintf(b, sizeof(b), "%*.0f", w, f);
706 putlongdouble(f, l, c, w, d, nz)
713 if (nz && f == 0.0) {
718 sprintf(b, "%*.*Lf", w, d, f);
720 sprintf(b, "%*.0Lf", w, f);
734 struct devinfo *tmp_dinfo;
737 int vms_size = sizeof(s->Vms);
738 int vmm_size = sizeof(s->Vmm);
740 if (sysctlbyname("vm.vmstats", &s->Vms, &vms_size, NULL, 0)) {
741 perror("sysctlbyname: vm.vmstats");
744 if (sysctlbyname("vm.vmmeter", &s->Vmm, &vmm_size, NULL, 0)) {
745 perror("sysctlbyname: vm.vmstats");
749 NREAD(X_CPTIME, s->time, sizeof s->time);
750 NREAD(X_CPTIME, cur.cp_time, sizeof(cur.cp_time));
751 NREAD(X_BUFFERSPACE, &s->bufspace, sizeof(s->bufspace));
752 NREAD(X_DESIREDVNODES, &s->desiredvnodes, sizeof(s->desiredvnodes));
753 NREAD(X_NUMVNODES, &s->numvnodes, LONG);
754 NREAD(X_FREEVNODES, &s->freevnodes, LONG);
755 NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
756 NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
757 NREAD(X_NUMDIRTYBUFFERS, &s->numdirtybuffers, sizeof(s->numdirtybuffers));
758 size = sizeof(s->Total);
759 if (sysctlbyname("vm.vmtotal", &s->Total, &size, NULL, 0) < 0) {
760 error("Can't get kernel info: %s\n", strerror(errno));
761 bzero(&s->Total, sizeof(s->Total));
764 if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0)
767 tmp_dinfo = last.dinfo;
768 last.dinfo = cur.dinfo;
769 cur.dinfo = tmp_dinfo;
771 last.busy_time = cur.busy_time;
772 switch (getdevs(&cur)) {
774 errx(1, "%s", devstat_errbuf);
777 num_devices = cur.dinfo->numdevs;
778 generation = cur.dinfo->generation;
779 cmdkre("refresh", NULL);
791 s->intrcnt = (long *) calloc(nintr, sizeof(long));
792 if (s->intrcnt == NULL)
793 errx(2, "out of memory");
798 register struct Info *from, *to;
803 * time, wds, seek, and xfer are malloc'd so we have to
804 * save the pointers before the structure copy and then
807 intrcnt = to->intrcnt;
810 bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
814 dinfo(dn, c, now, then)
816 struct statinfo *now, *then;
818 long double transfers_per_second;
819 long double kb_per_transfer, mb_per_second;
820 long double elapsed_time, device_busy;
823 di = dev_select[dn].position;
825 elapsed_time = compute_etime(now->busy_time, then ?
827 now->dinfo->devices[di].dev_creation_time);
829 device_busy = compute_etime(now->dinfo->devices[di].busy_time, then ?
830 then->dinfo->devices[di].busy_time :
831 now->dinfo->devices[di].dev_creation_time);
833 if (compute_stats(&now->dinfo->devices[di], then ?
834 &then->dinfo->devices[di] : NULL, elapsed_time,
836 &kb_per_transfer, &transfers_per_second,
837 &mb_per_second, NULL, NULL) != 0)
838 errx(1, "%s", devstat_errbuf);
840 if ((device_busy == 0) && (transfers_per_second > 5))
841 /* the device has been 100% busy, fake it because
842 * as long as the device is 100% busy the busy_time
843 * field in the devstat struct is not updated */
844 device_busy = elapsed_time;
845 if (device_busy > elapsed_time)
846 /* this normally happens after one or more periods
847 * where the device has been 100% busy, correct it */
848 device_busy = elapsed_time;
851 putlongdouble(kb_per_transfer, DISKROW + 1, c, 5, 2, 0);
852 putlongdouble(transfers_per_second, DISKROW + 2, c, 5, 0, 0);
853 putlongdouble(mb_per_second, DISKROW + 3, c, 5, 2, 0);
854 putlongdouble(device_busy * 100 / elapsed_time, DISKROW + 4, c, 5, 0, 0);