2 * Copyright (c) 1980, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 static const char copyright
[] =
32 "@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
33 The Regents of the University of California. All rights reserved.\n";
38 static char sccsid
[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
45 #include <sys/param.h>
48 #include <sys/namei.h>
49 #include <sys/malloc.h>
50 #include <sys/signal.h>
51 #include <sys/fcntl.h>
52 #include <sys/ioctl.h>
53 #include <sys/resource.h>
54 #include <sys/sysctl.h>
57 #include <sys/vmmeter.h>
60 #include <vm/vm_param.h>
81 #define VMSTAT_XO_VERSION "1"
83 static char da
[] = "da";
85 static struct nlist namelist
[] = {
96 #define X_SINTRNAMES 5
103 #define X_DEFICIT XXX
118 static struct statinfo cur
, last
;
119 static int num_devices
, maxshowdevs
;
120 static long generation
;
121 static struct device_selection
*dev_select
;
122 static int num_selected
;
123 static struct devstat_match
*matches
;
124 static int num_matches
= 0;
125 static int num_devices_specified
, num_selections
;
126 static long select_generation
;
127 static char **specified_devices
;
128 static devstat_select_mode select_mode
;
130 static struct vmmeter sum
, osum
;
132 #define VMSTAT_DEFAULT_LINES 20 /* Default number of `winlines'. */
133 volatile sig_atomic_t wresized
; /* Tty resized, when non-zero. */
134 static int winlines
= VMSTAT_DEFAULT_LINES
; /* Current number of tty rows. */
143 #define FORKSTAT 0x01
144 #define INTRSTAT 0x02
147 #define TIMESTAT 0x10
149 #define ZMEMSTAT 0x40
152 static void cpustats(void);
153 static void pcpustats(int, u_long
, int);
154 static void devstats(void);
155 static void doforkst(void);
156 static void dointr(unsigned int, int);
157 static void doobjstat(void);
158 static void dosum(void);
159 static void dovmstat(unsigned int, int);
160 static void domemstat_malloc(void);
161 static void domemstat_zone(void);
162 static void kread(int, void *, size_t);
163 static void kreado(int, void *, size_t, size_t);
164 static char *kgetstr(const char *);
165 static void needhdr(int);
166 static void needresize(int);
167 static void doresize(void);
168 static void printhdr(int, u_long
);
169 static void usage(void);
171 static long pct(long, long);
172 static long long getuptime(void);
174 static char **getdrivedata(char **);
177 main(int argc
, char *argv
[])
180 unsigned int interval
;
184 char errbuf
[_POSIX2_LINE_MAX
];
186 memf
= nlistf
= NULL
;
187 interval
= reps
= todo
= 0;
191 argc
= xo_parse_args(argc
, argv
);
195 while ((c
= getopt(argc
, argv
, "ac:fhHiM:mN:n:oPp:stw:z")) != -1) {
229 maxshowdevs
= atoi(optarg
);
231 xo_errx(1, "number of devices %d is < 0",
238 if (devstat_buildmatch(optarg
, &matches
, &num_matches
) != 0)
239 xo_errx(1, "%s", devstat_errbuf
);
248 xo_errx(EX_USAGE
, "sorry, -t is not (re)implemented yet");
252 /* Convert to milliseconds. */
267 xo_set_version(VMSTAT_XO_VERSION
);
272 kd
= kvm_openfiles(nlistf
, memf
, NULL
, O_RDONLY
, errbuf
);
274 xo_errx(1, "kvm_openfiles: %s", errbuf
);
278 if (kd
!= NULL
&& (c
= kvm_nlist(kd
, namelist
)) != 0) {
280 int bufsize
= 0, len
= 0;
283 * 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not
284 * found try looking up older 'cnt' symbol.
286 if (namelist
[X_SUM
].n_type
== 0 &&
287 strcmp(namelist
[X_SUM
].n_name
, "_vm_cnt") == 0) {
288 namelist
[X_SUM
].n_name
= "_cnt";
292 c
< (int)(sizeof(namelist
)/sizeof(namelist
[0]));
294 if (namelist
[c
].n_type
== 0)
295 bufsize
+= strlen(namelist
[c
].n_name
) + 1;
297 buf
= bp
= alloca(bufsize
);
300 c
< (int)(sizeof(namelist
)/sizeof(namelist
[0]));
302 if (namelist
[c
].n_type
== 0) {
305 len
= strlen(namelist
[c
].n_name
);
307 memcpy(bp
, namelist
[c
].n_name
, len
);
311 xo_error("undefined symbols:\n", buf
);
313 xo_warnx("kvm_nlist: %s", kvm_geterr(kd
));
318 xo_errx(1, "Cannot use -P with crash dumps");
322 * Make sure that the userland devstat version matches the
323 * kernel devstat version. If not, exit and print a
324 * message informing the user of his mistake.
326 if (devstat_checkversion(NULL
) < 0)
327 xo_errx(1, "%s", devstat_errbuf
);
330 argv
= getdrivedata(argv
);
361 dointr(interval
, reps
);
363 dovmstat(interval
, reps
);
369 mysysctl(const char *name
, void *oldp
, size_t *oldlenp
,
370 void *newp
, size_t newlen
)
374 error
= sysctlbyname(name
, oldp
, oldlenp
, newp
, newlen
);
375 if (error
!= 0 && errno
!= ENOMEM
)
376 xo_err(1, "sysctl(%s)", name
);
381 getdrivedata(char **argv
)
383 if ((num_devices
= devstat_getnumdevs(NULL
)) < 0)
384 xo_errx(1, "%s", devstat_errbuf
);
386 cur
.dinfo
= (struct devinfo
*)calloc(1, sizeof(struct devinfo
));
387 last
.dinfo
= (struct devinfo
*)calloc(1, sizeof(struct devinfo
));
389 if (devstat_getdevs(NULL
, &cur
) == -1)
390 xo_errx(1, "%s", devstat_errbuf
);
392 num_devices
= cur
.dinfo
->numdevs
;
393 generation
= cur
.dinfo
->generation
;
395 specified_devices
= (char **)malloc(sizeof(char *));
396 for (num_devices_specified
= 0; *argv
; ++argv
) {
399 num_devices_specified
++;
400 specified_devices
= (char **)realloc(specified_devices
,
402 num_devices_specified
);
403 specified_devices
[num_devices_specified
- 1] = *argv
;
407 if (nflag
== 0 && maxshowdevs
< num_devices_specified
)
408 maxshowdevs
= num_devices_specified
;
411 * People are generally only interested in disk statistics when
412 * they're running vmstat. So, that's what we're going to give
413 * them if they don't specify anything by default. We'll also give
414 * them any other random devices in the system so that we get to
415 * maxshowdevs devices, if that many devices exist. If the user
416 * specifies devices on the command line, either through a pattern
417 * match or by naming them explicitly, we will give the user only
420 if ((num_devices_specified
== 0) && (num_matches
== 0)) {
421 if (devstat_buildmatch(da
, &matches
, &num_matches
) != 0)
422 xo_errx(1, "%s", devstat_errbuf
);
424 select_mode
= DS_SELECT_ADD
;
426 select_mode
= DS_SELECT_ONLY
;
429 * At this point, selectdevs will almost surely indicate that the
430 * device list has changed, so we don't look for return values of 0
431 * or 1. If we get back -1, though, there is an error.
433 if (devstat_selectdevs(&dev_select
, &num_selected
, &num_selections
,
434 &select_generation
, generation
, cur
.dinfo
->devices
,
435 num_devices
, matches
, num_matches
, specified_devices
,
436 num_devices_specified
, select_mode
,
437 maxshowdevs
, 0) == -1)
438 xo_errx(1, "%s", devstat_errbuf
);
443 /* Return system uptime in nanoseconds */
449 (void)clock_gettime(CLOCK_UPTIME
, &sp
);
451 return((long long)sp
.tv_sec
* 1000000000LL + sp
.tv_nsec
);
455 fill_pcpu(struct pcpu
***pcpup
, int* maxcpup
)
466 maxcpu
= kvm_getmaxcpu(kd
);
468 xo_errx(1, "kvm_getmaxcpu: %s", kvm_geterr(kd
));
470 pcpu
= calloc(maxcpu
, sizeof(struct pcpu
*));
474 for (i
= 0; i
< maxcpu
; i
++) {
475 pcpu
[i
] = kvm_getpcpu(kd
, i
);
476 if (pcpu
[i
] == (struct pcpu
*)-1)
477 xo_errx(1, "kvm_getpcpu: %s", kvm_geterr(kd
));
485 free_pcpu(struct pcpu
**pcpu
, int maxcpu
)
489 for (i
= 0; i
< maxcpu
; i
++)
495 fill_vmmeter(struct vmmeter
*vmmp
)
501 kread(X_SUM
, vmmp
, sizeof(*vmmp
));
502 fill_pcpu(&pcpu
, &maxcpu
);
503 for (i
= 0; i
< maxcpu
; i
++) {
506 #define ADD_FROM_PCPU(i, name) \
507 vmmp->name += pcpu[i]->pc_cnt.name
508 ADD_FROM_PCPU(i
, v_swtch
);
509 ADD_FROM_PCPU(i
, v_trap
);
510 ADD_FROM_PCPU(i
, v_syscall
);
511 ADD_FROM_PCPU(i
, v_intr
);
512 ADD_FROM_PCPU(i
, v_soft
);
513 ADD_FROM_PCPU(i
, v_vm_faults
);
514 ADD_FROM_PCPU(i
, v_io_faults
);
515 ADD_FROM_PCPU(i
, v_cow_faults
);
516 ADD_FROM_PCPU(i
, v_cow_optim
);
517 ADD_FROM_PCPU(i
, v_zfod
);
518 ADD_FROM_PCPU(i
, v_ozfod
);
519 ADD_FROM_PCPU(i
, v_swapin
);
520 ADD_FROM_PCPU(i
, v_swapout
);
521 ADD_FROM_PCPU(i
, v_swappgsin
);
522 ADD_FROM_PCPU(i
, v_swappgsout
);
523 ADD_FROM_PCPU(i
, v_vnodein
);
524 ADD_FROM_PCPU(i
, v_vnodeout
);
525 ADD_FROM_PCPU(i
, v_vnodepgsin
);
526 ADD_FROM_PCPU(i
, v_vnodepgsout
);
527 ADD_FROM_PCPU(i
, v_intrans
);
528 ADD_FROM_PCPU(i
, v_tfree
);
529 ADD_FROM_PCPU(i
, v_forks
);
530 ADD_FROM_PCPU(i
, v_vforks
);
531 ADD_FROM_PCPU(i
, v_rforks
);
532 ADD_FROM_PCPU(i
, v_kthreads
);
533 ADD_FROM_PCPU(i
, v_forkpages
);
534 ADD_FROM_PCPU(i
, v_vforkpages
);
535 ADD_FROM_PCPU(i
, v_rforkpages
);
536 ADD_FROM_PCPU(i
, v_kthreadpages
);
539 free_pcpu(pcpu
, maxcpu
);
541 size_t size
= sizeof(unsigned int);
542 #define GET_VM_STATS(cat, name) \
543 mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size, NULL, 0)
545 GET_VM_STATS(sys
, v_swtch
);
546 GET_VM_STATS(sys
, v_trap
);
547 GET_VM_STATS(sys
, v_syscall
);
548 GET_VM_STATS(sys
, v_intr
);
549 GET_VM_STATS(sys
, v_soft
);
552 GET_VM_STATS(vm
, v_vm_faults
);
553 GET_VM_STATS(vm
, v_io_faults
);
554 GET_VM_STATS(vm
, v_cow_faults
);
555 GET_VM_STATS(vm
, v_cow_optim
);
556 GET_VM_STATS(vm
, v_zfod
);
557 GET_VM_STATS(vm
, v_ozfod
);
558 GET_VM_STATS(vm
, v_swapin
);
559 GET_VM_STATS(vm
, v_swapout
);
560 GET_VM_STATS(vm
, v_swappgsin
);
561 GET_VM_STATS(vm
, v_swappgsout
);
562 GET_VM_STATS(vm
, v_vnodein
);
563 GET_VM_STATS(vm
, v_vnodeout
);
564 GET_VM_STATS(vm
, v_vnodepgsin
);
565 GET_VM_STATS(vm
, v_vnodepgsout
);
566 GET_VM_STATS(vm
, v_intrans
);
567 GET_VM_STATS(vm
, v_reactivated
);
568 GET_VM_STATS(vm
, v_pdwakeups
);
569 GET_VM_STATS(vm
, v_pdpages
);
570 GET_VM_STATS(vm
, v_tcached
);
571 GET_VM_STATS(vm
, v_dfree
);
572 GET_VM_STATS(vm
, v_pfree
);
573 GET_VM_STATS(vm
, v_tfree
);
574 GET_VM_STATS(vm
, v_page_size
);
575 GET_VM_STATS(vm
, v_page_count
);
576 GET_VM_STATS(vm
, v_free_reserved
);
577 GET_VM_STATS(vm
, v_free_target
);
578 GET_VM_STATS(vm
, v_free_min
);
579 GET_VM_STATS(vm
, v_free_count
);
580 GET_VM_STATS(vm
, v_wire_count
);
581 GET_VM_STATS(vm
, v_active_count
);
582 GET_VM_STATS(vm
, v_inactive_target
);
583 GET_VM_STATS(vm
, v_inactive_count
);
584 GET_VM_STATS(vm
, v_cache_count
);
585 GET_VM_STATS(vm
, v_pageout_free_min
);
586 GET_VM_STATS(vm
, v_interrupt_free_min
);
587 /*GET_VM_STATS(vm, v_free_severe);*/
588 GET_VM_STATS(vm
, v_forks
);
589 GET_VM_STATS(vm
, v_vforks
);
590 GET_VM_STATS(vm
, v_rforks
);
591 GET_VM_STATS(vm
, v_kthreads
);
592 GET_VM_STATS(vm
, v_forkpages
);
593 GET_VM_STATS(vm
, v_vforkpages
);
594 GET_VM_STATS(vm
, v_rforkpages
);
595 GET_VM_STATS(vm
, v_kthreadpages
);
601 fill_vmtotal(struct vmtotal
*vmtp
)
605 xo_errx(1, "not implemented");
607 size_t size
= sizeof(*vmtp
);
608 mysysctl("vm.vmtotal", vmtp
, &size
, NULL
, 0);
609 if (size
!= sizeof(*vmtp
))
610 xo_errx(1, "vm.total size mismatch");
614 /* Determine how many cpu columns, and what index they are in kern.cp_times */
616 getcpuinfo(u_long
*maskp
, int *maxidp
)
628 xo_errx(1, "not implemented");
631 size
= sizeof(maxcpu
);
632 mysysctl("kern.smp.maxcpus", &maxcpu
, &size
, NULL
, 0);
633 if (size
!= sizeof(maxcpu
))
634 xo_errx(1, "sysctl kern.smp.maxcpus");
635 size
= sizeof(long) * maxcpu
* CPUSTATES
;
636 times
= malloc(size
);
638 xo_err(1, "malloc %zd bytes", size
);
639 mysysctl("kern.cp_times", times
, &size
, NULL
, 0);
640 maxid
= (size
/ CPUSTATES
/ sizeof(long)) - 1;
641 for (i
= 0; i
<= maxid
; i
++) {
643 for (j
= 0; empty
&& j
< CPUSTATES
; j
++) {
644 if (times
[i
* CPUSTATES
+ j
] != 0)
661 prthuman(const char *name
, u_int64_t val
, int size
)
667 snprintf(fmt
, sizeof(fmt
), "{:%s/%%*s}", name
);
669 if (size
< 5 || size
> 9)
670 xo_errx(1, "doofus");
671 flags
= HN_B
| HN_NOSPACE
| HN_DECIMAL
;
672 humanize_number(buf
, size
, val
, "", HN_AUTOSCALE
, flags
);
673 xo_attr("value", "%ju", (uintmax_t) val
);
674 xo_emit(fmt
, size
, buf
);
677 static int hz
, hdrcnt
;
679 static long *cur_cp_times
;
680 static long *last_cp_times
;
681 static size_t size_cp_times
;
684 dovmstat(unsigned int interval
, int reps
)
686 struct vmtotal total
;
687 time_t uptime
, halfuptime
;
688 struct devinfo
*tmp_dinfo
;
694 uptime
= getuptime() / 1000000000LL;
695 halfuptime
= uptime
/ 2;
701 * If the user stops the program (control-Z) and then resumes it,
702 * print out the header again.
704 (void)signal(SIGCONT
, needhdr
);
707 * If our standard output is a tty, then install a SIGWINCH handler
708 * and set wresized so that our first iteration through the main
709 * vmstat loop will peek at the terminal's current rows to find out
710 * how many lines can fit in a screenful of output.
712 if (isatty(fileno(stdout
)) != 0) {
714 (void)signal(SIGWINCH
, needresize
);
717 winlines
= VMSTAT_DEFAULT_LINES
;
721 if (namelist
[X_STATHZ
].n_type
!= 0 &&
722 namelist
[X_STATHZ
].n_value
!= 0)
723 kread(X_STATHZ
, &hz
, sizeof(hz
));
725 kread(X_HZ
, &hz
, sizeof(hz
));
727 struct clockinfo clockrate
;
729 size
= sizeof(clockrate
);
730 mysysctl("kern.clockrate", &clockrate
, &size
, NULL
, 0);
731 if (size
!= sizeof(clockrate
))
732 xo_errx(1, "clockrate size mismatch");
737 ncpus
= getcpuinfo(&cpumask
, &maxid
);
738 size_cp_times
= sizeof(long) * (maxid
+ 1) * CPUSTATES
;
739 cur_cp_times
= calloc(1, size_cp_times
);
740 last_cp_times
= calloc(1, size_cp_times
);
744 printhdr(maxid
, cpumask
);
746 if (kvm_getcptime(kd
, cur
.cp_time
) < 0)
747 xo_errx(1, "kvm_getcptime: %s", kvm_geterr(kd
));
749 size
= sizeof(cur
.cp_time
);
750 mysysctl("kern.cp_time", &cur
.cp_time
, &size
, NULL
, 0);
751 if (size
!= sizeof(cur
.cp_time
))
752 xo_errx(1, "cp_time size mismatch");
755 size
= size_cp_times
;
756 mysysctl("kern.cp_times", cur_cp_times
, &size
, NULL
, 0);
757 if (size
!= size_cp_times
)
758 xo_errx(1, "cp_times mismatch");
761 tmp_dinfo
= last
.dinfo
;
762 last
.dinfo
= cur
.dinfo
;
763 cur
.dinfo
= tmp_dinfo
;
764 last
.snap_time
= cur
.snap_time
;
767 * Here what we want to do is refresh our device stats.
768 * getdevs() returns 1 when the device list has changed.
769 * If the device list has changed, we want to go through
770 * the selection process again, in case a device that we
771 * were previously displaying has gone away.
773 switch (devstat_getdevs(NULL
, &cur
)) {
775 xo_errx(1, "%s", devstat_errbuf
);
780 num_devices
= cur
.dinfo
->numdevs
;
781 generation
= cur
.dinfo
->generation
;
783 retval
= devstat_selectdevs(&dev_select
, &num_selected
,
784 &num_selections
, &select_generation
,
785 generation
, cur
.dinfo
->devices
,
786 num_devices
, matches
, num_matches
,
788 num_devices_specified
, select_mode
,
792 xo_errx(1, "%s", devstat_errbuf
);
795 printhdr(maxid
, cpumask
);
806 fill_vmtotal(&total
);
807 xo_open_container("processes");
808 xo_emit("{:runnable/%1d} {:waiting/%ld} "
809 "{:swapped-out/%ld}",
810 total
.t_rq
- 1, total
.t_dw
+ total
.t_pw
, total
.t_sw
);
811 xo_close_container("processes");
812 xo_open_container("memory");
813 #define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10))
814 #define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */
817 prthuman("available-memory",
818 total
.t_avm
* (u_int64_t
)sum
.v_page_size
, 5);
820 prthuman("free-memory",
821 total
.t_free
* (u_int64_t
)sum
.v_page_size
, 5);
825 xo_emit("{:available-memory/%7d}",
826 vmstat_pgtok(total
.t_avm
));
828 xo_emit("{:free-memory/%7d}",
829 vmstat_pgtok(total
.t_free
));
831 xo_emit("{:total-page-faults/%5lu} ",
832 (unsigned long)rate(sum
.v_vm_faults
-
834 xo_close_container("memory");
836 xo_open_container("paging-rates");
837 xo_emit("{:page-reactivated/%3lu} ",
838 (unsigned long)rate(sum
.v_reactivated
- osum
.v_reactivated
));
839 xo_emit("{:paged-in/%3lu} ",
840 (unsigned long)rate(sum
.v_swapin
+ sum
.v_vnodein
-
841 (osum
.v_swapin
+ osum
.v_vnodein
)));
842 xo_emit("{:paged-out/%3lu} ",
843 (unsigned long)rate(sum
.v_swapout
+ sum
.v_vnodeout
-
844 (osum
.v_swapout
+ osum
.v_vnodeout
)));
845 xo_emit("{:freed/%5lu} ",
846 (unsigned long)rate(sum
.v_tfree
- osum
.v_tfree
));
847 xo_emit("{:scanned/%4lu} ",
848 (unsigned long)rate(sum
.v_pdpages
- osum
.v_pdpages
));
849 xo_close_container("paging-rates");
852 xo_open_container("fault-rates");
853 xo_emit("{:interrupts/%4lu} {:system-calls/%5lu} "
854 "{:context-switches/%5u}",
855 (unsigned long)rate(sum
.v_intr
- osum
.v_intr
),
856 (unsigned long)rate(sum
.v_syscall
- osum
.v_syscall
),
857 (unsigned long)rate(sum
.v_swtch
- osum
.v_swtch
));
858 xo_close_container("fault-rates");
860 pcpustats(ncpus
, cpumask
, maxid
);
865 if (reps
>= 0 && --reps
<= 0)
871 * We round upward to avoid losing low-frequency events
872 * (i.e., >= 1 per interval but < 1 per millisecond).
875 halfuptime
= (uptime
+ 1) / 2;
878 (void)usleep(interval
* 1000);
883 printhdr(int maxid
, u_long cpumask
)
887 num_shown
= MIN(num_selected
, maxshowdevs
);
889 xo_emit("{T:procs} {T:memory} {T:/page%*s}", 19, "");
891 xo_emit("{T:procs} {T:memory} {T:/page%*s}", 19, "");
894 xo_emit(" {T:/disks %*s}", num_shown
* 4 - 7, "");
895 else if (num_shown
== 1)
896 xo_emit(" {T:disks}");
897 xo_emit(" {T:faults} ");
899 for (i
= 0; i
<= maxid
; i
++) {
900 if (cpumask
& (1ul << i
))
901 xo_emit(" {T:/cpu%d} ", i
);
905 xo_emit(" {T:cpu}\n");
907 xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re} {T:pi} {T:po} {T:fr} {T:sr} ");
909 xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re} {T:pi} {T:po} {T:fr} {T:sr} ");
911 for (i
= 0; i
< num_devices
; i
++)
912 if ((dev_select
[i
].selected
)
913 && (dev_select
[i
].selected
<= maxshowdevs
))
914 xo_emit("{T:/%c%c%d} ", dev_select
[i
].device_name
[0],
915 dev_select
[i
].device_name
[1],
916 dev_select
[i
].unit_number
);
917 xo_emit(" {T:in} {T:sy} {T:cs}");
919 for (i
= 0; i
<= maxid
; i
++) {
920 if (cpumask
& (1ul << i
))
921 xo_emit(" {T:us} {T:sy} {T:id}");
925 xo_emit(" {T:us} {T:sy} {T:id}\n");
932 * Force a header to be prepended to the next output.
935 needhdr(int dummy __unused
)
942 * When the terminal is resized, force an update of the maximum number of rows
943 * printed between each header repetition. Then force a new header to be
944 * prepended to the next output.
947 needresize(int signo
)
955 * Update the global `winlines' count of terminal rows.
964 status
= ioctl(fileno(stdout
), TIOCGWINSZ
, &w
);
965 if (status
== -1 && errno
== EINTR
)
967 else if (status
== -1)
970 winlines
= w
.ws_row
- 3;
972 winlines
= VMSTAT_DEFAULT_LINES
;
977 * Inhibit doresize() calls until we are rescheduled by SIGWINCH.
986 unsigned int pgintime
, rectime
;
988 kread(X_REC
, &rectime
, sizeof(rectime
));
989 kread(X_PGIN
, &pgintime
, sizeof(pgintime
));
990 kread(X_SUM
, &sum
, sizeof(sum
));
991 xo_emit("{:page-reclaims/%u} {N:reclaims}, "
992 "{:reclaim-time/%u} {N:total time (usec)}\n",
993 sum
.v_pgrec
, rectime
);
994 xo_emit("{L:average}: {:reclaim-average/%u} {N:usec \\/ reclaim}\n",
995 rectime
/ sum
.v_pgrec
);
997 xo_emit("{:page-ins/%u} {N:page ins}, "
998 "{:page-in-time/%u} {N:total time (msec)}\n",
999 sum
.v_pgin
, pgintime
/ 10);
1000 xo_emit("{L:average}: {:average/%8.1f} {N:msec \\/ page in}\n",
1001 pgintime
/ (sum
.v_pgin
* 10.0));
1006 pct(long top
, long bot
)
1012 ans
= (quad_t
)top
* 100 / bot
;
1016 #define PCT(top, bot) pct((long)(top), (long)(bot))
1021 struct nchstats lnchstats
;
1025 xo_open_container("summary-statistics");
1026 xo_emit("{:context-switches/%9u} {N:cpu context switches}\n",
1028 xo_emit("{:interrupts/%9u} {N:device interrupts}\n",
1030 xo_emit("{:software-interrupts/%9u} {N:software interrupts}\n",
1032 xo_emit("{:traps/%9u} {N:traps}\n", sum
.v_trap
);
1033 xo_emit("{:system-calls/%9u} {N:system calls}\n",
1035 xo_emit("{:kernel-threads/%9u} {N:kernel threads created}\n",
1037 xo_emit("{:forks/%9u} {N: fork() calls}\n", sum
.v_forks
);
1038 xo_emit("{:vforks/%9u} {N:vfork() calls}\n",
1040 xo_emit("{:rforks/%9u} {N:rfork() calls}\n",
1042 xo_emit("{:swap-ins/%9u} {N:swap pager pageins}\n",
1044 xo_emit("{:swap-in-pages/%9u} {N:swap pager pages paged in}\n",
1046 xo_emit("{:swap-outs/%9u} {N:swap pager pageouts}\n",
1048 xo_emit("{:swap-out-pages/%9u} {N:swap pager pages paged out}\n",
1050 xo_emit("{:vnode-page-ins/%9u} {N:vnode pager pageins}\n",
1052 xo_emit("{:vnode-page-in-pages/%9u} {N:vnode pager pages paged in}\n",
1054 xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pageouts}\n",
1056 xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pages paged out}\n",
1058 xo_emit("{:page-daemon-wakeups/%9u} {N:page daemon wakeups}\n",
1060 xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page daemon}\n",
1062 xo_emit("{:reactivated/%9u} {N:pages reactivated}\n",
1064 xo_emit("{:copy-on-write-faults/%9u} {N:copy-on-write faults}\n",
1066 xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write optimized faults}\n",
1068 xo_emit("{:zero-fill-pages/%9u} {N:zero fill pages zeroed}\n",
1070 xo_emit("{:zero-fill-prezeroed/%9u} {N:zero fill pages prezeroed}\n",
1072 xo_emit("{:intransit-blocking/%9u} {N:intransit blocking page faults}\n",
1074 xo_emit("{:total-faults/%9u} {N:total VM faults taken}\n",
1076 xo_emit("{:faults-requiring-io/%9u} {N:page faults requiring I\\/O}\n",
1078 xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by kernel thread creation}\n",
1079 sum
.v_kthreadpages
);
1080 xo_emit("{:faults-from-fork/%9u} {N:pages affected by fork}()\n",
1082 xo_emit("{:faults-from-vfork/%9u} {N:pages affected by vfork}()\n",
1084 xo_emit("{:pages-rfork/%9u} {N:pages affected by rfork}()\n",
1086 xo_emit("{:pages-total-cached/%9u} {N:pages cached}\n",
1088 xo_emit("{:pages-freed/%9u} {N:pages freed}\n",
1090 xo_emit("{:pages-freed-by-daemon/%9u} {N:pages freed by daemon}\n",
1092 xo_emit("{:pages-freed-on-exit/%9u} {N:pages freed by exiting processes}\n",
1094 xo_emit("{:active-pages/%9u} {N:pages active}\n",
1095 sum
.v_active_count
);
1096 xo_emit("{:inactive-pages/%9u} {N:pages inactive}\n",
1097 sum
.v_inactive_count
);
1098 xo_emit("{:vm-cache/%9u} {N:pages in VM cache}\n",
1100 xo_emit("{:wired-pages/%9u} {N:pages wired down}\n",
1102 xo_emit("{:free-pages/%9u} {N:pages free}\n",
1104 xo_emit("{:bytes-per-page/%9u} {N:bytes per page}\n", sum
.v_page_size
);
1106 kread(X_NCHSTATS
, &lnchstats
, sizeof(lnchstats
));
1108 size_t size
= sizeof(lnchstats
);
1109 mysysctl("vfs.cache.nchstats", &lnchstats
, &size
, NULL
, 0);
1110 if (size
!= sizeof(lnchstats
))
1111 xo_errx(1, "vfs.cache.nchstats size mismatch");
1113 nchtotal
= lnchstats
.ncs_goodhits
+ lnchstats
.ncs_neghits
+
1114 lnchstats
.ncs_badhits
+ lnchstats
.ncs_falsehits
+
1115 lnchstats
.ncs_miss
+ lnchstats
.ncs_long
;
1116 xo_emit("{:total-name-lookups/%9ld} {N:total name lookups}\n",
1118 xo_emit("{P:/%9s} {N:cache hits} "
1119 "({:positive-cache-hits/%ld}% pos + "
1120 "{:negative-cache-hits/%ld}% {N:neg}) "
1121 "system {:cache-hit-percent/%ld}% per-directory\n",
1122 "", PCT(lnchstats
.ncs_goodhits
, nchtotal
),
1123 PCT(lnchstats
.ncs_neghits
, nchtotal
),
1124 PCT(lnchstats
.ncs_pass2
, nchtotal
));
1125 xo_emit("{P:/%9s} {L:deletions} {:deletions/%ld}%, "
1126 "{L:falsehits} {:false-hits/%ld}%, "
1127 "{L:toolong} {:too-long/%ld}%\n", "",
1128 PCT(lnchstats
.ncs_badhits
, nchtotal
),
1129 PCT(lnchstats
.ncs_falsehits
, nchtotal
),
1130 PCT(lnchstats
.ncs_long
, nchtotal
));
1131 xo_close_container("summary-statistics");
1138 xo_open_container("fork-statistics");
1139 xo_emit("{:fork/%u} {N:forks}, {:fork-pages/%u} {N:pages}, "
1140 "{L:average} {:fork-average/%.2f}\n",
1141 sum
.v_forks
, sum
.v_forkpages
,
1142 sum
.v_forks
== 0 ? 0.0 :
1143 (double)sum
.v_forkpages
/ sum
.v_forks
);
1144 xo_emit("{:vfork/%u} {N:vforks}, {:vfork-pages/%u} {N:pages}, "
1145 "{L:average} {:vfork-average/%.2f}\n",
1146 sum
.v_vforks
, sum
.v_vforkpages
,
1147 sum
.v_vforks
== 0 ? 0.0 :
1148 (double)sum
.v_vforkpages
/ sum
.v_vforks
);
1149 xo_emit("{:rfork/%u} {N:rforks}, {:rfork-pages/%u} {N:pages}, "
1150 "{L:average} {:rfork-average/%.2f}\n",
1151 sum
.v_rforks
, sum
.v_rforkpages
,
1152 sum
.v_rforks
== 0 ? 0.0 :
1153 (double)sum
.v_rforkpages
/ sum
.v_rforks
);
1154 xo_close_container("fork-statistics");
1161 long double transfers_per_second
;
1162 long double busy_seconds
;
1165 for (state
= 0; state
< CPUSTATES
; ++state
) {
1166 tmp
= cur
.cp_time
[state
];
1167 cur
.cp_time
[state
] -= last
.cp_time
[state
];
1168 last
.cp_time
[state
] = tmp
;
1171 busy_seconds
= cur
.snap_time
- last
.snap_time
;
1173 xo_open_list("device");
1174 for (dn
= 0; dn
< num_devices
; dn
++) {
1177 if ((dev_select
[dn
].selected
== 0)
1178 || (dev_select
[dn
].selected
> maxshowdevs
))
1181 di
= dev_select
[dn
].position
;
1183 if (devstat_compute_statistics(&cur
.dinfo
->devices
[di
],
1184 &last
.dinfo
->devices
[di
], busy_seconds
,
1185 DSM_TRANSFERS_PER_SECOND
, &transfers_per_second
,
1187 xo_errx(1, "%s", devstat_errbuf
);
1189 xo_open_instance("device");
1190 xo_emit("{ekq:name/%c%c%d}{:transfers/%3.0Lf} ",
1191 dev_select
[dn
].device_name
[0],
1192 dev_select
[dn
].device_name
[1],
1193 dev_select
[dn
].unit_number
,
1194 transfers_per_second
);
1195 xo_close_instance("device");
1197 xo_close_list("device");
1201 percent(const char *name
, double pct
, int *over
)
1207 snprintf(fmt
, sizeof(fmt
), " {:%s/%%*s}", name
);
1208 l
= snprintf(buf
, sizeof(buf
), "%.0f", pct
);
1209 if (l
== 1 && *over
) {
1210 xo_emit(fmt
, 1, buf
);
1213 xo_emit(fmt
, 2, buf
);
1225 for (state
= 0; state
< CPUSTATES
; ++state
)
1226 total
+= cur
.cp_time
[state
];
1228 lpct
= 100.0 / total
;
1232 xo_open_container("cpu-statistics");
1233 percent("user", (cur
.cp_time
[CP_USER
] + cur
.cp_time
[CP_NICE
]) * lpct
, &over
);
1234 percent("system", (cur
.cp_time
[CP_SYS
] + cur
.cp_time
[CP_INTR
]) * lpct
, &over
);
1235 percent("idle", cur
.cp_time
[CP_IDLE
] * lpct
, &over
);
1236 xo_close_container("cpu-statistics");
1240 pcpustats(int ncpus
, u_long cpumask
, int maxid
)
1247 /* devstats does this for cp_time */
1248 for (i
= 0; i
<= maxid
; i
++) {
1249 if ((cpumask
& (1ul << i
)) == 0)
1251 for (state
= 0; state
< CPUSTATES
; ++state
) {
1252 tmp
= cur_cp_times
[i
* CPUSTATES
+ state
];
1253 cur_cp_times
[i
* CPUSTATES
+ state
] -= last_cp_times
[i
*
1255 last_cp_times
[i
* CPUSTATES
+ state
] = tmp
;
1260 xo_open_list("cpu");
1261 for (i
= 0; i
<= maxid
; i
++) {
1262 if ((cpumask
& (1ul << i
)) == 0)
1264 xo_open_instance("cpu");
1265 xo_emit("{ke:name/%d}", i
);
1267 for (state
= 0; state
< CPUSTATES
; ++state
)
1268 total
+= cur_cp_times
[i
* CPUSTATES
+ state
];
1270 lpct
= 100.0 / total
;
1273 percent("user", (cur_cp_times
[i
* CPUSTATES
+ CP_USER
] +
1274 cur_cp_times
[i
* CPUSTATES
+ CP_NICE
]) * lpct
, &over
);
1275 percent("system", (cur_cp_times
[i
* CPUSTATES
+ CP_SYS
] +
1276 cur_cp_times
[i
* CPUSTATES
+ CP_INTR
]) * lpct
, &over
);
1277 percent("idle", cur_cp_times
[i
* CPUSTATES
+ CP_IDLE
] * lpct
,
1279 xo_close_instance("cpu");
1281 xo_close_list("cpu");
1285 read_intrcnts(unsigned long **intrcnts
)
1290 kread(X_SINTRCNT
, &intrcntlen
, sizeof(intrcntlen
));
1291 if ((*intrcnts
= malloc(intrcntlen
)) == NULL
)
1293 kread(X_INTRCNT
, *intrcnts
, intrcntlen
);
1295 for (*intrcnts
= NULL
, intrcntlen
= 1024; ; intrcntlen
*= 2) {
1296 *intrcnts
= reallocf(*intrcnts
, intrcntlen
);
1297 if (*intrcnts
== NULL
)
1298 err(1, "reallocf()");
1299 if (mysysctl("hw.intrcnt",
1300 *intrcnts
, &intrcntlen
, NULL
, 0) == 0)
1305 return (intrcntlen
/ sizeof(unsigned long));
1309 print_intrcnts(unsigned long *intrcnts
, unsigned long *old_intrcnts
,
1310 char *intrnames
, unsigned int nintr
,
1311 size_t istrnamlen
, long long period_ms
)
1313 unsigned long *intrcnt
, *old_intrcnt
;
1314 uint64_t inttotal
, old_inttotal
, total_count
, total_rate
;
1320 intrname
= intrnames
;
1321 xo_open_list("interrupt");
1322 for (i
= 0, intrcnt
=intrcnts
, old_intrcnt
=old_intrcnts
; i
< nintr
; i
++) {
1323 if (intrname
[0] != '\0' && (*intrcnt
!= 0 || aflag
)) {
1324 unsigned long count
, rate
;
1326 count
= *intrcnt
- *old_intrcnt
;
1327 rate
= (count
* 1000 + period_ms
/ 2) / period_ms
;
1328 xo_open_instance("interrupt");
1329 xo_emit("{d:name/%-*s}{ket:name/%s} "
1330 "{:total/%20lu} {:rate/%10lu}\n",
1331 (int)istrnamlen
, intrname
,
1332 intrname
, count
, rate
);
1333 xo_close_instance("interrupt");
1335 intrname
+= strlen(intrname
) + 1;
1336 inttotal
+= *intrcnt
++;
1337 old_inttotal
+= *old_intrcnt
++;
1339 total_count
= inttotal
- old_inttotal
;
1340 total_rate
= (total_count
* 1000 + period_ms
/ 2) / period_ms
;
1341 xo_close_list("interrupt");
1342 xo_emit("{L:/%-*s} {:total-interrupts/%20" PRIu64
"} "
1343 "{:total-rate/%10" PRIu64
"}\n", (int)istrnamlen
,
1344 "Total", total_count
, total_rate
);
1348 dointr(unsigned int interval
, int reps
)
1350 unsigned long *intrcnts
;
1351 long long uptime
, period_ms
;
1352 unsigned long *old_intrcnts
= NULL
;
1353 size_t clen
, inamlen
, istrnamlen
;
1354 char *intrnames
, *intrname
;
1356 uptime
= getuptime();
1358 /* Get the names of each interrupt source */
1360 kread(X_SINTRNAMES
, &inamlen
, sizeof(inamlen
));
1361 if ((intrnames
= malloc(inamlen
)) == NULL
)
1362 xo_err(1, "malloc()");
1363 kread(X_INTRNAMES
, intrnames
, inamlen
);
1365 for (intrnames
= NULL
, inamlen
= 1024; ; inamlen
*= 2) {
1366 if ((intrnames
= reallocf(intrnames
, inamlen
)) == NULL
)
1367 xo_err(1, "reallocf()");
1368 if (mysysctl("hw.intrnames",
1369 intrnames
, &inamlen
, NULL
, 0) == 0)
1374 /* Determine the length of the longest interrupt name */
1375 intrname
= intrnames
;
1376 istrnamlen
= strlen("interrupt");
1377 while(*intrname
!= '\0') {
1378 clen
= strlen(intrname
);
1379 if (clen
> istrnamlen
)
1381 intrname
+= strlen(intrname
) + 1;
1383 xo_emit("{T:/%-*s} {T:/%20s} {T:/%10s}\n",
1384 (int)istrnamlen
, "interrupt", "total", "rate");
1387 * Loop reps times printing differential interrupt counts. If reps is
1388 * zero, then run just once, printing total counts
1390 xo_open_container("interrupt-statistics");
1392 period_ms
= uptime
/ 1000000;
1395 long long old_uptime
;
1397 nintr
= read_intrcnts(&intrcnts
);
1399 * Initialize old_intrcnts to 0 for the first pass, so
1400 * print_intrcnts will print total interrupts since boot
1402 if (old_intrcnts
== NULL
) {
1403 old_intrcnts
= calloc(nintr
, sizeof(unsigned long));
1404 if (old_intrcnts
== NULL
)
1405 xo_err(1, "calloc()");
1408 print_intrcnts(intrcnts
, old_intrcnts
, intrnames
, nintr
,
1409 istrnamlen
, period_ms
);
1413 old_intrcnts
= intrcnts
;
1414 if (reps
>= 0 && --reps
<= 0)
1416 usleep(interval
* 1000);
1417 old_uptime
= uptime
;
1418 uptime
= getuptime();
1419 period_ms
= (uptime
- old_uptime
) / 1000000;
1422 xo_close_container("interrupt-statistics");
1426 domemstat_malloc(void)
1428 struct memory_type_list
*mtlp
;
1429 struct memory_type
*mtp
;
1430 int error
, first
, i
;
1432 mtlp
= memstat_mtl_alloc();
1434 xo_warn("memstat_mtl_alloc");
1438 if (memstat_sysctl_malloc(mtlp
, 0) < 0) {
1439 xo_warnx("memstat_sysctl_malloc: %s",
1440 memstat_strerror(memstat_mtl_geterror(mtlp
)));
1444 if (memstat_kvm_malloc(mtlp
, kd
) < 0) {
1445 error
= memstat_mtl_geterror(mtlp
);
1446 if (error
== MEMSTAT_ERROR_KVM
)
1447 xo_warnx("memstat_kvm_malloc: %s",
1450 xo_warnx("memstat_kvm_malloc: %s",
1451 memstat_strerror(error
));
1454 xo_open_container("malloc-statistics");
1455 xo_emit("{T:/%13s} {T:/%5s} {T:/%6s} {T:/%7s} {T:/%8s} {T:Size(s)}\n",
1456 "Type", "InUse", "MemUse", "HighUse", "Requests");
1457 xo_open_list("memory");
1458 for (mtp
= memstat_mtl_first(mtlp
); mtp
!= NULL
;
1459 mtp
= memstat_mtl_next(mtp
)) {
1460 if (memstat_get_numallocs(mtp
) == 0 &&
1461 memstat_get_count(mtp
) == 0)
1463 xo_open_instance("memory");
1464 xo_emit("{k:type/%13s/%s} {:in-use/%5" PRIu64
"} "
1465 "{:memory-use/%5" PRIu64
"}{U:K} {:high-use/%7s} "
1466 "{:requests/%8" PRIu64
"} ",
1467 memstat_get_name(mtp
), memstat_get_count(mtp
),
1468 (memstat_get_bytes(mtp
) + 1023) / 1024, "-",
1469 memstat_get_numallocs(mtp
));
1471 xo_open_list("size");
1472 for (i
= 0; i
< 32; i
++) {
1473 if (memstat_get_sizemask(mtp
) & (1 << i
)) {
1476 xo_emit("{l:size/%d}", 1 << (i
+ 4));
1480 xo_close_list("size");
1481 xo_close_instance("memory");
1484 xo_close_list("memory");
1485 xo_close_container("malloc-statistics");
1486 memstat_mtl_free(mtlp
);
1490 domemstat_zone(void)
1492 struct memory_type_list
*mtlp
;
1493 struct memory_type
*mtp
;
1494 char name
[MEMTYPE_MAXNAME
+ 1];
1497 mtlp
= memstat_mtl_alloc();
1499 xo_warn("memstat_mtl_alloc");
1503 if (memstat_sysctl_uma(mtlp
, 0) < 0) {
1504 xo_warnx("memstat_sysctl_uma: %s",
1505 memstat_strerror(memstat_mtl_geterror(mtlp
)));
1509 if (memstat_kvm_uma(mtlp
, kd
) < 0) {
1510 error
= memstat_mtl_geterror(mtlp
);
1511 if (error
== MEMSTAT_ERROR_KVM
)
1512 xo_warnx("memstat_kvm_uma: %s",
1515 xo_warnx("memstat_kvm_uma: %s",
1516 memstat_strerror(error
));
1519 xo_open_container("memory-zone-statistics");
1520 xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} "
1521 "{T:/%4s} {T:/%4s}\n\n", "ITEM", "SIZE",
1522 "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP");
1523 xo_open_list("zone");
1524 for (mtp
= memstat_mtl_first(mtlp
); mtp
!= NULL
;
1525 mtp
= memstat_mtl_next(mtp
)) {
1526 strlcpy(name
, memstat_get_name(mtp
), MEMTYPE_MAXNAME
);
1528 xo_open_instance("zone");
1529 xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6" PRIu64
"}, "
1530 "{:limit/%6" PRIu64
"},{:used/%8" PRIu64
"},"
1531 "{:free/%8" PRIu64
"},{:requests/%8" PRIu64
"},"
1532 "{:fail/%4" PRIu64
"},{:sleep/%4" PRIu64
"}\n", name
,
1533 memstat_get_name(mtp
),
1534 memstat_get_size(mtp
), memstat_get_countlimit(mtp
),
1535 memstat_get_count(mtp
), memstat_get_free(mtp
),
1536 memstat_get_numallocs(mtp
), memstat_get_failures(mtp
),
1537 memstat_get_sleeps(mtp
));
1538 xo_close_instance("zone");
1540 memstat_mtl_free(mtlp
);
1541 xo_close_list("zone");
1542 xo_close_container("memory-zone-statistics");
1547 display_object(struct kinfo_vmobject
*kvo
)
1551 xo_open_instance("object");
1552 xo_emit("{:resident/%5jd} ", (uintmax_t)kvo
->kvo_resident
);
1553 xo_emit("{:active/%5jd} ", (uintmax_t)kvo
->kvo_active
);
1554 xo_emit("{:inactive/%5jd} ", (uintmax_t)kvo
->kvo_inactive
);
1555 xo_emit("{:refcount/%3d} ", kvo
->kvo_ref_count
);
1556 xo_emit("{:shadowcount/%3d} ", kvo
->kvo_shadow_count
);
1557 switch (kvo
->kvo_memattr
) {
1558 #ifdef VM_MEMATTR_UNCACHEABLE
1559 case VM_MEMATTR_UNCACHEABLE
:
1563 #ifdef VM_MEMATTR_WRITE_COMBINING
1564 case VM_MEMATTR_WRITE_COMBINING
:
1568 #ifdef VM_MEMATTR_WRITE_THROUGH
1569 case VM_MEMATTR_WRITE_THROUGH
:
1573 #ifdef VM_MEMATTR_WRITE_PROTECTED
1574 case VM_MEMATTR_WRITE_PROTECTED
:
1578 #ifdef VM_MEMATTR_WRITE_BACK
1579 case VM_MEMATTR_WRITE_BACK
:
1583 #ifdef VM_MEMATTR_WEAK_UNCACHEABLE
1584 case VM_MEMATTR_WEAK_UNCACHEABLE
:
1588 #ifdef VM_MEMATTR_WB_WA
1589 case VM_MEMATTR_WB_WA
:
1593 #ifdef VM_MEMATTR_NOCACHE
1594 case VM_MEMATTR_NOCACHE
:
1598 #ifdef VM_MEMATTR_DEVICE
1599 case VM_MEMATTR_DEVICE
:
1603 #ifdef VM_MEMATTR_CACHEABLE
1604 case VM_MEMATTR_CACHEABLE
:
1608 #ifdef VM_MEMATTR_PREFETCHABLE
1609 case VM_MEMATTR_PREFETCHABLE
:
1617 xo_emit("{:attribute/%-3s} ", str
);
1618 switch (kvo
->kvo_type
) {
1619 case KVME_TYPE_NONE
:
1622 case KVME_TYPE_DEFAULT
:
1625 case KVME_TYPE_VNODE
:
1628 case KVME_TYPE_SWAP
:
1631 case KVME_TYPE_DEVICE
:
1634 case KVME_TYPE_PHYS
:
1637 case KVME_TYPE_DEAD
:
1643 case KVME_TYPE_UNKNOWN
:
1648 xo_emit("{:type/%-2s} ", str
);
1649 xo_emit("{:path/%-s}\n", kvo
->kvo_path
);
1650 xo_close_instance("object");
1656 struct kinfo_vmobject
*kvo
;
1659 kvo
= kinfo_getvmobject(&cnt
);
1661 xo_warn("Failed to fetch VM object list");
1664 xo_emit("{T:RES/%5s} {T:ACT/%5s} {T:INACT/%5s} {T:REF/%3s} {T:SHD/%3s} "
1665 "{T:CM/%3s} {T:TP/%2s} {T:PATH/%s}\n");
1666 xo_open_list("object");
1667 for (i
= 0; i
< cnt
; i
++)
1668 display_object(&kvo
[i
]);
1670 xo_close_list("object");
1674 * kread reads something from the kernel, given its nlist index.
1677 kreado(int nlx
, void *addr
, size_t size
, size_t offset
)
1681 if (namelist
[nlx
].n_type
== 0 || namelist
[nlx
].n_value
== 0) {
1682 sym
= namelist
[nlx
].n_name
;
1685 xo_errx(1, "symbol %s not defined", sym
);
1687 if ((size_t)kvm_read(kd
, namelist
[nlx
].n_value
+ offset
, addr
,
1689 sym
= namelist
[nlx
].n_name
;
1692 xo_errx(1, "%s: %s", sym
, kvm_geterr(kd
));
1697 kread(int nlx
, void *addr
, size_t size
)
1699 kreado(nlx
, addr
, size
, 0);
1703 kgetstr(const char *strp
)
1705 int n
= 0, size
= 1;
1709 if (size
== n
+ 1) {
1710 ret
= realloc(ret
, size
);
1712 xo_err(1, "%s: realloc", __func__
);
1715 if (kvm_read(kd
, (u_long
)strp
+ n
, &ret
[n
], 1) != 1)
1716 xo_errx(1, "%s: %s", __func__
, kvm_geterr(kd
));
1717 } while (ret
[n
++] != '\0');
1725 "usage: vmstat [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs]\n",
1726 " [-p type,if,pass] [-w wait] [disks] [wait [count]]\n");