Bug 191976 - [patch] vmstat(8): fix formatting to fit in 80 cols
Summary: [patch] vmstat(8): fix formatting to fit in 80 cols
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Kirk McKusick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-20 00:54 UTC by Andy Kosela
Modified: 2014-10-24 04:03 UTC (History)
2 users (show)

See Also:


Attachments
vmstat.diff (2.30 KB, patch)
2014-07-20 00:54 UTC, Andy Kosela
no flags Details | Diff
output on freefall (619 bytes, text/plain)
2014-09-19 20:55 UTC, Kirk McKusick
no flags Details
vmstat.diff (2.73 KB, patch)
2014-09-20 06:35 UTC, Andy Kosela
no flags Details | Diff
extended run of vmstat on freefall (1.42 KB, text/plain)
2014-09-22 14:01 UTC, Kirk McKusick
no flags Details
vmstat.diff (12.84 KB, patch)
2014-09-26 15:32 UTC, Andy Kosela
no flags Details | Diff
vmstat.diff (2.80 KB, patch)
2014-09-26 15:38 UTC, Andy Kosela
no flags Details | Diff
vmstat.diff (4.61 KB, patch)
2014-10-15 16:30 UTC, Andy Kosela
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Kosela 2014-07-20 00:54:36 UTC
Created attachment 144803 [details]
vmstat.diff

vmstat(8): fix formatting to fit in 80 cols.  

Fix formatting so that it looks cleaner on standard 80 cols displays and it's not wrapping so often.

---------------------------------[BEFORE]----------------------------------------
zork $ vmstat    
 procs      memory      page                    disks     faults         cpu
 r b w     avm    fre   flt  re  pi  po    fr  sr ad0 cd0   in   sy   cs us sy i
d
 1 0 0    446M    70M    16   0   0   0    17   5   0   0  407  188  141  0  0 1
00

---------------------------------[AFTER]-----------------------------------------
zork $ vmstat
 procs     memory      page                    disks     faults        cpu
 r b w     avm    fre  flt  re  pi  po  fr  sr ad0 cd0   in    sy   cs us sy id
 1 0 0    446M    70M   16   0   0   0  17   5   0   0  407   187  141  0  0 100
Comment 1 Kirk McKusick freebsd_committer freebsd_triage 2014-09-19 20:55:39 UTC
Created attachment 147490 [details]
output on freefall

The idea looks good, but output on a busy system still overflows. Suggest some more tweeking is needed.
Comment 2 Andy Kosela 2014-09-20 06:35:57 UTC
Created attachment 147495 [details]
vmstat.diff
Comment 3 Andy Kosela 2014-09-20 06:40:03 UTC
(In reply to Kirk McKusick from comment #1)
> Created attachment 147490 [details]
> output on freefall
> 
> The idea looks good, but output on a busy system still overflows. Suggest
> some more tweeking is needed.

New diff attached.  It reserves at least '%4lu' for parameters that are known 
to cause overflow.
Comment 4 Kirk McKusick freebsd_committer freebsd_triage 2014-09-22 14:01:02 UTC
Created attachment 147560 [details]
extended run of vmstat on freefall
Comment 5 Kirk McKusick freebsd_committer freebsd_triage 2014-09-22 14:04:33 UTC
Further (extended) run of vmstat with revised patch.
Different fields are now blowing it out.
It may be that the best way to fix it is to use the prthuman() function to bound the size of fields that may get too large.
It may also be sensible to check the width of the window and use that value to determine how many disk drives to display.
Comment 6 Andy Kosela 2014-09-26 15:32:27 UTC
Created attachment 147697 [details]
vmstat.diff
Comment 7 Andy Kosela 2014-09-26 15:38:59 UTC
Created attachment 147698 [details]
vmstat.diff
Comment 8 Andy Kosela 2014-09-26 15:47:34 UTC
New revised patch.  I'm not a big fan of using prthuman() to display 
fields which should stay the way they are from the historical
perspective.

Also, by the default only two drives are displayed unless you change it
with '-n' switch, so there is no reason to check TIOCGWINSZ.

This patch still can make vmstat(8) wrap in extreme cases, but it looks
much cleaner in 95% of cases now (much better than first patch).
Comment 9 Andy Kosela 2014-10-15 16:30:53 UTC
Created attachment 148344 [details]
vmstat.diff
Comment 10 commit-hook freebsd_committer freebsd_triage 2014-10-24 04:01:18 UTC
A commit references this bug:

Author: mckusick
Date: Fri Oct 24 04:01:15 UTC 2014
New revision: 273575
URL: https://svnweb.freebsd.org/changeset/base/273575

Log:
  Fix formatting of vmstat (1) so that it looks cleaner on standard 80
  column displays. In particular it wraps far less often.

  Submitted by: Andy Kosela <akosela@andykosela.com>
  PR:           191976

Changes:
  head/usr.bin/vmstat/vmstat.c