Module Name:    src
Committed By:   he
Date:           Sun Jun 30 19:57:24 UTC 2019

Modified Files:
        src/usr.bin/systat: vmstat.c vmstat.h
        src/usr.bin/vmstat: drvstats.c drvstats.h

Log Message:
Make the scaling of the "bytes written" sticky, so that if we go
to K, we don't return to unscaled, and similar for higher scales
(though it takes some effort, due to the wide field...)
Fixes PR#54334.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/systat/vmstat.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/systat/vmstat.h
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/vmstat/drvstats.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vmstat/drvstats.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/vmstat.c
diff -u src/usr.bin/systat/vmstat.c:1.86 src/usr.bin/systat/vmstat.c:1.87
--- src/usr.bin/systat/vmstat.c:1.86	Fri Jan 25 15:34:22 2019
+++ src/usr.bin/systat/vmstat.c	Sun Jun 30 19:57:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmstat.c,v 1.86 2019/01/25 15:34:22 christos Exp $	*/
+/*	$NetBSD: vmstat.c,v 1.87 2019/06/30 19:57:23 he Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.86 2019/01/25 15:34:22 christos Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.87 2019/06/30 19:57:23 he Exp $");
 #endif /* not lint */
 
 /*
@@ -756,7 +756,7 @@ cputime(int indx)
 }
 
 void
-puthumanint(u_int64_t n, int l, int c, int w)
+puthumanint_scale(u_int64_t n, int l, int c, int w, int scale)
 {
 	char b[128];
 
@@ -766,7 +766,7 @@ puthumanint(u_int64_t n, int l, int c, i
 		hline(' ', w);
 		return;
 	}
-	if (humanize_number(b, w, n, "", HN_AUTOSCALE, HN_NOSPACE) == -1 ) {
+	if (humanize_number(b, w, n, "", scale, HN_NOSPACE) == -1 ) {
 		hline('*', w);
 		return;
 	}
@@ -774,6 +774,28 @@ puthumanint(u_int64_t n, int l, int c, i
 }
 
 void
+puthumanint_sticky(u_int64_t n, int l, int c, int w, int *scale)
+{
+	char b[128];
+	int sc;
+
+	sc = humanize_number(b, w, n, "", HN_GETSCALE, HN_NOSPACE);
+	if (sc > *scale)
+		*scale = sc;
+	else
+		sc = *scale;
+
+	puthumanint_scale(n, l, c, w, sc);
+}
+
+void
+puthumanint(u_int64_t n, int l, int c, int w)
+{
+
+	puthumanint_scale(n, l, c, w, HN_AUTOSCALE);
+}
+
+void
 putint(int n, int l, int c, int w)
 {
 	char b[128];
@@ -899,8 +921,8 @@ dinfo(int dn, int r, int c)
 	putint((int)((cur.rxfer[dn]+cur.wxfer[dn])/dtime+0.5),
 	    r, c, DISKCOLWIDTH);
 	ADV;
-	puthumanint((cur.rbytes[dn] + cur.wbytes[dn]) / dtime + 0.5,
-		    r, c, DISKCOLWIDTH);
+	puthumanint_sticky((cur.rbytes[dn] + cur.wbytes[dn]) / dtime + 0.5,
+		    r, c, DISKCOLWIDTH, &cur.scale[dn]);
 	ADV;
 
 	/* time busy in disk activity */

Index: src/usr.bin/systat/vmstat.h
diff -u src/usr.bin/systat/vmstat.h:1.1 src/usr.bin/systat/vmstat.h:1.2
--- src/usr.bin/systat/vmstat.h:1.1	Sat Mar 18 14:58:49 2006
+++ src/usr.bin/systat/vmstat.h	Sun Jun 30 19:57:23 2019
@@ -1,4 +1,4 @@
-/*      $NetBSD: vmstat.h,v 1.1 2006/03/18 14:58:49 dsl Exp $  */
+/*      $NetBSD: vmstat.h,v 1.2 2019/06/30 19:57:23 he Exp $  */
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -35,6 +35,8 @@ extern double etime;
 
 void putfloat(double, int, int, int, int, int);
 void putint(int, int, int, int);
+void puthumanint_scale(u_int64_t, int, int, int, int);
+void puthumanint_sticky(u_int64_t, int, int, int, int*);
 void puthumanint(u_int64_t, int, int, int);
 
 typedef struct uvmexp_sysctl uvmexp_sysctl_t;

Index: src/usr.bin/vmstat/drvstats.c
diff -u src/usr.bin/vmstat/drvstats.c:1.12 src/usr.bin/vmstat/drvstats.c:1.13
--- src/usr.bin/vmstat/drvstats.c:1.12	Thu Feb  8 09:05:21 2018
+++ src/usr.bin/vmstat/drvstats.c	Sun Jun 30 19:57:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: drvstats.c,v 1.12 2018/02/08 09:05:21 dholland Exp $	*/
+/*	$NetBSD: drvstats.c,v 1.13 2019/06/30 19:57:24 he Exp $	*/
 
 /*
  * Copyright (c) 1996 John M. Vinopal
@@ -346,6 +346,7 @@ drvinit(int selected)
 	cur.seek = calloc(ndrive, sizeof(u_int64_t));
 	cur.rbytes = calloc(ndrive, sizeof(u_int64_t));
 	cur.wbytes = calloc(ndrive, sizeof(u_int64_t));
+	cur.scale = calloc(ndrive, sizeof(int));
 	last.time = calloc(ndrive, sizeof(struct timeval));
 	last.wait = calloc(ndrive, sizeof(struct timeval));
 	last.waitsum = calloc(ndrive, sizeof(struct timeval));

Index: src/usr.bin/vmstat/drvstats.h
diff -u src/usr.bin/vmstat/drvstats.h:1.5 src/usr.bin/vmstat/drvstats.h:1.6
--- src/usr.bin/vmstat/drvstats.h:1.5	Tue Jul  4 21:19:33 2017
+++ src/usr.bin/vmstat/drvstats.h	Sun Jun 30 19:57:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: drvstats.h,v 1.5 2017/07/04 21:19:33 mlelstv Exp $	*/
+/*	$NetBSD: drvstats.h,v 1.6 2019/06/30 19:57:24 he Exp $	*/
 
 /*
  * Copyright (c) 1996 John M. Vinopal
@@ -45,6 +45,7 @@ struct _drive {
 	u_int64_t	 *seek;	/* # of seeks (currently unused). */
 	u_int64_t	 *rbytes;	/* # of bytes read. */
 	u_int64_t	 *wbytes;	/* # of bytes written. */
+	int		 *scale;	/* Sticky scale for bytes */
 	struct timeval	 *time;		/* Time spent in disk i/o. */
 	struct timeval	 *wait;		/* Time spent in queue waiting. */
 	struct timeval	 *busysum;	/* Time busy * queue length */

Reply via email to