aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/vmstat/vmstat.c
diff options
context:
space:
mode:
authorMatthew Dillon <dillon@FreeBSD.org>1999-02-13 09:59:24 +0000
committerMatthew Dillon <dillon@FreeBSD.org>1999-02-13 09:59:24 +0000
commit2e8c5eaef890d21d2138c4106d67ec4cc281654d (patch)
tree7286583ed18339f2cfaef80b6b05840d9661070e /usr.bin/vmstat/vmstat.c
parent7345cf9025eb95d813caacddb42601253a2d146a (diff)
downloadsrc-2e8c5eaef890d21d2138c4106d67ec4cc281654d.tar.gz
src-2e8c5eaef890d21d2138c4106d67ec4cc281654d.zip
Add -z option to vmstat to dump data from the zone allocator
Notes
Notes: svn path=/head/; revision=43962
Diffstat (limited to 'usr.bin/vmstat/vmstat.c')
-rw-r--r--usr.bin/vmstat/vmstat.c83
1 files changed, 73 insertions, 10 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index d2b77b50f824..3dcd44caba6d 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: vmstat.c,v 1.29 1998/10/28 06:41:24 jdp Exp $";
+ "$Id: vmstat.c,v 1.31 1999/02/10 00:46:27 ken Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -60,6 +60,7 @@ static const char rcsid[] =
#include <sys/vmmeter.h>
#include <vm/vm_param.h>
+#include <vm/vm_zone.h>
#include <ctype.h>
#include <err.h>
@@ -101,20 +102,22 @@ struct nlist namelist[] = {
{ "_kmemstatistics" },
#define X_KMEMBUCKETS 11
{ "_bucket" },
+#define X_ZLIST 12
+ { "_zlist" },
#ifdef notyet
-#define X_DEFICIT 12
+#define X_DEFICIT 13
{ "_deficit" },
-#define X_FORKSTAT 13
+#define X_FORKSTAT 14
{ "_forkstat" },
-#define X_REC 14
+#define X_REC 15
{ "_rectime" },
-#define X_PGIN 15
+#define X_PGIN 16
{ "_pgintime" },
-#define X_XSTATS 16
+#define X_XSTATS 17
{ "_xstats" },
-#define X_END 17
+#define X_END 18
#else
-#define X_END 14
+#define X_END 13
#endif
#if defined(hp300) || defined(luna68k)
#define X_HPDINIT (X_END)
@@ -166,8 +169,9 @@ kvm_t *kd;
#define SUMSTAT 0x08
#define TIMESTAT 0x10
#define VMSTAT 0x20
+#define ZMEMSTAT 0x40
-void cpustats(), dointr(), domem(), dosum();
+void cpustats(), dointr(), domem(), dozmem(), dosum();
void dovmstat(), kread(), usage();
#ifdef notyet
void dotimes(), doforkst();
@@ -190,7 +194,7 @@ main(argc, argv)
memf = nlistf = NULL;
interval = reps = todo = 0;
maxshowdevs = 2;
- while ((c = getopt(argc, argv, "c:fiM:mN:n:p:stw:")) != -1) {
+ while ((c = getopt(argc, argv, "c:fiM:mzN:n:p:stw:")) != -1) {
switch (c) {
case 'c':
reps = atoi(optarg);
@@ -211,6 +215,9 @@ main(argc, argv)
case 'm':
todo |= MEMSTAT;
break;
+ case 'z':
+ todo |= ZMEMSTAT;
+ break;
case 'N':
nlistf = optarg;
break;
@@ -316,6 +323,8 @@ main(argc, argv)
#endif
if (todo & MEMSTAT)
domem();
+ if (todo & ZMEMSTAT)
+ dozmem();
if (todo & SUMSTAT)
dosum();
#ifdef notyet
@@ -896,6 +905,60 @@ domem()
(totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
}
+void
+dozmem()
+{
+ vm_zone_t zonep;
+ int nmax = 512;
+ int zused_bytes = 0;
+ int ztotal_bytes = 0;
+
+ printf(
+ "\n"
+ "%-16s%-8s%-8s%-8s\n",
+ "ZONE",
+ "used",
+ "total",
+ "mem-use"
+ );
+
+ kread(X_ZLIST, &zonep, sizeof(zonep));
+ while (zonep != NULL && nmax) {
+ struct vm_zone zone;
+ char buf[32];
+ int n;
+
+ if (kvm_read(kd, (u_long)zonep, &zone, sizeof(zone)) != sizeof(zone))
+ break;
+ n = kvm_read(kd, (u_long)zone.zname, buf, sizeof(buf) - 1);
+ if (n < 0)
+ n = 0;
+ buf[n] = 0;
+
+ printf(
+ "%-15.15s %-7d %-7d %4d/%dK\n",
+ buf,
+ zone.ztotal - zone.zfreecnt,
+ zone.ztotal,
+ (zone.ztotal - zone.zfreecnt) * zone.zsize / 1024,
+ zone.ztotal * zone.zsize / 1024
+ );
+ zused_bytes += (zone.ztotal - zone.zfreecnt) * zone.zsize;
+ ztotal_bytes += zone.ztotal * zone.zsize;
+ --nmax;
+ zonep = zone.znext;
+ }
+ printf(
+ "------------------------------------------\n"
+ "%-15.15s %-7s %-7s %4d/%dK\n\n",
+ "TOTAL",
+ "",
+ "",
+ zused_bytes / 1024,
+ ztotal_bytes / 1024
+ );
+}
+
/*
* kread reads something from the kernel, given its nlist index.
*/