Index: stable/12/usr.bin/systat/Makefile =================================================================== --- stable/12/usr.bin/systat/Makefile (revision 361895) +++ stable/12/usr.bin/systat/Makefile (revision 361896) @@ -1,21 +1,21 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD$ .include PROG= systat -SRCS= cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c \ +SRCS= cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c sysput.c \ netcmds.c netstat.c pigs.c swap.c icmp.c \ mode.c ip.c sctp.c tcp.c zarc.c \ vmstat.c convtbl.c ifcmds.c ifstat.c .if ${MK_INET6_SUPPORT} != "no" SRCS+= icmp6.c ip6.c CFLAGS+= -DINET6 .endif WARNS?= 1 LIBADD= ncursesw m devstat kvm util .include Index: stable/12/usr.bin/systat/extern.h =================================================================== --- stable/12/usr.bin/systat/extern.h (revision 361895) +++ stable/12/usr.bin/systat/extern.h (revision 361896) @@ -1,179 +1,184 @@ /*- * 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 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 ); +SYSTAT_CMD( sctp ); Index: stable/12/usr.bin/systat/fetch.c =================================================================== --- stable/12/usr.bin/systat/fetch.c (revision 361895) +++ stable/12/usr.bin/systat/fetch.c (revision 361896) @@ -1,139 +1,141 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1980, 1992, 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. */ #include __FBSDID("$FreeBSD$"); #ifdef lint static const char sccsid[] = "@(#)fetch.c 8.1 (Berkeley) 6/6/93"; #endif #include #include #include #include #include #include #include "systat.h" #include "extern.h" int kvm_ckread(void *a, void *b, int l) { if (kvm_read(kd, (u_long)a, b, l) != l) { if (verbose) error("error reading kmem at %p", a); return (0); } else return (1); } -void getsysctl(const char *name, void *ptr, size_t len) +void +getsysctl(const char *name, void *ptr, size_t len) { size_t nlen = len; + if (sysctlbyname(name, ptr, &nlen, NULL, 0) != 0) { error("sysctl(%s...) failed: %s", name, strerror(errno)); } if (nlen != len) { error("sysctl(%s...) expected %zu, got %zu", name, len, nlen); } } /* * Read sysctl data with variable size. Try some times (with increasing * buffers), fail if still too small. * This is needed sysctls with possibly raplidly increasing data sizes, * but imposes little overhead in the case of constant sizes. * Returns NULL on error, or a pointer to freshly malloc()'ed memory that holds * the requested data. * If szp is not NULL, the size of the returned data will be written into *szp. */ /* Some defines: Number of tries. */ #define SD_NTRIES 10 /* Percent of over-allocation (initial) */ #define SD_MARGIN 10 /* * Factor for over-allocation in percent (the margin is increased by this on * any failed try). */ #define SD_FACTOR 50 /* Maximum supported MIB depth */ #define SD_MAXMIB 16 char * sysctl_dynread(const char *n, size_t *szp) { char *rv = NULL; int mib[SD_MAXMIB]; size_t mibsz = SD_MAXMIB; size_t mrg = SD_MARGIN; size_t sz; int i; /* cache the MIB */ if (sysctlnametomib(n, mib, &mibsz) == -1) { if (errno == ENOMEM) { error("XXX: SD_MAXMIB too small, please bump!"); } return NULL; } for (i = 0; i < SD_NTRIES; i++) { /* get needed buffer size */ if (sysctl(mib, mibsz, NULL, &sz, NULL, 0) == -1) break; sz += sz * mrg / 100; if ((rv = (char *)malloc(sz)) == NULL) { error("Out of memory!"); return NULL; } if (sysctl(mib, mibsz, rv, &sz, NULL, 0) == -1) { free(rv); rv = NULL; if (errno == ENOMEM) { mrg += mrg * SD_FACTOR / 100; } else break; } else { /* success */ if (szp != NULL) *szp = sz; break; } } return rv; } Index: stable/12/usr.bin/systat/main.c =================================================================== --- stable/12/usr.bin/systat/main.c (revision 361895) +++ stable/12/usr.bin/systat/main.c (revision 361896) @@ -1,387 +1,378 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1980, 1992, 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. */ #include __FBSDID("$FreeBSD$"); #ifdef lint static const char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1980, 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "systat.h" #include "extern.h" static int dellave; kvm_t *kd; sig_t sigtstpdfl; double avenrun[3]; int col; unsigned int delay = 5000000; /* in microseconds */ int verbose = 1; /* to report kvm read errs */ struct clockinfo clkinfo; double hertz; char c; char *namp; char hostname[MAXHOSTNAMELEN]; WINDOW *wnd; int CMDLINE; int use_kvm = 1; static WINDOW *wload; /* one line window for load average */ struct cmdentry { SLIST_ENTRY(cmdentry) link; char *cmd; /* Command name */ char *argv; /* Arguments vector for a command */ }; SLIST_HEAD(, cmdentry) commands; static void parse_cmd_args (int argc, char **argv) { int in_command = 0; struct cmdentry *cmd = NULL; double t; while (argc) { if (argv[0][0] == '-') { if (in_command) SLIST_INSERT_HEAD(&commands, cmd, link); if (memcmp(argv[0], "--", 3) == 0) { in_command = 0; /*-- ends a command explicitly*/ argc --, argv ++; continue; } cmd = calloc(1, sizeof(struct cmdentry)); if (cmd == NULL) errx(1, "memory allocating failure"); cmd->cmd = strdup(&argv[0][1]); if (cmd->cmd == NULL) errx(1, "memory allocating failure"); in_command = 1; } else if (!in_command) { t = strtod(argv[0], NULL) * 1000000.0; if (t > 0 && t < (double)UINT_MAX) delay = (unsigned int)t; } else if (cmd != NULL) { cmd->argv = strdup(argv[0]); if (cmd->argv == NULL) errx(1, "memory allocating failure"); in_command = 0; SLIST_INSERT_HEAD(&commands, cmd, link); } else errx(1, "invalid arguments list"); argc--, argv++; } if (in_command && cmd != NULL) SLIST_INSERT_HEAD(&commands, cmd, link); } int main(int argc, char **argv) { char errbuf[_POSIX2_LINE_MAX], dummy; size_t size; struct cmdentry *cmd = NULL; (void) setlocale(LC_ALL, ""); SLIST_INIT(&commands); argc--, argv++; if (argc > 0) { if (argv[0][0] == '-') { struct cmdtab *p; p = lookup(&argv[0][1]); if (p == (struct cmdtab *)-1) errx(1, "%s: ambiguous request", &argv[0][1]); if (p == (struct cmdtab *)0) errx(1, "%s: unknown request", &argv[0][1]); curcmd = p; argc--, argv++; } parse_cmd_args (argc, argv); } kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); if (kd != NULL) { /* * Try to actually read something, we may be in a jail, and * have /dev/null opened as /dev/mem. */ if (kvm_nlist(kd, namelist) != 0 || namelist[0].n_value == 0 || kvm_read(kd, namelist[0].n_value, &dummy, sizeof(dummy)) != sizeof(dummy)) { kvm_close(kd); kd = NULL; } } if (kd == NULL) { /* * Maybe we are lacking permissions? Retry, this time with bogus * devices. We can now use sysctl only. */ use_kvm = 0; kd = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, _PATH_DEVNULL, O_RDONLY, errbuf); if (kd == NULL) { error("%s", errbuf); exit(1); } } signal(SIGHUP, die); signal(SIGINT, die); signal(SIGQUIT, die); signal(SIGTERM, die); /* * Initialize display. Load average appears in a one line * window of its own. Current command's display appears in * an overlapping sub-window of stdscr configured by the display * routines to minimize update work by curses. */ initscr(); CMDLINE = LINES - 1; wnd = (*curcmd->c_open)(); if (wnd == NULL) { warnx("couldn't initialize display"); die(0); } wload = newwin(1, 0, 1, 20); if (wload == NULL) { warnx("couldn't set up load average window"); die(0); } gethostname(hostname, sizeof (hostname)); size = sizeof(clkinfo); if (sysctlbyname("kern.clockrate", &clkinfo, &size, NULL, 0) || size != sizeof(clkinfo)) { error("kern.clockrate"); die(0); } hertz = clkinfo.stathz; (*curcmd->c_init)(); curcmd->c_flags |= CF_INIT; labels(); if (curcmd->c_cmd != NULL) SLIST_FOREACH (cmd, &commands, link) if (!curcmd->c_cmd(cmd->cmd, cmd->argv)) warnx("command is not understood"); dellave = 0.0; display(); noecho(); crmode(); keyboard(); /*NOTREACHED*/ return EXIT_SUCCESS; } void labels(void) { if (curcmd->c_flags & CF_LOADAV) { mvaddstr(0, 20, "/0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /10"); mvaddstr(1, 5, "Load Average"); } if (curcmd->c_flags & CF_ZFSARC) { mvaddstr(0, 20, " Total MFU MRU Anon Hdr L2Hdr Other"); mvaddstr(1, 5, "ZFS ARC "); } (*curcmd->c_label)(); #ifdef notdef mvprintw(21, 25, "CPU usage on %s", hostname); #endif refresh(); } void display(void) { uint64_t arc_stat; int i, j; /* Get the load average over the last minute. */ (void) getloadavg(avenrun, nitems(avenrun)); (*curcmd->c_fetch)(); if (curcmd->c_flags & CF_LOADAV) { j = 5.0*avenrun[0] + 0.5; dellave -= avenrun[0]; if (dellave >= 0.0) c = '<'; else { c = '>'; dellave = -dellave; } if (dellave < 0.1) c = '|'; dellave = avenrun[0]; wmove(wload, 0, 0); wclrtoeol(wload); for (i = MIN(j, 50); i > 0; i--) waddch(wload, c); if (j > 50) wprintw(wload, " %4.1f", avenrun[0]); } if (curcmd->c_flags & CF_ZFSARC) { uint64_t arc[7] = {}; size_t size = sizeof(arc[0]); if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc[0], &size, NULL, 0) == 0 ) { GETSYSCTL("vfs.zfs.mfu_size", arc[1]); GETSYSCTL("vfs.zfs.mru_size", arc[2]); GETSYSCTL("vfs.zfs.anon_size", arc[3]); GETSYSCTL("kstat.zfs.misc.arcstats.hdr_size", arc[4]); GETSYSCTL("kstat.zfs.misc.arcstats.l2_hdr_size", arc[5]); GETSYSCTL("kstat.zfs.misc.arcstats.bonus_size", arc[6]); GETSYSCTL("kstat.zfs.misc.arcstats.dnode_size", arc_stat); arc[6] += arc_stat; GETSYSCTL("kstat.zfs.misc.arcstats.dbuf_size", arc_stat); arc[6] += arc_stat; wmove(wload, 0, 0); wclrtoeol(wload); - for (i = 0 ; i < nitems(arc); i++) { - if (arc[i] > 10llu * 1024 * 1024 * 1024 ) { - wprintw(wload, "%7lluG", arc[i] >> 30); - } - else if (arc[i] > 10 * 1024 * 1024 ) { - wprintw(wload, "%7lluM", arc[i] >> 20); - } - else { - wprintw(wload, "%7lluK", arc[i] >> 10); - } - } + for (i = 0 ; i < nitems(arc); i++) + sysputuint64(wload, 0, i*8+2, 6, arc[i], 0); } } (*curcmd->c_refresh)(); if (curcmd->c_flags & (CF_LOADAV |CF_ZFSARC)) wrefresh(wload); wrefresh(wnd); move(CMDLINE, col); refresh(); } void load(void) { (void) getloadavg(avenrun, nitems(avenrun)); mvprintw(CMDLINE, 0, "%4.1f %4.1f %4.1f", avenrun[0], avenrun[1], avenrun[2]); clrtoeol(); } void die(int signo __unused) { move(CMDLINE, 0); clrtoeol(); refresh(); endwin(); exit(0); } #include void error(const char *fmt, ...) { va_list ap; char buf[255]; int oy, ox; va_start(ap, fmt); if (wnd) { getyx(stdscr, oy, ox); (void) vsnprintf(buf, sizeof(buf), fmt, ap); clrtoeol(); standout(); mvaddstr(CMDLINE, 0, buf); standend(); move(oy, ox); refresh(); } else { (void) vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); } va_end(ap); } void nlisterr(struct nlist n_list[]) { int i, n; n = 0; clear(); mvprintw(2, 10, "systat: nlist: can't find following symbols:"); for (i = 0; n_list[i].n_name != NULL && *n_list[i].n_name != '\0'; i++) if (n_list[i].n_value == 0) mvprintw(2 + ++n, 10, "%s", n_list[i].n_name); move(CMDLINE, 0); clrtoeol(); refresh(); endwin(); exit(1); } Index: stable/12/usr.bin/systat/sysput.c =================================================================== --- stable/12/usr.bin/systat/sysput.c (nonexistent) +++ stable/12/usr.bin/systat/sysput.c (revision 361896) @@ -0,0 +1,118 @@ +/*- + * Copyright (c) 2019 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[] = " "; + + mvwaddstr(wd, row, col, str40 + sizeof(str40) - width - 1); +} + +void +sysputstrs(WINDOW *wd, int row, int col, int width) +{ + static char str40[] = "****************************************"; + + mvwaddstr(wnd, row, col, str40 + sizeof(str40) - 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); +} Property changes on: stable/12/usr.bin/systat/sysput.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/12/usr.bin/systat/vmstat.c =================================================================== --- stable/12/usr.bin/systat/vmstat.c (revision 361895) +++ stable/12/usr.bin/systat/vmstat.c (revision 361896) @@ -1,834 +1,831 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1983, 1989, 1992, 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. */ #include __FBSDID("$FreeBSD$"); #ifdef lint static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; #endif /* * Cursed vmstat -- from Robert Elz. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "systat.h" #include "extern.h" #include "devs.h" static struct Info { long time[CPUSTATES]; uint64_t v_swtch; /* context switches */ uint64_t v_trap; /* calls to trap */ uint64_t v_syscall; /* calls to syscall() */ uint64_t v_intr; /* device interrupts */ uint64_t v_soft; /* software interrupts */ /* * Virtual memory activity. */ uint64_t v_vm_faults; /* number of address memory faults */ uint64_t v_io_faults; /* page faults requiring I/O */ uint64_t v_cow_faults; /* number of copy-on-writes */ uint64_t v_zfod; /* pages zero filled on demand */ uint64_t v_ozfod; /* optimized zero fill pages */ uint64_t v_swapin; /* swap pager pageins */ uint64_t v_swapout; /* swap pager pageouts */ uint64_t v_swappgsin; /* swap pager pages paged in */ uint64_t v_swappgsout; /* swap pager pages paged out */ uint64_t v_vnodein; /* vnode pager pageins */ uint64_t v_vnodeout; /* vnode pager pageouts */ uint64_t v_vnodepgsin; /* vnode_pager pages paged in */ uint64_t v_vnodepgsout; /* vnode pager pages paged out */ uint64_t v_intrans; /* intransit blocking page faults */ uint64_t v_reactivated; /* number of pages reactivated by pagedaemon */ uint64_t v_pdwakeups; /* number of times daemon has awaken from sleep */ uint64_t v_pdpages; /* number of pages analyzed by daemon */ uint64_t v_dfree; /* pages freed by daemon */ uint64_t v_pfree; /* pages freed by exiting processes */ uint64_t v_tfree; /* total pages freed */ /* * Distribution of page usages. */ - u_int v_page_size; /* page size in bytes */ u_int v_free_count; /* number of pages free */ u_int v_wire_count; /* number of pages wired down */ u_int v_active_count; /* number of pages active */ u_int v_inactive_count; /* number of pages inactive */ u_int v_laundry_count; /* number of pages in laundry queue */ u_long v_kmem_map_size; /* Current kmem allocation size */ struct vmtotal Total; struct nchstats nchstats; long nchcount; long *intrcnt; long bufspace; int desiredvnodes; long numvnodes; long freevnodes; int numdirtybuffers; } s, s1, s2, z; static u_long kmem_size; static u_int v_page_count; #define total s.Total #define nchtotal s.nchstats #define oldnchtotal s1.nchstats static enum state { BOOT, TIME, RUN } state = TIME; enum divisor { IEC = 0, SI = HN_DIVISOR_1000 }; static void allocinfo(struct Info *); static void copyinfo(struct Info *, struct Info *); static float cputime(int); static void do_putuint64(uint64_t, int, int, int, int); static void getinfo(struct Info *); static void putuint64(uint64_t, int, int, int); static int ucount(void); static int ncpu; static char buf[26]; static time_t t; static double etime; static int nintr; static long *intrloc; static char **intrname; static int nextintsrow; WINDOW * openkre(void) { return (stdscr); } void closekre(WINDOW *w) { if (w == NULL) return; wclear(w); wrefresh(w); } /* * These constants define where the major pieces are laid out */ #define STATROW 0 /* uses 1 row and 67 cols */ #define STATCOL 0 #define MEMROW 2 /* uses 4 rows and 45 cols */ #define MEMCOL 0 -#define PAGEROW 2 /* uses 4 rows and 30 cols */ +#define PAGEROW 1 /* uses 4 rows and 30 cols */ #define PAGECOL 47 -#define INTSROW 6 /* uses all rows to bottom and 16 cols */ +#define INTSROW 5 /* uses all rows to bottom and 16 cols */ #define INTSCOL 64 #define PROCSROW 6 /* uses 3 rows and 19 cols */ #define PROCSCOL 0 #define GENSTATROW 7 /* uses 2 rows and 29 cols */ #define GENSTATCOL 21 -#define VMSTATROW 7 /* uses 17 rows and 12-14 cols */ +#define VMSTATROW 5 /* uses 17 rows and 12-14 cols */ #define VMSTATCOL 49 /* actually 50-51 for some fields */ #define GRAPHROW 10 /* uses 3 rows and 49-51 cols */ #define GRAPHCOL 0 #define VNSTATROW 13 /* uses 4 rows and 13 columns */ #define VNSTATCOL 35 #define NAMEIROW 14 /* uses 3 rows and 32 cols */ #define NAMEICOL 0 #define DISKROW 18 /* uses 5 rows and 47 cols (for 7 drives) */ #define DISKCOL 0 #define DRIVESPACE 7 /* max # for space */ #define MAXDRIVES DRIVESPACE /* max # to display */ int initkre(void) { char *cp, *cp1, *cp2, *intrnamebuf, *nextcp; int i; size_t sz; if (dsinit(MAXDRIVES) != 1) return(0); if (nintr == 0) { if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) { error("sysctl(hw.intrcnt...) failed: %s", strerror(errno)); return (0); } nintr = sz / sizeof(u_long); intrloc = calloc(nintr, sizeof (long)); intrname = calloc(nintr, sizeof (char *)); intrnamebuf = sysctl_dynread("hw.intrnames", NULL); if (intrnamebuf == NULL || intrname == NULL || intrloc == NULL) { error("Out of memory"); if (intrnamebuf) free(intrnamebuf); if (intrname) free(intrname); if (intrloc) free(intrloc); nintr = 0; return(0); } for (cp = intrnamebuf, i = 0; i < nintr; i++) { nextcp = cp + strlen(cp) + 1; /* Discard trailing spaces. */ for (cp1 = nextcp - 1; cp1 > cp && *(cp1 - 1) == ' '; ) *--cp1 = '\0'; /* Convert "irqN: name" to "name irqN". */ if (strncmp(cp, "irq", 3) == 0) { cp1 = cp + 3; while (isdigit((u_char)*cp1)) cp1++; if (cp1 != cp && *cp1 == ':' && *(cp1 + 1) == ' ') { sz = strlen(cp); *cp1 = '\0'; cp1 = cp1 + 2; cp2 = strdup(cp); bcopy(cp1, cp, sz - (cp1 - cp) + 1); if (sz <= 10 + 4) { strcat(cp, " "); strcat(cp, cp2 + 3); } free(cp2); } } /* * Convert "name irqN" to "name N" if the former is * longer than the field width. */ if ((cp1 = strstr(cp, "irq")) != NULL && strlen(cp) > 10) bcopy(cp1 + 3, cp1, strlen(cp1 + 3) + 1); intrname[i] = cp; cp = nextcp; } nextintsrow = INTSROW + 2; allocinfo(&s); allocinfo(&s1); allocinfo(&s2); allocinfo(&z); } GETSYSCTL("vm.kmem_size", kmem_size); GETSYSCTL("vm.stats.vm.v_page_count", v_page_count); getinfo(&s2); copyinfo(&s2, &s1); return(1); } void fetchkre(void) { time_t now; struct tm *tp; static int d_first = -1; if (d_first < 0) d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); time(&now); tp = localtime(&now); (void) strftime(buf, sizeof(buf), d_first ? "%e %b %R" : "%b %e %R", tp); getinfo(&s); } void labelkre(void) { int i, j; clear(); mvprintw(STATROW, STATCOL + 6, "users Load"); mvprintw(STATROW + 1, STATCOL + 3, "Mem usage: %%Phy %%Kmem"); - mvprintw(MEMROW, MEMCOL, "Mem: KB REAL VIRTUAL"); + mvprintw(MEMROW, MEMCOL, "Mem: REAL VIRTUAL"); mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); mvprintw(MEMROW + 2, MEMCOL, "Act"); mvprintw(MEMROW + 3, MEMCOL, "All"); mvprintw(MEMROW + 1, MEMCOL + 41, "Free"); mvprintw(PAGEROW, PAGECOL, " VN PAGER SWAP PAGER"); mvprintw(PAGEROW + 1, PAGECOL, " in out in out"); mvprintw(PAGEROW + 2, PAGECOL, "count"); mvprintw(PAGEROW + 3, PAGECOL, "pages"); mvprintw(INTSROW, INTSCOL + 1, "Interrupts"); mvprintw(INTSROW + 1, INTSCOL + 6, "total"); mvprintw(VMSTATROW, VMSTATCOL + 9, "ioflt"); mvprintw(VMSTATROW + 1, VMSTATCOL + 9, "cow"); mvprintw(VMSTATROW + 2, VMSTATCOL + 9, "zfod"); mvprintw(VMSTATROW + 3, VMSTATCOL + 9, "ozfod"); mvprintw(VMSTATROW + 4, VMSTATCOL + 9 - 1, "%%ozfod"); mvprintw(VMSTATROW + 5, VMSTATCOL + 9, "daefr"); mvprintw(VMSTATROW + 6, VMSTATCOL + 9, "prcfr"); mvprintw(VMSTATROW + 7, VMSTATCOL + 9, "totfr"); mvprintw(VMSTATROW + 8, VMSTATCOL + 9, "react"); mvprintw(VMSTATROW + 9, VMSTATCOL + 9, "pdwak"); mvprintw(VMSTATROW + 10, VMSTATCOL + 9, "pdpgs"); mvprintw(VMSTATROW + 11, VMSTATCOL + 9, "intrn"); mvprintw(VMSTATROW + 12, VMSTATCOL + 9, "wire"); mvprintw(VMSTATROW + 13, VMSTATCOL + 9, "act"); mvprintw(VMSTATROW + 14, VMSTATCOL + 9, "inact"); mvprintw(VMSTATROW + 15, VMSTATCOL + 9, "laund"); mvprintw(VMSTATROW + 16, VMSTATCOL + 9, "free"); if (LINES - 1 > VMSTATROW + 17) mvprintw(VMSTATROW + 17, VMSTATCOL + 9, "buf"); mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); mvprintw(GRAPHROW, GRAPHCOL, " . %%Sys . %%Intr . %%User . %%Nice . %%Idle"); mvprintw(PROCSROW, PROCSCOL, "Proc:"); mvprintw(PROCSROW + 1, PROCSCOL, " r p d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, "| | | | | | | | | | |"); mvprintw(VNSTATROW, VNSTATCOL + 8, "dtbuf"); mvprintw(VNSTATROW + 1, VNSTATCOL + 8, "desvn"); mvprintw(VNSTATROW + 2, VNSTATCOL + 8, "numvn"); mvprintw(VNSTATROW + 3, VNSTATCOL + 8, "frevn"); mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache"); mvprintw(NAMEIROW + 1, NAMEICOL, " Calls hits %% hits %%"); dslabel(MAXDRIVES, DISKCOL, DISKROW); for (i = 0; i < nintr; i++) { if (intrloc[i] == 0) continue; mvprintw(intrloc[i], INTSCOL + 6, "%-10.10s", intrname[i]); } } #define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;} #define Q(fld) {t=cur_dev.fld[i]; cur_dev.fld[i]-=last_dev.fld[i]; if(state==TIME) last_dev.fld[i]=t;} #define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;} #define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \ if(state == TIME) s1.nchstats.fld = t;} #define PUTRATE(fld, l, c, w) \ do { \ Y(fld); \ - putint((int)((float)s.fld/etime + 0.5), l, c, w); \ + sysputwuint64(wnd, l, c, w, (s.fld/etime + 0.5), 0); \ } while (0) #define MAXFAIL 5 static char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' }; static char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE, CP_IDLE }; void showkre(void) { float f1, f2; int psiz, inttotal; int i, l, lc; static int failcnt = 0; etime = 0; for(i = 0; i < CPUSTATES; i++) { X(time); Q(cp_time); etime += s.time[i]; } if (etime < 5.0) { /* < 5 ticks - ignore this trash */ if (failcnt++ >= MAXFAIL) { clear(); mvprintw(2, 10, "The alternate system clock has died!"); mvprintw(3, 10, "Reverting to ``pigs'' display."); move(CMDLINE, 0); refresh(); failcnt = 0; sleep(5); command("pigs"); } return; } failcnt = 0; etime /= hertz; etime /= ncpu; inttotal = 0; for (i = 0; i < nintr; i++) { if (s.intrcnt[i] == 0) continue; X(intrcnt); l = (int)((float)s.intrcnt[i]/etime + 0.5); inttotal += l; if (intrloc[i] == 0) { if (nextintsrow == LINES) continue; intrloc[i] = nextintsrow++; mvprintw(intrloc[i], INTSCOL + 6, "%-10.10s", intrname[i]); } putint(l, intrloc[i], INTSCOL, 5); } putint(inttotal, INTSROW + 1, INTSCOL, 5); Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss); Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes); Z(ncs_neghits); s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits + nchtotal.ncs_miss + nchtotal.ncs_long + nchtotal.ncs_neghits; if (state == TIME) s1.nchcount = s.nchcount; psiz = 0; f2 = 0.0; for (lc = 0; lc < CPUSTATES; lc++) { i = cpuorder[lc]; f1 = cputime(i); f2 += f1; l = (int) ((f2 + 1.0) / 2.0) - psiz; putfloat(f1, GRAPHROW, GRAPHCOL + 10 * lc, 4, 1, 0); move(GRAPHROW + 2, psiz); psiz += l; while (l-- > 0) addch(cpuchar[lc]); } putint(ucount(), STATROW, STATCOL, 5); putfloat(avenrun[0], STATROW, STATCOL + 20, 5, 2, 0); putfloat(avenrun[1], STATROW, STATCOL + 26, 5, 2, 0); putfloat(avenrun[2], STATROW, STATCOL + 32, 5, 2, 0); mvaddstr(STATROW, STATCOL + 55, buf); -#define pgtokb(pg) ((pg) * (s.v_page_size / 1024)) putfloat(100.0 * (v_page_count - total.t_free) / v_page_count, STATROW + 1, STATCOL + 15, 2, 0, 1); putfloat(100.0 * s.v_kmem_map_size / kmem_size, STATROW + 1, STATCOL + 22, 2, 0, 1); - putuint64(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); - putuint64(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); - putuint64(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8); - putuint64(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8); - putuint64(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7); - putuint64(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7); - putuint64(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8); - putuint64(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8); - putuint64(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7); + sysputpage(wnd, MEMROW + 2, MEMCOL + 4, 7, total.t_arm, 0); + sysputpage(wnd, MEMROW + 2, MEMCOL + 12, 7, total.t_armshr, 0); + sysputpage(wnd, MEMROW + 2, MEMCOL + 20, 8, total.t_avm, 0); + sysputpage(wnd, MEMROW + 2, MEMCOL + 29, 8, total.t_avmshr, 0); + sysputpage(wnd, MEMROW + 3, MEMCOL + 4, 7, total.t_rm, 0); + sysputpage(wnd, MEMROW + 3, MEMCOL + 12, 7, total.t_rmshr, 0); + sysputpage(wnd, MEMROW + 3, MEMCOL + 20, 8, total.t_vm, 0); + sysputpage(wnd, MEMROW + 3, MEMCOL + 29, 8, total.t_vmshr, 0); + sysputpage(wnd, MEMROW + 2, MEMCOL + 38, 7, total.t_free, 0); putint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3); putint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3); putint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3); putint(total.t_sl, PROCSROW + 2, PROCSCOL + 12, 3); putint(total.t_sw, PROCSROW + 2, PROCSCOL + 16, 3); PUTRATE(v_io_faults, VMSTATROW, VMSTATCOL + 2, 8 - 2); PUTRATE(v_cow_faults, VMSTATROW + 1, VMSTATCOL + 2, 8 - 2); PUTRATE(v_zfod, VMSTATROW + 2, VMSTATCOL + 2, 8 - 2); PUTRATE(v_ozfod, VMSTATROW + 3, VMSTATCOL, 8); putint(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0, VMSTATROW + 4, VMSTATCOL + 1, 8 - 1); PUTRATE(v_dfree, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2); PUTRATE(v_pfree, VMSTATROW + 6, VMSTATCOL + 2, 8 - 2); PUTRATE(v_tfree, VMSTATROW + 7, VMSTATCOL, 8); PUTRATE(v_reactivated, VMSTATROW + 8, VMSTATCOL, 8); PUTRATE(v_pdwakeups, VMSTATROW + 9, VMSTATCOL, 8); PUTRATE(v_pdpages, VMSTATROW + 10, VMSTATCOL, 8); PUTRATE(v_intrans, VMSTATROW + 11, VMSTATCOL, 8); - putuint64(pgtokb(s.v_wire_count), VMSTATROW + 12, VMSTATCOL, 8); - putuint64(pgtokb(s.v_active_count), VMSTATROW + 13, VMSTATCOL, 8); - putuint64(pgtokb(s.v_inactive_count), VMSTATROW + 14, VMSTATCOL, 8); - putuint64(pgtokb(s.v_laundry_count), VMSTATROW + 15, VMSTATCOL, 8); - putuint64(pgtokb(s.v_free_count), VMSTATROW + 16, VMSTATCOL, 8); + sysputpage(wnd, VMSTATROW + 12, VMSTATCOL + 2, 8 - 2, s.v_wire_count, 0); + sysputpage(wnd, VMSTATROW + 13, VMSTATCOL + 2, 8 - 2, s.v_active_count, 0); + sysputpage(wnd, VMSTATROW + 14, VMSTATCOL + 2, 8 - 2, s.v_inactive_count, 0); + sysputpage(wnd, VMSTATROW + 15, VMSTATCOL + 2, 8 - 2, s.v_laundry_count, 0); + sysputpage(wnd, VMSTATROW + 16, VMSTATCOL + 2, 8 - 2, s.v_free_count, 0); if (LINES - 1 > VMSTATROW + 17) - putuint64(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8); + sysputuint64(wnd, VMSTATROW + 17, VMSTATCOL + 2, 8 - 2, s.bufspace, 0); PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5); PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5); PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5); PUTRATE(v_swapout, PAGEROW + 2, PAGECOL + 25, 5); PUTRATE(v_vnodepgsin, PAGEROW + 3, PAGECOL + 6, 5); PUTRATE(v_vnodepgsout, PAGEROW + 3, PAGECOL + 12, 5); PUTRATE(v_swappgsin, PAGEROW + 3, PAGECOL + 19, 5); PUTRATE(v_swappgsout, PAGEROW + 3, PAGECOL + 25, 5); PUTRATE(v_swtch, GENSTATROW + 1, GENSTATCOL, 4); PUTRATE(v_trap, GENSTATROW + 1, GENSTATCOL + 5, 4); PUTRATE(v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 4); PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4); PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4); PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4); switch(state) { case TIME: dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &last_dev); break; case RUN: dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &run_dev); break; case BOOT: dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, NULL); break; } putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7); putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7); putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7); putint(s.freevnodes, VNSTATROW + 3, VNSTATCOL, 7); putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 8); putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), NAMEIROW + 2, NAMEICOL + 9, 7); #define nz(x) ((x) ? (x) : 1) putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) * 100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 17, 3, 0, 1); putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 21, 7); putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 29, 3, 0, 1); #undef nz } int cmdkre(const char *cmd, const char *args) { int retval; if (prefix(cmd, "run")) { retval = 1; copyinfo(&s2, &s1); switch (devstat_getdevs(NULL, &run_dev)) { case -1: errx(1, "%s", devstat_errbuf); break; case 1: num_devices = run_dev.dinfo->numdevs; generation = run_dev.dinfo->generation; retval = dscmd("refresh", NULL, MAXDRIVES, &cur_dev); if (retval == 2) labelkre(); break; default: break; } state = RUN; return (retval); } if (prefix(cmd, "boot")) { state = BOOT; copyinfo(&z, &s1); return (1); } if (prefix(cmd, "time")) { state = TIME; return (1); } if (prefix(cmd, "zero")) { retval = 1; if (state == RUN) { getinfo(&s1); switch (devstat_getdevs(NULL, &run_dev)) { case -1: errx(1, "%s", devstat_errbuf); break; case 1: num_devices = run_dev.dinfo->numdevs; generation = run_dev.dinfo->generation; retval = dscmd("refresh",NULL, MAXDRIVES, &cur_dev); if (retval == 2) labelkre(); break; default: break; } } return (retval); } retval = dscmd(cmd, args, MAXDRIVES, &cur_dev); if (retval == 2) labelkre(); return(retval); } /* calculate number of users on the system */ static int ucount(void) { int nusers = 0; struct utmpx *ut; setutxent(); while ((ut = getutxent()) != NULL) if (ut->ut_type == USER_PROCESS) nusers++; endutxent(); return (nusers); } static float cputime(int indx) { double lt; int i; lt = 0; for (i = 0; i < CPUSTATES; i++) lt += s.time[i]; if (lt == 0.0) lt = 1.0; return (s.time[indx] * 100.0 / lt); } void putint(int n, int l, int lc, int w) { do_putuint64(n, l, lc, w, SI); } static void putuint64(uint64_t n, int l, int lc, int w) { do_putuint64(n, l, lc, w, IEC); } static void do_putuint64(uint64_t n, int l, int lc, int w, int div) { int snr; char b[128]; char buf[128]; move(l, lc); #ifdef DEBUG while (w-- > 0) addch('*'); return; #endif if (n == 0) { while (w-- > 0) addch(' '); return; } snr = snprintf(b, sizeof(b), "%*ju", w, (uintmax_t)n); if (snr != w) { humanize_number(buf, w, n, "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL | div); snr = snprintf(b, sizeof(b), "%*s", w, buf); } if (snr != w) { while (w-- > 0) addch('*'); return; } addstr(b); } void putfloat(double f, int l, int lc, int w, int d, int nz) { int snr; char b[128]; move(l, lc); #ifdef DEBUG while (--w >= 0) addch('*'); return; #endif if (nz && f == 0.0) { while (--w >= 0) addch(' '); return; } snr = snprintf(b, sizeof(b), "%*.*f", w, d, f); if (snr != w) snr = snprintf(b, sizeof(b), "%*.0f", w, f); if (snr != w) snr = snprintf(b, sizeof(b), "%*.0fk", w - 1, f / 1000); if (snr != w) snr = snprintf(b, sizeof(b), "%*.0fM", w - 1, f / 1000000); if (snr != w) { while (--w >= 0) addch('*'); return; } addstr(b); } void putlongdouble(long double f, int l, int lc, int w, int d, int nz) { int snr; char b[128]; move(l, lc); #ifdef DEBUG while (--w >= 0) addch('*'); return; #endif if (nz && f == 0.0) { while (--w >= 0) addch(' '); return; } snr = snprintf(b, sizeof(b), "%*.*Lf", w, d, f); if (snr != w) snr = snprintf(b, sizeof(b), "%*.0Lf", w, f); if (snr != w) snr = snprintf(b, sizeof(b), "%*.0Lfk", w - 1, f / 1000); if (snr != w) snr = snprintf(b, sizeof(b), "%*.0LfM", w - 1, f / 1000000); if (snr != w) { while (--w >= 0) addch('*'); return; } addstr(b); } static void getinfo(struct Info *ls) { struct devinfo *tmp_dinfo; size_t size; int mib[2]; GETSYSCTL("kern.cp_time", ls->time); GETSYSCTL("kern.cp_time", cur_dev.cp_time); GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch); GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap); GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall); GETSYSCTL("vm.stats.sys.v_intr", ls->v_intr); GETSYSCTL("vm.stats.sys.v_soft", ls->v_soft); GETSYSCTL("vm.stats.vm.v_vm_faults", ls->v_vm_faults); GETSYSCTL("vm.stats.vm.v_io_faults", ls->v_io_faults); GETSYSCTL("vm.stats.vm.v_cow_faults", ls->v_cow_faults); GETSYSCTL("vm.stats.vm.v_zfod", ls->v_zfod); GETSYSCTL("vm.stats.vm.v_ozfod", ls->v_ozfod); GETSYSCTL("vm.stats.vm.v_swapin", ls->v_swapin); GETSYSCTL("vm.stats.vm.v_swapout", ls->v_swapout); GETSYSCTL("vm.stats.vm.v_swappgsin", ls->v_swappgsin); GETSYSCTL("vm.stats.vm.v_swappgsout", ls->v_swappgsout); GETSYSCTL("vm.stats.vm.v_vnodein", ls->v_vnodein); GETSYSCTL("vm.stats.vm.v_vnodeout", ls->v_vnodeout); GETSYSCTL("vm.stats.vm.v_vnodepgsin", ls->v_vnodepgsin); GETSYSCTL("vm.stats.vm.v_vnodepgsout", ls->v_vnodepgsout); GETSYSCTL("vm.stats.vm.v_intrans", ls->v_intrans); GETSYSCTL("vm.stats.vm.v_reactivated", ls->v_reactivated); GETSYSCTL("vm.stats.vm.v_pdwakeups", ls->v_pdwakeups); GETSYSCTL("vm.stats.vm.v_pdpages", ls->v_pdpages); GETSYSCTL("vm.stats.vm.v_dfree", ls->v_dfree); GETSYSCTL("vm.stats.vm.v_pfree", ls->v_pfree); GETSYSCTL("vm.stats.vm.v_tfree", ls->v_tfree); - GETSYSCTL("vm.stats.vm.v_page_size", ls->v_page_size); GETSYSCTL("vm.stats.vm.v_free_count", ls->v_free_count); GETSYSCTL("vm.stats.vm.v_wire_count", ls->v_wire_count); GETSYSCTL("vm.stats.vm.v_active_count", ls->v_active_count); GETSYSCTL("vm.stats.vm.v_inactive_count", ls->v_inactive_count); GETSYSCTL("vm.stats.vm.v_laundry_count", ls->v_laundry_count); GETSYSCTL("vfs.bufspace", ls->bufspace); GETSYSCTL("kern.maxvnodes", ls->desiredvnodes); GETSYSCTL("vfs.numvnodes", ls->numvnodes); GETSYSCTL("vfs.freevnodes", ls->freevnodes); GETSYSCTL("vfs.cache.nchstats", ls->nchstats); GETSYSCTL("vfs.numdirtybuffers", ls->numdirtybuffers); GETSYSCTL("vm.kmem_map_size", ls->v_kmem_map_size); getsysctl("hw.intrcnt", ls->intrcnt, nintr * sizeof(u_long)); size = sizeof(ls->Total); mib[0] = CTL_VM; mib[1] = VM_TOTAL; if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) { error("Can't get kernel info: %s\n", strerror(errno)); bzero(&ls->Total, sizeof(ls->Total)); } size = sizeof(ncpu); if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0 || size != sizeof(ncpu)) ncpu = 1; 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); } static void allocinfo(struct Info *ls) { ls->intrcnt = (long *) calloc(nintr, sizeof(long)); if (ls->intrcnt == NULL) errx(2, "out of memory"); } static void copyinfo(struct Info *from, struct Info *to) { long *intrcnt; /* * time, wds, seek, and xfer are malloc'd so we have to * save the pointers before the structure copy and then * copy by hand. */ intrcnt = to->intrcnt; *to = *from; bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); } Index: stable/12/usr.bin/systat/zarc.c =================================================================== --- stable/12/usr.bin/systat/zarc.c (revision 361895) +++ stable/12/usr.bin/systat/zarc.c (revision 361896) @@ -1,239 +1,249 @@ /*- - * Copyright (c) 2014 - 2017 Yoshihiro Ota + * Copyright (c) 2014 - 2017, 2019 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 #include "systat.h" #include "extern.h" #include "devs.h" -struct zfield{ +struct zfield { uint64_t arcstats; uint64_t arcstats_demand_data; uint64_t arcstats_demand_metadata; uint64_t arcstats_prefetch_data; uint64_t arcstats_prefetch_metadata; uint64_t zfetchstats; uint64_t arcstats_l2; uint64_t vdev_cache_stats; }; static struct zarcstats { struct zfield hits; struct zfield misses; } curstat, initstat, oldstat; +struct zarcrates { + struct zfield current; + struct zfield total; +}; + static void getinfo(struct zarcstats *ls); WINDOW * openzarc(void) { - return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0)); + + return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0)); } void closezarc(WINDOW *w) { + if (w == NULL) return; wclear(w); wrefresh(w); delwin(w); } void labelzarc(void) { int row = 1; + wmove(wnd, 0, 0); wclrtoeol(wnd); - mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s", - "rate", "hits", "misses", "total hits", "total misses"); -#define L(str) mvwprintw(wnd, row, 5, #str); \ - mvwprintw(wnd, row, 31, ":"); \ - mvwprintw(wnd, row, 31+4, "%%"); ++row + mvwprintw(wnd, 0, 31+1, "%4.4s %6.6s %6.6s | Total %4.4s %6.6s %6.6s", + "Rate", "Hits", "Misses", "Rate", "Hits", "Misses"); +#define L(str) mvwprintw(wnd, row++, 5, \ + "%-26.26s: %% | %%", #str) L(arcstats); L(arcstats.demand_data); L(arcstats.demand_metadata); L(arcstats.prefetch_data); L(arcstats.prefetch_metadata); L(zfetchstats); L(arcstats.l2); L(vdev_cache_stats); #undef L dslabel(12, 0, 18); } -static int calc(uint64_t hits, uint64_t misses) +static int +calc_rate(uint64_t hits, uint64_t misses) { - if( hits ) - return 100 * hits / ( hits + misses ); + if(hits) + return 100 * hits / (hits + misses); else return 0; } static void -domode(struct zarcstats *delta, struct zarcstats *rate) +domode(struct zarcstats *delta, struct zarcrates *rate) { #define DO(stat) \ delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \ delta->misses.stat = (curstat.misses.stat - oldstat.misses.stat); \ - rate->hits.stat = calc(delta->hits.stat, delta->misses.stat) + rate->current.stat = calc_rate(delta->hits.stat, delta->misses.stat); \ + rate->total.stat = calc_rate(curstat.hits.stat, curstat.misses.stat) DO(arcstats); DO(arcstats_demand_data); DO(arcstats_demand_metadata); DO(arcstats_prefetch_data); DO(arcstats_prefetch_metadata); DO(zfetchstats); DO(arcstats_l2); DO(vdev_cache_stats); DO(arcstats); DO(arcstats_demand_data); DO(arcstats_demand_metadata); DO(arcstats_prefetch_data); DO(arcstats_prefetch_metadata); DO(zfetchstats); DO(arcstats_l2); DO(vdev_cache_stats); #undef DO } void showzarc(void) { int row = 1; - struct zarcstats delta, rate; + struct zarcstats delta = {}; + struct zarcrates rate = {}; - memset(&delta, 0, sizeof delta); - memset(&rate, 0, sizeof rate); - domode(&delta, &rate); -#define DO(stat, col, fmt) \ - mvwprintw(wnd, row, col, fmt, stat) -#define R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64) -#define H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \ - DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64) -#define M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \ - DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64) -#define E(stat) R(stat); H(stat); M(stat); ++row +#define DO(stat, col, width) \ + sysputuint64(wnd, row, col, width, stat, HN_DIVISOR_1000) +#define RATES(stat) mvwprintw(wnd, row, 31+1, "%3"PRIu64, rate.current.stat);\ + mvwprintw(wnd, row, 31+1+5+7+7+8, "%3"PRIu64, rate.total.stat) +#define HITS(stat) DO(delta.hits.stat, 31+1+5, 6); \ + DO(curstat.hits.stat, 31+1+5+7+7+8+5, 6) +#define MISSES(stat) DO(delta.misses.stat, 31+1+5+7, 6); \ + DO(curstat.misses.stat, 31+1+5+7+7+8+5+7, 6) +#define E(stat) RATES(stat); HITS(stat); MISSES(stat); ++row E(arcstats); E(arcstats_demand_data); E(arcstats_demand_metadata); E(arcstats_prefetch_data); E(arcstats_prefetch_metadata); E(zfetchstats); E(arcstats_l2); E(vdev_cache_stats); #undef DO #undef E -#undef M -#undef H -#undef R +#undef MISSES +#undef HITS +#undef RATES dsshow(12, 0, 18, &cur_dev, &last_dev); } int initzarc(void) { dsinit(12); getinfo(&initstat); curstat = oldstat = initstat; return 1; } void resetzarc(void) { + initzarc(); } static void getinfo(struct zarcstats *ls) { 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 ); + dsgetinfo(&cur_dev); - size_t size = sizeof( ls->hits.arcstats ); - if ( sysctlbyname("kstat.zfs.misc.arcstats.hits", - &ls->hits.arcstats, &size, NULL, 0 ) != 0 ) + size_t size = sizeof(ls->hits.arcstats); + if (sysctlbyname("kstat.zfs.misc.arcstats.hits", + &ls->hits.arcstats, &size, NULL, 0) != 0) return; GETSYSCTL("kstat.zfs.misc.arcstats.misses", ls->misses.arcstats); GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_hits", ls->hits.arcstats_demand_data); GETSYSCTL("kstat.zfs.misc.arcstats.demand_data_misses", ls->misses.arcstats_demand_data); GETSYSCTL("kstat.zfs.misc.arcstats.demand_metadata_hits", ls->hits.arcstats_demand_metadata); GETSYSCTL("kstat.zfs.misc.arcstats.demand_metadata_misses", ls->misses.arcstats_demand_metadata); GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_data_hits", ls->hits.arcstats_prefetch_data); GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_data_misses", ls->misses.arcstats_prefetch_data); GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_metadata_hits", ls->hits.arcstats_prefetch_metadata); GETSYSCTL("kstat.zfs.misc.arcstats.prefetch_metadata_misses", ls->misses.arcstats_prefetch_metadata); GETSYSCTL("kstat.zfs.misc.zfetchstats.hits", ls->hits.zfetchstats); GETSYSCTL("kstat.zfs.misc.zfetchstats.misses", ls->misses.zfetchstats); GETSYSCTL("kstat.zfs.misc.arcstats.l2_hits", ls->hits.arcstats_l2); GETSYSCTL("kstat.zfs.misc.arcstats.l2_misses", ls->misses.arcstats_l2); GETSYSCTL("kstat.zfs.misc.vdev_cache_stats.hits", ls->hits.vdev_cache_stats); GETSYSCTL("kstat.zfs.misc.vdev_cache_stats.misses", ls->misses.vdev_cache_stats); } void fetchzarc(void) { + oldstat = curstat; getinfo(&curstat); } Index: stable/12 =================================================================== --- stable/12 (revision 361895) +++ stable/12 (revision 361896) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r360919,360929,361084