Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src add a "-h" (humanize_number(3)) option to swapctl(8) and pst...
details: https://anonhg.NetBSD.org/src/rev/e1852d6c8a89
branches: trunk
changeset: 556552:e1852d6c8a89
user: mrg <mrg%NetBSD.org@localhost>
date: Sat Dec 20 11:22:25 2003 +0000
description:
add a "-h" (humanize_number(3)) option to swapctl(8) and pstat(8), from
Martin Weber in PR#23805.
ps: now we only need someone to do ls(1) :-)
diffstat:
sbin/swapctl/swapctl.8 | 9 ++++-
sbin/swapctl/swapctl.c | 20 +++++++---
sbin/swapctl/swapctl.h | 4 +-
sbin/swapctl/swaplist.c | 93 ++++++++++++++++++++++++++++++++++++++----------
usr.sbin/pstat/pstat.8 | 8 +++-
usr.sbin/pstat/pstat.c | 14 ++++--
6 files changed, 113 insertions(+), 35 deletions(-)
diffs (truncated from 371 to 300 lines):
diff -r 084e86ddd176 -r e1852d6c8a89 sbin/swapctl/swapctl.8
--- a/sbin/swapctl/swapctl.8 Sat Dec 20 10:09:20 2003 +0000
+++ b/sbin/swapctl/swapctl.8 Sat Dec 20 11:22:25 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: swapctl.8,v 1.26 2003/02/25 10:35:11 wiz Exp $
+.\" $NetBSD: swapctl.8,v 1.27 2003/12/20 11:22:25 mrg Exp $
.\"
.\" Copyright (c) 1997 Matthew R. Green
.\" All rights reserved.
@@ -57,6 +57,7 @@
.Nm
.Fl l | Fl s
.Op Fl k
+.Op Fl h
.Nm
.Fl z
.Nm swapon
@@ -181,6 +182,12 @@
The
.Fl k
option uses 1024 byte blocks instead of the default 512 byte.
+.It Fl h
+The
+.Fl h
+option uses
+.Xr humanize_number 3
+to display the sizes.
.It Fl t
This flag modifies the function of the
.Fl A
diff -r 084e86ddd176 -r e1852d6c8a89 sbin/swapctl/swapctl.c
--- a/sbin/swapctl/swapctl.c Sat Dec 20 10:09:20 2003 +0000
+++ b/sbin/swapctl/swapctl.c Sat Dec 20 11:22:25 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: swapctl.c,v 1.23 2003/10/21 02:32:54 fvdl Exp $ */
+/* $NetBSD: swapctl.c,v 1.24 2003/12/20 11:22:25 mrg Exp $ */
/*
* Copyright (c) 1996, 1997, 1999 Matthew R. Green
@@ -39,6 +39,7 @@
* or all non-block devices
* -a <dev> add this device
* -d <dev> remove this swap device
+ * -h use humanize_number(3) for listing
* -l list swap devices
* -s short listing of swap devices
* -k use kilobytes
@@ -55,7 +56,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: swapctl.c,v 1.23 2003/10/21 02:32:54 fvdl Exp $");
+__RCSID("$NetBSD: swapctl.c,v 1.24 2003/12/20 11:22:25 mrg Exp $");
#endif
@@ -108,6 +109,9 @@
int kflag; /* display in 1K blocks */
#define KFLAG_CMDS (CMD_l | CMD_s)
+int hflag; /* display with humanize_number */
+#define HFLAG_CMDS (CMD_l | CMD_s)
+
int pflag; /* priority was specified */
#define PFLAG_CMDS (CMD_A | CMD_a | CMD_c)
@@ -148,7 +152,7 @@
}
#endif
- while ((c = getopt(argc, argv, "ADUacdlkp:st:z")) != -1) {
+ while ((c = getopt(argc, argv, "ADUacdhlkp:st:z")) != -1) {
switch (c) {
case 'A':
SET_COMMAND(CMD_A);
@@ -174,6 +178,10 @@
SET_COMMAND(CMD_d);
break;
+ case 'h':
+ hflag = 1;
+ break;
+
case 'l':
SET_COMMAND(CMD_l);
break;
@@ -246,11 +254,11 @@
/* Dispatch the command. */
switch (command) {
case CMD_l:
- list_swap(pri, kflag, pflag, 0, 1);
+ list_swap(pri, kflag, pflag, 0, 1, hflag);
break;
case CMD_s:
- list_swap(pri, kflag, pflag, 0, 0);
+ list_swap(pri, kflag, pflag, 0, 0, hflag);
break;
case CMD_c:
@@ -568,6 +576,6 @@
fprintf(stderr, " %s -a [-p priority] path\n", progname);
fprintf(stderr, " %s -c -p priority path\n", progname);
fprintf(stderr, " %s -d path\n", progname);
- fprintf(stderr, " %s -l | -s [-k]\n", progname);
+ fprintf(stderr, " %s -l | -s [-k|-h]\n", progname);
exit(1);
}
diff -r 084e86ddd176 -r e1852d6c8a89 sbin/swapctl/swapctl.h
--- a/sbin/swapctl/swapctl.h Sat Dec 20 10:09:20 2003 +0000
+++ b/sbin/swapctl/swapctl.h Sat Dec 20 11:22:25 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: swapctl.h,v 1.2 1997/10/10 05:39:54 mrg Exp $ */
+/* $NetBSD: swapctl.h,v 1.3 2003/12/20 11:22:25 mrg Exp $ */
/*
* Copyright (c) 1997 Matthew R. Green
@@ -29,4 +29,4 @@
*/
/* pri, kflag, pflag, tflag, dolong (1 for long, 0 for short) */
-void list_swap __P((int, int, int, int, int));
+void list_swap __P((int, int, int, int, int, int));
diff -r 084e86ddd176 -r e1852d6c8a89 sbin/swapctl/swaplist.c
--- a/sbin/swapctl/swaplist.c Sat Dec 20 10:09:20 2003 +0000
+++ b/sbin/swapctl/swaplist.c Sat Dec 20 11:22:25 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: swaplist.c,v 1.10 2003/06/23 11:53:45 agc Exp $ */
+/* $NetBSD: swaplist.c,v 1.11 2003/12/20 11:22:25 mrg Exp $ */
/*
* Copyright (c) 1997 Matthew R. Green
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: swaplist.c,v 1.10 2003/06/23 11:53:45 agc Exp $");
+__RCSID("$NetBSD: swaplist.c,v 1.11 2003/12/20 11:22:25 mrg Exp $");
#endif
@@ -45,6 +45,7 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
+#include <util.h>
#define dbtoqb(b) dbtob((int64_t)(b))
@@ -55,16 +56,18 @@
#include "swapctl.h"
void
-list_swap(pri, kflag, pflag, tflag, dolong)
+list_swap(pri, kflag, pflag, tflag, dolong, hflag)
int pri;
int kflag;
int pflag;
int tflag;
int dolong;
+ int hflag;
{
struct swapent *sep, *fsep;
long blocksize;
char *header;
+ char szbuf[5], usbuf[5], avbuf[5]; /* size, used, avail */
size_t l;
int hlen, totalsize, size, totalinuse, inuse, ncounted, pathmax;
int rnswap, nswap = swapctl(SWAP_NSWAP, 0, 0), i;
@@ -90,7 +93,11 @@
header = "1K-blocks";
blocksize = 1024;
hlen = strlen(header);
- } else
+ } else if (hflag) {
+ header = "Size";
+ blocksize = 1; /* unused */
+ hlen = strlen(header);
+ } else
header = getbsize(&hlen, &blocksize);
for (i = rnswap; i-- > 0; sep++)
if (pathmax < (l = strlen(sep->se_path)))
@@ -111,33 +118,81 @@
totalinuse += inuse;
if (dolong && tflag == 0) {
- (void)printf("%-*s %*ld ", pathmax, sep->se_path, hlen,
- (long)(dbtoqb(size) / blocksize));
+ if (hflag == 0) {
+ (void)printf("%-*s %*ld ", pathmax, sep->se_path, hlen,
+ (long)(dbtoqb(size) / blocksize));
- (void)printf("%8ld %8ld %5.0f%% %d\n",
- (long)(dbtoqb(inuse) / blocksize),
- (long)(dbtoqb(size - inuse) / blocksize),
- (double)inuse / (double)size * 100.0,
- sep->se_priority);
+ (void)printf("%8ld %8ld %5.0f%% %d\n",
+ (long)(dbtoqb(inuse) / blocksize),
+ (long)(dbtoqb(size - inuse) / blocksize),
+ (double)inuse / (double)size * 100.0,
+ sep->se_priority);
+ } else {
+ if ((humanize_number(szbuf, sizeof(szbuf), (dbtoqb(size)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ if ((humanize_number(usbuf, sizeof(usbuf), (dbtoqb(inuse)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ if ((humanize_number(avbuf, sizeof(avbuf), (dbtoqb(size-inuse)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ (void)printf("%-*s %*s ", pathmax, sep->se_path, hlen, szbuf);
+
+ (void)printf("%8s %8s %5.0f%% %d\n",
+ usbuf, avbuf,
+ (double)inuse / (double)size * 100.0,
+ sep->se_priority);
+ }
}
}
if (tflag)
(void)printf("%dM/%dM swap space\n",
(int)(dbtoqb(totalinuse) / (1024 * 1024)),
(int)(dbtoqb(totalsize) / (1024 * 1024)));
- else if (dolong == 0)
+ else if (dolong == 0) {
+ if (hflag) {
+ if ((humanize_number(szbuf, sizeof(szbuf), (dbtoqb(totalsize)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ if ((humanize_number(usbuf, sizeof(usbuf), (dbtoqb(totalinuse)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ if ((humanize_number(avbuf, sizeof(avbuf), (dbtoqb(totalsize-totalinuse)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ (void)printf("total: %s allocated = %s used, %s available.\n",
+ szbuf, usbuf, avbuf);
+ } else {
printf("total: %ldk bytes allocated = %ldk used, "
"%ldk available\n",
(long)(dbtoqb(totalsize) / 1024),
(long)(dbtoqb(totalinuse) / 1024),
(long)(dbtoqb(totalsize - totalinuse) / 1024));
- else if (ncounted > 1)
- (void)printf("%-*s %*ld %8ld %8ld %5.0f%%\n", pathmax, "Total",
- hlen,
- (long)(dbtoqb(totalsize) / blocksize),
- (long)(dbtoqb(totalinuse) / blocksize),
- (long)(dbtoqb(totalsize - totalinuse) / blocksize),
- (double)(totalinuse) / (double)totalsize * 100.0);
+ }
+ } else if (ncounted > 1) {
+ if (hflag) {
+ if ((humanize_number(szbuf, sizeof(szbuf), (dbtoqb(totalsize)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ if ((humanize_number(usbuf, sizeof(usbuf), (dbtoqb(totalinuse)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ if ((humanize_number(avbuf, sizeof(avbuf), (dbtoqb(totalsize-totalinuse)),
+ "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
+ err(1, "humanize_number");
+ (void)printf("%-*s %*s %8s %8s %5.0f%%\n", pathmax, "Total",
+ hlen, szbuf, usbuf, avbuf,
+ (double)(totalinuse) / (double)totalsize * 100.0);
+ } else {
+ (void)printf("%-*s %*ld %8ld %8ld %5.0f%%\n", pathmax, "Total",
+ hlen,
+ (long)(dbtoqb(totalsize) / blocksize),
+ (long)(dbtoqb(totalinuse) / blocksize),
+ (long)(dbtoqb(totalsize - totalinuse) / blocksize),
+ (double)(totalinuse) / (double)totalsize * 100.0);
+ }
+ }
if (fsep)
(void)free(fsep);
}
diff -r 084e86ddd176 -r e1852d6c8a89 usr.sbin/pstat/pstat.8
--- a/usr.sbin/pstat/pstat.8 Sat Dec 20 10:09:20 2003 +0000
+++ b/usr.sbin/pstat/pstat.8 Sat Dec 20 11:22:25 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pstat.8,v 1.31 2003/08/07 11:25:38 agc Exp $
+.\" $NetBSD: pstat.8,v 1.32 2003/12/20 11:22:25 mrg Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -41,7 +41,7 @@
.Fl T | Fl f | Fl s |
.Fl t | Fl v
.Oc
-.Op Fl kn
+.Op Fl knh
.Op Fl M Ar core
.Op Fl N Ar system
.Sh DESCRIPTION
@@ -101,6 +101,10 @@
.El
.It Fl k
Home |
Main Index |
Thread Index |
Old Index