From nobody@FreeBSD.org  Wed Dec 28 21:16:39 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9044816A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 28 Dec 2005 21:16:39 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 032AF43D46
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 28 Dec 2005 21:16:39 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jBSLGcG9059202
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 28 Dec 2005 21:16:38 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jBSLGcNW059201;
	Wed, 28 Dec 2005 21:16:38 GMT
	(envelope-from nobody)
Message-Id: <200512282116.jBSLGcNW059201@www.freebsd.org>
Date: Wed, 28 Dec 2005 21:16:38 GMT
From: Robert Cousins <rec@RCousins.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: minor fix to iostat so that columns line up with 128KB xfers
X-Send-Pr-Version: www-2.3

>Number:         91034
>Category:       bin
>Synopsis:       [patch] minor fix to iostat(8) so that columns line up with 128KB xfers
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 28 21:20:03 GMT 2005
>Closed-Date:    
>Last-Modified:  Wed Jan  4 02:10:03 GMT 2006
>Originator:     Robert Cousins
>Release:        6.0
>Organization:
Cousins Consulting
>Environment:
FreeBSD hammer.home.rcousins.com 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Tue Dec 13 17:37:31 PST 2005     rec@hammer.home.rcousins.com:/usr/src/sys/amd64/compile/HAMMER  amd64
            
>Description:
Iostat's output can be kind of ugly under USF2 with 128KB transfers. Here is an example:

      tty             ad0              ad1             cpu
 tin tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
   0   60  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
   0  180  0.00   0  0.00  128.00   8  1.00  48  0  0  0 51
   0   61  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
   0   60  0.00   0  0.00   0.00   0  0.00  49  0  0  0 51

The problem comes from the KB/t column which goes one character too wide.

The patch I'm submitting notices when this value is >= 100 and
drops from 2 decimals to 1 in this case. The result is an output
like this:

      tty             ad0              ad1             cpu
 tin tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
   0   60  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
   0  180  0.00   0  0.00  128.0   8  1.00  48  0  0  0 51
   0   61  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
   0   60  0.00   0  0.00   0.00   0  0.00  49  0  0  0 51
        
I find this much easier to read. (A better fix would be to drop
down to 1 decimal digit for all values but I figured that would
be up to you, not me.)
>How-To-Repeat:

