Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/iostat Maintain 5-character width of MB/s column by...



details:   https://anonhg.NetBSD.org/src/rev/e9a7b079fd30
branches:  trunk
changeset: 760536:e9a7b079fd30
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Fri Jan 07 03:12:27 2011 +0000

description:
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.

diffstat:

 usr.sbin/iostat/Makefile |   6 +++---
 usr.sbin/iostat/iostat.c |  11 ++++++++---
 2 files changed, 11 insertions(+), 6 deletions(-)

diffs (65 lines):

diff -r d7f49314ff9a -r e9a7b079fd30 usr.sbin/iostat/Makefile
--- a/usr.sbin/iostat/Makefile  Fri Jan 07 03:04:12 2011 +0000
+++ b/usr.sbin/iostat/Makefile  Fri Jan 07 03:12:27 2011 +0000
@@ -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>
diff -r d7f49314ff9a -r e9a7b079fd30 usr.sbin/iostat/iostat.c
--- a/usr.sbin/iostat/iostat.c  Fri Jan 07 03:04:12 2011 +0000
+++ b/usr.sbin/iostat/iostat.c  Fri Jan 07 03:12:27 2011 +0000
@@ -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);
        }
 }
 



Home | Main Index | Thread Index | Old Index