diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3 index c0b46bf9e235..acbe409a8456 100644 --- a/lib/libc/gen/getbsize.3 +++ b/lib/libc/gen/getbsize.3 @@ -1,95 +1,94 @@ .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" .Dd June 11, 2017 .Dt GETBSIZE 3 .Os .Sh NAME .Nm getbsize .Nd get preferred block size .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdlib.h .Ft char * .Fn getbsize "int *headerlenp" "long *blocksizep" .Sh DESCRIPTION The .Fn getbsize function returns a preferred block size for reporting by system utilities .Xr df 1 , -.Xr du 1 , -.Xr ls 1 +.Xr du 1 and -.Xr systat 1 , +.Xr ls 1 , based on the value of the .Ev BLOCKSIZE environment variable. .Ev BLOCKSIZE may be specified directly in bytes, or in multiples of a kilobyte by specifying a number followed by ``K'' or ``k'', in multiples of a megabyte by specifying a number followed by ``M'' or ``m'' or in multiples of a gigabyte by specifying a number followed by ``G'' or ``g''. Multiples must be integers. .Pp Valid values of .Ev BLOCKSIZE are 512 bytes to 1 gigabyte. Sizes less than 512 bytes are rounded up to 512 bytes, and sizes greater than 1 GB are rounded down to 1 GB. In each case .Fn getbsize produces a warning message via .Xr warnx 3 . .Pp The .Fn getbsize function returns a pointer to a null-terminated string describing the block size, something like .Dq 1K-blocks . The memory referenced by .Fa headerlenp is filled in with the length of the string (not including the terminating null). The memory referenced by .Fa blocksizep is filled in with block size, in bytes. .Sh SEE ALSO .Xr df 1 , .Xr du 1 , .Xr ls 1 , .Xr systat 1 , .Xr environ 7 .Sh HISTORY The .Fn getbsize function first appeared in .Bx 4.4 . diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 6e3117bece4e..322065f79312 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -1,184 +1,185 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)extern.h 8.1 (Berkeley) 6/6/93 * $FreeBSD$ */ #include #include #include extern struct cmdtab *curcmd; extern struct cmdtab cmdtab[]; extern struct text *xtext; extern WINDOW *wnd; extern char **dr_name; extern char c, *namp, hostname[]; extern double avenrun[3]; extern float *dk_mspw; extern kvm_t *kd; extern long ntext, textp; extern int *dk_select; extern int CMDLINE; extern int dk_ndrive; extern int hz, stathz; extern double hertz; /* sampling frequency for cp_time and dk_time */ extern int col; extern int nhosts; extern int nports; extern int protos; extern int verbose; extern unsigned int delay; struct in_conninfo; extern struct device_selection *dev_select; extern long generation; extern int num_devices; extern int num_selected; extern int num_selections; extern long select_generation; extern struct nlist namelist[]; int checkhost(struct in_conninfo *); int checkport(struct in_conninfo *); void closeicmp(WINDOW *); void closeicmp6(WINDOW *); void closeifstat(WINDOW *); void closeiostat(WINDOW *); void closeip(WINDOW *); void closeip6(WINDOW *); void closekre(WINDOW *); void closenetstat(WINDOW *); void closepigs(WINDOW *); void closeswap(WINDOW *); void closetcp(WINDOW *); int cmdifstat(const char *, const char *); int cmdiostat(const char *, const char *); int cmdkre(const char *, const char *); int cmdnetstat(const char *, const char *); struct cmdtab *lookup(const char *); void command(const char *); void die(int); void display(void); int dkinit(void); int dkcmd(char *, char *); void error(const char *fmt, ...) __printflike(1, 2); void fetchicmp(void); void fetchicmp6(void); void fetchifstat(void); void fetchip(void); void fetchip6(void); void fetchiostat(void); void fetchkre(void); void fetchnetstat(void); void fetchpigs(void); void fetchswap(void); void fetchtcp(void); void getsysctl(const char *, void *, size_t); int ifcmd(const char *cmd, const char *args); int initicmp(void); int initicmp6(void); int initifstat(void); int initip(void); int initip6(void); int initiostat(void); int initkre(void); int initnetstat(void); int initpigs(void); int initswap(void); int inittcp(void); int keyboard(void); int kvm_ckread(void *, void *, int); void labelicmp(void); void labelicmp6(void); void labelifstat(void); void labelip(void); void labelip6(void); void labeliostat(void); void labelkre(void); void labelnetstat(void); void labelpigs(void); void labels(void); void labelswap(void); void labeltcp(void); void load(void); int netcmd(const char *, const char *); void nlisterr(struct nlist []); WINDOW *openicmp(void); WINDOW *openicmp6(void); WINDOW *openifstat(void); WINDOW *openip(void); WINDOW *openip6(void); WINDOW *openiostat(void); WINDOW *openkre(void); WINDOW *opennetstat(void); WINDOW *openpigs(void); WINDOW *openswap(void); WINDOW *opentcp(void); int prefix(const char *, const char *); void reseticmp(void); void reseticmp6(void); void resetip(void); void resetip6(void); void resettcp(void); void showicmp(void); void showicmp6(void); void showifstat(void); void showip(void); void showip6(void); void showiostat(void); void showkre(void); void shownetstat(void); void showpigs(void); void showswap(void); void showtcp(void); void status(void); void suspend(int); char *sysctl_dynread(const char *, size_t *); void sysputpage(WINDOW* , int, int, int, uint64_t, int); void sysputspaces(WINDOW* , int, int, int); void sysputstrs(WINDOW* , int, int, int); +void sysputXs(WINDOW* , int, int, int); void sysputuint64(WINDOW* , int, int, int, uint64_t, int); void sysputwuint64(WINDOW* , int, int, int, uint64_t, int); #define SYSTAT_CMD(name) \ void close ## name(WINDOW *); \ void fetch ## name(void); \ int init ## name(void); \ void label ## name(void); \ WINDOW *open ## name(void); \ void reset ## name(void); \ void show ## name(void) SYSTAT_CMD( zarc ); SYSTAT_CMD( sctp ); diff --git a/usr.bin/systat/swap.c b/usr.bin/systat/swap.c index fc44db7d7d42..29b04df0157f 100644 --- a/usr.bin/systat/swap.c +++ b/usr.bin/systat/swap.c @@ -1,233 +1,181 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1980, 1992, 1993 * The Regents of the University of California. All rights reserved. - * Copyright (c) 2017 Yoshihiro Ota + * Copyright (c) 2017, 2020 Yoshihiro Ota * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #ifdef lint static const char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95"; #endif /* * swapinfo - based on a program of the same name by Kevin Lahey */ #include #include #include #include #include #include #include #include #include #include #include "systat.h" #include "extern.h" #include "devs.h" -static char *header; -static long blocksize; -static int dlen, odlen; -static int hlen; -static int ulen, oulen; -static int pagesize; +static int pathlen; WINDOW * openswap(void) { - return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0)); + + return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0)); } void closeswap(WINDOW *w) { + if (w == NULL) return; wclear(w); wrefresh(w); delwin(w); } /* * The meat of all the swap stuff is stolen from pstat(8)'s * swapmode(), which is based on a program called swapinfo written by * Kevin Lahey . */ #define NSWAP 16 static struct kvm_swap kvmsw[NSWAP]; static int kvnsw, okvnsw; -static void calclens(void); - -#define CONVERT(v) ((int)((int64_t)(v) * pagesize / blocksize)) - -static void -calclens(void) -{ - int i, n; - int len; - - dlen = sizeof("Disk"); - for (i = 0; i < kvnsw; ++i) { - len = strlen(kvmsw[i].ksw_devname); - if (dlen < len) - dlen = len; - } - - ulen = sizeof("Used"); - for (n = CONVERT(kvmsw[kvnsw].ksw_used), len = 2; n /= 10; ++len); - if (ulen < len) - ulen = len; -} - int initswap(void) { static int once = 0; if (once) return (1); - header = getbsize(&hlen, &blocksize); - pagesize = getpagesize(); - if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) { error("systat: kvm_getswapinfo failed"); return (0); } - okvnsw = kvnsw; - - calclens(); - odlen = dlen; - oulen = ulen; - - once = 1; - + pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */; dsinit(12); + once = 1; return (1); } void fetchswap(void) { + okvnsw = kvnsw; if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) { error("systat: kvm_getswapinfo failed"); return; } - odlen = dlen; - oulen = ulen; - calclens(); - struct devinfo *tmp_dinfo; tmp_dinfo = last_dev.dinfo; last_dev.dinfo = cur_dev.dinfo; cur_dev.dinfo = tmp_dinfo; last_dev.snap_time = cur_dev.snap_time; dsgetinfo( &cur_dev ); } void labelswap(void) { const char *name; int i; - fetchswap(); - werase(wnd); - mvwprintw(wnd, 0, 0, "%*s%*s%*s %s", - -dlen, "Disk", hlen, header, ulen, "Used", - "/0% /10 /20 /30 /40 /50 /60 /70 /80 /90 /100"); + dslabel(12, 0, 18); + + if (kvnsw <= 0) { + mvwprintw(wnd, 0, 0, "(swap not configured)"); + return; + } + + mvwprintw(wnd, 0, 0, "%*s%5s %5s %s", + -pathlen, "Device/Path", "Size", "Used", + "|0% /10 /20 /30 /40 / 60\\ 70\\ 80\\ 90\\ 100|"); for (i = 0; i <= kvnsw; ++i) { - if (i == kvnsw) { - if (kvnsw == 1) - break; - name = "Total"; - } else - name = kvmsw[i].ksw_devname; - mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name); + name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname; + mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name); } - dslabel(12, 0, 18); } void showswap(void) { int count; int i; - if (kvnsw != okvnsw || dlen != odlen || ulen != oulen) + if (kvnsw != okvnsw) labelswap(); - for (i = 0; i <= kvnsw; ++i) { - if (i == kvnsw) { - if (kvnsw == 1) - break; - } - - if (kvmsw[i].ksw_total == 0) { - mvwprintw( - wnd, - i + 1, - dlen + hlen + ulen + 1, - "(swap not configured)" - ); - continue; - } - - wmove(wnd, i + 1, dlen); + dsshow(12, 0, 18, &cur_dev, &last_dev); - wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total)); - wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used)); + if (kvnsw <= 0) + return; - count = 50.0 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1; + for (i = 0; i <= kvnsw; ++i) { + sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0); + sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used, + 0); - waddch(wnd, ' '); - while (count--) - waddch(wnd, 'X'); + if (kvmsw[i].ksw_used > 0) { + count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total; + sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count); + } wclrtoeol(wnd); } - dsshow(12, 0, 18, &cur_dev, &last_dev); } diff --git a/usr.bin/systat/sysput.c b/usr.bin/systat/sysput.c index 31c9127a83b7..10401cee772a 100644 --- a/usr.bin/systat/sysput.c +++ b/usr.bin/systat/sysput.c @@ -1,118 +1,129 @@ /*- - * Copyright (c) 2019 Yoshihiro Ota + * Copyright (c) 2019, 2020 Yoshihiro Ota * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "systat.h" #include "extern.h" void sysputspaces(WINDOW *wd, int row, int col, int width) { - static char str40[] = " "; + static char str60[] = " " + " "; - mvwaddstr(wd, row, col, str40 + sizeof(str40) - width - 1); + mvwaddstr(wd, row, col, str60 + sizeof(str60) - width - 1); } void sysputstrs(WINDOW *wd, int row, int col, int width) { - static char str40[] = "****************************************"; + static char str60[] = "********************" + "****************************************"; - mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1); + mvwaddstr(wnd, row, col, str60 + sizeof(str60) - width - 1); +} + +void +sysputXs(WINDOW *wd, int row, int col, int width) +{ + static char str60[] = "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + + mvwaddstr(wnd, row, col, str60 + sizeof(str60) - width - 1); } void sysputuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags) { char unit, *ptr, *start, wrtbuf[width + width + 1]; int len; unit = 0; start = wrtbuf; flags |= HN_NOSPACE; if (val > INT64_MAX) goto error; else len = humanize_number(&wrtbuf[width], width + 1, val, "", HN_AUTOSCALE, flags); if (len < 0) goto error; else if (len < width) memset(wrtbuf + len, ' ', width - len); start += len; mvwaddstr(wd, row, col, start); return; error: sysputstrs(wd, row, col, width); } void sysputwuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags) { if(val == 0) sysputspaces(wd, row, col, width); else sysputuint64(wd, row, col, width, val, flags); } static int calc_page_shift() { u_int page_size; int shifts; shifts = 0; GETSYSCTL("vm.stats.vm.v_page_size", page_size); for(; page_size > 1; page_size >>= 1) shifts++; return shifts; } void sysputpage(WINDOW *wd, int row, int col, int width, uint64_t pages, int flags) { static int shifts = 0; if (shifts == 0) shifts = calc_page_shift(); pages <<= shifts; sysputuint64(wd, row, col, width, pages, flags); }