Tue Apr 30 23:29:18 2019 UTC ()
Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


(simonb)
diff -r1.225 -r1.226 src/usr.bin/vmstat/vmstat.c

cvs diff -r1.225 -r1.226 src/usr.bin/vmstat/vmstat.c (expand / switch to unified diff)

--- src/usr.bin/vmstat/vmstat.c 2018/12/13 01:58:04 1.225
+++ src/usr.bin/vmstat/vmstat.c 2019/04/30 23:29:18 1.226
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vmstat.c,v 1.225 2018/12/13 01:58:04 sevan Exp $ */ 1/* $NetBSD: vmstat.c,v 1.226 2019/04/30 23:29:18 simonb Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation by: 7 * This code is derived from software contributed to The NetBSD Foundation by:
8 * - Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * - Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * - Simon Burge and Luke Mewburn of Wasabi Systems, Inc. 10 * - Simon Burge and Luke Mewburn of Wasabi Systems, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -60,27 +60,27 @@ @@ -60,27 +60,27 @@
60 * SUCH DAMAGE. 60 * SUCH DAMAGE.
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64#ifndef lint 64#ifndef lint
65__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\ 65__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\
66 The Regents of the University of California. All rights reserved."); 66 The Regents of the University of California. All rights reserved.");
67#endif /* not lint */ 67#endif /* not lint */
68 68
69#ifndef lint 69#ifndef lint
70#if 0 70#if 0
71static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; 71static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
72#else 72#else
73__RCSID("$NetBSD: vmstat.c,v 1.225 2018/12/13 01:58:04 sevan Exp $"); 73__RCSID("$NetBSD: vmstat.c,v 1.226 2019/04/30 23:29:18 simonb Exp $");
74#endif 74#endif
75#endif /* not lint */ 75#endif /* not lint */
76 76
77#define __POOL_EXPOSE 77#define __POOL_EXPOSE
78 78
79#include <sys/param.h> 79#include <sys/param.h>
80#include <sys/types.h> 80#include <sys/types.h>
81#include <sys/mount.h> 81#include <sys/mount.h>
82#include <sys/uio.h> 82#include <sys/uio.h>
83 83
84#include <sys/buf.h> 84#include <sys/buf.h>
85#include <sys/evcnt.h> 85#include <sys/evcnt.h>
86#include <sys/ioctl.h> 86#include <sys/ioctl.h>
@@ -1425,141 +1425,134 @@ dopool_sysctl(int verbose, int wide) @@ -1425,141 +1425,134 @@ dopool_sysctl(int verbose, int wide)
1425 struct { 1425 struct {
1426 uint64_t pt_nget; 1426 uint64_t pt_nget;
1427 uint64_t pt_nfail; 1427 uint64_t pt_nfail;
1428 uint64_t pt_nput; 1428 uint64_t pt_nput;
1429 uint64_t pt_nout; 1429 uint64_t pt_nout;
1430 uint64_t pt_nitems; 1430 uint64_t pt_nitems;
1431 uint64_t pt_npagealloc; 1431 uint64_t pt_npagealloc;
1432 uint64_t pt_npagefree; 1432 uint64_t pt_npagefree;
1433 uint64_t pt_npages; 1433 uint64_t pt_npages;
1434 } pool_totals; 1434 } pool_totals;
1435 size_t i, len; 1435 size_t i, len;
1436 int name_len, ovflw; 1436 int name_len, ovflw;
1437 struct pool_sysctl *pp, *data; 1437 struct pool_sysctl *pp, *data;
1438 char in_use[8], avail[8], maxp[32]; 1438 char maxp[32];
1439 1439
1440 data = asysctlbyname("kern.pool", &len); 1440 data = asysctlbyname("kern.pool", &len);
1441 if (data == NULL) 1441 if (data == NULL)
1442 err(1, "failed to read kern.pool"); 1442 err(1, "failed to read kern.pool");
1443 1443
1444 memset(&pool_totals, 0, sizeof pool_totals); 1444 memset(&pool_totals, 0, sizeof pool_totals);
1445 total = inuse = 0; 1445 total = inuse = 0;
1446 len /= sizeof(*data); 1446 len /= sizeof(*data);
1447 1447
1448 (void)printf("Memory resource pool statistics\n"); 1448 (void)printf("Memory resource pool statistics\n");
1449 (void)printf( 1449 (void)printf(
1450 "%-*s%*s%*s%5s%*s%s%s%*s%*s%6s%s%6s%6s%6s%5s%s%s\n", 1450 "%-*s%*s%*s%*s%*s%s%s%*s%*s%*s%s%*s%6s%*s%5s%s%s\n",
1451 wide ? 16 : 11, "Name", 1451 wide ? 16 : 11, "Name",
1452 wide ? 6 : 5, "Size", 1452 wide ? 7 : 5, "Size",
1453 wide ? 12 : 9, "Requests", 1453 wide ? 12 : 9, "Requests",
1454 "Fail", 1454 wide ? 8 : 5, "Fail",
1455 wide ? 12 : 9, "Releases", 1455 wide ? 12 : 9, "Releases",
1456 wide ? " InUse" : "", 1456 wide ? " InUse" : "",
1457 wide ? " Avail" : "", 1457 wide ? " Avail" : "",
1458 wide ? 7 : 6, "Pgreq", 1458 wide ? 11 : 6, "Pgreq",
1459 wide ? 7 : 6, "Pgrel", 1459 wide ? 11 : 6, "Pgrel",
1460 "Npage", 1460 wide ? 8 : 6, "Npage",
1461 wide ? " PageSz" : "", 1461 wide ? " PageSz" : "",
1462 "Hiwat", 1462 wide ? 7 : 6, "Hiwat",
1463 "Minpg", 1463 "Minpg",
1464 "Maxpg", 1464 wide ? 7 : 6, "Maxpg",
1465 "Idle", 1465 "Idle",
1466 wide ? " Flags" : "", 1466 wide ? " Flags" : "",
1467 wide ? " Util" : ""); 1467 wide ? " Util" : "");
1468 1468
1469 name_len = MIN((int)sizeof(pp->pr_wchan), wide ? 16 : 11); 1469 name_len = MIN((int)sizeof(pp->pr_wchan), wide ? 16 : 11);
1470 for (i = 0; i < len; ++i) { 1470 for (i = 0; i < len; ++i) {
1471 pp = &data[i]; 1471 pp = &data[i];
1472 if (pp->pr_nget == 0 && !verbose) 1472 if (pp->pr_nget == 0 && !verbose)
1473 continue; 1473 continue;
1474 if (pp->pr_maxpages == UINT_MAX) 1474 if (pp->pr_maxpages == UINT_MAX)
1475 (void)snprintf(maxp, sizeof(maxp), "inf"); 1475 (void)snprintf(maxp, sizeof(maxp), "inf");
1476 else 1476 else
1477 (void)snprintf(maxp, sizeof(maxp), "%" PRIu64, 1477 (void)snprintf(maxp, sizeof(maxp), "%" PRIu64,
1478 pp->pr_maxpages); 1478 pp->pr_maxpages);
1479 ovflw = 0; 1479 ovflw = 0;
1480 PRWORD(ovflw, "%-*s", name_len, 0, pp->pr_wchan); 1480 PRWORD(ovflw, "%-*s", name_len, 0, pp->pr_wchan);
1481 PRWORD(ovflw, " %*" PRIu64, wide ? 6 : 5, 1, pp->pr_size); 1481 PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 5, 1, pp->pr_size);
1482 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pp->pr_nget); 1482 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pp->pr_nget);
1483 pool_totals.pt_nget += pp->pr_nget; 1483 pool_totals.pt_nget += pp->pr_nget;
1484 PRWORD(ovflw, " %*" PRIu64, 5, 1, pp->pr_nfail); 1484 PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 5, 1, pp->pr_nfail);
1485 pool_totals.pt_nfail += pp->pr_nfail; 1485 pool_totals.pt_nfail += pp->pr_nfail;
1486 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pp->pr_nput); 1486 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pp->pr_nput);
1487 pool_totals.pt_nput += pp->pr_nput; 1487 pool_totals.pt_nput += pp->pr_nput;
1488 if (wide) { 1488 if (wide) {
1489 PRWORD(ovflw, " %*" PRIu64, 7, 1, pp->pr_nout); 1489 PRWORD(ovflw, " %*" PRIu64, 9, 1, pp->pr_nout);
1490 pool_totals.pt_nout += pp->pr_nout; 1490 pool_totals.pt_nout += pp->pr_nout;
1491 } 1491 PRWORD(ovflw, " %*" PRIu64, 9, 1, pp->pr_nitems);
1492 if (wide) { 
1493 PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_nitems); 
1494 pool_totals.pt_nitems += pp->pr_nitems; 1492 pool_totals.pt_nitems += pp->pr_nitems;
1495 } 1493 }
1496 PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 6, 1, pp->pr_npagealloc); 1494 PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pp->pr_npagealloc);
1497 pool_totals.pt_npagealloc += pp->pr_npagealloc; 1495 pool_totals.pt_npagealloc += pp->pr_npagealloc;
1498 PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 6, 1, pp->pr_npagefree); 1496 PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pp->pr_npagefree);
1499 pool_totals.pt_npagefree += pp->pr_npagefree; 1497 pool_totals.pt_npagefree += pp->pr_npagefree;
1500 PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_npages); 1498 PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 6, 1, pp->pr_npages);
1501 pool_totals.pt_npages += pp->pr_npages; 1499 pool_totals.pt_npages += pp->pr_npages;
1502 if (wide) 1500 if (wide)
1503 PRWORD(ovflw, " %*" PRIu64, 7, 1, pp->pr_pagesize); 1501 PRWORD(ovflw, " %*" PRIu64, 7, 1, pp->pr_pagesize);
1504 PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_hiwat); 1502 PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 6, 1, pp->pr_hiwat);
1505 PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_minpages); 1503 PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_minpages);
1506 PRWORD(ovflw, " %*s", 6, 1, maxp); 1504 PRWORD(ovflw, " %*s", wide ? 7 : 6, 1, maxp);
1507 PRWORD(ovflw, " %*" PRIu64, 5, 1, pp->pr_nidle); 1505 PRWORD(ovflw, " %*" PRIu64, 5, 1, pp->pr_nidle);
1508 if (wide) 1506 if (wide)
1509 PRWORD(ovflw, " 0x%0*" PRIx64, 4, 1, 1507 PRWORD(ovflw, " 0x%0*" PRIx64, 5, 1,
1510 pp->pr_flags); 1508 pp->pr_flags);
1511 1509
1512 this_inuse = pp->pr_nout * pp->pr_size; 1510 this_inuse = pp->pr_nout * pp->pr_size;
1513 this_total = pp->pr_npages * pp->pr_pagesize; 1511 this_total = pp->pr_npages * pp->pr_pagesize;
1514 if (pp->pr_flags & PR_RECURSIVE) { 1512 if (pp->pr_flags & PR_RECURSIVE) {
1515 /* 1513 /*
1516 * Don't count in-use memory, since it's part 1514 * Don't count in-use memory, since it's part
1517 * of another pool and will be accounted for 1515 * of another pool and will be accounted for
1518 * there. 1516 * there.
1519 */ 1517 */
1520 total += (this_total - this_inuse); 1518 total += (this_total - this_inuse);
1521 } else { 1519 } else {
1522 inuse += this_inuse; 1520 inuse += this_inuse;
1523 total += this_total; 1521 total += this_total;
1524 } 1522 }
1525 if (wide) { 1523 if (wide) {
1526 if (this_total == 0) 1524 if (this_total == 0)
1527 (void)printf(" ---"); 1525 (void)printf(" ---");
1528 else 1526 else
1529 (void)printf(" %5.1f%%", 1527 (void)printf(" %5.1f%%",
1530 (100.0 * this_inuse) / this_total); 1528 (100.0 * this_inuse) / this_total);
1531 } 1529 }
1532 (void)printf("\n"); 1530 (void)printf("\n");
1533 } 1531 }
 1532 ovflw = 0;
 1533 PRWORD(ovflw, "%-*s", name_len, 0, "Totals");
 1534 PRWORD(ovflw, " %*s", wide ? 7 : 5, 1, "");
 1535 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pool_totals.pt_nget);
 1536 PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 5, 1, pool_totals.pt_nfail);
 1537 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pool_totals.pt_nput);
