Subject: bin/12691: vmstat output numbers run together
To: None <gnats-bugs@gnats.netbsd.org>
From: None <anne@alcor.concordia.ca>
List: netbsd-bugs
Date: 04/18/2001 13:36:17
>Number:         12691
>Category:       bin
>Synopsis:       vmstat output numbers run together
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 18 13:37:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Anne Bennett
>Release:        1.5
>Organization:
Concordia University
>Environment:
NetBSD eridani.concordia.ca 1.5 NetBSD 1.5 (ERIDANI) #1: Tue Mar 20 15:48:34 EST 2001     anne@eridani.concordia.ca:/big/sources/usr/src/sys/arch/i386/compile/ERIDANI i386

>Description:
The printf formats used to display the processes (r, b, w) and the
memory usage ("avm" and "fre") have no spaces in them, so if it is
necessary to display a number as wide as or wider than the formats
allow for, numbers run into each other and become hard for a human
to interpret, and *very* hard for a program to interpret.
>How-To-Repeat:
Invoke "vmstat" (no options) on a machine with enough memory to use up
at least 6 digits of "avm" or "fre"; for example, my machine has 256MB
of RAM, or 256K 1K pages, so if most of it is free, "fre" needs all
six digits and runs into "avm":

 procs   memory     page                       disks         faults      cpu
 r b w   avm   fre  flt  re  pi   po   fr   sr c0 f0 s0 c1   in   sy  cs us sy id
 0 0 0  8372184736  231   0   0    0    0    0  0  0  8  0  124  235  83 30  1 69

Something similar will happen when there are more than 99 blocked or
waiting processes.
>Fix:
Just change two printf formats to insert spaces.  I reduced the size
of the fields so that things would stay lined up as they are now
unless the number overruns the field.


--- vmstat.c.original   Thu Sep 28 11:23:56 2000
+++ vmstat.c    Wed Apr 18 16:31:25 2001
@@ -461,11 +461,11 @@
                                memset(&total, 0, sizeof(total));
                        }
                }
-               (void)printf("%2d%2d%2d",
+               (void)printf(" %d %d %d",
                    total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
 #define pgtok(a) (long)((a) * (pagesize >> 10))
 #define        rate(x) (u_long)(((x) + halfuptime) / uptime)   /* round */
-               (void)printf("%6ld%6ld ",
+               (void)printf(" %5ld %5ld ",
                    pgtok(total.t_avm), pgtok(total.t_free));
                (void)printf("%4lu ", rate(uvmexp.faults - ouvmexp.faults));
                (void)printf("%3lu ", rate(uvmexp.pdreact - ouvmexp.pdreact));

>Release-Note:
>Audit-Trail:
>Unformatted: