1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1986, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-25 06:40:05 +00:00
|
|
|
static const char copyright[] =
|
1994-05-27 12:33:43 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
2003-12-11 10:58:29 +00:00
|
|
|
#endif /* not lint */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-11 10:58:29 +00:00
|
|
|
#if 0
|
1994-05-27 12:33:43 +00:00
|
|
|
#ifndef lint
|
2003-12-11 10:58:29 +00:00
|
|
|
static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
|
|
|
|
#endif /* not lint */
|
1997-08-25 06:40:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-11 10:58:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
1995-12-13 15:01:13 +00:00
|
|
|
#include <sys/uio.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
2003-02-16 16:01:52 +00:00
|
|
|
#include <sys/resource.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/sysctl.h>
|
1995-12-13 11:33:34 +00:00
|
|
|
#include <sys/vmmeter.h>
|
1995-12-13 15:01:13 +00:00
|
|
|
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <ctype.h>
|
2001-12-11 22:59:36 +00:00
|
|
|
#include <devstat.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <err.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <errno.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <paths.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-10-06 18:52:16 +00:00
|
|
|
#include <sysexits.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-12-11 22:59:36 +00:00
|
|
|
static char da[] = "da";
|
|
|
|
|
|
|
|
static struct nlist namelist[] = {
|
1994-05-27 12:33:43 +00:00
|
|
|
#define X_CPTIME 0
|
|
|
|
{ "_cp_time" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_SUM 1
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_cnt" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_BOOTTIME 2
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_boottime" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_HZ 3
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_hz" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_STATHZ 4
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_stathz" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_NCHSTATS 5
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_nchstats" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_INTRNAMES 6
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_intrnames" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_EINTRNAMES 7
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_eintrnames" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_INTRCNT 8
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_intrcnt" },
|
1998-09-15 08:16:45 +00:00
|
|
|
#define X_EINTRCNT 9
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_eintrcnt" },
|
1997-10-06 18:52:16 +00:00
|
|
|
#ifdef notyet
|
2002-04-15 04:05:53 +00:00
|
|
|
#define X_DEFICIT 10
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_deficit" },
|
2003-04-14 07:21:03 +00:00
|
|
|
#define X_REC 11
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_rectime" },
|
2003-04-14 07:21:03 +00:00
|
|
|
#define X_PGIN 12
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_pgintime" },
|
2003-04-14 07:21:03 +00:00
|
|
|
#define X_XSTATS 13
|
1994-05-27 12:33:43 +00:00
|
|
|
{ "_xstats" },
|
2003-04-14 07:21:03 +00:00
|
|
|
#define X_END 14
|
1994-05-27 12:33:43 +00:00
|
|
|
#else
|
2002-04-15 04:05:53 +00:00
|
|
|
#define X_END 10
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
|
|
|
{ "" },
|
|
|
|
};
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static struct statinfo cur, last;
|
|
|
|
static int num_devices, maxshowdevs;
|
|
|
|
static long generation;
|
|
|
|
static struct device_selection *dev_select;
|
|
|
|
static int num_selected;
|
|
|
|
static struct devstat_match *matches;
|
|
|
|
static int num_matches = 0;
|
|
|
|
static int num_devices_specified, num_selections;
|
|
|
|
static long select_generation;
|
|
|
|
static char **specified_devices;
|
|
|
|
static devstat_select_mode select_mode;
|
|
|
|
|
|
|
|
static struct vmmeter sum, osum;
|
|
|
|
|
|
|
|
static int winlines = 20;
|
|
|
|
static int aflag;
|
|
|
|
static int nflag;
|
|
|
|
|
|
|
|
static kvm_t *kd;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#define FORKSTAT 0x01
|
|
|
|
#define INTRSTAT 0x02
|
|
|
|
#define MEMSTAT 0x04
|
|
|
|
#define SUMSTAT 0x08
|
|
|
|
#define TIMESTAT 0x10
|
|
|
|
#define VMSTAT 0x20
|
1999-02-13 09:59:24 +00:00
|
|
|
#define ZMEMSTAT 0x40
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-03-22 01:42:45 +00:00
|
|
|
static void cpustats(void);
|
|
|
|
static void devstats(void);
|
2003-11-08 07:24:03 +00:00
|
|
|
static void doforkst(void);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void domem(void);
|
|
|
|
static void dointr(void);
|
|
|
|
static void dosum(void);
|
2003-12-10 19:24:11 +00:00
|
|
|
static void dosysctl(const char *);
|
2003-12-10 21:43:10 +00:00
|
|
|
static void dovmstat(unsigned int, int);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void dozmem(void);
|
|
|
|
static void kread(int, void *, size_t);
|
|
|
|
static void needhdr(int);
|
|
|
|
static void printhdr(void);
|
|
|
|
static void usage(void);
|
|
|
|
|
|
|
|
static long pct(long, long);
|
|
|
|
static long getuptime(void);
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static char **getdrivedata(char **);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-08-25 06:40:05 +00:00
|
|
|
int
|
2003-12-07 17:46:14 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-11 22:59:36 +00:00
|
|
|
int c, todo;
|
2003-12-10 21:43:10 +00:00
|
|
|
unsigned int interval;
|
1994-05-27 12:33:43 +00:00
|
|
|
int reps;
|
|
|
|
char *memf, *nlistf;
|
2001-06-19 17:59:40 +00:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
memf = nlistf = NULL;
|
|
|
|
interval = reps = todo = 0;
|
1999-02-10 00:46:27 +00:00
|
|
|
maxshowdevs = 2;
|
2003-12-07 17:46:14 +00:00
|
|
|
while ((c = getopt(argc, argv, "ac:fiM:mN:n:p:stw:z")) != -1) {
|
1994-05-27 12:33:43 +00:00
|
|
|
switch (c) {
|
2003-12-07 17:46:14 +00:00
|
|
|
case 'a':
|
|
|
|
aflag++;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'c':
|
|
|
|
reps = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|
2003-04-14 07:21:03 +00:00
|
|
|
todo |= FORKSTAT;
|
1997-10-06 18:52:16 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'i':
|
|
|
|
todo |= INTRSTAT;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
todo |= MEMSTAT;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
case 'n':
|
1998-09-16 18:20:23 +00:00
|
|
|
nflag = 1;
|
1998-09-15 08:16:45 +00:00
|
|
|
maxshowdevs = atoi(optarg);
|
|
|
|
if (maxshowdevs < 0)
|
|
|
|
errx(1, "number of devices %d is < 0",
|
|
|
|
maxshowdevs);
|
|
|
|
break;
|
|
|
|
case 'p':
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_buildmatch(optarg, &matches, &num_matches) != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 's':
|
|
|
|
todo |= SUMSTAT;
|
|
|
|
break;
|
|
|
|
case 't':
|
1997-10-06 18:52:16 +00:00
|
|
|
#ifdef notyet
|
1994-05-27 12:33:43 +00:00
|
|
|
todo |= TIMESTAT;
|
1997-10-06 18:52:16 +00:00
|
|
|
#else
|
|
|
|
errx(EX_USAGE, "sorry, -t is not (re)implemented yet");
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
1997-10-06 18:52:16 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'w':
|
|
|
|
interval = atoi(optarg);
|
|
|
|
break;
|
1999-02-15 14:15:28 +00:00
|
|
|
case 'z':
|
|
|
|
todo |= ZMEMSTAT;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (todo == 0)
|
|
|
|
todo = VMSTAT;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (memf != NULL) {
|
|
|
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
|
|
|
if (kd == NULL)
|
|
|
|
errx(1, "kvm_openfiles: %s", errbuf);
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (c > 0) {
|
1997-08-25 06:40:05 +00:00
|
|
|
warnx("undefined symbols:");
|
1994-05-27 12:33:43 +00:00
|
|
|
for (c = 0;
|
2003-12-07 17:46:14 +00:00
|
|
|
c < (int)(sizeof(namelist)/sizeof(namelist[0]));
|
|
|
|
c++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (namelist[c].n_type == 0)
|
2001-08-11 19:41:56 +00:00
|
|
|
(void)fprintf(stderr, " %s",
|
1994-05-27 12:33:43 +00:00
|
|
|
namelist[c].n_name);
|
|
|
|
(void)fputc('\n', stderr);
|
|
|
|
} else
|
1997-08-25 06:40:05 +00:00
|
|
|
warnx("kvm_nlist: %s", kvm_geterr(kd));
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todo & VMSTAT) {
|
|
|
|
struct winsize winsize;
|
|
|
|
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
/*
|
|
|
|
* Make sure that the userland devstat version matches the
|
|
|
|
* kernel devstat version. If not, exit and print a
|
|
|
|
* message informing the user of his mistake.
|
|
|
|
*/
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_checkversion(NULL) < 0)
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
argv = getdrivedata(argv);
|
|
|
|
winsize.ws_row = 0;
|
|
|
|
(void) ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize);
|
|
|
|
if (winsize.ws_row > 0)
|
|
|
|
winlines = winsize.ws_row;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BACKWARD_COMPATIBILITY
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
|
|
|
if (*argv) {
|
|
|
|
interval = atoi(*argv);
|
|
|
|
if (*++argv)
|
|
|
|
reps = atoi(*argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (interval) {
|
|
|
|
if (!reps)
|
|
|
|
reps = -1;
|
|
|
|
} else if (reps)
|
|
|
|
interval = 1;
|
|
|
|
|
|
|
|
if (todo & FORKSTAT)
|
|
|
|
doforkst();
|
|
|
|
if (todo & MEMSTAT)
|
|
|
|
domem();
|
1999-02-13 09:59:24 +00:00
|
|
|
if (todo & ZMEMSTAT)
|
|
|
|
dozmem();
|
1994-05-27 12:33:43 +00:00
|
|
|
if (todo & SUMSTAT)
|
|
|
|
dosum();
|
1997-10-06 18:52:16 +00:00
|
|
|
#ifdef notyet
|
1994-05-27 12:33:43 +00:00
|
|
|
if (todo & TIMESTAT)
|
|
|
|
dotimes();
|
|
|
|
#endif
|
|
|
|
if (todo & INTRSTAT)
|
|
|
|
dointr();
|
|
|
|
if (todo & VMSTAT)
|
|
|
|
dovmstat(interval, reps);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static int
|
|
|
|
mysysctl(const char *name, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = sysctlbyname(name, oldp, oldlenp, newp, newlen);
|
|
|
|
if (error != 0 && errno != ENOMEM)
|
|
|
|
err(1, "sysctl(%s)", name);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **
|
|
|
|
getdrivedata(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-03-15 21:25:44 +00:00
|
|
|
if ((num_devices = devstat_getnumdevs(NULL)) < 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
bzero(cur.dinfo, sizeof(struct devinfo));
|
|
|
|
bzero(last.dinfo, sizeof(struct devinfo));
|
|
|
|
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_getdevs(NULL, &cur) == -1)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
|
|
|
|
|
|
|
specified_devices = (char **)malloc(sizeof(char *));
|
|
|
|
for (num_devices_specified = 0; *argv; ++argv) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (isdigit(**argv))
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
num_devices_specified++;
|
|
|
|
specified_devices = (char **)realloc(specified_devices,
|
|
|
|
sizeof(char *) *
|
|
|
|
num_devices_specified);
|
|
|
|
specified_devices[num_devices_specified - 1] = *argv;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
dev_select = NULL;
|
|
|
|
|
1998-09-16 18:20:23 +00:00
|
|
|
if (nflag == 0 && maxshowdevs < num_devices_specified)
|
|
|
|
maxshowdevs = num_devices_specified;
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* People are generally only interested in disk statistics when
|
|
|
|
* they're running vmstat. So, that's what we're going to give
|
|
|
|
* them if they don't specify anything by default. We'll also give
|
|
|
|
* them any other random devices in the system so that we get to
|
|
|
|
* maxshowdevs devices, if that many devices exist. If the user
|
|
|
|
* specifies devices on the command line, either through a pattern
|
|
|
|
* match or by naming them explicitly, we will give the user only
|
|
|
|
* those devices.
|
|
|
|
*/
|
|
|
|
if ((num_devices_specified == 0) && (num_matches == 0)) {
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_buildmatch(da, &matches, &num_matches) != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
select_mode = DS_SELECT_ADD;
|
|
|
|
} else
|
|
|
|
select_mode = DS_SELECT_ONLY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, selectdevs will almost surely indicate that the
|
|
|
|
* device list has changed, so we don't look for return values of 0
|
|
|
|
* or 1. If we get back -1, though, there is an error.
|
|
|
|
*/
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
|
1998-09-15 08:16:45 +00:00
|
|
|
&select_generation, generation, cur.dinfo->devices,
|
|
|
|
num_devices, matches, num_matches, specified_devices,
|
|
|
|
num_devices_specified, select_mode,
|
|
|
|
maxshowdevs, 0) == -1)
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
return(argv);
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static long
|
|
|
|
getuptime(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-08-09 15:47:43 +00:00
|
|
|
static struct timeval boottime;
|
|
|
|
static time_t now;
|
1994-05-27 12:33:43 +00:00
|
|
|
time_t uptime;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (boottime.tv_sec == 0) {
|
|
|
|
if (kd != NULL) {
|
|
|
|
kread(X_BOOTTIME, &boottime, sizeof(boottime));
|
|
|
|
} else {
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = sizeof(boottime);
|
|
|
|
mysysctl("kern.boottime", &boottime, &size, NULL, 0);
|
|
|
|
if (size != sizeof(boottime))
|
|
|
|
errx(1, "kern.boottime size mismatch");
|
|
|
|
}
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)time(&now);
|
2002-08-09 15:47:43 +00:00
|
|
|
uptime = now - boottime.tv_sec;
|
1997-08-25 06:40:05 +00:00
|
|
|
if (uptime <= 0 || uptime > 60*60*24*365*10)
|
|
|
|
errx(1, "time makes no sense; namelist must be wrong");
|
1994-05-27 12:33:43 +00:00
|
|
|
return(uptime);
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
fill_vmmeter(struct vmmeter *vmmp)
|
|
|
|
{
|
|
|
|
if (kd != NULL) {
|
|
|
|
kread(X_SUM, vmmp, sizeof(*vmmp));
|
|
|
|
} else {
|
|
|
|
size_t size = sizeof(unsigned int);
|
|
|
|
#define GET_VM_STATS(cat, name) \
|
|
|
|
mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size, NULL, 0)
|
|
|
|
/* sys */
|
|
|
|
GET_VM_STATS(sys, v_swtch);
|
|
|
|
GET_VM_STATS(sys, v_trap);
|
|
|
|
GET_VM_STATS(sys, v_syscall);
|
|
|
|
GET_VM_STATS(sys, v_intr);
|
|
|
|
GET_VM_STATS(sys, v_soft);
|
|
|
|
|
|
|
|
/* vm */
|
2003-12-10 22:19:19 +00:00
|
|
|
GET_VM_STATS(vm, v_vm_faults);
|
|
|
|
GET_VM_STATS(vm, v_cow_faults);
|
|
|
|
GET_VM_STATS(vm, v_cow_optim);
|
|
|
|
GET_VM_STATS(vm, v_zfod);
|
|
|
|
GET_VM_STATS(vm, v_ozfod);
|
|
|
|
GET_VM_STATS(vm, v_swapin);
|
|
|
|
GET_VM_STATS(vm, v_swapout);
|
|
|
|
GET_VM_STATS(vm, v_swappgsin);
|
|
|
|
GET_VM_STATS(vm, v_swappgsout);
|
|
|
|
GET_VM_STATS(vm, v_vnodein);
|
|
|
|
GET_VM_STATS(vm, v_vnodeout);
|
|
|
|
GET_VM_STATS(vm, v_vnodepgsin);
|
|
|
|
GET_VM_STATS(vm, v_vnodepgsout);
|
|
|
|
GET_VM_STATS(vm, v_intrans);
|
|
|
|
GET_VM_STATS(vm, v_reactivated);
|
|
|
|
GET_VM_STATS(vm, v_pdwakeups);
|
|
|
|
GET_VM_STATS(vm, v_pdpages);
|
|
|
|
GET_VM_STATS(vm, v_dfree);
|
|
|
|
GET_VM_STATS(vm, v_pfree);
|
|
|
|
GET_VM_STATS(vm, v_tfree);
|
|
|
|
GET_VM_STATS(vm, v_page_size);
|
|
|
|
GET_VM_STATS(vm, v_page_count);
|
|
|
|
GET_VM_STATS(vm, v_free_reserved);
|
|
|
|
GET_VM_STATS(vm, v_free_target);
|
|
|
|
GET_VM_STATS(vm, v_free_min);
|
|
|
|
GET_VM_STATS(vm, v_free_count);
|
|
|
|
GET_VM_STATS(vm, v_wire_count);
|
|
|
|
GET_VM_STATS(vm, v_active_count);
|
|
|
|
GET_VM_STATS(vm, v_inactive_target);
|
|
|
|
GET_VM_STATS(vm, v_inactive_count);
|
|
|
|
GET_VM_STATS(vm, v_cache_count);
|
|
|
|
GET_VM_STATS(vm, v_cache_min);
|
|
|
|
GET_VM_STATS(vm, v_cache_max);
|
|
|
|
GET_VM_STATS(vm, v_pageout_free_min);
|
|
|
|
GET_VM_STATS(vm, v_interrupt_free_min);
|
|
|
|
/*GET_VM_STATS(vm, v_free_severe);*/
|
2003-12-07 17:46:14 +00:00
|
|
|
GET_VM_STATS(vm, v_forks);
|
|
|
|
GET_VM_STATS(vm, v_vforks);
|
|
|
|
GET_VM_STATS(vm, v_rforks);
|
|
|
|
GET_VM_STATS(vm, v_kthreads);
|
|
|
|
GET_VM_STATS(vm, v_forkpages);
|
|
|
|
GET_VM_STATS(vm, v_vforkpages);
|
|
|
|
GET_VM_STATS(vm, v_rforkpages);
|
|
|
|
GET_VM_STATS(vm, v_kthreadpages);
|
|
|
|
#undef GET_VM_STATS
|
|
|
|
}
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
fill_vmtotal(struct vmtotal *vmtp)
|
|
|
|
{
|
|
|
|
if (kd != NULL) {
|
|
|
|
/* XXX fill vmtp */
|
|
|
|
errx(1, "not implemented");
|
|
|
|
} else {
|
|
|
|
size_t size = sizeof(*vmtp);
|
|
|
|
mysysctl("vm.vmtotal", vmtp, &size, NULL, 0);
|
|
|
|
if (size != sizeof(*vmtp))
|
|
|
|
errx(1, "vm.total size mismatch");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hz, hdrcnt;
|
|
|
|
|
|
|
|
static void
|
2003-12-10 21:43:10 +00:00
|
|
|
dovmstat(unsigned int interval, int reps)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct vmtotal total;
|
|
|
|
time_t uptime, halfuptime;
|
1998-09-15 08:16:45 +00:00
|
|
|
struct devinfo *tmp_dinfo;
|
2001-07-29 21:56:14 +00:00
|
|
|
size_t size;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
uptime = getuptime();
|
|
|
|
halfuptime = uptime / 2;
|
|
|
|
(void)signal(SIGCONT, needhdr);
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
if (namelist[X_STATHZ].n_type != 0 &&
|
|
|
|
namelist[X_STATHZ].n_value != 0)
|
|
|
|
kread(X_STATHZ, &hz, sizeof(hz));
|
|
|
|
if (!hz)
|
|
|
|
kread(X_HZ, &hz, sizeof(hz));
|
|
|
|
} else {
|
|
|
|
struct clockinfo clockrate;
|
|
|
|
|
|
|
|
size = sizeof(clockrate);
|
|
|
|
mysysctl("kern.clockrate", &clockrate, &size, NULL, 0);
|
|
|
|
if (size != sizeof(clockrate))
|
|
|
|
errx(1, "clockrate size mismatch");
|
|
|
|
hz = clockrate.hz;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (hdrcnt = 1;;) {
|
|
|
|
if (!--hdrcnt)
|
|
|
|
printhdr();
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
kread(X_CPTIME, cur.cp_time, sizeof(cur.cp_time));
|
|
|
|
} else {
|
|
|
|
size = sizeof(cur.cp_time);
|
|
|
|
mysysctl("kern.cp_time", &cur.cp_time, &size, NULL, 0);
|
|
|
|
if (size != sizeof(cur.cp_time))
|
|
|
|
errx(1, "cp_time size mismatch");
|
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
tmp_dinfo = last.dinfo;
|
|
|
|
last.dinfo = cur.dinfo;
|
|
|
|
cur.dinfo = tmp_dinfo;
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
last.snap_time = cur.snap_time;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here what we want to do is refresh our device stats.
|
|
|
|
* getdevs() returns 1 when the device list has changed.
|
|
|
|
* If the device list has changed, we want to go through
|
|
|
|
* the selection process again, in case a device that we
|
|
|
|
* were previously displaying has gone away.
|
|
|
|
*/
|
2003-03-15 21:25:44 +00:00
|
|
|
switch (devstat_getdevs(NULL, &cur)) {
|
1998-09-15 08:16:45 +00:00
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1: {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
|
|
|
|
2003-03-15 21:25:44 +00:00
|
|
|
retval = devstat_selectdevs(&dev_select, &num_selected,
|
1998-09-15 08:16:45 +00:00
|
|
|
&num_selections, &select_generation,
|
|
|
|
generation, cur.dinfo->devices,
|
|
|
|
num_devices, matches, num_matches,
|
|
|
|
specified_devices,
|
|
|
|
num_devices_specified, select_mode,
|
|
|
|
maxshowdevs, 0);
|
|
|
|
switch (retval) {
|
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
printhdr();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
fill_vmmeter(&sum);
|
|
|
|
fill_vmtotal(&total);
|
2001-06-23 17:52:10 +00:00
|
|
|
(void)printf("%2d %1d %1d",
|
1994-05-27 12:33:43 +00:00
|
|
|
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
|
2001-02-22 13:55:12 +00:00
|
|
|
#define vmstat_pgtok(a) ((a) * sum.v_page_size >> 10)
|
1994-05-27 12:33:43 +00:00
|
|
|
#define rate(x) (((x) + halfuptime) / uptime) /* round */
|
2001-08-11 19:41:56 +00:00
|
|
|
(void)printf(" %7ld %6ld ", (long)vmstat_pgtok(total.t_avm),
|
|
|
|
(long)vmstat_pgtok(total.t_free));
|
1998-07-06 21:01:54 +00:00
|
|
|
(void)printf("%4lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults));
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%3lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_reactivated - osum.v_reactivated));
|
1998-07-06 21:01:54 +00:00
|
|
|
(void)printf("%3lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_swapin + sum.v_vnodein -
|
1994-10-17 10:34:42 +00:00
|
|
|
(osum.v_swapin + osum.v_vnodein)));
|
1998-07-06 21:01:54 +00:00
|
|
|
(void)printf("%3lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_swapout + sum.v_vnodeout -
|
1994-10-18 15:00:06 +00:00
|
|
|
(osum.v_swapout + osum.v_vnodeout)));
|
1998-07-06 21:01:54 +00:00
|
|
|
(void)printf("%3lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_tfree - osum.v_tfree));
|
1998-07-06 21:01:54 +00:00
|
|
|
(void)printf("%3lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_pdpages - osum.v_pdpages));
|
1998-09-15 08:16:45 +00:00
|
|
|
devstats();
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%4lu %4lu %3lu ",
|
2003-12-10 21:43:10 +00:00
|
|
|
(unsigned long)rate(sum.v_intr - osum.v_intr),
|
|
|
|
(unsigned long)rate(sum.v_syscall - osum.v_syscall),
|
|
|
|
(unsigned long)rate(sum.v_swtch - osum.v_swtch));
|
1994-05-27 12:33:43 +00:00
|
|
|
cpustats();
|
|
|
|
(void)printf("\n");
|
|
|
|
(void)fflush(stdout);
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
|
|
|
osum = sum;
|
|
|
|
uptime = interval;
|
|
|
|
/*
|
|
|
|
* We round upward to avoid losing low-frequency events
|
|
|
|
* (i.e., >= 1 per interval but < 1 per second).
|
|
|
|
*/
|
1994-10-17 10:34:42 +00:00
|
|
|
if (interval != 1)
|
|
|
|
halfuptime = (uptime + 1) / 2;
|
|
|
|
else
|
|
|
|
halfuptime = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)sleep(interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
printhdr(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1999-02-10 00:46:27 +00:00
|
|
|
int i, num_shown;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1999-02-10 00:46:27 +00:00
|
|
|
num_shown = (num_selected < maxshowdevs) ? num_selected : maxshowdevs;
|
2001-06-23 17:52:10 +00:00
|
|
|
(void)printf(" procs memory page%*s", 19, "");
|
1999-02-10 00:46:27 +00:00
|
|
|
if (num_shown > 1)
|
|
|
|
(void)printf(" disks %*s", num_shown * 4 - 7, "");
|
|
|
|
else if (num_shown == 1)
|
|
|
|
(void)printf("disk");
|
|
|
|
(void)printf(" faults cpu\n");
|
2001-06-23 17:52:10 +00:00
|
|
|
(void)printf(" r b w avm fre flt re pi po fr sr ");
|
1998-09-15 08:16:45 +00:00
|
|
|
for (i = 0; i < num_devices; i++)
|
|
|
|
if ((dev_select[i].selected)
|
|
|
|
&& (dev_select[i].selected <= maxshowdevs))
|
|
|
|
(void)printf("%c%c%d ", dev_select[i].device_name[0],
|
|
|
|
dev_select[i].device_name[1],
|
|
|
|
dev_select[i].unit_number);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf(" in sy cs us sy id\n");
|
|
|
|
hdrcnt = winlines - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force a header to be prepended to the next output.
|
|
|
|
*/
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
needhdr(int dummy __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
hdrcnt = 1;
|
|
|
|
}
|
|
|
|
|
1997-10-06 18:52:16 +00:00
|
|
|
#ifdef notyet
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
dotimes(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-12-10 21:43:10 +00:00
|
|
|
unsigned int pgintime, rectime;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
kread(X_REC, &rectime, sizeof(rectime));
|
|
|
|
kread(X_PGIN, &pgintime, sizeof(pgintime));
|
|
|
|
kread(X_SUM, &sum, sizeof(sum));
|
|
|
|
(void)printf("%u reclaims, %u total time (usec)\n",
|
|
|
|
sum.v_pgrec, rectime);
|
|
|
|
(void)printf("average: %u usec / reclaim\n", rectime / sum.v_pgrec);
|
|
|
|
(void)printf("\n");
|
|
|
|
(void)printf("%u page ins, %u total time (msec)\n",
|
|
|
|
sum.v_pgin, pgintime / 10);
|
|
|
|
(void)printf("average: %8.1f msec / page in\n",
|
|
|
|
pgintime / (sum.v_pgin * 10.0));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static long
|
|
|
|
pct(long top, long bot)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
long ans;
|
|
|
|
|
|
|
|
if (bot == 0)
|
|
|
|
return(0);
|
|
|
|
ans = (quad_t)top * 100 / bot;
|
|
|
|
return (ans);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCT(top, bot) pct((long)(top), (long)(bot))
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
dosum(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-11 22:59:36 +00:00
|
|
|
struct nchstats lnchstats;
|
1994-05-27 12:33:43 +00:00
|
|
|
long nchtotal;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
fill_vmmeter(&sum);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%9u cpu context switches\n", sum.v_swtch);
|
|
|
|
(void)printf("%9u device interrupts\n", sum.v_intr);
|
|
|
|
(void)printf("%9u software interrupts\n", sum.v_soft);
|
|
|
|
(void)printf("%9u traps\n", sum.v_trap);
|
|
|
|
(void)printf("%9u system calls\n", sum.v_syscall);
|
2001-01-23 14:32:01 +00:00
|
|
|
(void)printf("%9u kernel threads created\n", sum.v_kthreads);
|
|
|
|
(void)printf("%9u fork() calls\n", sum.v_forks);
|
|
|
|
(void)printf("%9u vfork() calls\n", sum.v_vforks);
|
|
|
|
(void)printf("%9u rfork() calls\n", sum.v_rforks);
|
1994-10-17 10:34:42 +00:00
|
|
|
(void)printf("%9u swap pager pageins\n", sum.v_swapin);
|
|
|
|
(void)printf("%9u swap pager pages paged in\n", sum.v_swappgsin);
|
1994-10-18 15:00:06 +00:00
|
|
|
(void)printf("%9u swap pager pageouts\n", sum.v_swapout);
|
1994-10-17 10:34:42 +00:00
|
|
|
(void)printf("%9u swap pager pages paged out\n", sum.v_swappgsout);
|
|
|
|
(void)printf("%9u vnode pager pageins\n", sum.v_vnodein);
|
|
|
|
(void)printf("%9u vnode pager pages paged in\n", sum.v_vnodepgsin);
|
1994-10-18 15:00:06 +00:00
|
|
|
(void)printf("%9u vnode pager pageouts\n", sum.v_vnodeout);
|
1994-10-17 10:34:42 +00:00
|
|
|
(void)printf("%9u vnode pager pages paged out\n", sum.v_vnodepgsout);
|
1994-10-18 15:00:06 +00:00
|
|
|
(void)printf("%9u page daemon wakeups\n", sum.v_pdwakeups);
|
|
|
|
(void)printf("%9u pages examined by the page daemon\n", sum.v_pdpages);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%9u pages reactivated\n", sum.v_reactivated);
|
|
|
|
(void)printf("%9u copy-on-write faults\n", sum.v_cow_faults);
|
1998-03-07 23:40:23 +00:00
|
|
|
(void)printf("%9u copy-on-write optimized faults\n", sum.v_cow_optim);
|
1995-03-25 08:44:48 +00:00
|
|
|
(void)printf("%9u zero fill pages zeroed\n", sum.v_zfod);
|
1998-03-07 23:40:23 +00:00
|
|
|
(void)printf("%9u zero fill pages prezeroed\n", sum.v_ozfod);
|
1995-03-25 08:44:48 +00:00
|
|
|
(void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
|
1994-10-18 15:00:06 +00:00
|
|
|
(void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
|
2001-01-23 14:32:01 +00:00
|
|
|
(void)printf("%9u pages affected by kernel thread creation\n", sum.v_kthreadpages);
|
|
|
|
(void)printf("%9u pages affected by fork()\n", sum.v_forkpages);
|
|
|
|
(void)printf("%9u pages affected by vfork()\n", sum.v_vforkpages);
|
|
|
|
(void)printf("%9u pages affected by rfork()\n", sum.v_rforkpages);
|
1994-10-18 15:00:06 +00:00
|
|
|
(void)printf("%9u pages freed\n", sum.v_tfree);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%9u pages freed by daemon\n", sum.v_dfree);
|
|
|
|
(void)printf("%9u pages freed by exiting processes\n", sum.v_pfree);
|
|
|
|
(void)printf("%9u pages active\n", sum.v_active_count);
|
|
|
|
(void)printf("%9u pages inactive\n", sum.v_inactive_count);
|
1995-01-10 05:52:59 +00:00
|
|
|
(void)printf("%9u pages in VM cache\n", sum.v_cache_count);
|
1994-10-18 15:00:06 +00:00
|
|
|
(void)printf("%9u pages wired down\n", sum.v_wire_count);
|
|
|
|
(void)printf("%9u pages free\n", sum.v_free_count);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%9u bytes per page\n", sum.v_page_size);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats));
|
|
|
|
} else {
|
|
|
|
size_t size = sizeof(lnchstats);
|
|
|
|
mysysctl("vfs.cache.nchstats", &lnchstats, &size, NULL, 0);
|
|
|
|
if (size != sizeof(lnchstats))
|
|
|
|
errx(1, "vfs.cache.nchstats size mismatch");
|
|
|
|
}
|
2001-12-11 22:59:36 +00:00
|
|
|
nchtotal = lnchstats.ncs_goodhits + lnchstats.ncs_neghits +
|
|
|
|
lnchstats.ncs_badhits + lnchstats.ncs_falsehits +
|
|
|
|
lnchstats.ncs_miss + lnchstats.ncs_long;
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%9ld total name lookups\n", nchtotal);
|
|
|
|
(void)printf(
|
1997-08-25 06:40:05 +00:00
|
|
|
"%9s cache hits (%ld%% pos + %ld%% neg) system %ld%% per-directory\n",
|
2001-12-11 22:59:36 +00:00
|
|
|
"", PCT(lnchstats.ncs_goodhits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_neghits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_pass2, nchtotal));
|
1997-08-25 06:40:05 +00:00
|
|
|
(void)printf("%9s deletions %ld%%, falsehits %ld%%, toolong %ld%%\n", "",
|
2001-12-11 22:59:36 +00:00
|
|
|
PCT(lnchstats.ncs_badhits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_falsehits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_long, nchtotal));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
doforkst(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-12-07 17:46:14 +00:00
|
|
|
fill_vmmeter(&sum);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%d forks, %d pages, average %.2f\n",
|
2003-04-14 07:21:03 +00:00
|
|
|
sum.v_forks, sum.v_forkpages,
|
|
|
|
sum.v_forks == 0 ? 0.0 :
|
|
|
|
(double)sum.v_forkpages / sum.v_forks);
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)printf("%d vforks, %d pages, average %.2f\n",
|
2003-04-14 07:21:03 +00:00
|
|
|
sum.v_vforks, sum.v_vforkpages,
|
|
|
|
sum.v_vforks == 0 ? 0.0 :
|
|
|
|
(double)sum.v_vforkpages / sum.v_vforks);
|
|
|
|
(void)printf("%d rforks, %d pages, average %.2f\n",
|
|
|
|
sum.v_rforks, sum.v_rforkpages,
|
|
|
|
sum.v_rforks == 0 ? 0.0 :
|
|
|
|
(double)sum.v_rforkpages / sum.v_rforks);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
static void
|
2003-12-07 17:46:14 +00:00
|
|
|
devstats(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-11 22:59:36 +00:00
|
|
|
int dn, state;
|
1998-09-15 08:16:45 +00:00
|
|
|
long double transfers_per_second;
|
|
|
|
long double busy_seconds;
|
1994-05-27 12:33:43 +00:00
|
|
|
long tmp;
|
2003-12-07 17:46:14 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
for (state = 0; state < CPUSTATES; ++state) {
|
1998-09-15 08:16:45 +00:00
|
|
|
tmp = cur.cp_time[state];
|
|
|
|
cur.cp_time[state] -= last.cp_time[state];
|
|
|
|
last.cp_time[state] = tmp;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
busy_seconds = cur.snap_time - last.snap_time;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
for (dn = 0; dn < num_devices; dn++) {
|
|
|
|
int di;
|
|
|
|
|
|
|
|
if ((dev_select[dn].selected == 0)
|
|
|
|
|| (dev_select[dn].selected > maxshowdevs))
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
di = dev_select[dn].position;
|
|
|
|
|
2001-08-11 19:41:56 +00:00
|
|
|
if (devstat_compute_statistics(&cur.dinfo->devices[di],
|
|
|
|
&last.dinfo->devices[di], busy_seconds,
|
|
|
|
DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
|
|
|
|
DSM_NONE) != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
2001-08-11 19:41:56 +00:00
|
|
|
(void)printf("%3.0Lf ", transfers_per_second);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
cpustats(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-11 22:59:36 +00:00
|
|
|
int state;
|
|
|
|
double lpct, total;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
total = 0;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
1998-09-15 08:16:45 +00:00
|
|
|
total += cur.cp_time[state];
|
1994-05-27 12:33:43 +00:00
|
|
|
if (total)
|
2001-12-11 22:59:36 +00:00
|
|
|
lpct = 100.0 / total;
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2001-12-11 22:59:36 +00:00
|
|
|
lpct = 0.0;
|
1998-09-15 08:16:45 +00:00
|
|
|
(void)printf("%2.0f ", (cur.cp_time[CP_USER] +
|
2001-12-11 22:59:36 +00:00
|
|
|
cur.cp_time[CP_NICE]) * lpct);
|
1998-09-15 08:16:45 +00:00
|
|
|
(void)printf("%2.0f ", (cur.cp_time[CP_SYS] +
|
2001-12-11 22:59:36 +00:00
|
|
|
cur.cp_time[CP_INTR]) * lpct);
|
|
|
|
(void)printf("%2.0f", cur.cp_time[CP_IDLE] * lpct);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
dointr(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-12-10 21:43:10 +00:00
|
|
|
unsigned long *intrcnt, uptime;
|
2003-12-10 22:11:51 +00:00
|
|
|
uint64_t inttotal;
|
|
|
|
size_t clen, inamlen, intrcntlen, istrnamlen;
|
|
|
|
unsigned int i, nintr;
|
2003-10-28 05:02:03 +00:00
|
|
|
char *intrname, *tintrname;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
uptime = getuptime();
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
2003-12-10 22:11:51 +00:00
|
|
|
intrcntlen = namelist[X_EINTRCNT].n_value -
|
2003-12-07 17:46:14 +00:00
|
|
|
namelist[X_INTRCNT].n_value;
|
|
|
|
inamlen = namelist[X_EINTRNAMES].n_value -
|
|
|
|
namelist[X_INTRNAMES].n_value;
|
2003-12-10 22:11:51 +00:00
|
|
|
if ((intrcnt = malloc(intrcntlen)) == NULL ||
|
2003-12-08 07:57:57 +00:00
|
|
|
(intrname = malloc(inamlen)) == NULL)
|
2003-12-07 17:46:14 +00:00
|
|
|
err(1, "malloc()");
|
2003-12-10 22:11:51 +00:00
|
|
|
kread(X_INTRCNT, intrcnt, intrcntlen);
|
2003-12-08 07:57:57 +00:00
|
|
|
kread(X_INTRNAMES, intrname, inamlen);
|
2003-12-07 17:46:14 +00:00
|
|
|
} else {
|
2003-12-11 07:46:08 +00:00
|
|
|
for (intrcnt = NULL, intrcntlen = 1024; ; intrcntlen *= 2) {
|
|
|
|
if ((intrcnt = reallocf(intrcnt, intrcntlen)) == NULL)
|
|
|
|
err(1, "reallocf()");
|
|
|
|
if (mysysctl("hw.intrcnt",
|
|
|
|
intrcnt, &intrcntlen, NULL, 0) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2003-12-07 17:46:14 +00:00
|
|
|
for (intrname = NULL, inamlen = 1024; ; inamlen *= 2) {
|
|
|
|
if ((intrname = reallocf(intrname, inamlen)) == NULL)
|
|
|
|
err(1, "reallocf()");
|
|
|
|
if (mysysctl("hw.intrnames",
|
|
|
|
intrname, &inamlen, NULL, 0) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-10 22:11:51 +00:00
|
|
|
nintr = intrcntlen / sizeof(unsigned long);
|
2003-10-28 05:02:03 +00:00
|
|
|
tintrname = intrname;
|
2003-11-09 20:39:56 +00:00
|
|
|
istrnamlen = strlen("interrupt");
|
2003-10-28 05:02:03 +00:00
|
|
|
for (i = 0; i < nintr; i++) {
|
|
|
|
clen = strlen(tintrname);
|
|
|
|
if (clen > istrnamlen)
|
|
|
|
istrnamlen = clen;
|
|
|
|
tintrname += clen + 1;
|
|
|
|
}
|
|
|
|
(void)printf("%-*s %20s %10s\n", istrnamlen, "interrupt", "total",
|
|
|
|
"rate");
|
1994-05-27 12:33:43 +00:00
|
|
|
inttotal = 0;
|
2003-12-08 07:57:57 +00:00
|
|
|
for (i = 0; i < nintr; i++) {
|
2003-12-10 22:11:51 +00:00
|
|
|
if (intrname[0] != '\0' && (*intrcnt != 0 || aflag))
|
2003-10-28 05:02:03 +00:00
|
|
|
(void)printf("%-*s %20lu %10lu\n", istrnamlen, intrname,
|
1994-05-27 12:33:43 +00:00
|
|
|
*intrcnt, *intrcnt / uptime);
|
|
|
|
intrname += strlen(intrname) + 1;
|
|
|
|
inttotal += *intrcnt++;
|
|
|
|
}
|
2003-12-08 07:57:57 +00:00
|
|
|
(void)printf("%-*s %20llu %10llu\n", istrnamlen, "Total",
|
|
|
|
(long long)inttotal, (long long)(inttotal / uptime));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
2002-04-15 04:05:53 +00:00
|
|
|
domem(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL)
|
|
|
|
errx(1, "not implemented");
|
2002-04-15 04:05:53 +00:00
|
|
|
dosysctl("kern.malloc");
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
2002-04-15 04:05:53 +00:00
|
|
|
dozmem(void)
|
|
|
|
{
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL)
|
|
|
|
errx(1, "not implemented");
|
2002-04-15 04:05:53 +00:00
|
|
|
dosysctl("vm.zone");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
2003-12-10 19:24:11 +00:00
|
|
|
dosysctl(const char *name)
|
1999-02-13 09:59:24 +00:00
|
|
|
{
|
2001-01-23 00:31:56 +00:00
|
|
|
char *buf;
|
|
|
|
size_t bufsize;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
for (buf = NULL, bufsize = 1024; ; bufsize *= 2) {
|
2001-01-23 00:31:56 +00:00
|
|
|
if ((buf = realloc(buf, bufsize)) == NULL)
|
|
|
|
err(1, "realloc()");
|
2003-12-07 17:46:14 +00:00
|
|
|
if (mysysctl(name, buf, &bufsize, 0, NULL) == 0)
|
1999-02-13 09:59:24 +00:00
|
|
|
break;
|
2001-01-23 00:31:56 +00:00
|
|
|
bufsize *= 2;
|
1999-02-13 09:59:24 +00:00
|
|
|
}
|
2001-01-23 00:31:56 +00:00
|
|
|
buf[bufsize] = '\0'; /* play it safe */
|
|
|
|
(void)printf("%s\n\n", buf);
|
|
|
|
free(buf);
|
1999-02-13 09:59:24 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* kread reads something from the kernel, given its nlist index.
|
|
|
|
*/
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
kread(int nlx, void *addr, size_t size)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-12-25 01:32:55 +00:00
|
|
|
const char *sym;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-10-28 06:41:24 +00:00
|
|
|
if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
sym = namelist[nlx].n_name;
|
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
1997-08-25 06:40:05 +00:00
|
|
|
errx(1, "symbol %s not defined", sym);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2003-11-08 07:24:03 +00:00
|
|
|
if ((size_t)kvm_read(kd, namelist[nlx].n_value, addr, size) != size) {
|
1994-05-27 12:33:43 +00:00
|
|
|
sym = namelist[nlx].n_name;
|
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
1997-08-25 06:40:05 +00:00
|
|
|
errx(1, "%s: %s", sym, kvm_geterr(kd));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-02-22 13:55:12 +00:00
|
|
|
(void)fprintf(stderr, "%s%s",
|
2003-12-07 17:46:14 +00:00
|
|
|
"usage: vmstat [-aimsz] [-c count] [-M core] [-N system] [-w wait]\n",
|
2001-02-22 13:55:12 +00:00
|
|
|
" [-n devs] [disks]\n");
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|