1534 if (wide) { 1538 if (wide) {
1535 snprintf(in_use, sizeof in_use, "%7"PRId64, pool_totals.pt_nout); 1539 PRWORD(ovflw, " %*" PRIu64, 9, 1, pool_totals.pt_nout);
1536 snprintf(avail, sizeof avail, "%6"PRId64, pool_totals.pt_nitems); 1540 PRWORD(ovflw, " %*" PRIu64, 9, 1, pool_totals.pt_nitems);
1537 } else { 
1538 in_use[0] = '\0'; 
1539 avail[0] = '\0'; 
1540 } 1541 }
1541 (void)printf( 1542 PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pool_totals.pt_npagealloc);
1542 "%-*s%*s%*"PRId64"%5"PRId64"%*"PRId64"%s%s%*"PRId64"%*"PRId64"%6"PRId64"\n", 1543 PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pool_totals.pt_npagefree);
1543 wide ? 16 : 11, "Totals", 1544 PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 6, 1, pool_totals.pt_npages);
1544 wide ? 6 : 5, "", 1545 (void)printf("\n");
1545 wide ? 12 : 9, pool_totals.pt_nget, 
1546 pool_totals.pt_nfail, 
1547 wide ? 12 : 9, pool_totals.pt_nput, 
1548 in_use, 
1549 avail, 
1550 wide ? 7 : 6, pool_totals.pt_npagealloc, 
1551 wide ? 7 : 6, pool_totals.pt_npagefree, 
1552 pool_totals.pt_npages); 
1553 1546
1554 inuse /= KILO; 1547 inuse /= KILO;
1555 total /= KILO; 1548 total /= KILO;
1556 (void)printf( 1549 (void)printf(
1557 "\nIn use %" PRIu64 "K, " 1550 "\nIn use %" PRIu64 "K, "
1558 "total allocated %" PRIu64 "K; utilization %.1f%%\n", 1551 "total allocated %" PRIu64 "K; utilization %.1f%%\n",
1559 inuse, total, (100.0 * inuse) / total); 1552 inuse, total, (100.0 * inuse) / total);
1560 1553
1561 free(data); 1554 free(data);
1562} 1555}
1563 1556
1564void 1557void
1565dopool(int verbose, int wide) 1558dopool(int verbose, int wide)
@@ -1567,154 +1560,145 @@ dopool(int verbose, int wide) @@ -1567,154 +1560,145 @@ dopool(int verbose, int wide)
1567 int first, ovflw; 1560 int first, ovflw;
1568 void *addr; 1561 void *addr;
1569 long total, inuse, this_total, this_inuse; 1562 long total, inuse, this_total, this_inuse;
1570 struct { 1563 struct {
1571 uint64_t pt_nget; 1564 uint64_t pt_nget;
1572 uint64_t pt_nfail; 1565 uint64_t pt_nfail;
1573 uint64_t pt_nput; 1566 uint64_t pt_nput;
1574 uint64_t pt_nout; 1567 uint64_t pt_nout;
1575 uint64_t pt_nitems; 1568 uint64_t pt_nitems;
1576 uint64_t pt_npagealloc; 1569 uint64_t pt_npagealloc;
1577 uint64_t pt_npagefree; 1570 uint64_t pt_npagefree;
1578 uint64_t pt_npages; 1571 uint64_t pt_npages;
1579 } pool_totals; 1572 } pool_totals;
1580 char in_use[8]; 
1581 char avail[8]; 
1582 TAILQ_HEAD(,pool) pool_head; 1573 TAILQ_HEAD(,pool) pool_head;
1583 struct pool pool, *pp = &pool; 1574 struct pool pool, *pp = &pool;
1584 struct pool_allocator pa; 1575 struct pool_allocator pa;
1585 char name[32], maxp[32]; 1576 char maxp[32], name[32];
1586 1577
1587 if (memf == NULL) 1578 if (memf == NULL)
1588 return dopool_sysctl(verbose, wide); 1579 return dopool_sysctl(verbose, wide);
1589 1580
1590 memset(&pool_totals, 0, sizeof pool_totals); 1581 memset(&pool_totals, 0, sizeof pool_totals);
1591 kread(namelist, X_POOLHEAD, &pool_head, sizeof(pool_head)); 1582 kread(namelist, X_POOLHEAD, &pool_head, sizeof(pool_head));
1592 addr = TAILQ_FIRST(&pool_head); 1583 addr = TAILQ_FIRST(&pool_head);
1593 1584
1594 total = inuse = 0; 1585 total = inuse = 0;
1595 1586
1596 for (first = 1; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist) ) { 1587 for (first = 1; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist) ) {
1597 deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed"); 1588 deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed");
1598 deref_kptr(pp->pr_alloc, &pa, sizeof(pa), 1589 deref_kptr(pp->pr_alloc, &pa, sizeof(pa),
1599 "pool allocator trashed"); 1590 "pool allocator trashed");
1600 deref_kptr(pp->pr_wchan, name, sizeof(name), 1591 deref_kptr(pp->pr_wchan, name, sizeof(name),
1601 "pool wait channel trashed"); 1592 "pool wait channel trashed");
1602 name[sizeof(name)-1] = '\0'; 1593 name[sizeof(name)-1] = '\0';
1603 1594
1604 if (first) { 1595 if (first) {
1605 (void)printf("Memory resource pool statistics\n"); 1596 (void)printf("Memory resource pool statistics\n");
1606 (void)printf( 1597 (void)printf(
1607 "%-*s%*s%*s%5s%*s%s%s%*s%*s%6s%s%6s%6s%6s%5s%s%s\n", 1598 "%-*s%*s%*s%*s%*s%s%s%*s%*s%*s%s%*s%6s%*s%5s%s%s\n",
1608 wide ? 16 : 11, "Name", 1599 wide ? 16 : 11, "Name",
1609 wide ? 6 : 5, "Size", 1600 wide ? 7 : 5, "Size",
1610 wide ? 12 : 9, "Requests", 1601 wide ? 12 : 9, "Requests",
1611 "Fail", 1602 wide ? 8 : 5, "Fail",
1612 wide ? 12 : 9, "Releases", 1603 wide ? 12 : 9, "Releases",
1613 wide ? " InUse" : "", 1604 wide ? " InUse" : "",
1614 wide ? " Avail" : "", 1605 wide ? " Avail" : "",
1615 wide ? 7 : 6, "Pgreq", 1606 wide ? 11 : 6, "Pgreq",
1616 wide ? 7 : 6, "Pgrel", 1607 wide ? 11 : 6, "Pgrel",
1617 "Npage", 1608 wide ? 8 : 6, "Npage",
1618 wide ? " PageSz" : "", 1609 wide ? " PageSz" : "",
1619 "Hiwat", 1610 wide ? 7 : 6, "Hiwat",
1620 "Minpg", 1611 "Minpg",
1621 "Maxpg", 1612 wide ? 7 : 6, "Maxpg",
1622 "Idle", 1613 "Idle",
1623 wide ? " Flags" : "", 1614 wide ? " Flags" : "",
1624 wide ? " Util" : ""); 1615 wide ? " Util" : "");
1625 first = 0; 1616 first = 0;
1626 } 1617 }
1627 if (pp->pr_nget == 0 && !verbose) 1618 if (pp->pr_nget == 0 && !verbose)
1628 continue; 1619 continue;
1629 if (pp->pr_maxpages == UINT_MAX) 1620 if (pp->pr_maxpages == UINT_MAX)
1630 (void)snprintf(maxp, sizeof(maxp), "inf"); 1621 (void)snprintf(maxp, sizeof(maxp), "inf");
1631 else 1622 else
1632 (void)snprintf(maxp, sizeof(maxp), "%u", 1623 (void)snprintf(maxp, sizeof(maxp), "%u",
1633 pp->pr_maxpages); 1624 pp->pr_maxpages);
1634 ovflw = 0; 1625 ovflw = 0;
1635 PRWORD(ovflw, "%-*s", wide ? 16 : 11, 0, name); 1626 PRWORD(ovflw, "%-*s", wide ? 16 : 11, 0, name);
1636 PRWORD(ovflw, " %*u", wide ? 6 : 5, 1, pp->pr_size); 1627 PRWORD(ovflw, " %*u", wide ? 7 : 5, 1, pp->pr_size);
1637 PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nget); 1628 PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nget);
1638 pool_totals.pt_nget += pp->pr_nget; 1629 pool_totals.pt_nget += pp->pr_nget;
1639 PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nfail); 1630 PRWORD(ovflw, " %*lu", wide ? 8 : 5, 1, pp->pr_nfail);
1640 pool_totals.pt_nfail += pp->pr_nfail; 1631 pool_totals.pt_nfail += pp->pr_nfail;
1641 PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nput); 1632 PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nput);
1642 pool_totals.pt_nput += pp->pr_nput; 1633 pool_totals.pt_nput += pp->pr_nput;
1643 if (wide) { 1634 if (wide) {
1644 PRWORD(ovflw, " %*u", 7, 1, pp->pr_nout); 1635 PRWORD(ovflw, " %*u", 9, 1, pp->pr_nout);
1645 pool_totals.pt_nout += pp->pr_nout; 1636 pool_totals.pt_nout += pp->pr_nout;
1646 } 1637 PRWORD(ovflw, " %*u", 9, 1, pp->pr_nitems);
1647 if (wide) { 
1648 PRWORD(ovflw, " %*u", 6, 1, pp->pr_nitems); 
1649 pool_totals.pt_nitems += pp->pr_nitems; 1638 pool_totals.pt_nitems += pp->pr_nitems;
1650 } 1639 }
1651 PRWORD(ovflw, " %*lu", wide ? 7 : 6, 1, pp->pr_npagealloc); 1640 PRWORD(ovflw, " %*lu", wide ? 11 : 6, 1, pp->pr_npagealloc);
1652 pool_totals.pt_npagealloc += pp->pr_npagealloc; 1641 pool_totals.pt_npagealloc += pp->pr_npagealloc;
1653 PRWORD(ovflw, " %*lu", wide ? 7 : 6, 1, pp->pr_npagefree); 1642 PRWORD(ovflw, " %*lu", wide ? 11 : 6, 1, pp->pr_npagefree);
1654 pool_totals.pt_npagefree += pp->pr_npagefree; 1643 pool_totals.pt_npagefree += pp->pr_npagefree;
1655 PRWORD(ovflw, " %*u", 6, 1, pp->pr_npages); 1644 PRWORD(ovflw, " %*u", wide ? 8 : 6, 1, pp->pr_npages);
1656 pool_totals.pt_npages += pp->pr_npages; 1645 pool_totals.pt_npages += pp->pr_npages;
1657 if (wide) 1646 if (wide)
1658 PRWORD(ovflw, " %*u", 7, 1, pa.pa_pagesz); 1647 PRWORD(ovflw, " %*u", 7, 1, pa.pa_pagesz);
1659 PRWORD(ovflw, " %*u", 6, 1, pp->pr_hiwat); 1648 PRWORD(ovflw, " %*u", wide ? 7 : 6, 1, pp->pr_hiwat);
1660 PRWORD(ovflw, " %*u", 6, 1, pp->pr_minpages); 1649 PRWORD(ovflw, " %*u", 6, 1, pp->pr_minpages);
1661 PRWORD(ovflw, " %*s", 6, 1, maxp); 1650 PRWORD(ovflw, " %*s", wide ? 7 : 6, 1, maxp);
1662 PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nidle); 1651 PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nidle);
1663 if (wide) 1652 if (wide)
1664 PRWORD(ovflw, " 0x%0*x", 4, 1, 1653 PRWORD(ovflw, " 0x%0*x", 5, 1,
1665 pp->pr_flags | pp->pr_roflags); 1654 pp->pr_flags | pp->pr_roflags);
1666 1655
1667 this_inuse = pp->pr_nout * pp->pr_size; 1656 this_inuse = pp->pr_nout * pp->pr_size;
1668 this_total = pp->pr_npages * pa.pa_pagesz; 1657 this_total = pp->pr_npages * pa.pa_pagesz;
1669 if (pp->pr_roflags & PR_RECURSIVE) { 1658 if (pp->pr_roflags & PR_RECURSIVE) {
1670 /* 1659 /*
1671 * Don't count in-use memory, since it's part 1660 * Don't count in-use memory, since it's part
1672 * of another pool and will be accounted for 1661 * of another pool and will be accounted for
1673 * there. 1662 * there.
1674 */ 1663 */
1675 total += (this_total - this_inuse); 1664 total += (this_total - this_inuse);
1676 } else { 1665 } else {
1677 inuse += this_inuse; 1666 inuse += this_inuse;
1678 total += this_total; 1667 total += this_total;
1679 } 1668 }
1680 if (wide) { 1669 if (wide) {
1681 if (this_total == 0) 1670 if (this_total == 0)
1682 (void)printf(" ---"); 1671 (void)printf(" ---");
1683 else 1672 else
1684 (void)printf(" %5.1f%%", 1673 (void)printf(" %5.1f%%",
1685 (100.0 * this_inuse) / this_total); 1674 (100.0 * this_inuse) / this_total);
1686 } 1675 }
1687 (void)printf("\n"); 1676 (void)printf("\n");
1688 } 1677 }
1689 if (wide) { 1678 ovflw = 0;
1690 snprintf(in_use, sizeof in_use, "%7"PRId64, pool_totals.pt_nout); 1679 PRWORD(ovflw, "%-*s", wide ? 16 : 11, 0, "Totals");
1691 snprintf(avail, sizeof avail, "%6"PRId64, pool_totals.pt_nitems); 1680 PRWORD(ovflw, " %*s", wide ? 7 : 5, 1, "");
1692 } else { 1681 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pool_totals.pt_nget);
1693 in_use[0] = '\0'; 1682 PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 5, 1, pool_totals.pt_nfail);
1694 avail[0] = '\0'; 1683 PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pool_totals.pt_nput);
1695 } 1684 if (wide) {
1696 (void)printf( 1685 PRWORD(ovflw, " %*" PRIu64, 9, 1, pool_totals.pt_nout);
1697 "%-*s%*s%*"PRId64"%5"PRId64"%*"PRId64"%s%s%*"PRId64"%*"PRId64"%6"PRId64"\n", 1686 PRWORD(ovflw, " %*" PRIu64, 9, 1, pool_totals.pt_nitems);
1698 wide ? 16 : 11, "Totals", 1687 }
1699 wide ? 6 : 5, "", 1688 PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pool_totals.pt_npagealloc);
1700 wide ? 12 : 9, pool_totals.pt_nget, 1689 PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pool_totals.pt_npagefree);
1701 pool_totals.pt_nfail, 1690 PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 6, 1, pool_totals.pt_npages);
1702 wide ? 12 : 9, pool_totals.pt_nput, 1691 (void)printf("\n");
1703 in_use, 
1704 avail, 
1705 wide ? 7 : 6, pool_totals.pt_npagealloc, 
1706 wide ? 7 : 6, pool_totals.pt_npagefree, 
1707 pool_totals.pt_npages); 
1708 1692
1709 inuse /= KILO; 1693 inuse /= KILO;
1710 total /= KILO; 1694 total /= KILO;
1711 (void)printf( 1695 (void)printf(
1712 "\nIn use %ldK, total allocated %ldK; utilization %.1f%%\n", 1696 "\nIn use %ldK, total allocated %ldK; utilization %.1f%%\n",
1713 inuse, total, (100.0 * inuse) / total); 1697 inuse, total, (100.0 * inuse) / total);
1714} 1698}
1715 1699
1716static void 1700static void
1717dopoolcache_sysctl(int verbose) 1701dopoolcache_sysctl(int verbose)
1718{ 1702{
1719 struct pool_sysctl *data, *pp; 1703 struct pool_sysctl *data, *pp;
1720 size_t i, len; 1704 size_t i, len;