cvs commit: src/usr.bin/vmstat vmstat.c

Bruce Evans bde at zeta.org.au
Mon Dec 8 04:14:00 PST 2003


On Sun, 7 Dec 2003, Marcel Moolenaar wrote:

> marcel      2003/12/07 23:57:57 PST
>
>   FreeBSD src repository
>
>   Modified files:
>     usr.bin/vmstat       vmstat.c
>   Log:
>   Unbreak vmstat -i on ia64:
>   o  nintr and inamlen must by of type size_t, not int,
>   o  Remove now unnecessary casts,
>   o  Handle the aflag differently, because the intr. names have a
>      fixed width and almost always have trailing spaces.

The fixed width and padding with spaces is a new kernel bug on i386's.
Was it broken before on ia64's?  It causes problems in both vmstat
and systat.

I don't like the aflag handling and removed most of it.  Interrupts
with nonzero counts should always be displayed (like they used to be),
and there is little need for different levels of allness.

This patch depends on other changes to print the rate more precisely.
The extra precision should be an option.  Always printing it saves
me having to fix the rounding error for integer division to see that
the clock frequency are nearer to their nominal integral values than
to those values less 1.

%%%
Index: vmstat.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.71
diff -u -2 -r1.71 vmstat.c
--- vmstat.c	8 Dec 2003 07:57:57 -0000	1.71
+++ vmstat.c	8 Dec 2003 11:38:03 -0000
@@ -868,33 +878,30 @@
 		}
 	}
-	nintr /= sizeof(u_long);
-	tintrname = intrname;
+	nintr /= sizeof(*intrcnt);
 	istrnamlen = strlen("interrupt");
+	tintrname = intrname;
 	for (i = 0; i < nintr; i++) {
 		clen = strlen(tintrname);
+
+		/* Work around bogus padding in new interrupt code. */
+		while (clen > 0 && tintrname[clen - 1] == ' ')
+			clen--;
+
 		if (clen > istrnamlen)
 			istrnamlen = clen;
 		tintrname += clen + 1;
 	}
-	(void)printf("%-*s %20s %10s\n", istrnamlen, "interrupt", "total",
+	(void)printf("%-*s %20s %13s\n", istrnamlen, "interrupt", "total",
 	    "rate");
 	inttotal = 0;
 	for (i = 0; i < nintr; i++) {
-		const char *p;
-		if (intrname[0] != '\0' &&
-		    (aflag > 0 || *intrcnt != 0) &&
-#ifdef __ia64__
-		    (aflag > 1 || *intrname != '#'))
-#else
-		    (aflag > 1 || ((p = strchr(intrname, ' ')) && p[1] != ' ')) &&
-		    (aflag > 2 || strncmp(intrname, "stray ", 6) != 0))
-#endif
-			(void)printf("%-*s %20lu %10lu\n", istrnamlen, intrname,
-			    *intrcnt, *intrcnt / uptime);
+		if (*intrcnt != 0 || aflag && *intrname != '\0')
+			(void)printf("%-*.*s %20lu %17.6f\n", istrnamlen,
+			    istrnamlen, intrname, *intrcnt, *intrcnt / uptime);
 		intrname += strlen(intrname) + 1;
 		inttotal += *intrcnt++;
 	}
-	(void)printf("%-*s %20llu %10llu\n", istrnamlen, "Total",
-	    (long long)inttotal, (long long)(inttotal / uptime));
+	(void)printf("%-*s %20ju %17.6f\n", istrnamlen, "Total",
+	    (uintmax_t)inttotal, inttotal / uptime);
 }

%%%

Bruce


More information about the cvs-src mailing list