aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian S.J. Peron <csjp@FreeBSD.org>2020-02-20 21:12:10 +0000
committerChristian S.J. Peron <csjp@FreeBSD.org>2020-02-20 21:12:10 +0000
commit9a990500e5e0959c7a82aa6035d7a52ba33b7f6f (patch)
tree2ff31326951e1c4862a44760ba8f9ce601f42b00
parentf92bb8c19af0a06a957877dc6326c55d95136553 (diff)
downloadsrc-9a990500e5e0959c7a82aa6035d7a52ba33b7f6f.tar.gz
src-9a990500e5e0959c7a82aa6035d7a52ba33b7f6f.zip
- 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
Notes
Notes: svn path=/head/; revision=358181
-rw-r--r--usr.sbin/pstat/pstat.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c
index c704f1599fff..923357b2c24d 100644
--- a/usr.sbin/pstat/pstat.c
+++ b/usr.sbin/pstat/pstat.c
@@ -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, intmax_t bused,
{
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);
}
}