Make pstat act like swapinfo if so invoked.
This commit is contained in:
parent
4067631146
commit
59392fe2bc
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
/*
|
||||
* Don't report statistics for partitions which have not
|
||||
* yet been activated via swapon(8).
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* 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");
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user