2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1980, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char copyright[] =
34 "@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
35 The Regents of the University of California. All rights reserved.\n";
40 static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
47 #include <sys/param.h>
50 #include <sys/namei.h>
51 #include <sys/malloc.h>
52 #include <sys/signal.h>
53 #include <sys/fcntl.h>
54 #include <sys/ioctl.h>
55 #include <sys/resource.h>
56 #include <sys/sysctl.h>
60 #include <sys/vmmeter.h>
63 #include <vm/vm_param.h>
84 #define VMSTAT_XO_VERSION "1"
86 static char da[] = "da";
88 enum x_stats { X_SUM, X_HZ, X_STATHZ, X_NCHSTATS, X_INTRNAMES, X_SINTRNAMES,
89 X_INTRCNT, X_SINTRCNT, X_NINTRCNT };
91 static struct nlist namelist[] = {
92 [X_SUM] = { .n_name = "_vm_cnt", },
93 [X_HZ] = { .n_name = "_hz", },
94 [X_STATHZ] = { .n_name = "_stathz", },
95 [X_NCHSTATS] = { .n_name = "_nchstats", },
96 [X_INTRNAMES] = { .n_name = "_intrnames", },
97 [X_SINTRNAMES] = { .n_name = "_sintrnames", },
98 [X_INTRCNT] = { .n_name = "_intrcnt", },
99 [X_SINTRCNT] = { .n_name = "_sintrcnt", },
100 [X_NINTRCNT] = { .n_name = "_nintrcnt", },
104 static struct devstat_match *matches;
105 static struct device_selection *dev_select;
106 static struct statinfo cur, last;
107 static devstat_select_mode select_mode;
108 static size_t size_cp_times;
109 static long *cur_cp_times, *last_cp_times;
110 static long generation, select_generation;
111 static int hz, hdrcnt, maxshowdevs;
112 static int num_devices, num_devices_specified;
113 static int num_matches, num_selected, num_selections;
114 static char **specified_devices;
116 static struct __vmmeter {
122 uint64_t v_vm_faults;
123 uint64_t v_io_faults;
124 uint64_t v_cow_faults;
125 uint64_t v_cow_optim;
130 uint64_t v_swappgsin;
131 uint64_t v_swappgsout;
134 uint64_t v_vnodepgsin;
135 uint64_t v_vnodepgsout;
137 uint64_t v_reactivated;
138 uint64_t v_pdwakeups;
140 uint64_t v_pdshortfalls;
148 uint64_t v_forkpages;
149 uint64_t v_vforkpages;
150 uint64_t v_rforkpages;
151 uint64_t v_kthreadpages;
154 u_int v_free_reserved;
159 u_long v_user_wire_count;
160 u_int v_active_count;
161 u_int v_inactive_target;
162 u_int v_inactive_count;
163 u_int v_laundry_count;
164 u_int v_pageout_free_min;
165 u_int v_interrupt_free_min;
169 #define VMSTAT_DEFAULT_LINES 20 /* Default number of `winlines'. */
170 static volatile sig_atomic_t wresized; /* Tty resized when non-zero. */
171 static int winlines = VMSTAT_DEFAULT_LINES; /* Current number of tty rows. */
180 #define FORKSTAT 0x01
181 #define INTRSTAT 0x02
184 #define TIMESTAT 0x10
186 #define ZMEMSTAT 0x40
189 static void cpustats(void);
190 static void pcpustats(u_long, int);
191 static void devstats(void);
192 static void doforkst(void);
193 static void dointr(unsigned int, int);
194 static void doobjstat(void);
195 static void dosum(void);
196 static void dovmstat(unsigned int, int);
197 static void domemstat_malloc(void);
198 static void domemstat_zone(void);
199 static void kread(int, void *, size_t);
200 static void kreado(int, void *, size_t, size_t);
201 static void kreadptr(uintptr_t, void *, size_t);
202 static void needhdr(int);
203 static void needresize(int);
204 static void doresize(void);
205 static void printhdr(int, u_long);
206 static void usage(void);
208 static long pct(long, long);
209 static long long getuptime(void);
211 static char **getdrivedata(char **);
214 main(int argc, char *argv[])
216 char *bp, *buf, *memf, *nlistf;
218 int bufsize, c, reps, todo;
220 unsigned int interval;
221 char errbuf[_POSIX2_LINE_MAX];
223 memf = nlistf = NULL;
224 interval = reps = todo = 0;
228 argc = xo_parse_args(argc, argv);
232 while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:oPp:sw:z")) != -1) {
266 maxshowdevs = atoi(optarg);
268 xo_errx(1, "number of devices %d is < 0",
275 if (devstat_buildmatch(optarg, &matches, &num_matches)
277 xo_errx(1, "%s", devstat_errbuf);
283 /* Convert to milliseconds. */
298 xo_set_version(VMSTAT_XO_VERSION);
303 kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
305 xo_errx(1, "kvm_openfiles: %s", errbuf);
309 if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) {
315 * 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not
316 * found try looking up older 'cnt' symbol.
318 if (namelist[X_SUM].n_type == 0 &&
319 strcmp(namelist[X_SUM].n_name, "_vm_cnt") == 0) {
320 namelist[X_SUM].n_name = "_cnt";
325 * 'nintrcnt' doesn't exist in older kernels, but
328 if (namelist[X_NINTRCNT].n_type == 0 && c == 1)
331 for (c = 0; c < (int)(nitems(namelist)); c++)
332 if (namelist[c].n_type == 0)
333 bufsize += strlen(namelist[c].n_name)
336 buf = bp = alloca(bufsize);
338 for (c = 0; c < (int)(nitems(namelist)); c++)
339 if (namelist[c].n_type == 0) {
342 len = strlen(namelist[c].n_name);
344 memcpy(bp, namelist[c].n_name, len);
348 xo_error("undefined symbols:\n", buf);
350 xo_warnx("kvm_nlist: %s", kvm_geterr(kd));
356 xo_errx(1, "Cannot use -P with crash dumps");
360 * Make sure that the userland devstat version matches the
361 * kernel devstat version. If not, exit and print a
362 * message informing the user of his mistake.
364 if (devstat_checkversion(NULL) < 0)
365 xo_errx(1, "%s", devstat_errbuf);
368 argv = getdrivedata(argv);
395 dointr(interval, reps);
397 dovmstat(interval, reps);
403 mysysctl(const char *name, void *oldp, size_t *oldlenp)
407 error = sysctlbyname(name, oldp, oldlenp, NULL, 0);
408 if (error != 0 && errno != ENOMEM)
409 xo_err(1, "sysctl(%s)", name);
414 getdrivedata(char **argv)
417 if ((num_devices = devstat_getnumdevs(NULL)) < 0)
418 xo_errx(1, "%s", devstat_errbuf);
420 cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
421 last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
423 if (devstat_getdevs(NULL, &cur) == -1)
424 xo_errx(1, "%s", devstat_errbuf);
426 num_devices = cur.dinfo->numdevs;
427 generation = cur.dinfo->generation;
429 specified_devices = malloc(sizeof(char *));
430 for (num_devices_specified = 0; *argv; ++argv) {
433 num_devices_specified++;
434 specified_devices = reallocf(specified_devices,
435 sizeof(char *) * num_devices_specified);
436 if (specified_devices == NULL) {
437 xo_errx(1, "%s", "reallocf (specified_devices)");
439 specified_devices[num_devices_specified - 1] = *argv;
443 if (nflag == 0 && maxshowdevs < num_devices_specified)
444 maxshowdevs = num_devices_specified;
447 * People are generally only interested in disk statistics when
448 * they're running vmstat. So, that's what we're going to give
449 * them if they don't specify anything by default. We'll also give
450 * them any other random devices in the system so that we get to
451 * maxshowdevs devices, if that many devices exist. If the user
452 * specifies devices on the command line, either through a pattern
453 * match or by naming them explicitly, we will give the user only
456 if ((num_devices_specified == 0) && (num_matches == 0)) {
457 if (devstat_buildmatch(da, &matches, &num_matches) != 0)
458 xo_errx(1, "%s", devstat_errbuf);
459 select_mode = DS_SELECT_ADD;
461 select_mode = DS_SELECT_ONLY;
464 * At this point, selectdevs will almost surely indicate that the
465 * device list has changed, so we don't look for return values of 0
466 * or 1. If we get back -1, though, there is an error.
468 if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
469 &select_generation, generation, cur.dinfo->devices,
470 num_devices, matches, num_matches, specified_devices,
471 num_devices_specified, select_mode,
472 maxshowdevs, 0) == -1)
473 xo_errx(1, "%s", devstat_errbuf);
478 /* Return system uptime in nanoseconds */
484 (void)clock_gettime(CLOCK_UPTIME, &sp);
485 return((long long)sp.tv_sec * 1000000000LL + sp.tv_nsec);
489 fill_vmmeter(struct __vmmeter *vmmp)
491 struct vmmeter vm_cnt;
495 kread(X_SUM, &vm_cnt, sizeof(vm_cnt));
496 #define GET_COUNTER(name) \
497 vmmp->name = kvm_counter_u64_fetch(kd, (u_long)vm_cnt.name)
498 GET_COUNTER(v_swtch);
500 GET_COUNTER(v_syscall);
503 GET_COUNTER(v_vm_faults);
504 GET_COUNTER(v_io_faults);
505 GET_COUNTER(v_cow_faults);
506 GET_COUNTER(v_cow_optim);
508 GET_COUNTER(v_ozfod);
509 GET_COUNTER(v_swapin);
510 GET_COUNTER(v_swapout);
511 GET_COUNTER(v_swappgsin);
512 GET_COUNTER(v_swappgsout);
513 GET_COUNTER(v_vnodein);
514 GET_COUNTER(v_vnodeout);
515 GET_COUNTER(v_vnodepgsin);
516 GET_COUNTER(v_vnodepgsout);
517 GET_COUNTER(v_intrans);
518 GET_COUNTER(v_tfree);
519 GET_COUNTER(v_forks);
520 GET_COUNTER(v_vforks);
521 GET_COUNTER(v_rforks);
522 GET_COUNTER(v_kthreads);
523 GET_COUNTER(v_forkpages);
524 GET_COUNTER(v_vforkpages);
525 GET_COUNTER(v_rforkpages);
526 GET_COUNTER(v_kthreadpages);
529 #define GET_VM_STATS(cat, name) do { \
530 size = sizeof(vmmp->name); \
531 mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size); \
534 GET_VM_STATS(sys, v_swtch);
535 GET_VM_STATS(sys, v_trap);
536 GET_VM_STATS(sys, v_syscall);
537 GET_VM_STATS(sys, v_intr);
538 GET_VM_STATS(sys, v_soft);
541 GET_VM_STATS(vm, v_vm_faults);
542 GET_VM_STATS(vm, v_io_faults);
543 GET_VM_STATS(vm, v_cow_faults);
544 GET_VM_STATS(vm, v_cow_optim);
545 GET_VM_STATS(vm, v_zfod);
546 GET_VM_STATS(vm, v_ozfod);
547 GET_VM_STATS(vm, v_swapin);
548 GET_VM_STATS(vm, v_swapout);
549 GET_VM_STATS(vm, v_swappgsin);
550 GET_VM_STATS(vm, v_swappgsout);
551 GET_VM_STATS(vm, v_vnodein);
552 GET_VM_STATS(vm, v_vnodeout);
553 GET_VM_STATS(vm, v_vnodepgsin);
554 GET_VM_STATS(vm, v_vnodepgsout);
555 GET_VM_STATS(vm, v_intrans);
556 GET_VM_STATS(vm, v_reactivated);
557 GET_VM_STATS(vm, v_pdwakeups);
558 GET_VM_STATS(vm, v_pdpages);
559 GET_VM_STATS(vm, v_pdshortfalls);
560 GET_VM_STATS(vm, v_dfree);
561 GET_VM_STATS(vm, v_pfree);
562 GET_VM_STATS(vm, v_tfree);
563 GET_VM_STATS(vm, v_page_size);
564 GET_VM_STATS(vm, v_page_count);
565 GET_VM_STATS(vm, v_free_reserved);
566 GET_VM_STATS(vm, v_free_target);
567 GET_VM_STATS(vm, v_free_min);
568 GET_VM_STATS(vm, v_free_count);
569 GET_VM_STATS(vm, v_wire_count);
570 GET_VM_STATS(vm, v_user_wire_count);
571 GET_VM_STATS(vm, v_active_count);
572 GET_VM_STATS(vm, v_inactive_target);
573 GET_VM_STATS(vm, v_inactive_count);
574 GET_VM_STATS(vm, v_laundry_count);
575 GET_VM_STATS(vm, v_pageout_free_min);
576 GET_VM_STATS(vm, v_interrupt_free_min);
577 /*GET_VM_STATS(vm, v_free_severe);*/
578 GET_VM_STATS(vm, v_forks);
579 GET_VM_STATS(vm, v_vforks);
580 GET_VM_STATS(vm, v_rforks);
581 GET_VM_STATS(vm, v_kthreads);
582 GET_VM_STATS(vm, v_forkpages);
583 GET_VM_STATS(vm, v_vforkpages);
584 GET_VM_STATS(vm, v_rforkpages);
585 GET_VM_STATS(vm, v_kthreadpages);
591 fill_vmtotal(struct vmtotal *vmtp)
597 xo_errx(1, "not implemented");
599 size = sizeof(*vmtp);
600 mysysctl("vm.vmtotal", vmtp, &size);
601 if (size != sizeof(*vmtp))
602 xo_errx(1, "vm.total size mismatch");
606 /* Determine how many cpu columns, and what index they are in kern.cp_times */
608 getcpuinfo(u_long *maskp, int *maxidp)
613 int empty, i, j, maxcpu, maxid, ncpus;
616 xo_errx(1, "not implemented");
619 size = sizeof(maxcpu);
620 mysysctl("kern.smp.maxcpus", &maxcpu, &size);
621 if (size != sizeof(maxcpu))
622 xo_errx(1, "sysctl kern.smp.maxcpus");
623 size = sizeof(long) * maxcpu * CPUSTATES;
624 times = malloc(size);
626 xo_err(1, "malloc %zd bytes", size);
627 mysysctl("kern.cp_times", times, &size);
628 maxid = (size / CPUSTATES / sizeof(long)) - 1;
629 for (i = 0; i <= maxid; i++) {
631 for (j = 0; empty && j < CPUSTATES; j++) {
632 if (times[i * CPUSTATES + j] != 0)
649 prthuman(const char *name, uint64_t val, int size, int flags)
654 snprintf(fmt, sizeof(fmt), "{:%s/%%*s}", name);
656 if (size < 5 || size > 9)
657 xo_errx(1, "doofus");
658 flags |= HN_NOSPACE | HN_DECIMAL;
659 humanize_number(buf, size, val, "", HN_AUTOSCALE, flags);
660 xo_attr("value", "%ju", (uintmax_t) val);
661 xo_emit(fmt, size, buf);
665 dovmstat(unsigned int interval, int reps)
667 struct clockinfo clockrate;
668 struct vmtotal total;
669 struct devinfo *tmp_dinfo;
672 time_t uptime, halfuptime;
673 int ncpus, maxid, rate_adj, retval;
675 uptime = getuptime() / 1000000000LL;
676 halfuptime = uptime / 2;
683 * If the user stops the program (control-Z) and then resumes it,
684 * print out the header again.
686 (void)signal(SIGCONT, needhdr);
689 * If our standard output is a tty, then install a SIGWINCH handler
690 * and set wresized so that our first iteration through the main
691 * vmstat loop will peek at the terminal's current rows to find out
692 * how many lines can fit in a screenful of output.
694 if (isatty(fileno(stdout)) != 0) {
696 (void)signal(SIGWINCH, needresize);
699 winlines = VMSTAT_DEFAULT_LINES;
703 if (namelist[X_STATHZ].n_type != 0 &&
704 namelist[X_STATHZ].n_value != 0)
705 kread(X_STATHZ, &hz, sizeof(hz));
707 kread(X_HZ, &hz, sizeof(hz));
709 size = sizeof(clockrate);
710 mysysctl("kern.clockrate", &clockrate, &size);
711 if (size != sizeof(clockrate))
712 xo_errx(1, "clockrate size mismatch");
717 ncpus = getcpuinfo(&cpumask, &maxid);
718 size_cp_times = sizeof(long) * (maxid + 1) * CPUSTATES;
719 cur_cp_times = calloc(1, size_cp_times);
720 last_cp_times = calloc(1, size_cp_times);
724 printhdr(maxid, cpumask);
726 if (kvm_getcptime(kd, cur.cp_time) < 0)
727 xo_errx(1, "kvm_getcptime: %s", kvm_geterr(kd));
729 size = sizeof(cur.cp_time);
730 mysysctl("kern.cp_time", &cur.cp_time, &size);
731 if (size != sizeof(cur.cp_time))
732 xo_errx(1, "cp_time size mismatch");
735 size = size_cp_times;
736 mysysctl("kern.cp_times", cur_cp_times, &size);
737 if (size != size_cp_times)
738 xo_errx(1, "cp_times mismatch");
741 tmp_dinfo = last.dinfo;
742 last.dinfo = cur.dinfo;
743 cur.dinfo = tmp_dinfo;
744 last.snap_time = cur.snap_time;
747 * Here what we want to do is refresh our device stats.
748 * getdevs() returns 1 when the device list has changed.
749 * If the device list has changed, we want to go through
750 * the selection process again, in case a device that we
751 * were previously displaying has gone away.
753 switch (devstat_getdevs(NULL, &cur)) {
755 xo_errx(1, "%s", devstat_errbuf);
758 num_devices = cur.dinfo->numdevs;
759 generation = cur.dinfo->generation;
761 retval = devstat_selectdevs(&dev_select, &num_selected,
762 &num_selections, &select_generation,
763 generation, cur.dinfo->devices,
764 num_devices, matches, num_matches,
766 num_devices_specified, select_mode,
770 xo_errx(1, "%s", devstat_errbuf);
773 printhdr(maxid, cpumask);
784 fill_vmtotal(&total);
785 xo_open_container("processes");
786 xo_emit("{:runnable/%2d} {:waiting/%2ld} "
787 "{:swapped-out/%2ld}", total.t_rq - 1, total.t_dw +
788 total.t_pw, total.t_sw);
789 xo_close_container("processes");
790 xo_open_container("memory");
791 #define vmstat_pgtok(a) ((uintmax_t)(a) * (sum.v_page_size >> 10))
792 #define rate(x) (unsigned long)(((x) * rate_adj + halfuptime) / uptime)
794 prthuman("available-memory",
795 total.t_avm * (uint64_t)sum.v_page_size, 5, HN_B);
796 prthuman("free-memory",
797 total.t_free * (uint64_t)sum.v_page_size, 5, HN_B);
798 prthuman("total-page-faults",
799 rate(sum.v_vm_faults - osum.v_vm_faults), 5, 0);
803 xo_emit("{:available-memory/%7ju}",
804 vmstat_pgtok(total.t_avm));
806 xo_emit("{:free-memory/%7ju}",
807 vmstat_pgtok(total.t_free));
809 xo_emit("{:total-page-faults/%5lu} ",
810 rate(sum.v_vm_faults - osum.v_vm_faults));
812 xo_close_container("memory");
814 xo_open_container("paging-rates");
815 xo_emit("{:page-reactivated/%3lu} ",
816 rate(sum.v_reactivated - osum.v_reactivated));
817 xo_emit("{:paged-in/%3lu} ",
818 rate(sum.v_swapin + sum.v_vnodein -
819 (osum.v_swapin + osum.v_vnodein)));
820 xo_emit("{:paged-out/%3lu}",
821 rate(sum.v_swapout + sum.v_vnodeout -
822 (osum.v_swapout + osum.v_vnodeout)));
825 rate(sum.v_tfree - osum.v_tfree), 5, 0);
827 rate(sum.v_pdpages - osum.v_pdpages), 5, 0);
831 xo_emit("{:freed/%5lu} ",
832 rate(sum.v_tfree - osum.v_tfree));
833 xo_emit("{:scanned/%4lu} ",
834 rate(sum.v_pdpages - osum.v_pdpages));
836 xo_close_container("paging-rates");
839 xo_open_container("fault-rates");
840 xo_emit("{:interrupts/%4lu}", rate(sum.v_intr - osum.v_intr));
842 prthuman("system-calls",
843 rate(sum.v_syscall - osum.v_syscall), 5, 0);
844 prthuman("context-switches",
845 rate(sum.v_swtch - osum.v_swtch), 5, 0);
848 xo_emit("{:system-calls/%5lu} "
849 "{:context-switches/%5lu}",
850 rate(sum.v_syscall - osum.v_syscall),
851 rate(sum.v_swtch - osum.v_swtch));
853 xo_close_container("fault-rates");
855 pcpustats(cpumask, maxid);
860 if (reps >= 0 && --reps <= 0)
866 * We round upward to avoid losing low-frequency events
867 * (i.e., >= 1 per interval but < 1 per millisecond).
870 halfuptime = (uptime + 1) / 2;
873 (void)usleep(interval * 1000);
878 printhdr(int maxid, u_long cpumask)
882 num_shown = MIN(num_selected, maxshowdevs);
884 xo_emit(" {T:procs} {T:memory} {T:/page%*s}", 19, "");
886 xo_emit("{T:procs} {T:memory} {T:/page%*s}", 19, "");
888 xo_emit(" {T:/disks %*s} ", num_shown * 4 - 7, "");
889 else if (num_shown == 1)
890 xo_emit(" {T:disks}");
891 xo_emit(" {T:faults} ");
893 for (i = 0; i <= maxid; i++) {
894 if (cpumask & (1ul << i))
895 xo_emit(" {T:/cpu%d} ", i);
899 xo_emit(" {T:cpu}\n");
901 xo_emit(" {T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re}"
902 " {T:pi} {T:po} {T:fr} {T:sr} ");
904 xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} "
905 "{T:re} {T:pi} {T:po} {T:fr} {T:sr} ");
907 for (i = 0; i < num_devices; i++)
908 if ((dev_select[i].selected) &&
909 (dev_select[i].selected <= maxshowdevs))
910 xo_emit("{T:/%c%c%d} ", dev_select[i].device_name[0],
911 dev_select[i].device_name[1],
912 dev_select[i].unit_number);
913 xo_emit(" {T:in} {T:sy} {T:cs}");
915 for (i = 0; i <= maxid; i++) {
916 if (cpumask & (1ul << i))
917 xo_emit(" {T:us} {T:sy} {T:id}");
921 xo_emit(" {T:us} {T:sy} {T:id}\n");
928 * Force a header to be prepended to the next output.
931 needhdr(int dummy __unused)
938 * When the terminal is resized, force an update of the maximum number of rows
939 * printed between each header repetition. Then force a new header to be
940 * prepended to the next output.
943 needresize(int signo __unused)
951 * Update the global `winlines' count of terminal rows.
960 status = ioctl(fileno(stdout), TIOCGWINSZ, &w);
961 if (status == -1 && errno == EINTR)
963 else if (status == -1)
966 winlines = w.ws_row - 3;
968 winlines = VMSTAT_DEFAULT_LINES;
973 * Inhibit doresize() calls until we are rescheduled by SIGWINCH.
979 pct(long top, long bot)
985 ans = (quad_t)top * 100 / bot;
989 #define PCT(top, bot) pct((long)(top), (long)(bot))
994 struct nchstats lnchstats;
999 xo_open_container("summary-statistics");
1000 xo_emit("{:context-switches/%9u} {N:cpu context switches}\n",
1002 xo_emit("{:interrupts/%9u} {N:device interrupts}\n",
1004 xo_emit("{:software-interrupts/%9u} {N:software interrupts}\n",
1006 xo_emit("{:traps/%9u} {N:traps}\n", sum.v_trap);
1007 xo_emit("{:system-calls/%9u} {N:system calls}\n",
1009 xo_emit("{:kernel-threads/%9u} {N:kernel threads created}\n",
1011 xo_emit("{:forks/%9u} {N: fork() calls}\n", sum.v_forks);
1012 xo_emit("{:vforks/%9u} {N:vfork() calls}\n",
1014 xo_emit("{:rforks/%9u} {N:rfork() calls}\n",
1016 xo_emit("{:swap-ins/%9u} {N:swap pager pageins}\n",
1018 xo_emit("{:swap-in-pages/%9u} {N:swap pager pages paged in}\n",
1020 xo_emit("{:swap-outs/%9u} {N:swap pager pageouts}\n",
1022 xo_emit("{:swap-out-pages/%9u} {N:swap pager pages paged out}\n",
1024 xo_emit("{:vnode-page-ins/%9u} {N:vnode pager pageins}\n",
1026 xo_emit("{:vnode-page-in-pages/%9u} {N:vnode pager pages paged in}\n",
1028 xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pageouts}\n",
1030 xo_emit("{:vnode-page-out-pages/%9u} {N:vnode pager pages paged out}\n",
1032 xo_emit("{:page-daemon-wakeups/%9u} {N:page daemon wakeups}\n",
1034 xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page "
1035 "daemon}\n", sum.v_pdpages);
1036 xo_emit("{:page-reclamation-shortfalls/%9u} {N:clean page reclamation "
1037 "shortfalls}\n", sum.v_pdshortfalls);
1038 xo_emit("{:reactivated/%9u} {N:pages reactivated by the page daemon}\n",
1040 xo_emit("{:copy-on-write-faults/%9u} {N:copy-on-write faults}\n",
1042 xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write "
1043 "optimized faults}\n", sum.v_cow_optim);
1044 xo_emit("{:zero-fill-pages/%9u} {N:zero fill pages zeroed}\n",
1046 xo_emit("{:zero-fill-prezeroed/%9u} {N:zero fill pages prezeroed}\n",
1048 xo_emit("{:intransit-blocking/%9u} {N:intransit blocking page faults}\n",
1050 xo_emit("{:total-faults/%9u} {N:total VM faults taken}\n",
1052 xo_emit("{:faults-requiring-io/%9u} {N:page faults requiring I\\/O}\n",
1054 xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by "
1055 "kernel thread creation}\n", sum.v_kthreadpages);
1056 xo_emit("{:faults-from-fork/%9u} {N:pages affected by fork}()\n",
1058 xo_emit("{:faults-from-vfork/%9u} {N:pages affected by vfork}()\n",
1060 xo_emit("{:pages-rfork/%9u} {N:pages affected by rfork}()\n",
1062 xo_emit("{:pages-freed/%9u} {N:pages freed}\n",
1064 xo_emit("{:pages-freed-by-daemon/%9u} {N:pages freed by daemon}\n",
1066 xo_emit("{:pages-freed-on-exit/%9u} {N:pages freed by exiting processes}\n",
1068 xo_emit("{:active-pages/%9u} {N:pages active}\n",
1069 sum.v_active_count);
1070 xo_emit("{:inactive-pages/%9u} {N:pages inactive}\n",
1071 sum.v_inactive_count);
1072 xo_emit("{:laundry-pages/%9u} {N:pages in the laundry queue}\n",
1073 sum.v_laundry_count);
1074 xo_emit("{:wired-pages/%9u} {N:pages wired down}\n",
1076 xo_emit("{:virtual-user-wired-pages/%9lu} {N:virtual user pages wired "
1077 "down}\n", sum.v_user_wire_count);
1078 xo_emit("{:free-pages/%9u} {N:pages free}\n",
1080 xo_emit("{:bytes-per-page/%9u} {N:bytes per page}\n", sum.v_page_size);
1082 kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats));
1084 size = sizeof(lnchstats);
1085 mysysctl("vfs.cache.nchstats", &lnchstats, &size);
1086 if (size != sizeof(lnchstats))
1087 xo_errx(1, "vfs.cache.nchstats size mismatch");
1089 nchtotal = lnchstats.ncs_goodhits + lnchstats.ncs_neghits +
1090 lnchstats.ncs_badhits + lnchstats.ncs_falsehits +
1091 lnchstats.ncs_miss + lnchstats.ncs_long;
1092 xo_emit("{:total-name-lookups/%9ld} {N:total name lookups}\n",
1094 xo_emit("{P:/%9s} {N:cache hits} "
1095 "({:positive-cache-hits/%ld}% pos + "
1096 "{:negative-cache-hits/%ld}% {N:neg}) "
1097 "system {:cache-hit-percent/%ld}% per-directory\n",
1098 "", PCT(lnchstats.ncs_goodhits, nchtotal),
1099 PCT(lnchstats.ncs_neghits, nchtotal),
1100 PCT(lnchstats.ncs_pass2, nchtotal));
1101 xo_emit("{P:/%9s} {L:deletions} {:deletions/%ld}%, "
1102 "{L:falsehits} {:false-hits/%ld}%, "
1103 "{L:toolong} {:too-long/%ld}%\n", "",
1104 PCT(lnchstats.ncs_badhits, nchtotal),
1105 PCT(lnchstats.ncs_falsehits, nchtotal),
1106 PCT(lnchstats.ncs_long, nchtotal));
1107 xo_close_container("summary-statistics");
1115 xo_open_container("fork-statistics");
1116 xo_emit("{:fork/%u} {N:forks}, {:fork-pages/%u} {N:pages}, "
1117 "{L:average} {:fork-average/%.2f}\n",
1118 sum.v_forks, sum.v_forkpages,
1119 sum.v_forks == 0 ? 0.0 :
1120 (double)sum.v_forkpages / sum.v_forks);
1121 xo_emit("{:vfork/%u} {N:vforks}, {:vfork-pages/%u} {N:pages}, "
1122 "{L:average} {:vfork-average/%.2f}\n",
1123 sum.v_vforks, sum.v_vforkpages,
1124 sum.v_vforks == 0 ? 0.0 :
1125 (double)sum.v_vforkpages / sum.v_vforks);
1126 xo_emit("{:rfork/%u} {N:rforks}, {:rfork-pages/%u} {N:pages}, "
1127 "{L:average} {:rfork-average/%.2f}\n",
1128 sum.v_rforks, sum.v_rforkpages,
1129 sum.v_rforks == 0 ? 0.0 :
1130 (double)sum.v_rforkpages / sum.v_rforks);
1131 xo_close_container("fork-statistics");
1137 long double busy_seconds, transfers_per_second;
1141 for (state = 0; state < CPUSTATES; ++state) {
1142 tmp = cur.cp_time[state];
1143 cur.cp_time[state] -= last.cp_time[state];
1144 last.cp_time[state] = tmp;
1147 busy_seconds = cur.snap_time - last.snap_time;
1149 xo_open_list("device");
1150 for (dn = 0; dn < num_devices; dn++) {
1151 if (dev_select[dn].selected == 0 ||
1152 dev_select[dn].selected > maxshowdevs)
1155 di = dev_select[dn].position;
1157 if (devstat_compute_statistics(&cur.dinfo->devices[di],
1158 &last.dinfo->devices[di], busy_seconds,
1159 DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
1161 xo_errx(1, "%s", devstat_errbuf);
1163 xo_open_instance("device");
1164 xo_emit("{ekq:name/%c%c%d}{:transfers/%3.0Lf} ",
1165 dev_select[dn].device_name[0],
1166 dev_select[dn].device_name[1],
1167 dev_select[dn].unit_number,
1168 transfers_per_second);
1169 xo_close_instance("device");
1171 xo_close_list("device");
1175 percent(const char *name, double pctv, int *over)
1181 snprintf(fmt, sizeof(fmt), " {:%s/%%*s}", name);
1182 l = snprintf(buf, sizeof(buf), "%.0f", pctv);
1183 if (l == 1 && *over) {
1184 xo_emit(fmt, 1, buf);
1187 xo_emit(fmt, 2, buf);
1199 for (state = 0; state < CPUSTATES; ++state)
1200 total += cur.cp_time[state];
1202 lpct = 100.0 / total;
1206 xo_open_container("cpu-statistics");
1207 percent("user", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct,
1209 percent("system", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct,
1211 percent("idle", cur.cp_time[CP_IDLE] * lpct, &over);
1212 xo_close_container("cpu-statistics");
1216 pcpustats(u_long cpumask, int maxid)
1222 /* devstats does this for cp_time */
1223 for (i = 0; i <= maxid; i++) {
1224 if ((cpumask & (1ul << i)) == 0)
1226 for (state = 0; state < CPUSTATES; ++state) {
1227 tmp = cur_cp_times[i * CPUSTATES + state];
1228 cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i *
1230 last_cp_times[i * CPUSTATES + state] = tmp;
1235 xo_open_list("cpu");
1236 for (i = 0; i <= maxid; i++) {
1237 if ((cpumask & (1ul << i)) == 0)
1239 xo_open_instance("cpu");
1240 xo_emit("{ke:name/%d}", i);
1242 for (state = 0; state < CPUSTATES; ++state)
1243 total += cur_cp_times[i * CPUSTATES + state];
1245 lpct = 100.0 / total;
1248 percent("user", (cur_cp_times[i * CPUSTATES + CP_USER] +
1249 cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over);
1250 percent("system", (cur_cp_times[i * CPUSTATES + CP_SYS] +
1251 cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over);
1252 percent("idle", cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct,
1254 xo_close_instance("cpu");
1256 xo_close_list("cpu");
1260 read_intrcnts(unsigned long **intrcnts)
1266 kread(X_SINTRCNT, &intrcntlen, sizeof(intrcntlen));
1267 if ((*intrcnts = malloc(intrcntlen)) == NULL)
1269 if (namelist[X_NINTRCNT].n_type == 0)
1270 kread(X_INTRCNT, *intrcnts, intrcntlen);
1272 kread(X_INTRCNT, &kaddr, sizeof(kaddr));
1273 kreadptr(kaddr, *intrcnts, intrcntlen);
1276 for (*intrcnts = NULL, intrcntlen = 1024; ; intrcntlen *= 2) {
1277 *intrcnts = reallocf(*intrcnts, intrcntlen);
1278 if (*intrcnts == NULL)
1279 err(1, "reallocf()");
1280 if (mysysctl("hw.intrcnt", *intrcnts, &intrcntlen) == 0)
1285 return (intrcntlen / sizeof(unsigned long));
1289 print_intrcnts(unsigned long *intrcnts, unsigned long *old_intrcnts,
1290 char *intrnames, unsigned int nintr, size_t istrnamlen, long long period_ms)
1292 unsigned long *intrcnt, *old_intrcnt;
1294 uint64_t inttotal, old_inttotal, total_count, total_rate;
1295 unsigned long count, rate;
1300 intrname = intrnames;
1301 xo_open_list("interrupt");
1302 for (i = 0, intrcnt=intrcnts, old_intrcnt=old_intrcnts; i < nintr; i++) {
1303 if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) {
1304 count = *intrcnt - *old_intrcnt;
1305 rate = ((uint64_t)count * 1000 + period_ms / 2) / period_ms;
1306 xo_open_instance("interrupt");
1307 xo_emit("{d:name/%-*s}{ket:name/%s} "
1308 "{:total/%20lu} {:rate/%10lu}\n",
1309 (int)istrnamlen, intrname, intrname, count, rate);
1310 xo_close_instance("interrupt");
1312 intrname += strlen(intrname) + 1;
1313 inttotal += *intrcnt++;
1314 old_inttotal += *old_intrcnt++;
1316 total_count = inttotal - old_inttotal;
1317 total_rate = (total_count * 1000 + period_ms / 2) / period_ms;
1318 xo_close_list("interrupt");
1319 xo_emit("{L:/%-*s} {:total-interrupts/%20ju} "
1320 "{:total-rate/%10ju}\n", (int)istrnamlen,
1321 "Total", (uintmax_t)total_count, (uintmax_t)total_rate);
1325 dointr(unsigned int interval, int reps)
1327 unsigned long *intrcnts, *old_intrcnts;
1328 char *intrname, *intrnames;
1329 long long period_ms, old_uptime, uptime;
1330 size_t clen, inamlen, istrnamlen;
1334 old_intrcnts = NULL;
1335 uptime = getuptime();
1337 /* Get the names of each interrupt source */
1339 kread(X_SINTRNAMES, &inamlen, sizeof(inamlen));
1340 if ((intrnames = malloc(inamlen)) == NULL)
1341 xo_err(1, "malloc()");
1342 if (namelist[X_NINTRCNT].n_type == 0)
1343 kread(X_INTRNAMES, intrnames, inamlen);
1345 kread(X_INTRNAMES, &kaddr, sizeof(kaddr));
1346 kreadptr(kaddr, intrnames, inamlen);
1349 for (intrnames = NULL, inamlen = 1024; ; inamlen *= 2) {
1350 if ((intrnames = reallocf(intrnames, inamlen)) == NULL)
1351 xo_err(1, "reallocf()");
1352 if (mysysctl("hw.intrnames", intrnames, &inamlen) == 0)
1357 /* Determine the length of the longest interrupt name */
1358 intrname = intrnames;
1359 istrnamlen = strlen("interrupt");
1360 while(*intrname != '\0') {
1361 clen = strlen(intrname);
1362 if (clen > istrnamlen)
1364 intrname += strlen(intrname) + 1;
1366 xo_emit("{T:/%-*s} {T:/%20s} {T:/%10s}\n",
1367 (int)istrnamlen, "interrupt", "total", "rate");
1370 * Loop reps times printing differential interrupt counts. If reps is
1371 * zero, then run just once, printing total counts
1373 xo_open_container("interrupt-statistics");
1375 period_ms = uptime / 1000000;
1377 nintr = read_intrcnts(&intrcnts);
1379 * Initialize old_intrcnts to 0 for the first pass, so
1380 * print_intrcnts will print total interrupts since boot
1382 if (old_intrcnts == NULL) {
1383 old_intrcnts = calloc(nintr, sizeof(unsigned long));
1384 if (old_intrcnts == NULL)
1385 xo_err(1, "calloc()");
1388 print_intrcnts(intrcnts, old_intrcnts, intrnames, nintr,
1389 istrnamlen, period_ms);
1393 old_intrcnts = intrcnts;
1394 if (reps >= 0 && --reps <= 0)
1396 usleep(interval * 1000);
1397 old_uptime = uptime;
1398 uptime = getuptime();
1399 period_ms = (uptime - old_uptime) / 1000000;
1402 xo_close_container("interrupt-statistics");
1406 domemstat_malloc(void)
1408 struct memory_type_list *mtlp;
1409 struct memory_type *mtp;
1413 mtlp = memstat_mtl_alloc();
1415 xo_warn("memstat_mtl_alloc");
1419 if (memstat_sysctl_malloc(mtlp, 0) < 0) {
1420 xo_warnx("memstat_sysctl_malloc: %s",
1421 memstat_strerror(memstat_mtl_geterror(mtlp)));
1425 if (memstat_kvm_malloc(mtlp, kd) < 0) {
1426 error = memstat_mtl_geterror(mtlp);
1427 if (error == MEMSTAT_ERROR_KVM)
1428 xo_warnx("memstat_kvm_malloc: %s",
1431 xo_warnx("memstat_kvm_malloc: %s",
1432 memstat_strerror(error));
1435 xo_open_container("malloc-statistics");
1436 xo_emit("{T:/%13s} {T:/%5s} {T:/%6s} {T:/%8s} {T:Size(s)}\n",
1437 "Type", "InUse", "MemUse", "Requests");
1438 xo_open_list("memory");
1439 zones = memstat_malloc_zone_get_count();
1440 for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
1441 mtp = memstat_mtl_next(mtp)) {
1442 if (memstat_get_numallocs(mtp) == 0 &&
1443 memstat_get_count(mtp) == 0)
1445 xo_open_instance("memory");
1446 xo_emit("{k:type/%13s/%s} {:in-use/%5ju} "
1447 "{:memory-use/%5ju}{U:K} {:requests/%8ju} ",
1448 memstat_get_name(mtp), (uintmax_t)memstat_get_count(mtp),
1449 ((uintmax_t)memstat_get_bytes(mtp) + 1023) / 1024,
1450 (uintmax_t)memstat_get_numallocs(mtp));
1452 xo_open_list("size");
1453 for (i = 0; i < zones; i++) {
1454 if (memstat_malloc_zone_used(mtp, i)) {
1457 xo_emit("{l:size/%d}", memstat_malloc_zone_get_size(i));
1461 xo_close_list("size");
1462 xo_close_instance("memory");
1465 xo_close_list("memory");
1466 xo_close_container("malloc-statistics");
1467 memstat_mtl_free(mtlp);
1471 domemstat_zone(void)
1473 struct memory_type_list *mtlp;
1474 struct memory_type *mtp;
1476 char name[MEMTYPE_MAXNAME + 1];
1478 mtlp = memstat_mtl_alloc();
1480 xo_warn("memstat_mtl_alloc");
1484 if (memstat_sysctl_uma(mtlp, 0) < 0) {
1485 xo_warnx("memstat_sysctl_uma: %s",
1486 memstat_strerror(memstat_mtl_geterror(mtlp)));
1490 if (memstat_kvm_uma(mtlp, kd) < 0) {
1491 error = memstat_mtl_geterror(mtlp);
1492 if (error == MEMSTAT_ERROR_KVM)
1493 xo_warnx("memstat_kvm_uma: %s",
1496 xo_warnx("memstat_kvm_uma: %s",
1497 memstat_strerror(error));
1500 xo_open_container("memory-zone-statistics");
1501 xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} {T:/%8s}"
1502 "{T:/%4s} {T:/%4s}\n", "ITEM", "SIZE",
1503 "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP", "XDOMAIN");
1504 xo_open_list("zone");
1505 for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
1506 mtp = memstat_mtl_next(mtp)) {
1507 strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME);
1509 xo_open_instance("zone");
1510 xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6ju}, "
1511 "{:limit/%6ju},{:used/%8ju},"
1512 "{:free/%8ju},{:requests/%8ju},"
1513 "{:fail/%4ju},{:sleep/%4ju},{:xdomain/%4ju}\n", name,
1514 memstat_get_name(mtp),
1515 (uintmax_t)memstat_get_size(mtp),
1516 (uintmax_t)memstat_get_countlimit(mtp),
1517 (uintmax_t)memstat_get_count(mtp),
1518 (uintmax_t)memstat_get_free(mtp),
1519 (uintmax_t)memstat_get_numallocs(mtp),
1520 (uintmax_t)memstat_get_failures(mtp),
1521 (uintmax_t)memstat_get_sleeps(mtp),
1522 (uintmax_t)memstat_get_xdomain(mtp));
1523 xo_close_instance("zone");
1525 memstat_mtl_free(mtlp);
1526 xo_close_list("zone");
1527 xo_close_container("memory-zone-statistics");
1531 display_object(struct kinfo_vmobject *kvo)
1535 xo_open_instance("object");
1536 xo_emit("{:resident/%5ju} ", (uintmax_t)kvo->kvo_resident);
1537 xo_emit("{:active/%5ju} ", (uintmax_t)kvo->kvo_active);
1538 xo_emit("{:inactive/%5ju} ", (uintmax_t)kvo->kvo_inactive);
1539 xo_emit("{:refcount/%3d} ", kvo->kvo_ref_count);
1540 xo_emit("{:shadowcount/%3d} ", kvo->kvo_shadow_count);
1541 switch (kvo->kvo_memattr) {
1542 #ifdef VM_MEMATTR_UNCACHEABLE
1543 case VM_MEMATTR_UNCACHEABLE:
1547 #ifdef VM_MEMATTR_WRITE_COMBINING
1548 case VM_MEMATTR_WRITE_COMBINING:
1552 #ifdef VM_MEMATTR_WRITE_THROUGH
1553 case VM_MEMATTR_WRITE_THROUGH:
1557 #ifdef VM_MEMATTR_WRITE_PROTECTED
1558 case VM_MEMATTR_WRITE_PROTECTED:
1562 #ifdef VM_MEMATTR_WRITE_BACK
1563 case VM_MEMATTR_WRITE_BACK:
1567 #ifdef VM_MEMATTR_WEAK_UNCACHEABLE
1568 case VM_MEMATTR_WEAK_UNCACHEABLE:
1572 #ifdef VM_MEMATTR_WB_WA
1573 case VM_MEMATTR_WB_WA:
1577 #ifdef VM_MEMATTR_NOCACHE
1578 case VM_MEMATTR_NOCACHE:
1582 #ifdef VM_MEMATTR_DEVICE
1583 case VM_MEMATTR_DEVICE:
1587 #ifdef VM_MEMATTR_CACHEABLE
1588 case VM_MEMATTR_CACHEABLE:
1592 #ifdef VM_MEMATTR_PREFETCHABLE
1593 case VM_MEMATTR_PREFETCHABLE:
1601 xo_emit("{:attribute/%-3s} ", str);
1602 switch (kvo->kvo_type) {
1603 case KVME_TYPE_NONE:
1606 case KVME_TYPE_DEFAULT:
1609 case KVME_TYPE_VNODE:
1612 case KVME_TYPE_SWAP:
1615 case KVME_TYPE_DEVICE:
1618 case KVME_TYPE_PHYS:
1621 case KVME_TYPE_DEAD:
1627 case KVME_TYPE_MGTDEVICE:
1630 case KVME_TYPE_UNKNOWN:
1635 xo_emit("{:type/%-2s} ", str);
1636 xo_emit("{:path/%-s}\n", kvo->kvo_path);
1637 xo_close_instance("object");
1643 struct kinfo_vmobject *kvo;
1646 kvo = kinfo_getvmobject(&cnt);
1648 xo_warn("Failed to fetch VM object list");
1651 xo_emit("{T:RES/%5s} {T:ACT/%5s} {T:INACT/%5s} {T:REF/%3s} {T:SHD/%3s} "
1652 "{T:CM/%3s} {T:TP/%2s} {T:PATH/%s}\n");
1653 xo_open_list("object");
1654 for (i = 0; i < cnt; i++)
1655 display_object(&kvo[i]);
1657 xo_close_list("object");
1661 * kread reads something from the kernel, given its nlist index.
1664 kreado(int nlx, void *addr, size_t size, size_t offset)
1668 if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0) {
1669 sym = namelist[nlx].n_name;
1672 xo_errx(1, "symbol %s not defined", sym);
1674 if ((size_t)kvm_read(kd, namelist[nlx].n_value + offset, addr,
1676 sym = namelist[nlx].n_name;
1679 xo_errx(1, "%s: %s", sym, kvm_geterr(kd));
1684 kread(int nlx, void *addr, size_t size)
1687 kreado(nlx, addr, size, 0);
1691 kreadptr(uintptr_t addr, void *buf, size_t size)
1694 if ((size_t)kvm_read(kd, addr, buf, size) != size)
1695 xo_errx(1, "%s", kvm_geterr(kd));
1702 "usage: vmstat [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs]\n",
1703 " [-p type,if,pass] [-w wait] [disks] [wait [count]]\n");