CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: simonb Date: Fri Apr 2 06:28:55 UTC 2021 Modified Files: src/usr.bin/vmstat: Makefile vmstat.c Log Message: Drop setgid kmem, simplify nlist setup. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/vmstat/Makefile cvs rdiff -u -r1.245 -r1.246 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/Makefile diff -u src/usr.bin/vmstat/Makefile:1.34 src/usr.bin/vmstat/Makefile:1.35 --- src/usr.bin/vmstat/Makefile:1.34 Thu Dec 29 23:42:39 2016 +++ src/usr.bin/vmstat/Makefile Fri Apr 2 06:28:55 2021 @@ -1,8 +1,7 @@ -# $NetBSD: Makefile,v 1.34 2016/12/29 23:42:39 mrg Exp $ +# $NetBSD: Makefile,v 1.35 2021/04/02 06:28:55 simonb Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include -USE_FORT?= yes # setgid PROG= vmstat CPPFLAGS+=-D_KMEMUSER -I${NETBSDSRCDIR}/sys @@ -10,8 +9,6 @@ SRCS= drvstats.c vmstat.c MAN= vmstat.1 DPADD= ${LIBKVM} LDADD= -lkvm -BINGRP= kmem -BINMODE=2555 CWARNFLAGS.clang+= -Wno-format-extra-args COPTS.vmstat.c += -Wno-format-nonliteral @@ -19,6 +16,4 @@ COPTS.vmstat.c += -Wno-format-nonliteral # sparc64 is broken! COPTS.vmstat.c += -Wno-error=stack-protector -.include "../../compat/exec.mk" - .include Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.245 src/usr.bin/vmstat/vmstat.c:1.246 --- src/usr.bin/vmstat/vmstat.c:1.245 Thu Apr 1 06:23:14 2021 +++ src/usr.bin/vmstat/vmstat.c Fri Apr 2 06:28:55 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.245 2021/04/01 06:23:14 simonb Exp $ */ +/* $NetBSD: vmstat.c,v 1.246 2021/04/02 06:28:55 simonb Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.245 2021/04/01 06:23:14 simonb Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.246 2021/04/02 06:28:55 simonb Exp $"); #endif #endif /* not lint */ @@ -328,7 +328,6 @@ static const int clockrate_mib[] = { CTL static const int vmmeter_mib[] = { CTL_VM, VM_METER }; static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 }; static const int boottime_mib[] = { CTL_KERN, KERN_BOOTTIME }; -static char kvm_errbuf[_POSIX2_LINE_MAX]; int main(int argc, char *argv[]) @@ -336,11 +335,10 @@ main(int argc, char *argv[]) int c, todo, verbose, wide; struct timespec interval; int reps; - gid_t egid = getegid(); const char *histname, *hashname; + char errbuf[_POSIX2_LINE_MAX]; histname = hashname = NULL; - (void)setegid(getgid()); memf = nlistf = NULL; reps = todo = verbose = wide = 0; interval.tv_sec = 0; @@ -415,35 +413,21 @@ main(int argc, char *argv[]) if (todo == 0) todo = VMSTAT; - /* - * 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. - */ - if (nlistf != NULL || memf != NULL) - (void)setgid(getgid()); - else - (void)setegid(egid); - - kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, kvm_errbuf); - if (kd == NULL) { - if (nlistf != NULL || memf != NULL) { - errx(1, "kvm_openfiles: %s", kvm_errbuf); - } + if (memf == NULL) { + kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); + } else { + kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); + getnlist(todo); } - if (nlistf == NULL && memf == NULL) - (void)setgid(getgid()); - + if (kd == NULL) + errx(EXIT_FAILURE, "%s", errbuf); if (todo & VMSTAT) { struct winsize winsize; (void)drvinit(0);/* Initialize disk stats, no disks selected. */ - (void)setgid(getgid()); /* don't need privs anymore */ - argv = choosedrives(argv); /* Select disks. */ winsize.ws_row = 0; (void)ioctl(STDOUT_FILENO, TIOCGWINSZ, ); @@ -466,8 +450,6 @@ main(int argc, char *argv[]) } else if (reps) interval.tv_sec = 1; - - getnlist(todo); /* * Statistics dumping is incompatible with the default * VMSTAT/dovmstat() output. So perform the interval/reps handling @@ -539,36 +521,30 @@ main(int argc, char *argv[]) void getnlist(int todo) { - static int namelist_done = 0; static int done = 0; int c; size_t i; - if (kd == NULL) - errx(1, "kvm_openfiles: %s", kvm_errbuf); - - if (!namelist_done) { - namelist_done = 1; - if ((c = kvm_nlist(kd, namelist)) != 0) { - int doexit = 0; - if (c == -1) -errx(1, "kvm_nlist: %s %s", -"namelist", kvm_geterr(kd)); - for (i = 0; i < __arraycount(namelist)-1; i++) -if (namelist[i].n_type == 0) { - if (doexit++ == 0) - (void)fprintf(stderr, - "%s: undefined symbols:", - getprogname()); - (void)fprintf(stderr, " %s", - namelist[i].n_name); -} - if (doexit) { -
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: simonb Date: Thu Apr 1 06:23:15 UTC 2021 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use kernel sysctl hashstat collection instead of kmem grovelling directly. Also GC a few old hash nlist entries that no longer exist. To generate a diff of this commit: cvs rdiff -u -r1.244 -r1.245 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.244 src/usr.bin/vmstat/vmstat.c:1.245 --- src/usr.bin/vmstat/vmstat.c:1.244 Thu Apr 1 05:33:50 2021 +++ src/usr.bin/vmstat/vmstat.c Thu Apr 1 06:23:14 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.244 2021/04/01 05:33:50 simonb Exp $ */ +/* $NetBSD: vmstat.c,v 1.245 2021/04/01 06:23:14 simonb Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.244 2021/04/01 05:33:50 simonb Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.245 2021/04/01 06:23:14 simonb Exp $"); #endif #endif /* not lint */ @@ -113,6 +113,7 @@ __RCSID("$NetBSD: vmstat.c,v 1.244 2021/ #include #include +#include #include #include #include @@ -207,31 +208,23 @@ struct nlist intrnl[] = */ struct nlist hashnl[] = { -#define X_NFSNODE 0 - { .n_name = "_nfsnodehash" }, -#define X_NFSNODETBL 1 - { .n_name = "_nfsnodehashtbl" }, -#define X_IHASH 2 - { .n_name = "_ihash" }, -#define X_IHASHTBL 3 - { .n_name = "_ihashtbl" }, -#define X_BUFHASH 4 +#define X_BUFHASH 0 { .n_name = "_bufhash" }, -#define X_BUFHASHTBL 5 +#define X_BUFHASHTBL 1 { .n_name = "_bufhashtbl" }, -#define X_UIHASH 6 +#define X_UIHASH 2 { .n_name = "_uihash" }, -#define X_UIHASHTBL 7 +#define X_UIHASHTBL 3 { .n_name = "_uihashtbl" }, -#define X_IFADDRHASH 8 +#define X_IFADDRHASH 4 { .n_name = "_in_ifaddrhash" }, -#define X_IFADDRHASHTBL 9 +#define X_IFADDRHASHTBL 5 { .n_name = "_in_ifaddrhashtbl" }, -#define X_VCACHEHASH 10 +#define X_VCACHEHASH 6 { .n_name = "_vcache_hashmask" }, -#define X_VCACHETBL 11 +#define X_VCACHETBL 7 { .n_name = "_vcache_hashtab" }, -#define X_HASHNL_SIZE 12 /* must be last */ +#define X_HASHNL_SIZE 8 /* must be last */ { .n_name = NULL }, }; @@ -300,6 +293,7 @@ void deref_kptr(const void *, void *, si void drvstats(int *); void doevcnt(int verbose, int type); void dohashstat(int, int, const char *); +void dohashstat_sysctl(int, int, const char *); void dointr(int verbose); void dopool(int, int); void dopoolcache(int); @@ -1925,6 +1919,9 @@ dohashstat(int verbose, int todo, const u_long hashsize, i; int used, items, chain, maxchain; + if (memf == NULL) + return dohashstat_sysctl(verbose, todo, hashname); + hashbuf = NULL; hashbufsize = 0; @@ -2057,6 +2054,75 @@ dohashstat(int verbose, int todo, const } } +void +dohashstat_sysctl(int verbose, int todo, const char *hashname) +{ + struct hashstat_sysctl hash, *data, *hs; + int mib[3]; + int error; + size_t i, len, miblen; + + + miblen = __arraycount(mib); + error = sysctlnametomib("kern.hashstat", mib, ); + if (error) + err(EXIT_FAILURE, "nametomib kern.hashstat failed"); + assert(miblen < 3); + + if (todo & HASHLIST) { + mib[miblen] = CTL_DESCRIBE; + miblen++; + }; + + if (hashname) { + mib[miblen] = CTL_QUERY; + miblen++; + memset(, 0, sizeof(hash)); + strlcpy(hash.hash_name, hashname, sizeof(hash.hash_name)); + len = sizeof(hash); + error = sysctl(mib, miblen, , , , len); + if (error == ENOENT) { + err(1, "hash '%s' not found", hashname); + return; + } else if (error) { + err(1, "sysctl kern.hashstat query failed"); + return; + } + + data = + len = 1; + } else { + data = asysctl(mib, miblen, ); + if (data == NULL) + err(1, "failed to read kern.hashstat"); + len /= sizeof(*data); + } + + if (todo & HASHLIST) { + printf("Supported hashes:\n"); + for (i = 0, hs = data; i < len; i++, hs++) { + printf("\t%-16s%s\n", hs->hash_name, hs->hash_desc); + } + } else { + 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"); + for (i = 0, hs = data; i < len; i++, hs++) { + printf("%-16s %8"PRId64" %8"PRId64" %8.2f %8"PRId64 + " %8.2f %8"PRId64"\n", + hs->hash_name, hs->hash_size, hs->hash_used, + hs->hash_used * 100.0 / hs->hash_size, hs->hash_items, + hs->hash_used ? (double)hs->hash_items / hs->hash_used : 0.0, + hs->hash_maxchain); + } + } + + if (!hashname && (data != NULL)) + free(data); +} + /* * kreadc like kread but returns 1 if successful, 0 otherwise */ @@ -2254,7 +2320,7 @@ hist_traverse_sysctl(int todo, const cha warnx("kernel history
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: simonb Date: Thu Apr 1 05:33:51 UTC 2021 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Now that ports that use legacy intrcnt interrupt accounting have event counters to show that data, for the live kernel case just show INTR events for "vmstat -i". To generate a diff of this commit: cvs rdiff -u -r1.243 -r1.244 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.243 src/usr.bin/vmstat/vmstat.c:1.244 --- src/usr.bin/vmstat/vmstat.c:1.243 Wed Mar 3 08:25:16 2021 +++ src/usr.bin/vmstat/vmstat.c Thu Apr 1 05:33:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $ */ +/* $NetBSD: vmstat.c,v 1.244 2021/04/01 05:33:50 simonb Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.244 2021/04/01 05:33:50 simonb Exp $"); #endif #endif /* not lint */ @@ -1259,6 +1259,11 @@ dointr(int verbose) int nintr, inamlen; char *intrname, *ointrname; + if (memf == NULL) { + doevcnt(verbose, EVCNT_TYPE_INTR); + return; + } + inttotal = 0; uptime = getuptime(); nintr = intrnl[X_EINTRCNT].n_value - intrnl[X_INTRCNT].n_value;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: simonb Date: Wed Mar 3 08:25:16 UTC 2021 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: For vmstat -h/-H, calculate the hash element size correctly instead of assuming that everything that isn't a list is a tailq. Fixes random reads from kmem that either fail or return incorrect data for the vcache hash table. To generate a diff of this commit: cvs rdiff -u -r1.242 -r1.243 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.242 src/usr.bin/vmstat/vmstat.c:1.243 --- src/usr.bin/vmstat/vmstat.c:1.242 Sun Jun 14 21:41:42 2020 +++ src/usr.bin/vmstat/vmstat.c Wed Mar 3 08:25:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.242 2020/06/14 21:41:42 ad Exp $ */ +/* $NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.242 2020/06/14 21:41:42 ad Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $"); #endif #endif /* not lint */ @@ -1964,8 +1964,20 @@ dohashstat(int verbose, int todo, const if (hashname != NULL && strcmp(hashnl[curhash->hashsize].n_name + 1, hashname)) continue; - elemsize = curhash->type == HASH_LIST ? - sizeof(*hashtbl_list) : sizeof(*hashtbl_tailq); + switch (curhash->type) { + case HASH_LIST: + elemsize = sizeof(*hashtbl_list); + break; + case HASH_SLIST: + elemsize = sizeof(*hashtbl_slist); + break; + case HASH_TAILQ: + elemsize = sizeof(*hashtbl_tailq); + break; + default: + /* shouldn't get here */ + continue; + } deref_kptr((void *)hashnl[curhash->hashsize].n_value, , sizeof(hashsize), hashnl[curhash->hashsize].n_name);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ad Date: Mon Mar 23 18:44:18 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: ncs_collisions is gone. To generate a diff of this commit: cvs rdiff -u -r1.238 -r1.239 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.238 src/usr.bin/vmstat/vmstat.c:1.239 --- src/usr.bin/vmstat/vmstat.c:1.238 Sun Mar 22 18:32:42 2020 +++ src/usr.bin/vmstat/vmstat.c Mon Mar 23 18:44:17 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.238 2020/03/22 18:32:42 ad Exp $ */ +/* $NetBSD: vmstat.c,v 1.239 2020/03/23 18:44:17 ad Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.238 2020/03/22 18:32:42 ad Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.239 2020/03/23 18:44:17 ad Exp $"); #endif #endif /* not lint */ @@ -1124,7 +1124,6 @@ dosum(void) (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes); (void)printf("%9" PRIu64 " reverse hits\n", nch_stats.ncs_revhits); (void)printf("%9" PRIu64 " reverse miss\n", nch_stats.ncs_revmiss); - (void)printf("%9" PRIu64 " hash collisions\n", nch_stats.ncs_collisions); (void)printf("%9" PRIu64 " access denied\n", nch_stats.ncs_denied); (void)printf( "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ad Date: Sun Mar 22 14:39:29 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: - nchash is gone. - Report new namecache stats. To generate a diff of this commit: cvs rdiff -u -r1.236 -r1.237 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.236 src/usr.bin/vmstat/vmstat.c:1.237 --- src/usr.bin/vmstat/vmstat.c:1.236 Sat Jan 25 05:43:32 2020 +++ src/usr.bin/vmstat/vmstat.c Sun Mar 22 14:39:28 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.236 2020/01/25 05:43:32 simonb Exp $ */ +/* $NetBSD: vmstat.c,v 1.237 2020/03/22 14:39:28 ad Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.236 2020/01/25 05:43:32 simonb Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.237 2020/03/22 14:39:28 ad Exp $"); #endif #endif /* not lint */ @@ -227,15 +227,11 @@ struct nlist hashnl[] = { .n_name = "_in_ifaddrhash" }, #define X_IFADDRHASHTBL 9 { .n_name = "_in_ifaddrhashtbl" }, -#define X_NCHASH 10 - { .n_name = "_nchash" }, -#define X_NCHASHTBL 11 - { .n_name = "_nchashtbl" }, -#define X_NCVCACHEHASH 12 +#define X_VCACHEHASH 10 { .n_name = "_vcache_hashmask" }, -#define X_NCVCACHETBL 13 +#define X_VCACHETBL 11 { .n_name = "_vcache_hashtab" }, -#define X_HASHNL_SIZE 14 /* must be last */ +#define X_HASHNL_SIZE 12 /* must be last */ { .n_name = NULL }, }; @@ -1124,6 +1120,8 @@ dosum(void) (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes); (void)printf("%9" PRIu64 " reverse hits\n", nch_stats.ncs_revhits); (void)printf("%9" PRIu64 " reverse miss\n", nch_stats.ncs_revmiss); + (void)printf("%9" PRIu64 " hash collisions\n", nch_stats.ncs_collisions); + (void)printf("%9" PRIu64 " access denied\n", nch_stats.ncs_denied); (void)printf( "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n", "", PCT(nch_stats.ncs_goodhits, nchtotal), @@ -1898,16 +1896,12 @@ struct kernel_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), - }, { "user info (uid -> used processes) hash", X_UIHASH, X_UIHASHTBL, HASH_LIST, offsetof(struct uidinfo, ui_hash), }, { "vnode cache hash", - X_NCVCACHEHASH, X_NCVCACHETBL, + X_VCACHEHASH, X_VCACHETBL, HASH_SLIST, offsetof(struct vnode_impl, vi_hash), }, { NULL, -1, -1, 0, 0,
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: simonb Date: Sat Jan 25 05:43:32 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Fix alignment of Flags column for vmstat -mW. To generate a diff of this commit: cvs rdiff -u -r1.235 -r1.236 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.235 src/usr.bin/vmstat/vmstat.c:1.236 --- src/usr.bin/vmstat/vmstat.c:1.235 Wed Jan 15 17:56:46 2020 +++ src/usr.bin/vmstat/vmstat.c Sat Jan 25 05:43:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.235 2020/01/15 17:56:46 ad Exp $ */ +/* $NetBSD: vmstat.c,v 1.236 2020/01/25 05:43:32 simonb Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 @@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.235 2020/01/15 17:56:46 ad Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.236 2020/01/25 05:43:32 simonb Exp $"); #endif #endif /* not lint */ @@ -1492,7 +1492,7 @@ dopool_sysctl(int verbose, int wide) "Minpg", wide ? 7 : 6, "Maxpg", "Idle", - wide ? " Flags" : "", + wide ? " Flags" : "", wide ? " Util" : ""); name_len = MIN((int)sizeof(pp->pr_wchan), wide ? 16 : 11); @@ -1533,7 +1533,7 @@ dopool_sysctl(int verbose, int wide) PRWORD(ovflw, " %*s", wide ? 7 : 6, 1, maxp); PRWORD(ovflw, " %*" PRIu64, 5, 1, pp->pr_nidle); if (wide) - PRWORD(ovflw, " 0x%0*" PRIx64, 5, 1, + PRWORD(ovflw, " 0x%0*" PRIx64, 6, 1, pp->pr_flags); this_inuse = pp->pr_nout * pp->pr_size; @@ -1640,7 +1640,7 @@ dopool(int verbose, int wide) "Minpg", wide ? 7 : 6, "Maxpg", "Idle", - wide ? " Flags" : "", + wide ? " Flags" : "", wide ? " Util" : ""); first = 0; } @@ -1679,7 +1679,7 @@ dopool(int verbose, int wide) PRWORD(ovflw, " %*s", wide ? 7 : 6, 1, maxp); PRWORD(ovflw, " %*lu", 5, 1, pp->pr_nidle); if (wide) - PRWORD(ovflw, " 0x%0*x", 5, 1, + PRWORD(ovflw, " 0x%0*x", 6, 1, pp->pr_flags | pp->pr_roflags); this_inuse = pp->pr_nout * pp->pr_size;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ad Date: Wed Jan 15 17:56:46 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: vmstat -s: report new stats: 0 per-cpu stats one synced 7246 per-cpu stats all synced 4092 anon pages possibly dirty 8881 anon pages dirty 0 anon pages clean 68 file pages possibly dirty 0 file pages dirty 2367889 file pages clean To generate a diff of this commit: cvs rdiff -u -r1.234 -r1.235 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.234 src/usr.bin/vmstat/vmstat.c:1.235 --- src/usr.bin/vmstat/vmstat.c:1.234 Wed Jan 8 11:58:02 2020 +++ src/usr.bin/vmstat/vmstat.c Wed Jan 15 17:56:46 2020 @@ -1,7 +1,8 @@ -/* $NetBSD: vmstat.c,v 1.234 2020/01/08 11:58:02 ad Exp $ */ +/* $NetBSD: vmstat.c,v 1.235 2020/01/15 17:56:46 ad Exp $ */ /*- - * Copyright (c) 1998, 2000, 2001, 2007, 2019 The NetBSD Foundation, Inc. + * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 + * The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation by: @@ -70,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.234 2020/01/08 11:58:02 ad Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.235 2020/01/15 17:56:46 ad Exp $"); #endif #endif /* not lint */ @@ -1089,6 +1090,14 @@ dosum(void) (void)printf("%9" PRIu64 " pages found busy by daemon\n", uvmexp.pdbusy); (void)printf("%9" PRIu64 " total pending pageouts\n", uvmexp.pdpending); (void)printf("%9" PRIu64 " pages deactivated\n", uvmexp.pddeact); + (void)printf("%9" PRIu64 " per-cpu stats one synced\n", uvmexp.countsyncone); + (void)printf("%9" PRIu64 " per-cpu stats all synced\n", uvmexp.countsyncall); + (void)printf("%9" PRIu64 " anon pages possibly dirty\n", uvmexp.anonunknown); + (void)printf("%9" PRIu64 " anon pages dirty\n", uvmexp.anondirty); + (void)printf("%9" PRIu64 " anon pages clean\n", uvmexp.anonclean); + (void)printf("%9" PRIu64 " file pages possibly dirty\n", uvmexp.fileunknown); + (void)printf("%9" PRIu64 " file pages dirty\n", uvmexp.filedirty); + (void)printf("%9" PRIu64 " file pages clean\n", uvmexp.fileclean); if (active_kernel) { ssize = sizeof(nch_stats);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ad Date: Wed Jan 8 11:58:02 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Show reverse misses too. To generate a diff of this commit: cvs rdiff -u -r1.233 -r1.234 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.233 src/usr.bin/vmstat/vmstat.c:1.234 --- src/usr.bin/vmstat/vmstat.c:1.233 Mon Jan 6 11:24:30 2020 +++ src/usr.bin/vmstat/vmstat.c Wed Jan 8 11:58:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.233 2020/01/06 11:24:30 ad Exp $ */ +/* $NetBSD: vmstat.c,v 1.234 2020/01/08 11:58:02 ad Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.233 2020/01/06 11:24:30 ad Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.234 2020/01/08 11:58:02 ad Exp $"); #endif #endif /* not lint */ @@ -1114,6 +1114,7 @@ dosum(void) (void)printf("%9" PRIu64 " pass2 hits\n", nch_stats.ncs_pass2); (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes); (void)printf("%9" PRIu64 " reverse hits\n", nch_stats.ncs_revhits); + (void)printf("%9" PRIu64 " reverse miss\n", nch_stats.ncs_revmiss); (void)printf( "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n", "", PCT(nch_stats.ncs_goodhits, nchtotal),
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ad Date: Mon Jan 6 11:24:30 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: - Report namecache reverse hits with vmstat -s. - ncvhashtbl is no more. To generate a diff of this commit: cvs rdiff -u -r1.232 -r1.233 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.232 src/usr.bin/vmstat/vmstat.c:1.233 --- src/usr.bin/vmstat/vmstat.c:1.232 Sat Jan 4 03:09:55 2020 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 6 11:24:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.232 2020/01/04 03:09:55 mrg Exp $ */ +/* $NetBSD: vmstat.c,v 1.233 2020/01/06 11:24:30 ad Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.232 2020/01/04 03:09:55 mrg Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.233 2020/01/06 11:24:30 ad Exp $"); #endif #endif /* not lint */ @@ -230,15 +230,11 @@ struct nlist hashnl[] = { .n_name = "_nchash" }, #define X_NCHASHTBL 11 { .n_name = "_nchashtbl" }, -#define X_NCVHASH 12 - { .n_name = "_ncvhash" }, -#define X_NCVHASHTBL 13 - { .n_name = "_ncvhashtbl" }, -#define X_NCVCACHEHASH 14 +#define X_NCVCACHEHASH 12 { .n_name = "_vcache_hashmask" }, -#define X_NCVCACHETBL 15 +#define X_NCVCACHETBL 13 { .n_name = "_vcache_hashtab" }, -#define X_HASHNL_SIZE 16 /* must be last */ +#define X_HASHNL_SIZE 14 /* must be last */ { .n_name = NULL }, }; @@ -1117,6 +1113,7 @@ dosum(void) (void)printf("%9" PRIu64 " too long\n", nch_stats.ncs_long); (void)printf("%9" PRIu64 " pass2 hits\n", nch_stats.ncs_pass2); (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes); + (void)printf("%9" PRIu64 " reverse hits\n", nch_stats.ncs_revhits); (void)printf( "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n", "", PCT(nch_stats.ncs_goodhits, nchtotal), @@ -1895,10 +1892,6 @@ struct kernel_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), - }, { "user info (uid -> used processes) hash", X_UIHASH, X_UIHASHTBL, HASH_LIST, offsetof(struct uidinfo, ui_hash),
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mrg Date: Sat Jan 4 03:09:55 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: move the time nlist fetches into their own namelist and only fetch them when necessary. allow for fallback uses of older time sources if others are not present. this stops vmstat from exiting if it can't get the addresses of these time values it often doesn't need (eg, running kernels use the sysctl method), which has cropped up recently wit the removal of boottime variable. a slighly modified version of this patch (modified to handle the old boottime variable over the new one) works against a netbsd-9 vmstat in -current too. XXX: pullup To generate a diff of this commit: cvs rdiff -u -r1.231 -r1.232 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.231 src/usr.bin/vmstat/vmstat.c:1.232 --- src/usr.bin/vmstat/vmstat.c:1.231 Fri Jan 3 19:13:54 2020 +++ src/usr.bin/vmstat/vmstat.c Sat Jan 4 03:09:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.231 2020/01/03 19:13:54 thorpej Exp $ */ +/* $NetBSD: vmstat.c,v 1.232 2020/01/04 03:09:55 mrg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.231 2020/01/03 19:13:54 thorpej Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.232 2020/01/04 03:09:55 mrg Exp $"); #endif #endif /* not lint */ @@ -150,27 +150,36 @@ struct cpu_info { */ struct nlist namelist[] = { -#define X_TIMEBASEBIN 0 - { .n_name = "_timebasebin" }, -#define X_HZ 1 +#define X_HZ 0 { .n_name = "_hz" }, -#define X_STATHZ 2 +#define X_STATHZ 1 { .n_name = "_stathz" }, -#define X_NCHSTATS 3 +#define X_NCHSTATS 2 { .n_name = "_nchstats" }, -#define X_ALLEVENTS 4 +#define X_ALLEVENTS 3 { .n_name = "_allevents" }, -#define X_POOLHEAD 5 +#define X_POOLHEAD 4 { .n_name = "_pool_head" }, -#define X_UVMEXP 6 +#define X_UVMEXP 5 { .n_name = "_uvmexp" }, -#define X_TIME_SECOND 7 +#define X_CPU_INFOS 6 + { .n_name = "_cpu_infos" }, +#define X_NL_SIZE 7 + { .n_name = NULL }, +}; + +/* + * Namelist for time data. + */ +struct nlist timenl[] = +{ +#define X_TIMEBASEBIN 0 + { .n_name = "_timebasebin" }, +#define X_TIME_SECOND 1 { .n_name = "_time_second" }, -#define X_TIME 8 +#define X_TIME 2 { .n_name = "_time" }, -#define X_CPU_INFOS 9 - { .n_name = "_cpu_infos" }, -#define X_NL_SIZE 10 +#define X_TIMENL_SIZE 3 { .n_name = NULL }, }; @@ -559,9 +568,7 @@ getnlist(int todo) errx(1, "kvm_nlist: %s %s", "namelist", kvm_geterr(kd)); for (i = 0; i < __arraycount(namelist)-1; i++) -if (namelist[i].n_type == 0 && -i != X_TIME_SECOND && -i != X_TIME) { +if (namelist[i].n_type == 0) { if (doexit++ == 0) (void)fprintf(stderr, "%s: undefined symbols:", @@ -575,6 +582,11 @@ getnlist(int todo) } } } + if ((todo & (VMSTAT|INTRSTAT)) && !(done & (VMSTAT))) { + done |= VMSTAT; + if ((c = kvm_nlist(kd, timenl)) == -1 || c == X_TIMENL_SIZE) + errx(1, "kvm_nlist: %s %s", "timenl", kvm_geterr(kd)); + } if ((todo & (SUMSTAT|INTRSTAT)) && !(done & (SUMSTAT|INTRSTAT))) { done |= SUMSTAT|INTRSTAT; (void) kvm_nlist(kd, intrnl); @@ -645,11 +657,10 @@ getuptime(void) if (boottime.tv_sec == 0) { struct bintime bt; - kread(namelist, X_TIMEBASEBIN, , - sizeof(bt)); + kread(timenl, X_TIMEBASEBIN, , sizeof(bt)); bintime2timespec(, ); } - if (kreadc(namelist, X_TIME_SECOND, , sizeof(nowsec))) { + if (kreadc(timenl, X_TIME_SECOND, , sizeof(nowsec))) { /* * XXX this assignment dance can be removed once * timeval tv_sec is SUS mandated time_t @@ -657,7 +668,7 @@ getuptime(void) now.tv_sec = nowsec; now.tv_nsec = 0; } else { - kread(namelist, X_TIME, , sizeof(now)); + kread(timenl, X_TIME, , sizeof(now)); } } uptime = now.tv_sec - boottime.tv_sec;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: thorpej Date: Fri Jan 3 19:13:54 UTC 2020 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: boottime in the kernel is no more. Instead, read timebasebin and convert from bintime to timespec. To generate a diff of this commit: cvs rdiff -u -r1.230 -r1.231 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.230 src/usr.bin/vmstat/vmstat.c:1.231 --- src/usr.bin/vmstat/vmstat.c:1.230 Fri Dec 27 09:45:27 2019 +++ src/usr.bin/vmstat/vmstat.c Fri Jan 3 19:13:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.230 2019/12/27 09:45:27 msaitoh Exp $ */ +/* $NetBSD: vmstat.c,v 1.231 2020/01/03 19:13:54 thorpej Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007, 2019 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.230 2019/12/27 09:45:27 msaitoh Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.231 2020/01/03 19:13:54 thorpej Exp $"); #endif #endif /* not lint */ @@ -150,8 +150,8 @@ struct cpu_info { */ struct nlist namelist[] = { -#define X_BOOTTIME 0 - { .n_name = "_boottime" }, +#define X_TIMEBASEBIN 0 + { .n_name = "_timebasebin" }, #define X_HZ 1 { .n_name = "_hz" }, #define X_STATHZ 2 @@ -642,9 +642,13 @@ getuptime(void) } clock_gettime(CLOCK_REALTIME, ); } else { - if (boottime.tv_sec == 0) - kread(namelist, X_BOOTTIME, , - sizeof(boottime)); + if (boottime.tv_sec == 0) { + struct bintime bt; + + kread(namelist, X_TIMEBASEBIN, , + sizeof(bt)); + bintime2timespec(, ); + } if (kreadc(namelist, X_TIME_SECOND, , sizeof(nowsec))) { /* * XXX this assignment dance can be removed once
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ad Date: Sun Dec 22 17:27:54 UTC 2019 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Have vmstat -H report on vcache_hashtab. To generate a diff of this commit: cvs rdiff -u -r1.228 -r1.229 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.228 src/usr.bin/vmstat/vmstat.c:1.229 --- src/usr.bin/vmstat/vmstat.c:1.228 Fri Sep 13 13:56:05 2019 +++ src/usr.bin/vmstat/vmstat.c Sun Dec 22 17:27:53 2019 @@ -1,7 +1,7 @@ -/* $NetBSD: vmstat.c,v 1.228 2019/09/13 13:56:05 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.229 2019/12/22 17:27:53 ad Exp $ */ /*- - * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. + * Copyright (c) 1998, 2000, 2001, 2007, 2019 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation by: @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.228 2019/09/13 13:56:05 christos Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.229 2019/12/22 17:27:53 ad Exp $"); #endif #endif /* not lint */ @@ -96,6 +96,8 @@ __RCSID("$NetBSD: vmstat.c,v 1.228 2019/ #include #include #include +#include +#include #include #include @@ -223,7 +225,11 @@ struct nlist hashnl[] = { .n_name = "_ncvhash" }, #define X_NCVHASHTBL 13 { .n_name = "_ncvhashtbl" }, -#define X_HASHNL_SIZE 14 /* must be last */ +#define X_NCVCACHEHASH 14 + { .n_name = "_vcache_hashmask" }, +#define X_NCVCACHETBL 15 + { .n_name = "_vcache_hashtab" }, +#define X_HASHNL_SIZE 16 /* must be last */ { .n_name = NULL }, }; @@ -1842,7 +1848,9 @@ dopoolcache(int verbose) enum hashtype { /* from */ HASH_LIST, - HASH_TAILQ + HASH_SLIST, + HASH_TAILQ, + HASH_PSLIST }; struct uidinfo { /* XXX: no kernel header file */ @@ -1880,6 +1888,10 @@ struct kernel_hash { X_UIHASH, X_UIHASHTBL, HASH_LIST, offsetof(struct uidinfo, ui_hash), }, { + "vnode cache hash", + X_NCVCACHEHASH, X_NCVCACHETBL, + HASH_SLIST, offsetof(struct vnode_impl, vi_hash), + }, { NULL, -1, -1, 0, 0, } }; @@ -1888,6 +1900,7 @@ void dohashstat(int verbose, int todo, const char *hashname) { LIST_HEAD(, generic) *hashtbl_list; + SLIST_HEAD(, generic) *hashtbl_slist; TAILQ_HEAD(, generic) *hashtbl_tailq; struct kernel_hash *curhash; void *hashaddr, *hashbuf, *nhashbuf, *nextaddr; @@ -1969,14 +1982,22 @@ dohashstat(int verbose, int todo, const items = maxchain = 0; if (curhash->type == HASH_LIST) { hashtbl_list = hashbuf; + hashtbl_slist = NULL; + hashtbl_tailq = NULL; + } else if (curhash->type == HASH_SLIST) { + hashtbl_list = NULL; + hashtbl_slist = hashbuf; hashtbl_tailq = NULL; } else { hashtbl_list = NULL; + hashtbl_slist = NULL; hashtbl_tailq = hashbuf; } for (i = 0; i < hashsize; i++) { if (curhash->type == HASH_LIST) nextaddr = LIST_FIRST(_list[i]); + else if (curhash->type == HASH_SLIST) +nextaddr = SLIST_FIRST(_slist[i]); else nextaddr = TAILQ_FIRST(_tailq[i]); if (nextaddr == NULL)
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mrg Date: Thu May 9 08:01:07 UTC 2019 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: when dumping a kernhist history replace "%s" with "%p" so that the kernhist in kernel can be a little more usable without making the userland dumping code crash. To generate a diff of this commit: cvs rdiff -u -r1.226 -r1.227 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.226 src/usr.bin/vmstat/vmstat.c:1.227 --- src/usr.bin/vmstat/vmstat.c:1.226 Tue Apr 30 23:29:18 2019 +++ src/usr.bin/vmstat/vmstat.c Thu May 9 08:01:07 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.226 2019/04/30 23:29:18 simonb Exp $ */ +/* $NetBSD: vmstat.c,v 1.227 2019/05/09 08:01:07 mrg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.226 2019/04/30 23:29:18 simonb Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.227 2019/05/09 08:01:07 mrg Exp $"); #endif #endif /* not lint */ @@ -2148,15 +2148,13 @@ hist_dodump(struct kern_history *histp) e = [i]; if (e->fmt != NULL) { if (fmt == NULL || e->fmtlen > fmtlen) { -if (fmt != NULL) - free(fmt); +free(fmt); fmtlen = e->fmtlen; if ((fmt = malloc(fmtlen + 1)) == NULL) err(1, "malloc printf format"); } if (fn == NULL || e->fnlen > fnlen) { -if (fn != NULL) - free(fn); +free(fn); fnlen = e->fnlen; if ((fn = malloc(fnlen + 1)) == NULL) err(1, "malloc function name"); @@ -2164,6 +2162,10 @@ hist_dodump(struct kern_history *histp) deref_kptr(e->fmt, fmt, fmtlen, "printf format"); fmt[fmtlen] = '\0'; + for (unsigned z = 0; z < fmtlen - 1; z++) { +if (fmt[z] == '%' && fmt[z+1] == 's') + fmt[z+1] = 'p'; + } deref_kptr(e->fn, fn, fnlen, "function name"); fn[fnlen] = '\0'; @@ -2180,10 +2182,8 @@ hist_dodump(struct kern_history *histp) } while (i != histp->f); free(histents); - if (fmt != NULL) - free(fmt); - if (fn != NULL) - free(fn); + free(fmt); + free(fn); } void @@ -2293,6 +2293,11 @@ hist_dodump_sysctl(int mib[], unsigned i e = >sh_events[i]; if (e->she_fmtoffset != 0) { fmt = [e->she_fmtoffset]; + size_t fmtlen = strlen(fmt); + for (unsigned z = 0; z < fmtlen - 1; z++) { +if (fmt[z] == '%' && fmt[z+1] == 's') + fmt[z+1] = 'p'; + } fn = [e->she_funcoffset]; bintime2timeval(>she_bintime, ); (void)printf("%06ld.%06ld %s#%"PRIu32"@%"PRIu32": ",
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: simonb Date: Tue Apr 30 23:29:18 UTC 2019 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use PRWORD for printing -m/-mW totals so fields don't run in to each other. While here, update field widths for 'vmstat -mW' for modern machines. To generate a diff of this commit: cvs rdiff -u -r1.225 -r1.226 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.225 src/usr.bin/vmstat/vmstat.c:1.226 --- src/usr.bin/vmstat/vmstat.c:1.225 Thu Dec 13 01:58:04 2018 +++ src/usr.bin/vmstat/vmstat.c Tue Apr 30 23:29:18 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.225 2018/12/13 01:58:04 sevan Exp $ */ +/* $NetBSD: vmstat.c,v 1.226 2019/04/30 23:29:18 simonb Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.225 2018/12/13 01:58:04 sevan Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.226 2019/04/30 23:29:18 simonb Exp $"); #endif #endif /* not lint */ @@ -1435,7 +1435,7 @@ dopool_sysctl(int verbose, int wide) size_t i, len; int name_len, ovflw; struct pool_sysctl *pp, *data; - char in_use[8], avail[8], maxp[32]; + char maxp[32]; data = asysctlbyname("kern.pool", ); if (data == NULL) @@ -1447,23 +1447,23 @@ dopool_sysctl(int verbose, int wide) (void)printf("Memory resource pool statistics\n"); (void)printf( - "%-*s%*s%*s%5s%*s%s%s%*s%*s%6s%s%6s%6s%6s%5s%s%s\n", + "%-*s%*s%*s%*s%*s%s%s%*s%*s%*s%s%*s%6s%*s%5s%s%s\n", wide ? 16 : 11, "Name", - wide ? 6 : 5, "Size", + wide ? 7 : 5, "Size", wide ? 12 : 9, "Requests", - "Fail", + wide ? 8 : 5, "Fail", wide ? 12 : 9, "Releases", - wide ? " InUse" : "", - wide ? " Avail" : "", - wide ? 7 : 6, "Pgreq", - wide ? 7 : 6, "Pgrel", - "Npage", + wide ? "InUse" : "", + wide ? "Avail" : "", + wide ? 11 : 6, "Pgreq", + wide ? 11 : 6, "Pgrel", + wide ? 8 : 6, "Npage", wide ? " PageSz" : "", - "Hiwat", + wide ? 7 : 6, "Hiwat", "Minpg", - "Maxpg", + wide ? 7 : 6, "Maxpg", "Idle", - wide ? " Flags" : "", + wide ? " Flags" : "", wide ? " Util" : ""); name_len = MIN((int)sizeof(pp->pr_wchan), wide ? 16 : 11); @@ -1478,35 +1478,33 @@ dopool_sysctl(int verbose, int wide) pp->pr_maxpages); ovflw = 0; PRWORD(ovflw, "%-*s", name_len, 0, pp->pr_wchan); - PRWORD(ovflw, " %*" PRIu64, wide ? 6 : 5, 1, pp->pr_size); + PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 5, 1, pp->pr_size); PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pp->pr_nget); pool_totals.pt_nget += pp->pr_nget; - PRWORD(ovflw, " %*" PRIu64, 5, 1, pp->pr_nfail); + PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 5, 1, pp->pr_nfail); pool_totals.pt_nfail += pp->pr_nfail; PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pp->pr_nput); pool_totals.pt_nput += pp->pr_nput; if (wide) { - PRWORD(ovflw, " %*" PRIu64, 7, 1, pp->pr_nout); + PRWORD(ovflw, " %*" PRIu64, 9, 1, pp->pr_nout); pool_totals.pt_nout += pp->pr_nout; - } - if (wide) { - PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_nitems); + PRWORD(ovflw, " %*" PRIu64, 9, 1, pp->pr_nitems); pool_totals.pt_nitems += pp->pr_nitems; } - PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 6, 1, pp->pr_npagealloc); + PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pp->pr_npagealloc); pool_totals.pt_npagealloc += pp->pr_npagealloc; - PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 6, 1, pp->pr_npagefree); + PRWORD(ovflw, " %*" PRIu64, wide ? 11 : 6, 1, pp->pr_npagefree); pool_totals.pt_npagefree += pp->pr_npagefree; - PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_npages); + PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 6, 1, pp->pr_npages); pool_totals.pt_npages += pp->pr_npages; if (wide) PRWORD(ovflw, " %*" PRIu64, 7, 1, pp->pr_pagesize); - PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_hiwat); + PRWORD(ovflw, " %*" PRIu64, wide ? 7 : 6, 1, pp->pr_hiwat); PRWORD(ovflw, " %*" PRIu64, 6, 1, pp->pr_minpages); - PRWORD(ovflw, " %*s", 6, 1, maxp); + PRWORD(ovflw, " %*s", wide ? 7 : 6, 1, maxp); PRWORD(ovflw, " %*" PRIu64, 5, 1, pp->pr_nidle); if (wide) - PRWORD(ovflw, " 0x%0*" PRIx64, 4, 1, + PRWORD(ovflw, " 0x%0*" PRIx64, 5, 1, pp->pr_flags); this_inuse = pp->pr_nout * pp->pr_size; @@ -1531,25 +1529,20 @@ dopool_sysctl(int verbose, int wide) } (void)printf("\n"); } + ovflw = 0; + PRWORD(ovflw, "%-*s", name_len, 0, "Totals"); + PRWORD(ovflw, " %*s", wide ? 7 : 5, 1, ""); + PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1, pool_totals.pt_nget); + PRWORD(ovflw, " %*" PRIu64, wide ? 8 : 5, 1, pool_totals.pt_nfail); + PRWORD(ovflw, " %*" PRIu64, wide ? 12 : 9, 1,
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: sevan Date: Tue Dec 25 03:38:59 UTC 2018 Modified Files: src/usr.bin/vmstat: vmstat.1 Log Message: Remove reference to Installing and Operating 4.3BSD paper, at present it's not possible to find a paper titled as such with sections starting with "Interpreting system activity". There is a "Monitoring System Performance" section present from the 4.1BSD Installing and Operating paper up to and including the 4.4BSD paper. The advice in this section has not aged very well. >From "Installing and Operating 4.3BSD-tahoe UNIX on the VAX": "Cumulatively on one of our large machines we average about 60-100 context switches and interrupts per second and about 70-120 system calls per second" To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/vmstat/vmstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.1 diff -u src/usr.bin/vmstat/vmstat.1:1.23 src/usr.bin/vmstat/vmstat.1:1.24 --- src/usr.bin/vmstat/vmstat.1:1.23 Thu Dec 13 01:29:10 2018 +++ src/usr.bin/vmstat/vmstat.1 Tue Dec 25 03:38:59 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: vmstat.1,v 1.23 2018/12/13 01:29:10 sevan Exp $ +.\" $NetBSD: vmstat.1,v 1.24 2018/12/25 03:38:59 sevan Exp $ .\" .\" Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -53,7 +53,7 @@ .\" .\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93 .\" -.Dd December 13, 2018 +.Dd December 25, 2018 .Dt VMSTAT 1 .Os .Sh NAME @@ -300,11 +300,6 @@ apparent which are recomputed every seco .Xr iostat 8 , .Xr pstat 8 , .Xr kernhist 9 -.Pp -The sections starting with -.Dq Interpreting system activity -in -.%T Installing and Operating 4.3BSD . .Sh BUGS The .Fl c
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: sevan Date: Thu Dec 13 01:58:04 UTC 2018 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: typo To generate a diff of this commit: cvs rdiff -u -r1.224 -r1.225 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.224 src/usr.bin/vmstat/vmstat.c:1.225 --- src/usr.bin/vmstat/vmstat.c:1.224 Mon Dec 4 03:05:57 2017 +++ src/usr.bin/vmstat/vmstat.c Thu Dec 13 01:58:04 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.224 2017/12/04 03:05:57 mrg Exp $ */ +/* $NetBSD: vmstat.c,v 1.225 2018/12/13 01:58:04 sevan Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.224 2017/12/04 03:05:57 mrg Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.225 2018/12/13 01:58:04 sevan Exp $"); #endif #endif /* not lint */ @@ -1439,7 +1439,7 @@ dopool_sysctl(int verbose, int wide) data = asysctlbyname("kern.pool", ); if (data == NULL) - err(1, "failed to reead kern.pool"); + err(1, "failed to read kern.pool"); memset(_totals, 0, sizeof pool_totals); total = inuse = 0; @@ -1725,7 +1725,7 @@ dopoolcache_sysctl(int verbose) data = asysctlbyname("kern.pool", ); if (data == NULL) - err(1, "failed to reead kern.pool"); + err(1, "failed to read kern.pool"); len /= sizeof(*data); for (i = 0; i < len; ++i) {
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: sevan Date: Thu Dec 13 01:29:11 UTC 2018 Modified Files: src/usr.bin/vmstat: vmstat.1 Log Message: Describe what happens when you run vmstat witout any options aka the first line of vmstat. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/vmstat/vmstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.1 diff -u src/usr.bin/vmstat/vmstat.1:1.22 src/usr.bin/vmstat/vmstat.1:1.23 --- src/usr.bin/vmstat/vmstat.1:1.22 Wed Dec 5 23:42:23 2018 +++ src/usr.bin/vmstat/vmstat.1 Thu Dec 13 01:29:10 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: vmstat.1,v 1.22 2018/12/05 23:42:23 sevan Exp $ +.\" $NetBSD: vmstat.1,v 1.23 2018/12/13 01:29:10 sevan Exp $ .\" .\" Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -53,7 +53,7 @@ .\" .\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93 .\" -.Dd December 5, 2018 +.Dd December 13, 2018 .Dt VMSTAT 1 .Os .Sh NAME @@ -73,6 +73,12 @@ .Nm reports certain kernel statistics kept about process, virtual memory, disk, trap, and CPU activity. +If +.Nm +is invoked without any options, it displays the summary of statistics since +boot and exits. +This is also referred to as the first line of +.Nm . .Pp The options are as follows: .Bl -tag -width xxxhistname
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: sevan Date: Wed Dec 5 23:42:23 UTC 2018 Modified Files: src/usr.bin/vmstat: vmstat.1 Log Message: Document vmstat -w -1 is accepted. via FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/vmstat/vmstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.1 diff -u src/usr.bin/vmstat/vmstat.1:1.21 src/usr.bin/vmstat/vmstat.1:1.22 --- src/usr.bin/vmstat/vmstat.1:1.21 Wed Dec 5 10:35:14 2018 +++ src/usr.bin/vmstat/vmstat.1 Wed Dec 5 23:42:23 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: vmstat.1,v 1.21 2018/12/05 10:35:14 sevan Exp $ +.\" $NetBSD: vmstat.1,v 1.22 2018/12/05 23:42:23 sevan Exp $ .\" .\" Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -186,6 +186,11 @@ seconds between each display. If no repeat .Ar count is specified, the default is infinity. +The +.Nm +command will accept and honor a negative number of +.Ar wait +seconds. .El .Pp By default,
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: sevan Date: Wed Dec 5 10:35:14 UTC 2018 Modified Files: src/usr.bin/vmstat: vmstat.1 Log Message: Suggest kernhist(9) which is required for vmstat -u and -U Drop Pp before Bl while here. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/vmstat/vmstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.1 diff -u src/usr.bin/vmstat/vmstat.1:1.20 src/usr.bin/vmstat/vmstat.1:1.21 --- src/usr.bin/vmstat/vmstat.1:1.20 Wed Oct 21 22:18:37 2009 +++ src/usr.bin/vmstat/vmstat.1 Wed Dec 5 10:35:14 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: vmstat.1,v 1.20 2009/10/21 22:18:37 wiz Exp $ +.\" $NetBSD: vmstat.1,v 1.21 2018/12/05 10:35:14 sevan Exp $ .\" .\" Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -53,7 +53,7 @@ .\" .\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93 .\" -.Dd October 22, 2009 +.Dd December 5, 2018 .Dt VMSTAT 1 .Os .Sh NAME @@ -191,7 +191,6 @@ is specified, the default is infinity. By default, .Nm displays the following information: -.Pp .Bl -tag -width memory .It procs Information about the numbers of processes in various states. @@ -288,7 +287,8 @@ apparent which are recomputed every seco .Xr ps 1 , .Xr systat 1 , .Xr iostat 8 , -.Xr pstat 8 +.Xr pstat 8 , +.Xr kernhist 9 .Pp The sections starting with .Dq Interpreting system activity
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mrg Date: Mon Dec 4 03:05:57 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: deref the right address to get the pool_allocator. To generate a diff of this commit: cvs rdiff -u -r1.223 -r1.224 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.223 src/usr.bin/vmstat/vmstat.c:1.224 --- src/usr.bin/vmstat/vmstat.c:1.223 Sun Dec 3 21:10:01 2017 +++ src/usr.bin/vmstat/vmstat.c Mon Dec 4 03:05:57 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.223 2017/12/03 21:10:01 mrg Exp $ */ +/* $NetBSD: vmstat.c,v 1.224 2017/12/04 03:05:57 mrg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.223 2017/12/03 21:10:01 mrg Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.224 2017/12/04 03:05:57 mrg Exp $"); #endif #endif /* not lint */ @@ -968,8 +968,8 @@ dosum(void) uvmexp.poolpages = 0; for (; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist)) { deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed"); - deref_kptr(addr, , sizeof(pa), - "pool_allocator trashed"); + deref_kptr(pp->pr_alloc, , sizeof(pa), + "pool allocator trashed"); bytes = pp->pr_npages * pa.pa_pagesz; if ((pp->pr_roflags & PR_RECURSIVE) != 0) bytes -= (pp->pr_nout * pp->pr_size);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mrg Date: Sun Dec 3 21:10:01 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: remove now wrong comment. minor KNF. To generate a diff of this commit: cvs rdiff -u -r1.222 -r1.223 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.222 src/usr.bin/vmstat/vmstat.c:1.223 --- src/usr.bin/vmstat/vmstat.c:1.222 Sun Dec 3 21:09:01 2017 +++ src/usr.bin/vmstat/vmstat.c Sun Dec 3 21:10:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.222 2017/12/03 21:09:01 mrg Exp $ */ +/* $NetBSD: vmstat.c,v 1.223 2017/12/03 21:10:01 mrg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.222 2017/12/03 21:09:01 mrg Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.223 2017/12/03 21:10:01 mrg Exp $"); #endif #endif /* not lint */ @@ -968,8 +968,8 @@ dosum(void) uvmexp.poolpages = 0; for (; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist)) { deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed"); - deref_kptr(addr, , sizeof(pa), "pool_allocator trashed"); - // XXX deref pr_alloc first + deref_kptr(addr, , sizeof(pa), + "pool_allocator trashed"); bytes = pp->pr_npages * pa.pa_pagesz; if ((pp->pr_roflags & PR_RECURSIVE) != 0) bytes -= (pp->pr_nout * pp->pr_size);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mrg Date: Sun Dec 3 21:09:01 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: fix the kvm version of counting pool pages for vmstat -s. To generate a diff of this commit: cvs rdiff -u -r1.221 -r1.222 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.221 src/usr.bin/vmstat/vmstat.c:1.222 --- src/usr.bin/vmstat/vmstat.c:1.221 Sat Dec 2 08:15:43 2017 +++ src/usr.bin/vmstat/vmstat.c Sun Dec 3 21:09:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.221 2017/12/02 08:15:43 mrg Exp $ */ +/* $NetBSD: vmstat.c,v 1.222 2017/12/03 21:09:01 mrg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.221 2017/12/02 08:15:43 mrg Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.222 2017/12/03 21:09:01 mrg Exp $"); #endif #endif /* not lint */ @@ -893,8 +893,10 @@ dosum(void) } else { struct uvmexp uvmexp_kernel; struct pool pool, *pp = + struct pool_allocator pa; TAILQ_HEAD(,pool) pool_head; void *addr; + uint64_t bytes; kread(namelist, X_UVMEXP, _kernel, sizeof(uvmexp_kernel)); #define COPY(field) uvmexp.field = uvmexp_kernel.field @@ -963,13 +965,15 @@ dosum(void) #undef COPY kread(namelist, X_POOLHEAD, _head, sizeof(pool_head)); addr = TAILQ_FIRST(_head); + uvmexp.poolpages = 0; for (; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist)) { deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed"); - /* - * XXXMRG - if ((pp->pr_roflags & PR_RECURSIVE) == 0) - */ -uvmexp.poolpages += pp->pr_npages; + deref_kptr(addr, , sizeof(pa), "pool_allocator trashed"); + // XXX deref pr_alloc first + bytes = pp->pr_npages * pa.pa_pagesz; + if ((pp->pr_roflags & PR_RECURSIVE) != 0) +bytes -= (pp->pr_nout * pp->pr_size); + uvmexp.poolpages += bytes / uvmexp.pagesize; } }
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mlelstv Date: Wed Sep 6 06:05:23 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Don't print "nan" when there is no disk activity. To generate a diff of this commit: cvs rdiff -u -r1.217 -r1.218 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.217 src/usr.bin/vmstat/vmstat.c:1.218 --- src/usr.bin/vmstat/vmstat.c:1.217 Tue Jul 4 21:19:33 2017 +++ src/usr.bin/vmstat/vmstat.c Wed Sep 6 06:05:23 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.217 2017/07/04 21:19:33 mlelstv Exp $ */ +/* $NetBSD: vmstat.c,v 1.218 2017/09/06 06:05:23 mlelstv Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.217 2017/07/04 21:19:33 mlelstv Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.218 2017/09/06 06:05:23 mlelstv Exp $"); #endif #endif /* not lint */ @@ -1123,8 +1123,11 @@ drvstats(int *ovflwp) for (dn = 0; dn < ndrive; ++dn) { /* elapsed time for disk stats */ - dtime = (double)cur.timestamp[dn].tv_sec + - ((double)cur.timestamp[dn].tv_usec / (double)100); + dtime = cur.cp_etime; + if (cur.timestamp[dn].tv_sec || cur.timestamp[dn].tv_usec) { + dtime = (double)cur.timestamp[dn].tv_sec + +((double)cur.timestamp[dn].tv_usec / (double)100); + } if (!drv_select[dn]) continue;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: ryo Date: Thu Jan 5 07:53:20 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: "vmstat -ie[v]" auto fit to minimum columns Reviewed by msaitoh@ To generate a diff of this commit: cvs rdiff -u -r1.215 -r1.216 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.215 src/usr.bin/vmstat/vmstat.c:1.216 --- src/usr.bin/vmstat/vmstat.c:1.215 Thu Jan 5 03:42:27 2017 +++ src/usr.bin/vmstat/vmstat.c Thu Jan 5 07:53:20 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.215 2017/01/05 03:42:27 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.216 2017/01/05 07:53:20 ryo Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.215 2017/01/05 03:42:27 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.216 2017/01/05 07:53:20 ryo Exp $"); #endif #endif /* not lint */ @@ -1216,10 +1216,11 @@ dointr(int verbose) inttotal = 0; uptime = getuptime(); - (void)printf("%-34s %16s %8s\n", "interrupt", "total", "rate"); nintr = intrnl[X_EINTRCNT].n_value - intrnl[X_INTRCNT].n_value; inamlen = intrnl[X_EINTRNAMES].n_value - intrnl[X_INTRNAMES].n_value; if (nintr != 0 && inamlen != 0) { + (void)printf("%-34s %16s %8s\n", "interrupt", "total", "rate"); + ointrcnt = intrcnt = malloc((size_t)nintr); ointrname = intrname = malloc((size_t)inamlen); if (intrcnt == NULL || intrname == NULL) @@ -1250,19 +1251,17 @@ doevcnt(int verbose, int type) uint64_t counttotal, uptime; struct evcntlist allevents; struct evcnt evcnt, *evptr; + size_t evlen_max, total_max, rate_max; char evgroup[EVCNT_STRING_MAX], evname[EVCNT_STRING_MAX]; counttotal = 0; uptime = getuptime(); - if (type == EVCNT_TYPE_ANY) - (void)printf("%-34s %16s %8s %s\n", "event", "total", "rate", - "type"); if (memf == NULL) do { const int mib[4] = { CTL_KERN, KERN_EVCNT, type, verbose ? KERN_EVCNT_COUNT_ANY : KERN_EVCNT_COUNT_NONZERO }; - size_t buflen = 0; - void *buf = NULL; + size_t buflen0, buflen = 0; + void *buf0, *buf = NULL; const struct evcnt_sysctl *evs, *last_evs; for (;;) { size_t newlen; @@ -1285,33 +1284,80 @@ doevcnt(int verbose, int type) free(buf); buflen = newlen; } - evs = buf; + buflen0 = buflen; + evs = buf0 = buf; + last_evs = (void *)((char *)buf + buflen); + buflen /= sizeof(uint64_t); + /* calc columns */ + evlen_max = 0; + total_max = sizeof("total") - 1; + rate_max = sizeof("rate") - 1; + while (evs < last_evs + && buflen >= sizeof(*evs)/sizeof(uint64_t) + && buflen >= evs->ev_len) { + char cbuf[64]; + size_t len; + len = strlen(evs->ev_strings + evs->ev_grouplen + 1); + len += evs->ev_grouplen + 1; + if (evlen_max < len) +evlen_max= len; + len = snprintf(cbuf, sizeof(cbuf), "%"PRIu64, + evs->ev_count); + if (total_max < len) +total_max = len; + len = snprintf(cbuf, sizeof(cbuf), "%"PRIu64, + evs->ev_count / uptime); + if (rate_max < len) +rate_max = len; + buflen -= evs->ev_len; + evs = (const void *) + ((const uint64_t *)evs + evs->ev_len); + } + + (void)printf(type == EVCNT_TYPE_ANY ? + "%-*s %*s %*s %s\n" : + "%-*s %*s %*s\n", + (int)evlen_max, "interrupt", + (int)total_max, "total", + (int)rate_max, "rate", + "type"); + + buflen = buflen0; + evs = buf0; last_evs = (void *)((char *)buf + buflen); buflen /= sizeof(uint64_t); while (evs < last_evs && buflen >= sizeof(*evs)/sizeof(uint64_t) && buflen >= evs->ev_len) { (void)printf(type == EVCNT_TYPE_ANY ? - "%s %s%*s %16"PRIu64" %8"PRIu64" %s\n" : - "%s %s%*s %16"PRIu64" %8"PRIu64"\n", + "%s %s%*s %*"PRIu64" %*"PRIu64" %s\n" : + "%s %s%*s %*"PRIu64" %*"PRIu64"\n", evs->ev_strings, evs->ev_strings + evs->ev_grouplen + 1, - 34 - (evs->ev_grouplen + 1 + evs->ev_namelen), "", - evs->ev_count, - evs->ev_count / uptime, + (int)evlen_max - (evs->ev_grouplen + 1 + + evs->ev_namelen), "", + (int)total_max, evs->ev_count, + (int)rate_max, evs->ev_count / uptime, (evs->ev_type < __arraycount(evtypes) ? -evtypes[evs->ev_type] : "?")); + evtypes[evs->ev_type] : "?")); buflen -= evs->ev_len; counttotal += evs->ev_count; - evs = (const void *)((const uint64_t *)evs + evs->ev_len); + evs = (const void *) + ((const uint64_t *)evs + evs->ev_len); } free(buf); if (type != EVCNT_TYPE_ANY) - (void)printf("%-34s %16"PRIu64" %8"PRIu64"\n", - "Total", counttotal, counttotal / uptime); + (void)printf("%-*s %*"PRIu64" %*"PRIu64"\n", +
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Thu Jan 5 03:42:27 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Adapt to use of bintime(9) for kernel history timestamps (7.99.55). To generate a diff of this commit: cvs rdiff -u -r1.214 -r1.215 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.214 src/usr.bin/vmstat/vmstat.c:1.215 --- src/usr.bin/vmstat/vmstat.c:1.214 Wed Jan 4 01:29:18 2017 +++ src/usr.bin/vmstat/vmstat.c Thu Jan 5 03:42:27 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.214 2017/01/04 01:29:18 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.215 2017/01/05 03:42:27 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.214 2017/01/04 01:29:18 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.215 2017/01/05 03:42:27 pgoyette Exp $"); #endif #endif /* not lint */ @@ -2069,6 +2069,7 @@ void hist_dodump(struct kern_history *histp) { struct kern_history_ent *histents, *e; + struct timeval tv; size_t histsize; char *fmt = NULL, *fn = NULL; size_t fmtlen = 0, fnlen = 0; @@ -2110,8 +2111,9 @@ hist_dodump(struct kern_history *histp) deref_kptr(e->fn, fn, fnlen, "function name"); fn[fnlen] = '\0'; - (void)printf("%06ld.%06ld ", (long int)e->tv.tv_sec, - (long int)e->tv.tv_usec); + bintime2timeval(>bt, ); + (void)printf("%06ld.%06ld ", (long int)tv.tv_sec, + (long int)tv.tv_usec); (void)printf("%s#%ld@%d: ", fn, e->call, e->cpunum); (void)printf(fmt, e->v[0], e->v[1], e->v[2], e->v[3]); (void)putchar('\n'); @@ -2198,6 +2200,7 @@ hist_traverse_sysctl(int todo, const cha hist_dodump_sysctl(int mib[], unsigned int miblen) { struct sysctl_history *hist; + struct timeval tv; struct sysctl_history_event *e; size_t histsize; char *strp; @@ -2231,9 +2234,9 @@ hist_dodump_sysctl(int mib[], unsigned i if (e->she_fmtoffset != 0) { fmt = [e->she_fmtoffset]; fn = [e->she_funcoffset]; + bintime2timeval(>she_bintime, ); (void)printf("%06ld.%06ld %s#%"PRIu64"@%"PRIu32": ", - (long int)e->she_time_sec, - (long int)e->she_time_usec, + (long int)tv.tv_sec, (long int)tv.tv_usec, fn, e->she_callnumber, e->she_cpunum); (void)printf(fmt, e->she_values[0], e->she_values[1], e->she_values[2], e->she_values[3]);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Wed Jan 4 01:29:18 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Fix error handling confusion between error and errno To generate a diff of this commit: cvs rdiff -u -r1.213 -r1.214 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.213 src/usr.bin/vmstat/vmstat.c:1.214 --- src/usr.bin/vmstat/vmstat.c:1.213 Wed Jan 4 01:06:26 2017 +++ src/usr.bin/vmstat/vmstat.c Wed Jan 4 01:29:18 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.213 2017/01/04 01:06:26 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.214 2017/01/04 01:29:18 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.213 2017/01/04 01:06:26 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.214 2017/01/04 01:29:18 pgoyette Exp $"); #endif #endif /* not lint */ @@ -2138,13 +2138,12 @@ hist_traverse_sysctl(int todo, const cha /* retrieve names of available histories */ miblen = __arraycount(mib); error = sysctlnametomib("kern.hist", mib, ); - if (error == ENOENT) { - warnx("kernel history is not compiled into the kernel."); - return; - } if (error != 0) { - err(1, "nametomib failed"); - return; + if (errno == ENOENT) { + warnx("kernel history is not compiled into the kernel."); + return; + } else + err(EXIT_FAILURE, "nametomib failed"); } /* get the list of nodenames below kern.hist */
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Wed Jan 4 01:06:26 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Adapt to new version of the sysctl export structure To generate a diff of this commit: cvs rdiff -u -r1.212 -r1.213 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.212 src/usr.bin/vmstat/vmstat.c:1.213 --- src/usr.bin/vmstat/vmstat.c:1.212 Mon Jan 2 09:24:54 2017 +++ src/usr.bin/vmstat/vmstat.c Wed Jan 4 01:06:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.212 2017/01/02 09:24:54 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.213 2017/01/04 01:06:26 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.212 2017/01/02 09:24:54 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.213 2017/01/04 01:06:26 pgoyette Exp $"); #endif #endif /* not lint */ @@ -2232,11 +2232,10 @@ hist_dodump_sysctl(int mib[], unsigned i if (e->she_fmtoffset != 0) { fmt = [e->she_fmtoffset]; fn = [e->she_funcoffset]; - (void)printf("%06ld.%06ld ", - (long int)e->she_tspec.tv_sec, - (long int)(e->she_tspec.tv_nsec / 1000)); - (void)printf("%s#%"PRIu64"@%"PRIu32": ", fn, - e->she_callnumber, e->she_cpunum); + (void)printf("%06ld.%06ld %s#%"PRIu64"@%"PRIu32": ", + (long int)e->she_time_sec, + (long int)e->she_time_usec, + fn, e->she_callnumber, e->she_cpunum); (void)printf(fmt, e->she_values[0], e->she_values[1], e->she_values[2], e->she_values[3]); (void)putchar('\n');
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Mon Jan 2 09:24:55 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use appropriate PRI* format specifiers for fixed-bit-size numbers Should fix i386 build. To generate a diff of this commit: cvs rdiff -u -r1.211 -r1.212 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.211 src/usr.bin/vmstat/vmstat.c:1.212 --- src/usr.bin/vmstat/vmstat.c:1.211 Mon Jan 2 02:08:05 2017 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 2 09:24:54 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.211 2017/01/02 02:08:05 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.212 2017/01/02 09:24:54 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.211 2017/01/02 02:08:05 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.212 2017/01/02 09:24:54 pgoyette Exp $"); #endif #endif /* not lint */ @@ -2235,8 +2235,8 @@ hist_dodump_sysctl(int mib[], unsigned i (void)printf("%06ld.%06ld ", (long int)e->she_tspec.tv_sec, (long int)(e->she_tspec.tv_nsec / 1000)); - (void)printf("%s#%ld@%d: ", fn, e->she_callnumber, - e->she_cpunum); + (void)printf("%s#%"PRIu64"@%"PRIu32": ", fn, + e->she_callnumber, e->she_cpunum); (void)printf(fmt, e->she_values[0], e->she_values[1], e->she_values[2], e->she_values[3]); (void)putchar('\n');
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Mon Jan 2 02:08:05 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: For kvm-based kernhist code, print size of history table and "next free" pointer, same as we do for sysctl-based code. To generate a diff of this commit: cvs rdiff -u -r1.210 -r1.211 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.210 src/usr.bin/vmstat/vmstat.c:1.211 --- src/usr.bin/vmstat/vmstat.c:1.210 Mon Jan 2 01:48:56 2017 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 2 02:08:05 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.210 2017/01/02 01:48:56 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.211 2017/01/02 02:08:05 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.210 2017/01/02 01:48:56 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.211 2017/01/02 02:08:05 pgoyette Exp $"); #endif #endif /* not lint */ @@ -2081,6 +2081,9 @@ hist_dodump(struct kern_history *histp) (void)memset(histents, 0, histsize); + (void)printf("%"PRIu32" entries, next is %"PRIu32"\n", + histp->n, histp->f); + deref_kptr(histp->e, histents, histsize, "history entries"); i = histp->f; do {
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Mon Jan 2 01:48:56 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Restore the kvm-grovelling code for use on crash files (where sysctl(3) is not available). Otherwise, this would always report on the current running kernel regardless of the use of -M option. To generate a diff of this commit: cvs rdiff -u -r1.209 -r1.210 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.209 src/usr.bin/vmstat/vmstat.c:1.210 --- src/usr.bin/vmstat/vmstat.c:1.209 Mon Jan 2 01:02:19 2017 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 2 01:48:56 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.209 2017/01/02 01:02:19 pgoyette Exp $ */ +/* $NetBSD: vmstat.c,v 1.210 2017/01/02 01:48:56 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.209 2017/01/02 01:02:19 pgoyette Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.210 2017/01/02 01:48:56 pgoyette Exp $"); #endif #endif /* not lint */ @@ -309,7 +309,9 @@ __dead static void usage(void); void doforkst(void); void hist_traverse(int, const char *); -void hist_dodump(int[], unsigned int); +void hist_dodump(struct kern_history *); +void hist_traverse_sysctl(int, const char *); +void hist_dodump_sysctl(int[], unsigned int); char **choosedrives(char **); @@ -475,7 +477,10 @@ main(int argc, char *argv[]) (HISTLIST|HISTDUMP)) errx(1, "you may list or dump," " but not both!"); -hist_traverse(todo, histname); +if (memf != NULL) + hist_traverse(todo, histname); +else + hist_traverse_sysctl(todo, histname); (void)putchar('\n'); } if (todo & FORKSTAT) { @@ -2000,6 +2005,127 @@ deref_kptr(const void *kptr, void *ptr, void hist_traverse(int todo, const char *histname) { + struct kern_history_head histhead; + struct kern_history hist, *histkva; + char *name = NULL; + size_t namelen = 0; + + if (histnl[0].n_value == 0) { + warnx("kernel history is not compiled into the kernel."); + return; + } + + deref_kptr((void *)histnl[X_KERN_HISTORIES].n_value, , + sizeof(histhead), histnl[X_KERN_HISTORIES].n_name); + + if (histhead.lh_first == NULL) { + warnx("No active kernel history logs."); + return; + } + + if (todo & HISTLIST) + (void)printf("Active kernel histories:"); + + for (histkva = LIST_FIRST(); histkva != NULL; + histkva = LIST_NEXT(, list)) { + deref_kptr(histkva, , sizeof(hist), "histkva"); + if (name == NULL || hist.namelen > namelen) { + if (name != NULL) +free(name); + namelen = hist.namelen; + if ((name = malloc(namelen + 1)) == NULL) +err(1, "malloc history name"); + } + + deref_kptr(hist.name, name, namelen, "history name"); + name[namelen] = '\0'; + if (todo & HISTLIST) + (void)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) + (void)printf( + "\nkernel history `%s':\n", name); +hist_dodump(); + } + } + } + + if (todo & HISTLIST) + (void)putchar('\n'); + + if (name != NULL) + free(name); +} + +/* + * Actually dump the history buffer at the specified KVA. + */ +void +hist_dodump(struct kern_history *histp) +{ + struct kern_history_ent *histents, *e; + size_t histsize; + char *fmt = NULL, *fn = NULL; + size_t fmtlen = 0, fnlen = 0; + unsigned i; + + histsize = sizeof(struct kern_history_ent) * histp->n; + + if ((histents = malloc(histsize)) == NULL) + err(1, "malloc history entries"); + + (void)memset(histents, 0, histsize); + + deref_kptr(histp->e, histents, histsize, "history entries"); + i = histp->f; + do { + e = [i]; + if (e->fmt != NULL) { + if (fmt == NULL || e->fmtlen > fmtlen) { +if (fmt != NULL) + free(fmt); +fmtlen = e->fmtlen; +if ((fmt = malloc(fmtlen + 1)) == NULL) + err(1, "malloc printf format"); + } + if (fn == NULL || e->fnlen > fnlen) { +if (fn != NULL) + free(fn); +fnlen = e->fnlen; +if ((fn = malloc(fnlen + 1)) == NULL) + err(1, "malloc function name"); + } + + deref_kptr(e->fmt, fmt, fmtlen, "printf format"); + fmt[fmtlen] = '\0'; + + deref_kptr(e->fn, fn, fnlen, "function name"); + fn[fnlen] = '\0'; + + (void)printf("%06ld.%06ld ", (long int)e->tv.tv_sec, + (long int)e->tv.tv_usec); + (void)printf("%s#%ld@%d: ", fn, e->call, e->cpunum); + (void)printf(fmt, e->v[0], e->v[1], e->v[2], e->v[3]); + (void)putchar('\n'); + } + i = (i + 1) % histp->n; + } while (i != histp->f); + + free(histents); + if (fmt != NULL) +
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pgoyette Date: Mon Jan 2 01:02:19 UTC 2017 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: For kernel history display, replace the kvm grovelling with the newly available sysctl access to the history data. XXX vmstat still uses kvm for several other displays To generate a diff of this commit: cvs rdiff -u -r1.208 -r1.209 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.208 src/usr.bin/vmstat/vmstat.c:1.209 --- src/usr.bin/vmstat/vmstat.c:1.208 Tue Oct 4 17:36:21 2016 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 2 01:02:19 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.208 2016/10/04 17:36:21 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.209 2017/01/02 01:02:19 pgoyette Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.208 2016/10/04 17:36:21 christos Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.209 2017/01/02 01:02:19 pgoyette Exp $"); #endif #endif /* not lint */ @@ -309,7 +309,7 @@ __dead static void usage(void); void doforkst(void); void hist_traverse(int, const char *); -void hist_dodump(struct kern_history *); +void hist_dodump(int[], unsigned int); char **choosedrives(char **); @@ -2000,122 +2000,122 @@ deref_kptr(const void *kptr, void *ptr, void hist_traverse(int todo, const char *histname) { - struct kern_history_head histhead; - struct kern_history hist, *histkva; - char *name = NULL; - size_t namelen = 0; - - if (histnl[0].n_value == 0) { + int error; + int mib[4]; + unsigned int i; + size_t len, miblen; + struct sysctlnode query, histnode[32]; + + /* retrieve names of available histories */ + miblen = __arraycount(mib); + error = sysctlnametomib("kern.hist", mib, ); + if (error == ENOENT) { warnx("kernel history is not compiled into the kernel."); return; } + if (error != 0) { + err(1, "nametomib failed"); + return; + } - deref_kptr((void *)histnl[X_KERN_HISTORIES].n_value, , - sizeof(histhead), histnl[X_KERN_HISTORIES].n_name); - - if (histhead.lh_first == NULL) { + /* get the list of nodenames below kern.hist */ + mib[2] = CTL_QUERY; + memset(, 0, sizeof(query)); + query.sysctl_flags = SYSCTL_VERSION; + len = sizeof(histnode); + error = sysctl(mib, 3, [0], , , sizeof(query)); + if (error != 0) { + err(1, "query failed"); + return; + } + if (len == 0) { warnx("No active kernel history logs."); return; } + len = len / sizeof(histnode[0]); /* get # of entries returned */ + if (todo & HISTLIST) (void)printf("Active kernel histories:"); - for (histkva = LIST_FIRST(); histkva != NULL; - histkva = LIST_NEXT(, list)) { - deref_kptr(histkva, , sizeof(hist), "histkva"); - if (name == NULL || hist.namelen > namelen) { - if (name != NULL) -free(name); - namelen = hist.namelen; - if ((name = malloc(namelen + 1)) == NULL) -err(1, "malloc history name"); - } - - deref_kptr(hist.name, name, namelen, "history name"); - name[namelen] = '\0'; + for (i = 0; i < len; i++) { if (todo & HISTLIST) - (void)printf(" %s", name); + (void)printf(" %s", histnode[i].sysctl_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 || + strcmp(histname, histnode[i].sysctl_name) == 0) { if (histname == NULL) (void)printf( - "\nkernel history `%s':\n", name); -hist_dodump(); + "\nkernel history `%s':\n", + histnode[i].sysctl_name); +mib[2] = histnode[i].sysctl_num; +mib[3] = CTL_EOL; +hist_dodump(mib, 4); } } } if (todo & HISTLIST) (void)putchar('\n'); - - if (name != NULL) - free(name); } /* * Actually dump the history buffer at the specified KVA. */ void -hist_dodump(struct kern_history *histp) +hist_dodump(int mib[], unsigned int miblen) { - struct kern_history_ent *histents, *e; + struct sysctl_history *hist; + struct sysctl_history_event *e; size_t histsize; - char *fmt = NULL, *fn = NULL; - size_t fmtlen = 0, fnlen = 0; + char *strp; unsigned i; + char *fmt = NULL, *fn = NULL; - histsize = sizeof(struct kern_history_ent) * histp->n; - - if ((histents = malloc(histsize)) == NULL) - err(1, "malloc history entries"); - - (void)memset(histents, 0, histsize); - - deref_kptr(histp->e, histents, histsize, "history entries"); - i = histp->f; + hist = NULL; + histsize = 0; do { - e = [i]; - if (e->fmt != NULL) { - if (fmt == NULL || e->fmtlen > fmtlen) { -if (fmt != NULL) - free(fmt); -fmtlen = e->fmtlen; -if ((fmt = malloc(fmtlen + 1)) == NULL) -
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Tue Oct 4 17:36:21 UTC 2016 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: No point in using float here; makes evbmips64 need __truncdfsf2, and that causes static linking issues because of softfloat. To generate a diff of this commit: cvs rdiff -u -r1.207 -r1.208 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.207 src/usr.bin/vmstat/vmstat.c:1.208 --- src/usr.bin/vmstat/vmstat.c:1.207 Sun Sep 4 20:40:30 2016 +++ src/usr.bin/vmstat/vmstat.c Tue Oct 4 13:36:21 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.207 2016/09/05 00:40:30 sevan Exp $ */ +/* $NetBSD: vmstat.c,v 1.208 2016/10/04 17:36:21 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; #else -__RCSID("$NetBSD: vmstat.c,v 1.207 2016/09/05 00:40:30 sevan Exp $"); +__RCSID("$NetBSD: vmstat.c,v 1.208 2016/10/04 17:36:21 christos Exp $"); #endif #endif /* not lint */ @@ -1643,7 +1643,7 @@ dopoolcache_sysctl(int verbose) bool first = true; int ovflw; uint64_t tot; - float p; + double p; data = asysctlbyname("kern.pool", ); if (data == NULL)
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Sun Mar 6 18:01:28 UTC 2016 Modified Files: src/usr.bin/vmstat: Makefile Log Message: Work around gcc on sparc64 bug To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/vmstat/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/Makefile diff -u src/usr.bin/vmstat/Makefile:1.32 src/usr.bin/vmstat/Makefile:1.33 --- src/usr.bin/vmstat/Makefile:1.32 Tue Jun 3 17:41:56 2014 +++ src/usr.bin/vmstat/Makefile Sun Mar 6 13:01:28 2016 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.32 2014/06/03 21:41:56 joerg Exp $ +# $NetBSD: Makefile,v 1.33 2016/03/06 18:01:28 christos Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include @@ -16,4 +16,7 @@ BINMODE=2555 CWARNFLAGS.clang+= -Wno-format-extra-args COPTS.vmstat.c += -Wno-format-nonliteral +# sparc64 is broken! +COPTS.vmstat.c += -Wno-error=stack-protector + .include
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: skrll Date: Fri Sep 12 16:25:55 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.204 -r1.205 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.204 src/usr.bin/vmstat/vmstat.c:1.205 --- src/usr.bin/vmstat/vmstat.c:1.204 Fri Sep 12 16:25:29 2014 +++ src/usr.bin/vmstat/vmstat.c Fri Sep 12 16:25:55 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.204 2014/09/12 16:25:29 skrll Exp $ */ +/* $NetBSD: vmstat.c,v 1.205 2014/09/12 16:25:55 skrll Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.204 2014/09/12 16:25:29 skrll Exp $); +__RCSID($NetBSD: vmstat.c,v 1.205 2014/09/12 16:25:55 skrll Exp $); #endif #endif /* not lint */ @@ -237,7 +237,7 @@ struct nlist histnl[] = }; -#define KILO 1024 +#define KILO 1024 struct cpu_counter { uint64_t nintr;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: skrll Date: Fri Sep 12 16:25:30 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Print the cpu in the kernhist record. To generate a diff of this commit: cvs rdiff -u -r1.203 -r1.204 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.203 src/usr.bin/vmstat/vmstat.c:1.204 --- src/usr.bin/vmstat/vmstat.c:1.203 Sat Jul 12 20:04:31 2014 +++ src/usr.bin/vmstat/vmstat.c Fri Sep 12 16:25:29 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.203 2014/07/12 20:04:31 nakayama Exp $ */ +/* $NetBSD: vmstat.c,v 1.204 2014/09/12 16:25:29 skrll Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.203 2014/07/12 20:04:31 nakayama Exp $); +__RCSID($NetBSD: vmstat.c,v 1.204 2014/09/12 16:25:29 skrll Exp $); #endif #endif /* not lint */ @@ -2118,7 +2118,7 @@ hist_dodump(struct kern_history *histp) (void)printf(%06ld.%06ld , (long int)e-tv.tv_sec, (long int)e-tv.tv_usec); - (void)printf(%s#%ld: , fn, e-call); + (void)printf(%s#%ld@%d: , fn, e-call, e-cpunum); (void)printf(fmt, e-v[0], e-v[1], e-v[2], e-v[3]); (void)putchar('\n'); }
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: nakayama Date: Sat Jul 12 20:04:31 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use u_long to avoid negative value outputs. To generate a diff of this commit: cvs rdiff -u -r1.202 -r1.203 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.202 src/usr.bin/vmstat/vmstat.c:1.203 --- src/usr.bin/vmstat/vmstat.c:1.202 Sat Jun 14 04:06:54 2014 +++ src/usr.bin/vmstat/vmstat.c Sat Jul 12 20:04:31 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.202 2014/06/14 04:06:54 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.203 2014/07/12 20:04:31 nakayama Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.202 2014/06/14 04:06:54 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.203 2014/07/12 20:04:31 nakayama Exp $); #endif #endif /* not lint */ @@ -304,7 +304,7 @@ void needhdr(int); void getnlist(int); long getuptime(void); void printhdr(void); -long pct(long, long); +long pct(u_long, u_long); __dead static void usage(void); void doforkst(void); @@ -852,7 +852,7 @@ needhdr(int dummy) } long -pct(long top, long bot) +pct(u_long top, u_long bot) { long ans; @@ -862,7 +862,7 @@ pct(long top, long bot) return (ans); } -#define PCT(top, bot) (int)pct((long)(top), (long)(bot)) +#define PCT(top, bot) (int)pct((u_long)(top), (u_long)(bot)) void dosum(void)
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Fri Jun 13 11:26:37 UTC 2014 Modified Files: src/usr.bin/vmstat: drvstats.c Log Message: Remove unused headers. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/vmstat/drvstats.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/drvstats.c diff -u src/usr.bin/vmstat/drvstats.c:1.8 src/usr.bin/vmstat/drvstats.c:1.9 --- src/usr.bin/vmstat/drvstats.c:1.8 Mon Jun 2 22:57:50 2014 +++ src/usr.bin/vmstat/drvstats.c Fri Jun 13 11:26:37 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: drvstats.c,v 1.8 2014/06/02 22:57:50 joerg Exp $ */ +/* $NetBSD: drvstats.c,v 1.9 2014/06/13 11:26:37 joerg Exp $ */ /* * Copyright (c) 1996 John M. Vinopal @@ -40,9 +40,7 @@ #include err.h #include fcntl.h -#include kvm.h #include limits.h -#include nlist.h #include stdio.h #include stdlib.h #include string.h
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Fri Jun 13 19:10:01 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use kern.pool for the live system. To generate a diff of this commit: cvs rdiff -u -r1.199 -r1.200 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.199 src/usr.bin/vmstat/vmstat.c:1.200 --- src/usr.bin/vmstat/vmstat.c:1.199 Tue Jun 3 21:56:30 2014 +++ src/usr.bin/vmstat/vmstat.c Fri Jun 13 19:10:01 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.199 2014/06/03 21:56:30 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.200 2014/06/13 19:10:01 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.199 2014/06/03 21:56:30 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.200 2014/06/13 19:10:01 joerg Exp $); #endif #endif /* not lint */ @@ -1354,6 +1354,147 @@ doevcnt(int verbose, int type) Total, counttotal, counttotal / uptime); } +static void +dopool_sysctl(int verbose, int wide) +{ + uint64_t total, inuse, this_total, this_inuse; + struct { + uint64_t pt_nget; + uint64_t pt_nfail; + uint64_t pt_nput; + uint64_t pt_nout; + uint64_t pt_nitems; + uint64_t pt_npagealloc; + uint64_t pt_npagefree; + uint64_t pt_npages; + } pool_totals; + size_t i, len; + int name_len, ovflw; + struct pool_sysctl *pp, *data; + char in_use[8], avail[8], maxp[32]; + + data = asysctlbyname(kern.pool, len); + if (data == NULL) + err(1, failed to reead kern.pool); + + total = inuse = 0; + len /= sizeof(*data); + + (void)printf(Memory resource pool statistics\n); + (void)printf( + %-*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, + Fail, + wide ? 12 : 9, Releases, + wide ? InUse : , + wide ? Avail : , + wide ? 7 : 6, Pgreq, + wide ? 7 : 6, Pgrel, + Npage, + wide ? PageSz : , + Hiwat, + Minpg, + Maxpg, + Idle, + wide ? Flags : , + wide ?Util : ); + + name_len = MIN((int)sizeof(pp-pr_wchan), wide ? 16 : 11); + for (i = 0; i len; ++i) { + pp = data[i]; + if (pp-pr_nget == 0 !verbose) + continue; + if (pp-pr_maxpages == UINT_MAX) + (void)snprintf(maxp, sizeof(maxp), inf); + else + (void)snprintf(maxp, sizeof(maxp), % PRIu64, + pp-pr_maxpages); + ovflw = 0; + PRWORD(ovflw, %-*s, name_len, 0, pp-pr_wchan); + PRWORD(ovflw, %* PRIu64, wide ? 6 : 5, 1, pp-pr_size); + PRWORD(ovflw, %* PRIu64, wide ? 12 : 9, 1, pp-pr_nget); + pool_totals.pt_nget += pp-pr_nget; + PRWORD(ovflw, %* PRIu64, 5, 1, pp-pr_nfail); + pool_totals.pt_nfail += pp-pr_nfail; + PRWORD(ovflw, %* PRIu64, wide ? 12 : 9, 1, pp-pr_nput); + pool_totals.pt_nput += pp-pr_nput; + if (wide) { + PRWORD(ovflw, %* PRIu64, 7, 1, pp-pr_nout); + pool_totals.pt_nout += pp-pr_nout; + } + if (wide) { + PRWORD(ovflw, %* PRIu64, 6, 1, pp-pr_nitems); + pool_totals.pt_nitems += pp-pr_nitems; + } + PRWORD(ovflw, %* PRIu64, wide ? 7 : 6, 1, pp-pr_npagealloc); + pool_totals.pt_npagealloc += pp-pr_npagealloc; + PRWORD(ovflw, %* PRIu64, wide ? 7 : 6, 1, pp-pr_npagefree); + pool_totals.pt_npagefree += pp-pr_npagefree; + PRWORD(ovflw, %* PRIu64, 6, 1, pp-pr_npages); + pool_totals.pt_npages += pp-pr_npages; + if (wide) + PRWORD(ovflw, %* PRIu64, 7, 1, pp-pr_pagesize); + PRWORD(ovflw, %* PRIu64, 6, 1, pp-pr_hiwat); + PRWORD(ovflw, %* PRIu64, 6, 1, pp-pr_minpages); + PRWORD(ovflw, %*s, 6, 1, maxp); + PRWORD(ovflw, %* PRIu64, 5, 1, pp-pr_nidle); + if (wide) + PRWORD(ovflw, 0x%0* PRIx64, 4, 1, + pp-pr_flags); + + this_inuse = pp-pr_nout * pp-pr_size; + this_total = pp-pr_npages * pp-pr_pagesize; + if (pp-pr_flags PR_RECURSIVE) { + /* + * Don't count in-use memory, since it's part + * of another pool and will be accounted for + * there. + */ + total += (this_total - this_inuse); + } else { + inuse += this_inuse; + total += this_total; + } + if (wide) { + if (this_total == 0) +(void)printf( ---); + else +(void)printf( %5.1f%%, +(100.0 * this_inuse) / this_total); + } + (void)printf(\n); + } + if (wide) { + snprintf(in_use, sizeof in_use, %7PRId64, pool_totals.pt_nout); + snprintf(avail, sizeof avail, %6PRId64, pool_totals.pt_nitems); + } else { + in_use[0] = '\0'; + avail[0] = '\0'; + } + (void)printf( + %-*s%*s%*PRId64%5PRId64%*PRId64%s%s%*PRId64%*PRId64%6PRId64\n, + wide ? 16 : 11, Totals, + wide ? 6 : 5, , + wide ? 12 : 9, pool_totals.pt_nget, + pool_totals.pt_nfail, + wide ? 12 : 9, pool_totals.pt_nput, + in_use, + avail, + wide ? 7 : 6,
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Sat Jun 14 01:27:00 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Fix format string for ILP32. To generate a diff of this commit: cvs rdiff -u -r1.200 -r1.201 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.200 src/usr.bin/vmstat/vmstat.c:1.201 --- src/usr.bin/vmstat/vmstat.c:1.200 Fri Jun 13 19:10:01 2014 +++ src/usr.bin/vmstat/vmstat.c Sat Jun 14 01:26:59 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.200 2014/06/13 19:10:01 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.201 2014/06/14 01:26:59 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.200 2014/06/13 19:10:01 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.201 2014/06/14 01:26:59 joerg Exp $); #endif #endif /* not lint */ @@ -1489,7 +1489,8 @@ dopool_sysctl(int verbose, int wide) inuse /= KILO; total /= KILO; (void)printf( - \nIn use %ldK, total allocated %ldK; utilization %.1f%%\n, + \nIn use % PRIu64 K, + total allocated % PRIu64 K; utilization %.1f%%\n, inuse, total, (100.0 * inuse) / total); free(data);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Sat Jun 14 04:06:54 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Init summary counters. To generate a diff of this commit: cvs rdiff -u -r1.201 -r1.202 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.201 src/usr.bin/vmstat/vmstat.c:1.202 --- src/usr.bin/vmstat/vmstat.c:1.201 Sat Jun 14 01:26:59 2014 +++ src/usr.bin/vmstat/vmstat.c Sat Jun 14 04:06:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.201 2014/06/14 01:26:59 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.202 2014/06/14 04:06:54 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.201 2014/06/14 01:26:59 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.202 2014/06/14 04:06:54 joerg Exp $); #endif #endif /* not lint */ @@ -1377,6 +1377,7 @@ dopool_sysctl(int verbose, int wide) if (data == NULL) err(1, failed to reead kern.pool); + memset(pool_totals, 0, sizeof pool_totals); total = inuse = 0; len /= sizeof(*data);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Tue Jun 3 21:31:54 UTC 2014 Modified Files: src/usr.bin/vmstat: Makefile vmstat.c Log Message: Use vm.uvmexp data as much as possible for vmstat -s. Temporarily disable shadowing warning until the other users are cleaned up. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/usr.bin/vmstat/Makefile cvs rdiff -u -r1.194 -r1.195 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/Makefile diff -u src/usr.bin/vmstat/Makefile:1.30 src/usr.bin/vmstat/Makefile:1.31 --- src/usr.bin/vmstat/Makefile:1.30 Wed Aug 17 13:54:31 2011 +++ src/usr.bin/vmstat/Makefile Tue Jun 3 21:31:54 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.30 2011/08/17 13:54:31 christos Exp $ +# $NetBSD: Makefile,v 1.31 2014/06/03 21:31:54 joerg Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include bsd.own.mk @@ -14,6 +14,6 @@ BINGRP= kmem BINMODE=2555 CWARNFLAGS.clang+= -Wno-format-extra-args -COPTS.vmstat.c += -Wno-format-nonliteral +COPTS.vmstat.c += -Wno-format-nonliteral -Wno-shadow .include bsd.prog.mk Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.194 src/usr.bin/vmstat/vmstat.c:1.195 --- src/usr.bin/vmstat/vmstat.c:1.194 Tue Jun 3 21:16:15 2014 +++ src/usr.bin/vmstat/vmstat.c Tue Jun 3 21:31:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.194 2014/06/03 21:16:15 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.195 2014/06/03 21:31:54 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.194 2014/06/03 21:16:15 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.195 2014/06/03 21:31:54 joerg Exp $); #endif #endif /* not lint */ @@ -850,7 +850,7 @@ dosum(void) { struct nchstats_sysctl nch_stats; uint64_t nchtotal; - struct uvmexp_sysctl uvmexp2; + struct uvmexp_sysctl uvmexp; size_t ssize; int active_kernel; struct cpu_counter cc; @@ -860,47 +860,112 @@ dosum(void) * are now estimated by the kernel and sadly * can not easily be dug out of a crash dump. */ - ssize = sizeof(uvmexp2); - memset(uvmexp2, 0, ssize); + ssize = sizeof(uvmexp); + memset(uvmexp, 0, ssize); active_kernel = (memf == NULL); if (active_kernel) { /* only on active kernel */ - if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), uvmexp2, + if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), uvmexp, ssize, NULL, 0) == -1) warn(sysctl vm.uvmexp2 failed); + } else { + struct uvmexp uvmexp_kernel; + kread(namelist, X_UVMEXP, uvmexp_kernel, sizeof(uvmexp_kernel)); +#define COPY(field) uvmexp.field = uvmexp_kernel.field + COPY(pagesize); + COPY(ncolors); + COPY(npages); + COPY(free); + COPY(paging); + COPY(wired); + COPY(zeropages); + COPY(reserve_pagedaemon); + COPY(reserve_kernel); + COPY(anonpages); + COPY(filepages); + COPY(execpages); + COPY(freemin); + COPY(freetarg); + COPY(wiredmax); + COPY(nswapdev); + COPY(swpages); + COPY(swpginuse); + COPY(nswget); + COPY(pageins); + COPY(pdpageouts); + COPY(pgswapin); + COPY(pgswapout); + COPY(forks); + COPY(forks_ppwait); + COPY(forks_sharevm); + COPY(pga_zerohit); + COPY(pga_zeromiss); + COPY(zeroaborts); + COPY(colorhit); + COPY(colormiss); + COPY(cpuhit); + COPY(cpumiss); + COPY(fltnoram); + COPY(fltnoanon); + COPY(fltpgwait); + COPY(fltpgrele); + COPY(fltrelck); + COPY(fltrelckok); + COPY(fltanget); + COPY(fltanretry); + COPY(fltamcopy); + COPY(fltamcopy); + COPY(fltnomap); + COPY(fltlget); + COPY(fltget); + COPY(flt_anon); + COPY(flt_acow); + COPY(flt_obj); + COPY(flt_prcopy); + COPY(flt_przero); + COPY(pdwoke); + COPY(pdrevs); + COPY(pdfreed); + COPY(pdscans); + COPY(pdanscan); + COPY(pdobscan); + COPY(pdreact); + COPY(pdbusy); + COPY(pdpending); + COPY(pddeact); +#undef COPY } - kread(namelist, X_UVMEXP, uvmexp, sizeof(uvmexp)); - (void)printf(%9u bytes per page\n, uvmexp.pagesize); + (void)printf(%9 PRIu64 bytes per page\n, uvmexp.pagesize); - (void)printf(%9u page color%s\n, + (void)printf(%9 PRIu64 page color%s\n, uvmexp.ncolors, uvmexp.ncolors == 1 ? : s); - (void)printf(%9u pages managed\n, uvmexp.npages); - (void)printf(%9u pages free\n, uvmexp.free); + (void)printf(%9 PRIu64 pages managed\n, uvmexp.npages); + (void)printf(%9 PRIu64 pages free\n, uvmexp.free); if (active_kernel) { - (void)printf(%9 PRIu64 pages active\n, uvmexp2.active); - (void)printf(%9 PRIu64 pages inactive\n, uvmexp2.inactive); + (void)printf(%9 PRIu64 pages active\n, uvmexp.active); + (void)printf(%9 PRIu64 pages inactive\n, uvmexp.inactive); } - (void)printf(%9u pages paging\n, uvmexp.paging); - (void)printf(%9u pages wired\n, uvmexp.wired); - (void)printf(%9u zero pages\n,
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Tue Jun 3 21:41:56 UTC 2014 Modified Files: src/usr.bin/vmstat: Makefile vmstat.c Log Message: Convert the remaining uvmexp users to the sysctl as default source. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/usr.bin/vmstat/Makefile cvs rdiff -u -r1.195 -r1.196 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/Makefile diff -u src/usr.bin/vmstat/Makefile:1.31 src/usr.bin/vmstat/Makefile:1.32 --- src/usr.bin/vmstat/Makefile:1.31 Tue Jun 3 21:31:54 2014 +++ src/usr.bin/vmstat/Makefile Tue Jun 3 21:41:56 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.31 2014/06/03 21:31:54 joerg Exp $ +# $NetBSD: Makefile,v 1.32 2014/06/03 21:41:56 joerg Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include bsd.own.mk @@ -14,6 +14,6 @@ BINGRP= kmem BINMODE=2555 CWARNFLAGS.clang+= -Wno-format-extra-args -COPTS.vmstat.c += -Wno-format-nonliteral -Wno-shadow +COPTS.vmstat.c += -Wno-format-nonliteral .include bsd.prog.mk Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.195 src/usr.bin/vmstat/vmstat.c:1.196 --- src/usr.bin/vmstat/vmstat.c:1.195 Tue Jun 3 21:31:54 2014 +++ src/usr.bin/vmstat/vmstat.c Tue Jun 3 21:41:56 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.195 2014/06/03 21:31:54 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.196 2014/06/03 21:41:56 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.195 2014/06/03 21:31:54 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.196 2014/06/03 21:41:56 joerg Exp $); #endif #endif /* not lint */ @@ -250,7 +250,7 @@ struct cpu_counter { uint64_t nsoft; } cpucounter, ocpucounter; -struct uvmexp uvmexp, ouvmexp; +struct uvmexp_sysctl uvmexp, ouvmexp; int ndrives; int winlines = 20; @@ -738,14 +738,22 @@ dovmstat(struct timespec *interval, int cpureadstats(); drvreadstats(); tkreadstats(); - kread(namelist, X_UVMEXP, uvmexp, sizeof(uvmexp)); if (memf != NULL) { + struct uvmexp uvmexp_kernel; /* * XXX Can't do this if we're reading a crash * XXX dump because they're lazily-calculated. */ warnx(Unable to get vmtotals from crash dump.); (void)memset(total, 0, sizeof(total)); + kread(namelist, X_UVMEXP, uvmexp_kernel, sizeof(uvmexp_kernel)); +#define COPY(field) uvmexp.field = uvmexp_kernel.field + COPY(pdreact); + COPY(pageins); + COPY(pgswapout); + COPY(pdfreed); + COPY(pdscans); +#undef COPY } else { size = sizeof(total); if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib), @@ -753,6 +761,10 @@ dovmstat(struct timespec *interval, int warn(Can't get vmtotals); (void)memset(total, 0, sizeof(total)); } + size = sizeof(uvmexp); + if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), uvmexp, + size, NULL, 0) == -1) +warn(sysctl vm.uvmexp2 failed); } cpucounters(cpucounter); ovflw = 0; @@ -850,7 +862,6 @@ dosum(void) { struct nchstats_sysctl nch_stats; uint64_t nchtotal; - struct uvmexp_sysctl uvmexp; size_t ssize; int active_kernel; struct cpu_counter cc; @@ -1081,10 +1092,24 @@ void doforkst(void) { kread(namelist, X_UVMEXP, uvmexp, sizeof(uvmexp)); + if (memf != NULL) { + struct uvmexp uvmexp_kernel; + kread(namelist, X_UVMEXP, uvmexp_kernel, sizeof(uvmexp_kernel)); +#define COPY(field) uvmexp.field = uvmexp_kernel.field + COPY(forks); + COPY(forks_ppwait); + COPY(forks_sharevm); +#undef COPY + } else { + size_t size = sizeof(uvmexp); + if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), uvmexp, + size, NULL, 0) == -1) + warn(sysctl vm.uvmexp2 failed); + } - (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, + (void)printf(% PRIu64 forks total\n, uvmexp.forks); + (void)printf(% PRIu64 forks blocked parent\n, uvmexp.forks_ppwait); + (void)printf(% PRIu64 forks shared address space with parent\n, uvmexp.forks_sharevm); }
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Tue Jun 3 21:45:41 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use kern.clockrate if possible. To generate a diff of this commit: cvs rdiff -u -r1.196 -r1.197 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.196 src/usr.bin/vmstat/vmstat.c:1.197 --- src/usr.bin/vmstat/vmstat.c:1.196 Tue Jun 3 21:41:56 2014 +++ src/usr.bin/vmstat/vmstat.c Tue Jun 3 21:45:41 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.196 2014/06/03 21:41:56 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.197 2014/06/03 21:45:41 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.196 2014/06/03 21:41:56 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.197 2014/06/03 21:45:41 joerg Exp $); #endif #endif /* not lint */ @@ -322,6 +322,7 @@ char *nlistf, *memf; /* allow old usage [vmstat 1] */ #define BACKWARD_COMPATIBILITY +static const int clockrate_mib[] = { CTL_KERN, KERN_CLOCKRATE }; static const int vmmeter_mib[] = { CTL_VM, VM_METER }; static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 }; static const int boottime_mib[] = { CTL_KERN, KERN_BOOTTIME }; @@ -724,10 +725,20 @@ dovmstat(struct timespec *interval, int halfuptime = uptime / 2; (void)signal(SIGCONT, needhdr); - if (namelist[X_STATHZ].n_type != 0 namelist[X_STATHZ].n_value != 0) - kread(namelist, X_STATHZ, hz, sizeof(hz)); - if (!hz) - kread(namelist, X_HZ, hz, sizeof(hz)); + if (memf != NULL) { + if (namelist[X_STATHZ].n_type != 0 namelist[X_STATHZ].n_value != 0) + kread(namelist, X_STATHZ, hz, sizeof(hz)); + if (!hz) + kread(namelist, X_HZ, hz, sizeof(hz)); + } else { + struct clockinfo clockinfo; + size = sizeof(clockinfo); + if (sysctl(clockrate_mib, 2, clockinfo, size, NULL, 0) == -1) + err(1, sysctl kern.clockrate failed); + hz = clockinfo.stathz; + if (!hz) + hz = clockinfo.hz; + } kread(namelist, X_CPU_INFOS, cpu_infos, sizeof(cpu_infos));
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Tue Jun 3 21:56:03 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use CPU statistics from uvmexp when possible. To generate a diff of this commit: cvs rdiff -u -r1.197 -r1.198 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.197 src/usr.bin/vmstat/vmstat.c:1.198 --- src/usr.bin/vmstat/vmstat.c:1.197 Tue Jun 3 21:45:41 2014 +++ src/usr.bin/vmstat/vmstat.c Tue Jun 3 21:56:03 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.197 2014/06/03 21:45:41 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.198 2014/06/03 21:56:03 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.197 2014/06/03 21:45:41 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.198 2014/06/03 21:56:03 joerg Exp $); #endif #endif /* not lint */ @@ -142,8 +142,6 @@ struct cpu_info { # include sys/cpu.h #endif -struct cpu_info **cpu_infos; - /* * General namelist */ @@ -740,8 +738,6 @@ dovmstat(struct timespec *interval, int hz = clockinfo.hz; } - kread(namelist, X_CPU_INFOS, cpu_infos, sizeof(cpu_infos)); - for (hdrcnt = 1;;) { if (!--hdrcnt) printhdr(); @@ -989,7 +985,6 @@ dosum(void) (void)printf(%9 PRIu64 swap pages in use\n, uvmexp.swpginuse); (void)printf(%9 PRIu64 swap allocations\n, uvmexp.nswget); - kread(namelist, X_CPU_INFOS, cpu_infos, sizeof(cpu_infos)); cpucounters(cc); (void)printf(%9 PRIu64 total faults taken\n, cc.nfault); @@ -1149,7 +1144,26 @@ drvstats(int *ovflwp) void cpucounters(struct cpu_counter *cc) { - struct cpu_info **slot = cpu_infos; + static struct cpu_info **cpu_infos; + static int initialised; + struct cpu_info **slot; + + if (memf == NULL) { + cc-nintr = uvmexp.intrs; + cc-nsyscall = uvmexp.syscalls; + cc-nswtch = uvmexp.swtch; + cc-nfault = uvmexp.faults; + cc-ntrap = uvmexp.traps; + cc-nsoft = uvmexp.softs; + return; + } + + if (!initialised) { + kread(namelist, X_CPU_INFOS, cpu_infos, sizeof(cpu_infos)); + initialised = 1; + } + + slot = cpu_infos; memset(cc, 0, sizeof(*cc));
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Tue Jun 3 21:56:30 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: GC left-over kread. To generate a diff of this commit: cvs rdiff -u -r1.198 -r1.199 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.198 src/usr.bin/vmstat/vmstat.c:1.199 --- src/usr.bin/vmstat/vmstat.c:1.198 Tue Jun 3 21:56:03 2014 +++ src/usr.bin/vmstat/vmstat.c Tue Jun 3 21:56:30 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.198 2014/06/03 21:56:03 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.199 2014/06/03 21:56:30 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.198 2014/06/03 21:56:03 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.199 2014/06/03 21:56:30 joerg Exp $); #endif #endif /* not lint */ @@ -1097,7 +1097,6 @@ dosum(void) void doforkst(void) { - kread(namelist, X_UVMEXP, uvmexp, sizeof(uvmexp)); if (memf != NULL) { struct uvmexp uvmexp_kernel; kread(namelist, X_UVMEXP, uvmexp_kernel, sizeof(uvmexp_kernel));
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Mon Jun 2 19:16:11 UTC 2014 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Make missing kern.evcnt an error, don't try to fallback to kmem use. To generate a diff of this commit: cvs rdiff -u -r1.192 -r1.193 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.192 src/usr.bin/vmstat/vmstat.c:1.193 --- src/usr.bin/vmstat/vmstat.c:1.192 Thu May 8 08:21:53 2014 +++ src/usr.bin/vmstat/vmstat.c Mon Jun 2 19:16:10 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.192 2014/05/08 08:21:53 hannken Exp $ */ +/* $NetBSD: vmstat.c,v 1.193 2014/06/02 19:16:10 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.192 2014/05/08 08:21:53 hannken Exp $); +__RCSID($NetBSD: vmstat.c,v 1.193 2014/06/02 19:16:10 joerg Exp $); #endif #endif /* not lint */ @@ -1144,10 +1144,7 @@ doevcnt(int verbose, int type) error = sysctl(mib, __arraycount(mib), buf, newlen, NULL, 0); if (error) { -/* if the sysctl is unknown, try groveling */ -if (error == ENOENT) - break; -warn(kern.evcnt); +err(1, kern.evcnt); if (buf) free(buf); return;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Mon Jun 2 19:29:00 UTC 2014 Modified Files: src/usr.bin/vmstat: drvstats.c Log Message: Drop kvm-based access for driver statistics. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vmstat/drvstats.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/drvstats.c diff -u src/usr.bin/vmstat/drvstats.c:1.6 src/usr.bin/vmstat/drvstats.c:1.7 --- src/usr.bin/vmstat/drvstats.c:1.6 Tue Nov 13 14:09:58 2012 +++ src/usr.bin/vmstat/drvstats.c Mon Jun 2 19:29:00 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: drvstats.c,v 1.6 2012/11/13 14:09:58 chs Exp $ */ +/* $NetBSD: drvstats.c,v 1.7 2014/06/02 19:29:00 joerg Exp $ */ /* * Copyright (c) 1996 John M. Vinopal @@ -49,29 +49,9 @@ #include unistd.h #include drvstats.h -static struct nlist namelist[] = { -#define X_TK_NIN 0 - { .n_name = _tk_nin }, /* tty characters in */ -#define X_TK_NOUT 1 - { .n_name = _tk_nout }, /* tty characters out */ -#define X_HZ 2 - { .n_name = _hz }, /* ticks per second */ -#define X_STATHZ 3 - { .n_name = _stathz }, -#define X_DRIVE_COUNT 4 - { .n_name = _iostat_count }, /* number of drives */ -#define X_DRIVELIST 5 - { .n_name = _iostatlist }, /* TAILQ of drives */ - { .n_name = NULL }, -}; - /* Structures to hold the statistics. */ struct _drive cur, last; -/* Kernel pointers: nlistf and memf defined in calling program. */ -static kvm_t *kd = NULL; -extern char *nlistf; -extern char *memf; extern int hz; /* Pointer to list of drives. */ @@ -84,27 +64,12 @@ size_t ndrive = 0; int *drv_select; char **dr_name; -#define KVM_ERROR(_string) do { \ - warnx(%s, (_string)); \ - errx(1, %s, kvm_geterr(kd)); \ -} while (/* CONSTCOND */0) - -/* - * Dereference the namelist pointer `v' and fill in the local copy - * 'p' which is of size 's'. - */ -#define deref_nl(v, p, s) do { \ - deref_kptr((void *)namelist[(v)].n_value, (p), (s)); \ -} while (/* CONSTCOND */0) - /* Missing from sys/time.h */ #define timerset(tvp, uvp) do { \ ((uvp)-tv_sec = (tvp)-tv_sec);\ ((uvp)-tv_usec = (tvp)-tv_usec);\ } while (/* CONSTCOND */0) -static void deref_kptr(void *, void *, size_t); - /* * Take the delta between the present values and the last recorded * values, storing the present values in the 'last' structure, and @@ -183,70 +148,47 @@ cpuswap(void) void drvreadstats(void) { - struct io_stats cur_drive, *p; + struct io_stats *p; size_t size, i; int mib[3]; p = iostathead; - if (memf == NULL) { - mib[0] = CTL_HW; - mib[1] = HW_IOSTATS; - mib[2] = sizeof(struct io_sysctl); - - size = ndrive * sizeof(struct io_sysctl); - if (sysctl(mib, 3, drives, size, NULL, 0) 0) - err(1, sysctl hw.iostats failed); - for (i = 0; i ndrive; i++) { - cur.rxfer[i] = drives[i].rxfer; - cur.wxfer[i] = drives[i].wxfer; - cur.seek[i] = drives[i].seek; - cur.rbytes[i] = drives[i].rbytes; - cur.wbytes[i] = drives[i].wbytes; - cur.time[i].tv_sec = drives[i].time_sec; - cur.time[i].tv_usec = drives[i].time_usec; - } + mib[0] = CTL_HW; + mib[1] = HW_IOSTATS; + mib[2] = sizeof(struct io_sysctl); + + size = ndrive * sizeof(struct io_sysctl); + if (sysctl(mib, 3, drives, size, NULL, 0) 0) + err(1, sysctl hw.iostats failed); + for (i = 0; i ndrive; i++) { + cur.rxfer[i] = drives[i].rxfer; + cur.wxfer[i] = drives[i].wxfer; + cur.seek[i] = drives[i].seek; + cur.rbytes[i] = drives[i].rbytes; + cur.wbytes[i] = drives[i].wbytes; + cur.time[i].tv_sec = drives[i].time_sec; + cur.time[i].tv_usec = drives[i].time_usec; + } mib[0] = CTL_KERN; - mib[1] = KERN_TKSTAT; - mib[2] = KERN_TKSTAT_NIN; - size = sizeof(cur.tk_nin); - if (sysctl(mib, 3, cur.tk_nin, size, NULL, 0) 0) - cur.tk_nin = 0; - - mib[2] = KERN_TKSTAT_NOUT; - size = sizeof(cur.tk_nout); - if (sysctl(mib, 3, cur.tk_nout, size, NULL, 0) 0) - cur.tk_nout = 0; - } else { - for (i = 0; i ndrive; i++) { - deref_kptr(p, cur_drive, sizeof(cur_drive)); - cur.rxfer[i] = cur_drive.io_rxfer; - cur.wxfer[i] = cur_drive.io_wxfer; - cur.seek[i] = cur_drive.io_seek; - cur.rbytes[i] = cur_drive.io_rbytes; - cur.wbytes[i] = cur_drive.io_wbytes; - timerset((cur_drive.io_time), (cur.time[i])); - p = cur_drive.io_link.tqe_next; - } - - deref_nl(X_TK_NIN, cur.tk_nin, sizeof(cur.tk_nin)); - deref_nl(X_TK_NOUT, cur.tk_nout, sizeof(cur.tk_nout)); - } + mib[1] = KERN_TKSTAT; + mib[2] = KERN_TKSTAT_NIN; + size = sizeof(cur.tk_nin); + if (sysctl(mib, 3, cur.tk_nin, size, NULL, 0) 0) + cur.tk_nin = 0; + + mib[2] = KERN_TKSTAT_NOUT; + size = sizeof(cur.tk_nout); + if (sysctl(mib, 3, cur.tk_nout, size, NULL, 0) 0) + cur.tk_nout = 0; - /* - * XXX Need to locate the `correct' CPU when looking for this - * XXX in crash dumps. Just don't report it for now, in that - * XXX case. - */ size = sizeof(cur.cp_time);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Mon Jun 2 22:57:50 UTC 2014 Modified Files: src/usr.bin/vmstat: drvstats.c Log Message: GC unused variables. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/vmstat/drvstats.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/drvstats.c diff -u src/usr.bin/vmstat/drvstats.c:1.7 src/usr.bin/vmstat/drvstats.c:1.8 --- src/usr.bin/vmstat/drvstats.c:1.7 Mon Jun 2 19:29:00 2014 +++ src/usr.bin/vmstat/drvstats.c Mon Jun 2 22:57:50 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: drvstats.c,v 1.7 2014/06/02 19:29:00 joerg Exp $ */ +/* $NetBSD: drvstats.c,v 1.8 2014/06/02 22:57:50 joerg Exp $ */ /* * Copyright (c) 1996 John M. Vinopal @@ -54,8 +54,6 @@ struct _drive cur, last; extern int hz; -/* Pointer to list of drives. */ -static struct io_stats *iostathead = NULL; /* sysctl hw.drivestats buffer. */ static struct io_sysctl *drives = NULL; @@ -148,12 +146,9 @@ cpuswap(void) void drvreadstats(void) { - struct io_stats *p; size_t size, i; int mib[3]; - p = iostathead; - mib[0] = CTL_HW; mib[1] = HW_IOSTATS; mib[2] = sizeof(struct io_sysctl);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mrg Date: Sun Nov 10 05:16:10 UTC 2013 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: add a row with totals for some pool statistics. To generate a diff of this commit: cvs rdiff -u -r1.188 -r1.189 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.188 src/usr.bin/vmstat/vmstat.c:1.189 --- src/usr.bin/vmstat/vmstat.c:1.188 Sun Apr 29 16:23:56 2012 +++ src/usr.bin/vmstat/vmstat.c Sun Nov 10 05:16:10 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.188 2012/04/29 16:23:56 para Exp $ */ +/* $NetBSD: vmstat.c,v 1.189 2013/11/10 05:16:10 mrg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.188 2012/04/29 16:23:56 para Exp $); +__RCSID($NetBSD: vmstat.c,v 1.189 2013/11/10 05:16:10 mrg Exp $); #endif #endif /* not lint */ @@ -1226,11 +1226,24 @@ dopool(int verbose, int wide) int first, ovflw; void *addr; long total, inuse, this_total, this_inuse; + struct { + uint64_t pt_nget; + uint64_t pt_nfail; + uint64_t pt_nput; + uint64_t pt_nout; + uint64_t pt_nitems; + uint64_t pt_npagealloc; + uint64_t pt_npagefree; + uint64_t pt_npages; + } pool_totals; + char in_use[8]; + char avail[8]; TAILQ_HEAD(,pool) pool_head; struct pool pool, *pp = pool; struct pool_allocator pa; char name[32], maxp[32]; + memset(pool_totals, 0, sizeof pool_totals); kread(namelist, X_POOLHEAD, pool_head, sizeof(pool_head)); addr = TAILQ_FIRST(pool_head); @@ -1278,15 +1291,25 @@ dopool(int verbose, int wide) 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); + pool_totals.pt_nget += pp-pr_nget; PRWORD(ovflw, %*lu, 5, 1, pp-pr_nfail); + pool_totals.pt_nfail += pp-pr_nfail; PRWORD(ovflw, %*lu, wide ? 12 : 9, 1, pp-pr_nput); - if (wide) + pool_totals.pt_nput += pp-pr_nput; + if (wide) { PRWORD(ovflw, %*u, 7, 1, pp-pr_nout); - if (wide) + pool_totals.pt_nout += pp-pr_nout; + } + if (wide) { PRWORD(ovflw, %*u, 6, 1, pp-pr_nitems); + pool_totals.pt_nitems += pp-pr_nitems; + } PRWORD(ovflw, %*lu, wide ? 7 : 6, 1, pp-pr_npagealloc); + pool_totals.pt_npagealloc += pp-pr_npagealloc; PRWORD(ovflw, %*lu, wide ? 7 : 6, 1, pp-pr_npagefree); + pool_totals.pt_npagefree += pp-pr_npagefree; PRWORD(ovflw, %*u, 6, 1, pp-pr_npages); + pool_totals.pt_npages += pp-pr_npages; if (wide) PRWORD(ovflw, %*u, 7, 1, pa.pa_pagesz); PRWORD(ovflw, %*u, 6, 1, pp-pr_hiwat); @@ -1319,6 +1342,25 @@ dopool(int verbose, int wide) } (void)printf(\n); } + if (wide) { + snprintf(in_use, sizeof in_use, %7PRId64, pool_totals.pt_nout); + snprintf(avail, sizeof avail, %6PRId64, pool_totals.pt_nitems); + } else { + in_use[0] = '\0'; + avail[0] = '\0'; + } + (void)printf( + %-*s%*s%*PRId64%5PRId64%*PRId64%s%s%*PRId64%*PRId64%6PRId64\n, + wide ? 16 : 11, Totals, + wide ? 6 : 5, , + wide ? 12 : 9, pool_totals.pt_nget, + pool_totals.pt_nfail, + wide ? 12 : 9, pool_totals.pt_nput, + in_use, + avail, + wide ? 7 : 6, pool_totals.pt_npagealloc, + wide ? 7 : 6, pool_totals.pt_npagefree, + pool_totals.pt_npages); inuse /= KILO; total /= KILO;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: chs Date: Tue Nov 13 14:09:58 UTC 2012 Modified Files: src/usr.bin/vmstat: drvstats.c Log Message: fix operation on core files: cur_drive.io_name is an embedded array in the structure we already fetched, not a pointer, so don't try to dereference its address as a kernel address. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vmstat/drvstats.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/drvstats.c diff -u src/usr.bin/vmstat/drvstats.c:1.5 src/usr.bin/vmstat/drvstats.c:1.6 --- src/usr.bin/vmstat/drvstats.c:1.5 Sun Jan 18 07:20:00 2009 +++ src/usr.bin/vmstat/drvstats.c Tue Nov 13 14:09:58 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: drvstats.c,v 1.5 2009/01/18 07:20:00 lukem Exp $ */ +/* $NetBSD: drvstats.c,v 1.6 2012/11/13 14:09:58 chs Exp $ */ /* * Copyright (c) 1996 John M. Vinopal @@ -425,10 +425,8 @@ drvinit(int selected) } else { p = iostathead; for (i = 0; i ndrive; i++) { - char buf[10]; deref_kptr(p, cur_drive, sizeof(cur_drive)); - deref_kptr(cur_drive.io_name, buf, sizeof(buf)); - cur.name[i] = strdup(buf); + cur.name[i] = strdup(cur_drive.io_name); if (!cur.name[i]) err(1, strdup); cur.select[i] = selected;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: para Date: Sun Apr 29 16:23:56 UTC 2012 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: remove malloc(9) output function from vmstat it is not required and working any more To generate a diff of this commit: cvs rdiff -u -r1.187 -r1.188 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.187 src/usr.bin/vmstat/vmstat.c:1.188 --- src/usr.bin/vmstat/vmstat.c:1.187 Tue Mar 20 20:34:59 2012 +++ src/usr.bin/vmstat/vmstat.c Sun Apr 29 16:23:56 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.187 2012/03/20 20:34:59 matt Exp $ */ +/* $NetBSD: vmstat.c,v 1.188 2012/04/29 16:23:56 para Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.187 2012/03/20 20:34:59 matt Exp $); +__RCSID($NetBSD: vmstat.c,v 1.188 2012/04/29 16:23:56 para Exp $); #endif #endif /* not lint */ @@ -161,23 +161,19 @@ struct nlist namelist[] = { .n_name = _stathz }, #define X_NCHSTATS 3 { .n_name = _nchstats }, -#define X_KMEMSTAT 4 - { .n_name = _kmemstatistics }, -#define X_KMEMBUCKETS 5 - { .n_name = _kmembuckets }, -#define X_ALLEVENTS 6 +#define X_ALLEVENTS 4 { .n_name = _allevents }, -#define X_POOLHEAD 7 +#define X_POOLHEAD 5 { .n_name = _pool_head }, -#define X_UVMEXP 8 +#define X_UVMEXP 6 { .n_name = _uvmexp }, -#define X_TIME_SECOND 9 +#define X_TIME_SECOND 7 { .n_name = _time_second }, -#define X_TIME 10 +#define X_TIME 8 { .n_name = _time }, -#define X_CPU_QUEUE 11 +#define X_CPU_QUEUE 9 { .n_name = _cpu_queue }, -#define X_NL_SIZE 12 +#define X_NL_SIZE 10 { .n_name = NULL }, }; @@ -302,7 +298,6 @@ void drvstats(int *); void doevcnt(int verbose, int type); void dohashstat(int, int, const char *); void dointr(int verbose); -void domem(void); void dopool(int, int); void dopoolcache(int); void dosum(void); @@ -494,7 +489,6 @@ main(int argc, char *argv[]) (void)putchar('\n'); } if (todo MEMSTAT) { -domem(); dopool(verbose, wide); (void)putchar('\n'); } @@ -1226,119 +1220,6 @@ doevcnt(int verbose, int type) Total, counttotal, counttotal / uptime); } -static char memname[64]; - -void -domem(void) -{ - struct kmembuckets *kp; - struct malloc_type ks, *ksp; - int i, j; - int len, size, first; - long totuse = 0, totfree = 0, totreq = 0; - struct kmembuckets buckets[MINBUCKET + 16]; - - kread(namelist, X_KMEMBUCKETS, buckets, sizeof(buckets)); - for (first = 1, i = MINBUCKET, kp = buckets[i]; i MINBUCKET + 16; - i++, kp++) { - if (kp-kb_calls == 0) - continue; - if (first) { - (void)printf(Memory statistics by bucket size\n); - (void)printf( - Size In Use Free Requests HighWater Couldfree\n); - first = 0; - } - 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; - } - - /* - * If kmem statistics are not being gathered by the kernel, - * first will still be 1. - */ - if (first) { - warnx(Kmem statistics are not being gathered by the kernel.); - return; - } - - (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 (kread(namelist, X_KMEMSTAT, ksp, sizeof(ksp)); - ksp != NULL; ksp = ks.ks_next) { - deref_kptr(ksp, ks, sizeof(ks), malloc type); - if (ks.ks_calls == 0) -continue; - if ((ks.ks_size j) == 0) -continue; - deref_kptr(ks.ks_shortdesc, memname, - sizeof(memname), malloc type name); - len += 2 + strlen(memname); - if (first) -(void)printf(%8d %s, j, memname); - else -(void)printf(,); - if (len = 80) { -(void)printf(\n\t ); -len = 10 + strlen(memname); - } - if (!first) -(void)printf( %s, memname); - first = 0; - } - (void)putchar('\n'); - } - - (void)printf( - \nMemory statistics by typeType Kern\n); - (void)printf( - Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)\n); - for (kread(namelist, X_KMEMSTAT, ksp, sizeof(ksp)); - ksp != NULL; ksp = ks.ks_next) { - deref_kptr(ksp, ks, sizeof(ks), malloc type); - if (ks.ks_calls == 0) - continue; - deref_kptr(ks.ks_shortdesc, memname, - sizeof(memname), malloc type name); - (void)printf(%15s %5ld %6ldK %6ldK %6ldK %10ld %5u %5u, - memname, - ks.ks_inuse, howmany(ks.ks_memuse, KILO), - howmany(ks.ks_maxused, KILO), -
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Sat Oct 15 21:06:05 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: unbreak -f -H -h, etc, part 1 - get nlist once in the beginning and fix the flags. Not each time! It is not like the kernel will change it symbols in the middle of the run. To generate a diff of this commit: cvs rdiff -u -r1.184 -r1.185 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.184 src/usr.bin/vmstat/vmstat.c:1.185 --- src/usr.bin/vmstat/vmstat.c:1.184 Wed Sep 21 08:08:02 2011 +++ src/usr.bin/vmstat/vmstat.c Sat Oct 15 17:06:05 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.184 2011/09/21 12:08:02 jym Exp $ */ +/* $NetBSD: vmstat.c,v 1.185 2011/10/15 21:06:05 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.184 2011/09/21 12:08:02 jym Exp $); +__RCSID($NetBSD: vmstat.c,v 1.185 2011/10/15 21:06:05 christos Exp $); #endif #endif /* not lint */ @@ -266,18 +266,18 @@ int winlines = 20; kvm_t *kd; -#define FORKSTAT 10 -#define INTRSTAT 11 -#define MEMSTAT 12 -#define SUMSTAT 13 -#define EVCNTSTAT 14 -#define VMSTAT 15 -#define HISTLIST 16 -#define HISTDUMP 17 -#define HASHSTAT 18 -#define HASHLIST 19 -#define VMTOTAL 110 -#define POOLCACHESTAT 111 +#define FORKSTAT 0x001 +#define INTRSTAT 0x002 +#define MEMSTAT 0x004 +#define SUMSTAT 0x008 +#define EVCNTSTAT 0x010 +#define VMSTAT 0x020 +#define HISTLIST 0x040 +#define HISTDUMP 0x080 +#define HASHSTAT 0x100 +#define HASHLIST 0x200 +#define VMTOTAL 0x400 +#define POOLCACHESTAT 0x800 /* * Print single word. `ovflow' is number of characters didn't fit @@ -473,6 +473,7 @@ main(int argc, char *argv[]) interval.tv_sec = 1; + getnlist(todo); /* * Statistics dumping is incompatible with the default * VMSTAT/dovmstat() output. So perform the interval/reps handling @@ -543,9 +544,7 @@ void getnlist(int todo) { static int namelist_done = 0; - static int hash_done = 0; - static int hist_done = 0; - static int intr_done = 0; + static int done = 0; int c; size_t i; @@ -576,17 +575,17 @@ getnlist(int todo) } } } - if ((todo INTRSTAT) !intr_done) { - intr_done = 1; + if ((todo (SUMSTAT|INTRSTAT)) !(done (SUMSTAT|INTRSTAT))) { + done |= SUMSTAT|INTRSTAT; (void) kvm_nlist(kd, intrnl); } - if ((todo HASHLIST) !hash_done) { - hash_done = 1; + if ((todo (HASHLIST|HASHSTAT)) !(done (HASHLIST|HASHSTAT))) { + done |= HASHLIST|HASHSTAT; if ((c = kvm_nlist(kd, hashnl)) == -1 || c == X_HASHNL_SIZE) errx(1, kvm_nlist: %s %s, hashnl, kvm_geterr(kd)); } - if ((todo (HISTLIST|HISTDUMP)) !hist_done) { - hist_done = 1; + if ((todo (HISTLIST|HISTDUMP)) !(done (HISTLIST|HISTDUMP))) { + done |= HISTLIST|HISTDUMP; if (kvm_nlist(kd, histnl) == -1) errx(1, kvm_nlist: %s %s, histnl, kvm_geterr(kd)); } @@ -731,7 +730,6 @@ dovmstat(struct timespec *interval, int int pagesize = getpagesize(); int ovflw; - getnlist(VMSTAT); uptime = getuptime(); halfuptime = uptime / 2; (void)signal(SIGCONT, needhdr); @@ -867,8 +865,6 @@ dosum(void) int active_kernel; struct cpu_counter cc; - getnlist(INTRSTAT); - /* * The active and inactive variables * are now estimated by the kernel and sadly @@ -1005,7 +1001,6 @@ dosum(void) void doforkst(void) { - kread(namelist, X_UVMEXP, uvmexp, sizeof(uvmexp)); (void)printf(%u forks total\n, uvmexp.forks); @@ -1097,7 +1092,6 @@ dointr(int verbose) int nintr, inamlen; char *intrname, *ointrname; - getnlist(INTRSTAT); inttotal = 0; uptime = getuptime(); (void)printf(%-34s %16s %8s\n, interrupt, total, rate); @@ -1199,7 +1193,6 @@ doevcnt(int verbose, int type) return; } while (/*CONSTCOND*/ 0); - getnlist(EVCNTSTAT); kread(namelist, X_ALLEVENTS, allevents, sizeof allevents); evptr = TAILQ_FIRST(allevents); while (evptr) { @@ -1245,7 +1238,6 @@ domem(void) long totuse = 0, totfree = 0, totreq = 0; struct kmembuckets buckets[MINBUCKET + 16]; - getnlist(MEMSTAT); kread(namelist, X_KMEMBUCKETS, buckets, sizeof(buckets)); for (first = 1, i = MINBUCKET, kp = buckets[i]; i MINBUCKET + 16; i++, kp++) { @@ -1358,7 +1350,6 @@ dopool(int verbose, int wide) struct pool_allocator pa; char name[32], maxp[32]; - getnlist(MEMSTAT); kread(namelist, X_POOLHEAD, pool_head, sizeof(pool_head)); addr = TAILQ_FIRST(pool_head); @@ -1469,7 +1460,6 @@ dopoolcache(int verbose) size_t i; double p; - getnlist(POOLCACHESTAT); kread(namelist, X_POOLHEAD, pool_head, sizeof(pool_head)); addr = TAILQ_FIRST(pool_head); @@ -1595,7 +1585,6 @@ dohashstat(int verbose, int
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Sat Oct 15 21:59:48 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: use warn instead of perror. To generate a diff of this commit: cvs rdiff -u -r1.185 -r1.186 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.185 src/usr.bin/vmstat/vmstat.c:1.186 --- src/usr.bin/vmstat/vmstat.c:1.185 Sat Oct 15 17:06:05 2011 +++ src/usr.bin/vmstat/vmstat.c Sat Oct 15 17:59:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.185 2011/10/15 21:06:05 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.186 2011/10/15 21:59:48 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ __COPYRIGHT(@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.185 2011/10/15 21:06:05 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.186 2011/10/15 21:59:48 christos Exp $); #endif #endif /* not lint */ @@ -1153,7 +1153,7 @@ doevcnt(int verbose, int type) /* if the sysctl is unknown, try groveling */ if (error == ENOENT) break; -perror(sysctl: kern.evcnt); +warn(kern.evcnt); if (buf) free(buf); return;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: jym Date: Wed Sep 21 12:08:02 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Use __arraycount(), as done above. To generate a diff of this commit: cvs rdiff -u -r1.183 -r1.184 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.183 src/usr.bin/vmstat/vmstat.c:1.184 --- src/usr.bin/vmstat/vmstat.c:1.183 Tue Sep 6 18:44:46 2011 +++ src/usr.bin/vmstat/vmstat.c Wed Sep 21 12:08:02 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.183 2011/09/06 18:44:46 joerg Exp $ */ +/* $NetBSD: vmstat.c,v 1.184 2011/09/21 12:08:02 jym Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.183 2011/09/06 18:44:46 joerg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.184 2011/09/21 12:08:02 jym Exp $); #endif #endif /* not lint */ @@ -1486,8 +1486,7 @@ cpuhit = 0; cpumiss = 0; - for (i = 0; i sizeof(pc-pc_cpus) / sizeof(pc-pc_cpus[0]); - i++) { + for (i = 0; i __arraycount(pc-pc_cpus); i++) { if ((addr = pc-pc_cpus[i]) == NULL) continue; deref_kptr(addr, cc, sizeof(*cc),
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: joerg Date: Tue Sep 6 18:44:46 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Mark usage as static and __dead. To generate a diff of this commit: cvs rdiff -u -r1.182 -r1.183 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.182 src/usr.bin/vmstat/vmstat.c:1.183 --- src/usr.bin/vmstat/vmstat.c:1.182 Tue Jul 26 13:24:38 2011 +++ src/usr.bin/vmstat/vmstat.c Tue Sep 6 18:44:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.182 2011/07/26 13:24:38 yamt Exp $ */ +/* $NetBSD: vmstat.c,v 1.183 2011/09/06 18:44:46 joerg Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.182 2011/07/26 13:24:38 yamt Exp $); +__RCSID($NetBSD: vmstat.c,v 1.183 2011/09/06 18:44:46 joerg Exp $); #endif #endif /* not lint */ @@ -316,7 +316,7 @@ long getuptime(void); void printhdr(void); long pct(long, long); -void usage(void); +__dead static void usage(void); void doforkst(void); void hist_traverse(int, const char *); @@ -1881,7 +1881,7 @@ free(fn); } -void +static void usage(void) {
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Wed Aug 17 13:54:31 UTC 2011 Modified Files: src/usr.bin/vmstat: Makefile Log Message: document that we are using non-literal string formats. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/usr.bin/vmstat/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/Makefile diff -u src/usr.bin/vmstat/Makefile:1.29 src/usr.bin/vmstat/Makefile:1.30 --- src/usr.bin/vmstat/Makefile:1.29 Thu May 26 08:56:33 2011 +++ src/usr.bin/vmstat/Makefile Wed Aug 17 09:54:31 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.29 2011/05/26 12:56:33 joerg Exp $ +# $NetBSD: Makefile,v 1.30 2011/08/17 13:54:31 christos Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include bsd.own.mk @@ -14,5 +14,6 @@ BINMODE=2555 CWARNFLAGS.clang+= -Wno-format-extra-args +COPTS.vmstat.c += -Wno-format-nonliteral .include bsd.prog.mk
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: yamt Date: Tue Jul 26 13:24:38 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: dopoolcache: don't print unused caches unless verbose To generate a diff of this commit: cvs rdiff -u -r1.181 -r1.182 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.181 src/usr.bin/vmstat/vmstat.c:1.182 --- src/usr.bin/vmstat/vmstat.c:1.181 Tue May 17 04:18:07 2011 +++ src/usr.bin/vmstat/vmstat.c Tue Jul 26 13:24:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.181 2011/05/17 04:18:07 mrg Exp $ */ +/* $NetBSD: vmstat.c,v 1.182 2011/07/26 13:24:38 yamt Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.181 2011/05/17 04:18:07 mrg Exp $); +__RCSID($NetBSD: vmstat.c,v 1.182 2011/07/26 13:24:38 yamt Exp $); #endif #endif /* not lint */ @@ -304,7 +304,7 @@ void dointr(int verbose); void domem(void); void dopool(int, int); -void dopoolcache(void); +void dopoolcache(int); void dosum(void); void dovmstat(struct timespec *, int); void print_total_hdr(void); @@ -498,7 +498,7 @@ (void)putchar('\n'); } if (todo POOLCACHESTAT) { -dopoolcache(); +dopoolcache(verbose); (void)putchar('\n'); } if (todo SUMSTAT) { @@ -1456,7 +1456,7 @@ } void -dopoolcache(void) +dopoolcache(int verbose) { struct pool_cache pool_cache, *pc = pool_cache; pool_cache_cpu_t cache_cpu, *cc = cache_cpu; @@ -1480,6 +1480,8 @@ deref_kptr(pp-pr_wchan, name, sizeof(name), pool wait channel trashed); deref_kptr(pp-pr_cache, pc, sizeof(*pc), pool cache trashed); + if (pc-pc_misses == 0 !verbose) + continue; name[sizeof(name)-1] = '\0'; cpuhit = 0;
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: nakayama Date: Wed Feb 16 12:58:38 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Fix header, format and total count of system interrupt counters. To generate a diff of this commit: cvs rdiff -u -r1.179 -r1.180 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.179 src/usr.bin/vmstat/vmstat.c:1.180 --- src/usr.bin/vmstat/vmstat.c:1.179 Sat Feb 5 13:12:07 2011 +++ src/usr.bin/vmstat/vmstat.c Wed Feb 16 12:58:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.179 2011/02/05 13:12:07 mlelstv Exp $ */ +/* $NetBSD: vmstat.c,v 1.180 2011/02/16 12:58:38 nakayama Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.179 2011/02/05 13:12:07 mlelstv Exp $); +__RCSID($NetBSD: vmstat.c,v 1.180 2011/02/16 12:58:38 nakayama Exp $); #endif #endif /* not lint */ @@ -1137,7 +1137,9 @@ counttotal = 0; uptime = getuptime(); - (void)printf(%-34s %16s %8s %s\n, event, total, rate, type); + if (type == EVCNT_TYPE_ANY) + (void)printf(%-34s %16s %8s %s\n, event, total, rate, + type); if (memf == NULL) do { const int mib[4] = { CTL_KERN, KERN_EVCNT, type, @@ -1175,7 +1177,9 @@ while (evs last_evs buflen = sizeof(*evs)/sizeof(uint64_t) buflen = evs-ev_len) { - (void)printf(%s %s%*s %16PRIu64 %8PRIu64 %s\n, + (void)printf(type == EVCNT_TYPE_ANY ? + %s %s%*s %16PRIu64 %8PRIu64 %s\n : + %s %s%*s %16PRIu64 %8PRIu64\n, evs-ev_strings, evs-ev_strings + evs-ev_grouplen + 1, 34 - (evs-ev_grouplen + 1 + evs-ev_namelen), , @@ -1184,8 +1188,8 @@ (evs-ev_type __arraycount(evtypes) ? evtypes[evs-ev_type] : ?)); buflen -= evs-ev_len; + counttotal += evs-ev_count; evs = (const void *)((const uint64_t *)evs + evs-ev_len); - counttotal += evcnt.ev_count++; } free(buf); if (type != EVCNT_TYPE_ANY) @@ -1211,7 +1215,9 @@ deref_kptr(evcnt.ev_name, evname, (size_t)evcnt.ev_namelen + 1, event chain trashed); - (void)printf(%s %s%*s %16PRIu64 %8PRIu64 %s\n, + (void)printf(type == EVCNT_TYPE_ANY ? + %s %s%*s %16PRIu64 %8PRIu64 %s\n : + %s %s%*s %16PRIu64 %8PRIu64\n, evgroup, evname, 34 - (evcnt.ev_grouplen + 1 + evcnt.ev_namelen), , evcnt.ev_count, @@ -1219,7 +1225,7 @@ (evcnt.ev_type __arraycount(evtypes) ? evtypes[evcnt.ev_type] : ?)); - counttotal += evcnt.ev_count++; + counttotal += evcnt.ev_count; } if (type != EVCNT_TYPE_ANY) (void)printf(%-34s %16PRIu64 %8PRIu64\n,
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: mlelstv Date: Sat Feb 5 13:12:07 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: dosum also needs getnlist To generate a diff of this commit: cvs rdiff -u -r1.178 -r1.179 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.178 src/usr.bin/vmstat/vmstat.c:1.179 --- src/usr.bin/vmstat/vmstat.c:1.178 Mon Jan 31 19:41:19 2011 +++ src/usr.bin/vmstat/vmstat.c Sat Feb 5 13:12:07 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.178 2011/01/31 19:41:19 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.179 2011/02/05 13:12:07 mlelstv Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.178 2011/01/31 19:41:19 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.179 2011/02/05 13:12:07 mlelstv Exp $); #endif #endif /* not lint */ @@ -866,6 +866,8 @@ int active_kernel; struct cpu_counter cc; + getnlist(INTRSTAT); + /* * The active and inactive variables * are now estimated by the kernel and sadly
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: matt Date: Mon Jan 31 18:56:04 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Make sure to getnlist in dovmstat To generate a diff of this commit: cvs rdiff -u -r1.176 -r1.177 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.176 src/usr.bin/vmstat/vmstat.c:1.177 --- src/usr.bin/vmstat/vmstat.c:1.176 Sat Jan 29 18:10:08 2011 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 31 18:56:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.176 2011/01/29 18:10:08 matt Exp $ */ +/* $NetBSD: vmstat.c,v 1.177 2011/01/31 18:56:04 matt Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.176 2011/01/29 18:10:08 matt Exp $); +__RCSID($NetBSD: vmstat.c,v 1.177 2011/01/31 18:56:04 matt Exp $); #endif #endif /* not lint */ @@ -730,6 +730,7 @@ int pagesize = getpagesize(); int ovflw; + getnlist(VMSTAT); uptime = getuptime(); halfuptime = uptime / 2; (void)signal(SIGCONT, needhdr);
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Mon Jan 31 19:41:19 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: deal with detecting the first and last cpu differently. To generate a diff of this commit: cvs rdiff -u -r1.177 -r1.178 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.177 src/usr.bin/vmstat/vmstat.c:1.178 --- src/usr.bin/vmstat/vmstat.c:1.177 Mon Jan 31 13:56:04 2011 +++ src/usr.bin/vmstat/vmstat.c Mon Jan 31 14:41:19 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.177 2011/01/31 18:56:04 matt Exp $ */ +/* $NetBSD: vmstat.c,v 1.178 2011/01/31 19:41:19 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.177 2011/01/31 18:56:04 matt Exp $); +__RCSID($NetBSD: vmstat.c,v 1.178 2011/01/31 19:41:19 christos Exp $); #endif #endif /* not lint */ @@ -1036,7 +1036,7 @@ void cpucounters(struct cpu_counter *cc) { - struct cpu_info *ci; + struct cpu_info *ci, *first = NULL; (void)memset(cc, 0, sizeof(*cc)); CIRCLEQ_FOREACH(ci, cpu_queue, ci_data.cpu_qchain) { struct cpu_info tci; @@ -1047,9 +1047,8 @@ (void)memset(cc, 0, sizeof(*cc)); return; } - /* Found the fake element, done */ - if (tci.ci_data.cpu_qchain.cqe_prev == NULL) - break; + if (first == NULL) + first = tci.ci_data.cpu_qchain.cqe_prev; cc-nintr += tci.ci_data.cpu_nintr; cc-nsyscall += tci.ci_data.cpu_nsyscall; cc-nswtch = tci.ci_data.cpu_nswtch; @@ -1057,6 +1056,8 @@ cc-ntrap = tci.ci_data.cpu_ntrap; cc-nsoft = tci.ci_data.cpu_nsoft; ci = tci; + if (tci.ci_data.cpu_qchain.cqe_next == first) + break; } }
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: matt Date: Sat Jan 29 18:10:08 UTC 2011 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Defer nlist processing until we know we need to it. If everything can be obtained via sysctl, we can skip it entirely. This means we can run even if not setgid. getuptime will now use sysctl/clock_gettime if memf is NULL. doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to groveling if sysctl returns an error of ENOENT. dointr will call doevcnt to evcnt based intr stats. To generate a diff of this commit: cvs rdiff -u -r1.175 -r1.176 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.175 src/usr.bin/vmstat/vmstat.c:1.176 --- src/usr.bin/vmstat/vmstat.c:1.175 Sat Dec 25 23:36:59 2010 +++ src/usr.bin/vmstat/vmstat.c Sat Jan 29 18:10:08 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.175 2010/12/25 23:36:59 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.176 2011/01/29 18:10:08 matt Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.175 2010/12/25 23:36:59 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.176 2011/01/29 18:10:08 matt Exp $); #endif #endif /* not lint */ @@ -298,7 +298,7 @@ void cpucounters(struct cpu_counter *); void deref_kptr(const void *, void *, size_t, const char *); void drvstats(int *); -void doevcnt(int verbose); +void doevcnt(int verbose, int type); void dohashstat(int, int, const char *); void dointr(int verbose); void domem(void); @@ -311,6 +311,7 @@ void kread(struct nlist *, int, void *, size_t); int kreadc(struct nlist *, int, void *, size_t); void needhdr(int); +void getnlist(int); long getuptime(void); void printhdr(void); long pct(long, long); @@ -331,6 +332,8 @@ static const int vmmeter_mib[] = { CTL_VM, VM_METER }; static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 }; +static const int boottime_mib[] = { CTL_KERN, KERN_BOOTTIME }; +static char kvm_errbuf[_POSIX2_LINE_MAX]; int main(int argc, char *argv[]) @@ -338,10 +341,8 @@ int c, todo, verbose, wide; struct timespec interval; int reps; - char errbuf[_POSIX2_LINE_MAX]; gid_t egid = getegid(); const char *histname, *hashname; - size_t i; histname = hashname = NULL; (void)setegid(getgid()); @@ -430,39 +431,16 @@ else (void)setegid(egid); - kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); - if (kd == NULL) - errx(1, kvm_openfiles: %s, errbuf); + kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, kvm_errbuf); + if (kd == NULL) { + if (nlistf != NULL || memf != NULL) { + errx(1, kvm_openfiles: %s, kvm_errbuf); + } + } if (nlistf == NULL memf == NULL) (void)setgid(getgid()); - if ((c = kvm_nlist(kd, namelist)) != 0) { - int doexit = 0; - if (c == -1) - errx(1, kvm_nlist: %s %s, namelist, kvm_geterr(kd)); - for (i = 0; i sizeof(namelist) / sizeof(namelist[0])-1; i++) - if (namelist[i].n_type == 0 - i != X_TIME_SECOND - i != X_TIME) { -if (doexit++ == 0) - (void)fprintf(stderr, - %s: undefined symbols:, - getprogname()); -(void)fprintf(stderr, %s, -namelist[i].n_name); - } - if (doexit) { - (void)fputc('\n', stderr); - exit(1); - } - } - if (todo INTRSTAT) - (void) kvm_nlist(kd, intrnl); - 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; @@ -531,7 +509,7 @@ (void)putchar('\n'); } if (todo EVCNTSTAT) { -doevcnt(verbose); +doevcnt(verbose, EVCNT_TYPE_ANY); (void)putchar('\n'); } if (todo (HASHLIST|HASHSTAT)) { @@ -560,6 +538,59 @@ return 0; } +void +getnlist(int todo) +{ + static int namelist_done = 0; + static int hash_done = 0; + static int hist_done = 0; + static int intr_done = 0; + int c; + size_t i; + + if (kd == NULL) + errx(1, kvm_openfiles: %s, kvm_errbuf); + + if (!namelist_done) { + namelist_done = 1; + if ((c = kvm_nlist(kd, namelist)) != 0) { + int doexit = 0; + if (c == -1) +errx(1, kvm_nlist: %s %s, +namelist, kvm_geterr(kd)); + for (i = 0; i __arraycount(namelist)-1; i++) +if (namelist[i].n_type == 0 +i != X_TIME_SECOND +i != X_TIME) { + if (doexit++ == 0) + (void)fprintf(stderr, + %s: undefined symbols:, + getprogname()); + (void)fprintf(stderr, %s, + namelist[i].n_name); +} + if (doexit) { +(void)fputc('\n', stderr); +exit(1); + } + } + } + if ((todo INTRSTAT) !intr_done) { + intr_done = 1; + (void) kvm_nlist(kd, intrnl); + } + if
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Sat Dec 25 14:18:38 UTC 2010 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Don't crash on old kernels that don't have the new per cpu counters. To generate a diff of this commit: cvs rdiff -u -r1.172 -r1.173 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.172 src/usr.bin/vmstat/vmstat.c:1.173 --- src/usr.bin/vmstat/vmstat.c:1.172 Fri Dec 24 18:39:19 2010 +++ src/usr.bin/vmstat/vmstat.c Sat Dec 25 09:18:37 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.172 2010/12/24 23:39:19 enami Exp $ */ +/* $NetBSD: vmstat.c,v 1.173 2010/12/25 14:18:37 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.172 2010/12/24 23:39:19 enami Exp $); +__RCSID($NetBSD: vmstat.c,v 1.173 2010/12/25 14:18:37 christos Exp $); #endif #endif /* not lint */ @@ -983,7 +983,8 @@ != sizeof(tci)) { warnx(Can't read cpu info from %p (%s), ci, kvm_geterr(kd)); - continue; + (void)memset(cc, 0, sizeof(*cc)); + return; } /* Found the fake element, done */ if (tci.ci_data.cpu_qchain.cqe_prev == NULL)
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Sat Dec 25 20:50:36 UTC 2010 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST To generate a diff of this commit: cvs rdiff -u -r1.173 -r1.174 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.173 src/usr.bin/vmstat/vmstat.c:1.174 --- src/usr.bin/vmstat/vmstat.c:1.173 Sat Dec 25 09:18:37 2010 +++ src/usr.bin/vmstat/vmstat.c Sat Dec 25 15:50:36 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.173 2010/12/25 14:18:37 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.174 2010/12/25 20:50:36 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,13 +70,14 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.173 2010/12/25 14:18:37 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.174 2010/12/25 20:50:36 christos Exp $); #endif #endif /* not lint */ #define __POOL_EXPOSE #include sys/param.h +#include sys/types.h #include sys/mount.h #include sys/uio.h @@ -130,6 +131,18 @@ #include drvstats.h /* + * All this mess will go away once everything is converted. + */ +#ifdef __HAVE_CPU_DATA_FIRST +#include sys/cpu_data.h +struct xcpu_info { + struct cpu_data ci_data; +}; +# define CPU_INFO xcpu_info +#else +# define CPU_INFO cpu_info +#endif +/* * General namelist */ struct nlist namelist[] = @@ -247,6 +260,7 @@ kvm_t *kd; + #define FORKSTAT 10 #define INTRSTAT 11 #define MEMSTAT 12 @@ -975,10 +989,10 @@ void cpucounters(struct cpu_counter *cc) { - struct cpu_info *ci; + struct CPU_INFO *ci; (void)memset(cc, 0, sizeof(*cc)); CIRCLEQ_FOREACH(ci, cpu_queue, ci_data.cpu_qchain) { - struct cpu_info tci; + struct CPU_INFO tci; if ((size_t)kvm_read(kd, (u_long)ci, tci, sizeof(tci)) != sizeof(tci)) { warnx(Can't read cpu info from %p (%s),
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Sat Dec 25 23:36:59 UTC 2010 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: can't play games with structure names since cpu_data refers to cpu_info, so provide our own copy for everything. To generate a diff of this commit: cvs rdiff -u -r1.174 -r1.175 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.174 src/usr.bin/vmstat/vmstat.c:1.175 --- src/usr.bin/vmstat/vmstat.c:1.174 Sat Dec 25 15:50:36 2010 +++ src/usr.bin/vmstat/vmstat.c Sat Dec 25 18:36:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.174 2010/12/25 20:50:36 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.175 2010/12/25 23:36:59 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.174 2010/12/25 20:50:36 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.175 2010/12/25 23:36:59 christos Exp $); #endif #endif /* not lint */ @@ -95,7 +95,6 @@ #include sys/time.h #include sys/user.h #include sys/queue.h -#include sys/cpu.h #include uvm/uvm_extern.h #include uvm/uvm_stat.h @@ -134,13 +133,19 @@ * All this mess will go away once everything is converted. */ #ifdef __HAVE_CPU_DATA_FIRST -#include sys/cpu_data.h -struct xcpu_info { + +# include sys/cpu_data.h +struct cpu_info { struct cpu_data ci_data; }; -# define CPU_INFO xcpu_info +CIRCLEQ_HEAD(cpuqueue, cpu_info); +struct cpuqueue cpu_queue; + #else -# define CPU_INFO cpu_info + +# include sys/cpu.h +struct cpuqueue cpu_queue; + #endif /* * General namelist @@ -253,7 +258,6 @@ } cpucounter, ocpucounter; struct uvmexp uvmexp, ouvmexp; -struct cpuqueue cpu_queue; int ndrives; int winlines = 20; @@ -989,10 +993,10 @@ void cpucounters(struct cpu_counter *cc) { - struct CPU_INFO *ci; + struct cpu_info *ci; (void)memset(cc, 0, sizeof(*cc)); CIRCLEQ_FOREACH(ci, cpu_queue, ci_data.cpu_qchain) { - struct CPU_INFO tci; + struct cpu_info tci; if ((size_t)kvm_read(kd, (u_long)ci, tci, sizeof(tci)) != sizeof(tci)) { warnx(Can't read cpu info from %p (%s),
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: enami Date: Fri Dec 24 23:39:19 UTC 2010 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: We still need to update ouvmexp to output the differene from previous iteration. To generate a diff of this commit: cvs rdiff -u -r1.171 -r1.172 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.171 src/usr.bin/vmstat/vmstat.c:1.172 --- src/usr.bin/vmstat/vmstat.c:1.171 Mon Dec 20 04:25:03 2010 +++ src/usr.bin/vmstat/vmstat.c Fri Dec 24 23:39:19 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.171 2010/12/20 04:25:03 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.172 2010/12/24 23:39:19 enami Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.171 2010/12/20 04:25:03 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.172 2010/12/24 23:39:19 enami Exp $); #endif #endif /* not lint */ @@ -736,6 +736,7 @@ (void)fflush(stdout); if (reps = 0 --reps = 0) break; + ouvmexp = uvmexp; ocpucounter = cpucounter; uptime = interval-tv_sec; /*
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Mon Dec 20 04:25:03 UTC 2010 Modified Files: src/usr.bin/vmstat: Makefile vmstat.c Log Message: make this work with the per-cpu counters. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/usr.bin/vmstat/Makefile cvs rdiff -u -r1.170 -r1.171 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/Makefile diff -u src/usr.bin/vmstat/Makefile:1.27 src/usr.bin/vmstat/Makefile:1.28 --- src/usr.bin/vmstat/Makefile:1.27 Tue Apr 14 18:15:28 2009 +++ src/usr.bin/vmstat/Makefile Sun Dec 19 23:25:03 2010 @@ -1,9 +1,11 @@ -# $NetBSD: Makefile,v 1.27 2009/04/14 22:15:28 lukem Exp $ +# $NetBSD: Makefile,v 1.28 2010/12/20 04:25:03 christos Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 +.include bsd.own.mk USE_FORT?= yes # setgid PROG= vmstat +CPPFLAGS+=-D_KMEMUSER -I${NETBSDSRCDIR}/sys SRCS= drvstats.c vmstat.c MAN= vmstat.1 DPADD= ${LIBKVM} Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.170 src/usr.bin/vmstat/vmstat.c:1.171 --- src/usr.bin/vmstat/vmstat.c:1.170 Mon Oct 18 15:39:32 2010 +++ src/usr.bin/vmstat/vmstat.c Sun Dec 19 23:25:03 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.170 2010/10/18 19:39:32 christos Exp $ */ +/* $NetBSD: vmstat.c,v 1.171 2010/12/20 04:25:03 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.170 2010/10/18 19:39:32 christos Exp $); +__RCSID($NetBSD: vmstat.c,v 1.171 2010/12/20 04:25:03 christos Exp $); #endif #endif /* not lint */ @@ -93,6 +93,8 @@ #include sys/sysctl.h #include sys/time.h #include sys/user.h +#include sys/queue.h +#include sys/cpu.h #include uvm/uvm_extern.h #include uvm/uvm_stat.h @@ -154,7 +156,9 @@ { .n_name = _time_second }, #define X_TIME 10 { .n_name = _time }, -#define X_NL_SIZE 11 +#define X_CPU_QUEUE 11 + { .n_name = _cpu_queue }, +#define X_NL_SIZE 12 { .n_name = NULL }, }; @@ -226,7 +230,17 @@ #define KILO 1024 +struct cpu_counter { + uint64_t nintr; + uint64_t nsyscall; + uint64_t nswtch; + uint64_t nfault; + uint64_t ntrap; + uint64_t nsoft; +} cpucounter, ocpucounter; + struct uvmexp uvmexp, ouvmexp; +struct cpuqueue cpu_queue; int ndrives; int winlines = 20; @@ -263,6 +277,7 @@ } while (/* CONSTCOND */0) void cpustats(int *); +void cpucounters(struct cpu_counter *); void deref_kptr(const void *, void *, size_t, const char *); void drvstats(int *); void doevcnt(int verbose); @@ -664,6 +679,8 @@ if (!hz) kread(namelist, X_HZ, hz, sizeof(hz)); + kread(namelist, X_CPU_QUEUE, cpu_queue, sizeof(cpu_queue)); + for (hdrcnt = 1;;) { if (!--hdrcnt) printhdr(); @@ -687,6 +704,7 @@ (void)memset(total, 0, sizeof(total)); } } + cpucounters(cpucounter); ovflw = 0; PRWORD(ovflw, %*d, 2, 1, total.t_rq - 1); PRWORD(ovflw, %*d, 2, 1, total.t_dw + total.t_pw); @@ -695,7 +713,7 @@ PRWORD(ovflw, %*ld, 9, 1, pgtok(total.t_avm)); PRWORD(ovflw, %*ld, 7, 1, pgtok(total.t_free)); PRWORD(ovflw, %*ld, 5, 1, - rate(uvmexp.faults - ouvmexp.faults)); + rate(cpucounter.nfault - ocpucounter.nfault)); PRWORD(ovflw, %*ld, 4, 1, rate(uvmexp.pdreact - ouvmexp.pdreact)); PRWORD(ovflw, %*ld, 4, 1, @@ -708,17 +726,17 @@ rate(uvmexp.pdscans - ouvmexp.pdscans)); drvstats(ovflw); PRWORD(ovflw, %*ld, 5, 1, - rate(uvmexp.intrs - ouvmexp.intrs)); + rate(cpucounter.nintr - ocpucounter.nintr)); PRWORD(ovflw, %*ld, 5, 1, - rate(uvmexp.syscalls - ouvmexp.syscalls)); + rate(cpucounter.nsyscall - ocpucounter.nsyscall)); PRWORD(ovflw, %*ld, 4, 1, - rate(uvmexp.swtch - ouvmexp.swtch)); + rate(cpucounter.nswtch - ocpucounter.nswtch)); cpustats(ovflw); (void)putchar('\n'); (void)fflush(stdout); if (reps = 0 --reps = 0) break; - ouvmexp = uvmexp; + ocpucounter = cpucounter; uptime = interval-tv_sec; /* * We round upward to avoid losing low-frequency events @@ -784,6 +802,7 @@ struct uvmexp_sysctl uvmexp2; size_t ssize; int active_kernel; + struct cpu_counter cc; /* * The active and inactive variables @@ -832,12 +851,14 @@ (void)printf(%9u swap pages in use\n, uvmexp.swpginuse); (void)printf(%9u swap allocations\n, uvmexp.nswget); - (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); + kread(namelist, X_CPU_QUEUE, cpu_queue, sizeof(cpu_queue)); + cpucounters(cc); + (void)printf(%9 PRIu64 total faults taken\n, cc.nfault); +
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: christos Date: Mon Oct 18 19:39:33 UTC 2010 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: simplify and modernize: - make sysctl mibs static - use warn/warnx for warnings makes binary 4K smaller. To generate a diff of this commit: cvs rdiff -u -r1.169 -r1.170 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.169 src/usr.bin/vmstat/vmstat.c:1.170 --- src/usr.bin/vmstat/vmstat.c:1.169 Wed Jul 7 07:42:18 2010 +++ src/usr.bin/vmstat/vmstat.c Mon Oct 18 15:39:32 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.169 2010/07/07 11:42:18 pooka Exp $ */ +/* $NetBSD: vmstat.c,v 1.170 2010/10/18 19:39:32 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.169 2010/07/07 11:42:18 pooka Exp $); +__RCSID($NetBSD: vmstat.c,v 1.170 2010/10/18 19:39:32 christos Exp $); #endif #endif /* not lint */ @@ -296,6 +296,9 @@ /* allow old usage [vmstat 1] */ #define BACKWARD_COMPATIBILITY +static const int vmmeter_mib[] = { CTL_VM, VM_METER }; +static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 }; + int main(int argc, char *argv[]) { @@ -410,7 +413,9 @@ i != X_TIME_SECOND i != X_TIME) { if (doexit++ == 0) - (void)fprintf(stderr, vmstat: undefined symbols:); + (void)fprintf(stderr, + %s: undefined symbols:, + getprogname()); (void)fprintf(stderr, %s, namelist[i].n_name); } @@ -599,7 +604,6 @@ dovmtotal(struct timespec *interval, int reps) { struct vmtotal total; - int mib[2]; size_t size; (void)signal(SIGCONT, needhdr); @@ -608,16 +612,13 @@ if (!--hdrcnt) print_total_hdr(); if (memf != NULL) { - (void)printf( - Unable to get vmtotals from crash dump.\n); + warnx(Unable to get vmtotals from crash dump.); (void)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) { -(void)printf(Can't get vmtotals: %s\n, -strerror(errno)); + if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib), + total, size, NULL, 0) == -1) { +warn(Can't get vmtotals); (void)memset(total, 0, sizeof(total)); } } @@ -650,7 +651,6 @@ { struct vmtotal total; time_t uptime, halfuptime; - int mib[2]; size_t size; int pagesize = getpagesize(); int ovflw; @@ -677,16 +677,13 @@ * XXX Can't do this if we're reading a crash * XXX dump because they're lazily-calculated. */ - (void)printf( - Unable to get vmtotals from crash dump.\n); + warnx(Unable to get vmtotals from crash dump.); (void)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) { -(void)printf(Can't get vmtotals: %s\n, -strerror(errno)); + if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib), + total, size, NULL, 0) == -1) { +warn(Can't get vmtotals); (void)memset(total, 0, sizeof(total)); } } @@ -784,7 +781,6 @@ { struct nchstats nchstats; u_long nchtotal; - int mib[2]; struct uvmexp_sysctl uvmexp2; size_t ssize; int active_kernel; @@ -799,11 +795,9 @@ active_kernel = (memf == NULL); if (active_kernel) { /* only on active kernel */ - mib[0] = CTL_VM; - mib[1] = VM_UVMEXP2; - if (sysctl(mib, 2, uvmexp2, ssize, NULL, 0) 0) - fprintf(stderr, %s: sysctl vm.uvmexp2 failed: %s, -getprogname(), strerror(errno)); + if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), uvmexp2, + ssize, NULL, 0) == -1) + warn(sysctl vm.uvmexp2 failed); } kread(namelist, X_UVMEXP, uvmexp, sizeof(uvmexp));
CVS commit: src/usr.bin/vmstat
Module Name:src Committed By: pooka Date: Wed Jul 7 11:42:18 UTC 2010 Modified Files: src/usr.bin/vmstat: vmstat.c Log Message: Make i unsigned to mirror change to struct uvm_history To generate a diff of this commit: cvs rdiff -u -r1.168 -r1.169 src/usr.bin/vmstat/vmstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vmstat/vmstat.c diff -u src/usr.bin/vmstat/vmstat.c:1.168 src/usr.bin/vmstat/vmstat.c:1.169 --- src/usr.bin/vmstat/vmstat.c:1.168 Mon Apr 5 08:03:42 2010 +++ src/usr.bin/vmstat/vmstat.c Wed Jul 7 11:42:18 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: vmstat.c,v 1.168 2010/04/05 08:03:42 he Exp $ */ +/* $NetBSD: vmstat.c,v 1.169 2010/07/07 11:42:18 pooka Exp $ */ /*- * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = @(#)vmstat.c 8.2 (Berkeley) 3/1/95; #else -__RCSID($NetBSD: vmstat.c,v 1.168 2010/04/05 08:03:42 he Exp $); +__RCSID($NetBSD: vmstat.c,v 1.169 2010/07/07 11:42:18 pooka Exp $); #endif #endif /* not lint */ @@ -1671,7 +1671,7 @@ size_t histsize; char *fmt = NULL, *fn = NULL; size_t fmtlen = 0, fnlen = 0; - int i; + unsigned i; histsize = sizeof(struct uvm_history_ent) * histp-n;