=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/vmstat/vmstat.c,v retrieving revision 1.53 retrieving revision 1.54 diff -u -r1.53 -r1.54 --- src/usr.bin/vmstat/vmstat.c 2001/05/11 14:35:29 1.53 +++ src/usr.bin/vmstat/vmstat.c 2001/06/23 21:59:44 1.54 @@ -1,5 +1,5 @@ /* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.53 2001/05/11 14:35:29 deraadt Exp $ */ +/* $OpenBSD: vmstat.c,v 1.54 2001/06/23 21:59:44 art Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -1033,20 +1033,85 @@ (totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq); } +static void +print_pool(struct pool *pp, char *name) +{ + static int first = 1; + int ovflw; + char maxp[32]; + + if (first) { + (void)printf("Memory resource pool statistics\n"); + (void)printf( + "%-11s%5s%9s%5s%9s%6s%6s%6s%6s%6s%6s%5s\n", + "Name", + "Size", + "Requests", + "Fail", + "Releases", + "Pgreq", + "Pgrel", + "Npage", + "Hiwat", + "Minpg", + "Maxpg", + "Idle"); + first = 0; + } + if (pp->pr_maxpages == UINT_MAX) + sprintf(maxp, "inf"); + else + sprintf(maxp, "%u", pp->pr_maxpages); +/* + * Print single word. `ovflow' is number of characters didn't fit + * on the last word. `fmt' is a format string to print this word. + * It must contain asterisk for field width. `width' is a width + * occupied by this word. `fixed' is a number of constant chars in + * `fmt'. `val' is a value to be printed using format string `fmt'. + */ +#define PRWORD(ovflw, fmt, width, fixed, val) do { \ + (ovflw) += printf((fmt), \ + (width) - (fixed) - (ovflw) > 0 ? \ + (width) - (fixed) - (ovflw) : 0, \ + (val)) - (width); \ + if ((ovflw) < 0) \ + (ovflw) = 0; \ +} while (/* CONSTCOND */0) + + ovflw = 0; + PRWORD(ovflw, "%-*s", 11, 0, name); + PRWORD(ovflw, " %*u", 5, 1, pp->pr_size); + PRWORD(ovflw, " %*lu", 9, 1, pp->pr_nget); + PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nfail); + PRWORD(ovflw, " %*lu", 9, 1, pp->pr_nput); + PRWORD(ovflw, " %*lu", 6, 1, pp->pr_npagealloc); + PRWORD(ovflw, " %*lu", 6, 1, pp->pr_npagefree); + PRWORD(ovflw, " %*d", 6, 1, pp->pr_npages); + PRWORD(ovflw, " %*d", 6, 1, pp->pr_hiwat); + PRWORD(ovflw, " %*d", 6, 1, pp->pr_minpages); + PRWORD(ovflw, " %*s", 6, 1, maxp); + PRWORD(ovflw, " %*lu\n", 5, 1, pp->pr_nidle); +} + void dopool(void) { - int first, ovflw; + int first; long addr; long total = 0, inuse = 0; TAILQ_HEAD(,pool) pool_head; struct pool pool, *pp = &pool; + int dosysctl, numpools; + int mib[4]; + size_t size; + dosysctl = (nlist != NULL || memf != NULL); + kread(X_POOLHEAD, &pool_head, sizeof(pool_head)); addr = (long)TAILQ_FIRST(&pool_head); for (first = 1; addr != 0; ) { - char name[32], maxp[32]; + char name[32]; if (kvm_read(kd, addr, (void *)pp, sizeof *pp) != sizeof *pp) { (void)fprintf(stderr, "vmstat: pool chain trashed: %s\n", @@ -1061,56 +1126,7 @@ } name[31] = '\0'; - if (first) { - (void)printf("Memory resource pool statistics\n"); - (void)printf( - "%-11s%5s%9s%5s%9s%6s%6s%6s%6s%6s%6s%5s\n", - "Name", - "Size", - "Requests", - "Fail", - "Releases", - "Pgreq", - "Pgrel", - "Npage", - "Hiwat", - "Minpg", - "Maxpg", - "Idle"); - first = 0; - } - if (pp->pr_maxpages == UINT_MAX) - sprintf(maxp, "inf"); - else - sprintf(maxp, "%u", pp->pr_maxpages); -/* - * Print single word. `ovflow' is number of characters didn't fit - * on the last word. `fmt' is a format string to print this word. - * It must contain asterisk for field width. `width' is a width - * occupied by this word. `fixed' is a number of constant chars in - * `fmt'. `val' is a value to be printed using format string `fmt'. - */ -#define PRWORD(ovflw, fmt, width, fixed, val) do { \ - (ovflw) += printf((fmt), \ - (width) - (fixed) - (ovflw) > 0 ? \ - (width) - (fixed) - (ovflw) : 0, \ - (val)) - (width); \ - if ((ovflw) < 0) \ - (ovflw) = 0; \ -} while (/* CONSTCOND */0) - ovflw = 0; - PRWORD(ovflw, "%-*s", 11, 0, name); - PRWORD(ovflw, " %*u", 5, 1, pp->pr_size); - PRWORD(ovflw, " %*lu", 9, 1, pp->pr_nget); - PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nfail); - PRWORD(ovflw, " %*lu", 9, 1, pp->pr_nput); - PRWORD(ovflw, " %*lu", 6, 1, pp->pr_npagealloc); - PRWORD(ovflw, " %*lu", 6, 1, pp->pr_npagefree); - PRWORD(ovflw, " %*d", 6, 1, pp->pr_npages); - PRWORD(ovflw, " %*d", 6, 1, pp->pr_hiwat); - PRWORD(ovflw, " %*d", 6, 1, pp->pr_minpages); - PRWORD(ovflw, " %*s", 6, 1, maxp); - PRWORD(ovflw, " %*lu\n", 5, 1, pp->pr_nidle); + print_pool(pp, name); inuse += (pp->pr_nget - pp->pr_nput) * pp->pr_size; total += pp->pr_npages * pp->pr_pagesz;