Module Name:    src
Committed By:   mrg
Date:           Tue Feb  1 09:18:07 UTC 2022

Modified Files:
        src/usr.bin/vmstat: vmstat.c

Log Message:
when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/usr.bin/vmstat/vmstat.c

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/vmstat/vmstat.c
diff -u src/usr.bin/vmstat/vmstat.c:1.248 src/usr.bin/vmstat/vmstat.c:1.249
--- src/usr.bin/vmstat/vmstat.c:1.248	Sat Nov 27 22:16:42 2021
+++ src/usr.bin/vmstat/vmstat.c	Tue Feb  1 09:18:07 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.248 2021/11/27 22:16:42 rillig Exp $ */
+/* $NetBSD: vmstat.c,v 1.249 2022/02/01 09:18:07 mrg Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020
@@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 3/1/95";
 #else
-__RCSID("$NetBSD: vmstat.c,v 1.248 2021/11/27 22:16:42 rillig Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.249 2022/02/01 09:18:07 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -569,7 +569,7 @@ getnlist(int todo)
 char **
 choosedrives(char **argv)
 {
-	size_t i;
+	size_t i, j, k;
 
 	/*
 	 * Choose drives to be displayed.  Priority goes to (in order) drives
@@ -591,11 +591,30 @@ choosedrives(char **argv)
 			break;
 		}
 	}
+
+	/*
+	 * Pick the most active drives.  Must read the stats once before
+	 * sorting so that there is current IO data, before selecting
+	 * just the first two drives.
+	 */
+	drvreadstats();
 	for (i = 0; i < ndrive && ndrives < 2; i++) {
-		if (drv_select[i])
-			continue;
-		drv_select[i] = 1;
-		++ndrives;
+		uint64_t high_bytes = 0, bytes;
+
+		k = ndrive;
+		for (j = 0; j < ndrive; j++) {
+			if (drv_select[j])
+				continue;
+			bytes = cur.rbytes[j] + cur.wbytes[j];
+			if (bytes > high_bytes) {
+				high_bytes = bytes;
+				k = j;
+			}
+		}
+		if (k != ndrive) {
+			drv_select[k] = 1;
+			++ndrives;
+		}
 	}
 
 	return (argv);

Reply via email to