svn commit: r358181 - head/usr.sbin/pstat

Piotr P. Stefaniak pstef at freebsd.org
Mon Jun 22 21:53:16 UTC 2020


On 2020-02-20 21:12:10, Christian S.J. Peron wrote:
>Author: csjp
>Date: Thu Feb 20 21:12:10 2020
>New Revision: 358181
>URL: https://svnweb.freebsd.org/changeset/base/358181
>
>Log:
>  - Implement -h (human readable) for the size of the underlying block disk.
>    Currently, the size of the swap device is unconditionally reported using
>    blocks, even if -h has been used.
>  - While here, switch to CONVERT_BLOCKS() instead of CONVERT() which will
>    avoid overflowing size counters (in human readable form see: r196244)
>  - Update the column headers to reflect that a size is being reported instead
>    of the block size units being used
>
>  Before:
>
>  $ swapinfo
>  Device          1K-blocks     Used    Avail Capacity
>  /dev/gpt/swapfs   1048576        0  1048576     0%

In the above, the "1K-blocks" and "1048576" line up because both the
header and the value have field width of hlen which is always set by
getbsize(&hlen, &blocksize). In other words, the header name sets the
width for the column. It is especially apparent when you compare output
with BLOCKSIZE=1000000000 and BLOCKSIZE=1K.

>  After:
>
>  $ swapinfo -h
>  Device           Size     Used    Avail Capacity
>  /dev/gpt/swapfs    1.0G       0B     1.0G     0%

Here the width for the header is sizeof "Size" and the width for values
of the size is 8, so the header and the values don't make up a column.

Since field width for all values of Size, Used, and Avail are hardcoded
to 8 as well as the column headers, I think the best suggestion I can
give is to change it like this:

@@ -475,7 +475,7 @@ print_swap_header(void)
  
         if (humanflag) {
                 header = SIZEHDR;
-               hlen = sizeof(SIZEHDR);
+               hlen = 8; /* as the hardcoded field width of values */
         } else {
                 header = getbsize(&hlen, &blocksize);
         }

Although 8 seems to me a bit high. And too bad that humanize_number() is
locale-agnostic. 

>  Differential Revision:	https://reviews.freebsd.org/D23758
>  Reviewed by:	kevans
>  MFC after:	3 weeks
>
>Modified:
>  head/usr.sbin/pstat/pstat.c


More information about the svn-src-head mailing list