Run 'iostat 1' on any machine with periodic (bursty) I/O on a file system.
The results will be as shown above.
>Fix:
My fix is trivial but functional. You probably have a better way to do it.
*** old_iostat.c        Wed Dec 28 13:01:20 2005
--- iostat.c    Wed Dec 28 13:02:21 2005
***************
*** 696,707 ****
                                       msdig,
                                       ms_per_transaction);
                } else {
!                       if (Iflag == 0)
                                printf(" %5.2Lf %3.0Lf %5.2Lf ", 
                                       kb_per_transfer,
                                       transfers_per_second,
                                       mb_per_second);
!                       else {
                                total_mb = total_bytes;
                                total_mb /= 1024 * 1024;
  
--- 696,713 ----
                                       msdig,
                                       ms_per_transaction);
                } else {
!                       if (Iflag == 0) {
!                           if (kb_per_transfer < 100.)
                                printf(" %5.2Lf %3.0Lf %5.2Lf ", 
                                       kb_per_transfer,
                                       transfers_per_second,
                                       mb_per_second);
!                              else
!                               printf(" %5.1Lf %3.0Lf %5.2Lf ", 
!                                      kb_per_transfer,
!                                      transfers_per_second,
!                                      mb_per_second);
!                       } else {
                                total_mb = total_bytes;
                                total_mb /= 1024 * 1024;
  
         
>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Robert Cousins <rec@RCousins.com>
Cc: bug-followup@freebsd.org
Subject: Re: bin/91034: minor fix to iostat so that columns line up with 128KB xfers
Date: Tue, 3 Jan 2006 10:28:23 +0200

 On 2005-12-28 21:16, Robert Cousins <rec@RCousins.com> wrote:
 > Iostat's output can be kind of ugly under USF2 with 128KB
 > transfers. Here is an example:
 >
 >       tty             ad0              ad1             cpu
 >  tin tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
 >    0   60  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
 >    0  180  0.00   0  0.00  128.00   8  1.00  48  0  0  0 51
 >    0   61  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
 >    0   60  0.00   0  0.00   0.00   0  0.00  49  0  0  0 51
 >
 > The problem comes from the KB/t column which goes one character too wide.
 >
 > The patch I'm submitting notices when this value is >= 100 and
 > drops from 2 decimals to 1 in this case. The result is an output
 > like this:
 >
 >       tty             ad0              ad1             cpu
 >  tin tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
 >    0   60  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
 >    0  180  0.00   0  0.00  128.0   8  1.00  48  0  0  0 51
 >    0   61  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
 >    0   60  0.00   0  0.00   0.00   0  0.00  49  0  0  0 51
 
 The misaligned dots seem a bit ugly.  Is it ok to use %6.2Lf as
 the format specifier, widening the KB columns a bit to fit the
 new length of the text?
 

From: Giorgos Keramidas <keramida@ceid.upatras.gr>
To: Bruce Evans <bde@zeta.org.au>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/91034: minor fix to iostat so that columns line up with 128KB xfers
Date: Tue, 3 Jan 2006 23:46:52 +0200

 On 2006-01-03 22:40, Bruce Evans <bde@zeta.org.au> wrote:
 >On Tue, 3 Jan 2006, Giorgos Keramidas wrote:
 >>On 2005-12-28 21:16, Robert Cousins <rec@RCousins.com> wrote:
 >>> Iostat's output can be kind of ugly under USF2 with 128KB
 >>> transfers. Here is an example:
 >>> ...
 >>> The patch I'm submitting notices when this value is >= 100 and
 >>> drops from 2 decimals to 1 in this case. The result is an output
 >>> like this:
 >>>
 >>>       tty             ad0              ad1             cpu
 >>>  tin tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
 >>>    0   60  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
 >>>    0  180  0.00   0  0.00  128.0   8  1.00  48  0  0  0 51
 >>>    0   61  0.00   0  0.00   0.00   0  0.00  50  0  0  0 50
 >>>    0   60  0.00   0  0.00   0.00   0  0.00  49  0  0  0 51
 >>
 >> The misaligned dots seem a bit ugly.
 >
 > Indeed.  They are like the -h (hideous or human-unreadable) output
 > in many utilities.  Exponential notation and columns that aren't
 > lined up are hard for humans to read.
 >
 > >Is it ok to use %6.2Lf as
 > >the format specifier, widening the KB columns a bit to fit the
 > >new length of the text?
 >
 > No.  There is space in the above, but most systems have more than 2 drives
 > (most of mine have 6, with 4 physical drives and extras from atapicam
 > duplicating acd0 and cam giving a virtual drive pass0).  Info about 3
 > drives just fits in 80 columns with %5.2Lf format.  It results in 77
 > coumns being used.  %6.2Lf format would result in 80 columns being used
 > and thus ugly line wrap on some terminals (or the number of drives being
 > limited to 2).
 
 So, there's no way to keep the pretty format of current iostat output
 *and* account for larger transfer speeds? :-(
 
 Looking at an awk-formatted version of the iostat output it seems that
 even with 3 disks we *do* hae 3 columns to spare until 79 columns are
 reached:
 
 $ iostat ad0 da0 pass0 | awk '{printf "%-78s|\n",$0}'
       tty             ad0              da0            pass0             cpu   |
  tin tout  KB/t tps  MB/s   KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id   |
   63  514  7.10  13  0.09   0.01   0  0.00   0.00   0  0.00   1  0  2  0 96   |
 $
 
 Is this enough for adding an extra column to every KB/t column and
 still keeping everything under 80 columns?
 

From: "Matthew D. Fuller" <fullermd@over-yonder.net>
To: Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/91034: minor fix to iostat so that columns line up with 128KB xfers
Date: Tue, 3 Jan 2006 18:42:06 -0600

 On Tue, Jan 03, 2006 at 09:50:09PM +0000 I heard the voice of
 Giorgos Keramidas, and lo! it spake thus:
 >  
 >  So, there's no way to keep the pretty format of current iostat
 >  output *and* account for larger transfer speeds? :-(
 
 Drop to one digit after the decimal point?  100-byte granularity
 sounds reasonable for such an overview tool.
 
 
 -- 
 Matthew Fuller     (MF4839)   |  fullermd@over-yonder.net
 Systems/Network Administrator |  http://www.over-yonder.net/~fullermd/
            On the Internet, nobody can hear you scream.

From: Bruce Evans <bde@zeta.org.au>
To: Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/91034: minor fix to iostat so that columns line up with
 128KB xfers
Date: Wed, 4 Jan 2006 13:09:02 +1100 (EST)

 On Tue, 3 Jan 2006, Giorgos Keramidas wrote:
 
 > On 2006-01-03 22:40, Bruce Evans <bde@zeta.org.au> wrote:
 >> On Tue, 3 Jan 2006, Giorgos Keramidas wrote:
 >>> On 2005-12-28 21:16, Robert Cousins <rec@RCousins.com> wrote:
 >>>> Iostat's output can be kind of ugly under USF2 with 128KB
 >>>> transfers. Here is an example:
 >>>> ...
 >>>> The patch I'm submitting notices when this value is >= 100 and
 >>>> drops from 2 decimals to 1 in this case. The result is an output
 >>>> like this:
 >>> ...
 >>> The misaligned dots seem a bit ugly.
 >> ...
 >>> Is it ok to use %6.2Lf as
 >>> the format specifier, widening the KB columns a bit to fit the
 >>> new length of the text?
 >>
 >> No.  There is space in the above, but most systems have more than 2 drives
 >> ...
 >
 > So, there's no way to keep the pretty format of current iostat output
 > *and* account for larger transfer speeds? :-(
 
 Maybe always drop %5.1Lf format for disk MB/s.  If the value is < 0.10
 MB/s then it is so low that you don't really care if it is 0.01 or 0.09.
 However, floppies have a top speed of about 0.04, and speeds below
 0.10 are all too common for faster disks doing too many seeks.
 
 > Looking at an awk-formatted version of the iostat output it seems that
 > even with 3 disks we *do* hae 3 columns to spare until 79 columns are
 > reached:
 >
 > $ iostat ad0 da0 pass0 | awk '{printf "%-78s|\n",$0}'
 >      tty             ad0              da0            pass0             cpu   |
 > tin tout  KB/t tps  MB/s   KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id   |
 >  63  514  7.10  13  0.09   0.01   0  0.00   0.00   0  0.00   1  0  2  0 96   |
 > $
 
 >
 > Is this enough for adding an extra column to every KB/t column and
 > still keeping everything under 80 columns?
 
 No, since there are actually only 2 columns to spare.  "id" sometimes
 takes an extra column since it is sometimes 100.  I hacked its format
 in rev.1.25 of iostat.c from %3.0f to " %2.0f".  The space keeps it
 from running into "in", and reducing the field width keeps the line
 length the same except when cpu is 100 when it doesn't fit in %2.0f.
 As mentioned in the log message for this, larger fixes are needed.
 I think they should be something like
 "iostat -w N | awk '{printf "%*.*s %*.*s ...\n", $1, $2, ...}'" where the
 awk script calculates the column widths dynamically and is actually
 a library function.  This should also work for ps and df.  It's easier
 for them since all the input can be read before doing any output.
 Except I'd like ps to have a "repeat" arg like iostat, for watching
 a few selected processes better than top(1) or repeatedly rerunning
 ps(1) can do.
 
 Bruce
>Unformatted:
