Module Name: src Committed By: jakllsch Date: Fri Jan 7 03:12:27 UTC 2011
Modified Files: src/usr.sbin/iostat: Makefile iostat.c Log Message: Maintain 5-character width of MB/s column by dynamically adjusting the decimal precision. This should work until disk transfer rates exceed 99999 MB/s. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.sbin/iostat/Makefile cvs rdiff -u -r1.53 -r1.54 src/usr.sbin/iostat/iostat.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.sbin/iostat/Makefile diff -u src/usr.sbin/iostat/Makefile:1.23 src/usr.sbin/iostat/Makefile:1.24 --- src/usr.sbin/iostat/Makefile:1.23 Fri Apr 21 13:46:37 2006 +++ src/usr.sbin/iostat/Makefile Fri Jan 7 03:12:27 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.23 2006/04/21 13:46:37 yamt Exp $ +# $NetBSD: Makefile,v 1.24 2011/01/07 03:12:27 jakllsch Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 .include <bsd.own.mk> @@ -13,7 +13,7 @@ # drvstats.c pulled in from ../../usr.bin/vmstat SRCS= drvstats.c iostat.c -DPADD= ${LIBKVM} -LDADD= -lkvm +DPADD= ${LIBKVM} ${LIBM} +LDADD= -lkvm -lm .include <bsd.prog.mk> Index: src/usr.sbin/iostat/iostat.c diff -u src/usr.sbin/iostat/iostat.c:1.53 src/usr.sbin/iostat/iostat.c:1.54 --- src/usr.sbin/iostat/iostat.c:1.53 Wed Apr 15 10:05:41 2009 +++ src/usr.sbin/iostat/iostat.c Fri Jan 7 03:12:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: iostat.c,v 1.53 2009/04/15 10:05:41 lukem Exp $ */ +/* $NetBSD: iostat.c,v 1.54 2011/01/07 03:12:27 jakllsch Exp $ */ /* * Copyright (c) 1996 John M. Vinopal @@ -71,7 +71,7 @@ #if 0 static char sccsid[] = "@(#)iostat.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: iostat.c,v 1.53 2009/04/15 10:05:41 lukem Exp $"); +__RCSID("$NetBSD: iostat.c,v 1.54 2011/01/07 03:12:27 jakllsch Exp $"); #endif #endif /* not lint */ @@ -87,6 +87,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <math.h> #include "drvstats.h" @@ -99,6 +100,8 @@ static int winlines = 20; static int wincols = 80; +#define MAX(a,b) (((a)>(b))?(a):(b)) + #define ISSET(x, a) ((x) & (a)) #define SHOW_CPU (1<<0) #define SHOW_TTY (1<<1) @@ -339,7 +342,9 @@ (double)(1024 * 1024); else mbps = 0; - (void)printf(" %5.2f ", mbps / etime); + mbps /= etime; + (void)printf(" %5.*f ", + MAX(0,3-(int)floor(log10(fabs(fmax(1.0,mbps))))), mbps); } }