Fri Jan 7 03:12:27 2011 UTC ()
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.


(jakllsch)
diff -r1.23 -r1.24 src/usr.sbin/iostat/Makefile
diff -r1.53 -r1.54 src/usr.sbin/iostat/iostat.c

cvs diff -r1.23 -r1.24 src/usr.sbin/iostat/Makefile (expand / switch to unified diff)

--- src/usr.sbin/iostat/Makefile 2006/04/21 13:46:37 1.23
+++ src/usr.sbin/iostat/Makefile 2011/01/07 03:12:27 1.24
@@ -1,19 +1,19 @@ @@ -1,19 +1,19 @@
1# $NetBSD: Makefile,v 1.23 2006/04/21 13:46:37 yamt Exp $ 1# $NetBSD: Makefile,v 1.24 2011/01/07 03:12:27 jakllsch Exp $
2# from: @(#)Makefile 8.1 (Berkeley) 6/6/93 2# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
3 3
4.include <bsd.own.mk> 4.include <bsd.own.mk>
5 5
6PROG= iostat 6PROG= iostat
7MAN= iostat.8 7MAN= iostat.8
8 8
9.PATH: ${NETBSDSRCDIR}/usr.bin/vmstat 9.PATH: ${NETBSDSRCDIR}/usr.bin/vmstat
10 10
11CPPFLAGS+=-I${NETBSDSRCDIR}/usr.bin/vmstat 11CPPFLAGS+=-I${NETBSDSRCDIR}/usr.bin/vmstat
12 12
13# drvstats.c pulled in from ../../usr.bin/vmstat 13# drvstats.c pulled in from ../../usr.bin/vmstat
14SRCS= drvstats.c iostat.c 14SRCS= drvstats.c iostat.c
15 15
16DPADD= ${LIBKVM} 16DPADD= ${LIBKVM} ${LIBM}
17LDADD= -lkvm 17LDADD= -lkvm -lm
18 18
19.include <bsd.prog.mk> 19.include <bsd.prog.mk>

cvs diff -r1.53 -r1.54 src/usr.sbin/iostat/iostat.c (expand / switch to unified diff)

--- src/usr.sbin/iostat/iostat.c 2009/04/15 10:05:41 1.53
+++ src/usr.sbin/iostat/iostat.c 2011/01/07 03:12:27 1.54
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: iostat.c,v 1.53 2009/04/15 10:05:41 lukem Exp $ */ 1/* $NetBSD: iostat.c,v 1.54 2011/01/07 03:12:27 jakllsch Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 John M. Vinopal 4 * Copyright (c) 1996 John M. Vinopal
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -61,54 +61,57 @@ @@ -61,54 +61,57 @@
61 * SUCH DAMAGE. 61 * SUCH DAMAGE.
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65#ifndef lint 65#ifndef lint
66__COPYRIGHT("@(#) Copyright (c) 1986, 1991, 1993\ 66__COPYRIGHT("@(#) Copyright (c) 1986, 1991, 1993\
67 The Regents of the University of California. All rights reserved."); 67 The Regents of the University of California. All rights reserved.");
68#endif /* not lint */ 68#endif /* not lint */
69 69
70#ifndef lint 70#ifndef lint
71#if 0 71#if 0
72static char sccsid[] = "@(#)iostat.c 8.3 (Berkeley) 4/28/95"; 72static char sccsid[] = "@(#)iostat.c 8.3 (Berkeley) 4/28/95";
73#else 73#else
74__RCSID("$NetBSD: iostat.c,v 1.53 2009/04/15 10:05:41 lukem Exp $"); 74__RCSID("$NetBSD: iostat.c,v 1.54 2011/01/07 03:12:27 jakllsch Exp $");
75#endif 75#endif
76#endif /* not lint */ 76#endif /* not lint */
77 77
78#include <sys/types.h> 78#include <sys/types.h>
79#include <sys/ioctl.h> 79#include <sys/ioctl.h>
80#include <sys/sched.h> 80#include <sys/sched.h>
81#include <sys/time.h> 81#include <sys/time.h>
82 82
83#include <err.h> 83#include <err.h>
84#include <ctype.h> 84#include <ctype.h>
85#include <signal.h> 85#include <signal.h>
86#include <stdio.h> 86#include <stdio.h>
87#include <stdlib.h> 87#include <stdlib.h>
88#include <string.h> 88#include <string.h>
89#include <unistd.h> 89#include <unistd.h>
 90#include <math.h>
