diff options
author | Can Erkin Acar <canacar@cvs.openbsd.org> | 2008-11-02 06:23:29 +0000 |
---|---|---|
committer | Can Erkin Acar <canacar@cvs.openbsd.org> | 2008-11-02 06:23:29 +0000 |
commit | ba01741f59523b781311fbbeb62e1818153a4836 (patch) | |
tree | 189f7cc9af7c0ce6aea9bd3a474cb6125cb90b8d /usr.bin/systat | |
parent | 6ebb14a8cb39d39392bf0901d2e06995511d02f0 (diff) |
Add a view that displays pool(9) information. Idea and ok deraadt@
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/systat/main.c | 3 | ||||
-rw-r--r-- | usr.bin/systat/pool.c | 256 | ||||
-rw-r--r-- | usr.bin/systat/systat.1 | 14 | ||||
-rw-r--r-- | usr.bin/systat/systat.h | 3 |
5 files changed, 272 insertions, 8 deletions
diff --git a/usr.bin/systat/Makefile b/usr.bin/systat/Makefile index 3cc4ff83bcf..071ebac678e 100644 --- a/usr.bin/systat/Makefile +++ b/usr.bin/systat/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.20 2008/06/12 22:26:01 canacar Exp $ +# $OpenBSD: Makefile,v 1.21 2008/11/02 06:23:28 canacar Exp $ PROG= systat @@ -8,7 +8,7 @@ CFLAGS+=-DNOKVM CPPFLAGS+=-I${.CURDIR}/../../usr.bin/vmstat CPPFLAGS+=-I${.CURDIR}/../../sbin/pfctl SRCS= dkstats.c engine.c if.c iostat.c main.c mbufs.c netstat.c \ - pigs.c sensors.c swap.c vmstat.c pftop.c cache.c pf.c + pigs.c sensors.c swap.c vmstat.c pftop.c cache.c pf.c pool.c DPADD= ${LIBCURSES} ${LIBM} ${LIBKVM} LDADD= -lcurses -lm -lkvm diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index be6ff8fde0f..002b814051f 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.47 2008/11/01 00:41:11 canacar Exp $ */ +/* $Id: main.c,v 1.48 2008/11/02 06:23:28 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * Copyright (c) 2001 Daniel Hartmeier @@ -354,6 +354,7 @@ initialize(void) initswap(); initpftop(); initpf(); + initpool(); } void diff --git a/usr.bin/systat/pool.c b/usr.bin/systat/pool.c new file mode 100644 index 00000000000..c6bbede69dc --- /dev/null +++ b/usr.bin/systat/pool.c @@ -0,0 +1,256 @@ +/* $OpenBSD: pool.c,v 1.1 2008/11/02 06:23:28 canacar Exp $ */ +/* + * Copyright (c) 2008 Can Erkin Acar <canacar@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/pool.h> +#include <errno.h> +#include <stdlib.h> + +#include "systat.h" + +void print_pool(void); +int read_pool(void); +void sort_pool(void); +int select_pool(void); +void showpool(int k); + +/* qsort callbacks */ +int sort_name_callback(const void *s1, const void *s2); + +struct pool_info { + char name[32]; + struct pool pool; +}; + + +int num_pools = 0; +struct pool_info *pools = NULL; + + +field_def fields_pool[] = { + {"NAME", 11, 32, 1, FLD_ALIGN_LEFT, -1, 0, 0, 0}, + {"SIZE", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"REQUESTS", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"FAIL", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"INUSE", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"PGREQ", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"PGREL", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"NPAGE", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"HIWAT", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"MINPG", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"MAXPG", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0}, + {"IDLE", 8, 24, 1, FLD_ALIGN_RIGHT, -1, 0, 0, 0} +}; + + +#define FIELD_ADDR(x) (&fields_pool[x]) + +#define FLD_POOL_NAME FIELD_ADDR(0) +#define FLD_POOL_SIZE FIELD_ADDR(1) +#define FLD_POOL_REQS FIELD_ADDR(2) +#define FLD_POOL_FAIL FIELD_ADDR(3) +#define FLD_POOL_INUSE FIELD_ADDR(4) +#define FLD_POOL_PGREQ FIELD_ADDR(5) +#define FLD_POOL_PGREL FIELD_ADDR(6) +#define FLD_POOL_NPAGE FIELD_ADDR(7) +#define FLD_POOL_HIWAT FIELD_ADDR(8) +#define FLD_POOL_MINPG FIELD_ADDR(9) +#define FLD_POOL_MAXPG FIELD_ADDR(10) +#define FLD_POOL_IDLE FIELD_ADDR(11) + +/* Define views */ +field_def *view_pool_0[] = { + FLD_POOL_NAME, FLD_POOL_SIZE, FLD_POOL_REQS, FLD_POOL_FAIL, + FLD_POOL_INUSE, FLD_POOL_PGREQ, FLD_POOL_PGREL, FLD_POOL_NPAGE, + FLD_POOL_HIWAT, FLD_POOL_MINPG, FLD_POOL_MAXPG, FLD_POOL_IDLE, NULL +}; + +order_type pool_order_list[] = { + {"name", "name", 0, sort_name_callback}, + {NULL, NULL, 0, NULL} +}; + +/* Define view managers */ +struct view_manager pool_mgr = { + "Pool", select_pool, read_pool, sort_pool, print_header, + print_pool, keyboard_callback, pool_order_list, pool_order_list +}; + +field_view views_pool[] = { + {view_pool_0, "pool", '5', &pool_mgr}, + {NULL, NULL, 0, NULL} +}; + + +int +sort_name_callback(const void *s1, const void *s2) +{ + struct pool_info *p1, *p2; + p1 = (struct pool_info *)s1; + p2 = (struct pool_info *)s2; + + return strcmp(p1->name, p2->name); +} + +void +sort_pool(void) +{ + order_type *ordering; + + if (curr_mgr == NULL) + return; + + ordering = curr_mgr->order_curr; + + if (ordering == NULL) + return; + if (ordering->func == NULL) + return; + if (pools == NULL) + return; + if (num_pools <= 0) + return; + + qsort(pools, num_pools, sizeof(struct pool_info), ordering->func); +} + +int +select_pool(void) +{ + num_disp = num_pools; + return (0); +} + +int +read_pool(void) +{ + int mib[4], np, i; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_POOL; + mib[2] = KERN_POOL_NPOOLS; + size = sizeof(np); + + if (sysctl(mib, 3, &np, &size, NULL, 0) < 0) { + error("sysctl(npools): %s", strerror(errno)); + return (-1); + } + + if (np <= 0) { + num_pools = 0; + return (0); + } + + if (np > num_pools || pools == NULL) { + struct pool_info *p = realloc(pools, sizeof(*pools) * np); + if (p == NULL) { + error("realloc: %s", strerror(errno)); + return (-1); + } + pools = p; + num_pools = np; + } + + for (i = 0; i < num_pools; i++) { + mib[0] = CTL_KERN; + mib[1] = KERN_POOL; + mib[2] = KERN_POOL_POOL; + mib[3] = i + 1; + size = sizeof(struct pool); + if (sysctl(mib, 4, &pools[i].pool, &size, NULL, 0) < 0) { + error("sysctl(pool): %s", strerror(errno)); + break; + } + mib[2] = KERN_POOL_NAME; + size = sizeof(pools[i].name); + if (sysctl(mib, 4, &pools[i].name, &size, NULL, 0) < 0) { + error("sysctl(pool_name): %s", strerror(errno)); + break; + } + } + + if (i != num_pools) { + memset(pools, 0, sizeof(*pools) * num_pools); + return (-1); + } + + return 0; +} + + +void +print_pool(void) +{ + int n, count = 0; + + if (pools == NULL) + return; + + for (n = dispstart; n < num_disp; n++) { + showpool(n); + count++; + if (maxprint > 0 && count >= maxprint) + break; + } +} + +int +initpool(void) +{ + field_view *v; + + for (v = views_pool; v->name != NULL; v++) + add_view(v); + + read_pool(); + + return(0); +} + +void +showpool(int k) +{ + struct pool_info *p = pools + k; + + if (k < 0 || k >= num_pools) + return; + + print_fld_str(FLD_POOL_NAME, p->name); + print_fld_uint(FLD_POOL_SIZE, p->pool.pr_size); + + print_fld_size(FLD_POOL_REQS, p->pool.pr_nget); + print_fld_size(FLD_POOL_FAIL, p->pool.pr_nfail); + print_fld_ssize(FLD_POOL_INUSE, p->pool.pr_nget - p->pool.pr_nput); + print_fld_size(FLD_POOL_PGREQ, p->pool.pr_npagealloc); + print_fld_size(FLD_POOL_PGREL, p->pool.pr_npagefree); + + print_fld_size(FLD_POOL_NPAGE, p->pool.pr_npages); + print_fld_size(FLD_POOL_HIWAT, p->pool.pr_hiwat); + print_fld_size(FLD_POOL_MINPG, p->pool.pr_minpages); + + if (p->pool.pr_maxpages == UINT_MAX) + print_fld_str(FLD_POOL_MAXPG, "inf"); + else + print_fld_size(FLD_POOL_MAXPG, p->pool.pr_maxpages); + + print_fld_size(FLD_POOL_IDLE, p->pool.pr_nidle); + + end_line(); +} diff --git a/usr.bin/systat/systat.1 b/usr.bin/systat/systat.1 index 9413e95ebfb..151f3aee7d6 100644 --- a/usr.bin/systat/systat.1 +++ b/usr.bin/systat/systat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: systat.1,v 1.67 2008/11/01 07:43:45 jmc Exp $ +.\" $OpenBSD: systat.1,v 1.68 2008/11/02 06:23:28 canacar Exp $ .\" $NetBSD: systat.1,v 1.6 1996/05/10 23:16:39 thorpej Exp $ .\" .\" Copyright (c) 1985, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)systat.1 8.2 (Berkeley) 12/30/93 .\" -.Dd $Mdocdate: November 1 2008 $ +.Dd $Mdocdate: November 2 2008 $ .Dt SYSTAT 1 .Os .Sh NAME @@ -119,9 +119,10 @@ argument expects to be one of: .Ic swap , .Ic states , .Ic rules , -.Ic queues +.Ic queues , +.Ic pf or -.Ic pf . +.Ic pool . These displays can also be requested interactively and are described in full detail below. .Ar view @@ -324,6 +325,11 @@ processor is scheduled to user processes, the remaining time is accounted to the .Dq idle process. +.It Ic pool +Display kernel +.Xr pool 9 +statistics similar to the output of +.Cm vmstat Fl m . .It Ic queues Display statistics about the active .Xr altq 9 diff --git a/usr.bin/systat/systat.h b/usr.bin/systat/systat.h index dfd6742128a..cb0c60e0770 100644 --- a/usr.bin/systat/systat.h +++ b/usr.bin/systat/systat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systat.h,v 1.9 2008/06/12 22:26:01 canacar Exp $ */ +/* $OpenBSD: systat.h,v 1.10 2008/11/02 06:23:28 canacar Exp $ */ /* $NetBSD: systat.h,v 1.2 1995/01/20 08:52:14 jtc Exp $ */ /*- @@ -82,6 +82,7 @@ int initpigs(void); int initswap(void); int initvmstat(void); int initpf(void); +int initpool(void); void error(const char *fmt, ...); void nlisterr(struct nlist []); |