1999-02-12 18:04:00 +03:00
|
|
|
/* $NetBSD: vmstat.c,v 1.55 1999/02/12 15:04:00 kleink Exp $ */
|
1998-02-13 08:10:32 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
1995-05-08 02:16:23 +04:00
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
1994-05-11 11:34:05 +04:00
|
|
|
* Copyright (c) 1980, 1986, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:58:42 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#ifndef lint
|
1997-10-20 07:11:57 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-05-08 02:16:23 +04:00
|
|
|
#if 0
|
1997-10-18 18:34:39 +04:00
|
|
|
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
|
1995-05-08 02:16:23 +04:00
|
|
|
#else
|
1999-02-12 18:04:00 +03:00
|
|
|
__RCSID("$NetBSD: vmstat.c,v 1.55 1999/02/12 15:04:00 kleink Exp $");
|
1995-05-08 02:16:23 +04:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-05-11 11:34:05 +04:00
|
|
|
#include <sys/sysctl.h>
|
1995-03-14 10:35:49 +03:00
|
|
|
#include <sys/device.h>
|
1998-07-27 14:26:11 +04:00
|
|
|
#include <sys/pool.h>
|
1994-05-11 11:34:05 +04:00
|
|
|
#include <vm/vm.h>
|
1998-02-13 08:10:32 +03:00
|
|
|
#include <err.h>
|
1999-02-12 18:04:00 +03:00
|
|
|
#include <fcntl.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <time.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
1995-06-27 04:31:00 +04:00
|
|
|
#include <signal.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <paths.h>
|
1994-05-11 11:34:05 +04:00
|
|
|
#include <limits.h>
|
1996-05-11 03:16:30 +04:00
|
|
|
#include "dkstats.h"
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
#include <uvm/uvm_stat.h>
|
|
|
|
#endif
|
|
|
|
|
1994-05-11 11:34:05 +04:00
|
|
|
struct nlist namelist[] = {
|
1993-04-09 16:58:42 +04:00
|
|
|
#define X_CPTIME 0
|
|
|
|
{ "_cp_time" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_BOOTTIME 1
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_boottime" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_HZ 2
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_hz" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_STATHZ 3
|
1994-05-11 11:34:05 +04:00
|
|
|
{ "_stathz" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_NCHSTATS 4
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_nchstats" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_INTRNAMES 5
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_intrnames" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_EINTRNAMES 6
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_eintrnames" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_INTRCNT 7
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_intrcnt" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_EINTRCNT 8
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_eintrcnt" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_KMEMSTAT 9
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_kmemstats" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_KMEMBUCKETS 10
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_bucket" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#define X_ALLEVENTS 11
|
1995-03-14 10:35:49 +03:00
|
|
|
{ "_allevents" },
|
1998-07-27 14:26:11 +04:00
|
|
|
#define X_POOLHEAD 12
|
|
|
|
{ "_pool_head" },
|
1998-02-07 18:42:32 +03:00
|
|
|
#if defined(UVM)
|
1998-07-27 14:26:11 +04:00
|
|
|
#define X_END 13
|
1993-04-09 16:58:42 +04:00
|
|
|
#else
|
1998-07-27 14:26:11 +04:00
|
|
|
#define X_SUM 13
|
1998-02-07 18:42:32 +03:00
|
|
|
{ "_cnt" },
|
1998-07-27 14:26:11 +04:00
|
|
|
#define X_END 14
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif
|
1995-08-27 10:20:27 +04:00
|
|
|
#if defined(pc532)
|
|
|
|
#define X_IVT (X_END)
|
|
|
|
{ "_ivt" },
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif
|
|
|
|
{ "" },
|
|
|
|
};
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
/* Objects defined in dkstats.c */
|
|
|
|
extern struct _disk cur;
|
|
|
|
extern char **dr_name;
|
|
|
|
extern int *dk_select, dk_ndrive;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-02-07 18:42:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
struct uvmexp uvmexp, ouvmexp;
|
|
|
|
#else
|
1994-05-11 11:34:05 +04:00
|
|
|
struct vmmeter sum, osum;
|
1998-02-07 18:42:32 +03:00
|
|
|
#endif
|
1996-05-11 03:16:30 +04:00
|
|
|
int ndrives;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
int winlines = 20;
|
|
|
|
|
1994-05-11 11:34:05 +04:00
|
|
|
kvm_t *kd;
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
#define FORKSTAT 0x01
|
|
|
|
#define INTRSTAT 0x02
|
|
|
|
#define MEMSTAT 0x04
|
|
|
|
#define SUMSTAT 0x08
|
|
|
|
#define VMSTAT 0x20
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
#define HISTLIST 0x40
|
|
|
|
#define HISTDUMP 0x80
|
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
void cpustats __P((void));
|
|
|
|
void dkstats __P((void));
|
|
|
|
void dointr __P((void));
|
|
|
|
void domem __P((void));
|
1998-07-27 14:26:11 +04:00
|
|
|
void dopool __P((void));
|
1996-05-11 03:16:30 +04:00
|
|
|
void dosum __P((void));
|
|
|
|
void dovmstat __P((u_int, int));
|
|
|
|
void kread __P((int, void *, size_t));
|
1997-10-20 07:11:57 +04:00
|
|
|
void needhdr __P((int));
|
|
|
|
long getuptime __P((void));
|
|
|
|
void printhdr __P((void));
|
|
|
|
long pct __P((long, long));
|
1996-05-11 03:16:30 +04:00
|
|
|
void usage __P((void));
|
1998-01-04 06:59:04 +03:00
|
|
|
void doforkst __P((void));
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
void hist_traverse __P((int, const char *));
|
|
|
|
void hist_dodump __P((struct uvm_history *));
|
|
|
|
#endif
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
int main __P((int, char **));
|
1996-05-11 03:16:30 +04:00
|
|
|
char **choosedrives __P((char **));
|
|
|
|
|
1998-07-19 21:47:07 +04:00
|
|
|
extern int dkinit __P((int, gid_t));
|
1997-10-20 07:11:57 +04:00
|
|
|
extern void dkreadstats __P((void));
|
|
|
|
extern void dkswap __P((void));
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
/* Namelist and memory file names. */
|
|
|
|
char *nlistf, *memf;
|
|
|
|
|
1998-07-05 12:02:34 +04:00
|
|
|
/* allow old usage [vmstat 1] */
|
|
|
|
#define BACKWARD_COMPATIBILITY
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
int
|
1993-04-09 16:58:42 +04:00
|
|
|
main(argc, argv)
|
1997-10-20 07:11:57 +04:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
1997-10-20 07:11:57 +04:00
|
|
|
int c, todo;
|
1993-04-09 16:58:42 +04:00
|
|
|
u_int interval;
|
|
|
|
int reps;
|
1994-05-11 11:34:05 +04:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
1998-07-06 11:50:18 +04:00
|
|
|
gid_t egid = getegid();
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
const char *histname = NULL;
|
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-07-06 11:50:18 +04:00
|
|
|
(void)setegid(getgid());
|
1994-05-11 11:34:05 +04:00
|
|
|
memf = nlistf = NULL;
|
1993-04-09 16:58:42 +04:00
|
|
|
interval = reps = todo = 0;
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
1999-01-12 02:03:06 +03:00
|
|
|
while ((c = getopt(argc, argv, "c:fh:HilM:mN:sw:")) != -1) {
|
1998-02-13 08:10:32 +03:00
|
|
|
#else
|
1999-01-12 02:03:06 +03:00
|
|
|
while ((c = getopt(argc, argv, "c:fiM:mN:sw:")) != -1) {
|
1998-02-13 08:10:32 +03:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
reps = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
todo |= FORKSTAT;
|
|
|
|
break;
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
case 'h':
|
|
|
|
histname = optarg;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'H':
|
|
|
|
todo |= HISTDUMP;
|
|
|
|
break;
|
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
case 'i':
|
|
|
|
todo |= INTRSTAT;
|
|
|
|
break;
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
case 'l':
|
|
|
|
todo |= HISTLIST;
|
|
|
|
break;
|
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
case 'M':
|
1994-05-11 11:34:05 +04:00
|
|
|
memf = optarg;
|
1993-04-09 16:58:42 +04:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
todo |= MEMSTAT;
|
|
|
|
break;
|
|
|
|
case 'N':
|
1994-05-11 11:34:05 +04:00
|
|
|
nlistf = optarg;
|
1993-04-09 16:58:42 +04:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
todo |= SUMSTAT;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
interval = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (todo == 0)
|
|
|
|
todo = VMSTAT;
|
|
|
|
|
1994-05-11 11:34:05 +04:00
|
|
|
/*
|
1998-07-06 11:50:18 +04:00
|
|
|
* Discard setgid privileges. If not the running kernel, we toss
|
|
|
|
* them away totally so that bad guys can't print interesting stuff
|
|
|
|
* from kernel memory, otherwise switch back to kmem for the
|
|
|
|
* duration of the kvm_openfiles() call.
|
1994-05-11 11:34:05 +04:00
|
|
|
*/
|
|
|
|
if (nlistf != NULL || memf != NULL)
|
1998-07-06 11:50:18 +04:00
|
|
|
(void)setgid(getgid());
|
|
|
|
else
|
|
|
|
(void)setegid(egid);
|
1994-05-11 11:34:05 +04:00
|
|
|
|
|
|
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
1998-07-06 11:50:18 +04:00
|
|
|
if (kd == 0)
|
|
|
|
errx(1, "kvm_openfiles: %s\n", errbuf);
|
|
|
|
|
|
|
|
if (nlistf == NULL && memf == NULL) {
|
|
|
|
if (todo & VMSTAT)
|
|
|
|
(void)setegid(getgid()); /* XXX: dkinit */
|
|
|
|
else
|
|
|
|
(void)setgid(getgid());
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1994-05-11 11:34:05 +04:00
|
|
|
if ((c = kvm_nlist(kd, namelist)) != 0) {
|
1993-04-09 16:58:42 +04:00
|
|
|
if (c > 0) {
|
|
|
|
(void)fprintf(stderr,
|
1994-05-11 11:34:05 +04:00
|
|
|
"vmstat: undefined symbols:");
|
|
|
|
for (c = 0;
|
|
|
|
c < sizeof(namelist)/sizeof(namelist[0]); c++)
|
|
|
|
if (namelist[c].n_type == 0)
|
|
|
|
fprintf(stderr, " %s",
|
|
|
|
namelist[c].n_name);
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)fputc('\n', stderr);
|
|
|
|
} else
|
|
|
|
(void)fprintf(stderr, "vmstat: kvm_nlist: %s\n",
|
1994-05-11 11:34:05 +04:00
|
|
|
kvm_geterr(kd));
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todo & VMSTAT) {
|
|
|
|
struct winsize winsize;
|
|
|
|
|
1998-07-19 21:47:07 +04:00
|
|
|
dkinit(0, egid); /* Initialize disk stats, no disks selected. */
|
|
|
|
|
|
|
|
(void)setgid(getgid()); /* don't need privs anymore */
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
argv = choosedrives(argv); /* Select disks. */
|
1993-04-09 16:58:42 +04:00
|
|
|
winsize.ws_row = 0;
|
1998-07-05 12:02:34 +04:00
|
|
|
(void)ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize);
|
1993-04-09 16:58:42 +04:00
|
|
|
if (winsize.ws_row > 0)
|
|
|
|
winlines = winsize.ws_row;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
if (todo & (HISTLIST|HISTDUMP)) {
|
|
|
|
if ((todo & (HISTLIST|HISTDUMP)) == (HISTLIST|HISTDUMP))
|
|
|
|
errx(1, "you may list or dump, but not both!");
|
|
|
|
hist_traverse(todo, histname);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
if (todo & FORKSTAT)
|
|
|
|
doforkst();
|
1998-07-27 14:26:11 +04:00
|
|
|
if (todo & MEMSTAT) {
|
1993-04-09 16:58:42 +04:00
|
|
|
domem();
|
1998-07-27 14:26:11 +04:00
|
|
|
dopool();
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
if (todo & SUMSTAT)
|
1994-05-11 11:34:05 +04:00
|
|
|
dosum();
|
1993-04-09 16:58:42 +04:00
|
|
|
if (todo & INTRSTAT)
|
|
|
|
dointr();
|
|
|
|
if (todo & VMSTAT)
|
|
|
|
dovmstat(interval, reps);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
1996-05-11 03:16:30 +04:00
|
|
|
choosedrives(argv)
|
1993-04-09 16:58:42 +04:00
|
|
|
char **argv;
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
int i;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose drives to be displayed. Priority goes to (in order) drives
|
|
|
|
* supplied as arguments, default drives. If everything isn't filled
|
|
|
|
* in and there are drives not taken care of, display the first few
|
|
|
|
* that fit.
|
|
|
|
*/
|
|
|
|
#define BACKWARD_COMPATIBILITY
|
|
|
|
for (ndrives = 0; *argv; ++argv) {
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
|
|
|
if (isdigit(**argv))
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
for (i = 0; i < dk_ndrive; i++) {
|
|
|
|
if (strcmp(dr_name[i], *argv))
|
|
|
|
continue;
|
1996-05-11 03:16:30 +04:00
|
|
|
dk_select[i] = 1;
|
1993-04-09 16:58:42 +04:00
|
|
|
++ndrives;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
|
1996-05-11 03:16:30 +04:00
|
|
|
if (dk_select[i])
|
1993-04-09 16:58:42 +04:00
|
|
|
continue;
|
1996-05-11 03:16:30 +04:00
|
|
|
dk_select[i] = 1;
|
1993-04-09 16:58:42 +04:00
|
|
|
++ndrives;
|
|
|
|
}
|
|
|
|
return(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
getuptime()
|
|
|
|
{
|
1996-06-05 04:18:58 +04:00
|
|
|
static time_t now;
|
|
|
|
static struct timeval boottime;
|
1993-04-09 16:58:42 +04:00
|
|
|
time_t uptime;
|
|
|
|
|
1996-06-05 04:18:58 +04:00
|
|
|
if (boottime.tv_sec == 0)
|
1993-04-09 16:58:42 +04:00
|
|
|
kread(X_BOOTTIME, &boottime, sizeof(boottime));
|
|
|
|
(void)time(&now);
|
1996-06-05 04:18:58 +04:00
|
|
|
uptime = now - boottime.tv_sec;
|
1993-04-09 16:58:42 +04:00
|
|
|
if (uptime <= 0 || uptime > 60*60*24*365*10) {
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"vmstat: time makes no sense; namelist must be wrong.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return(uptime);
|
|
|
|
}
|
|
|
|
|
|
|
|
int hz, hdrcnt;
|
|
|
|
|
|
|
|
void
|
|
|
|
dovmstat(interval, reps)
|
|
|
|
u_int interval;
|
|
|
|
int reps;
|
|
|
|
{
|
|
|
|
struct vmtotal total;
|
|
|
|
time_t uptime, halfuptime;
|
1994-12-24 20:02:20 +03:00
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
1998-02-07 18:42:32 +03:00
|
|
|
int pagesize = getpagesize();
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
uptime = getuptime();
|
|
|
|
halfuptime = uptime / 2;
|
|
|
|
(void)signal(SIGCONT, needhdr);
|
|
|
|
|
1994-05-11 11:34:05 +04:00
|
|
|
if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0)
|
|
|
|
kread(X_STATHZ, &hz, sizeof(hz));
|
1993-04-09 16:58:42 +04:00
|
|
|
if (!hz)
|
|
|
|
kread(X_HZ, &hz, sizeof(hz));
|
|
|
|
|
|
|
|
for (hdrcnt = 1;;) {
|
|
|
|
if (!--hdrcnt)
|
|
|
|
printhdr();
|
1996-05-11 03:16:30 +04:00
|
|
|
/* Read new disk statistics */
|
|
|
|
dkreadstats();
|
1998-02-07 18:42:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
size = sizeof(uvmexp);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_UVMEXP;
|
|
|
|
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
|
|
|
printf("can't get uvmexp: %s\n", strerror(errno));
|
1998-08-10 06:57:23 +04:00
|
|
|
memset(&uvmexp, 0, sizeof(uvmexp));
|
1998-02-07 18:42:32 +03:00
|
|
|
}
|
|
|
|
#else
|
1994-05-11 11:34:05 +04:00
|
|
|
kread(X_SUM, &sum, sizeof(sum));
|
1998-02-07 18:42:32 +03:00
|
|
|
#endif
|
1994-05-11 11:34:05 +04:00
|
|
|
size = sizeof(total);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_METER;
|
|
|
|
if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
|
|
|
|
printf("Can't get kerninfo: %s\n", strerror(errno));
|
1998-08-10 06:57:23 +04:00
|
|
|
memset(&total, 0, sizeof(total));
|
1994-05-11 11:34:05 +04:00
|
|
|
}
|
|
|
|
(void)printf("%2d%2d%2d",
|
|
|
|
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
|
1998-02-07 18:42:32 +03:00
|
|
|
#define pgtok(a) (long)((a) * (pagesize >> 10))
|
1997-10-20 07:11:57 +04:00
|
|
|
#define rate(x) (u_long)(((x) + halfuptime) / uptime) /* round */
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)printf("%6ld%6ld ",
|
1993-04-09 16:58:42 +04:00
|
|
|
pgtok(total.t_avm), pgtok(total.t_free));
|
1998-02-07 18:42:32 +03:00
|
|
|
#if defined(UVM)
|
1998-02-07 19:18:14 +03:00
|
|
|
(void)printf("%4lu ", rate(uvmexp.faults - ouvmexp.faults));
|
|
|
|
(void)printf("%3lu ", rate(uvmexp.pdreact - ouvmexp.pdreact));
|
1998-03-05 05:47:05 +03:00
|
|
|
(void)printf("%3lu ", rate(uvmexp.pageins - ouvmexp.pageins));
|
1998-02-09 16:11:26 +03:00
|
|
|
(void)printf("%4lu ",
|
|
|
|
rate(uvmexp.pgswapout - ouvmexp.pgswapout));
|
|
|
|
(void)printf("%4lu ", rate(uvmexp.pdfreed - ouvmexp.pdfreed));
|
|
|
|
(void)printf("%4lu ", rate(uvmexp.pdscans - ouvmexp.pdscans));
|
1998-02-07 19:18:14 +03:00
|
|
|
dkstats();
|
|
|
|
(void)printf("%4lu %4lu %3lu ",
|
|
|
|
rate(uvmexp.intrs - ouvmexp.intrs),
|
|
|
|
rate(uvmexp.syscalls - ouvmexp.syscalls),
|
|
|
|
rate(uvmexp.swtch - ouvmexp.swtch));
|
|
|
|
cpustats();
|
|
|
|
(void)printf("\n");
|
|
|
|
(void)fflush(stdout);
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
|
|
|
ouvmexp = uvmexp;
|
1998-02-07 18:42:32 +03:00
|
|
|
#else
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)printf("%4lu ", rate(sum.v_faults - osum.v_faults));
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf("%3lu ",
|
1994-05-11 11:34:05 +04:00
|
|
|
rate(sum.v_reactivated - osum.v_reactivated));
|
|
|
|
(void)printf("%3lu ", rate(sum.v_pageins - osum.v_pageins));
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf("%3lu %3lu ",
|
1997-10-20 07:11:57 +04:00
|
|
|
rate(sum.v_pageouts - osum.v_pageouts), (u_long)0);
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)printf("%3lu ", rate(sum.v_scan - osum.v_scan));
|
1993-04-09 16:58:42 +04:00
|
|
|
dkstats();
|
|
|
|
(void)printf("%4lu %4lu %3lu ",
|
1994-05-11 11:34:05 +04:00
|
|
|
rate(sum.v_intr - osum.v_intr),
|
|
|
|
rate(sum.v_syscall - osum.v_syscall),
|
|
|
|
rate(sum.v_swtch - osum.v_swtch));
|
1993-04-09 16:58:42 +04:00
|
|
|
cpustats();
|
|
|
|
(void)printf("\n");
|
|
|
|
(void)fflush(stdout);
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
1994-05-11 11:34:05 +04:00
|
|
|
osum = sum;
|
1998-02-07 18:42:32 +03:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
uptime = interval;
|
|
|
|
/*
|
|
|
|
* We round upward to avoid losing low-frequency events
|
|
|
|
* (i.e., >= 1 per interval but < 1 per second).
|
|
|
|
*/
|
1996-11-29 22:40:56 +03:00
|
|
|
halfuptime = uptime == 1 ? 0 : (uptime + 1) / 2;
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)sleep(interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
printhdr()
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
int i;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-02-09 16:11:26 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
(void)printf(" procs memory page%*s", 23, "");
|
|
|
|
#else
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf(" procs memory page%*s", 20, "");
|
1998-02-09 16:11:26 +03:00
|
|
|
#endif
|
1996-05-11 03:16:30 +04:00
|
|
|
if (ndrives > 0)
|
|
|
|
(void)printf("%s %*sfaults cpu\n",
|
|
|
|
((ndrives > 1) ? "disks" : "disk"),
|
|
|
|
((ndrives > 1) ? ndrives * 3 - 4 : 0), "");
|
1993-04-09 16:58:42 +04:00
|
|
|
else
|
1996-05-11 03:16:30 +04:00
|
|
|
(void)printf("%*s faults cpu\n",
|
|
|
|
ndrives * 3, "");
|
|
|
|
|
1998-02-09 16:11:26 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
(void)printf(" r b w avm fre flt re pi po fr sr ");
|
|
|
|
#else
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf(" r b w avm fre flt re pi po fr sr ");
|
1998-02-09 16:11:26 +03:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
if (dk_select[i])
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf("%c%c ", dr_name[i][0],
|
|
|
|
dr_name[i][strlen(dr_name[i]) - 1]);
|
|
|
|
(void)printf(" in sy cs us sy id\n");
|
|
|
|
hdrcnt = winlines - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force a header to be prepended to the next output.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-20 07:11:57 +04:00
|
|
|
needhdr(dummy)
|
|
|
|
int dummy;
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
hdrcnt = 1;
|
|
|
|
}
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
long
|
1993-04-09 16:58:42 +04:00
|
|
|
pct(top, bot)
|
|
|
|
long top, bot;
|
|
|
|
{
|
1994-05-11 11:34:05 +04:00
|
|
|
long ans;
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
if (bot == 0)
|
|
|
|
return(0);
|
1994-05-11 11:34:05 +04:00
|
|
|
ans = (quad_t)top * 100 / bot;
|
|
|
|
return (ans);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
#define PCT(top, bot) (int)pct((long)(top), (long)(bot))
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
void
|
1994-05-11 11:34:05 +04:00
|
|
|
dosum()
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
struct nchstats nchstats;
|
|
|
|
long nchtotal;
|
|
|
|
|
1998-02-07 18:42:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = sizeof(uvmexp);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_UVMEXP;
|
|
|
|
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
|
|
|
printf("can't get uvmexp: %s\n", strerror(errno));
|
1998-08-10 06:57:23 +04:00
|
|
|
memset(&uvmexp, 0, sizeof(uvmexp));
|
1998-02-07 18:42:32 +03:00
|
|
|
}
|
|
|
|
|
1998-02-09 16:11:26 +03:00
|
|
|
(void)printf("%9u bytes per page\n", uvmexp.pagesize);
|
|
|
|
|
|
|
|
(void)printf("%9u pages managed\n", uvmexp.npages);
|
|
|
|
(void)printf("%9u pages free\n", uvmexp.free);
|
|
|
|
(void)printf("%9u pages active\n", uvmexp.active);
|
|
|
|
(void)printf("%9u pages inactive\n", uvmexp.inactive);
|
|
|
|
(void)printf("%9u pages paging\n", uvmexp.paging);
|
|
|
|
(void)printf("%9u pages wired\n", uvmexp.wired);
|
|
|
|
(void)printf("%9u reserve pagedaemon pages\n",
|
|
|
|
uvmexp.reserve_pagedaemon);
|
|
|
|
(void)printf("%9u reserve kernel pages\n", uvmexp.reserve_kernel);
|
|
|
|
|
|
|
|
(void)printf("%9u minimum free pages\n", uvmexp.freemin);
|
|
|
|
(void)printf("%9u target free pages\n", uvmexp.freetarg);
|
|
|
|
(void)printf("%9u target inactive pages\n", uvmexp.inactarg);
|
|
|
|
(void)printf("%9u maximum wired pages\n", uvmexp.wiredmax);
|
|
|
|
|
|
|
|
(void)printf("%9u swap devices\n", uvmexp.nswapdev);
|
|
|
|
(void)printf("%9u swap pages\n", uvmexp.swpages);
|
|
|
|
(void)printf("%9u swap pages in use\n", uvmexp.swpginuse);
|
|
|
|
(void)printf("%9u swap allocations\n", uvmexp.nswget);
|
|
|
|
(void)printf("%9u anons\n", uvmexp.nanon);
|
|
|
|
(void)printf("%9u free anons\n", uvmexp.nfreeanon);
|
|
|
|
|
1998-02-07 19:50:59 +03:00
|
|
|
(void)printf("%9u total faults taken\n", uvmexp.faults);
|
|
|
|
(void)printf("%9u traps\n", uvmexp.traps);
|
|
|
|
(void)printf("%9u device interrupts\n", uvmexp.intrs);
|
|
|
|
(void)printf("%9u cpu context switches\n", uvmexp.swtch);
|
|
|
|
(void)printf("%9u software interrupts\n", uvmexp.softs);
|
|
|
|
(void)printf("%9u system calls\n", uvmexp.syscalls);
|
1998-02-09 16:11:26 +03:00
|
|
|
(void)printf("%9u pagein requests\n", uvmexp.pageins / CLSIZE);
|
|
|
|
(void)printf("%9u pageout requests\n", uvmexp.pdpageouts / CLSIZE);
|
1998-02-07 19:50:59 +03:00
|
|
|
(void)printf("%9u swap ins\n", uvmexp.swapins);
|
|
|
|
(void)printf("%9u swap outs\n", uvmexp.swapouts);
|
1998-02-09 16:11:26 +03:00
|
|
|
(void)printf("%9u pages swapped in\n", uvmexp.pgswapin / CLSIZE);
|
|
|
|
(void)printf("%9u pages swapped out\n", uvmexp.pgswapout / CLSIZE);
|
1998-02-07 19:50:59 +03:00
|
|
|
(void)printf("%9u forks total\n", uvmexp.forks);
|
|
|
|
(void)printf("%9u forks blocked parent\n", uvmexp.forks_ppwait);
|
|
|
|
(void)printf("%9u forks shared address space with parent\n",
|
|
|
|
uvmexp.forks_sharevm);
|
1998-02-09 16:11:26 +03:00
|
|
|
|
|
|
|
(void)printf("%9u faults with no memory\n", uvmexp.fltnoram);
|
|
|
|
(void)printf("%9u faults with no anons\n", uvmexp.fltnoanon);
|
1998-02-07 19:50:59 +03:00
|
|
|
(void)printf("%9u faults had to wait on pages\n", uvmexp.fltpgwait);
|
|
|
|
(void)printf("%9u faults found released page\n", uvmexp.fltpgrele);
|
|
|
|
(void)printf("%9u faults relock (%u ok)\n", uvmexp.fltrelck,
|
|
|
|
uvmexp.fltrelckok);
|
|
|
|
(void)printf("%9u anon page faults\n", uvmexp.fltanget);
|
|
|
|
(void)printf("%9u anon retry faults\n", uvmexp.fltanretry);
|
|
|
|
(void)printf("%9u amap copy faults\n", uvmexp.fltamcopy);
|
|
|
|
(void)printf("%9u neighbour anon page faults\n", uvmexp.fltnamap);
|
|
|
|
(void)printf("%9u neighbour object page faults\n", uvmexp.fltnomap);
|
|
|
|
(void)printf("%9u locked pager get faults\n", uvmexp.fltlget);
|
|
|
|
(void)printf("%9u unlocked pager get faults\n", uvmexp.fltget);
|
|
|
|
(void)printf("%9u anon faults\n", uvmexp.flt_anon);
|
|
|
|
(void)printf("%9u anon copy on write faults\n", uvmexp.flt_acow);
|
|
|
|
(void)printf("%9u object faults\n", uvmexp.flt_obj);
|
|
|
|
(void)printf("%9u promote copy faults\n", uvmexp.flt_prcopy);
|
|
|
|
(void)printf("%9u promote zero fill faults\n", uvmexp.flt_przero);
|
1998-02-09 16:11:26 +03:00
|
|
|
|
|
|
|
(void)printf("%9u times daemon wokeup\n",uvmexp.pdwoke);
|
|
|
|
(void)printf("%9u revolutions of the clock hand\n", uvmexp.pdrevs);
|
|
|
|
(void)printf("%9u times daemon attempted swapout\n", uvmexp.pdswout);
|
|
|
|
(void)printf("%9u pages freed by daemon\n", uvmexp.pdfreed);
|
|
|
|
(void)printf("%9u pages scanned by daemon\n", uvmexp.pdscans);
|
|
|
|
(void)printf("%9u anonymous pages scanned by daemon\n", uvmexp.pdanscan);
|
|
|
|
(void)printf("%9u object pages scanned by daemon\n", uvmexp.pdobscan);
|
|
|
|
(void)printf("%9u pages reactivated\n", uvmexp.pdreact);
|
|
|
|
(void)printf("%9u pages found busy by daemon\n", uvmexp.pdbusy);
|
|
|
|
(void)printf("%9u total pending pageouts\n", uvmexp.pdpending);
|
|
|
|
(void)printf("%9u pages deactivated\n", uvmexp.pddeact);
|
1998-02-07 18:42:32 +03:00
|
|
|
#else
|
1994-05-11 11:34:05 +04:00
|
|
|
kread(X_SUM, &sum, sizeof(sum));
|
|
|
|
(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);
|
|
|
|
(void)printf("%9u total faults taken\n", sum.v_faults);
|
|
|
|
(void)printf("%9u swap ins\n", sum.v_swpin);
|
|
|
|
(void)printf("%9u swap outs\n", sum.v_swpout);
|
|
|
|
(void)printf("%9u pages swapped in\n", sum.v_pswpin / CLSIZE);
|
|
|
|
(void)printf("%9u pages swapped out\n", sum.v_pswpout / CLSIZE);
|
|
|
|
(void)printf("%9u page ins\n", sum.v_pageins);
|
|
|
|
(void)printf("%9u page outs\n", sum.v_pageouts);
|
|
|
|
(void)printf("%9u pages paged in\n", sum.v_pgpgin);
|
|
|
|
(void)printf("%9u pages paged out\n", sum.v_pgpgout);
|
|
|
|
(void)printf("%9u pages reactivated\n", sum.v_reactivated);
|
|
|
|
(void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
|
|
|
|
(void)printf("%9u zero fill pages created\n", sum.v_nzfod / CLSIZE);
|
|
|
|
(void)printf("%9u zero fill page faults\n", sum.v_zfod / CLSIZE);
|
|
|
|
(void)printf("%9u pages examined by the clock daemon\n", sum.v_scan);
|
|
|
|
(void)printf("%9u revolutions of the clock hand\n", sum.v_rev);
|
|
|
|
(void)printf("%9u VM object cache lookups\n", sum.v_lookups);
|
|
|
|
(void)printf("%9u VM object hits\n", sum.v_hits);
|
|
|
|
(void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
|
|
|
|
(void)printf("%9u copy-on-write faults\n", sum.v_cow_faults);
|
|
|
|
(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 free\n", sum.v_free_count);
|
|
|
|
(void)printf("%9u pages wired down\n", sum.v_wire_count);
|
|
|
|
(void)printf("%9u pages active\n", sum.v_active_count);
|
|
|
|
(void)printf("%9u pages inactive\n", sum.v_inactive_count);
|
|
|
|
(void)printf("%9u bytes per page\n", sum.v_page_size);
|
1997-10-18 18:34:39 +04:00
|
|
|
(void)printf("%9u target inactive pages\n", sum.v_inactive_target);
|
|
|
|
(void)printf("%9u target free pages\n", sum.v_free_target);
|
|
|
|
(void)printf("%9u minimum free pages\n", sum.v_free_min);
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif
|
|
|
|
kread(X_NCHSTATS, &nchstats, sizeof(nchstats));
|
|
|
|
nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits +
|
|
|
|
nchstats.ncs_badhits + nchstats.ncs_falsehits +
|
|
|
|
nchstats.ncs_miss + nchstats.ncs_long;
|
|
|
|
(void)printf("%9ld total name lookups\n", nchtotal);
|
|
|
|
(void)printf(
|
|
|
|
"%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
|
|
|
|
"", PCT(nchstats.ncs_goodhits, nchtotal),
|
|
|
|
PCT(nchstats.ncs_neghits, nchtotal),
|
|
|
|
PCT(nchstats.ncs_pass2, nchtotal));
|
|
|
|
(void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "",
|
|
|
|
PCT(nchstats.ncs_badhits, nchtotal),
|
|
|
|
PCT(nchstats.ncs_falsehits, nchtotal),
|
|
|
|
PCT(nchstats.ncs_long, nchtotal));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
doforkst()
|
|
|
|
{
|
1998-02-07 18:42:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = sizeof(uvmexp);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_UVMEXP;
|
|
|
|
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
|
|
|
printf("can't get uvmexp: %s\n", strerror(errno));
|
1998-08-10 06:57:23 +04:00
|
|
|
memset(&uvmexp, 0, sizeof(uvmexp));
|
1998-02-07 18:42:32 +03:00
|
|
|
}
|
|
|
|
(void)printf("%u forks total\n", uvmexp.forks);
|
|
|
|
(void)printf("%u forks blocked parent\n", uvmexp.forks_ppwait);
|
|
|
|
(void)printf("%u forks shared address space with parent\n",
|
|
|
|
uvmexp.forks_sharevm);
|
|
|
|
#else
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-01-04 06:59:04 +03:00
|
|
|
kread(X_SUM, &sum, sizeof(sum));
|
|
|
|
(void)printf("%u forks total\n", sum.v_forks);
|
|
|
|
(void)printf("%u forks blocked parent\n", sum.v_forks_ppwait);
|
|
|
|
(void)printf("%u forks shared address space with parent\n",
|
|
|
|
sum.v_forks_sharevm);
|
1998-02-07 18:42:32 +03:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dkstats()
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
int dn, state;
|
1993-04-09 16:58:42 +04:00
|
|
|
double etime;
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
/* Calculate disk stat deltas. */
|
|
|
|
dkswap();
|
1993-04-09 16:58:42 +04:00
|
|
|
etime = 0;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state) {
|
1996-05-11 03:16:30 +04:00
|
|
|
etime += cur.cp_time[state];
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
if (etime == 0)
|
|
|
|
etime = 1;
|
|
|
|
etime /= hz;
|
|
|
|
for (dn = 0; dn < dk_ndrive; ++dn) {
|
1996-05-11 03:16:30 +04:00
|
|
|
if (!dk_select[dn])
|
1993-04-09 16:58:42 +04:00
|
|
|
continue;
|
1996-05-11 03:16:30 +04:00
|
|
|
(void)printf("%2.0f ", cur.dk_xfer[dn] / etime);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cpustats()
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
int state;
|
1993-04-09 16:58:42 +04:00
|
|
|
double pct, total;
|
|
|
|
|
|
|
|
total = 0;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
1996-05-11 03:16:30 +04:00
|
|
|
total += cur.cp_time[state];
|
1993-04-09 16:58:42 +04:00
|
|
|
if (total)
|
|
|
|
pct = 100 / total;
|
|
|
|
else
|
|
|
|
pct = 0;
|
1996-05-11 03:16:30 +04:00
|
|
|
(void)printf("%2.0f ", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * pct);
|
|
|
|
(void)printf("%2.0f ", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * pct);
|
|
|
|
(void)printf("%2.0f", cur.cp_time[CP_IDLE] * pct);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1995-08-27 10:20:27 +04:00
|
|
|
#if defined(pc532)
|
1995-09-24 09:34:47 +03:00
|
|
|
/* To get struct iv ...*/
|
|
|
|
#define _KERNEL
|
1995-08-27 10:20:27 +04:00
|
|
|
#include <machine/psl.h>
|
1995-09-24 09:34:47 +03:00
|
|
|
#undef _KERNEL
|
1995-08-27 10:20:27 +04:00
|
|
|
void
|
|
|
|
dointr()
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
long i, j, inttotal, uptime;
|
1995-08-27 10:20:27 +04:00
|
|
|
static char iname[64];
|
|
|
|
struct iv ivt[32], *ivp = ivt;
|
|
|
|
|
|
|
|
iname[63] = '\0';
|
|
|
|
uptime = getuptime();
|
|
|
|
kread(X_IVT, ivp, sizeof(ivt));
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
(void)printf("%sware interrupts:\n", i ? "\nsoft" : "hard");
|
|
|
|
(void)printf("interrupt total rate\n");
|
|
|
|
inttotal = 0;
|
|
|
|
for (j = 0; j < 16; j++, ivp++) {
|
|
|
|
if (ivp->iv_vec && ivp->iv_use && ivp->iv_cnt) {
|
|
|
|
if (kvm_read(kd, (u_long)ivp->iv_use, iname, 63) != 63) {
|
|
|
|
(void)fprintf(stderr, "vmstat: iv_use: %s\n",
|
|
|
|
kvm_geterr(kd));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
(void)printf("%-12s %8ld %8ld\n", iname,
|
|
|
|
ivp->iv_cnt, ivp->iv_cnt / uptime);
|
|
|
|
inttotal += ivp->iv_cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(void)printf("Total %8ld %8ld\n",
|
|
|
|
inttotal, inttotal / uptime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
1993-04-09 16:58:42 +04:00
|
|
|
void
|
|
|
|
dointr()
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
long *intrcnt, inttotal, uptime;
|
|
|
|
int nintr, inamlen;
|
|
|
|
char *intrname;
|
1996-04-04 04:27:50 +04:00
|
|
|
struct evcntlist allevents;
|
|
|
|
struct evcnt evcnt, *evptr;
|
1995-03-14 10:35:49 +03:00
|
|
|
struct device dev;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
uptime = getuptime();
|
1994-05-11 11:34:05 +04:00
|
|
|
nintr = namelist[X_EINTRCNT].n_value - namelist[X_INTRCNT].n_value;
|
|
|
|
inamlen =
|
|
|
|
namelist[X_EINTRNAMES].n_value - namelist[X_INTRNAMES].n_value;
|
1993-04-09 16:58:42 +04:00
|
|
|
intrcnt = malloc((size_t)nintr);
|
|
|
|
intrname = malloc((size_t)inamlen);
|
|
|
|
if (intrcnt == NULL || intrname == NULL) {
|
|
|
|
(void)fprintf(stderr, "vmstat: %s.\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
kread(X_INTRCNT, intrcnt, (size_t)nintr);
|
|
|
|
kread(X_INTRNAMES, intrname, (size_t)inamlen);
|
1995-10-10 04:17:35 +03:00
|
|
|
(void)printf("interrupt total rate\n");
|
1993-04-09 16:58:42 +04:00
|
|
|
inttotal = 0;
|
|
|
|
nintr /= sizeof(long);
|
|
|
|
while (--nintr >= 0) {
|
|
|
|
if (*intrcnt)
|
1995-10-10 04:17:35 +03:00
|
|
|
(void)printf("%-14s %8ld %8ld\n", intrname,
|
1993-04-09 16:58:42 +04:00
|
|
|
*intrcnt, *intrcnt / uptime);
|
|
|
|
intrname += strlen(intrname) + 1;
|
|
|
|
inttotal += *intrcnt++;
|
|
|
|
}
|
1995-03-14 10:35:49 +03:00
|
|
|
kread(X_ALLEVENTS, &allevents, sizeof allevents);
|
1996-04-04 04:27:50 +04:00
|
|
|
evptr = allevents.tqh_first;
|
|
|
|
while (evptr) {
|
|
|
|
if (kvm_read(kd, (long)evptr, (void *)&evcnt,
|
1995-03-14 10:35:49 +03:00
|
|
|
sizeof evcnt) != sizeof evcnt) {
|
1997-10-20 07:11:57 +04:00
|
|
|
(void)fprintf(stderr, "vmstat: event chain trashed: %s\n",
|
1995-03-14 10:35:49 +03:00
|
|
|
kvm_geterr(kd));
|
|
|
|
exit(1);
|
|
|
|
}
|
1996-11-26 01:55:59 +03:00
|
|
|
if (kvm_read(kd, (long)evcnt.ev_dev, (void *)&dev,
|
|
|
|
sizeof dev) != sizeof dev) {
|
1997-10-20 07:11:57 +04:00
|
|
|
(void)fprintf(stderr, "vmstat: event chain trashed: %s\n",
|
1996-11-26 01:55:59 +03:00
|
|
|
kvm_geterr(kd));
|
|
|
|
exit(1);
|
1995-03-14 10:35:49 +03:00
|
|
|
}
|
1996-11-26 01:55:59 +03:00
|
|
|
if (evcnt.ev_count)
|
|
|
|
(void)printf("%-14s %8ld %8ld\n", dev.dv_xname,
|
1997-10-20 07:11:57 +04:00
|
|
|
(long)evcnt.ev_count, evcnt.ev_count / uptime);
|
1996-11-26 01:55:59 +03:00
|
|
|
inttotal += evcnt.ev_count++;
|
|
|
|
|
1996-04-04 04:27:50 +04:00
|
|
|
evptr = evcnt.ev_list.tqe_next;
|
1995-03-14 10:35:49 +03:00
|
|
|
}
|
1995-10-10 04:17:35 +03:00
|
|
|
(void)printf("Total %8ld %8ld\n", inttotal, inttotal / uptime);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
1995-08-27 10:20:27 +04:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These names are defined in <sys/malloc.h>.
|
|
|
|
*/
|
|
|
|
char *kmemnames[] = INITKMEMNAMES;
|
|
|
|
|
|
|
|
void
|
|
|
|
domem()
|
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
struct kmembuckets *kp;
|
|
|
|
struct kmemstats *ks;
|
|
|
|
int i, j;
|
1994-05-11 11:34:05 +04:00
|
|
|
int len, size, first;
|
|
|
|
long totuse = 0, totfree = 0, totreq = 0;
|
|
|
|
char *name;
|
|
|
|
struct kmemstats kmemstats[M_LAST];
|
1993-04-09 16:58:42 +04:00
|
|
|
struct kmembuckets buckets[MINBUCKET + 16];
|
|
|
|
|
|
|
|
kread(X_KMEMBUCKETS, buckets, sizeof(buckets));
|
1997-02-22 05:04:42 +03:00
|
|
|
for (first = 1, i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16;
|
|
|
|
i++, kp++) {
|
1993-04-09 16:58:42 +04:00
|
|
|
if (kp->kb_calls == 0)
|
|
|
|
continue;
|
1997-02-22 05:04:42 +03:00
|
|
|
if (first) {
|
|
|
|
(void)printf("Memory statistics by bucket size\n");
|
|
|
|
(void)printf(
|
|
|
|
" Size In Use Free Requests HighWater Couldfree\n");
|
|
|
|
first = 0;
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
size = 1 << i;
|
|
|
|
(void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size,
|
|
|
|
kp->kb_total - kp->kb_totalfree,
|
|
|
|
kp->kb_totalfree, kp->kb_calls,
|
|
|
|
kp->kb_highwat, kp->kb_couldfree);
|
|
|
|
totfree += size * kp->kb_totalfree;
|
|
|
|
}
|
|
|
|
|
1997-02-22 05:04:42 +03:00
|
|
|
/*
|
|
|
|
* If kmem statistics are not being gathered by the kernel,
|
|
|
|
* first will still be 1.
|
|
|
|
*/
|
|
|
|
if (first) {
|
|
|
|
printf(
|
|
|
|
"Kmem statistics are not being gathered by the kernel.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
kread(X_KMEMSTAT, kmemstats, sizeof(kmemstats));
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)printf("\nMemory usage type by bucket size\n");
|
|
|
|
(void)printf(" Size Type(s)\n");
|
|
|
|
kp = &buckets[MINBUCKET];
|
|
|
|
for (j = 1 << MINBUCKET; j < 1 << (MINBUCKET + 16); j <<= 1, kp++) {
|
|
|
|
if (kp->kb_calls == 0)
|
|
|
|
continue;
|
|
|
|
first = 1;
|
|
|
|
len = 8;
|
|
|
|
for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) {
|
|
|
|
if (ks->ks_calls == 0)
|
|
|
|
continue;
|
|
|
|
if ((ks->ks_size & j) == 0)
|
|
|
|
continue;
|
1997-04-10 19:23:50 +04:00
|
|
|
if (kmemnames[i] == 0) {
|
|
|
|
kmemnames[i] = malloc(10);
|
|
|
|
/* strlen("undef/")+3+1);*/
|
|
|
|
snprintf(kmemnames[i], 10, "undef/%d", i);
|
|
|
|
/* same 10 as above!!! */
|
|
|
|
}
|
|
|
|
name = kmemnames[i];
|
1994-05-11 11:34:05 +04:00
|
|
|
len += 2 + strlen(name);
|
|
|
|
if (first)
|
|
|
|
printf("%8d %s", j, name);
|
|
|
|
else
|
|
|
|
printf(",");
|
|
|
|
if (len >= 80) {
|
|
|
|
printf("\n\t ");
|
|
|
|
len = 10 + strlen(name);
|
|
|
|
}
|
|
|
|
if (!first)
|
|
|
|
printf(" %s", name);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf(
|
1994-05-11 11:34:05 +04:00
|
|
|
"\nMemory statistics by type Type Kern\n");
|
|
|
|
(void)printf(
|
1997-04-10 19:49:30 +04:00
|
|
|
" Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)\n");
|
1994-05-11 11:34:05 +04:00
|
|
|
for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) {
|
1993-04-09 16:58:42 +04:00
|
|
|
if (ks->ks_calls == 0)
|
|
|
|
continue;
|
1997-04-10 19:49:30 +04:00
|
|
|
(void)printf("%14s%6ld%6ldK%7ldK%6ldK%9ld%5u%6u",
|
1993-04-09 16:58:42 +04:00
|
|
|
kmemnames[i] ? kmemnames[i] : "undefined",
|
|
|
|
ks->ks_inuse, (ks->ks_memuse + 1023) / 1024,
|
|
|
|
(ks->ks_maxused + 1023) / 1024,
|
|
|
|
(ks->ks_limit + 1023) / 1024, ks->ks_calls,
|
|
|
|
ks->ks_limblocks, ks->ks_mapblocks);
|
1994-05-11 11:34:05 +04:00
|
|
|
first = 1;
|
|
|
|
for (j = 1 << MINBUCKET; j < 1 << (MINBUCKET + 16); j <<= 1) {
|
|
|
|
if ((ks->ks_size & j) == 0)
|
|
|
|
continue;
|
|
|
|
if (first)
|
|
|
|
printf(" %d", j);
|
|
|
|
else
|
|
|
|
printf(",%d", j);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
printf("\n");
|
1993-04-09 16:58:42 +04:00
|
|
|
totuse += ks->ks_memuse;
|
|
|
|
totreq += ks->ks_calls;
|
|
|
|
}
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)printf("\nMemory Totals: In Use Free Requests\n");
|
|
|
|
(void)printf(" %7ldK %6ldK %8ld\n",
|
|
|
|
(totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1998-07-27 14:26:11 +04:00
|
|
|
void
|
|
|
|
dopool()
|
|
|
|
{
|
|
|
|
int first;
|
|
|
|
long addr;
|
|
|
|
long total = 0, inuse = 0;
|
|
|
|
TAILQ_HEAD(,pool) pool_head;
|
|
|
|
struct pool pool, *pp = &pool;
|
|
|
|
|
|
|
|
kread(X_POOLHEAD, &pool_head, sizeof(pool_head));
|
|
|
|
addr = (long)TAILQ_FIRST(&pool_head);
|
|
|
|
|
|
|
|
for (first = 1; addr != 0; ) {
|
|
|
|
char name[32], maxp[32];
|
|
|
|
if (kvm_read(kd, addr, (void *)pp, sizeof *pp) != sizeof *pp) {
|
|
|
|
(void)fprintf(stderr, "vmstat: pool chain trashed: %s\n",
|
|
|
|
kvm_geterr(kd));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (kvm_read(kd, (long)pp->pr_wchan, name, sizeof name) < 0) {
|
|
|
|
(void)fprintf(stderr, "vmstat: pool name trashed: %s\n",
|
|
|
|
kvm_geterr(kd));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
name[31]='\0';
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
(void)printf("Memory resource pool statistics\n");
|
|
|
|
(void)printf(
|
1998-08-02 03:45:05 +04:00
|
|
|
"%16s %6s %8s %8s %8s %7s %7s %6s %6s %6s %6s %6s\n",
|
1998-07-27 14:26:11 +04:00
|
|
|
"Name",
|
|
|
|
"Size",
|
|
|
|
"Requests",
|
|
|
|
"Failed",
|
|
|
|
"Releases",
|
|
|
|
"Pagereq",
|
|
|
|
"Pagerel",
|
|
|
|
"Npage",
|
|
|
|
"Hiwat",
|
|
|
|
"Minpage",
|
1998-08-02 03:45:05 +04:00
|
|
|
"Maxpage",
|
|
|
|
"Idle");
|
1998-07-27 14:26:11 +04:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
if (pp->pr_maxpages == UINT_MAX)
|
|
|
|
sprintf(maxp, "inf");
|
|
|
|
else
|
|
|
|
sprintf(maxp, "%6u", pp->pr_maxpages);
|
|
|
|
(void)printf(
|
1998-08-02 03:45:05 +04:00
|
|
|
"%16s %6u %8lu %8lu %8lu %7lu %7lu %6u %6u %6u %6s %6lu\n",
|
1998-07-27 14:26:11 +04:00
|
|
|
name,
|
|
|
|
pp->pr_size,
|
|
|
|
pp->pr_nget,
|
|
|
|
pp->pr_nfail,
|
|
|
|
pp->pr_nput,
|
|
|
|
pp->pr_npagealloc,
|
|
|
|
pp->pr_npagefree,
|
|
|
|
pp->pr_npages,
|
|
|
|
pp->pr_hiwat,
|
|
|
|
pp->pr_minpages,
|
1998-08-02 03:45:05 +04:00
|
|
|
maxp,
|
|
|
|
pp->pr_nidle);
|
1998-07-27 14:26:11 +04:00
|
|
|
|
|
|
|
inuse += (pp->pr_nget - pp->pr_nput) * pp->pr_size;
|
|
|
|
total += pp->pr_npages * pp->pr_pagesz;
|
|
|
|
addr = (long)TAILQ_NEXT(pp, pr_poollist);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nIn use %ldK, total allocated %ldK; utilization %.1f%%\n",
|
|
|
|
inuse/1024, total/1024, (double)(100 * inuse) / total);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
|
|
|
* kread reads something from the kernel, given its nlist index.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kread(nlx, addr, size)
|
|
|
|
int nlx;
|
|
|
|
void *addr;
|
|
|
|
size_t size;
|
|
|
|
{
|
1998-07-26 21:53:10 +04:00
|
|
|
const char *sym;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1994-05-11 11:34:05 +04:00
|
|
|
if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0) {
|
|
|
|
sym = namelist[nlx].n_name;
|
1993-04-09 16:58:42 +04:00
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
|
|
|
(void)fprintf(stderr,
|
1994-05-11 11:34:05 +04:00
|
|
|
"vmstat: symbol %s not defined\n", sym);
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1994-05-11 11:34:05 +04:00
|
|
|
if (kvm_read(kd, namelist[nlx].n_value, addr, size) != size) {
|
|
|
|
sym = namelist[nlx].n_name;
|
1993-04-09 16:58:42 +04:00
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)fprintf(stderr, "vmstat: %s: %s\n", sym, kvm_geterr(kd));
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
struct nlist histnl[] = {
|
|
|
|
{ "_uvm_histories" },
|
|
|
|
#define X_UVM_HISTORIES 0
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traverse the UVM history buffers, performing the requested action.
|
|
|
|
*
|
|
|
|
* Note, we assume that if we're not listing, we're dumping.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
hist_traverse(todo, histname)
|
|
|
|
int todo;
|
|
|
|
const char *histname;
|
|
|
|
{
|
|
|
|
struct uvm_history_head histhead;
|
|
|
|
struct uvm_history hist, *histkva;
|
|
|
|
char *name = NULL;
|
|
|
|
size_t namelen = 0;
|
|
|
|
|
|
|
|
if (kvm_nlist(kd, histnl) != 0) {
|
|
|
|
printf("UVM history is not compiled into the kernel.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kvm_read(kd, histnl[X_UVM_HISTORIES].n_value, &histhead,
|
|
|
|
sizeof(histhead)) != sizeof(histhead)) {
|
|
|
|
warnx("unable to read %s: %s",
|
|
|
|
histnl[X_UVM_HISTORIES].n_name, kvm_geterr(kd));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (histhead.lh_first == NULL) {
|
|
|
|
printf("No active UVM history logs.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todo & HISTLIST)
|
|
|
|
printf("Active UVM histories:");
|
|
|
|
|
|
|
|
for (histkva = histhead.lh_first; histkva != NULL;
|
|
|
|
histkva = hist.list.le_next) {
|
|
|
|
if (kvm_read(kd, (u_long)histkva, &hist, sizeof(hist)) !=
|
|
|
|
sizeof(hist)) {
|
|
|
|
warnx("unable to read history at %p: %s",
|
|
|
|
histkva, kvm_geterr(kd));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hist.namelen > namelen) {
|
|
|
|
if (name != NULL)
|
|
|
|
free(name);
|
|
|
|
namelen = hist.namelen;
|
|
|
|
if ((name = malloc(namelen + 1)) == NULL)
|
|
|
|
err(1, "malloc history name");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kvm_read(kd, (u_long)hist.name, name, namelen) !=
|
|
|
|
namelen) {
|
|
|
|
warnx("unable to read history name at %p: %s",
|
|
|
|
hist.name, kvm_geterr(kd));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
name[namelen] = '\0';
|
|
|
|
if (todo & HISTLIST)
|
|
|
|
printf(" %s", name);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* If we're dumping all histories, do it, else
|
|
|
|
* check to see if this is the one we want.
|
|
|
|
*/
|
|
|
|
if (histname == NULL || strcmp(histname, name) == 0) {
|
|
|
|
if (histname == NULL)
|
|
|
|
printf("\nUVM history `%s':\n", name);
|
|
|
|
hist_dodump(&hist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todo & HISTLIST)
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (name != NULL)
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually dump the history buffer at the specified KVA.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
hist_dodump(histp)
|
|
|
|
struct uvm_history *histp;
|
|
|
|
{
|
|
|
|
struct uvm_history_ent *histents, *e;
|
|
|
|
size_t histsize;
|
|
|
|
char *fmt = NULL, *fn = NULL;
|
|
|
|
size_t fmtlen = 0, fnlen = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
histsize = sizeof(struct uvm_history_ent) * histp->n;
|
|
|
|
|
|
|
|
if ((histents = malloc(histsize)) == NULL)
|
|
|
|
err(1, "malloc history entries");
|
|
|
|
|
|
|
|
memset(histents, 0, histsize);
|
|
|
|
|
|
|
|
if (kvm_read(kd, (u_long)histp->e, histents, histsize) != histsize) {
|
|
|
|
warnx("unable to read history entries at %p: %s",
|
|
|
|
histp->e, kvm_geterr(kd));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = histp->f;
|
|
|
|
do {
|
|
|
|
e = &histents[i];
|
|
|
|
if (e->fmt != NULL) {
|
|
|
|
if (e->fmtlen > fmtlen) {
|
|
|
|
if (fmt != NULL)
|
|
|
|
free(fmt);
|
|
|
|
fmtlen = e->fmtlen;
|
|
|
|
if ((fmt = malloc(fmtlen + 1)) == NULL)
|
|
|
|
err(1, "malloc printf format");
|
|
|
|
}
|
|
|
|
if (e->fnlen > fnlen) {
|
|
|
|
if (fn != NULL)
|
|
|
|
free(fn);
|
|
|
|
fnlen = e->fnlen;
|
|
|
|
if ((fn = malloc(fnlen + 1)) == NULL)
|
|
|
|
err(1, "malloc function name");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kvm_read(kd, (u_long)e->fmt, fmt, fmtlen)
|
|
|
|
!= fmtlen) {
|
|
|
|
warnx("unable to read printf format "
|
|
|
|
"at %p: %s", e->fmt, kvm_geterr(kd));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fmt[fmtlen] = '\0';
|
|
|
|
|
|
|
|
if (kvm_read(kd, (u_long)e->fn, fn, fnlen) != fnlen) {
|
|
|
|
warnx("unable to read function name "
|
|
|
|
"at %p: %s", e->fn, kvm_geterr(kd));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fn[fnlen] = '\0';
|
|
|
|
|
|
|
|
printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
|
|
|
|
printf("%s#%ld: ", fn, e->call);
|
|
|
|
printf(fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
i = (i + 1) % histp->n;
|
|
|
|
} while (i != histp->f);
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(histents);
|
|
|
|
if (fmt != NULL)
|
|
|
|
free(fmt);
|
|
|
|
if (fn != NULL)
|
|
|
|
free(fn);
|
|
|
|
}
|
|
|
|
#endif /* UVM */
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
1998-07-05 12:02:34 +04:00
|
|
|
|
1998-02-13 08:10:32 +03:00
|
|
|
#if defined(UVM)
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)fprintf(stderr,
|
1998-02-13 08:10:32 +03:00
|
|
|
"usage: vmstat [-fHilms] [-h histname] [-c count] [-M core] \
|
1993-04-09 16:58:42 +04:00
|
|
|
[-N system] [-w wait] [disks]\n");
|
1998-02-13 08:10:32 +03:00
|
|
|
#else
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"usage: vmstat [-fims] [-c count] [-M core] \
|
|
|
|
[-N system] [-w wait] [disks]\n");
|
|
|
|
#endif /* UVM */
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|