summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pstat
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-05-13 17:25:23 +0000
committerphk <phk@FreeBSD.org>1995-05-13 17:25:23 +0000
commitc542ac95d3977a5878cea297413f20247dbe04d4 (patch)
treed4676e11a221865c9058218bdeaab1eb724ab770 /usr.sbin/pstat
parent8eb426e0952b47c8bc117ea3d14c72eb9a4946fd (diff)
downloadFreeBSD-src-c542ac95d3977a5878cea297413f20247dbe04d4.zip
FreeBSD-src-c542ac95d3977a5878cea297413f20247dbe04d4.tar.gz
Make pstat act like swapinfo if so invoked.
Diffstat (limited to 'usr.sbin/pstat')
-rw-r--r--usr.sbin/pstat/Makefile2
-rw-r--r--usr.sbin/pstat/pstat.825
-rw-r--r--usr.sbin/pstat/pstat.c60
3 files changed, 55 insertions, 32 deletions
diff --git a/usr.sbin/pstat/Makefile b/usr.sbin/pstat/Makefile
index 5018d43..a8f0496 100644
--- a/usr.sbin/pstat/Makefile
+++ b/usr.sbin/pstat/Makefile
@@ -7,5 +7,7 @@ BINMODE=2555
DPADD= ${LIBKVM}
LDADD= -lkvm
MAN8= pstat.8
+LINKS= ${BINDIR}/pstat ${BINDIR}/swapinfo
+MLINKS= pstat.8 swapinfo.8
.include <bsd.prog.mk>
diff --git a/usr.sbin/pstat/pstat.8 b/usr.sbin/pstat/pstat.8
index b2e8dec..fee4d0b 100644
--- a/usr.sbin/pstat/pstat.8
+++ b/usr.sbin/pstat/pstat.8
@@ -40,9 +40,12 @@
.Nd display system data structures
.Sh SYNOPSIS
.Nm pstat
-.Op Fl Tfnstv
+.Op Fl Tfknstv
.Op Fl M Ar core
.Op Fl N Ar system
+.Pp
+.Nm swapinfo
+.Op Fl k
.Sh DESCRIPTION
.Nm Pstat
displays open file entry, swap space utilization,
@@ -57,13 +60,22 @@ The required namelist is taken from
unless
.Ar system
is specified.
-The
-.Fl n
-option specifies that devices should be printed out by major/minor
-number rather than by name.
+.Pp
+If invoked as
+.Nm swapinfo
+the
+.Fl s
+option is implied, and only the
+.Fl k
+option is legal.
.Pp
Options are
.Bl -tag -width indent
+.It Fl n
+Print devices out by major/minor instead of name.
+.It Fl k
+Print sizes in kilobytes, regardless of the setting of the BLOCKSIZE
+environment variable.
.It Fl T
Prints the number of used and free slots in the several system tables
and is useful for checking to see how large system tables have become
@@ -311,9 +323,6 @@ default source of tables
.Ra K. Thompson
.Re
.Sh BUGS
-Swap statistics are reported for all swap partitions compiled into the kernel,
-regardless of whether those partitions are being used.
-.Pp
Does not understand NFS swap servers.
.Sh HISTORY
The
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c
index 493d7ce..3d40cb7 100644
--- a/usr.sbin/pstat/pstat.c
+++ b/usr.sbin/pstat/pstat.c
@@ -148,6 +148,8 @@ char *nlistf = NULL;
char *memf = NULL;
kvm_t *kd;
+char *usage;
+
#define SVAR(var) __STRING(var) /* to force expansion */
#define KGET(idx, var) \
KGET1(idx, &var, sizeof(var), SVAR(var))
@@ -179,7 +181,6 @@ void ttyprt __P((struct tty *, int));
void ttytype __P((struct tty *, char *, int, int));
void ufs_header __P((void));
int ufs_print __P((struct vnode *));
-void usage __P((void));
void vnode_header __P((void));
void vnode_print __P((struct vnode *, struct vnode *));
void vnodemode __P((void));
@@ -193,14 +194,33 @@ main(argc, argv)
extern int optind;
int ch, i, quit, ret;
int fileflag, swapflag, ttyflag, vnodeflag;
- char buf[_POSIX2_LINE_MAX];
+ char buf[_POSIX2_LINE_MAX],*opts;
fileflag = swapflag = ttyflag = vnodeflag = 0;
- while ((ch = getopt(argc, argv, "TM:N:finstv")) != EOF)
+
+ /* We will behave like good old swapinfo if thus invoked */
+ opts = strrchr(argv[0],'/');
+ if (opts)
+ opts++;
+ else
+ opts = argv[0];
+ if (!strcmp(opts,"swapinfo")) {
+ swapflag = 1;
+ opts = "k";
+ usage = "usage: swapinfo [-k] [-M core] [-N system]\n";
+ } else {
+ opts = "TM:N:fiknstv";
+ usage = "usage: pstat [-Tfknstv] [-M core] [-N system]\n";
+ }
+
+ while ((ch = getopt(argc, argv, opts)) != EOF)
switch (ch) {
case 'f':
fileflag = 1;
break;
+ case 'k':
+ putenv("BLOCKSIZE=1K");
+ break;
case 'M':
memf = optarg;
break;
@@ -224,7 +244,8 @@ main(argc, argv)
vnodeflag = 1;
break;
default:
- usage();
+ (void)fprintf(stderr, usage);
+ exit(1);
}
argc -= optind;
argv += optind;
@@ -249,8 +270,10 @@ main(argc, argv)
if (quit)
exit(1);
}
- if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag))
- usage();
+ if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag)) {
+ (void)fprintf(stderr, usage);
+ exit(1);
+ }
if (fileflag || totalflag)
filemode();
if (vnodeflag || totalflag)
@@ -1047,21 +1070,18 @@ swapmode()
for (i = 0; i < nswdev; i++) {
int xsize, xfree;
- if (!totalflag)
- (void)printf("/dev/%-6s %*d ",
- devname(sw[i].sw_dev, S_IFBLK),
- hlen, sw[i].sw_nblks / div);
-
/*
* Don't report statistics for partitions which have not
* yet been activated via swapon(8).
*/
- if (!(sw[i].sw_flags & SW_FREED)) {
- if (totalflag)
- continue;
- (void)printf(" *** not available for swapping ***\n");
+ if (!(sw[i].sw_flags & SW_FREED))
continue;
- }
+
+ if (!totalflag)
+ (void)printf("/dev/%-6s %*d ",
+ devname(sw[i].sw_dev, S_IFBLK),
+ hlen, sw[i].sw_nblks / div);
+
xsize = sw[i].sw_nblks;
xfree = perdev[i];
used = xsize - xfree;
@@ -1091,11 +1111,3 @@ swapmode()
(double)used / (double)avail * 100.0);
}
}
-
-void
-usage()
-{
- (void)fprintf(stderr,
- "usage: pstat [-Tfnstv] [-M core] [-N system]\n");
- exit(1);
-}
OpenPOWER on IntegriCloud