2005-03-10 19:23:42 +03:00
|
|
|
/* $NetBSD: vmstat.c,v 1.130 2005/03/10 16:23:42 he Exp $ */
|
1998-02-13 08:10:32 +03:00
|
|
|
|
|
|
|
/*-
|
2001-11-26 10:40:01 +03:00
|
|
|
* Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
|
1998-02-13 08:10:32 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2001-11-26 10:40:01 +03:00
|
|
|
* 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.
|
|
|
|
* - Simon Burge and Luke Mewburn of Wasabi Systems, Inc.
|
1998-02-13 08:10:32 +03: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 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.
|
2003-08-07 15:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-09 16:58:42 +04:00
|
|
|
* 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
|
2005-03-10 19:23:42 +03:00
|
|
|
__RCSID("$NetBSD: vmstat.c,v 1.130 2005/03/10 16:23:42 he Exp $");
|
1995-05-08 02:16:23 +04:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1999-04-01 03:25:46 +04:00
|
|
|
#define __POOL_EXPOSE
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <sys/param.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <sys/buf.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <sys/device.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <sys/ioctl.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <sys/malloc.h>
|
2003-02-01 09:29:14 +03:00
|
|
|
#include <sys/mallocvar.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/pool.h>
|
|
|
|
#include <sys/proc.h>
|
2000-06-04 06:25:40 +04:00
|
|
|
#include <sys/sched.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <sys/socket.h>
|
1994-05-11 11:34:05 +04:00
|
|
|
#include <sys/sysctl.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/user.h>
|
2000-06-29 10:26:33 +04:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
#include <uvm/uvm_stat.h>
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
|
|
|
|
#include <nfs/rpcv2.h>
|
|
|
|
#include <nfs/nfsproto.h>
|
|
|
|
#include <nfs/nfsnode.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1998-02-13 08:10:32 +03:00
|
|
|
#include <err.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <errno.h>
|
1999-02-12 18:04:00 +03:00
|
|
|
#include <fcntl.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <kvm.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <limits.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#undef n_hash
|
|
|
|
#include <paths.h>
|
1995-06-27 04:31:00 +04:00
|
|
|
#include <signal.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <stdio.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <stddef.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2002-11-01 15:47:55 +03:00
|
|
|
#include <util.h>
|
2001-11-26 10:40:01 +03:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
#include "dkstats.h"
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2001-11-26 17:06:31 +03:00
|
|
|
/*
|
|
|
|
* General namelist
|
|
|
|
*/
|
2001-11-26 10:40:01 +03:00
|
|
|
struct nlist namelist[] =
|
|
|
|
{
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_BOOTTIME 0
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_boottime" },
|
2001-01-27 14:08:23 +03:00
|
|
|
#define X_HZ 1
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_hz" },
|
2001-01-27 14:08:23 +03:00
|
|
|
#define X_STATHZ 2
|
1994-05-11 11:34:05 +04:00
|
|
|
{ "_stathz" },
|
2001-01-27 14:08:23 +03:00
|
|
|
#define X_NCHSTATS 3
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_nchstats" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_INTRNAMES 4
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_intrnames" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_EINTRNAMES 5
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_eintrnames" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_INTRCNT 6
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_intrcnt" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_EINTRCNT 7
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_eintrcnt" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_KMEMSTAT 8
|
2003-02-01 09:29:14 +03:00
|
|
|
{ "_kmemstatistics" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_KMEMBUCKETS 9
|
1993-04-09 16:58:42 +04:00
|
|
|
{ "_bucket" },
|
2001-01-27 14:08:23 +03:00
|
|
|
#define X_ALLEVENTS 10
|
1995-03-14 10:35:49 +03:00
|
|
|
{ "_allevents" },
|
2001-01-27 14:08:23 +03:00
|
|
|
#define X_POOLHEAD 11
|
1998-07-27 14:26:11 +04:00
|
|
|
{ "_pool_head" },
|
2000-06-04 12:07:36 +04:00
|
|
|
#define X_UVMEXP 12
|
1999-10-31 02:49:58 +04:00
|
|
|
{ "_uvmexp" },
|
2002-11-18 06:17:24 +03:00
|
|
|
#define X_TIME 13
|
|
|
|
{ "_time" },
|
|
|
|
#define X_END 14
|
2001-11-26 17:06:31 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Namelist for hash statistics
|
|
|
|
*/
|
|
|
|
struct nlist hashnl[] =
|
|
|
|
{
|
|
|
|
#define X_NFSNODE 0
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_nfsnodehash" },
|
2001-11-26 17:06:31 +03:00
|
|
|
#define X_NFSNODETBL 1
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_nfsnodehashtbl" },
|
2001-11-26 17:06:31 +03:00
|
|
|
#define X_IHASH 2
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_ihash" },
|
2001-11-26 17:06:31 +03:00
|
|
|
#define X_IHASHTBL 3
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_ihashtbl" },
|
2001-11-26 17:06:31 +03:00
|
|
|
#define X_BUFHASH 4
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_bufhash" },
|
2001-11-26 17:06:31 +03:00
|
|
|
#define X_BUFHASHTBL 5
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_bufhashtbl" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_UIHASH 6
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_uihash" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_UIHASHTBL 7
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_uihashtbl" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_IFADDRHASH 8
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_in_ifaddrhash" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_IFADDRHASHTBL 9
|
2001-11-26 10:40:01 +03:00
|
|
|
{ "_in_ifaddrhashtbl" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_NCHASH 10
|
2001-11-26 13:38:59 +03:00
|
|
|
{ "_nchash" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_NCHASHTBL 11
|
2001-11-26 13:38:59 +03:00
|
|
|
{ "_nchashtbl" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_NCVHASH 12
|
2001-11-26 13:38:59 +03:00
|
|
|
{ "_ncvhash" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_NCVHASHTBL 13
|
2001-11-26 13:38:59 +03:00
|
|
|
{ "_ncvhashtbl" },
|
2004-02-28 08:14:55 +03:00
|
|
|
#define X_HASHNL_SIZE 14 /* must be last */
|
2001-11-26 17:06:31 +03:00
|
|
|
{ NULL },
|
1993-04-09 16:58:42 +04:00
|
|
|
};
|
|
|
|
|
2001-11-26 17:06:31 +03:00
|
|
|
/*
|
|
|
|
* Namelist for UVM histories
|
|
|
|
*/
|
|
|
|
struct nlist histnl[] =
|
|
|
|
{
|
|
|
|
{ "_uvm_histories" },
|
|
|
|
#define X_UVM_HISTORIES 0
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
|
1998-02-07 18:42:32 +03:00
|
|
|
struct uvmexp uvmexp, ouvmexp;
|
2000-12-01 02:59:03 +03: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;
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
#define FORKSTAT 1<<0
|
|
|
|
#define INTRSTAT 1<<1
|
|
|
|
#define MEMSTAT 1<<2
|
|
|
|
#define SUMSTAT 1<<3
|
|
|
|
#define EVCNTSTAT 1<<4
|
|
|
|
#define VMSTAT 1<<5
|
|
|
|
#define HISTLIST 1<<6
|
|
|
|
#define HISTDUMP 1<<7
|
|
|
|
#define HASHSTAT 1<<8
|
2001-11-26 13:18:08 +03:00
|
|
|
#define HASHLIST 1<<9
|
2005-03-10 19:23:42 +03:00
|
|
|
#define VMTOTAL 1<<10
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2000-12-01 02:59:03 +03:00
|
|
|
void cpustats(void);
|
2001-11-26 10:40:01 +03:00
|
|
|
void deref_kptr(const void *, void *, size_t, const char *);
|
2000-12-01 02:59:03 +03:00
|
|
|
void dkstats(void);
|
|
|
|
void doevcnt(int verbose);
|
2001-11-26 13:18:08 +03:00
|
|
|
void dohashstat(int, int, const char *);
|
2000-12-01 02:59:03 +03:00
|
|
|
void dointr(int verbose);
|
|
|
|
void domem(void);
|
2005-01-26 16:07:32 +03:00
|
|
|
void dopool(int, int);
|
2002-02-20 10:43:30 +03:00
|
|
|
void dopoolcache(struct pool *, int);
|
2000-12-01 02:59:03 +03:00
|
|
|
void dosum(void);
|
2002-09-19 03:24:13 +04:00
|
|
|
void dovmstat(struct timespec *, int);
|
2005-03-10 19:23:42 +03:00
|
|
|
void print_total_hdr(void);
|
|
|
|
void dovmtotal(struct timespec *, int);
|
2000-12-01 02:59:03 +03:00
|
|
|
void kread(int, void *, size_t);
|
|
|
|
void needhdr(int);
|
|
|
|
long getuptime(void);
|
|
|
|
void printhdr(void);
|
|
|
|
long pct(long, long);
|
|
|
|
void usage(void);
|
|
|
|
void doforkst(void);
|
|
|
|
|
|
|
|
void hist_traverse(int, const char *);
|
|
|
|
void hist_dodump(struct uvm_history *);
|
|
|
|
|
|
|
|
int main(int, char **);
|
|
|
|
char **choosedrives(char **);
|
|
|
|
|
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
|
2001-01-27 14:08:23 +03:00
|
|
|
main(int argc, char *argv[])
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
2005-01-26 16:07:32 +03:00
|
|
|
int c, todo, verbose, wide;
|
2002-09-19 03:24:13 +04:00
|
|
|
struct timespec interval;
|
1993-04-09 16:58:42 +04:00
|
|
|
int reps;
|
2001-01-27 14:08:23 +03:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
|
|
|
gid_t egid = getegid();
|
2001-11-26 13:18:08 +03:00
|
|
|
const char *histname, *hashname;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2001-11-26 13:18:08 +03:00
|
|
|
histname = hashname = NULL;
|
1998-07-06 11:50:18 +04:00
|
|
|
(void)setegid(getgid());
|
1994-05-11 11:34:05 +04:00
|
|
|
memf = nlistf = NULL;
|
2005-01-26 16:07:32 +03:00
|
|
|
reps = todo = verbose = wide = 0;
|
2002-09-19 03:24:13 +04:00
|
|
|
interval.tv_sec = 0;
|
|
|
|
interval.tv_nsec = 0;
|
2005-03-10 19:23:42 +03:00
|
|
|
while ((c = getopt(argc, argv, "c:efh:HilLM:mN:stu:UvWw:")) != -1) {
|
1993-04-09 16:58:42 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
reps = atoi(optarg);
|
|
|
|
break;
|
2000-06-04 23:14:14 +04:00
|
|
|
case 'e':
|
|
|
|
todo |= EVCNTSTAT;
|
|
|
|
break;
|
1993-04-09 16:58:42 +04:00
|
|
|
case 'f':
|
|
|
|
todo |= FORKSTAT;
|
|
|
|
break;
|
1998-02-13 08:10:32 +03:00
|
|
|
case 'h':
|
2001-11-26 13:18:08 +03:00
|
|
|
hashname = optarg;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'H':
|
2001-11-26 10:40:01 +03:00
|
|
|
todo |= HASHSTAT;
|
1998-02-13 08:10:32 +03:00
|
|
|
break;
|
1993-04-09 16:58:42 +04:00
|
|
|
case 'i':
|
|
|
|
todo |= INTRSTAT;
|
|
|
|
break;
|
1998-02-13 08:10:32 +03:00
|
|
|
case 'l':
|
|
|
|
todo |= HISTLIST;
|
|
|
|
break;
|
2001-11-26 13:18:08 +03:00
|
|
|
case 'L':
|
|
|
|
todo |= HASHLIST;
|
|
|
|
break;
|
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;
|
2005-03-10 19:23:42 +03:00
|
|
|
case 't':
|
|
|
|
todo |= VMTOTAL;
|
|
|
|
break;
|
2001-11-26 10:40:01 +03:00
|
|
|
case 'u':
|
|
|
|
histname = optarg;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'U':
|
|
|
|
todo |= HISTDUMP;
|
|
|
|
break;
|
2000-06-04 23:14:14 +04:00
|
|
|
case 'v':
|
2001-11-26 10:40:01 +03:00
|
|
|
verbose++;
|
2000-06-04 23:14:14 +04:00
|
|
|
break;
|
2005-01-26 16:07:32 +03:00
|
|
|
case 'W':
|
|
|
|
wide++;
|
|
|
|
break;
|
1993-04-09 16:58:42 +04:00
|
|
|
case 'w':
|
2002-09-19 03:24:13 +04:00
|
|
|
interval.tv_sec = atol(optarg);
|
1993-04-09 16:58:42 +04:00
|
|
|
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
|
|
|
|
2001-01-27 14:08:23 +03:00
|
|
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
|
|
|
if (kd == NULL)
|
2001-11-26 10:40:01 +03:00
|
|
|
errx(1, "kvm_openfiles: %s", errbuf);
|
1998-07-06 11:50:18 +04:00
|
|
|
|
2002-01-28 05:15:15 +03:00
|
|
|
if (nlistf == NULL && memf == NULL)
|
|
|
|
(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) {
|
2001-11-26 17:06:31 +03:00
|
|
|
if (c == -1)
|
|
|
|
errx(1, "kvm_nlist: %s %s", "namelist", kvm_geterr(kd));
|
|
|
|
(void)fprintf(stderr, "vmstat: undefined symbols:");
|
2003-02-01 23:52:58 +03:00
|
|
|
for (c = 0; c < sizeof(namelist) / sizeof(namelist[0])-1; c++)
|
2001-11-26 17:06:31 +03:00
|
|
|
if (namelist[c].n_type == 0)
|
|
|
|
fprintf(stderr, " %s", namelist[c].n_name);
|
|
|
|
(void)fputc('\n', stderr);
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2001-11-26 17:06:31 +03:00
|
|
|
if ((c = kvm_nlist(kd, hashnl)) == -1 || c == X_HASHNL_SIZE)
|
|
|
|
errx(1, "kvm_nlist: %s %s", "hashnl", kvm_geterr(kd));
|
|
|
|
if (kvm_nlist(kd, histnl) == -1)
|
|
|
|
errx(1, "kvm_nlist: %s %s", "histnl", kvm_geterr(kd));
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
if (todo & VMSTAT) {
|
|
|
|
struct winsize winsize;
|
|
|
|
|
2002-01-28 05:15:15 +03:00
|
|
|
dkinit(0); /* Initialize disk stats, no disks selected. */
|
1998-07-19 21:47:07 +04:00
|
|
|
|
|
|
|
(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;
|
2003-07-02 16:47:00 +04:00
|
|
|
(void)ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize);
|
1993-04-09 16:58:42 +04:00
|
|
|
if (winsize.ws_row > 0)
|
|
|
|
winlines = winsize.ws_row;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
|
|
|
if (*argv) {
|
2002-09-19 03:24:13 +04:00
|
|
|
interval.tv_sec = atol(*argv);
|
1993-04-09 16:58:42 +04:00
|
|
|
if (*++argv)
|
|
|
|
reps = atoi(*argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-19 03:24:13 +04:00
|
|
|
if (interval.tv_sec) {
|
1993-04-09 16:58:42 +04:00
|
|
|
if (!reps)
|
|
|
|
reps = -1;
|
|
|
|
} else if (reps)
|
2002-09-19 03:24:13 +04:00
|
|
|
interval.tv_sec = 1;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2001-04-06 00:04:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Statistics dumping is incompatible with the default
|
|
|
|
* VMSTAT/dovmstat() output. So perform the interval/reps handling
|
|
|
|
* for it here.
|
|
|
|
*/
|
2005-03-10 19:23:42 +03:00
|
|
|
if ((todo & (VMSTAT|VMTOTAL)) == 0) {
|
2002-03-11 18:29:22 +03:00
|
|
|
for (;;) {
|
|
|
|
if (todo & (HISTLIST|HISTDUMP)) {
|
|
|
|
if ((todo & (HISTLIST|HISTDUMP)) ==
|
|
|
|
(HISTLIST|HISTDUMP))
|
|
|
|
errx(1, "you may list or dump,"
|
|
|
|
" but not both!");
|
|
|
|
hist_traverse(todo, histname);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (todo & FORKSTAT) {
|
|
|
|
doforkst();
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (todo & MEMSTAT) {
|
|
|
|
domem();
|
2005-01-26 16:07:32 +03:00
|
|
|
dopool(verbose, wide);
|
2002-03-11 18:29:22 +03:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (todo & SUMSTAT) {
|
|
|
|
dosum();
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (todo & INTRSTAT) {
|
|
|
|
dointr(verbose);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (todo & EVCNTSTAT) {
|
|
|
|
doevcnt(verbose);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (todo & (HASHLIST|HASHSTAT)) {
|
|
|
|
if ((todo & (HASHLIST|HASHSTAT)) ==
|
|
|
|
(HASHLIST|HASHSTAT))
|
|
|
|
errx(1, "you may list or display,"
|
|
|
|
" but not both!");
|
|
|
|
dohashstat(verbose, todo, hashname);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2002-06-30 04:10:33 +04:00
|
|
|
|
|
|
|
if (reps >= 0 && --reps <=0)
|
2002-03-11 18:29:22 +03:00
|
|
|
break;
|
2002-09-19 03:24:13 +04:00
|
|
|
nanosleep(&interval, NULL);
|
2002-03-11 18:29:22 +03:00
|
|
|
}
|
2005-03-10 19:23:42 +03:00
|
|
|
} else {
|
|
|
|
if ((todo & (VMSTAT|VMTOTAL)) == (VMSTAT|VMTOTAL)) {
|
|
|
|
errx(1, "you may not both do vmstat and vmtotal");
|
|
|
|
}
|
|
|
|
if (todo & VMSTAT)
|
|
|
|
dovmstat(&interval, reps);
|
|
|
|
if (todo & VMTOTAL)
|
|
|
|
dovmtotal(&interval, reps);
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
2000-12-01 02:59:03 +03:00
|
|
|
choosedrives(char **argv)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
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.
|
|
|
|
*/
|
2001-01-27 14:08:23 +03:00
|
|
|
#define BACKWARD_COMPATIBILITY
|
1993-04-09 16:58:42 +04:00
|
|
|
for (ndrives = 0; *argv; ++argv) {
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
2004-11-05 22:56:34 +03:00
|
|
|
if (isdigit((unsigned char)**argv))
|
1993-04-09 16:58:42 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2004-01-23 00:47:55 +03:00
|
|
|
for (i = 0; i < dk_ndrive && ndrives < 3; 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;
|
|
|
|
}
|
2001-01-27 14:08:23 +03:00
|
|
|
return (argv);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2000-12-01 02:59:03 +03:00
|
|
|
getuptime(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1996-06-05 04:18:58 +04:00
|
|
|
static struct timeval boottime;
|
2002-11-18 06:17:24 +03:00
|
|
|
struct timeval now, diff;
|
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));
|
2002-11-18 06:17:24 +03:00
|
|
|
kread(X_TIME, &now, sizeof(now));
|
|
|
|
timersub(&now, &boottime, &diff);
|
|
|
|
uptime = diff.tv_sec;
|
2001-11-26 10:40:01 +03:00
|
|
|
if (uptime <= 0 || uptime > 60*60*24*365*10)
|
|
|
|
errx(1, "time makes no sense; namelist must be wrong.");
|
2001-01-27 14:08:23 +03:00
|
|
|
return (uptime);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int hz, hdrcnt;
|
|
|
|
|
2005-03-10 19:23:42 +03:00
|
|
|
void
|
|
|
|
print_total_hdr()
|
|
|
|
{
|
|
|
|
|
|
|
|
(void)printf("procs memory\n");
|
|
|
|
(void)printf("ru dw pw sl sw");
|
|
|
|
(void)printf(" total-v active-v active-r");
|
|
|
|
(void)printf(" vm-sh avm-sh rm-sh arm-sh free\n");
|
|
|
|
hdrcnt = winlines - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dovmtotal(struct timespec *interval, int reps)
|
|
|
|
{
|
|
|
|
struct vmtotal total;
|
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
(void)signal(SIGCONT, needhdr);
|
|
|
|
|
|
|
|
for (hdrcnt = 1;;) {
|
|
|
|
if (!--hdrcnt)
|
|
|
|
print_total_hdr();
|
|
|
|
if (memf != NULL) {
|
|
|
|
printf("Unable to get vmtotals from crash dump.\n");
|
|
|
|
memset(&total, 0, sizeof(total));
|
|
|
|
} else {
|
|
|
|
size = sizeof(total);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_METER;
|
|
|
|
if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
|
|
|
|
printf("Can't get vmtotals: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
memset(&total, 0, sizeof(total));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("%2d ", total.t_rq);
|
|
|
|
printf("%2d ", total.t_dw);
|
|
|
|
printf("%2d ", total.t_pw);
|
|
|
|
printf("%2d ", total.t_sl);
|
|
|
|
printf("%2d ", total.t_sw);
|
|
|
|
|
|
|
|
printf("%9d ", total.t_vm);
|
|
|
|
printf("%9d ", total.t_avm);
|
|
|
|
printf("%9d ", total.t_arm);
|
|
|
|
printf("%5d ", total.t_vmshr);
|
|
|
|
printf("%6d ", total.t_avmshr);
|
|
|
|
printf("%5d ", total.t_rmshr);
|
|
|
|
printf("%6d ", total.t_armshr);
|
|
|
|
printf("%5d", total.t_free);
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
(void)fflush(stdout);
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nanosleep(interval, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
void
|
2002-09-19 03:24:13 +04:00
|
|
|
dovmstat(struct timespec *interval, int reps)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
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();
|
1999-10-31 02:49:58 +04:00
|
|
|
kread(X_UVMEXP, &uvmexp, sizeof(uvmexp));
|
|
|
|
if (memf != NULL) {
|
|
|
|
/*
|
|
|
|
* XXX Can't do this if we're reading a crash
|
|
|
|
* XXX dump because they're lazily-calculated.
|
|
|
|
*/
|
|
|
|
printf("Unable to get vmtotals from crash dump.\n");
|
1998-08-10 06:57:23 +04:00
|
|
|
memset(&total, 0, sizeof(total));
|
1999-10-31 02:49:58 +04:00
|
|
|
} else {
|
|
|
|
size = sizeof(total);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_METER;
|
|
|
|
if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
|
|
|
|
printf("Can't get vmtotals: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
memset(&total, 0, sizeof(total));
|
|
|
|
}
|
1994-05-11 11:34:05 +04:00
|
|
|
}
|
2004-01-23 00:47:55 +03:00
|
|
|
(void)printf("%2d %d %d",
|
1994-05-11 11:34:05 +04:00
|
|
|
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
|
2001-01-27 14:08:23 +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 */
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %6ld %6ld ",
|
1993-04-09 16:58:42 +04:00
|
|
|
pgtok(total.t_avm), pgtok(total.t_free));
|
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();
|
2001-11-26 10:40:01 +03:00
|
|
|
putchar('\n');
|
1998-02-07 19:18:14 +03:00
|
|
|
(void)fflush(stdout);
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
|
|
|
ouvmexp = uvmexp;
|
2002-09-19 03:24:13 +04:00
|
|
|
uptime = interval->tv_sec;
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
|
|
|
* 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;
|
2002-09-19 03:24:13 +04:00
|
|
|
nanosleep(interval, NULL);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
printhdr(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
int i;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" procs memory page%*s", 23, "");
|
1996-05-11 03:16:30 +04:00
|
|
|
if (ndrives > 0)
|
2000-09-28 18:56:52 +04:00
|
|
|
(void)printf("%s %*sfaults cpu\n",
|
2001-01-27 14:08:23 +03:00
|
|
|
((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",
|
2001-01-27 14:08:23 +03:00
|
|
|
ndrives * 3, "");
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" r b w avm fre flt re pi po fr sr ");
|
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
|
2000-12-01 02:59:03 +03:00
|
|
|
needhdr(int dummy)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
hdrcnt = 1;
|
|
|
|
}
|
|
|
|
|
1997-10-20 07:11:57 +04:00
|
|
|
long
|
2000-12-01 02:59:03 +03:00
|
|
|
pct(long top, long bot)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1994-05-11 11:34:05 +04:00
|
|
|
long ans;
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
if (bot == 0)
|
2001-01-27 14:08:23 +03:00
|
|
|
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
|
2000-12-01 02:59:03 +03:00
|
|
|
dosum(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
struct nchstats nchstats;
|
2004-10-16 01:29:03 +04:00
|
|
|
u_long nchtotal;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1999-10-31 02:49:58 +04:00
|
|
|
kread(X_UVMEXP, &uvmexp, 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);
|
|
|
|
|
2001-05-02 05:26:04 +04:00
|
|
|
(void)printf("%9u page color%s\n",
|
|
|
|
uvmexp.ncolors, uvmexp.ncolors == 1 ? "" : "s");
|
|
|
|
|
1998-02-09 16:11:26 +03:00
|
|
|
(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);
|
2000-04-24 21:40:31 +04:00
|
|
|
(void)printf("%9u zero pages\n", uvmexp.zeropages);
|
1998-02-09 16:11:26 +03:00
|
|
|
(void)printf("%9u reserve pagedaemon pages\n",
|
|
|
|
uvmexp.reserve_pagedaemon);
|
|
|
|
(void)printf("%9u reserve kernel pages\n", uvmexp.reserve_kernel);
|
2001-12-09 06:07:43 +03:00
|
|
|
(void)printf("%9u anonymous pages\n", uvmexp.anonpages);
|
|
|
|
(void)printf("%9u cached file pages\n", uvmexp.filepages);
|
|
|
|
(void)printf("%9u cached executable pages\n", uvmexp.execpages);
|
1998-02-09 16:11:26 +03:00
|
|
|
|
|
|
|
(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);
|
2004-02-13 14:36:08 +03:00
|
|
|
(void)printf("%9u CPU context switches\n", uvmexp.swtch);
|
1998-02-07 19:50:59 +03:00
|
|
|
(void)printf("%9u software interrupts\n", uvmexp.softs);
|
|
|
|
(void)printf("%9u system calls\n", uvmexp.syscalls);
|
1999-12-05 21:54:34 +03:00
|
|
|
(void)printf("%9u pagein requests\n", uvmexp.pageins);
|
|
|
|
(void)printf("%9u pageout requests\n", uvmexp.pdpageouts);
|
1998-02-07 19:50:59 +03:00
|
|
|
(void)printf("%9u swap ins\n", uvmexp.swapins);
|
|
|
|
(void)printf("%9u swap outs\n", uvmexp.swapouts);
|
1999-12-05 21:54:34 +03:00
|
|
|
(void)printf("%9u pages swapped in\n", uvmexp.pgswapin);
|
|
|
|
(void)printf("%9u pages swapped out\n", uvmexp.pgswapout);
|
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);
|
2000-04-24 21:40:31 +04:00
|
|
|
(void)printf("%9u pagealloc zero wanted and avail\n",
|
|
|
|
uvmexp.pga_zerohit);
|
|
|
|
(void)printf("%9u pagealloc zero wanted and not avail\n",
|
|
|
|
uvmexp.pga_zeromiss);
|
2000-09-22 02:38:28 +04:00
|
|
|
(void)printf("%9u aborts of idle page zeroing\n",
|
|
|
|
uvmexp.zeroaborts);
|
2001-04-29 09:56:47 +04:00
|
|
|
(void)printf("%9u pagealloc desired color avail\n",
|
|
|
|
uvmexp.colorhit);
|
|
|
|
(void)printf("%9u pagealloc desired color not avail\n",
|
|
|
|
uvmexp.colormiss);
|
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);
|
2001-01-27 14:08:23 +03:00
|
|
|
(void)printf("%9u anonymous pages scanned by daemon\n",
|
|
|
|
uvmexp.pdanscan);
|
1998-02-09 16:11:26 +03:00
|
|
|
(void)printf("%9u object pages scanned by daemon\n", uvmexp.pdobscan);
|
|
|
|
(void)printf("%9u pages reactivated\n", uvmexp.pdreact);
|
2004-10-16 01:29:03 +04:00
|
|
|
(void)printf("%9u anonymous pages reactivated\n", uvmexp.pdreanon);
|
|
|
|
(void)printf("%9u cached file pages reactivated\n", uvmexp.pdrefile);
|
|
|
|
(void)printf("%9u cached executable pages reactivated\n",
|
|
|
|
uvmexp.pdreexec);
|
1998-02-09 16:11:26 +03:00
|
|
|
(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);
|
2004-10-16 01:29:03 +04:00
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
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;
|
2004-10-16 01:29:03 +04:00
|
|
|
(void)printf("%9lu total name lookups\n", nchtotal);
|
|
|
|
(void)printf("%9lu good hits\n", nchstats.ncs_goodhits);
|
|
|
|
(void)printf("%9lu negative hits\n", nchstats.ncs_neghits);
|
|
|
|
(void)printf("%9lu bad hits\n", nchstats.ncs_badhits);
|
|
|
|
(void)printf("%9lu false hits\n", nchstats.ncs_falsehits);
|
|
|
|
(void)printf("%9lu miss\n", nchstats.ncs_miss);
|
|
|
|
(void)printf("%9lu too long\n", nchstats.ncs_long);
|
|
|
|
(void)printf("%9lu pass2 hits\n", nchstats.ncs_pass2);
|
|
|
|
(void)printf("%9lu 2passes\n", nchstats.ncs_2passes);
|
1993-04-09 16:58:42 +04:00
|
|
|
(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
|
2000-12-01 02:59:03 +03:00
|
|
|
doforkst(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1999-10-31 02:49:58 +04:00
|
|
|
|
|
|
|
kread(X_UVMEXP, &uvmexp, 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);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
dkstats(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
2002-06-30 04:10:33 +04:00
|
|
|
int dn;
|
1993-04-09 16:58:42 +04:00
|
|
|
double etime;
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
/* Calculate disk stat deltas. */
|
|
|
|
dkswap();
|
2002-06-30 04:10:33 +04:00
|
|
|
etime = cur.cp_etime;
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
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;
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf("%2.0f ",
|
|
|
|
(cur.dk_rxfer[dn] + cur.dk_wxfer[dn]) / etime);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
cpustats(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
int state;
|
2005-02-27 00:19:18 +03:00
|
|
|
double pcnt, total;
|
2004-01-23 00:47:55 +03:00
|
|
|
double stat_us, stat_sy, stat_id;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
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)
|
2005-02-27 00:19:18 +03:00
|
|
|
pcnt = 100 / total;
|
1993-04-09 16:58:42 +04:00
|
|
|
else
|
2005-02-27 00:19:18 +03:00
|
|
|
pcnt = 0;
|
|
|
|
stat_us = (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * pcnt;
|
|
|
|
stat_sy = (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * pcnt;
|
|
|
|
stat_id = cur.cp_time[CP_IDLE] * pcnt;
|
2004-01-23 00:47:55 +03:00
|
|
|
(void)printf("%*.0f ", ((stat_sy >= 100) ? 1 : 2), stat_us);
|
|
|
|
(void)printf("%*.0f ", ((stat_us >= 100 || stat_id >= 100) ? 1 : 2), stat_sy);
|
|
|
|
(void)printf("%2.0f", stat_id);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-04 23:14:14 +04:00
|
|
|
dointr(int verbose)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
2001-11-21 03:38:50 +03:00
|
|
|
unsigned long *intrcnt;
|
|
|
|
unsigned long long inttotal, uptime;
|
1997-10-20 07:11:57 +04:00
|
|
|
int nintr, inamlen;
|
|
|
|
char *intrname;
|
1996-04-04 04:27:50 +04:00
|
|
|
struct evcntlist allevents;
|
|
|
|
struct evcnt evcnt, *evptr;
|
2000-06-04 23:14:14 +04:00
|
|
|
char evgroup[EVCNT_STRING_MAX], evname[EVCNT_STRING_MAX];
|
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);
|
2001-11-26 10:40:01 +03:00
|
|
|
if (intrcnt == NULL || intrname == NULL)
|
|
|
|
errx(1, "%s", "");
|
1993-04-09 16:58:42 +04:00
|
|
|
kread(X_INTRCNT, intrcnt, (size_t)nintr);
|
|
|
|
kread(X_INTRNAMES, intrname, (size_t)inamlen);
|
2001-08-26 06:50:37 +04:00
|
|
|
(void)printf("%-34s %16s %8s\n", "interrupt", "total", "rate");
|
1993-04-09 16:58:42 +04:00
|
|
|
inttotal = 0;
|
|
|
|
nintr /= sizeof(long);
|
|
|
|
while (--nintr >= 0) {
|
2000-06-04 23:14:14 +04:00
|
|
|
if (*intrcnt || verbose)
|
2001-11-21 03:38:50 +03:00
|
|
|
(void)printf("%-34s %16llu %8llu\n", intrname,
|
|
|
|
(unsigned long long)*intrcnt,
|
|
|
|
(unsigned long long)(*intrcnt / uptime));
|
1993-04-09 16:58:42 +04:00
|
|
|
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) {
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(evptr, &evcnt, sizeof(evcnt), "event chain trashed");
|
2000-06-04 23:14:14 +04:00
|
|
|
evptr = evcnt.ev_list.tqe_next;
|
|
|
|
if (evcnt.ev_type != EVCNT_TYPE_INTR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (evcnt.ev_count == 0 && !verbose)
|
|
|
|
continue;
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(evcnt.ev_group, evgroup, evcnt.ev_grouplen + 1,
|
|
|
|
"event chain trashed");
|
|
|
|
deref_kptr(evcnt.ev_name, evname, evcnt.ev_namelen + 1,
|
|
|
|
"event chain trashed");
|
2000-06-04 23:14:14 +04:00
|
|
|
|
2001-11-21 03:38:50 +03:00
|
|
|
(void)printf("%s %s%*s %16llu %8llu\n", evgroup, evname,
|
2001-08-26 06:50:37 +04:00
|
|
|
34 - (evcnt.ev_grouplen + 1 + evcnt.ev_namelen), "",
|
2001-11-21 03:38:50 +03:00
|
|
|
(unsigned long long)evcnt.ev_count,
|
|
|
|
(unsigned long long)(evcnt.ev_count / uptime));
|
2000-06-04 23:14:14 +04:00
|
|
|
|
|
|
|
inttotal += evcnt.ev_count++;
|
|
|
|
}
|
2001-11-21 03:38:50 +03:00
|
|
|
(void)printf("%-34s %16llu %8llu\n", "Total", inttotal,
|
|
|
|
(unsigned long long)(inttotal / uptime));
|
2000-06-04 23:14:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
doevcnt(int verbose)
|
|
|
|
{
|
2001-08-26 06:50:37 +04:00
|
|
|
static const char * evtypes [] = { "misc", "intr", "trap" };
|
2001-11-21 03:38:50 +03:00
|
|
|
unsigned long long uptime;
|
2000-06-04 23:14:14 +04:00
|
|
|
struct evcntlist allevents;
|
|
|
|
struct evcnt evcnt, *evptr;
|
|
|
|
char evgroup[EVCNT_STRING_MAX], evname[EVCNT_STRING_MAX];
|
|
|
|
|
|
|
|
/* XXX should print type! */
|
|
|
|
|
|
|
|
uptime = getuptime();
|
2001-08-26 06:50:37 +04:00
|
|
|
(void)printf("%-34s %16s %8s %s\n", "event", "total", "rate", "type");
|
2000-06-04 23:14:14 +04:00
|
|
|
kread(X_ALLEVENTS, &allevents, sizeof allevents);
|
|
|
|
evptr = allevents.tqh_first;
|
|
|
|
while (evptr) {
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(evptr, &evcnt, sizeof(evcnt), "event chain trashed");
|
1996-11-26 01:55:59 +03:00
|
|
|
|
1996-04-04 04:27:50 +04:00
|
|
|
evptr = evcnt.ev_list.tqe_next;
|
2000-06-04 23:14:14 +04:00
|
|
|
if (evcnt.ev_count == 0 && !verbose)
|
|
|
|
continue;
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(evcnt.ev_group, evgroup, evcnt.ev_grouplen + 1,
|
|
|
|
"event chain trashed");
|
|
|
|
deref_kptr(evcnt.ev_name, evname, evcnt.ev_namelen + 1,
|
|
|
|
"event chain trashed");
|
2000-06-04 23:14:14 +04:00
|
|
|
|
2001-11-21 03:38:50 +03:00
|
|
|
(void)printf("%s %s%*s %16llu %8llu %s\n", evgroup, evname,
|
2001-08-26 06:50:37 +04:00
|
|
|
34 - (evcnt.ev_grouplen + 1 + evcnt.ev_namelen), "",
|
2001-11-21 03:38:50 +03:00
|
|
|
(unsigned long long)evcnt.ev_count,
|
|
|
|
(unsigned long long)(evcnt.ev_count / uptime),
|
2001-11-21 03:40:56 +03:00
|
|
|
(evcnt.ev_type < sizeof(evtypes)/sizeof(evtypes[0]) ?
|
|
|
|
evtypes[evcnt.ev_type] : "?"));
|
1995-03-14 10:35:49 +03:00
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
2003-02-01 09:29:14 +03:00
|
|
|
static char memname[64];
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
domem(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-10-20 07:11:57 +04:00
|
|
|
struct kmembuckets *kp;
|
2003-02-01 09:29:14 +03:00
|
|
|
struct malloc_type ks, *ksp;
|
1997-10-20 07:11:57 +04:00
|
|
|
int i, j;
|
1994-05-11 11:34:05 +04:00
|
|
|
int len, size, first;
|
|
|
|
long totuse = 0, totfree = 0, totreq = 0;
|
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;
|
2001-01-27 14:08:23 +03:00
|
|
|
(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);
|
1993-04-09 16:58:42 +04:00
|
|
|
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) {
|
2001-11-26 10:40:01 +03:00
|
|
|
warnx("Kmem statistics are not being gathered by the kernel.");
|
1997-02-22 05:04:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
2003-02-01 09:29:14 +03:00
|
|
|
for (kread(X_KMEMSTAT, &ksp, sizeof(ksp));
|
|
|
|
ksp != NULL; ksp = ks.ks_next) {
|
|
|
|
deref_kptr(ksp, &ks, sizeof(ks), "malloc type");
|
|
|
|
if (ks.ks_calls == 0)
|
1994-05-11 11:34:05 +04:00
|
|
|
continue;
|
2003-02-01 09:29:14 +03:00
|
|
|
if ((ks.ks_size & j) == 0)
|
1994-05-11 11:34:05 +04:00
|
|
|
continue;
|
2003-02-01 09:29:14 +03:00
|
|
|
deref_kptr(ks.ks_shortdesc, memname,
|
|
|
|
sizeof(memname), "malloc type name");
|
|
|
|
len += 2 + strlen(memname);
|
1994-05-11 11:34:05 +04:00
|
|
|
if (first)
|
2003-02-01 09:29:14 +03:00
|
|
|
printf("%8d %s", j, memname);
|
1994-05-11 11:34:05 +04:00
|
|
|
else
|
|
|
|
printf(",");
|
|
|
|
if (len >= 80) {
|
|
|
|
printf("\n\t ");
|
2003-02-01 09:29:14 +03:00
|
|
|
len = 10 + strlen(memname);
|
1994-05-11 11:34:05 +04:00
|
|
|
}
|
|
|
|
if (!first)
|
2003-02-01 09:29:14 +03:00
|
|
|
printf(" %s", memname);
|
1994-05-11 11:34:05 +04:00
|
|
|
first = 0;
|
|
|
|
}
|
2001-11-26 10:40:01 +03:00
|
|
|
putchar('\n');
|
1994-05-11 11:34:05 +04:00
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)printf(
|
2003-09-29 03:31:48 +04:00
|
|
|
"\nMemory statistics by type Type Kern\n");
|
1994-05-11 11:34:05 +04:00
|
|
|
(void)printf(
|
1997-04-10 19:49:30 +04:00
|
|
|
" Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)\n");
|
2003-02-01 09:29:14 +03:00
|
|
|
for (kread(X_KMEMSTAT, &ksp, sizeof(ksp));
|
|
|
|
ksp != NULL; ksp = ks.ks_next) {
|
|
|
|
deref_kptr(ksp, &ks, sizeof(ks), "malloc type");
|
|
|
|
if (ks.ks_calls == 0)
|
1993-04-09 16:58:42 +04:00
|
|
|
continue;
|
2003-02-01 09:29:14 +03:00
|
|
|
deref_kptr(ks.ks_shortdesc, memname,
|
|
|
|
sizeof(memname), "malloc type name");
|
1997-04-10 19:49:30 +04:00
|
|
|
(void)printf("%14s%6ld%6ldK%7ldK%6ldK%9ld%5u%6u",
|
2003-02-01 09:29:14 +03:00
|
|
|
memname,
|
|
|
|
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) {
|
2003-02-01 09:29:14 +03:00
|
|
|
if ((ks.ks_size & j) == 0)
|
1994-05-11 11:34:05 +04:00
|
|
|
continue;
|
|
|
|
if (first)
|
|
|
|
printf(" %d", j);
|
|
|
|
else
|
|
|
|
printf(",%d", j);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
printf("\n");
|
2003-02-01 09:29:14 +03:00
|
|
|
totuse += ks.ks_memuse;
|
|
|
|
totreq += ks.ks_calls;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2002-08-10 23:08:41 +04:00
|
|
|
(void)printf("\nMemory totals: In Use Free Requests\n");
|
|
|
|
(void)printf(" %7ldK %6ldK %8ld\n\n",
|
2001-01-27 14:08:23 +03:00
|
|
|
(totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1998-07-27 14:26:11 +04:00
|
|
|
void
|
2005-01-26 16:07:32 +03:00
|
|
|
dopool(int verbose, int wide)
|
1998-07-27 14:26:11 +04:00
|
|
|
{
|
2000-09-23 04:39:19 +04:00
|
|
|
int first, ovflw;
|
2001-11-26 10:40:01 +03:00
|
|
|
void *addr;
|
2005-01-26 16:07:32 +03:00
|
|
|
long total, inuse, this_total, this_inuse;
|
1998-07-27 14:26:11 +04:00
|
|
|
TAILQ_HEAD(,pool) pool_head;
|
|
|
|
struct pool pool, *pp = &pool;
|
2002-03-10 04:48:25 +03:00
|
|
|
struct pool_allocator pa;
|
2001-11-26 10:40:01 +03:00
|
|
|
char name[32], maxp[32];
|
1998-07-27 14:26:11 +04:00
|
|
|
|
|
|
|
kread(X_POOLHEAD, &pool_head, sizeof(pool_head));
|
2001-11-26 10:40:01 +03:00
|
|
|
addr = TAILQ_FIRST(&pool_head);
|
1998-07-27 14:26:11 +04:00
|
|
|
|
2005-01-26 16:07:32 +03:00
|
|
|
total = inuse = 0;
|
|
|
|
|
2003-05-06 14:10:11 +04:00
|
|
|
for (first = 1; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist) ) {
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed");
|
2002-03-10 04:48:25 +03:00
|
|
|
deref_kptr(pp->pr_alloc, &pa, sizeof(pa),
|
2004-12-20 11:20:50 +03:00
|
|
|
"pool allocator trashed");
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(pp->pr_wchan, name, sizeof(name),
|
2002-03-10 04:48:25 +03:00
|
|
|
"pool wait channel trashed");
|
2001-11-26 10:40:01 +03:00
|
|
|
name[sizeof(name)-1] = '\0';
|
1998-07-27 14:26:11 +04:00
|
|
|
|
|
|
|
if (first) {
|
|
|
|
(void)printf("Memory resource pool statistics\n");
|
|
|
|
(void)printf(
|
2005-01-26 16:07:32 +03:00
|
|
|
"%-*s%*s%*s%5s%*s%s%s%*s%*s%6s%s%6s%6s%6s%5s%s%s\n",
|
|
|
|
wide ? 16 : 11, "Name",
|
|
|
|
wide ? 6 : 5, "Size",
|
|
|
|
wide ? 12 : 9, "Requests",
|
2001-01-27 14:08:23 +03:00
|
|
|
"Fail",
|
2005-01-26 16:07:32 +03:00
|
|
|
wide ? 12 : 9, "Releases",
|
|
|
|
wide ? " InUse" : "",
|
|
|
|
wide ? " Avail" : "",
|
|
|
|
wide ? 7 : 6, "Pgreq",
|
|
|
|
wide ? 7 : 6, "Pgrel",
|
2001-01-27 14:08:23 +03:00
|
|
|
"Npage",
|
2005-01-26 16:07:32 +03:00
|
|
|
wide ? " PageSz" : "",
|
2001-01-27 14:08:23 +03:00
|
|
|
"Hiwat",
|
|
|
|
"Minpg",
|
|
|
|
"Maxpg",
|
2005-01-26 16:07:32 +03:00
|
|
|
"Idle",
|
|
|
|
wide ? " Flags" : "",
|
|
|
|
wide ? " Util" : "");
|
1998-07-27 14:26:11 +04:00
|
|
|
first = 0;
|
|
|
|
}
|
2003-05-06 14:10:11 +04:00
|
|
|
if (pp->pr_nget == 0 && !verbose)
|
|
|
|
continue;
|
1998-07-27 14:26:11 +04:00
|
|
|
if (pp->pr_maxpages == UINT_MAX)
|
2003-07-15 09:52:48 +04:00
|
|
|
snprintf(maxp, sizeof(maxp), "inf");
|
1998-07-27 14:26:11 +04:00
|
|
|
else
|
2003-07-15 09:52:48 +04:00
|
|
|
snprintf(maxp, sizeof(maxp), "%u", pp->pr_maxpages);
|
2000-09-23 04:39:19 +04:00
|
|
|
/*
|
|
|
|
* Print single word. `ovflow' is number of characters didn't fit
|
|
|
|
* on the last word. `fmt' is a format string to print this word.
|
|
|
|
* It must contain asterisk for field width. `width' is a width
|
|
|
|
* occupied by this word. `fixed' is a number of constant chars in
|
|
|
|
* `fmt'. `val' is a value to be printed using format string `fmt'.
|
|
|
|
*/
|
|
|
|
#define PRWORD(ovflw, fmt, width, fixed, val) do { \
|
|
|
|
(ovflw) += printf((fmt), \
|
|
|
|
(width) - (fixed) - (ovflw) > 0 ? \
|
|
|
|
(width) - (fixed) - (ovflw) : 0, \
|
|
|
|
(val)) - (width); \
|
|
|
|
if ((ovflw) < 0) \
|
|
|
|
(ovflw) = 0; \
|
|
|
|
} while (/* CONSTCOND */0)
|
|
|
|
ovflw = 0;
|
2005-01-26 16:07:32 +03:00
|
|
|
PRWORD(ovflw, "%-*s", wide ? 16 : 11, 0, name);
|
|
|
|
PRWORD(ovflw, " %*u", wide ? 6 : 5, 1, pp->pr_size);
|
|
|
|
PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nget);
|
2000-09-23 04:39:19 +04:00
|
|
|
PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nfail);
|
2005-01-26 16:07:32 +03:00
|
|
|
PRWORD(ovflw, " %*lu", wide ? 12 : 9, 1, pp->pr_nput);
|
|
|
|
if (wide)
|
|
|
|
PRWORD(ovflw, " %*u", 6, 1, pp->pr_nout);
|
|
|
|
if (wide)
|
|
|
|
PRWORD(ovflw, " %*u", 6, 1, pp->pr_nitems);
|
|
|
|
PRWORD(ovflw, " %*lu", wide ? 7 : 6, 1, pp->pr_npagealloc);
|
|
|
|
PRWORD(ovflw, " %*lu", wide ? 7 : 6, 1, pp->pr_npagefree);
|
|
|
|
PRWORD(ovflw, " %*u", 6, 1, pp->pr_npages);
|
|
|
|
if (wide)
|
|
|
|
PRWORD(ovflw, " %*u", 7, 1, pa.pa_pagesz);
|
|
|
|
PRWORD(ovflw, " %*u", 6, 1, pp->pr_hiwat);
|
|
|
|
PRWORD(ovflw, " %*u", 6, 1, pp->pr_minpages);
|
2000-09-23 04:39:19 +04:00
|
|
|
PRWORD(ovflw, " %*s", 6, 1, maxp);
|
2005-01-26 16:07:32 +03:00
|
|
|
PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nidle);
|
|
|
|
if (wide)
|
|
|
|
PRWORD(ovflw, " 0x%0*x", 4, 1,
|
|
|
|
pp->pr_flags | pp->pr_roflags);
|
1998-07-27 14:26:11 +04:00
|
|
|
|
2005-01-26 16:07:32 +03:00
|
|
|
this_inuse = pp->pr_nout * pp->pr_size;
|
|
|
|
this_total = pp->pr_npages * pa.pa_pagesz;
|
2001-10-07 16:50:54 +04:00
|
|
|
if (pp->pr_roflags & PR_RECURSIVE) {
|
|
|
|
/*
|
|
|
|
* Don't count in-use memory, since it's part
|
|
|
|
* of another pool and will be accounted for
|
|
|
|
* there.
|
|
|
|
*/
|
2005-01-26 16:07:32 +03:00
|
|
|
total += (this_total - this_inuse);
|
2001-10-07 16:50:54 +04:00
|
|
|
} else {
|
2005-01-26 16:07:32 +03:00
|
|
|
inuse += this_inuse;
|
|
|
|
total += this_total;
|
2001-10-07 16:50:54 +04:00
|
|
|
}
|
2005-01-26 16:07:32 +03:00
|
|
|
if (wide) {
|
|
|
|
if (this_total == 0)
|
|
|
|
printf(" ---");
|
|
|
|
else
|
|
|
|
printf(" %5.1f%%",
|
|
|
|
(100.0 * this_inuse) / this_total);
|
|
|
|
}
|
|
|
|
printf("\n");
|
2002-02-20 10:43:30 +03:00
|
|
|
dopoolcache(pp, verbose);
|
1998-07-27 14:26:11 +04:00
|
|
|
}
|
|
|
|
|
2001-01-27 14:10:18 +03:00
|
|
|
inuse /= 1024;
|
|
|
|
total /= 1024;
|
1998-07-27 14:26:11 +04:00
|
|
|
printf("\nIn use %ldK, total allocated %ldK; utilization %.1f%%\n",
|
2005-01-26 16:07:32 +03:00
|
|
|
inuse, total, (100.0 * inuse) / total);
|
1998-07-27 14:26:11 +04:00
|
|
|
}
|
|
|
|
|
2002-02-20 10:43:30 +03:00
|
|
|
void
|
|
|
|
dopoolcache(struct pool *pp, int verbose)
|
|
|
|
{
|
|
|
|
struct pool_cache pool_cache, *pc = &pool_cache;
|
|
|
|
struct pool_cache_group pool_cache_group, *pcg = &pool_cache_group;
|
|
|
|
void *addr, *pcg_addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (verbose < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (addr = TAILQ_FIRST(&pp->pr_cachelist); addr != NULL;
|
|
|
|
addr = TAILQ_NEXT(pc, pc_poollist)) {
|
|
|
|
deref_kptr(addr, pc, sizeof(*pc), "pool cache trashed");
|
|
|
|
printf("\tcache %p: allocfrom %p freeto %p\n", addr,
|
|
|
|
pc->pc_allocfrom, pc->pc_freeto);
|
|
|
|
printf("\t hits %lu misses %lu ngroups %lu nitems %lu\n",
|
|
|
|
pc->pc_hits, pc->pc_misses, pc->pc_ngroups, pc->pc_nitems);
|
|
|
|
if (verbose < 2)
|
|
|
|
continue;
|
|
|
|
for (pcg_addr = TAILQ_FIRST(&pc->pc_grouplist);
|
|
|
|
pcg_addr != NULL; pcg_addr = TAILQ_NEXT(pcg, pcg_list)) {
|
2002-02-20 10:52:43 +03:00
|
|
|
deref_kptr(pcg_addr, pcg, sizeof(*pcg),
|
|
|
|
"pool cache group trashed");
|
2002-02-20 10:43:30 +03:00
|
|
|
printf("\t\tgroup %p: avail %d\n", pcg_addr,
|
|
|
|
pcg->pcg_avail);
|
2003-04-09 23:02:29 +04:00
|
|
|
for (i = 0; i < PCG_NOBJECTS; i++) {
|
|
|
|
if (pcg->pcg_objects[i].pcgo_pa !=
|
|
|
|
POOL_PADDR_INVALID) {
|
|
|
|
printf("\t\t\t%p, 0x%llx\n",
|
|
|
|
pcg->pcg_objects[i].pcgo_va,
|
|
|
|
(unsigned long long)
|
|
|
|
pcg->pcg_objects[i].pcgo_pa);
|
|
|
|
} else {
|
|
|
|
printf("\t\t\t%p\n",
|
|
|
|
pcg->pcg_objects[i].pcgo_va);
|
|
|
|
}
|
|
|
|
}
|
2002-02-20 10:43:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-11-26 17:06:31 +03:00
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
enum hashtype { /* from <sys/systm.h> */
|
|
|
|
HASH_LIST,
|
|
|
|
HASH_TAILQ
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uidinfo { /* XXX: no kernel header file */
|
|
|
|
LIST_ENTRY(uidinfo) ui_hash;
|
|
|
|
uid_t ui_uid;
|
|
|
|
long ui_proccnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kernel_hash {
|
2001-11-26 17:06:31 +03:00
|
|
|
const char * description; /* description */
|
|
|
|
int hashsize; /* nlist index for hash size */
|
|
|
|
int hashtbl; /* nlist index for hash table */
|
|
|
|
enum hashtype type; /* type of hash table */
|
2002-06-30 04:10:33 +04:00
|
|
|
size_t offset; /* offset of {LIST,TAILQ}_NEXT */
|
2001-11-26 10:40:01 +03:00
|
|
|
} khashes[] =
|
|
|
|
{
|
|
|
|
{
|
2001-11-26 17:06:31 +03:00
|
|
|
"buffer hash",
|
2001-11-26 10:40:01 +03:00
|
|
|
X_BUFHASH, X_BUFHASHTBL,
|
|
|
|
HASH_LIST, offsetof(struct buf, b_hash)
|
2001-11-26 17:06:31 +03:00
|
|
|
}, {
|
|
|
|
"inode cache (ihash)",
|
|
|
|
X_IHASH, X_IHASHTBL,
|
|
|
|
HASH_LIST, offsetof(struct inode, i_hash)
|
|
|
|
}, {
|
|
|
|
"ipv4 address -> interface hash",
|
2001-11-26 10:40:01 +03:00
|
|
|
X_IFADDRHASH, X_IFADDRHASHTBL,
|
|
|
|
HASH_LIST, offsetof(struct in_ifaddr, ia_hash),
|
2001-11-26 17:06:31 +03:00
|
|
|
}, {
|
|
|
|
"name cache hash",
|
2001-11-26 13:38:59 +03:00
|
|
|
X_NCHASH, X_NCHASHTBL,
|
|
|
|
HASH_LIST, offsetof(struct namecache, nc_hash),
|
2001-11-26 17:06:31 +03:00
|
|
|
}, {
|
|
|
|
"name cache directory hash",
|
2001-11-26 13:38:59 +03:00
|
|
|
X_NCVHASH, X_NCVHASHTBL,
|
|
|
|
HASH_LIST, offsetof(struct namecache, nc_vhash),
|
2001-11-26 17:06:31 +03:00
|
|
|
}, {
|
|
|
|
"nfs client node cache",
|
|
|
|
X_NFSNODE, X_NFSNODETBL,
|
|
|
|
HASH_LIST, offsetof(struct nfsnode, n_hash)
|
|
|
|
}, {
|
|
|
|
"user info (uid -> used processes) hash",
|
|
|
|
X_UIHASH, X_UIHASHTBL,
|
|
|
|
HASH_LIST, offsetof(struct uidinfo, ui_hash),
|
|
|
|
}, {
|
|
|
|
NULL, -1, -1, 0, 0,
|
2001-11-26 10:40:01 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2001-11-26 13:18:08 +03:00
|
|
|
dohashstat(int verbose, int todo, const char *hashname)
|
2002-06-30 04:10:33 +04:00
|
|
|
{
|
2001-11-26 10:40:01 +03:00
|
|
|
LIST_HEAD(, generic) *hashtbl_list;
|
|
|
|
TAILQ_HEAD(, generic) *hashtbl_tailq;
|
|
|
|
struct kernel_hash *curhash;
|
2003-09-19 11:08:50 +04:00
|
|
|
void *hashaddr, *hashbuf, *nhashbuf, *nextaddr;
|
2001-11-26 10:40:01 +03:00
|
|
|
size_t elemsize, hashbufsize, thissize;
|
|
|
|
u_long hashsize;
|
|
|
|
int i, used, items, chain, maxchain;
|
|
|
|
|
|
|
|
hashbuf = NULL;
|
|
|
|
hashbufsize = 0;
|
2001-11-26 13:18:08 +03:00
|
|
|
|
|
|
|
if (todo & HASHLIST) {
|
2001-11-26 17:06:31 +03:00
|
|
|
printf("Supported hashes:\n");
|
|
|
|
for (curhash = khashes; curhash->description; curhash++) {
|
2002-06-30 04:10:33 +04:00
|
|
|
if (hashnl[curhash->hashsize].n_value == 0 ||
|
2001-11-26 17:06:31 +03:00
|
|
|
hashnl[curhash->hashtbl].n_value == 0)
|
|
|
|
continue;
|
|
|
|
printf("\t%-16s%s\n",
|
|
|
|
hashnl[curhash->hashsize].n_name + 1,
|
|
|
|
curhash->description);
|
2001-11-26 13:18:08 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hashname != NULL) {
|
2001-11-26 17:06:31 +03:00
|
|
|
for (curhash = khashes; curhash->description; curhash++) {
|
|
|
|
if (strcmp(hashnl[curhash->hashsize].n_name + 1,
|
|
|
|
hashname) == 0 &&
|
2002-06-30 04:10:33 +04:00
|
|
|
hashnl[curhash->hashsize].n_value != 0 &&
|
2001-11-26 17:06:31 +03:00
|
|
|
hashnl[curhash->hashtbl].n_value != 0)
|
2001-11-26 13:18:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2001-11-26 17:06:31 +03:00
|
|
|
if (curhash->description == NULL) {
|
|
|
|
warnx("%s: no such hash", hashname);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-26 13:18:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
printf(
|
|
|
|
"%-16s %8s %8s %8s %8s %8s %8s\n"
|
|
|
|
"%-16s %8s %8s %8s %8s %8s %8s\n",
|
|
|
|
"", "total", "used", "util", "num", "average", "maximum",
|
|
|
|
"hash table", "buckets", "buckets", "%", "items", "chain",
|
|
|
|
"chain");
|
2001-11-26 10:40:01 +03:00
|
|
|
|
2001-11-26 17:06:31 +03:00
|
|
|
for (curhash = khashes; curhash->description; curhash++) {
|
2002-06-30 04:10:33 +04:00
|
|
|
if (hashnl[curhash->hashsize].n_value == 0 ||
|
2001-11-26 17:06:31 +03:00
|
|
|
hashnl[curhash->hashtbl].n_value == 0)
|
|
|
|
continue;
|
2001-11-26 13:18:08 +03:00
|
|
|
if (hashname != NULL &&
|
2001-11-26 17:06:31 +03:00
|
|
|
strcmp(hashnl[curhash->hashsize].n_name + 1, hashname))
|
2001-11-26 13:18:08 +03:00
|
|
|
continue;
|
2001-11-26 10:40:01 +03:00
|
|
|
elemsize = curhash->type == HASH_LIST ?
|
|
|
|
sizeof(*hashtbl_list) : sizeof(*hashtbl_tailq);
|
2001-11-26 17:06:31 +03:00
|
|
|
deref_kptr((void *)hashnl[curhash->hashsize].n_value,
|
|
|
|
&hashsize, sizeof(hashsize),
|
|
|
|
hashnl[curhash->hashsize].n_name);
|
2001-11-26 10:40:01 +03:00
|
|
|
hashsize++;
|
2001-11-26 17:06:31 +03:00
|
|
|
deref_kptr((void *)hashnl[curhash->hashtbl].n_value,
|
|
|
|
&hashaddr, sizeof(hashaddr),
|
|
|
|
hashnl[curhash->hashtbl].n_name);
|
2001-11-26 10:40:01 +03:00
|
|
|
if (verbose)
|
2001-11-27 00:04:49 +03:00
|
|
|
printf("%s %lu, %s %p, offset %ld, elemsize %llu\n",
|
2001-11-26 17:06:31 +03:00
|
|
|
hashnl[curhash->hashsize].n_name + 1, hashsize,
|
|
|
|
hashnl[curhash->hashtbl].n_name + 1, hashaddr,
|
2002-06-30 04:10:33 +04:00
|
|
|
(long)curhash->offset,
|
2001-11-27 00:04:49 +03:00
|
|
|
(unsigned long long)elemsize);
|
2001-11-26 10:40:01 +03:00
|
|
|
thissize = hashsize * elemsize;
|
|
|
|
if (thissize > hashbufsize) {
|
2003-09-19 11:08:50 +04:00
|
|
|
if ((nhashbuf = realloc(hashbuf, thissize)) == NULL)
|
2002-06-30 04:10:33 +04:00
|
|
|
errx(1, "malloc hashbuf %llu",
|
2001-11-27 00:04:49 +03:00
|
|
|
(unsigned long long)hashbufsize);
|
2003-09-19 11:08:50 +04:00
|
|
|
hashbuf = nhashbuf;
|
|
|
|
hashbufsize = thissize;
|
2001-11-26 10:40:01 +03:00
|
|
|
}
|
|
|
|
deref_kptr(hashaddr, hashbuf, thissize,
|
2001-11-26 17:06:31 +03:00
|
|
|
hashnl[curhash->hashtbl].n_name);
|
2001-11-26 10:40:01 +03:00
|
|
|
used = 0;
|
|
|
|
items = maxchain = 0;
|
|
|
|
if (curhash->type == HASH_LIST)
|
|
|
|
hashtbl_list = hashbuf;
|
|
|
|
else
|
|
|
|
hashtbl_tailq = hashbuf;
|
|
|
|
for (i = 0; i < hashsize; i++) {
|
|
|
|
if (curhash->type == HASH_LIST)
|
|
|
|
nextaddr = LIST_FIRST(&hashtbl_list[i]);
|
|
|
|
else
|
|
|
|
nextaddr = TAILQ_FIRST(&hashtbl_tailq[i]);
|
|
|
|
if (nextaddr == NULL)
|
|
|
|
continue;
|
|
|
|
if (verbose)
|
|
|
|
printf("%5d: %p\n", i, nextaddr);
|
|
|
|
used++;
|
|
|
|
chain = 0;
|
|
|
|
do {
|
|
|
|
chain++;
|
|
|
|
deref_kptr((char *)nextaddr + curhash->offset,
|
|
|
|
&nextaddr, sizeof(void *),
|
|
|
|
"hash chain corrupted");
|
|
|
|
if (verbose > 1)
|
|
|
|
printf("got nextaddr as %p\n",
|
|
|
|
nextaddr);
|
|
|
|
} while (nextaddr != NULL);
|
|
|
|
items += chain;
|
|
|
|
if (verbose && chain > 1)
|
|
|
|
printf("\tchain = %d\n", chain);
|
|
|
|
if (chain > maxchain)
|
|
|
|
maxchain = chain;
|
|
|
|
}
|
2001-12-06 06:48:56 +03:00
|
|
|
printf("%-16s %8ld %8d %8.2f %8d %8.2f %8d\n",
|
2001-11-26 17:06:31 +03:00
|
|
|
hashnl[curhash->hashsize].n_name + 1,
|
2001-11-26 10:40:01 +03:00
|
|
|
hashsize, used, used * 100.0 / hashsize,
|
2001-12-06 06:48:56 +03:00
|
|
|
items, used ? (double)items / used : 0.0, maxchain);
|
2001-11-26 10:40:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
2001-11-26 17:06:31 +03:00
|
|
|
* kread reads something from the kernel, given its nlist index in namelist[].
|
1993-04-09 16:58:42 +04:00
|
|
|
*/
|
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
kread(int nlx, void *addr, size_t size)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1998-07-26 21:53:10 +04:00
|
|
|
const char *sym;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
sym = namelist[nlx].n_name;
|
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
|
|
|
if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0)
|
|
|
|
errx(1, "symbol %s not defined", sym);
|
|
|
|
deref_kptr((void *)namelist[nlx].n_value, addr, size, sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-06-30 04:10:33 +04:00
|
|
|
* Dereference the kernel pointer `kptr' and fill in the local copy
|
2001-11-26 10:40:01 +03:00
|
|
|
* pointed to by `ptr'. The storage space must be pre-allocated,
|
|
|
|
* and the size of the copy passed in `len'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
deref_kptr(const void *kptr, void *ptr, size_t len, const char *msg)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (*msg == '_')
|
|
|
|
msg++;
|
|
|
|
if (kvm_read(kd, (u_long)kptr, (char *)ptr, len) != len)
|
|
|
|
errx(1, "kptr %lx: %s: %s", (u_long)kptr, msg, kvm_geterr(kd));
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1998-02-13 08:10:32 +03:00
|
|
|
/*
|
|
|
|
* Traverse the UVM history buffers, performing the requested action.
|
|
|
|
*
|
|
|
|
* Note, we assume that if we're not listing, we're dumping.
|
|
|
|
*/
|
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
hist_traverse(int todo, const char *histname)
|
1998-02-13 08:10:32 +03:00
|
|
|
{
|
|
|
|
struct uvm_history_head histhead;
|
|
|
|
struct uvm_history hist, *histkva;
|
|
|
|
char *name = NULL;
|
|
|
|
size_t namelen = 0;
|
|
|
|
|
2001-11-26 17:06:31 +03:00
|
|
|
if (histnl[0].n_value == 0) {
|
2001-11-26 10:40:01 +03:00
|
|
|
warnx("UVM history is not compiled into the kernel.");
|
1998-02-13 08:10:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr((void *)histnl[X_UVM_HISTORIES].n_value, &histhead,
|
|
|
|
sizeof(histhead), histnl[X_UVM_HISTORIES].n_name);
|
1998-02-13 08:10:32 +03:00
|
|
|
|
|
|
|
if (histhead.lh_first == NULL) {
|
2001-11-26 10:40:01 +03:00
|
|
|
warnx("No active UVM history logs.");
|
1998-02-13 08:10:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todo & HISTLIST)
|
|
|
|
printf("Active UVM histories:");
|
|
|
|
|
2001-01-27 14:08:23 +03:00
|
|
|
for (histkva = LIST_FIRST(&histhead); histkva != NULL;
|
|
|
|
histkva = LIST_NEXT(&hist, list)) {
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(histkva, &hist, sizeof(hist), "histkva");
|
1998-02-13 08:10:32 +03:00
|
|
|
if (hist.namelen > namelen) {
|
|
|
|
if (name != NULL)
|
|
|
|
free(name);
|
|
|
|
namelen = hist.namelen;
|
|
|
|
if ((name = malloc(namelen + 1)) == NULL)
|
|
|
|
err(1, "malloc history name");
|
|
|
|
}
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(hist.name, name, namelen, "history name");
|
1998-02-13 08:10:32 +03:00
|
|
|
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)
|
2001-11-26 10:40:01 +03:00
|
|
|
putchar('\n');
|
1998-02-13 08:10:32 +03:00
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually dump the history buffer at the specified KVA.
|
|
|
|
*/
|
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
hist_dodump(struct uvm_history *histp)
|
1998-02-13 08:10:32 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(histp->e, histents, histsize, "history entries");
|
1998-02-13 08:10:32 +03:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(e->fmt, fmt, fmtlen, "printf format");
|
1998-02-13 08:10:32 +03:00
|
|
|
fmt[fmtlen] = '\0';
|
|
|
|
|
2001-11-26 10:40:01 +03:00
|
|
|
deref_kptr(e->fn, fn, fnlen, "function name");
|
1998-02-13 08:10:32 +03:00
|
|
|
fn[fnlen] = '\0';
|
|
|
|
|
2000-03-27 21:03:25 +04:00
|
|
|
printf("%06ld.%06ld ", (long int)e->tv.tv_sec,
|
|
|
|
(long int)e->tv.tv_usec);
|
2001-01-27 14:08:23 +03:00
|
|
|
printf("%s#%ld: ", fn, e->call);
|
1998-02-13 08:10:32 +03:00
|
|
|
printf(fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
|
2001-11-26 10:40:01 +03:00
|
|
|
putchar('\n');
|
1998-02-13 08:10:32 +03:00
|
|
|
}
|
|
|
|
i = (i + 1) % histp->n;
|
|
|
|
} while (i != histp->f);
|
|
|
|
|
|
|
|
free(histents);
|
|
|
|
if (fmt != NULL)
|
|
|
|
free(fmt);
|
|
|
|
if (fn != NULL)
|
|
|
|
free(fn);
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
void
|
2000-12-01 02:59:03 +03:00
|
|
|
usage(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1998-07-05 12:02:34 +04:00
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
(void)fprintf(stderr,
|
2005-01-26 16:42:07 +03:00
|
|
|
"usage: %s [-efHiLlmsUvW] [-c count] [-h hashname] [-M core] [-N system]\n"
|
|
|
|
"\t\t[-u histname] [-w wait] [disks]\n", getprogname());
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|