121585Sdist /* 221585Sdist * Copyright (c) 1980 Regents of the University of California. 321585Sdist * All rights reserved. The Berkeley software License Agreement 421585Sdist * specifies the terms and conditions for redistribution. 521585Sdist */ 621585Sdist 710826Ssam #ifndef lint 821585Sdist char copyright[] = 921585Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1021585Sdist All rights reserved.\n"; 1121585Sdist #endif not lint 1210826Ssam 1321585Sdist #ifndef lint 14*30266Sbostic static char sccsid[] = "@(#)vmstat.c 5.8 (Berkeley) 12/09/86"; 1521585Sdist #endif not lint 1621585Sdist 171155Sbill #include <stdio.h> 1818761Ssam #include <ctype.h> 1918761Ssam #include <nlist.h> 2018761Ssam 211155Sbill #include <sys/param.h> 2218761Ssam #include <sys/file.h> 231155Sbill #include <sys/vm.h> 2429664Ssam #include <sys/dkstat.h> 253162Stoy #include <sys/buf.h> 2615807Smckusick #include <sys/dir.h> 2718761Ssam #include <sys/inode.h> 2817262Smckusick #include <sys/namei.h> 2925708Ssam #include <sys/text.h> 301155Sbill 311155Sbill struct nlist nl[] = { 321448Sbill #define X_CPTIME 0 331448Sbill { "_cp_time" }, 341448Sbill #define X_RATE 1 351155Sbill { "_rate" }, 361448Sbill #define X_TOTAL 2 371155Sbill { "_total" }, 381448Sbill #define X_DEFICIT 3 391155Sbill { "_deficit" }, 401448Sbill #define X_FORKSTAT 4 411155Sbill { "_forkstat" }, 421448Sbill #define X_SUM 5 431155Sbill { "_sum" }, 441448Sbill #define X_FIRSTFREE 6 451155Sbill { "_firstfree" }, 461448Sbill #define X_MAXFREE 7 471155Sbill { "_maxfree" }, 489249Ssam #define X_BOOTTIME 8 499249Ssam { "_boottime" }, 501448Sbill #define X_DKXFER 9 511448Sbill { "_dk_xfer" }, 5210826Ssam #define X_REC 10 531155Sbill { "_rectime" }, 5410826Ssam #define X_PGIN 11 551155Sbill { "_pgintime" }, 5610826Ssam #define X_HZ 12 573162Stoy { "_hz" }, 5818761Ssam #define X_PHZ 13 5915266Ssam { "_phz" }, 6015807Smckusick #define X_NCHSTATS 14 6115807Smckusick { "_nchstats" }, 6217262Smckusick #define X_INTRNAMES 15 6317262Smckusick { "_intrnames" }, 6417262Smckusick #define X_EINTRNAMES 16 6517262Smckusick { "_eintrnames" }, 6617262Smckusick #define X_INTRCNT 17 6717262Smckusick { "_intrcnt" }, 6817262Smckusick #define X_EINTRCNT 18 6917262Smckusick { "_eintrcnt" }, 7018761Ssam #define X_DK_NDRIVE 19 7118761Ssam { "_dk_ndrive" }, 7225512Ssam #define X_XSTATS 20 7325512Ssam { "_xstats" }, 7410826Ssam #ifdef vax 7525708Ssam #define X_MBDINIT (X_XSTATS+1) 7610826Ssam { "_mbdinit" }, 7725708Ssam #define X_UBDINIT (X_XSTATS+2) 7810826Ssam { "_ubdinit" }, 7910826Ssam #endif 8025708Ssam #ifdef tahoe 8125708Ssam #define X_VBDINIT (X_XSTATS+1) 8225708Ssam { "_vbdinit" }, 8325960Ssam #define X_CKEYSTATS (X_XSTATS+2) 8425960Ssam { "_ckeystats" }, 8525960Ssam #define X_DKEYSTATS (X_XSTATS+3) 8625960Ssam { "_dkeystats" }, 8725708Ssam #endif 8810826Ssam { "" }, 891155Sbill }; 901155Sbill 9118761Ssam char **dr_name; 9218761Ssam int *dr_select; 9318761Ssam int dk_ndrive; 9418761Ssam int ndrives = 0; 9518761Ssam #ifdef vax 9618761Ssam char *defdrives[] = { "hp0", "hp1", "hp2", 0 }; 9718761Ssam #else 9818761Ssam char *defdrives[] = { 0 }; 9918761Ssam #endif 1001155Sbill double stat1(); 1011155Sbill int firstfree, maxfree; 1023162Stoy int hz; 10315266Ssam int phz; 10415266Ssam int HZ; 10518761Ssam 10618761Ssam struct { 1071155Sbill int busy; 1081448Sbill long time[CPUSTATES]; 10918761Ssam long *xfer; 1101155Sbill struct vmmeter Rate; 1111155Sbill struct vmtotal Total; 1121155Sbill struct vmmeter Sum; 1131155Sbill struct forkstat Forkstat; 1141155Sbill unsigned rectime; 1151155Sbill unsigned pgintime; 1161155Sbill } s, s1, z; 1171155Sbill #define rate s.Rate 1181155Sbill #define total s.Total 1191155Sbill #define sum s.Sum 1201155Sbill #define forkstat s.Forkstat 1211155Sbill 12210826Ssam struct vmmeter osum; 1231155Sbill int deficit; 1241155Sbill double etime; 1251155Sbill int mf; 12617262Smckusick time_t now, boottime; 12717262Smckusick int printhdr(); 12818768Ssam int lines = 1; 1291155Sbill 13029664Ssam #define INTS(x) ((x) - (hz + phz)) 13129664Ssam 1321155Sbill main(argc, argv) 13310826Ssam int argc; 13410826Ssam char **argv; 1351155Sbill { 1361155Sbill extern char *ctime(); 13729664Ssam register i; 13817262Smckusick int iter, nintv, iflag = 0; 1391155Sbill long t; 14029664Ssam char *arg, **cp, buf[BUFSIZ]; 1411155Sbill 1421155Sbill nlist("/vmunix", nl); 1431155Sbill if(nl[0].n_type == 0) { 14429664Ssam fprintf(stderr, "no /vmunix namelist\n"); 1451155Sbill exit(1); 1461155Sbill } 1471155Sbill mf = open("/dev/kmem", 0); 1481155Sbill if(mf < 0) { 14929664Ssam fprintf(stderr, "cannot open /dev/kmem\n"); 1501155Sbill exit(1); 1511155Sbill } 1521155Sbill iter = 0; 1531155Sbill argc--, argv++; 1541155Sbill while (argc>0 && argv[0][0]=='-') { 1551155Sbill char *cp = *argv++; 1561155Sbill argc--; 1571155Sbill while (*++cp) switch (*cp) { 1581155Sbill 1591155Sbill case 't': 1601155Sbill dotimes(); 1611155Sbill exit(0); 16210826Ssam 1631155Sbill case 'z': 1641155Sbill close(mf); 1651155Sbill mf = open("/dev/kmem", 2); 16618761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 1671155Sbill write(mf, &z.Sum, sizeof z.Sum); 1681155Sbill exit(0); 1691155Sbill 1701155Sbill case 'f': 1711155Sbill doforkst(); 1721155Sbill exit(0); 1731155Sbill 1741155Sbill case 's': 1751155Sbill dosum(); 1761155Sbill exit(0); 1771155Sbill 17817262Smckusick case 'i': 17917262Smckusick iflag++; 18017262Smckusick break; 18117262Smckusick 1821155Sbill default: 18318761Ssam fprintf(stderr, 18418761Ssam "usage: vmstat [ -fsi ] [ interval ] [ count]\n"); 1851155Sbill exit(1); 1861155Sbill } 1871155Sbill } 18818761Ssam lseek(mf, (long)nl[X_FIRSTFREE].n_value, L_SET); 1891155Sbill read(mf, &firstfree, sizeof firstfree); 19018761Ssam lseek(mf, (long)nl[X_MAXFREE].n_value, L_SET); 1911155Sbill read(mf, &maxfree, sizeof maxfree); 19218761Ssam lseek(mf, (long)nl[X_BOOTTIME].n_value, L_SET); 1939249Ssam read(mf, &boottime, sizeof boottime); 19418761Ssam lseek(mf, (long)nl[X_HZ].n_value, L_SET); 1953162Stoy read(mf, &hz, sizeof hz); 19618761Ssam if (nl[X_PHZ].n_value != 0) { 19718761Ssam lseek(mf, (long)nl[X_PHZ].n_value, L_SET); 19818761Ssam read(mf, &phz, sizeof phz); 19918761Ssam } 20015266Ssam HZ = phz ? phz : hz; 201*30266Sbostic if (nl[X_DK_NDRIVE].n_value == 0) { 20229664Ssam fprintf(stderr, "dk_ndrive undefined in system\n"); 20318761Ssam exit(1); 2043162Stoy } 20518761Ssam lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET); 20618761Ssam read(mf, &dk_ndrive, sizeof (dk_ndrive)); 20718761Ssam if (dk_ndrive <= 0) { 20829664Ssam fprintf(stderr, "dk_ndrive %d\n", dk_ndrive); 20918761Ssam exit(1); 21018761Ssam } 21118761Ssam dr_select = (int *)calloc(dk_ndrive, sizeof (int)); 21218761Ssam dr_name = (char **)calloc(dk_ndrive, sizeof (char *)); 21318761Ssam #define allocate(e, t) \ 21418761Ssam s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ 21518761Ssam s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); 21618761Ssam allocate(xfer, long); 21718761Ssam for (arg = buf, i = 0; i < dk_ndrive; i++) { 21818761Ssam dr_name[i] = arg; 21918761Ssam sprintf(dr_name[i], "dk%d", i); 22018761Ssam arg += strlen(dr_name[i]) + 1; 22118761Ssam } 2223162Stoy read_names(); 2231155Sbill time(&now); 2249249Ssam nintv = now - boottime; 2251155Sbill if (nintv <= 0 || nintv > 60*60*24*365*10) { 22629664Ssam fprintf(stderr, 22729664Ssam "Time makes no sense... namelist must be wrong.\n"); 2281155Sbill exit(1); 2291155Sbill } 23017262Smckusick if (iflag) { 23117262Smckusick dointr(nintv); 23217262Smckusick exit(0); 23317262Smckusick } 23418761Ssam /* 23518761Ssam * Choose drives to be displayed. Priority 23618761Ssam * goes to (in order) drives supplied as arguments, 23718761Ssam * default drives. If everything isn't filled 23818761Ssam * in and there are drives not taken care of, 23918761Ssam * display the first few that fit. 24018761Ssam */ 24118761Ssam ndrives = 0; 24218761Ssam while (argc > 0 && !isdigit(argv[0][0])) { 24318761Ssam for (i = 0; i < dk_ndrive; i++) { 24418761Ssam if (strcmp(dr_name[i], argv[0])) 24518761Ssam continue; 24618761Ssam dr_select[i] = 1; 24718761Ssam ndrives++; 24818761Ssam } 24918761Ssam argc--, argv++; 25018761Ssam } 25118761Ssam for (i = 0; i < dk_ndrive && ndrives < 4; i++) { 25218761Ssam if (dr_select[i]) 25318761Ssam continue; 25418761Ssam for (cp = defdrives; *cp; cp++) 25518761Ssam if (strcmp(dr_name[i], *cp) == 0) { 25618761Ssam dr_select[i] = 1; 25718761Ssam ndrives++; 25818761Ssam break; 25918761Ssam } 26018761Ssam } 26118761Ssam for (i = 0; i < dk_ndrive && ndrives < 4; i++) { 26218761Ssam if (dr_select[i]) 26318761Ssam continue; 26418761Ssam dr_select[i] = 1; 26518761Ssam ndrives++; 26618761Ssam } 26718761Ssam if (argc > 1) 26818761Ssam iter = atoi(argv[1]); 26917262Smckusick signal(SIGCONT, printhdr); 2701155Sbill loop: 27118768Ssam if (--lines == 0) 27218768Ssam printhdr(); 27318761Ssam lseek(mf, (long)nl[X_CPTIME].n_value, L_SET); 2741448Sbill read(mf, s.time, sizeof s.time); 27518761Ssam lseek(mf, (long)nl[X_DKXFER].n_value, L_SET); 27618761Ssam read(mf, s.xfer, dk_ndrive * sizeof (long)); 27718761Ssam if (nintv != 1) 27818761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 27918761Ssam else 28018761Ssam lseek(mf, (long)nl[X_RATE].n_value, L_SET); 28118761Ssam read(mf, &rate, sizeof rate); 28218761Ssam lseek(mf, (long)nl[X_TOTAL].n_value, L_SET); 2831155Sbill read(mf, &total, sizeof total); 28410826Ssam osum = sum; 28518761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 28610826Ssam read(mf, &sum, sizeof sum); 28718761Ssam lseek(mf, (long)nl[X_DEFICIT].n_value, L_SET); 2881155Sbill read(mf, &deficit, sizeof deficit); 2891448Sbill etime = 0; 29018761Ssam for (i=0; i < dk_ndrive; i++) { 2911448Sbill t = s.xfer[i]; 2921448Sbill s.xfer[i] -= s1.xfer[i]; 2931448Sbill s1.xfer[i] = t; 2941155Sbill } 2951155Sbill for (i=0; i < CPUSTATES; i++) { 2961448Sbill t = s.time[i]; 2971448Sbill s.time[i] -= s1.time[i]; 2981448Sbill s1.time[i] = t; 2991448Sbill etime += s.time[i]; 3001155Sbill } 3011155Sbill if(etime == 0.) 3021155Sbill etime = 1.; 3033162Stoy printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw); 30410826Ssam #define pgtok(a) ((a)*NBPG/1024) 30529664Ssam printf("%6d%6d", pgtok(total.t_avm), pgtok(total.t_free)); 30615266Ssam printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv, 30715266Ssam (rate.v_xsfrec+rate.v_xifrec)/nintv); 30810826Ssam printf("%4d", pgtok(rate.v_pgpgin)/nintv); 30910826Ssam printf("%4d%4d%4d%4d", pgtok(rate.v_pgpgout)/nintv, 31010826Ssam pgtok(rate.v_dfree)/nintv, pgtok(deficit), rate.v_scan/nintv); 31118761Ssam etime /= (float)HZ; 31218761Ssam for (i = 0; i < dk_ndrive; i++) 31318761Ssam if (dr_select[i]) 31418761Ssam stats(i); 31515266Ssam printf("%4d%4d%4d", INTS(rate.v_intr/nintv), rate.v_syscall/nintv, 31615266Ssam rate.v_swtch/nintv); 3171155Sbill for(i=0; i<CPUSTATES; i++) { 3181155Sbill float f = stat1(i); 3191155Sbill if (i == 0) { /* US+NI */ 3201155Sbill i++; 3211155Sbill f += stat1(i); 3221155Sbill } 3231155Sbill printf("%3.0f", f); 3241155Sbill } 3251155Sbill printf("\n"); 3261155Sbill fflush(stdout); 3271155Sbill nintv = 1; 32818768Ssam if (--iter &&argc > 0) { 3291155Sbill sleep(atoi(argv[0])); 3301155Sbill goto loop; 3311155Sbill } 3321155Sbill } 3331155Sbill 33417262Smckusick printhdr() 33517262Smckusick { 33618761Ssam register int i, j; 33718761Ssam 33829664Ssam printf(" procs memory page "); 33918761Ssam i = (ndrives * 3 - 6) / 2; 34018761Ssam if (i < 0) 34118761Ssam i = 0; 34218761Ssam for (j = 0; j < i; j++) 34318761Ssam putchar(' '); 34418761Ssam printf("faults"); 34518761Ssam i = ndrives * 3 - 6 - i; 34618761Ssam for (j = 0; j < i; j++) 34718761Ssam putchar(' '); 34818761Ssam printf(" cpu\n"); 34929664Ssam printf(" r b w avm fre re at pi po fr de sr "); 35018761Ssam for (i = 0; i < dk_ndrive; i++) 35118761Ssam if (dr_select[i]) 35218761Ssam printf("%c%c ", dr_name[i][0], dr_name[i][2]); 35318761Ssam printf(" in sy cs us sy id\n"); 35418768Ssam lines = 19; 35517262Smckusick } 35617262Smckusick 3571155Sbill dotimes() 3581155Sbill { 3591155Sbill 36018761Ssam lseek(mf, (long)nl[X_REC].n_value, L_SET); 3611155Sbill read(mf, &s.rectime, sizeof s.rectime); 36218761Ssam lseek(mf, (long)nl[X_PGIN].n_value, L_SET); 3631155Sbill read(mf, &s.pgintime, sizeof s.pgintime); 36418761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 3651155Sbill read(mf, &sum, sizeof sum); 3661155Sbill printf("%d reclaims, %d total time (usec)\n", sum.v_pgrec, s.rectime); 3671155Sbill printf("average: %d usec / reclaim\n", s.rectime/sum.v_pgrec); 3681155Sbill printf("\n"); 3691155Sbill printf("%d page ins, %d total time (msec)\n",sum.v_pgin, s.pgintime/10); 3701155Sbill printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0)); 3711155Sbill } 3721155Sbill 37330069Ssam #if defined(tahoe) 37430069Ssam #include <tahoe/cpu.h> 37530069Ssam #endif 37630069Ssam 3771155Sbill dosum() 3781155Sbill { 37918761Ssam struct nchstats nchstats; 38025960Ssam struct xstats xstats; 38115807Smckusick long nchtotal; 38225960Ssam #if defined(tahoe) 38325960Ssam struct keystats keystats; 38425960Ssam #endif 3851155Sbill 38618761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 3871155Sbill read(mf, &sum, sizeof sum); 3881155Sbill printf("%9d swap ins\n", sum.v_swpin); 3891155Sbill printf("%9d swap outs\n", sum.v_swpout); 3901155Sbill printf("%9d pages swapped in\n", sum.v_pswpin / CLSIZE); 3911155Sbill printf("%9d pages swapped out\n", sum.v_pswpout / CLSIZE); 3921155Sbill printf("%9d total address trans. faults taken\n", sum.v_faults); 3931155Sbill printf("%9d page ins\n", sum.v_pgin); 3941155Sbill printf("%9d page outs\n", sum.v_pgout); 3953612Sroot printf("%9d pages paged in\n", sum.v_pgpgin); 3963612Sroot printf("%9d pages paged out\n", sum.v_pgpgout); 3973612Sroot printf("%9d sequential process pages freed\n", sum.v_seqfree); 39812830Ssam printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec, 39929664Ssam pct(sum.v_fastpgrec, sum.v_pgrec)); 4001155Sbill printf("%9d reclaims from free list\n", sum.v_pgfrec); 4011155Sbill printf("%9d intransit blocking page faults\n", sum.v_intrans); 4021155Sbill printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE); 4031155Sbill printf("%9d zero fill page faults\n", sum.v_zfod / CLSIZE); 4041155Sbill printf("%9d executable fill pages created\n", sum.v_nexfod / CLSIZE); 4051155Sbill printf("%9d executable fill page faults\n", sum.v_exfod / CLSIZE); 4061155Sbill printf("%9d swap text pages found in free list\n", sum.v_xsfrec); 4071155Sbill printf("%9d inode text pages found in free list\n", sum.v_xifrec); 4081155Sbill printf("%9d file fill pages created\n", sum.v_nvrfod / CLSIZE); 4091155Sbill printf("%9d file fill page faults\n", sum.v_vrfod / CLSIZE); 4101155Sbill printf("%9d pages examined by the clock daemon\n", sum.v_scan); 4111155Sbill printf("%9d revolutions of the clock hand\n", sum.v_rev); 4121155Sbill printf("%9d pages freed by the clock daemon\n", sum.v_dfree / CLSIZE); 4131155Sbill printf("%9d cpu context switches\n", sum.v_swtch); 4141155Sbill printf("%9d device interrupts\n", sum.v_intr); 41517262Smckusick printf("%9d software interrupts\n", sum.v_soft); 41618761Ssam #ifdef vax 41724429Smckusick printf("%9d pseudo-dma dz interrupts\n", sum.v_pdma); 41818761Ssam #endif 4191155Sbill printf("%9d traps\n", sum.v_trap); 4201155Sbill printf("%9d system calls\n", sum.v_syscall); 42115807Smckusick lseek(mf, (long)nl[X_NCHSTATS].n_value, 0); 42218761Ssam read(mf, &nchstats, sizeof nchstats); 42318761Ssam nchtotal = nchstats.ncs_goodhits + nchstats.ncs_badhits + 42418761Ssam nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long; 42515807Smckusick printf("%9d total name lookups", nchtotal); 42615807Smckusick printf(" (cache hits %d%% system %d%% per-process)\n", 42729664Ssam pct(nchstats.ncs_goodhits, nchtotal), 42829664Ssam pct(nchstats.ncs_pass2, nchtotal)); 42916586Ssam printf("%9s badhits %d, falsehits %d, toolong %d\n", "", 43018761Ssam nchstats.ncs_badhits, nchstats.ncs_falsehits, nchstats.ncs_long); 43125512Ssam lseek(mf, (long)nl[X_XSTATS].n_value, 0); 43225512Ssam read(mf, &xstats, sizeof xstats); 43325512Ssam printf("%9d total calls to xalloc (cache hits %d%%)\n", 43429664Ssam xstats.alloc, pct(xstats.alloc_cachehit, xstats.alloc)); 43525512Ssam printf("%9s sticky %d flushed %d unused %d\n", "", 43625512Ssam xstats.alloc_inuse, xstats.alloc_cacheflush, xstats.alloc_unused); 43725512Ssam printf("%9d total calls to xfree", xstats.free); 43825512Ssam printf(" (sticky %d cached %d swapped %d)\n", 43925512Ssam xstats.free_inuse, xstats.free_cache, xstats.free_cacheswap); 44025960Ssam #if defined(tahoe) 44125960Ssam lseek(mf, (long)nl[X_CKEYSTATS].n_value, 0); 44225960Ssam read(mf, &keystats, sizeof keystats); 44325960Ssam printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n", 44425960Ssam keystats.ks_allocs, "code cache keys allocated", 44529664Ssam pct(keystats.ks_free, keystats.ks_allocs), 44629664Ssam pct(keystats.ks_norefs, keystats.ks_allocs), 44729664Ssam pct(keystats.ks_taken, keystats.ks_allocs), 44829664Ssam pct(keystats.ks_shared, keystats.ks_allocs)); 44925960Ssam lseek(mf, (long)nl[X_DKEYSTATS].n_value, 0); 45025960Ssam read(mf, &keystats, sizeof keystats); 45125960Ssam printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n", 45225960Ssam keystats.ks_allocs, "data cache keys allocated", 45329664Ssam pct(keystats.ks_free, keystats.ks_allocs), 45429664Ssam pct(keystats.ks_norefs, keystats.ks_allocs), 45529664Ssam pct(keystats.ks_taken, keystats.ks_allocs), 45629664Ssam pct(keystats.ks_shared, keystats.ks_allocs)); 45725960Ssam #endif 4581155Sbill } 4591155Sbill 4601155Sbill doforkst() 4611155Sbill { 4621155Sbill 46318761Ssam lseek(mf, (long)nl[X_FORKSTAT].n_value, L_SET); 4641155Sbill read(mf, &forkstat, sizeof forkstat); 4651155Sbill printf("%d forks, %d pages, average=%.2f\n", 4661155Sbill forkstat.cntfork, forkstat.sizfork, 4671155Sbill (float) forkstat.sizfork / forkstat.cntfork); 4681155Sbill printf("%d vforks, %d pages, average=%.2f\n", 4691155Sbill forkstat.cntvfork, forkstat.sizvfork, 4701155Sbill (float)forkstat.sizvfork / forkstat.cntvfork); 4711155Sbill } 4721155Sbill 4731155Sbill stats(dn) 4741155Sbill { 4751155Sbill 47618761Ssam if (dn >= dk_ndrive) { 4771155Sbill printf(" 0"); 4781155Sbill return; 4791155Sbill } 4801448Sbill printf("%3.0f", s.xfer[dn]/etime); 4811155Sbill } 4821155Sbill 4831155Sbill double 4841155Sbill stat1(row) 4851155Sbill { 4861448Sbill double t; 4871448Sbill register i; 4881155Sbill 4891155Sbill t = 0; 4901155Sbill for(i=0; i<CPUSTATES; i++) 4911448Sbill t += s.time[i]; 4921448Sbill if(t == 0.) 4931448Sbill t = 1.; 4941448Sbill return(s.time[row]*100./t); 4951155Sbill } 4961155Sbill 4971155Sbill pct(top, bot) 4981155Sbill { 4991155Sbill 5001155Sbill if (bot == 0) 5011155Sbill return (0); 5021155Sbill return ((top * 100) / bot); 5031155Sbill } 5043162Stoy 50517262Smckusick dointr(nintv) 50617262Smckusick { 50717262Smckusick int nintr, inttotal; 50817262Smckusick long *intrcnt; 50917262Smckusick char *intrname, *malloc(); 51017262Smckusick 51117262Smckusick nintr = (nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value) / sizeof(long); 51217262Smckusick intrcnt = (long *) malloc(nl[X_EINTRCNT].n_value - 51317262Smckusick nl[X_INTRCNT].n_value); 51417262Smckusick intrname = malloc(nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value); 51517262Smckusick if (intrcnt == NULL || intrname == NULL) { 51617262Smckusick fprintf(stderr, "vmstat: out of memory\n"); 51717262Smckusick exit(9); 51817262Smckusick } 51918761Ssam lseek(mf, (long)nl[X_INTRCNT].n_value, L_SET); 52017262Smckusick read(mf, intrcnt, nintr * sizeof (long)); 52118761Ssam lseek(mf, (long)nl[X_INTRNAMES].n_value, L_SET); 52217262Smckusick read(mf, intrname, nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value); 52317262Smckusick printf("interrupt total rate\n"); 52417262Smckusick inttotal = 0; 52517262Smckusick while (nintr--) { 52617262Smckusick if (*intrcnt) 52717262Smckusick printf("%-12s %8ld %8ld\n", intrname, 52817262Smckusick *intrcnt, *intrcnt / nintv); 52917262Smckusick intrname += strlen(intrname) + 1; 53017262Smckusick inttotal += *intrcnt++; 53117262Smckusick } 53217262Smckusick printf("Total %8ld %8ld\n", inttotal, inttotal / nintv); 53317262Smckusick } 53417262Smckusick 53518761Ssam #define steal(where, var) \ 53618761Ssam lseek(mf, where, L_SET); read(mf, &var, sizeof var); 5373162Stoy /* 5383162Stoy * Read the drive names out of kmem. 5393162Stoy */ 54010826Ssam #ifdef vax 54118761Ssam #include <vaxuba/ubavar.h> 54218761Ssam #include <vaxmba/mbavar.h> 54318761Ssam 5443162Stoy read_names() 5453162Stoy { 5463162Stoy struct mba_device mdev; 5473162Stoy register struct mba_device *mp; 5483162Stoy struct mba_driver mdrv; 5493162Stoy short two_char; 5503162Stoy char *cp = (char *) &two_char; 5513162Stoy struct uba_device udev, *up; 5523162Stoy struct uba_driver udrv; 5533162Stoy 5543162Stoy mp = (struct mba_device *) nl[X_MBDINIT].n_value; 5553162Stoy up = (struct uba_device *) nl[X_UBDINIT].n_value; 5563492Sroot if (up == 0) { 55710826Ssam fprintf(stderr, "vmstat: Disk init info not in namelist\n"); 5583162Stoy exit(1); 5593162Stoy } 5603492Sroot if (mp) for (;;) { 5613162Stoy steal(mp++, mdev); 5623162Stoy if (mdev.mi_driver == 0) 5633162Stoy break; 5643162Stoy if (mdev.mi_dk < 0 || mdev.mi_alive == 0) 5653162Stoy continue; 5663162Stoy steal(mdev.mi_driver, mdrv); 5673162Stoy steal(mdrv.md_dname, two_char); 56818761Ssam sprintf(dr_name[mdev.mi_dk], "%c%c%d", 56918761Ssam cp[0], cp[1], mdev.mi_unit); 5703162Stoy } 5713492Sroot for (;;) { 5723162Stoy steal(up++, udev); 5733162Stoy if (udev.ui_driver == 0) 5743162Stoy break; 5753162Stoy if (udev.ui_dk < 0 || udev.ui_alive == 0) 5763162Stoy continue; 5773162Stoy steal(udev.ui_driver, udrv); 5783162Stoy steal(udrv.ud_dname, two_char); 57918761Ssam sprintf(dr_name[udev.ui_dk], "%c%c%d", 58018761Ssam cp[0], cp[1], udev.ui_unit); 5813162Stoy } 5823162Stoy } 58310826Ssam #endif 58425708Ssam 58525708Ssam #ifdef tahoe 58625708Ssam #include <tahoevba/vbavar.h> 58725708Ssam 58825708Ssam /* 58925708Ssam * Read the drive names out of kmem. 59025708Ssam */ 59125708Ssam read_names() 59225708Ssam { 59325708Ssam struct vba_device udev, *up; 59425708Ssam struct vba_driver udrv; 59525708Ssam short two_char; 59625708Ssam char *cp = (char *)&two_char; 59725708Ssam 59825708Ssam up = (struct vba_device *) nl[X_VBDINIT].n_value; 59925708Ssam if (up == 0) { 60025708Ssam fprintf(stderr, "vmstat: Disk init info not in namelist\n"); 60125708Ssam exit(1); 60225708Ssam } 60325708Ssam for (;;) { 60425708Ssam steal(up++, udev); 60525708Ssam if (udev.ui_driver == 0) 60625708Ssam break; 60725708Ssam if (udev.ui_dk < 0 || udev.ui_alive == 0) 60825708Ssam continue; 60925708Ssam steal(udev.ui_driver, udrv); 61025708Ssam steal(udrv.ud_dname, two_char); 61125708Ssam sprintf(dr_name[udev.ui_dk], "%c%c%d", 61225708Ssam cp[0], cp[1], udev.ui_unit); 61325708Ssam } 61425708Ssam } 61525708Ssam #endif 616