121585Sdist /* 236580Sbostic * Copyright (c) 1980 The Regents of the University of California. 336580Sbostic * All rights reserved. 436580Sbostic * 542784Sbostic * %sccs.include.redist.c% 621585Sdist */ 721585Sdist 810826Ssam #ifndef lint 921585Sdist char copyright[] = 1036580Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ 1121585Sdist All rights reserved.\n"; 1236580Sbostic #endif /* not lint */ 1310826Ssam 1421585Sdist #ifndef lint 15*42952Sbostic static char sccsid[] = "@(#)vmstat.c 5.21 (Berkeley) 06/06/90"; 1636580Sbostic #endif /* not lint */ 1721585Sdist 181155Sbill #include <sys/param.h> 1918761Ssam #include <sys/file.h> 201155Sbill #include <sys/vm.h> 2129664Ssam #include <sys/dkstat.h> 223162Stoy #include <sys/buf.h> 2317262Smckusick #include <sys/namei.h> 2425708Ssam #include <sys/text.h> 2533610Smckusick #include <sys/malloc.h> 2637912Sbostic #include <stdio.h> 2737912Sbostic #include <ctype.h> 2837912Sbostic #include <nlist.h> 2937912Sbostic #include <paths.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" }, 7433610Smckusick #define X_KMEMSTAT 21 7533610Smckusick { "_kmemstats" }, 7633610Smckusick #define X_KMEMBUCKETS 22 7733610Smckusick { "_bucket" }, 78*42952Sbostic #define X_END 22 7910826Ssam #ifdef vax 80*42952Sbostic #define X_MBDINIT (X_END+1) 8110826Ssam { "_mbdinit" }, 82*42952Sbostic #define X_UBDINIT (X_END+2) 8310826Ssam { "_ubdinit" }, 8410826Ssam #endif 8525708Ssam #ifdef tahoe 86*42952Sbostic #define X_VBDINIT (X_END+1) 8725708Ssam { "_vbdinit" }, 88*42952Sbostic #define X_CKEYSTATS (X_END+2) 8925960Ssam { "_ckeystats" }, 90*42952Sbostic #define X_DKEYSTATS (X_END+3) 9125960Ssam { "_dkeystats" }, 9225708Ssam #endif 93*42952Sbostic #ifdef hp300 94*42952Sbostic #define X_HPDINIT (X_END+1) 95*42952Sbostic { "_hp_dinit" }, 96*42952Sbostic #endif 9710826Ssam { "" }, 981155Sbill }; 991155Sbill 10018761Ssam char **dr_name; 10118761Ssam int *dr_select; 10218761Ssam int dk_ndrive; 10318761Ssam int ndrives = 0; 10418761Ssam #ifdef vax 10518761Ssam char *defdrives[] = { "hp0", "hp1", "hp2", 0 }; 10618761Ssam #else 107*42952Sbostic #ifdef hp300 108*42952Sbostic char *defdrives[] = { "rd0", "rd1", "rd2", 0 }; 109*42952Sbostic #else 11018761Ssam char *defdrives[] = { 0 }; 11118761Ssam #endif 112*42952Sbostic #endif 1131155Sbill double stat1(); 1141155Sbill int firstfree, maxfree; 1153162Stoy int hz; 11615266Ssam int phz; 11715266Ssam int HZ; 11818761Ssam 11918761Ssam struct { 1201155Sbill int busy; 1211448Sbill long time[CPUSTATES]; 12218761Ssam long *xfer; 1231155Sbill struct vmmeter Rate; 1241155Sbill struct vmtotal Total; 1251155Sbill struct vmmeter Sum; 1261155Sbill struct forkstat Forkstat; 1271155Sbill unsigned rectime; 1281155Sbill unsigned pgintime; 1291155Sbill } s, s1, z; 1301155Sbill #define rate s.Rate 1311155Sbill #define total s.Total 1321155Sbill #define sum s.Sum 1331155Sbill #define forkstat s.Forkstat 1341155Sbill 13510826Ssam struct vmmeter osum; 1361155Sbill int deficit; 1371155Sbill double etime; 1381155Sbill int mf; 13917262Smckusick time_t now, boottime; 14017262Smckusick int printhdr(); 14118768Ssam int lines = 1; 1421155Sbill 14329664Ssam #define INTS(x) ((x) - (hz + phz)) 14429664Ssam 1451155Sbill main(argc, argv) 14610826Ssam int argc; 14710826Ssam char **argv; 1481155Sbill { 1491155Sbill extern char *ctime(); 15029664Ssam register i; 15117262Smckusick int iter, nintv, iflag = 0; 1521155Sbill long t; 15329664Ssam char *arg, **cp, buf[BUFSIZ]; 1541155Sbill 15537912Sbostic nlist(_PATH_UNIX, nl); 1561155Sbill if(nl[0].n_type == 0) { 15737912Sbostic fprintf(stderr, "vmstat: no %s namelist\n", _PATH_UNIX); 1581155Sbill exit(1); 1591155Sbill } 16037912Sbostic mf = open(_PATH_KMEM, 0); 1611155Sbill if(mf < 0) { 16237912Sbostic fprintf(stderr, "vmstat: cannot open %s\n", _PATH_KMEM); 1631155Sbill exit(1); 1641155Sbill } 1651155Sbill iter = 0; 1661155Sbill argc--, argv++; 1671155Sbill while (argc>0 && argv[0][0]=='-') { 1681155Sbill char *cp = *argv++; 1691155Sbill argc--; 1701155Sbill while (*++cp) switch (*cp) { 1711155Sbill 1721155Sbill case 't': 1731155Sbill dotimes(); 1741155Sbill exit(0); 17510826Ssam 1761155Sbill case 'z': 1771155Sbill close(mf); 17837912Sbostic mf = open(_PATH_KMEM, 2); 17918761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 1801155Sbill write(mf, &z.Sum, sizeof z.Sum); 1811155Sbill exit(0); 1821155Sbill 1831155Sbill case 'f': 1841155Sbill doforkst(); 1851155Sbill exit(0); 1861155Sbill 18733610Smckusick case 'm': 18833610Smckusick domem(); 18933610Smckusick exit(0); 19033610Smckusick 1911155Sbill case 's': 1921155Sbill dosum(); 1931155Sbill exit(0); 1941155Sbill 19517262Smckusick case 'i': 19617262Smckusick iflag++; 19717262Smckusick break; 19817262Smckusick 1991155Sbill default: 20018761Ssam fprintf(stderr, 20133610Smckusick "usage: vmstat [ -fsim ] [ interval ] [ count]\n"); 2021155Sbill exit(1); 2031155Sbill } 2041155Sbill } 20518761Ssam lseek(mf, (long)nl[X_FIRSTFREE].n_value, L_SET); 2061155Sbill read(mf, &firstfree, sizeof firstfree); 20718761Ssam lseek(mf, (long)nl[X_MAXFREE].n_value, L_SET); 2081155Sbill read(mf, &maxfree, sizeof maxfree); 20918761Ssam lseek(mf, (long)nl[X_BOOTTIME].n_value, L_SET); 2109249Ssam read(mf, &boottime, sizeof boottime); 21118761Ssam lseek(mf, (long)nl[X_HZ].n_value, L_SET); 2123162Stoy read(mf, &hz, sizeof hz); 21318761Ssam if (nl[X_PHZ].n_value != 0) { 21418761Ssam lseek(mf, (long)nl[X_PHZ].n_value, L_SET); 21518761Ssam read(mf, &phz, sizeof phz); 21618761Ssam } 21715266Ssam HZ = phz ? phz : hz; 21830266Sbostic if (nl[X_DK_NDRIVE].n_value == 0) { 21929664Ssam fprintf(stderr, "dk_ndrive undefined in system\n"); 22018761Ssam exit(1); 2213162Stoy } 22218761Ssam lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET); 22318761Ssam read(mf, &dk_ndrive, sizeof (dk_ndrive)); 22418761Ssam if (dk_ndrive <= 0) { 22529664Ssam fprintf(stderr, "dk_ndrive %d\n", dk_ndrive); 22618761Ssam exit(1); 22718761Ssam } 22818761Ssam dr_select = (int *)calloc(dk_ndrive, sizeof (int)); 22918761Ssam dr_name = (char **)calloc(dk_ndrive, sizeof (char *)); 23018761Ssam #define allocate(e, t) \ 23118761Ssam s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ 23218761Ssam s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); 23318761Ssam allocate(xfer, long); 23418761Ssam for (arg = buf, i = 0; i < dk_ndrive; i++) { 23518761Ssam dr_name[i] = arg; 23618761Ssam sprintf(dr_name[i], "dk%d", i); 23718761Ssam arg += strlen(dr_name[i]) + 1; 23818761Ssam } 2393162Stoy read_names(); 2401155Sbill time(&now); 2419249Ssam nintv = now - boottime; 2421155Sbill if (nintv <= 0 || nintv > 60*60*24*365*10) { 24329664Ssam fprintf(stderr, 24429664Ssam "Time makes no sense... namelist must be wrong.\n"); 2451155Sbill exit(1); 2461155Sbill } 24717262Smckusick if (iflag) { 24817262Smckusick dointr(nintv); 24917262Smckusick exit(0); 25017262Smckusick } 25118761Ssam /* 25218761Ssam * Choose drives to be displayed. Priority 25318761Ssam * goes to (in order) drives supplied as arguments, 25418761Ssam * default drives. If everything isn't filled 25518761Ssam * in and there are drives not taken care of, 25618761Ssam * display the first few that fit. 25718761Ssam */ 25818761Ssam ndrives = 0; 25918761Ssam while (argc > 0 && !isdigit(argv[0][0])) { 26018761Ssam for (i = 0; i < dk_ndrive; i++) { 26118761Ssam if (strcmp(dr_name[i], argv[0])) 26218761Ssam continue; 26318761Ssam dr_select[i] = 1; 26418761Ssam ndrives++; 26518761Ssam } 26618761Ssam argc--, argv++; 26718761Ssam } 26818761Ssam for (i = 0; i < dk_ndrive && ndrives < 4; i++) { 26918761Ssam if (dr_select[i]) 27018761Ssam continue; 27118761Ssam for (cp = defdrives; *cp; cp++) 27218761Ssam if (strcmp(dr_name[i], *cp) == 0) { 27318761Ssam dr_select[i] = 1; 27418761Ssam ndrives++; 27518761Ssam break; 27618761Ssam } 27718761Ssam } 27818761Ssam for (i = 0; i < dk_ndrive && ndrives < 4; i++) { 27918761Ssam if (dr_select[i]) 28018761Ssam continue; 28118761Ssam dr_select[i] = 1; 28218761Ssam ndrives++; 28318761Ssam } 28418761Ssam if (argc > 1) 28518761Ssam iter = atoi(argv[1]); 28617262Smckusick signal(SIGCONT, printhdr); 2871155Sbill loop: 28818768Ssam if (--lines == 0) 28918768Ssam printhdr(); 29018761Ssam lseek(mf, (long)nl[X_CPTIME].n_value, L_SET); 2911448Sbill read(mf, s.time, sizeof s.time); 29218761Ssam lseek(mf, (long)nl[X_DKXFER].n_value, L_SET); 29318761Ssam read(mf, s.xfer, dk_ndrive * sizeof (long)); 29418761Ssam if (nintv != 1) 29518761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 29618761Ssam else 29718761Ssam lseek(mf, (long)nl[X_RATE].n_value, L_SET); 29818761Ssam read(mf, &rate, sizeof rate); 29918761Ssam lseek(mf, (long)nl[X_TOTAL].n_value, L_SET); 3001155Sbill read(mf, &total, sizeof total); 30110826Ssam osum = sum; 30218761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 30310826Ssam read(mf, &sum, sizeof sum); 30418761Ssam lseek(mf, (long)nl[X_DEFICIT].n_value, L_SET); 3051155Sbill read(mf, &deficit, sizeof deficit); 3061448Sbill etime = 0; 30718761Ssam for (i=0; i < dk_ndrive; i++) { 3081448Sbill t = s.xfer[i]; 3091448Sbill s.xfer[i] -= s1.xfer[i]; 3101448Sbill s1.xfer[i] = t; 3111155Sbill } 3121155Sbill for (i=0; i < CPUSTATES; i++) { 3131448Sbill t = s.time[i]; 3141448Sbill s.time[i] -= s1.time[i]; 3151448Sbill s1.time[i] = t; 3161448Sbill etime += s.time[i]; 3171155Sbill } 3181155Sbill if(etime == 0.) 3191155Sbill etime = 1.; 3203162Stoy printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw); 32110826Ssam #define pgtok(a) ((a)*NBPG/1024) 32229664Ssam printf("%6d%6d", pgtok(total.t_avm), pgtok(total.t_free)); 32315266Ssam printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv, 32415266Ssam (rate.v_xsfrec+rate.v_xifrec)/nintv); 32510826Ssam printf("%4d", pgtok(rate.v_pgpgin)/nintv); 32610826Ssam printf("%4d%4d%4d%4d", pgtok(rate.v_pgpgout)/nintv, 32710826Ssam pgtok(rate.v_dfree)/nintv, pgtok(deficit), rate.v_scan/nintv); 32818761Ssam etime /= (float)HZ; 32918761Ssam for (i = 0; i < dk_ndrive; i++) 33018761Ssam if (dr_select[i]) 33118761Ssam stats(i); 33215266Ssam printf("%4d%4d%4d", INTS(rate.v_intr/nintv), rate.v_syscall/nintv, 33315266Ssam rate.v_swtch/nintv); 3341155Sbill for(i=0; i<CPUSTATES; i++) { 3351155Sbill float f = stat1(i); 3361155Sbill if (i == 0) { /* US+NI */ 3371155Sbill i++; 3381155Sbill f += stat1(i); 3391155Sbill } 3401155Sbill printf("%3.0f", f); 3411155Sbill } 3421155Sbill printf("\n"); 3431155Sbill fflush(stdout); 3441155Sbill nintv = 1; 34518768Ssam if (--iter &&argc > 0) { 3461155Sbill sleep(atoi(argv[0])); 3471155Sbill goto loop; 3481155Sbill } 3491155Sbill } 3501155Sbill 35117262Smckusick printhdr() 35217262Smckusick { 35318761Ssam register int i, j; 35418761Ssam 35529664Ssam printf(" procs memory page "); 35618761Ssam i = (ndrives * 3 - 6) / 2; 35718761Ssam if (i < 0) 35818761Ssam i = 0; 35918761Ssam for (j = 0; j < i; j++) 36018761Ssam putchar(' '); 36118761Ssam printf("faults"); 36218761Ssam i = ndrives * 3 - 6 - i; 36318761Ssam for (j = 0; j < i; j++) 36418761Ssam putchar(' '); 36518761Ssam printf(" cpu\n"); 36629664Ssam printf(" r b w avm fre re at pi po fr de sr "); 36718761Ssam for (i = 0; i < dk_ndrive; i++) 36818761Ssam if (dr_select[i]) 36918761Ssam printf("%c%c ", dr_name[i][0], dr_name[i][2]); 37018761Ssam printf(" in sy cs us sy id\n"); 37118768Ssam lines = 19; 37217262Smckusick } 37317262Smckusick 3741155Sbill dotimes() 3751155Sbill { 3761155Sbill 37718761Ssam lseek(mf, (long)nl[X_REC].n_value, L_SET); 3781155Sbill read(mf, &s.rectime, sizeof s.rectime); 37918761Ssam lseek(mf, (long)nl[X_PGIN].n_value, L_SET); 3801155Sbill read(mf, &s.pgintime, sizeof s.pgintime); 38118761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 3821155Sbill read(mf, &sum, sizeof sum); 3831155Sbill printf("%d reclaims, %d total time (usec)\n", sum.v_pgrec, s.rectime); 3841155Sbill printf("average: %d usec / reclaim\n", s.rectime/sum.v_pgrec); 3851155Sbill printf("\n"); 3861155Sbill printf("%d page ins, %d total time (msec)\n",sum.v_pgin, s.pgintime/10); 3871155Sbill printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0)); 3881155Sbill } 3891155Sbill 39030069Ssam #if defined(tahoe) 39130069Ssam #include <tahoe/cpu.h> 39230069Ssam #endif 39330069Ssam 3941155Sbill dosum() 3951155Sbill { 39618761Ssam struct nchstats nchstats; 39725960Ssam struct xstats xstats; 39815807Smckusick long nchtotal; 39925960Ssam #if defined(tahoe) 40025960Ssam struct keystats keystats; 40125960Ssam #endif 4021155Sbill 40318761Ssam lseek(mf, (long)nl[X_SUM].n_value, L_SET); 4041155Sbill read(mf, &sum, sizeof sum); 4051155Sbill printf("%9d swap ins\n", sum.v_swpin); 4061155Sbill printf("%9d swap outs\n", sum.v_swpout); 4071155Sbill printf("%9d pages swapped in\n", sum.v_pswpin / CLSIZE); 4081155Sbill printf("%9d pages swapped out\n", sum.v_pswpout / CLSIZE); 4091155Sbill printf("%9d total address trans. faults taken\n", sum.v_faults); 4101155Sbill printf("%9d page ins\n", sum.v_pgin); 4111155Sbill printf("%9d page outs\n", sum.v_pgout); 4123612Sroot printf("%9d pages paged in\n", sum.v_pgpgin); 4133612Sroot printf("%9d pages paged out\n", sum.v_pgpgout); 4143612Sroot printf("%9d sequential process pages freed\n", sum.v_seqfree); 41512830Ssam printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec, 41629664Ssam pct(sum.v_fastpgrec, sum.v_pgrec)); 4171155Sbill printf("%9d reclaims from free list\n", sum.v_pgfrec); 4181155Sbill printf("%9d intransit blocking page faults\n", sum.v_intrans); 4191155Sbill printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE); 4201155Sbill printf("%9d zero fill page faults\n", sum.v_zfod / CLSIZE); 4211155Sbill printf("%9d executable fill pages created\n", sum.v_nexfod / CLSIZE); 4221155Sbill printf("%9d executable fill page faults\n", sum.v_exfod / CLSIZE); 4231155Sbill printf("%9d swap text pages found in free list\n", sum.v_xsfrec); 4241155Sbill printf("%9d inode text pages found in free list\n", sum.v_xifrec); 4251155Sbill printf("%9d file fill pages created\n", sum.v_nvrfod / CLSIZE); 4261155Sbill printf("%9d file fill page faults\n", sum.v_vrfod / CLSIZE); 4271155Sbill printf("%9d pages examined by the clock daemon\n", sum.v_scan); 4281155Sbill printf("%9d revolutions of the clock hand\n", sum.v_rev); 4291155Sbill printf("%9d pages freed by the clock daemon\n", sum.v_dfree / CLSIZE); 4301155Sbill printf("%9d cpu context switches\n", sum.v_swtch); 4311155Sbill printf("%9d device interrupts\n", sum.v_intr); 43217262Smckusick printf("%9d software interrupts\n", sum.v_soft); 43318761Ssam #ifdef vax 43424429Smckusick printf("%9d pseudo-dma dz interrupts\n", sum.v_pdma); 43518761Ssam #endif 4361155Sbill printf("%9d traps\n", sum.v_trap); 4371155Sbill printf("%9d system calls\n", sum.v_syscall); 43815807Smckusick lseek(mf, (long)nl[X_NCHSTATS].n_value, 0); 43918761Ssam read(mf, &nchstats, sizeof nchstats); 44038773Smckusick nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits + 44138773Smckusick nchstats.ncs_badhits + nchstats.ncs_falsehits + 44238773Smckusick nchstats.ncs_miss + nchstats.ncs_long; 44338773Smckusick printf("%9d total name lookups\n", nchtotal); 44438773Smckusick printf("%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n", 44538773Smckusick "", pct(nchstats.ncs_goodhits, nchtotal), 44638773Smckusick pct(nchstats.ncs_neghits, nchtotal), 44729664Ssam pct(nchstats.ncs_pass2, nchtotal)); 44838773Smckusick printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "", 44938773Smckusick pct(nchstats.ncs_badhits, nchtotal), 45038773Smckusick pct(nchstats.ncs_falsehits, nchtotal), 45138773Smckusick pct(nchstats.ncs_long, nchtotal)); 45225512Ssam lseek(mf, (long)nl[X_XSTATS].n_value, 0); 45325512Ssam read(mf, &xstats, sizeof xstats); 45425512Ssam printf("%9d total calls to xalloc (cache hits %d%%)\n", 45529664Ssam xstats.alloc, pct(xstats.alloc_cachehit, xstats.alloc)); 45625512Ssam printf("%9s sticky %d flushed %d unused %d\n", "", 45725512Ssam xstats.alloc_inuse, xstats.alloc_cacheflush, xstats.alloc_unused); 45825512Ssam printf("%9d total calls to xfree", xstats.free); 45925512Ssam printf(" (sticky %d cached %d swapped %d)\n", 46025512Ssam xstats.free_inuse, xstats.free_cache, xstats.free_cacheswap); 46125960Ssam #if defined(tahoe) 46225960Ssam lseek(mf, (long)nl[X_CKEYSTATS].n_value, 0); 46325960Ssam read(mf, &keystats, sizeof keystats); 46425960Ssam printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n", 46525960Ssam keystats.ks_allocs, "code cache keys allocated", 46633610Smckusick pct(keystats.ks_allocfree, keystats.ks_allocs), 46729664Ssam pct(keystats.ks_norefs, keystats.ks_allocs), 46829664Ssam pct(keystats.ks_taken, keystats.ks_allocs), 46929664Ssam pct(keystats.ks_shared, keystats.ks_allocs)); 47025960Ssam lseek(mf, (long)nl[X_DKEYSTATS].n_value, 0); 47125960Ssam read(mf, &keystats, sizeof keystats); 47225960Ssam printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n", 47325960Ssam keystats.ks_allocs, "data cache keys allocated", 47433610Smckusick pct(keystats.ks_allocfree, keystats.ks_allocs), 47529664Ssam pct(keystats.ks_norefs, keystats.ks_allocs), 47629664Ssam pct(keystats.ks_taken, keystats.ks_allocs), 47729664Ssam pct(keystats.ks_shared, keystats.ks_allocs)); 47825960Ssam #endif 4791155Sbill } 4801155Sbill 4811155Sbill doforkst() 4821155Sbill { 4831155Sbill 48418761Ssam lseek(mf, (long)nl[X_FORKSTAT].n_value, L_SET); 4851155Sbill read(mf, &forkstat, sizeof forkstat); 4861155Sbill printf("%d forks, %d pages, average=%.2f\n", 4871155Sbill forkstat.cntfork, forkstat.sizfork, 4881155Sbill (float) forkstat.sizfork / forkstat.cntfork); 4891155Sbill printf("%d vforks, %d pages, average=%.2f\n", 4901155Sbill forkstat.cntvfork, forkstat.sizvfork, 4911155Sbill (float)forkstat.sizvfork / forkstat.cntvfork); 4921155Sbill } 4931155Sbill 4941155Sbill stats(dn) 4951155Sbill { 4961155Sbill 49718761Ssam if (dn >= dk_ndrive) { 4981155Sbill printf(" 0"); 4991155Sbill return; 5001155Sbill } 5011448Sbill printf("%3.0f", s.xfer[dn]/etime); 5021155Sbill } 5031155Sbill 5041155Sbill double 5051155Sbill stat1(row) 5061155Sbill { 5071448Sbill double t; 5081448Sbill register i; 5091155Sbill 5101155Sbill t = 0; 5111155Sbill for(i=0; i<CPUSTATES; i++) 5121448Sbill t += s.time[i]; 5131448Sbill if(t == 0.) 5141448Sbill t = 1.; 5151448Sbill return(s.time[row]*100./t); 5161155Sbill } 5171155Sbill 5181155Sbill pct(top, bot) 5191155Sbill { 5201155Sbill 5211155Sbill if (bot == 0) 5221155Sbill return (0); 5231155Sbill return ((top * 100) / bot); 5241155Sbill } 5253162Stoy 52617262Smckusick dointr(nintv) 52717262Smckusick { 52817262Smckusick int nintr, inttotal; 52917262Smckusick long *intrcnt; 53017262Smckusick char *intrname, *malloc(); 53117262Smckusick 53217262Smckusick nintr = (nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value) / sizeof(long); 53317262Smckusick intrcnt = (long *) malloc(nl[X_EINTRCNT].n_value - 53417262Smckusick nl[X_INTRCNT].n_value); 53517262Smckusick intrname = malloc(nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value); 53617262Smckusick if (intrcnt == NULL || intrname == NULL) { 53717262Smckusick fprintf(stderr, "vmstat: out of memory\n"); 53817262Smckusick exit(9); 53917262Smckusick } 54018761Ssam lseek(mf, (long)nl[X_INTRCNT].n_value, L_SET); 54117262Smckusick read(mf, intrcnt, nintr * sizeof (long)); 54218761Ssam lseek(mf, (long)nl[X_INTRNAMES].n_value, L_SET); 54317262Smckusick read(mf, intrname, nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value); 54417262Smckusick printf("interrupt total rate\n"); 54517262Smckusick inttotal = 0; 54617262Smckusick while (nintr--) { 54717262Smckusick if (*intrcnt) 54817262Smckusick printf("%-12s %8ld %8ld\n", intrname, 54917262Smckusick *intrcnt, *intrcnt / nintv); 55017262Smckusick intrname += strlen(intrname) + 1; 55117262Smckusick inttotal += *intrcnt++; 55217262Smckusick } 55317262Smckusick printf("Total %8ld %8ld\n", inttotal, inttotal / nintv); 55417262Smckusick } 55517262Smckusick 55633610Smckusick /* 55733610Smckusick * These names must be kept in sync with 55833610Smckusick * the types defined in <sys/malloc.h>. 55933610Smckusick */ 56033610Smckusick char *kmemnames[] = { 56136510Smarc "free", /* 0 M_FREE */ 56236510Smarc "mbuf", /* 1 M_MBUF */ 56336510Smarc "devbuf", /* 2 M_DEVBUF */ 56436510Smarc "socket", /* 3 M_SOCKET */ 56536510Smarc "pcb", /* 4 M_PCB */ 56636510Smarc "routetbl", /* 5 M_RTABLE */ 56736510Smarc "hosttbl", /* 6 M_HTABLE */ 56836510Smarc "fragtbl", /* 7 M_FTABLE */ 56936510Smarc "zombie", /* 8 M_ZOMBIE */ 57036510Smarc "ifaddr", /* 9 M_IFADDR */ 57136510Smarc "soopts", /* 10 M_SOOPTS */ 57236510Smarc "soname", /* 11 M_SONAME */ 57336510Smarc "namei", /* 12 M_NAMEI */ 57436510Smarc "gprof", /* 13 M_GPROF */ 57536510Smarc "ioctlops", /* 14 M_IOCTLOPS */ 57636510Smarc "superblk", /* 15 M_SUPERBLK */ 57736510Smarc "cred", /* 16 M_CRED */ 57836510Smarc "pgrp", /* 17 M_PGRP */ 57936510Smarc "session", /* 18 M_SESSION */ 58036513Smarc "iov", /* 19 M_IOV */ 58138262Smckusick "mount", /* 20 M_MOUNT */ 58238262Smckusick "fhandle", /* 21 M_FHANDLE */ 58338262Smckusick "NFS req", /* 22 M_NFSREQ */ 58438262Smckusick "NFS mount", /* 23 M_NFSMNT */ 58540889Smckusick "vnodes", /* 24 M_VNODE */ 58640889Smckusick "namecache", /* 25 M_CACHE */ 58741315Smckusick "UFS quota", /* 26 M_DQUOT */ 58841315Smckusick "UFS mount", /* 27 M_UFSMNT */ 589*42952Sbostic "mapmem", /* 28 M_MAPMEM */ 590*42952Sbostic "shm", /* 29 M_SHM */ 591*42952Sbostic 0, 0, 0, 0, 59236510Smarc 0, 0, 0, 0, 0, 59336510Smarc 0, 0, 0, 0, 0, 59436510Smarc 0, 0, 0, 0, 0, 59536510Smarc "temp", /* 49 M_TEMP */ 59633610Smckusick }; 59733610Smckusick 59833610Smckusick domem() 59933610Smckusick { 60033610Smckusick struct kmemstats kmemstats[M_LAST]; 60133610Smckusick struct kmembuckets buckets[MINBUCKET + 16]; 60233610Smckusick register struct kmembuckets *kp; 60333610Smckusick register struct kmemstats *ks; 60433610Smckusick int i; 60533610Smckusick 60633610Smckusick lseek(mf, (long)nl[X_KMEMBUCKETS].n_value, L_SET); 60733610Smckusick read(mf, buckets, sizeof buckets); 60833610Smckusick printf("Memory statistics by bucket size\n"); 60933610Smckusick printf(" Size In Use Free Requests HighWater Couldfree\n"); 61033610Smckusick for (i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16; i++, kp++) { 61133610Smckusick if (kp->kb_calls == 0) 61233610Smckusick continue; 61333610Smckusick printf("%8d%9d%7d%11d%8d%11d\n", 1 << i, 61433610Smckusick kp->kb_total - kp->kb_totalfree, 61533610Smckusick kp->kb_totalfree, kp->kb_calls, 61633610Smckusick kp->kb_highwat, kp->kb_couldfree); 61733610Smckusick 61833610Smckusick } 61933610Smckusick lseek(mf, (long)nl[X_KMEMSTAT].n_value, L_SET); 62033610Smckusick read(mf, kmemstats, sizeof kmemstats); 62133610Smckusick printf("Memory statistics by type\n"); 62233610Smckusick printf(" Type In Use MemUse HighUse Limit Requests %s\n", 62333610Smckusick "TypeLimit KernLimit"); 62433610Smckusick for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) { 62533610Smckusick if (ks->ks_calls == 0) 62633610Smckusick continue; 62733610Smckusick printf("%10s%7d%8dK%9dK%6dK%9d%7d%10d\n", 62833610Smckusick kmemnames[i] ? kmemnames[i] : "undefined", 62933610Smckusick ks->ks_inuse, (ks->ks_memuse + 1023) / 1024, 63033610Smckusick (ks->ks_maxused + 1023) / 1024, 63133610Smckusick (ks->ks_limit + 1023) / 1024, ks->ks_calls, 63233610Smckusick ks->ks_limblocks, ks->ks_mapblocks); 63333610Smckusick } 63433610Smckusick } 63533610Smckusick 63618761Ssam #define steal(where, var) \ 63718761Ssam lseek(mf, where, L_SET); read(mf, &var, sizeof var); 6383162Stoy /* 6393162Stoy * Read the drive names out of kmem. 6403162Stoy */ 64110826Ssam #ifdef vax 64218761Ssam #include <vaxuba/ubavar.h> 64318761Ssam #include <vaxmba/mbavar.h> 64418761Ssam 6453162Stoy read_names() 6463162Stoy { 6473162Stoy struct mba_device mdev; 6483162Stoy register struct mba_device *mp; 6493162Stoy struct mba_driver mdrv; 6503162Stoy short two_char; 6513162Stoy char *cp = (char *) &two_char; 6523162Stoy struct uba_device udev, *up; 6533162Stoy struct uba_driver udrv; 6543162Stoy 6553162Stoy mp = (struct mba_device *) nl[X_MBDINIT].n_value; 6563162Stoy up = (struct uba_device *) nl[X_UBDINIT].n_value; 6573492Sroot if (up == 0) { 65810826Ssam fprintf(stderr, "vmstat: Disk init info not in namelist\n"); 6593162Stoy exit(1); 6603162Stoy } 6613492Sroot if (mp) for (;;) { 6623162Stoy steal(mp++, mdev); 6633162Stoy if (mdev.mi_driver == 0) 6643162Stoy break; 6653162Stoy if (mdev.mi_dk < 0 || mdev.mi_alive == 0) 6663162Stoy continue; 6673162Stoy steal(mdev.mi_driver, mdrv); 6683162Stoy steal(mdrv.md_dname, two_char); 66918761Ssam sprintf(dr_name[mdev.mi_dk], "%c%c%d", 67018761Ssam cp[0], cp[1], mdev.mi_unit); 6713162Stoy } 6723492Sroot for (;;) { 6733162Stoy steal(up++, udev); 6743162Stoy if (udev.ui_driver == 0) 6753162Stoy break; 6763162Stoy if (udev.ui_dk < 0 || udev.ui_alive == 0) 6773162Stoy continue; 6783162Stoy steal(udev.ui_driver, udrv); 6793162Stoy steal(udrv.ud_dname, two_char); 68018761Ssam sprintf(dr_name[udev.ui_dk], "%c%c%d", 68118761Ssam cp[0], cp[1], udev.ui_unit); 6823162Stoy } 6833162Stoy } 68410826Ssam #endif 68525708Ssam 68625708Ssam #ifdef tahoe 68725708Ssam #include <tahoevba/vbavar.h> 68825708Ssam 68925708Ssam /* 69025708Ssam * Read the drive names out of kmem. 69125708Ssam */ 69225708Ssam read_names() 69325708Ssam { 69425708Ssam struct vba_device udev, *up; 69525708Ssam struct vba_driver udrv; 69625708Ssam short two_char; 69725708Ssam char *cp = (char *)&two_char; 69825708Ssam 69925708Ssam up = (struct vba_device *) nl[X_VBDINIT].n_value; 70025708Ssam if (up == 0) { 70125708Ssam fprintf(stderr, "vmstat: Disk init info not in namelist\n"); 70225708Ssam exit(1); 70325708Ssam } 70425708Ssam for (;;) { 70525708Ssam steal(up++, udev); 70625708Ssam if (udev.ui_driver == 0) 70725708Ssam break; 70825708Ssam if (udev.ui_dk < 0 || udev.ui_alive == 0) 70925708Ssam continue; 71025708Ssam steal(udev.ui_driver, udrv); 71125708Ssam steal(udrv.ud_dname, two_char); 71225708Ssam sprintf(dr_name[udev.ui_dk], "%c%c%d", 71325708Ssam cp[0], cp[1], udev.ui_unit); 71425708Ssam } 71525708Ssam } 71625708Ssam #endif 717*42952Sbostic 718*42952Sbostic #ifdef hp300 719*42952Sbostic #include <hpdev/device.h> 720*42952Sbostic 721*42952Sbostic #define validdisk(cp) ((cp)[1] == 'd' && ((cp)[0] == 'r' || (cp)[0] == 's')) 722*42952Sbostic 723*42952Sbostic read_names() 724*42952Sbostic { 725*42952Sbostic struct hp_device hdev; 726*42952Sbostic register struct hp_device *hp; 727*42952Sbostic struct driver hdrv; 728*42952Sbostic short two_char; 729*42952Sbostic char *cp = (char *) &two_char; 730*42952Sbostic register char *dp; 731*42952Sbostic 732*42952Sbostic hp = (struct hp_device *) nl[X_HPDINIT].n_value; 733*42952Sbostic if (hp == 0) { 734*42952Sbostic fprintf(stderr, "vmstat: Disk init info not in namelist\n"); 735*42952Sbostic exit(1); 736*42952Sbostic } 737*42952Sbostic for (;;) { 738*42952Sbostic steal(hp++, hdev); 739*42952Sbostic if (hdev.hp_driver == 0) 740*42952Sbostic break; 741*42952Sbostic steal(hdev.hp_driver, hdrv); 742*42952Sbostic steal(hdrv.d_name, two_char); 743*42952Sbostic /* 744*42952Sbostic * hp_dk is meaningless if the device isn't a disk 745*42952Sbostic * (d_name not valid) or the disk was not found when 746*42952Sbostic * booting (hp_alive == 0). 747*42952Sbostic */ 748*42952Sbostic if (!validdisk(cp) || hdev.hp_alive == 0) 749*42952Sbostic continue; 750*42952Sbostic dp = dr_name[hdev.hp_dk]; 751*42952Sbostic sprintf(dp, "%c%c%d", cp[0], cp[1], hdev.hp_unit); 752*42952Sbostic } 753*42952Sbostic } 754*42952Sbostic #endif 755