vmstat.c revision 155656
133965Sjdp/*- 2218822Sdim * Copyright (c) 1983, 1989, 1992, 1993 3218822Sdim * The Regents of the University of California. All rights reserved. 460484Sobrien * 533965Sjdp * Redistribution and use in source and binary forms, with or without 633965Sjdp * modification, are permitted provided that the following conditions 733965Sjdp * are met: 833965Sjdp * 1. Redistributions of source code must retain the above copyright 933965Sjdp * notice, this list of conditions and the following disclaimer. 1033965Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1133965Sjdp * notice, this list of conditions and the following disclaimer in the 1233965Sjdp * documentation and/or other materials provided with the distribution. 1333965Sjdp * 3. All advertising materials mentioning features or use of this software 1433965Sjdp * must display the following acknowledgement: 1533965Sjdp * This product includes software developed by the University of 1633965Sjdp * California, Berkeley and its contributors. 1733965Sjdp * 4. Neither the name of the University nor the names of its contributors 1833965Sjdp * may be used to endorse or promote products derived from this software 1933965Sjdp * without specific prior written permission. 2033965Sjdp * 21218822Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22218822Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2333965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2433965Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2560484Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2633965Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2733965Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2860484Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2933965Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3033965Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3133965Sjdp * SUCH DAMAGE. 3233965Sjdp */ 3333965Sjdp 3489857Sobrien#include <sys/cdefs.h> 3533965Sjdp 3633965Sjdp__FBSDID("$FreeBSD: head/usr.bin/systat/vmstat.c 155656 2006-02-14 05:37:25Z bde $"); 3789857Sobrien 3833965Sjdp#ifdef lint 3933965Sjdpstatic const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; 4033965Sjdp#endif 4133965Sjdp 4233965Sjdp/* 4333965Sjdp * Cursed vmstat -- from Robert Elz. 4433965Sjdp */ 4533965Sjdp 4633965Sjdp#include <sys/param.h> 4733965Sjdp#include <sys/stat.h> 4833965Sjdp#include <sys/time.h> 4933965Sjdp#include <sys/proc.h> 5033965Sjdp#include <sys/uio.h> 5133965Sjdp#include <sys/namei.h> 5233965Sjdp#include <sys/resource.h> 5333965Sjdp#include <sys/sysctl.h> 5433965Sjdp#include <sys/vmmeter.h> 5533965Sjdp 5633965Sjdp#include <vm/vm_param.h> 57218822Sdim 58218822Sdim#include <ctype.h> 59218822Sdim#include <err.h> 60218822Sdim#include <errno.h> 6133965Sjdp#include <langinfo.h> 62218822Sdim#include <nlist.h> 63218822Sdim#include <paths.h> 64218822Sdim#include <signal.h> 65218822Sdim#include <stdlib.h> 66218822Sdim#include <string.h> 67218822Sdim#include <time.h> 68218822Sdim#include <unistd.h> 6933965Sjdp#include <utmp.h> 70218822Sdim#include <devstat.h> 71218822Sdim#include "systat.h" 72218822Sdim#include "extern.h" 73218822Sdim#include "devs.h" 74218822Sdim 75218822Sdimstatic struct Info { 76218822Sdim long time[CPUSTATES]; 77218822Sdim u_int v_swtch; /* context switches */ 7833965Sjdp u_int v_trap; /* calls to trap */ 79218822Sdim u_int v_syscall; /* calls to syscall() */ 80218822Sdim u_int v_intr; /* device interrupts */ 81218822Sdim u_int v_soft; /* software interrupts */ 82218822Sdim /* 83218822Sdim * Virtual memory activity. 84218822Sdim */ 85218822Sdim u_int v_vm_faults; /* number of address memory faults */ 86218822Sdim u_int v_cow_faults; /* number of copy-on-writes */ 87218822Sdim u_int v_zfod; /* pages zero filled on demand */ 88218822Sdim u_int v_ozfod; /* optimized zero fill pages */ 89218822Sdim u_int v_swapin; /* swap pager pageins */ 90218822Sdim u_int v_swapout; /* swap pager pageouts */ 91218822Sdim u_int v_swappgsin; /* swap pager pages paged in */ 92218822Sdim u_int v_swappgsout; /* swap pager pages paged out */ 93218822Sdim u_int v_vnodein; /* vnode pager pageins */ 94218822Sdim u_int v_vnodeout; /* vnode pager pageouts */ 95218822Sdim u_int v_vnodepgsin; /* vnode_pager pages paged in */ 96218822Sdim u_int v_vnodepgsout; /* vnode pager pages paged out */ 97218822Sdim u_int v_intrans; /* intransit blocking page faults */ 98218822Sdim u_int v_reactivated; /* number of pages reactivated from free list */ 99218822Sdim u_int v_pdwakeups; /* number of times daemon has awaken from sleep */ 100218822Sdim u_int v_pdpages; /* number of pages analyzed by daemon */ 101218822Sdim 102218822Sdim u_int v_dfree; /* pages freed by daemon */ 103218822Sdim u_int v_pfree; /* pages freed by exiting processes */ 104218822Sdim u_int v_tfree; /* total pages freed */ 105218822Sdim /* 106218822Sdim * Distribution of page usages. 107218822Sdim */ 108218822Sdim u_int v_page_size; /* page size in bytes */ 109218822Sdim u_int v_free_count; /* number of pages free */ 110218822Sdim u_int v_wire_count; /* number of pages wired down */ 111218822Sdim u_int v_active_count; /* number of pages active */ 112218822Sdim u_int v_inactive_count; /* number of pages inactive */ 113218822Sdim u_int v_cache_count; /* number of pages on buffer cache queue */ 114218822Sdim struct vmtotal Total; 115218822Sdim struct nchstats nchstats; 116218822Sdim long nchcount; 117218822Sdim long *intrcnt; 118218822Sdim int bufspace; 119218822Sdim int desiredvnodes; 120218822Sdim long numvnodes; 121218822Sdim long freevnodes; 122218822Sdim int numdirtybuffers; 123218822Sdim} s, s1, s2, z; 124218822Sdim 125218822Sdimstruct statinfo cur, last, run; 126218822Sdim 127218822Sdim#define total s.Total 128218822Sdim#define nchtotal s.nchstats 129218822Sdim#define oldnchtotal s1.nchstats 130218822Sdim 131218822Sdimstatic enum state { BOOT, TIME, RUN } state = TIME; 132218822Sdim 133218822Sdimstatic void allocinfo(struct Info *); 134218822Sdimstatic void copyinfo(struct Info *, struct Info *); 135218822Sdimstatic float cputime(int); 136218822Sdimstatic void dinfo(int, int, struct statinfo *, struct statinfo *); 137218822Sdimstatic void getinfo(struct Info *); 138218822Sdimstatic void putint(int, int, int, int); 139218822Sdimstatic void putfloat(double, int, int, int, int, int); 140218822Sdimstatic void putlongdouble(long double, int, int, int, int, int); 141218822Sdimstatic int ucount(void); 142218822Sdim 143218822Sdimstatic int ncpu; 144218822Sdimstatic int ut; 145218822Sdimstatic char buf[26]; 146218822Sdimstatic time_t t; 147218822Sdimstatic double etime; 148218822Sdimstatic int nintr; 149218822Sdimstatic long *intrloc; 150218822Sdimstatic char **intrname; 151218822Sdimstatic int nextintsrow; 152218822Sdimstatic int extended_vm_stats; 153218822Sdim 154218822Sdimstruct utmp utmp; 155218822Sdim 156218822Sdim 157218822SdimWINDOW * 158218822Sdimopenkre() 159218822Sdim{ 160218822Sdim 161218822Sdim ut = open(_PATH_UTMP, O_RDONLY); 162218822Sdim if (ut < 0) 163218822Sdim error("No utmp"); 164218822Sdim return (stdscr); 165218822Sdim} 166218822Sdim 167218822Sdimvoid 168218822Sdimclosekre(w) 169218822Sdim WINDOW *w; 170218822Sdim{ 171218822Sdim 172218822Sdim (void) close(ut); 173218822Sdim if (w == NULL) 174218822Sdim return; 175218822Sdim wclear(w); 176218822Sdim wrefresh(w); 177218822Sdim} 178218822Sdim 179218822Sdim/* 180218822Sdim * These constants define where the major pieces are laid out 181218822Sdim */ 182218822Sdim#define STATROW 0 /* uses 1 row and 68 cols */ 183218822Sdim#define STATCOL 2 184218822Sdim#define MEMROW 2 /* uses 4 rows and 31 cols */ 185218822Sdim#define MEMCOL 0 186218822Sdim#define PAGEROW 2 /* uses 4 rows and 26 cols */ 187218822Sdim#define PAGECOL 46 188218822Sdim#define INTSROW 6 /* uses all rows to bottom and 17 cols */ 189218822Sdim#define INTSCOL 63 190218822Sdim#define PROCSROW 7 /* uses 2 rows and 20 cols */ 191218822Sdim#define PROCSCOL 0 192218822Sdim#define GENSTATROW 7 /* uses 2 rows and 30 cols */ 193218822Sdim#define GENSTATCOL 20 194218822Sdim#define VMSTATROW 6 /* uses 17 rows and 12 cols */ 195218822Sdim#define VMSTATCOL 48 19633965Sjdp#define GRAPHROW 10 /* uses 3 rows and 51 cols */ 197218822Sdim#define GRAPHCOL 0 19833965Sjdp#define NAMEIROW 14 /* uses 3 rows and 38 cols */ 19933965Sjdp#define NAMEICOL 0 20033965Sjdp#define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */ 20133965Sjdp#define DISKCOL 0 20233965Sjdp 20333965Sjdp#define DRIVESPACE 7 /* max # for space */ 20460484Sobrien 20533965Sjdp#define MAXDRIVES DRIVESPACE /* max # to display */ 206218822Sdim 20733965Sjdpint 20833965Sjdpinitkre() 20933965Sjdp{ 21033965Sjdp char *intrnamebuf, *cp; 21133965Sjdp int i; 21233965Sjdp size_t sz; 21333965Sjdp 214218822Sdim if ((num_devices = devstat_getnumdevs(NULL)) < 0) { 21533965Sjdp warnx("%s", devstat_errbuf); 21633965Sjdp return(0); 21733965Sjdp } 21833965Sjdp 21933965Sjdp cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 22033965Sjdp last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 22133965Sjdp run.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 222218822Sdim bzero(cur.dinfo, sizeof(struct devinfo)); 22333965Sjdp bzero(last.dinfo, sizeof(struct devinfo)); 22433965Sjdp bzero(run.dinfo, sizeof(struct devinfo)); 22533965Sjdp 22633965Sjdp if (dsinit(MAXDRIVES, &cur, &last, &run) != 1) 22733965Sjdp return(0); 22833965Sjdp 22933965Sjdp if (nintr == 0) { 230218822Sdim if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) { 23133965Sjdp error("sysctl(hw.intrcnt...) failed: %s", 23233965Sjdp strerror(errno)); 23333965Sjdp return (0); 234218822Sdim } 23533965Sjdp nintr = sz / sizeof(u_long); 23633965Sjdp intrloc = calloc(nintr, sizeof (long)); 23733965Sjdp intrname = calloc(nintr, sizeof (char *)); 23833965Sjdp intrnamebuf = sysctl_dynread("hw.intrnames", NULL); 239218822Sdim if (intrnamebuf == NULL || intrname == NULL || 24033965Sjdp intrloc == NULL) { 24133965Sjdp error("Out of memory"); 24233965Sjdp if (intrnamebuf) 243218822Sdim free(intrnamebuf); 24433965Sjdp if (intrname) 24533965Sjdp free(intrname); 24633965Sjdp if (intrloc) 247218822Sdim free(intrloc); 24833965Sjdp nintr = 0; 24933965Sjdp return(0); 25033965Sjdp } 25133965Sjdp for (cp = intrnamebuf, i = 0; i < nintr; i++) { 252218822Sdim intrname[i] = cp; 25333965Sjdp cp += strlen(cp) + 1; 25433965Sjdp } 25533965Sjdp nextintsrow = INTSROW + 2; 25633965Sjdp allocinfo(&s); 257218822Sdim allocinfo(&s1); 25833965Sjdp allocinfo(&s2); 25933965Sjdp allocinfo(&z); 26033965Sjdp } 26133965Sjdp getinfo(&s2); 262218822Sdim copyinfo(&s2, &s1); 26333965Sjdp return(1); 26433965Sjdp} 26533965Sjdp 26633965Sjdpvoid 267218822Sdimfetchkre() 26833965Sjdp{ 26933965Sjdp time_t now; 27033965Sjdp struct tm *tp; 27133965Sjdp static int d_first = -1; 272218822Sdim 27333965Sjdp if (d_first < 0) 27433965Sjdp d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); 27533965Sjdp 276218822Sdim time(&now); 27733965Sjdp tp = localtime(&now); 27833965Sjdp (void) strftime(buf, sizeof(buf), 27933965Sjdp d_first ? "%e %b %R" : "%b %e %R", tp); 28033965Sjdp getinfo(&s); 28133965Sjdp} 28233965Sjdp 28333965Sjdpvoid 28433965Sjdplabelkre() 285218822Sdim{ 28633965Sjdp int i, j; 28733965Sjdp 28833965Sjdp clear(); 28933965Sjdp mvprintw(STATROW, STATCOL + 4, "users Load"); 29033965Sjdp mvprintw(MEMROW, MEMCOL, "Mem:KB REAL VIRTUAL"); 291218822Sdim mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); 29233965Sjdp mvprintw(MEMROW + 2, MEMCOL, "Act"); 29333965Sjdp mvprintw(MEMROW + 3, MEMCOL, "All"); 29433965Sjdp 29533965Sjdp mvprintw(MEMROW + 1, MEMCOL + 41, "Free"); 296218822Sdim 29733965Sjdp mvprintw(PAGEROW, PAGECOL, " VN PAGER SWAP PAGER "); 29860484Sobrien mvprintw(PAGEROW + 1, PAGECOL, " in out in out "); 29933965Sjdp mvprintw(PAGEROW + 2, PAGECOL, "count"); 30033965Sjdp mvprintw(PAGEROW + 3, PAGECOL, "pages"); 301218822Sdim 30233965Sjdp mvprintw(INTSROW, INTSCOL + 2, "Interrupts"); 30333965Sjdp mvprintw(INTSROW + 1, INTSCOL + 7, "total"); 30433965Sjdp 30533965Sjdp mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "cow"); 30633965Sjdp mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "wire"); 30733965Sjdp mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "act"); 30833965Sjdp mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "inact"); 30933965Sjdp mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "cache"); 310218822Sdim mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "free"); 31133965Sjdp mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "daefr"); 31233965Sjdp mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "prcfr"); 31333965Sjdp mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "react"); 314218822Sdim mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "pdwake"); 31533965Sjdp mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "pdpgs"); 31633965Sjdp mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "intrn"); 31760484Sobrien mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "buf"); 31860484Sobrien mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "dirtybuf"); 319218822Sdim 32060484Sobrien mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "desiredvnodes"); 32160484Sobrien mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "numvnodes"); 32260484Sobrien mvprintw(VMSTATROW + 17, VMSTATCOL + 10, "freevnodes"); 323218822Sdim 32460484Sobrien mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); 32560484Sobrien 32660484Sobrien mvprintw(GRAPHROW, GRAPHCOL, 32760484Sobrien " . %%Sys . %%Intr . %%User . %%Nice . %%Idle"); 32833965Sjdp mvprintw(PROCSROW, PROCSCOL, "Proc:r p d s w"); 32933965Sjdp mvprintw(GRAPHROW + 1, GRAPHCOL, 33060484Sobrien "| | | | | | | | | | |"); 33133965Sjdp 33233965Sjdp mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache"); 333218822Sdim mvprintw(NAMEIROW + 1, NAMEICOL, 33433965Sjdp " Calls hits %% hits %%"); 335218822Sdim mvprintw(DISKROW, DISKCOL, "Disks"); 33633965Sjdp mvprintw(DISKROW + 1, DISKCOL, "KB/t"); 33733965Sjdp mvprintw(DISKROW + 2, DISKCOL, "tps"); 33833965Sjdp mvprintw(DISKROW + 3, DISKCOL, "MB/s"); 339218822Sdim mvprintw(DISKROW + 4, DISKCOL, "%% busy"); 34033965Sjdp /* 34133965Sjdp * For now, we don't support a fourth disk statistic. So there's 34233965Sjdp * no point in providing a label for it. If someone can think of a 34333965Sjdp * fourth useful disk statistic, there is room to add it. 344218822Sdim */ 34533965Sjdp /* mvprintw(DISKROW + 4, DISKCOL, " msps"); */ 34633965Sjdp j = 0; 34733965Sjdp for (i = 0; i < num_devices && j < MAXDRIVES; i++) 34833965Sjdp if (dev_select[i].selected) { 349218822Sdim char tmpstr[80]; 35033965Sjdp sprintf(tmpstr, "%s%d", dev_select[i].device_name, 35133965Sjdp dev_select[i].unit_number); 35233965Sjdp mvprintw(DISKROW, DISKCOL + 5 + 6 * j, 35333965Sjdp " %5.5s", tmpstr); 354218822Sdim j++; 35533965Sjdp } 35633965Sjdp 35733965Sjdp if (j <= 4) { 35833965Sjdp /* 359218822Sdim * room for extended VM stats 36033965Sjdp */ 36133965Sjdp mvprintw(VMSTATROW + 11, VMSTATCOL - 6, "zfod"); 36233965Sjdp mvprintw(VMSTATROW + 12, VMSTATCOL - 6, "ofod"); 36333965Sjdp mvprintw(VMSTATROW + 13, VMSTATCOL - 6, "%%slo-z"); 36433965Sjdp mvprintw(VMSTATROW + 14, VMSTATCOL - 6, "tfree"); 365218822Sdim extended_vm_stats = 1; 36633965Sjdp } else { 36733965Sjdp extended_vm_stats = 0; 36833965Sjdp mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "zfod"); 36933965Sjdp } 37033965Sjdp 37133965Sjdp for (i = 0; i < nintr; i++) { 372218822Sdim if (intrloc[i] == 0) 37333965Sjdp continue; 37433965Sjdp mvprintw(intrloc[i], INTSCOL + 7, "%-10.10s", intrname[i]); 37533965Sjdp } 37633965Sjdp} 377218822Sdim 37833965Sjdp#define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;} 37933965Sjdp#define Q(fld) {t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;} 38033965Sjdp#define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;} 38133965Sjdp#define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \ 382218822Sdim if(state == TIME) s1.nchstats.fld = t;} 38333965Sjdp#define PUTRATE(fld, l, c, w) \ 38433965Sjdp Y(fld); \ 38533965Sjdp putint((int)((float)s.fld/etime + 0.5), l, c, w) 38633965Sjdp#define MAXFAIL 5 38733965Sjdp 38833965Sjdpstatic char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' }; 38933965Sjdpstatic char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE, 39033965Sjdp CP_IDLE }; 39160484Sobrien 39260484Sobrienvoid 39360484Sobrienshowkre() 39460484Sobrien{ 39560484Sobrien float f1, f2; 39660484Sobrien int psiz, inttotal; 39760484Sobrien int i, j, k, l, lc; 39860484Sobrien static int failcnt = 0; 39933965Sjdp char intrbuffer[10]; 40033965Sjdp 40133965Sjdp etime = 0; 40233965Sjdp for(i = 0; i < CPUSTATES; i++) { 40360484Sobrien X(time); 40433965Sjdp Q(cp_time); 40533965Sjdp etime += s.time[i]; 40633965Sjdp } 40733965Sjdp if (etime < 5.0) { /* < 5 ticks - ignore this trash */ 408218822Sdim if (failcnt++ >= MAXFAIL) { 40933965Sjdp clear(); 41033965Sjdp mvprintw(2, 10, "The alternate system clock has died!"); 41133965Sjdp mvprintw(3, 10, "Reverting to ``pigs'' display."); 41233965Sjdp move(CMDLINE, 0); 41333965Sjdp refresh(); 41433965Sjdp failcnt = 0; 41533965Sjdp sleep(5); 41633965Sjdp command("pigs"); 41733965Sjdp } 41833965Sjdp return; 41933965Sjdp } 42033965Sjdp failcnt = 0; 42133965Sjdp etime /= hertz; 42233965Sjdp etime /= ncpu; 42333965Sjdp inttotal = 0; 42460484Sobrien for (i = 0; i < nintr; i++) { 42533965Sjdp if (s.intrcnt[i] == 0) 42633965Sjdp continue; 42733965Sjdp if (intrloc[i] == 0) { 42833965Sjdp if (nextintsrow == LINES) 42933965Sjdp continue; 43033965Sjdp intrloc[i] = nextintsrow++; 43133965Sjdp k = 0; 43233965Sjdp for (j = 0; j < (int)sizeof(intrbuffer); j++) { 43333965Sjdp if (strncmp(&intrname[i][j], "irq", 3) == 0) 43433965Sjdp j += 3; 43533965Sjdp intrbuffer[k++] = intrname[i][j]; 43633965Sjdp } 43733965Sjdp intrbuffer[k] = '\0'; 43833965Sjdp mvprintw(intrloc[i], INTSCOL + 7, "%-10.10s", 43933965Sjdp intrbuffer); 44033965Sjdp } 44133965Sjdp X(intrcnt); 44233965Sjdp l = (int)((float)s.intrcnt[i]/etime + 0.5); 44333965Sjdp inttotal += l; 44433965Sjdp putint(l, intrloc[i], INTSCOL, 6); 44533965Sjdp } 44633965Sjdp putint(inttotal, INTSROW + 1, INTSCOL, 6); 44733965Sjdp Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss); 44833965Sjdp Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes); Z(ncs_neghits); 44933965Sjdp s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits + 45033965Sjdp nchtotal.ncs_miss + nchtotal.ncs_long + nchtotal.ncs_neghits; 45133965Sjdp if (state == TIME) 45233965Sjdp s1.nchcount = s.nchcount; 45333965Sjdp 45433965Sjdp psiz = 0; 45533965Sjdp f2 = 0.0; 45633965Sjdp for (lc = 0; lc < CPUSTATES; lc++) { 45733965Sjdp i = cpuorder[lc]; 45833965Sjdp f1 = cputime(i); 45933965Sjdp f2 += f1; 46033965Sjdp l = (int) ((f2 + 1.0) / 2.0) - psiz; 46133965Sjdp if (f1 > 99.9) 46233965Sjdp f1 = 99.9; /* no room to display 100.0 */ 46333965Sjdp putfloat(f1, GRAPHROW, GRAPHCOL + 10 * lc, 4, 1, 0); 46433965Sjdp move(GRAPHROW + 2, psiz); 46533965Sjdp psiz += l; 46633965Sjdp while (l-- > 0) 46733965Sjdp addch(cpuchar[lc]); 468218822Sdim } 46933965Sjdp 470218822Sdim putint(ucount(), STATROW, STATCOL, 3); 471218822Sdim putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0); 47233965Sjdp putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); 47333965Sjdp putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); 47433965Sjdp mvaddstr(STATROW, STATCOL + 53, buf); 475130561Sobrien#define pgtokb(pg) ((pg) * (s.v_page_size / 1024)) 47633965Sjdp putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 8); 47733965Sjdp putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 11, 8); 47833965Sjdp putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 19, 9); 479130561Sobrien putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 28, 9); 480130561Sobrien putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 8); 481130561Sobrien putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 11, 8); 48233965Sjdp putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 19, 9); 48333965Sjdp putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 28, 9); 48433965Sjdp putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 37, 8); 48591041Sobrien putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3); 48633965Sjdp putint(total.t_pw, PROCSROW + 1, PROCSCOL + 6, 3); 48791041Sobrien putint(total.t_dw, PROCSROW + 1, PROCSCOL + 9, 3); 48833965Sjdp putint(total.t_sl, PROCSROW + 1, PROCSCOL + 12, 3); 48933965Sjdp putint(total.t_sw, PROCSROW + 1, PROCSCOL + 15, 3); 49089857Sobrien if (extended_vm_stats == 0) { 49189857Sobrien PUTRATE(v_zfod, VMSTATROW + 0, VMSTATCOL + 4, 5); 49233965Sjdp } 49333965Sjdp PUTRATE(v_cow_faults, VMSTATROW + 1, VMSTATCOL + 3, 6); 49433965Sjdp putint(pgtokb(s.v_wire_count), VMSTATROW + 2, VMSTATCOL, 9); 49533965Sjdp putint(pgtokb(s.v_active_count), VMSTATROW + 3, VMSTATCOL, 9); 49633965Sjdp putint(pgtokb(s.v_inactive_count), VMSTATROW + 4, VMSTATCOL, 9); 49733965Sjdp putint(pgtokb(s.v_cache_count), VMSTATROW + 5, VMSTATCOL, 9); 49833965Sjdp putint(pgtokb(s.v_free_count), VMSTATROW + 6, VMSTATCOL, 9); 49933965Sjdp PUTRATE(v_dfree, VMSTATROW + 7, VMSTATCOL, 9); 50033965Sjdp PUTRATE(v_pfree, VMSTATROW + 8, VMSTATCOL, 9); 50133965Sjdp PUTRATE(v_reactivated, VMSTATROW + 9, VMSTATCOL, 9); 50233965Sjdp PUTRATE(v_pdwakeups, VMSTATROW + 10, VMSTATCOL, 9); 50333965Sjdp PUTRATE(v_pdpages, VMSTATROW + 11, VMSTATCOL, 9); 50433965Sjdp PUTRATE(v_intrans, VMSTATROW + 12, VMSTATCOL, 9); 50533965Sjdp 50633965Sjdp if (extended_vm_stats) { 50733965Sjdp PUTRATE(v_zfod, VMSTATROW + 11, VMSTATCOL - 16, 9); 50833965Sjdp PUTRATE(v_ozfod, VMSTATROW + 12, VMSTATCOL - 16, 9); 50933965Sjdp putint( 51033965Sjdp ((s.v_ozfod < s.v_zfod) ? 51133965Sjdp s.v_ozfod * 100 / s.v_zfod : 51233965Sjdp 0 51333965Sjdp ), 51433965Sjdp VMSTATROW + 13, 51533965Sjdp VMSTATCOL - 16, 51633965Sjdp 9 51733965Sjdp ); 51833965Sjdp PUTRATE(v_tfree, VMSTATROW + 14, VMSTATCOL - 16, 9); 51933965Sjdp } 52033965Sjdp 52133965Sjdp putint(s.bufspace/1024, VMSTATROW + 13, VMSTATCOL, 9); 52233965Sjdp putint(s.numdirtybuffers, VMSTATROW + 14, VMSTATCOL, 9); 52333965Sjdp putint(s.desiredvnodes, VMSTATROW + 15, VMSTATCOL, 9); 52433965Sjdp putint(s.numvnodes, VMSTATROW + 16, VMSTATCOL, 9); 52533965Sjdp putint(s.freevnodes, VMSTATROW + 17, VMSTATCOL, 9); 52633965Sjdp PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 5, 5); 52733965Sjdp PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 10, 5); 52833965Sjdp PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 17, 5); 52933965Sjdp PUTRATE(v_swapout, PAGEROW + 2, PAGECOL + 22, 5); 53033965Sjdp PUTRATE(v_vnodepgsin, PAGEROW + 3, PAGECOL + 5, 5); 53133965Sjdp PUTRATE(v_vnodepgsout, PAGEROW + 3, PAGECOL + 10, 5); 53233965Sjdp PUTRATE(v_swappgsin, PAGEROW + 3, PAGECOL + 17, 5); 53333965Sjdp PUTRATE(v_swappgsout, PAGEROW + 3, PAGECOL + 22, 5); 53433965Sjdp PUTRATE(v_swtch, GENSTATROW + 1, GENSTATCOL, 5); 53533965Sjdp PUTRATE(v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5); 53633965Sjdp PUTRATE(v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5); 53733965Sjdp PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5); 53833965Sjdp PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5); 53933965Sjdp PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 5); 54033965Sjdp mvprintw(DISKROW, DISKCOL + 5, " "); 54133965Sjdp for (i = 0, lc = 0; i < num_devices && lc < MAXDRIVES; i++) 54233965Sjdp if (dev_select[i].selected) { 54333965Sjdp char tmpstr[80]; 54433965Sjdp sprintf(tmpstr, "%s%d", dev_select[i].device_name, 54533965Sjdp dev_select[i].unit_number); 54633965Sjdp mvprintw(DISKROW, DISKCOL + 5 + 6 * lc, 54733965Sjdp " %5.5s", tmpstr); 54833965Sjdp switch(state) { 54933965Sjdp case TIME: 55033965Sjdp dinfo(i, ++lc, &cur, &last); 55133965Sjdp break; 55233965Sjdp case RUN: 55333965Sjdp dinfo(i, ++lc, &cur, &run); 55433965Sjdp break; 55560484Sobrien case BOOT: 55633965Sjdp dinfo(i, ++lc, &cur, NULL); 55733965Sjdp break; 55833965Sjdp } 55933965Sjdp } 56033965Sjdp putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); 56133965Sjdp putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), 56233965Sjdp NAMEIROW + 2, NAMEICOL + 9, 9); 56333965Sjdp#define nz(x) ((x) ? (x) : 1) 56433965Sjdp putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) * 56533965Sjdp 100.0 / nz(s.nchcount), 56633965Sjdp NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); 56733965Sjdp putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9); 56860484Sobrien putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), 56933965Sjdp NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); 57033965Sjdp#undef nz 57133965Sjdp} 57233965Sjdp 57333965Sjdpint 57433965Sjdpcmdkre(cmd, args) 57533965Sjdp const char *cmd, *args; 57633965Sjdp{ 57733965Sjdp int retval; 57833965Sjdp 57933965Sjdp if (prefix(cmd, "run")) { 58033965Sjdp retval = 1; 58133965Sjdp copyinfo(&s2, &s1); 58233965Sjdp switch (devstat_getdevs(NULL, &run)) { 58333965Sjdp case -1: 58433965Sjdp errx(1, "%s", devstat_errbuf); 58533965Sjdp break; 58633965Sjdp case 1: 58733965Sjdp num_devices = run.dinfo->numdevs; 58833965Sjdp generation = run.dinfo->generation; 58933965Sjdp retval = dscmd("refresh", NULL, MAXDRIVES, &cur); 59033965Sjdp if (retval == 2) 59133965Sjdp labelkre(); 59233965Sjdp break; 59333965Sjdp default: 59433965Sjdp break; 59533965Sjdp } 59633965Sjdp state = RUN; 59733965Sjdp return (retval); 59833965Sjdp } 59933965Sjdp if (prefix(cmd, "boot")) { 60033965Sjdp state = BOOT; 60133965Sjdp copyinfo(&z, &s1); 60233965Sjdp return (1); 60333965Sjdp } 60433965Sjdp if (prefix(cmd, "time")) { 60533965Sjdp state = TIME; 60633965Sjdp return (1); 60733965Sjdp } 60833965Sjdp if (prefix(cmd, "zero")) { 60933965Sjdp retval = 1; 61033965Sjdp if (state == RUN) { 61133965Sjdp getinfo(&s1); 61233965Sjdp switch (devstat_getdevs(NULL, &run)) { 61333965Sjdp case -1: 61433965Sjdp errx(1, "%s", devstat_errbuf); 61533965Sjdp break; 61633965Sjdp case 1: 61733965Sjdp num_devices = run.dinfo->numdevs; 61833965Sjdp generation = run.dinfo->generation; 61933965Sjdp retval = dscmd("refresh",NULL, MAXDRIVES, &cur); 62033965Sjdp if (retval == 2) 62133965Sjdp labelkre(); 62233965Sjdp break; 62333965Sjdp default: 62433965Sjdp break; 62533965Sjdp } 62633965Sjdp } 62733965Sjdp return (retval); 62833965Sjdp } 62933965Sjdp retval = dscmd(cmd, args, MAXDRIVES, &cur); 63033965Sjdp 63133965Sjdp if (retval == 2) 63233965Sjdp labelkre(); 63333965Sjdp 63433965Sjdp return(retval); 63533965Sjdp} 63633965Sjdp 63733965Sjdp/* calculate number of users on the system */ 63833965Sjdpstatic int 63933965Sjdpucount() 64033965Sjdp{ 64133965Sjdp int nusers = 0; 64233965Sjdp 64333965Sjdp if (ut < 0) 64433965Sjdp return (0); 64533965Sjdp while (read(ut, &utmp, sizeof(utmp))) 64633965Sjdp if (utmp.ut_name[0] != '\0') 64733965Sjdp nusers++; 64833965Sjdp 64933965Sjdp lseek(ut, 0L, L_SET); 65033965Sjdp return (nusers); 65133965Sjdp} 65233965Sjdp 65333965Sjdpstatic float 65433965Sjdpcputime(indx) 65533965Sjdp int indx; 65633965Sjdp{ 65733965Sjdp double lt; 65833965Sjdp int i; 65933965Sjdp 66033965Sjdp lt = 0; 66133965Sjdp for (i = 0; i < CPUSTATES; i++) 66233965Sjdp lt += s.time[i]; 66333965Sjdp if (lt == 0.0) 66460484Sobrien lt = 1.0; 66560484Sobrien return (s.time[indx] * 100.0 / lt); 66633965Sjdp} 66733965Sjdp 66860484Sobrienstatic void 66960484Sobrienputint(n, l, lc, w) 67060484Sobrien int n, l, lc, w; 67160484Sobrien{ 67233965Sjdp char b[128]; 67360484Sobrien 67433965Sjdp move(l, lc); 67533965Sjdp if (n == 0) { 67660484Sobrien while (w-- > 0) 67760484Sobrien addch(' '); 67860484Sobrien return; 67960484Sobrien } 68060484Sobrien snprintf(b, sizeof(b), "%*d", w, n); 68160484Sobrien if ((int)strlen(b) > w) 68260484Sobrien snprintf(b, sizeof(b), "%*dk", w - 1, n / 1000); 68360484Sobrien if ((int)strlen(b) > w) 68460484Sobrien snprintf(b, sizeof(b), "%*dM", w - 1, n / 1000000); 68560484Sobrien addstr(b); 68660484Sobrien} 68760484Sobrien 68860484Sobrienstatic void 68960484Sobrienputfloat(f, l, lc, w, d, nz) 69060484Sobrien double f; 69160484Sobrien int l, lc, w, d, nz; 69260484Sobrien{ 69360484Sobrien char b[128]; 69460484Sobrien 69560484Sobrien move(l, lc); 69660484Sobrien if (nz && f == 0.0) { 69760484Sobrien while (--w >= 0) 69860484Sobrien addch(' '); 69960484Sobrien return; 70060484Sobrien } 70160484Sobrien snprintf(b, sizeof(b), "%*.*f", w, d, f); 70260484Sobrien if ((int)strlen(b) > w) 70360484Sobrien snprintf(b, sizeof(b), "%*.0f", w, f); 70460484Sobrien if ((int)strlen(b) > w) { 70560484Sobrien while (--w >= 0) 70660484Sobrien addch('*'); 70760484Sobrien return; 70860484Sobrien } 70960484Sobrien addstr(b); 71060484Sobrien} 71160484Sobrien 71260484Sobrienstatic void 71360484Sobrienputlongdouble(f, l, lc, w, d, nz) 71433965Sjdp long double f; 71533965Sjdp int l, lc, w, d, nz; 71633965Sjdp{ 71733965Sjdp char b[128]; 71833965Sjdp 71933965Sjdp move(l, lc); 72033965Sjdp if (nz && f == 0.0) { 72133965Sjdp while (--w >= 0) 72233965Sjdp addch(' '); 72333965Sjdp return; 72433965Sjdp } 72533965Sjdp sprintf(b, "%*.*Lf", w, d, f); 72633965Sjdp if ((int)strlen(b) > w) 72733965Sjdp sprintf(b, "%*.0Lf", w, f); 72833965Sjdp if ((int)strlen(b) > w) { 72933965Sjdp while (--w >= 0) 73033965Sjdp addch('*'); 73133965Sjdp return; 73233965Sjdp } 73333965Sjdp addstr(b); 73433965Sjdp} 73533965Sjdp 73633965Sjdpstatic void 73733965Sjdpgetinfo(ls) 73833965Sjdp struct Info *ls; 73933965Sjdp{ 74033965Sjdp struct devinfo *tmp_dinfo; 74133965Sjdp size_t size; 74233965Sjdp int mib[2]; 74333965Sjdp 74433965Sjdp GETSYSCTL("kern.cp_time", ls->time); 74533965Sjdp GETSYSCTL("kern.cp_time", cur.cp_time); 74633965Sjdp GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch); 74733965Sjdp GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap); 74833965Sjdp GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall); 74933965Sjdp GETSYSCTL("vm.stats.sys.v_intr", ls->v_intr); 75033965Sjdp GETSYSCTL("vm.stats.sys.v_soft", ls->v_soft); 75133965Sjdp GETSYSCTL("vm.stats.vm.v_vm_faults", ls->v_vm_faults); 75233965Sjdp GETSYSCTL("vm.stats.vm.v_cow_faults", ls->v_cow_faults); 75333965Sjdp GETSYSCTL("vm.stats.vm.v_zfod", ls->v_zfod); 75433965Sjdp GETSYSCTL("vm.stats.vm.v_ozfod", ls->v_ozfod); 75533965Sjdp GETSYSCTL("vm.stats.vm.v_swapin", ls->v_swapin); 75633965Sjdp GETSYSCTL("vm.stats.vm.v_swapout", ls->v_swapout); 75733965Sjdp GETSYSCTL("vm.stats.vm.v_swappgsin", ls->v_swappgsin); 75833965Sjdp GETSYSCTL("vm.stats.vm.v_swappgsout", ls->v_swappgsout); 75933965Sjdp GETSYSCTL("vm.stats.vm.v_vnodein", ls->v_vnodein); 76033965Sjdp GETSYSCTL("vm.stats.vm.v_vnodeout", ls->v_vnodeout); 76133965Sjdp GETSYSCTL("vm.stats.vm.v_vnodepgsin", ls->v_vnodepgsin); 76233965Sjdp GETSYSCTL("vm.stats.vm.v_vnodepgsout", ls->v_vnodepgsout); 76333965Sjdp GETSYSCTL("vm.stats.vm.v_intrans", ls->v_intrans); 76433965Sjdp GETSYSCTL("vm.stats.vm.v_reactivated", ls->v_reactivated); 76533965Sjdp GETSYSCTL("vm.stats.vm.v_pdwakeups", ls->v_pdwakeups); 76633965Sjdp GETSYSCTL("vm.stats.vm.v_pdpages", ls->v_pdpages); 76733965Sjdp GETSYSCTL("vm.stats.vm.v_dfree", ls->v_dfree); 76833965Sjdp GETSYSCTL("vm.stats.vm.v_pfree", ls->v_pfree); 76933965Sjdp GETSYSCTL("vm.stats.vm.v_tfree", ls->v_tfree); 77033965Sjdp GETSYSCTL("vm.stats.vm.v_page_size", ls->v_page_size); 77133965Sjdp GETSYSCTL("vm.stats.vm.v_free_count", ls->v_free_count); 77233965Sjdp GETSYSCTL("vm.stats.vm.v_wire_count", ls->v_wire_count); 77333965Sjdp GETSYSCTL("vm.stats.vm.v_active_count", ls->v_active_count); 77433965Sjdp GETSYSCTL("vm.stats.vm.v_inactive_count", ls->v_inactive_count); 77533965Sjdp GETSYSCTL("vm.stats.vm.v_cache_count", ls->v_cache_count); 77633965Sjdp GETSYSCTL("vfs.bufspace", ls->bufspace); 77733965Sjdp GETSYSCTL("kern.maxvnodes", ls->desiredvnodes); 77833965Sjdp GETSYSCTL("vfs.numvnodes", ls->numvnodes); 77933965Sjdp GETSYSCTL("vfs.freevnodes", ls->freevnodes); 78033965Sjdp GETSYSCTL("vfs.cache.nchstats", ls->nchstats); 78133965Sjdp GETSYSCTL("vfs.numdirtybuffers", ls->numdirtybuffers); 78233965Sjdp getsysctl("hw.intrcnt", ls->intrcnt, nintr * sizeof(u_long)); 78333965Sjdp 78433965Sjdp size = sizeof(ls->Total); 78533965Sjdp mib[0] = CTL_VM; 78633965Sjdp mib[1] = VM_TOTAL; 78733965Sjdp if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) { 78833965Sjdp error("Can't get kernel info: %s\n", strerror(errno)); 78933965Sjdp bzero(&ls->Total, sizeof(ls->Total)); 79033965Sjdp } 79133965Sjdp size = sizeof(ncpu); 79233965Sjdp if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0 || 79333965Sjdp size != sizeof(ncpu)) 79433965Sjdp ncpu = 1; 79533965Sjdp 79633965Sjdp tmp_dinfo = last.dinfo; 79733965Sjdp last.dinfo = cur.dinfo; 79833965Sjdp cur.dinfo = tmp_dinfo; 79933965Sjdp 80033965Sjdp last.snap_time = cur.snap_time; 80133965Sjdp switch (devstat_getdevs(NULL, &cur)) { 80233965Sjdp case -1: 80333965Sjdp errx(1, "%s", devstat_errbuf); 80433965Sjdp break; 80533965Sjdp case 1: 80633965Sjdp num_devices = cur.dinfo->numdevs; 80733965Sjdp generation = cur.dinfo->generation; 80833965Sjdp cmdkre("refresh", NULL); 80933965Sjdp break; 81033965Sjdp default: 81133965Sjdp break; 81233965Sjdp } 81333965Sjdp} 81433965Sjdp 81533965Sjdpstatic void 81633965Sjdpallocinfo(ls) 81733965Sjdp struct Info *ls; 81833965Sjdp{ 81933965Sjdp 82033965Sjdp ls->intrcnt = (long *) calloc(nintr, sizeof(long)); 82133965Sjdp if (ls->intrcnt == NULL) 82233965Sjdp errx(2, "out of memory"); 82333965Sjdp} 82433965Sjdp 82533965Sjdpstatic void 82633965Sjdpcopyinfo(from, to) 82733965Sjdp struct Info *from, *to; 82833965Sjdp{ 82933965Sjdp long *intrcnt; 83033965Sjdp 83133965Sjdp /* 83233965Sjdp * time, wds, seek, and xfer are malloc'd so we have to 83333965Sjdp * save the pointers before the structure copy and then 83433965Sjdp * copy by hand. 83533965Sjdp */ 83633965Sjdp intrcnt = to->intrcnt; 83733965Sjdp *to = *from; 83833965Sjdp 83933965Sjdp bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); 84033965Sjdp} 84133965Sjdp 84233965Sjdpstatic void 84333965Sjdpdinfo(dn, lc, now, then) 84433965Sjdp int dn, lc; 84533965Sjdp struct statinfo *now, *then; 84633965Sjdp{ 84733965Sjdp long double transfers_per_second; 84833965Sjdp long double kb_per_transfer, mb_per_second; 84933965Sjdp long double elapsed_time, device_busy; 85033965Sjdp int di; 85133965Sjdp 85233965Sjdp di = dev_select[dn].position; 85333965Sjdp 85433965Sjdp if (then != NULL) { 85533965Sjdp /* Calculate relative to previous sample */ 85633965Sjdp elapsed_time = now->snap_time - then->snap_time; 85733965Sjdp } else { 85833965Sjdp /* Calculate relative to device creation */ 85933965Sjdp elapsed_time = now->snap_time - devstat_compute_etime( 86033965Sjdp &now->dinfo->devices[di].creation_time, NULL); 86133965Sjdp } 86233965Sjdp 86333965Sjdp if (devstat_compute_statistics(&now->dinfo->devices[di], then ? 86433965Sjdp &then->dinfo->devices[di] : NULL, elapsed_time, 86533965Sjdp DSM_KB_PER_TRANSFER, &kb_per_transfer, 86633965Sjdp DSM_TRANSFERS_PER_SECOND, &transfers_per_second, 86733965Sjdp DSM_MB_PER_SECOND, &mb_per_second, 86833965Sjdp DSM_BUSY_PCT, &device_busy, 86933965Sjdp DSM_NONE) != 0) 87033965Sjdp errx(1, "%s", devstat_errbuf); 87133965Sjdp 87233965Sjdp lc = DISKCOL + lc * 6; 87333965Sjdp putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0); 87433965Sjdp putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0); 87533965Sjdp putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0); 87633965Sjdp putlongdouble(device_busy, DISKROW + 4, lc, 5, 0, 0); 87733965Sjdp} 87833965Sjdp