svn commit: r361896 - stable/12/usr.bin/systat

Michael Reifenberger mr at FreeBSD.org
Sun Jun 7 16:42:05 UTC 2020


Author: mr
Date: Sun Jun  7 16:42:03 2020
New Revision: 361896
URL: https://svnweb.freebsd.org/changeset/base/361896

Log:
  MFC r360919,r360929,r361084:
  
  Patch systat -zarc to display cumulative rate and round down large numbers by SI units
  
  Introduce sysputpage() to display large page size with human readable format.
    Using UI units allows to fit larger numbers in columns.
    Stop calling v_page_size - this is a value that doesn't change at runtime.
    Renamed WINDOW *wnd to *wd to avoid conflict with global *wnd variable.
    Use bit-shift to convert page size to byte.
  
  PR:		237664, 246458
  Submitted by:	ota at j.email.ne.jp

Added:
  stable/12/usr.bin/systat/sysput.c
     - copied, changed from r360929, head/usr.bin/systat/sysput.c
Modified:
  stable/12/usr.bin/systat/Makefile
  stable/12/usr.bin/systat/extern.h
  stable/12/usr.bin/systat/fetch.c
  stable/12/usr.bin/systat/main.c
  stable/12/usr.bin/systat/vmstat.c
  stable/12/usr.bin/systat/zarc.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/systat/Makefile
==============================================================================
--- stable/12/usr.bin/systat/Makefile	Sun Jun  7 14:39:20 2020	(r361895)
+++ stable/12/usr.bin/systat/Makefile	Sun Jun  7 16:42:03 2020	(r361896)
@@ -4,7 +4,7 @@
 .include <src.opts.mk>
 
 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

Modified: stable/12/usr.bin/systat/extern.h
==============================================================================
--- stable/12/usr.bin/systat/extern.h	Sun Jun  7 14:39:20 2020	(r361895)
+++ stable/12/usr.bin/systat/extern.h	Sun Jun  7 16:42:03 2020	(r361896)
@@ -165,6 +165,11 @@ 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 *); \
@@ -176,4 +181,4 @@ char	*sysctl_dynread(const char *, size_t *);
 	void	 show ## name(void)
 
 SYSTAT_CMD( zarc );
-SYSTAT_CMD ( sctp );
+SYSTAT_CMD( sctp );

Modified: stable/12/usr.bin/systat/fetch.c
==============================================================================
--- stable/12/usr.bin/systat/fetch.c	Sun Jun  7 14:39:20 2020	(r361895)
+++ stable/12/usr.bin/systat/fetch.c	Sun Jun  7 16:42:03 2020	(r361896)
@@ -60,9 +60,11 @@ kvm_ckread(void *a, void *b, int l)
 		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));

Modified: stable/12/usr.bin/systat/main.c
==============================================================================
--- stable/12/usr.bin/systat/main.c	Sun Jun  7 14:39:20 2020	(r361895)
+++ stable/12/usr.bin/systat/main.c	Sun Jun  7 16:42:03 2020	(r361896)
@@ -300,17 +300,8 @@ display(void)
 		    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)();

Copied and modified: stable/12/usr.bin/systat/sysput.c (from r360929, head/usr.bin/systat/sysput.c)
==============================================================================
--- head/usr.bin/systat/sysput.c	Mon May 11 21:22:16 2020	(r360929, copy source)
+++ stable/12/usr.bin/systat/sysput.c	Sun Jun  7 16:42:03 2020	(r361896)
@@ -41,15 +41,23 @@ __FBSDID("$FreeBSD$");
 #include "extern.h"
 
 void
-sysputstrs(WINDOW *wnd, int row, int col, int width)
+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 *wnd, int row, int col, int width, uint64_t val, int flags)
+sysputuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags)
 {
 	char unit, *ptr, *start, wrtbuf[width + width + 1];
 	int len;
@@ -69,9 +77,42 @@ sysputuint64(WINDOW *wnd, int row, int col, int width,
 		memset(wrtbuf + len, ' ', width - len);
 	start += len;
 
-	mvwaddstr(wnd, row, col, start);
+	mvwaddstr(wd, row, col, start);
 	return;
 
 error:
-	sysputstrs(wnd, row, col, width);
+	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);
 }

Modified: stable/12/usr.bin/systat/vmstat.c
==============================================================================
--- stable/12/usr.bin/systat/vmstat.c	Sun Jun  7 14:39:20 2020	(r361895)
+++ stable/12/usr.bin/systat/vmstat.c	Sun Jun  7 16:42:03 2020	(r361896)
@@ -104,7 +104,6 @@ static struct Info {
 	/*
 	 * 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 */
@@ -173,15 +172,15 @@ closekre(WINDOW *w)
 #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
@@ -304,7 +303,7 @@ labelkre(void)
 	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");
@@ -373,7 +372,7 @@ labelkre(void)
 #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
 
@@ -454,21 +453,20 @@ showkre(void)
 	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);
@@ -487,13 +485,13 @@ showkre(void)
 	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);
@@ -773,7 +771,6 @@ getinfo(struct Info *ls)
 	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);

Modified: stable/12/usr.bin/systat/zarc.c
==============================================================================
--- stable/12/usr.bin/systat/zarc.c	Sun Jun  7 14:39:20 2020	(r361895)
+++ stable/12/usr.bin/systat/zarc.c	Sun Jun  7 16:42:03 2020	(r361896)
@@ -1,5 +1,5 @@
 /*-
- * 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
@@ -32,16 +32,16 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
-/* #include <stdlib.h> */
 #include <inttypes.h>
 #include <string.h>
 #include <err.h>
+#include <libutil.h>
 
 #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;
@@ -57,18 +57,25 @@ static struct zarcstats {
 	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);
@@ -80,12 +87,12 @@ 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);
@@ -98,21 +105,23 @@ labelzarc(void)
 	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);
@@ -136,21 +145,20 @@ 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);
@@ -161,9 +169,9 @@ showzarc(void)
 	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);
 }
 
@@ -180,6 +188,7 @@ initzarc(void)
 void
 resetzarc(void)
 {
+
 	initzarc();
 }
 
@@ -193,11 +202,11 @@ getinfo(struct zarcstats *ls)
 	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);
@@ -234,6 +243,7 @@ getinfo(struct zarcstats *ls)
 void
 fetchzarc(void)
 {
+
 	oldstat = curstat;
 	getinfo(&curstat);
 }


More information about the svn-src-stable mailing list