Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/vmstat - Separate hashstat namelist into separate ha...
details: https://anonhg.NetBSD.org/src/rev/41ac953d45de
branches: trunk
changeset: 518214:41ac953d45de
user: lukem <lukem%NetBSD.org@localhost>
date: Mon Nov 26 14:06:31 2001 +0000
description:
- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on
diffstat:
usr.bin/vmstat/vmstat.c | 256 +++++++++++++++++++++++++++--------------------
1 files changed, 147 insertions(+), 109 deletions(-)
diffs (truncated from 384 to 300 lines):
diff -r 73b113e86e46 -r 41ac953d45de usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c Mon Nov 26 13:16:17 2001 +0000
+++ b/usr.bin/vmstat/vmstat.c Mon Nov 26 14:06:31 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.89 2001/11/26 10:38:59 lukem Exp $ */
+/* $NetBSD: vmstat.c,v 1.90 2001/11/26 14:06:31 lukem Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
#else
-__RCSID("$NetBSD: vmstat.c,v 1.89 2001/11/26 10:38:59 lukem Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.90 2001/11/26 14:06:31 lukem Exp $");
#endif
#endif /* not lint */
@@ -137,6 +137,9 @@
#include "dkstats.h"
+/*
+ * General namelist
+ */
struct nlist namelist[] =
{
#define X_BOOTTIME 0
@@ -165,51 +168,71 @@
{ "_pool_head" },
#define X_UVMEXP 12
{ "_uvmexp" },
-#define X_NFSNODE 13
- { "_nfsnodehash" },
-#define X_NFSNODETBL 14
- { "_nfsnodehashtbl" },
-#define X_IHASH 15
- { "_ihash" },
-#define X_IHASHTBL 16
- { "_ihashtbl" },
-#define X_BUFHASH 17
- { "_bufhash" },
-#define X_BUFHASHTBL 18
- { "_bufhashtbl" },
-#define X_PIDHASH 19
- { "_pidhash" },
-#define X_PIDHASHTBL 20
- { "_pidhashtbl" },
-#define X_PGRPHASH 21
- { "_pgrphash" },
-#define X_PGRPHASHTBL 22
- { "_pgrphashtbl" },
-#define X_UIHASH 23
- { "_uihash" },
-#define X_UIHASHTBL 24
- { "_uihashtbl" },
-#define X_IFADDRHASH 25
- { "_in_ifaddrhash" },
-#define X_IFADDRHASHTBL 26
- { "_in_ifaddrhashtbl" },
-#define X_NCHASH 27
- { "_nchash" },
-#define X_NCHASHTBL 28
- { "_nchashtbl" },
-#define X_NCVHASH 29
- { "_ncvhash" },
-#define X_NCVHASHTBL 30
- { "_ncvhashtbl" },
-
-#define X_END 31
+#define X_END 13
#if defined(pc532)
#define X_IVT (X_END)
{ "_ivt" },
#endif
- { "" },
+ { NULL },
};
+/*
+ * Namelist for hash statistics
+ */
+struct nlist hashnl[] =
+{
+#define X_NFSNODE 0
+ { "_nfsnodehash" },
+#define X_NFSNODETBL 1
+ { "_nfsnodehashtbl" },
+#define X_IHASH 2
+ { "_ihash" },
+#define X_IHASHTBL 3
+ { "_ihashtbl" },
+#define X_BUFHASH 4
+ { "_bufhash" },
+#define X_BUFHASHTBL 5
+ { "_bufhashtbl" },
+#define X_PIDHASH 6
+ { "_pidhash" },
+#define X_PIDHASHTBL 7
+ { "_pidhashtbl" },
+#define X_PGRPHASH 8
+ { "_pgrphash" },
+#define X_PGRPHASHTBL 9
+ { "_pgrphashtbl" },
+#define X_UIHASH 10
+ { "_uihash" },
+#define X_UIHASHTBL 11
+ { "_uihashtbl" },
+#define X_IFADDRHASH 12
+ { "_in_ifaddrhash" },
+#define X_IFADDRHASHTBL 13
+ { "_in_ifaddrhashtbl" },
+#define X_NCHASH 14
+ { "_nchash" },
+#define X_NCHASHTBL 15
+ { "_nchashtbl" },
+#define X_NCVHASH 16
+ { "_ncvhash" },
+#define X_NCVHASHTBL 17
+ { "_ncvhashtbl" },
+#define X_HASHNL_SIZE 18 /* must be last */
+ { NULL },
+
+};
+
+/*
+ * Namelist for UVM histories
+ */
+struct nlist histnl[] =
+{
+ { "_uvm_histories" },
+#define X_UVM_HISTORIES 0
+ { NULL },
+};
+
+
struct uvmexp uvmexp, ouvmexp;
int ndrives;
@@ -357,19 +380,19 @@
}
if ((c = kvm_nlist(kd, namelist)) != 0) {
- if (c > 0) {
- (void)fprintf(stderr,
- "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);
- (void)fputc('\n', stderr);
- } else
- warnx("kvm_nlist: %s", kvm_geterr(kd));
+ if (c == -1)
+ errx(1, "kvm_nlist: %s %s", "namelist", kvm_geterr(kd));
+ (void)fprintf(stderr, "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);
+ (void)fputc('\n', stderr);
exit(1);
}
+ 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));
if (todo & VMSTAT) {
struct winsize winsize;
@@ -1129,6 +1152,7 @@
inuse, total, (double)(100 * inuse) / total);
}
+
enum hashtype { /* from <sys/systm.h> */
HASH_LIST,
HASH_TAILQ
@@ -1141,41 +1165,51 @@
};
struct kernel_hash {
- int hashsize;
- int hashtbl;
- enum hashtype type;
- size_t offset;
+ 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 */
+ size_t offset; /* offset of {LIST,TAILQ}_NEXT */
} khashes[] =
{
{
- X_NFSNODE, X_NFSNODETBL,
- HASH_LIST, offsetof(struct nfsnode, n_hash)
- } , {
+ "buffer hash",
+ X_BUFHASH, X_BUFHASHTBL,
+ HASH_LIST, offsetof(struct buf, b_hash)
+ }, {
+ "inode cache (ihash)",
X_IHASH, X_IHASHTBL,
HASH_LIST, offsetof(struct inode, i_hash)
- } , {
- X_BUFHASH, X_BUFHASHTBL,
- HASH_LIST, offsetof(struct buf, b_hash)
- } , {
- X_PIDHASH, X_PIDHASHTBL,
- HASH_LIST, offsetof(struct proc, p_hash)
- } , {
+ }, {
+ "ipv4 address -> interface hash",
+ X_IFADDRHASH, X_IFADDRHASHTBL,
+ HASH_LIST, offsetof(struct in_ifaddr, ia_hash),
+ }, {
+ "name cache hash",
+ X_NCHASH, X_NCHASHTBL,
+ HASH_LIST, offsetof(struct namecache, nc_hash),
+ }, {
+ "name cache directory hash",
+ X_NCVHASH, X_NCVHASHTBL,
+ HASH_LIST, offsetof(struct namecache, nc_vhash),
+ }, {
+ "nfs client node cache",
+ X_NFSNODE, X_NFSNODETBL,
+ HASH_LIST, offsetof(struct nfsnode, n_hash)
+ }, {
+ "process group (pgrp) hash",
X_PGRPHASH, X_PGRPHASHTBL,
HASH_LIST, offsetof(struct pgrp, pg_hash),
- } , {
+ }, {
+ "process id (pid) hash",
+ X_PIDHASH, X_PIDHASHTBL,
+ HASH_LIST, offsetof(struct proc, p_hash)
+ }, {
+ "user info (uid -> used processes) hash",
X_UIHASH, X_UIHASHTBL,
HASH_LIST, offsetof(struct uidinfo, ui_hash),
- } , {
- X_IFADDRHASH, X_IFADDRHASHTBL,
- HASH_LIST, offsetof(struct in_ifaddr, ia_hash),
- } , {
- X_NCHASH, X_NCHASHTBL,
- HASH_LIST, offsetof(struct namecache, nc_hash),
- } , {
- X_NCVHASH, X_NCVHASHTBL,
- HASH_LIST, offsetof(struct namecache, nc_vhash),
- } , {
- -1, -1, 0, 0
+ }, {
+ NULL, -1, -1, 0, 0,
}
};
@@ -1194,25 +1228,30 @@
hashbufsize = 0;
if (todo & HASHLIST) {
- const char *prefix = "";
-
- printf("Supported hashes:\n\t");
- for (curhash = khashes; curhash->hashsize != -1; curhash++) {
- printf("%s%s",
- prefix, namelist[curhash->hashsize].n_name + 1);
- prefix = ", ";
+ printf("Supported hashes:\n");
+ for (curhash = khashes; curhash->description; curhash++) {
+ if (hashnl[curhash->hashsize].n_value == 0 ||
+ hashnl[curhash->hashtbl].n_value == 0)
+ continue;
+ printf("\t%-16s%s\n",
+ hashnl[curhash->hashsize].n_name + 1,
+ curhash->description);
}
return;
}
if (hashname != NULL) {
- for (curhash = khashes; curhash->hashsize != -1; curhash++) {
- if (strcmp(namelist[curhash->hashsize].n_name + 1,
- hashname) == 0)
+ for (curhash = khashes; curhash->description; curhash++) {
+ if (strcmp(hashnl[curhash->hashsize].n_name + 1,
+ hashname) == 0 &&
+ hashnl[curhash->hashsize].n_value != 0 &&
+ hashnl[curhash->hashtbl].n_value != 0)
break;
}
- if (curhash->hashsize == -1)
- errx(1, "%s: no such hash", hashname);
+ if (curhash->description == NULL) {
+ warnx("%s: no such hash", hashname);
+ return;
+ }
}
printf(
@@ -1222,28 +1261,35 @@
Home |
Main Index |
Thread Index |
Old Index