From owner-svn-src-head@freebsd.org Thu Feb 20 21:12:12 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 61C81245EFD; Thu, 20 Feb 2020 21:12:12 +0000 (UTC) (envelope-from csjp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48NnNC0Hvbz4231; Thu, 20 Feb 2020 21:12:11 +0000 (UTC) (envelope-from csjp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E738327E7E; Thu, 20 Feb 2020 21:12:10 +0000 (UTC) (envelope-from csjp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01KLCAD8000853; Thu, 20 Feb 2020 21:12:10 GMT (envelope-from csjp@FreeBSD.org) Received: (from csjp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01KLCAKx000852; Thu, 20 Feb 2020 21:12:10 GMT (envelope-from csjp@FreeBSD.org) Message-Id: <202002202112.01KLCAKx000852@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: csjp set sender to csjp@FreeBSD.org using -f From: "Christian S.J. Peron" Date: Thu, 20 Feb 2020 21:12:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r358181 - head/usr.sbin/pstat X-SVN-Group: head X-SVN-Commit-Author: csjp X-SVN-Commit-Paths: head/usr.sbin/pstat X-SVN-Commit-Revision: 358181 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Feb 2020 21:12:12 -0000 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% $ After: $ swapinfo -h Device Size Used Avail Capacity /dev/gpt/swapfs 1.0G 0B 1.0G 0% $ Differential Revision: https://reviews.freebsd.org/D23758 Reviewed by: kevans MFC after: 3 weeks Modified: head/usr.sbin/pstat/pstat.c Modified: head/usr.sbin/pstat/pstat.c ============================================================================== --- head/usr.sbin/pstat/pstat.c Thu Feb 20 21:07:23 2020 (r358180) +++ head/usr.sbin/pstat/pstat.c Thu Feb 20 21:12:10 2020 (r358181) @@ -95,6 +95,8 @@ static struct { #define NNAMES (sizeof(namelist) / sizeof(*namelist)) static struct nlist nl[NNAMES]; +#define SIZEHDR "Size" + static int humanflag; static int usenumflag; static int totalflag; @@ -471,7 +473,12 @@ print_swap_header(void) long blocksize; const char *header; - header = getbsize(&hlen, &blocksize); + if (humanflag) { + header = SIZEHDR; + hlen = sizeof(SIZEHDR); + } else { + header = getbsize(&hlen, &blocksize); + } if (totalflag == 0) (void)printf("%-15s %*s %8s %8s %8s\n", "Device", hlen, header, @@ -484,23 +491,30 @@ print_swap_line(const char *swdevname, intmax_t nblks, { char usedbuf[5]; char availbuf[5]; + char sizebuf[5]; int hlen, pagesize; long blocksize; pagesize = getpagesize(); getbsize(&hlen, &blocksize); - printf("%-15s %*jd ", swdevname, hlen, CONVERT(nblks)); + printf("%-15s ", swdevname); if (humanflag) { + humanize_number(sizebuf, sizeof(sizebuf), + CONVERT_BLOCKS(nblks), "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); humanize_number(usedbuf, sizeof(usedbuf), CONVERT_BLOCKS(bused), "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); humanize_number(availbuf, sizeof(availbuf), CONVERT_BLOCKS(bavail), "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); - printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent); + printf("%8s %8s %8s %5.0f%%\n", sizebuf, + usedbuf, availbuf, bpercent); } else { - printf("%8jd %8jd %5.0f%%\n", (intmax_t)CONVERT(bused), + printf("%*jd %8jd %8jd %5.0f%%\n", hlen, + (intmax_t)CONVERT(nblks), + (intmax_t)CONVERT(bused), (intmax_t)CONVERT(bavail), bpercent); } }