90 91
91#include "drvstats.h" 92#include "drvstats.h"
92 93
93/* Namelist and memory files. */ 94/* Namelist and memory files. */
94char *nlistf, *memf; 95char *nlistf, *memf;
95 96
96int hz, reps, interval; 97int hz, reps, interval;
97static int todo = 0; 98static int todo = 0;
98static int defdrives; 99static int defdrives;
99static int winlines = 20; 100static int winlines = 20;
100static int wincols = 80; 101static int wincols = 80;
101 102
 103#define MAX(a,b) (((a)>(b))?(a):(b))
 104
102#define ISSET(x, a) ((x) & (a)) 105#define ISSET(x, a) ((x) & (a))
103#define SHOW_CPU (1<<0) 106#define SHOW_CPU (1<<0)
104#define SHOW_TTY (1<<1) 107#define SHOW_TTY (1<<1)
105#define SHOW_STATS_1 (1<<2) 108#define SHOW_STATS_1 (1<<2)
106#define SHOW_STATS_2 (1<<3) 109#define SHOW_STATS_2 (1<<3)
107#define SHOW_STATS_X (1<<4) 110#define SHOW_STATS_X (1<<4)
108#define SHOW_TOTALS (1<<7) 111#define SHOW_TOTALS (1<<7)
109#define SHOW_STATS_ALL (SHOW_STATS_1 | SHOW_STATS_2 | SHOW_STATS_X) 112#define SHOW_STATS_ALL (SHOW_STATS_1 | SHOW_STATS_2 | SHOW_STATS_X)
110 113
111static void cpustats(void); 114static void cpustats(void);
112static void drive_stats(double); 115static void drive_stats(double);
113static void drive_stats2(double); 116static void drive_stats2(double);
114static void drive_statsx(double); 117static void drive_statsx(double);
@@ -329,27 +332,29 @@ drive_stats(double etime) @@ -329,27 +332,29 @@ drive_stats(double etime)
329 (void)printf(" %4.0f", 332 (void)printf(" %4.0f",
330 (cur.rxfer[dn] + cur.wxfer[dn]) / etime); 333 (cur.rxfer[dn] + cur.wxfer[dn]) / etime);
331 334
332 /* time busy in drive activity */ 335 /* time busy in drive activity */
333 atime = (double)cur.time[dn].tv_sec + 336 atime = (double)cur.time[dn].tv_sec +
334 ((double)cur.time[dn].tv_usec / (double)1000000); 337 ((double)cur.time[dn].tv_usec / (double)1000000);
335 338
336 /* Megabytes per second. */ 339 /* Megabytes per second. */
337 if (atime != 0.0) 340 if (atime != 0.0)
338 mbps = (cur.rbytes[dn] + cur.wbytes[dn]) / 341 mbps = (cur.rbytes[dn] + cur.wbytes[dn]) /
339 (double)(1024 * 1024); 342 (double)(1024 * 1024);
340 else 343 else
341 mbps = 0; 344 mbps = 0;
342 (void)printf(" %5.2f ", mbps / etime); 345 mbps /= etime;
 346 (void)printf(" %5.*f ",
 347 MAX(0,3-(int)floor(log10(fabs(fmax(1.0,mbps))))), mbps);
343 } 348 }
344} 349}
345 350
346static void 351static void
347drive_stats2(double etime) 352drive_stats2(double etime)
348{ 353{
349 size_t dn; 354 size_t dn;
350 double atime; 355 double atime;
351 356
352 for (dn = 0; dn < ndrive; ++dn) { 357 for (dn = 0; dn < ndrive; ++dn) {
353 if (!cur.select[dn]) 358 if (!cur.select[dn])
354 continue; 359 continue;
355 360