Sun Feb 27 19:00:46 2022 UTC ()
vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible.  There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


(rillig)
diff -r1.251 -r1.252 src/usr.bin/vmstat/vmstat.c

cvs diff -r1.251 -r1.252 src/usr.bin/vmstat/vmstat.c (switch to unified diff)

--- src/usr.bin/vmstat/vmstat.c 2022/02/09 07:51:45 1.251
+++ src/usr.bin/vmstat/vmstat.c 2022/02/27 19:00:46 1.252
@@ -1,1331 +1,1331 @@ @@ -1,1331 +1,1331 @@
1/* $NetBSD: vmstat.c,v 1.251 2022/02/09 07:51:45 wiz Exp $ */ 1/* $NetBSD: vmstat.c,v 1.252 2022/02/27 19:00:46 rillig Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020 4 * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020
5 * The NetBSD Foundation, Inc. 5 * The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation by: 8 * This code is derived from software contributed to The NetBSD Foundation by:
9 * - Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * - Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center. 10 * NASA Ames Research Center.
11 * - Simon Burge and Luke Mewburn of Wasabi Systems, Inc. 11 * - Simon Burge and Luke Mewburn of Wasabi Systems, Inc.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
15 * are met: 15 * are met:
16 * 1. Redistributions of source code must retain the above copyright 16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer. 17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright 18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the 19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution. 20 * documentation and/or other materials provided with the distribution.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE. 32 * POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35/* 35/*
36 * Copyright (c) 1980, 1986, 1991, 1993 36 * Copyright (c) 1980, 1986, 1991, 1993
37 * The Regents of the University of California. All rights reserved. 37 * The Regents of the University of California. All rights reserved.
38 * 38 *
39 * Redistribution and use in source and binary forms, with or without 39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions 40 * modification, are permitted provided that the following conditions
41 * are met: 41 * are met:
42 * 1. Redistributions of source code must retain the above copyright 42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer. 43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright 44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the 45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution. 46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the University nor the names of its contributors 47 * 3. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software 48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission. 49 * without specific prior written permission.
50 * 50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE. 61 * SUCH DAMAGE.
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65#ifndef lint 65#ifndef lint
66__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\ 66__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\
67 The Regents of the University of California. All rights reserved."); 67 The Regents of the University of California. All rights reserved.");
68#endif /* not lint */ 68#endif /* not lint */
69 69
70#ifndef lint 70#ifndef lint
71#if 0 71#if 0
72static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; 72static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
73#else 73#else
74__RCSID("$NetBSD: vmstat.c,v 1.251 2022/02/09 07:51:45 wiz Exp $"); 74__RCSID("$NetBSD: vmstat.c,v 1.252 2022/02/27 19:00:46 rillig Exp $");
75#endif 75#endif
76#endif /* not lint */ 76#endif /* not lint */
77 77
78#define __POOL_EXPOSE 78#define __POOL_EXPOSE
79#define __NAMECACHE_PRIVATE 79#define __NAMECACHE_PRIVATE
80 80
81#include <sys/param.h> 81#include <sys/param.h>
82#include <sys/types.h> 82#include <sys/types.h>
83#include <sys/mount.h> 83#include <sys/mount.h>
84#include <sys/uio.h> 84#include <sys/uio.h>
85 85
86#include <sys/buf.h> 86#include <sys/buf.h>
87#include <sys/evcnt.h> 87#include <sys/evcnt.h>
88#include <sys/ioctl.h> 88#include <sys/ioctl.h>
89#include <sys/malloc.h> 89#include <sys/malloc.h>
90#include <sys/mallocvar.h> 90#include <sys/mallocvar.h>
91#include <sys/namei.h> 91#include <sys/namei.h>
92#include <sys/pool.h> 92#include <sys/pool.h>
93#include <sys/proc.h> 93#include <sys/proc.h>
94#include <sys/sched.h> 94#include <sys/sched.h>
95#include <sys/socket.h> 95#include <sys/socket.h>
96#include <sys/sysctl.h> 96#include <sys/sysctl.h>
97#include <sys/time.h> 97#include <sys/time.h>
98#include <sys/queue.h> 98#include <sys/queue.h>
99#include <sys/kernhist.h> 99#include <sys/kernhist.h>
100#include <sys/vnode.h> 100#include <sys/vnode.h>
101#include <sys/vnode_impl.h> 101#include <sys/vnode_impl.h>
102 102
103#include <uvm/uvm_extern.h> 103#include <uvm/uvm_extern.h>
104#include <uvm/uvm_stat.h> 104#include <uvm/uvm_stat.h>
105 105
106#include <net/if.h> 106#include <net/if.h>
107#include <netinet/in.h> 107#include <netinet/in.h>
108#include <netinet/in_var.h> 108#include <netinet/in_var.h>
109 109
110#include <ufs/ufs/inode.h> 110#include <ufs/ufs/inode.h>
111 111
112#include <nfs/rpcv2.h> 112#include <nfs/rpcv2.h>
113#include <nfs/nfsproto.h> 113#include <nfs/nfsproto.h>
114#include <nfs/nfsnode.h> 114#include <nfs/nfsnode.h>
115 115
116#include <assert.h> 116#include <assert.h>
117#include <ctype.h> 117#include <ctype.h>
118#include <err.h> 118#include <err.h>
119#include <errno.h> 119#include <errno.h>
120#include <fcntl.h> 120#include <fcntl.h>
121#include <kvm.h> 121#include <kvm.h>
122#include <limits.h> 122#include <limits.h>
123#include <nlist.h> 123#include <nlist.h>
124#undef n_hash 124#undef n_hash
125#include <paths.h> 125#include <paths.h>
126#include <signal.h> 126#include <signal.h>
127#include <stdio.h> 127#include <stdio.h>
128#include <stddef.h> 128#include <stddef.h>
129#include <stdlib.h> 129#include <stdlib.h>
130#include <string.h> 130#include <string.h>
131#include <time.h> 131#include <time.h>
132#include <unistd.h> 132#include <unistd.h>
133#include <util.h> 133#include <util.h>
134 134
135#include "drvstats.h" 135#include "drvstats.h"
136 136
137/* 137/*
138 * All this mess will go away once everything is converted. 138 * All this mess will go away once everything is converted.
139 */ 139 */
140#ifdef __HAVE_CPU_DATA_FIRST 140#ifdef __HAVE_CPU_DATA_FIRST
141 141
142# include <sys/cpu_data.h> 142# include <sys/cpu_data.h>
143struct cpu_info { 143struct cpu_info {
144 struct cpu_data ci_data; 144 struct cpu_data ci_data;
145}; 145};
146#else 146#else
147# include <sys/cpu.h> 147# include <sys/cpu.h>
148#endif 148#endif
149 149
150/* 150/*
151 * General namelist 151 * General namelist
152 */ 152 */
153struct nlist namelist[] = 153struct nlist namelist[] =
154{ 154{
155#define X_HZ 0 155#define X_HZ 0
156 { .n_name = "_hz" }, 156 { .n_name = "_hz" },
157#define X_STATHZ 1 157#define X_STATHZ 1
158 { .n_name = "_stathz" }, 158 { .n_name = "_stathz" },
159#define X_NCHSTATS 2 159#define X_NCHSTATS 2
160 { .n_name = "_nchstats" }, 160 { .n_name = "_nchstats" },
161#define X_ALLEVENTS 3 161#define X_ALLEVENTS 3
162 { .n_name = "_allevents" }, 162 { .n_name = "_allevents" },
163#define X_POOLHEAD 4 163#define X_POOLHEAD 4
164 { .n_name = "_pool_head" }, 164 { .n_name = "_pool_head" },
165#define X_UVMEXP 5 165#define X_UVMEXP 5
166 { .n_name = "_uvmexp" }, 166 { .n_name = "_uvmexp" },
167#define X_CPU_INFOS 6 167#define X_CPU_INFOS 6
168 { .n_name = "_cpu_infos" }, 168 { .n_name = "_cpu_infos" },
169#define X_NL_SIZE 7 169#define X_NL_SIZE 7
170 { .n_name = NULL }, 170 { .n_name = NULL },
171}; 171};
172 172
173/* 173/*
174 * Namelist for time data. 174 * Namelist for time data.
175 */ 175 */
176struct nlist timenl[] = 176struct nlist timenl[] =
177{ 177{
178#define X_TIMEBASEBIN 0 178#define X_TIMEBASEBIN 0
179 { .n_name = "_timebasebin" }, 179 { .n_name = "_timebasebin" },
180#define X_TIME_SECOND 1 180#define X_TIME_SECOND 1
181 { .n_name = "_time_second" }, 181 { .n_name = "_time_second" },
182#define X_TIME 2 182#define X_TIME 2
183 { .n_name = "_time" }, 183 { .n_name = "_time" },
184#define X_TIMENL_SIZE 3 184#define X_TIMENL_SIZE 3
185 { .n_name = NULL }, 185 { .n_name = NULL },
186}; 186};
187 187
188/* 188/*
189 * Namelist for pre-evcnt interrupt counters. 189 * Namelist for pre-evcnt interrupt counters.
190 */ 190 */
191struct nlist intrnl[] = 191struct nlist intrnl[] =
192{ 192{
193#define X_INTRNAMES 0 193#define X_INTRNAMES 0
194 { .n_name = "_intrnames" }, 194 { .n_name = "_intrnames" },
195#define X_EINTRNAMES 1 195#define X_EINTRNAMES 1
196 { .n_name = "_eintrnames" }, 196 { .n_name = "_eintrnames" },
197#define X_INTRCNT 2 197#define X_INTRCNT 2
198 { .n_name = "_intrcnt" }, 198 { .n_name = "_intrcnt" },
199#define X_EINTRCNT 3 199#define X_EINTRCNT 3
200 { .n_name = "_eintrcnt" }, 200 { .n_name = "_eintrcnt" },
201#define X_INTRNL_SIZE 4 201#define X_INTRNL_SIZE 4
202 { .n_name = NULL }, 202 { .n_name = NULL },
203}; 203};
204 204
205 205
206/* 206/*
207 * Namelist for hash statistics 207 * Namelist for hash statistics
208 */ 208 */
209struct nlist hashnl[] = 209struct nlist hashnl[] =
210{ 210{
211#define X_BUFHASH 0 211#define X_BUFHASH 0
212 { .n_name = "_bufhash" }, 212 { .n_name = "_bufhash" },
213#define X_BUFHASHTBL 1 213#define X_BUFHASHTBL 1
214 { .n_name = "_bufhashtbl" }, 214 { .n_name = "_bufhashtbl" },
215#define X_UIHASH 2 215#define X_UIHASH 2
216 { .n_name = "_uihash" }, 216 { .n_name = "_uihash" },
217#define X_UIHASHTBL 3 217#define X_UIHASHTBL 3
218 { .n_name = "_uihashtbl" }, 218 { .n_name = "_uihashtbl" },
219#define X_IFADDRHASH 4 219#define X_IFADDRHASH 4
220 { .n_name = "_in_ifaddrhash" }, 220 { .n_name = "_in_ifaddrhash" },
221#define X_IFADDRHASHTBL 5 221#define X_IFADDRHASHTBL 5
222 { .n_name = "_in_ifaddrhashtbl" }, 222 { .n_name = "_in_ifaddrhashtbl" },
223#define X_VCACHEHASH 6 223#define X_VCACHEHASH 6
224 { .n_name = "_vcache_hashmask" }, 224 { .n_name = "_vcache_hashmask" },
225#define X_VCACHETBL 7 225#define X_VCACHETBL 7
226 { .n_name = "_vcache_hashtab" }, 226 { .n_name = "_vcache_hashtab" },
227#define X_HASHNL_SIZE 8 /* must be last */ 227#define X_HASHNL_SIZE 8 /* must be last */
228 { .n_name = NULL }, 228 { .n_name = NULL },
229}; 229};
230 230
231/* 231/*
232 * Namelist for kernel histories 232 * Namelist for kernel histories
233 */ 233 */
234struct nlist histnl[] = 234struct nlist histnl[] =
235{ 235{
236 { .n_name = "_kern_histories" }, 236 { .n_name = "_kern_histories" },
237#define X_KERN_HISTORIES 0 237#define X_KERN_HISTORIES 0
238 { .n_name = NULL }, 238 { .n_name = NULL },
239}; 239};
240 240
241 241
242#define KILO 1024 242#define KILO 1024
243 243
244struct cpu_counter { 244struct cpu_counter {
245 uint64_t nintr; 245 uint64_t nintr;
246 uint64_t nsyscall; 246 uint64_t nsyscall;
247 uint64_t nswtch; 247 uint64_t nswtch;
248 uint64_t nfault; 248 uint64_t nfault;
249 uint64_t ntrap; 249 uint64_t ntrap;
250 uint64_t nsoft; 250 uint64_t nsoft;
251} cpucounter, ocpucounter; 251} cpucounter, ocpucounter;
252 252
253struct uvmexp_sysctl uvmexp, ouvmexp; 253struct uvmexp_sysctl uvmexp, ouvmexp;
254int ndrives; 254int ndrives;
255 255
256int winlines = 20; 256int winlines = 20;
257 257
258kvm_t *kd; 258kvm_t *kd;
259 259
260 260
261#define FORKSTAT 0x001 261#define FORKSTAT 0x001
262#define INTRSTAT 0x002 262#define INTRSTAT 0x002
263#define MEMSTAT 0x004 263#define MEMSTAT 0x004
264#define SUMSTAT 0x008 264#define SUMSTAT 0x008
265#define EVCNTSTAT 0x010 265#define EVCNTSTAT 0x010
266#define VMSTAT 0x020 266#define VMSTAT 0x020
267#define HISTLIST 0x040 267#define HISTLIST 0x040
268#define HISTDUMP 0x080 268#define HISTDUMP 0x080
269#define HASHSTAT 0x100 269#define HASHSTAT 0x100
270#define HASHLIST 0x200 270#define HASHLIST 0x200
271#define VMTOTAL 0x400 271#define VMTOTAL 0x400
272#define POOLCACHESTAT 0x800 272#define POOLCACHESTAT 0x800
273 273
274/* 274/*
275 * Print single word. `ovflow' is number of characters didn't fit 275 * Print single word. `ovflow' is number of characters didn't fit
276 * on the last word. `fmt' is a format string to print this word. 276 * on the last word. `fmt' is a format string to print this word.
277 * It must contain asterisk for field width. `width' is a width 277 * It must contain asterisk for field width. `width' is a width
278 * occupied by this word. `fixed' is a number of constant chars in 278 * occupied by this word. `fixed' is a number of constant chars in
279 * `fmt'. `val' is a value to be printed using format string `fmt'. 279 * `fmt'. `val' is a value to be printed using format string `fmt'.
280 */ 280 */
281#define PRWORD(ovflw, fmt, width, fixed, val) do { \ 281#define PRWORD(ovflw, fmt, width, fixed, val) do { \
282 (ovflw) += printf((fmt), \ 282 (ovflw) += printf((fmt), \
283 (width) - (fixed) - (ovflw) > 0 ? \ 283 (width) - (fixed) - (ovflw) > 0 ? \
284 (width) - (fixed) - (ovflw) : 0, \ 284 (width) - (fixed) - (ovflw) : 0, \
285 (val)) - (width); \ 285 (val)) - (width); \
286 if ((ovflw) < 0) \ 286 if ((ovflw) < 0) \
287 (ovflw) = 0; \ 287 (ovflw) = 0; \
288} while (0) 288} while (0)
289 289
290void cpustats(int *); 290void cpustats(int *);
291void cpucounters(struct cpu_counter *); 291void cpucounters(struct cpu_counter *);
292void deref_kptr(const void *, void *, size_t, const char *); 292void deref_kptr(const void *, void *, size_t, const char *);
293void drvstats(int *); 293void drvstats(int *);
294void doevcnt(int verbose, int type); 294void doevcnt(int verbose, int type);
295void dohashstat(int, int, const char *); 295void dohashstat(int, int, const char *);
296void dohashstat_sysctl(int, int, const char *); 296void dohashstat_sysctl(int, int, const char *);
297void dointr(int verbose); 297void dointr(int verbose);
298void dopool(int, int); 298void dopool(int, int);
299void dopoolcache(int); 299void dopoolcache(int);
300void dosum(void); 300void dosum(void);
301void dovmstat(struct timespec *, int); 301void dovmstat(struct timespec *, int);
302void print_total_hdr(void); 302void print_total_hdr(void);
303void dovmtotal(struct timespec *, int); 303void dovmtotal(struct timespec *, int);
304void kread(struct nlist *, int, void *, size_t); 304void kread(struct nlist *, int, void *, size_t);
305int kreadc(struct nlist *, int, void *, size_t); 305int kreadc(struct nlist *, int, void *, size_t);
306void needhdr(int); 306void needhdr(int);
307void getnlist(int); 307void getnlist(int);
308long getuptime(void); 308long getuptime(void);
309void printhdr(void); 309void printhdr(void);
310long pct(u_long, u_long); 310long pct(u_long, u_long);
311__dead static void usage(void); 311__dead static void usage(void);
312void doforkst(void); 312void doforkst(void);
313 313
314void hist_traverse(int, const char *); 314void hist_traverse(int, const char *);
315void hist_dodump(struct kern_history *); 315void hist_dodump(struct kern_history *);
316void hist_traverse_sysctl(int, const char *); 316void hist_traverse_sysctl(int, const char *);
317void hist_dodump_sysctl(int[], unsigned int); 317void hist_dodump_sysctl(int[], unsigned int);
318 318
319char **choosedrives(char **); 319char **choosedrives(char **);
320 320
321/* Namelist and memory file names. */ 321/* Namelist and memory file names. */
322char *nlistf, *memf; 322char *nlistf, *memf;
323 323
324/* allow old usage [vmstat 1] */ 324/* allow old usage [vmstat 1] */
325#define BACKWARD_COMPATIBILITY 325#define BACKWARD_COMPATIBILITY
326 326
327static const int clockrate_mib[] = { CTL_KERN, KERN_CLOCKRATE }; 327static const int clockrate_mib[] = { CTL_KERN, KERN_CLOCKRATE };
328static const int vmmeter_mib[] = { CTL_VM, VM_METER }; 328static const int vmmeter_mib[] = { CTL_VM, VM_METER };
329static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 }; 329static const int uvmexp2_mib[] = { CTL_VM, VM_UVMEXP2 };
330static const int boottime_mib[] = { CTL_KERN, KERN_BOOTTIME }; 330static const int boottime_mib[] = { CTL_KERN, KERN_BOOTTIME };
331 331
332int numdisks = 2; 332static int numdisks = 2;
333 333
334int 334int
335main(int argc, char *argv[]) 335main(int argc, char *argv[])
336{ 336{
337 int c, todo, verbose, wide; 337 int c, todo, verbose, wide;
338 struct timespec interval; 338 struct timespec interval;
339 int reps; 339 int reps;
340 const char *histname, *hashname; 340 const char *histname, *hashname;
341 char errbuf[_POSIX2_LINE_MAX]; 341 char errbuf[_POSIX2_LINE_MAX];
342 342
343 histname = hashname = NULL; 343 histname = hashname = NULL;
344 memf = nlistf = NULL; 344 memf = nlistf = NULL;
345 reps = todo = verbose = wide = 0; 345 reps = todo = verbose = wide = 0;
346 interval.tv_sec = 0; 346 interval.tv_sec = 0;
347 interval.tv_nsec = 0; 347 interval.tv_nsec = 0;
348 while ((c = getopt(argc, argv, "Cc:efh:HilLM:mN:n:stu:UvWw:")) != -1) { 348 while ((c = getopt(argc, argv, "Cc:efh:HilLM:mN:n:stu:UvWw:")) != -1) {
349 switch (c) { 349 switch (c) {
350 case 'c': 350 case 'c':
351 reps = atoi(optarg); 351 reps = atoi(optarg);
352 break; 352 break;
353 case 'C': 353 case 'C':
354 todo |= POOLCACHESTAT; 354 todo |= POOLCACHESTAT;
355 break; 355 break;
356 case 'e': 356 case 'e':
357 todo |= EVCNTSTAT; 357 todo |= EVCNTSTAT;
358 break; 358 break;
359 case 'f': 359 case 'f':
360 todo |= FORKSTAT; 360 todo |= FORKSTAT;
361 break; 361 break;
362 case 'h': 362 case 'h':
363 hashname = optarg; 363 hashname = optarg;
364 /* FALLTHROUGH */ 364 /* FALLTHROUGH */
365 case 'H': 365 case 'H':
366 todo |= HASHSTAT; 366 todo |= HASHSTAT;
367 break; 367 break;
368 case 'i': 368 case 'i':
369 todo |= INTRSTAT; 369 todo |= INTRSTAT;
370 break; 370 break;
371 case 'l': 371 case 'l':
372 todo |= HISTLIST; 372 todo |= HISTLIST;
373 break; 373 break;
374 case 'L': 374 case 'L':
375 todo |= HASHLIST; 375 todo |= HASHLIST;
376 break; 376 break;
377 case 'M': 377 case 'M':
378 memf = optarg; 378 memf = optarg;
379 break; 379 break;
380 case 'm': 380 case 'm':
381 todo |= MEMSTAT; 381 todo |= MEMSTAT;
382 break; 382 break;
383 case 'N': 383 case 'N':
384 nlistf = optarg; 384 nlistf = optarg;
385 break; 385 break;
386 case 'n': 386 case 'n':
387 numdisks = atoi(optarg); 387 numdisks = atoi(optarg);
388 break; 388 break;
389 case 's': 389 case 's':
390 todo |= SUMSTAT; 390 todo |= SUMSTAT;
391 break; 391 break;
392 case 't': 392 case 't':
393 todo |= VMTOTAL; 393 todo |= VMTOTAL;
394 break; 394 break;
395 case 'u': 395 case 'u':
396 histname = optarg; 396 histname = optarg;
397 /* FALLTHROUGH */ 397 /* FALLTHROUGH */
398 case 'U': 398 case 'U':
399 todo |= HISTDUMP; 399 todo |= HISTDUMP;
400 break; 400 break;
401 case 'v': 401 case 'v':
402 verbose++; 402 verbose++;
403 break; 403 break;
404 case 'W': 404 case 'W':
405 wide++; 405 wide++;
406 break; 406 break;
407 case 'w': 407 case 'w':
408 interval.tv_sec = atol(optarg); 408 interval.tv_sec = atol(optarg);
409 break; 409 break;
410 case '?': 410 case '?':
411 default: 411 default:
412 usage(); 412 usage();
413 } 413 }
414 } 414 }
415 argc -= optind; 415 argc -= optind;
416 argv += optind; 416 argv += optind;
417 417
418 if (todo == 0) 418 if (todo == 0)
419 todo = VMSTAT; 419 todo = VMSTAT;
420 420
421 if (memf == NULL) { 421 if (memf == NULL) {
422 kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); 422 kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
423 } else { 423 } else {
424 kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); 424 kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
425 getnlist(todo); 425 getnlist(todo);
426 } 426 }
427 427
428 if (kd == NULL) 428 if (kd == NULL)
429 errx(EXIT_FAILURE, "%s", errbuf); 429 errx(EXIT_FAILURE, "%s", errbuf);
430 430
431 if (todo & VMSTAT) { 431 if (todo & VMSTAT) {
432 struct winsize winsize; 432 struct winsize winsize;
433 433
434 (void)drvinit(0);/* Initialize disk stats, no disks selected. */ 434 (void)drvinit(0);/* Initialize disk stats, no disks selected. */
435 435
436 argv = choosedrives(argv); /* Select disks. */ 436 argv = choosedrives(argv); /* Select disks. */
437 winsize.ws_row = 0; 437 winsize.ws_row = 0;
438 (void)ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize); 438 (void)ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize);
439 if (winsize.ws_row > 0) 439 if (winsize.ws_row > 0)
440 winlines = winsize.ws_row; 440 winlines = winsize.ws_row;
441 441
442 } 442 }
443 443
444#ifdef BACKWARD_COMPATIBILITY 444#ifdef BACKWARD_COMPATIBILITY
445 if (*argv) { 445 if (*argv) {
446 interval.tv_sec = atol(*argv); 446 interval.tv_sec = atol(*argv);
447 if (*++argv) 447 if (*++argv)
448 reps = atoi(*argv); 448 reps = atoi(*argv);
449 } 449 }
450#endif 450#endif
451 451
452 if (interval.tv_sec) { 452 if (interval.tv_sec) {
453 if (!reps) 453 if (!reps)
454 reps = -1; 454 reps = -1;
455 } else if (reps) 455 } else if (reps)
456 interval.tv_sec = 1; 456 interval.tv_sec = 1;
457 457
458 /* 458 /*
459 * Statistics dumping is incompatible with the default 459 * Statistics dumping is incompatible with the default
460 * VMSTAT/dovmstat() output. So perform the interval/reps handling 460 * VMSTAT/dovmstat() output. So perform the interval/reps handling
461 * for it here. 461 * for it here.
462 */ 462 */
463 if ((todo & (VMSTAT|VMTOTAL)) == 0) { 463 if ((todo & (VMSTAT|VMTOTAL)) == 0) {
464 for (;;) { 464 for (;;) {
465 if (todo & (HISTLIST|HISTDUMP)) { 465 if (todo & (HISTLIST|HISTDUMP)) {
466 if ((todo & (HISTLIST|HISTDUMP)) == 466 if ((todo & (HISTLIST|HISTDUMP)) ==
467 (HISTLIST|HISTDUMP)) 467 (HISTLIST|HISTDUMP))
468 errx(1, "you may list or dump," 468 errx(1, "you may list or dump,"
469 " but not both!"); 469 " but not both!");
470 if (memf != NULL) 470 if (memf != NULL)
471 hist_traverse(todo, histname); 471 hist_traverse(todo, histname);
472 else 472 else
473 hist_traverse_sysctl(todo, histname); 473 hist_traverse_sysctl(todo, histname);
474 (void)putchar('\n'); 474 (void)putchar('\n');
475 } 475 }
476 if (todo & FORKSTAT) { 476 if (todo & FORKSTAT) {
477 doforkst(); 477 doforkst();
478 (void)putchar('\n'); 478 (void)putchar('\n');
479 } 479 }
480 if (todo & MEMSTAT) { 480 if (todo & MEMSTAT) {
481 dopool(verbose, wide); 481 dopool(verbose, wide);
482 (void)putchar('\n'); 482 (void)putchar('\n');
483 } 483 }
484 if (todo & POOLCACHESTAT) { 484 if (todo & POOLCACHESTAT) {
485 dopoolcache(verbose); 485 dopoolcache(verbose);
486 (void)putchar('\n'); 486 (void)putchar('\n');
487 } 487 }
488 if (todo & SUMSTAT) { 488 if (todo & SUMSTAT) {
489 dosum(); 489 dosum();
490 (void)putchar('\n'); 490 (void)putchar('\n');
491 } 491 }
492 if (todo & INTRSTAT) { 492 if (todo & INTRSTAT) {
493 dointr(verbose); 493 dointr(verbose);
494 (void)putchar('\n'); 494 (void)putchar('\n');
495 } 495 }
496 if (todo & EVCNTSTAT) { 496 if (todo & EVCNTSTAT) {
497 doevcnt(verbose, EVCNT_TYPE_ANY); 497 doevcnt(verbose, EVCNT_TYPE_ANY);
498 (void)putchar('\n'); 498 (void)putchar('\n');
499 } 499 }
500 if (todo & (HASHLIST|HASHSTAT)) { 500 if (todo & (HASHLIST|HASHSTAT)) {
501 if ((todo & (HASHLIST|HASHSTAT)) == 501 if ((todo & (HASHLIST|HASHSTAT)) ==
502 (HASHLIST|HASHSTAT)) 502 (HASHLIST|HASHSTAT))
503 errx(1, "you may list or display," 503 errx(1, "you may list or display,"
504 " but not both!"); 504 " but not both!");
505 dohashstat(verbose, todo, hashname); 505 dohashstat(verbose, todo, hashname);
506 (void)putchar('\n'); 506 (void)putchar('\n');
507 } 507 }
508 508
509 fflush(stdout); 509 fflush(stdout);
510 if (reps >= 0 && --reps <=0) 510 if (reps >= 0 && --reps <=0)
511 break; 511 break;
512 (void)nanosleep(&interval, NULL); 512 (void)nanosleep(&interval, NULL);
513 } 513 }
514 } else { 514 } else {
515 if ((todo & (VMSTAT|VMTOTAL)) == (VMSTAT|VMTOTAL)) { 515 if ((todo & (VMSTAT|VMTOTAL)) == (VMSTAT|VMTOTAL)) {
516 errx(1, "you may not both do vmstat and vmtotal"); 516 errx(1, "you may not both do vmstat and vmtotal");
517 } 517 }
518 if (todo & VMSTAT) 518 if (todo & VMSTAT)
519 dovmstat(&interval, reps); 519 dovmstat(&interval, reps);
520 if (todo & VMTOTAL) 520 if (todo & VMTOTAL)
521 dovmtotal(&interval, reps); 521 dovmtotal(&interval, reps);
522 } 522 }
523 return 0; 523 return 0;
524} 524}
525 525
526void 526void
527getnlist(int todo) 527getnlist(int todo)
528{ 528{
529 static int done = 0; 529 static int done = 0;
530 int c; 530 int c;
531 size_t i; 531 size_t i;
532 532
533 if ((c = kvm_nlist(kd, namelist)) != 0) { 533 if ((c = kvm_nlist(kd, namelist)) != 0) {
534 int doexit = 0; 534 int doexit = 0;
535 if (c == -1) 535 if (c == -1)
536 errx(1, "kvm_nlist: %s %s", 536 errx(1, "kvm_nlist: %s %s",
537 "namelist", kvm_geterr(kd)); 537 "namelist", kvm_geterr(kd));
538 for (i = 0; i < __arraycount(namelist)-1; i++) 538 for (i = 0; i < __arraycount(namelist)-1; i++)
539 if (namelist[i].n_type == 0) { 539 if (namelist[i].n_type == 0) {
540 if (doexit++ == 0) 540 if (doexit++ == 0)
541 (void)fprintf(stderr, 541 (void)fprintf(stderr,
542 "%s: undefined symbols:", 542 "%s: undefined symbols:",
543 getprogname()); 543 getprogname());
544 (void)fprintf(stderr, " %s", 544 (void)fprintf(stderr, " %s",
545 namelist[i].n_name); 545 namelist[i].n_name);
546 } 546 }
547 if (doexit) { 547 if (doexit) {
548 (void)fputc('\n', stderr); 548 (void)fputc('\n', stderr);
549 exit(1); 549 exit(1);
550 } 550 }
551 } 551 }
552 552
553 if ((todo & (VMSTAT|INTRSTAT)) && !(done & (VMSTAT))) { 553 if ((todo & (VMSTAT|INTRSTAT)) && !(done & (VMSTAT))) {
554 done |= VMSTAT; 554 done |= VMSTAT;
555 if ((c = kvm_nlist(kd, timenl)) == -1 || c == X_TIMENL_SIZE) 555 if ((c = kvm_nlist(kd, timenl)) == -1 || c == X_TIMENL_SIZE)
556 errx(1, "kvm_nlist: %s %s", "timenl", kvm_geterr(kd)); 556 errx(1, "kvm_nlist: %s %s", "timenl", kvm_geterr(kd));
557 } 557 }
558 if ((todo & (SUMSTAT|INTRSTAT)) && !(done & (SUMSTAT|INTRSTAT))) { 558 if ((todo & (SUMSTAT|INTRSTAT)) && !(done & (SUMSTAT|INTRSTAT))) {
559 done |= SUMSTAT|INTRSTAT; 559 done |= SUMSTAT|INTRSTAT;
560 (void) kvm_nlist(kd, intrnl); 560 (void) kvm_nlist(kd, intrnl);
561 } 561 }
562 if ((todo & (HASHLIST|HASHSTAT)) && !(done & (HASHLIST|HASHSTAT))) { 562 if ((todo & (HASHLIST|HASHSTAT)) && !(done & (HASHLIST|HASHSTAT))) {
563 done |= HASHLIST|HASHSTAT; 563 done |= HASHLIST|HASHSTAT;
564 if ((c = kvm_nlist(kd, hashnl)) == -1 || c == X_HASHNL_SIZE) 564 if ((c = kvm_nlist(kd, hashnl)) == -1 || c == X_HASHNL_SIZE)
565 errx(1, "kvm_nlist: %s %s", "hashnl", kvm_geterr(kd)); 565 errx(1, "kvm_nlist: %s %s", "hashnl", kvm_geterr(kd));
566 } 566 }
567 if ((todo & (HISTLIST|HISTDUMP)) && !(done & (HISTLIST|HISTDUMP))) { 567 if ((todo & (HISTLIST|HISTDUMP)) && !(done & (HISTLIST|HISTDUMP))) {
568 done |= HISTLIST|HISTDUMP; 568 done |= HISTLIST|HISTDUMP;
569 if (kvm_nlist(kd, histnl) == -1) 569 if (kvm_nlist(kd, histnl) == -1)
570 errx(1, "kvm_nlist: %s %s", "histnl", kvm_geterr(kd)); 570 errx(1, "kvm_nlist: %s %s", "histnl", kvm_geterr(kd));
571 } 571 }
572} 572}
573 573
574char ** 574char **
575choosedrives(char **argv) 575choosedrives(char **argv)
576{ 576{
577 size_t i, j, k; 577 size_t i, j, k;
578 578
579 /* 579 /*
580 * Choose drives to be displayed. Priority goes to (in order) drives 580 * Choose drives to be displayed. Priority goes to (in order) drives
581 * supplied as arguments, default drives. If everything isn't filled 581 * supplied as arguments, default drives. If everything isn't filled
582 * in and there are drives not taken care of, display the first few 582 * in and there are drives not taken care of, display the first few
583 * that fit. 583 * that fit.
584 */ 584 */
585#define BACKWARD_COMPATIBILITY 585#define BACKWARD_COMPATIBILITY
586 for (ndrives = 0; *argv; ++argv) { 586 for (ndrives = 0; *argv; ++argv) {
587#ifdef BACKWARD_COMPATIBILITY 587#ifdef BACKWARD_COMPATIBILITY
588 if (isdigit((unsigned char)**argv)) 588 if (isdigit((unsigned char)**argv))
589 break; 589 break;
590#endif 590#endif
591 for (i = 0; i < ndrive; i++) { 591 for (i = 0; i < ndrive; i++) {
592 if (strcmp(dr_name[i], *argv)) 592 if (strcmp(dr_name[i], *argv))
593 continue; 593 continue;
594 drv_select[i] = 1; 594 drv_select[i] = 1;
595 ++ndrives; 595 ++ndrives;
596 break; 596 break;
597 } 597 }
598 } 598 }
599 599
600 /* 600 /*
601 * Pick the most active drives. Must read the stats once before 601 * Pick the most active drives. Must read the stats once before
602 * sorting so that there is current IO data, before selecting 602 * sorting so that there is current IO data, before selecting
603 * just the first 'numdisks' (default 2) drives. 603 * just the first 'numdisks' (default 2) drives.
604 */ 604 */
605 drvreadstats(); 605 drvreadstats();
606 for (i = 0; i < ndrive && ndrives < numdisks; i++) { 606 for (i = 0; i < ndrive && ndrives < numdisks; i++) {
607 uint64_t high_bytes = 0, bytes; 607 uint64_t high_bytes = 0, bytes;
608 608
609 k = ndrive; 609 k = ndrive;
610 for (j = 0; j < ndrive; j++) { 610 for (j = 0; j < ndrive; j++) {
611 if (drv_select[j]) 611 if (drv_select[j])
612 continue; 612 continue;
613 bytes = cur.rbytes[j] + cur.wbytes[j]; 613 bytes = cur.rbytes[j] + cur.wbytes[j];
614 if (bytes > high_bytes) { 614 if (bytes > high_bytes) {
615 high_bytes = bytes; 615 high_bytes = bytes;
616 k = j; 616 k = j;
617 } 617 }
618 } 618 }
619 if (k != ndrive) { 619 if (k != ndrive) {
620 drv_select[k] = 1; 620 drv_select[k] = 1;
621 ++ndrives; 621 ++ndrives;
622 } 622 }
623 } 623 }
624 624
625 return (argv); 625 return (argv);
626} 626}
627 627
628long 628long
629getuptime(void) 629getuptime(void)
630{ 630{
631 static struct timespec boottime; 631 static struct timespec boottime;
632 struct timespec now; 632 struct timespec now;
633 time_t uptime, nowsec; 633 time_t uptime, nowsec;
634 634
635 if (memf == NULL) { 635 if (memf == NULL) {
636 if (boottime.tv_sec == 0) { 636 if (boottime.tv_sec == 0) {
637 size_t buflen = sizeof(boottime); 637 size_t buflen = sizeof(boottime);
638 if (sysctl(boottime_mib, __arraycount(boottime_mib), 638 if (sysctl(boottime_mib, __arraycount(boottime_mib),
639 &boottime, &buflen, NULL, 0) == -1) 639 &boottime, &buflen, NULL, 0) == -1)
640 warn("Can't get boottime"); 640 warn("Can't get boottime");
641 } 641 }
642 clock_gettime(CLOCK_REALTIME, &now); 642 clock_gettime(CLOCK_REALTIME, &now);
643 } else { 643 } else {
644 if (boottime.tv_sec == 0) { 644 if (boottime.tv_sec == 0) {
645 struct bintime bt; 645 struct bintime bt;
646 646
647 kread(timenl, X_TIMEBASEBIN, &bt, sizeof(bt)); 647 kread(timenl, X_TIMEBASEBIN, &bt, sizeof(bt));
648 bintime2timespec(&bt, &boottime); 648 bintime2timespec(&bt, &boottime);
649 } 649 }
650 if (kreadc(timenl, X_TIME_SECOND, &nowsec, sizeof(nowsec))) { 650 if (kreadc(timenl, X_TIME_SECOND, &nowsec, sizeof(nowsec))) {
651 /* 651 /*
652 * XXX this assignment dance can be removed once 652 * XXX this assignment dance can be removed once
653 * timeval tv_sec is SUS mandated time_t 653 * timeval tv_sec is SUS mandated time_t
654 */ 654 */
655 now.tv_sec = nowsec; 655 now.tv_sec = nowsec;
656 now.tv_nsec = 0; 656 now.tv_nsec = 0;
657 } else { 657 } else {
658 kread(timenl, X_TIME, &now, sizeof(now)); 658 kread(timenl, X_TIME, &now, sizeof(now));
659 } 659 }
660 } 660 }
661 uptime = now.tv_sec - boottime.tv_sec; 661 uptime = now.tv_sec - boottime.tv_sec;
662 if (uptime <= 0 || uptime > 60*60*24*365*10) 662 if (uptime <= 0 || uptime > 60*60*24*365*10)
663 errx(1, "time makes no sense; namelist must be wrong."); 663 errx(1, "time makes no sense; namelist must be wrong.");
664 return (uptime); 664 return (uptime);
665} 665}
666 666
667int hz, hdrcnt; 667int hz, hdrcnt;
668 668
669void 669void
670print_total_hdr(void) 670print_total_hdr(void)
671{ 671{
672 672
673 (void)printf("procs memory\n"); 673 (void)printf("procs memory\n");
674 (void)printf("ru dw pw sl"); 674 (void)printf("ru dw pw sl");
675 (void)printf(" total-v active-v active-r"); 675 (void)printf(" total-v active-v active-r");
676 (void)printf(" vm-sh avm-sh rm-sh arm-sh free\n"); 676 (void)printf(" vm-sh avm-sh rm-sh arm-sh free\n");
677 hdrcnt = winlines - 2; 677 hdrcnt = winlines - 2;
678} 678}
679 679
680void 680void
681dovmtotal(struct timespec *interval, int reps) 681dovmtotal(struct timespec *interval, int reps)
682{ 682{
683 struct vmtotal total; 683 struct vmtotal total;
684 size_t size; 684 size_t size;
685 685
686 (void)signal(SIGCONT, needhdr); 686 (void)signal(SIGCONT, needhdr);
687 687
688 for (hdrcnt = 1;;) { 688 for (hdrcnt = 1;;) {
689 if (!--hdrcnt) 689 if (!--hdrcnt)
690 print_total_hdr(); 690 print_total_hdr();
691 if (memf != NULL) { 691 if (memf != NULL) {
692 warnx("Unable to get vmtotals from crash dump."); 692 warnx("Unable to get vmtotals from crash dump.");
693 (void)memset(&total, 0, sizeof(total)); 693 (void)memset(&total, 0, sizeof(total));
694 } else { 694 } else {
695 size = sizeof(total); 695 size = sizeof(total);
696 if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib), 696 if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib),
697 &total, &size, NULL, 0) == -1) { 697 &total, &size, NULL, 0) == -1) {
698 warn("Can't get vmtotals"); 698 warn("Can't get vmtotals");
699 (void)memset(&total, 0, sizeof(total)); 699 (void)memset(&total, 0, sizeof(total));
700 } 700 }
701 } 701 }
702 (void)printf("%2d ", total.t_rq); 702 (void)printf("%2d ", total.t_rq);
703 (void)printf("%2d ", total.t_dw); 703 (void)printf("%2d ", total.t_dw);
704 (void)printf("%2d ", total.t_pw); 704 (void)printf("%2d ", total.t_pw);
705 (void)printf("%2d ", total.t_sl); 705 (void)printf("%2d ", total.t_sl);
706 706
707 (void)printf("%9d ", total.t_vm); 707 (void)printf("%9d ", total.t_vm);
708 (void)printf("%9d ", total.t_avm); 708 (void)printf("%9d ", total.t_avm);
709 (void)printf("%9d ", total.t_arm); 709 (void)printf("%9d ", total.t_arm);
710 (void)printf("%5d ", total.t_vmshr); 710 (void)printf("%5d ", total.t_vmshr);
711 (void)printf("%6d ", total.t_avmshr); 711 (void)printf("%6d ", total.t_avmshr);
712 (void)printf("%5d ", total.t_rmshr); 712 (void)printf("%5d ", total.t_rmshr);
713 (void)printf("%6d ", total.t_armshr); 713 (void)printf("%6d ", total.t_armshr);
714 (void)printf("%5d", total.t_free); 714 (void)printf("%5d", total.t_free);
715 715
716 (void)putchar('\n'); 716 (void)putchar('\n');
717 717
718 (void)fflush(stdout); 718 (void)fflush(stdout);
719 if (reps >= 0 && --reps <= 0) 719 if (reps >= 0 && --reps <= 0)
720 break; 720 break;
721 721
722 (void)nanosleep(interval, NULL); 722 (void)nanosleep(interval, NULL);
723 } 723 }
724} 724}
725 725
726void 726void
727dovmstat(struct timespec *interval, int reps) 727dovmstat(struct timespec *interval, int reps)
728{ 728{
729 struct vmtotal total; 729 struct vmtotal total;
730 time_t uptime, halfuptime; 730 time_t uptime, halfuptime;
731 size_t size; 731 size_t size;
732 int pagesize = getpagesize(); 732 int pagesize = getpagesize();
733 int ovflw; 733 int ovflw;
734 734
735 uptime = getuptime(); 735 uptime = getuptime();
736 halfuptime = uptime / 2; 736 halfuptime = uptime / 2;
737 (void)signal(SIGCONT, needhdr); 737 (void)signal(SIGCONT, needhdr);
738 738
739 if (memf != NULL) { 739 if (memf != NULL) {
740 if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0) 740 if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0)
741 kread(namelist, X_STATHZ, &hz, sizeof(hz)); 741 kread(namelist, X_STATHZ, &hz, sizeof(hz));
742 if (!hz) 742 if (!hz)
743 kread(namelist, X_HZ, &hz, sizeof(hz)); 743 kread(namelist, X_HZ, &hz, sizeof(hz));
744 } else { 744 } else {
745 struct clockinfo clockinfo; 745 struct clockinfo clockinfo;
746 size = sizeof(clockinfo); 746 size = sizeof(clockinfo);
747 if (sysctl(clockrate_mib, 2, &clockinfo, &size, NULL, 0) == -1) 747 if (sysctl(clockrate_mib, 2, &clockinfo, &size, NULL, 0) == -1)
748 err(1, "sysctl kern.clockrate failed"); 748 err(1, "sysctl kern.clockrate failed");
749 hz = clockinfo.stathz; 749 hz = clockinfo.stathz;
750 if (!hz) 750 if (!hz)
751 hz = clockinfo.hz; 751 hz = clockinfo.hz;
752 } 752 }
753 753
754 for (hdrcnt = 1;;) { 754 for (hdrcnt = 1;;) {
755 if (!--hdrcnt) 755 if (!--hdrcnt)
756 printhdr(); 756 printhdr();
757 /* Read new disk statistics */ 757 /* Read new disk statistics */
758 cpureadstats(); 758 cpureadstats();
759 drvreadstats(); 759 drvreadstats();
760 tkreadstats(); 760 tkreadstats();
761 if (memf != NULL) { 761 if (memf != NULL) {
762 struct uvmexp uvmexp_kernel; 762 struct uvmexp uvmexp_kernel;
763 /* 763 /*
764 * XXX Can't do this if we're reading a crash 764 * XXX Can't do this if we're reading a crash
765 * XXX dump because they're lazily-calculated. 765 * XXX dump because they're lazily-calculated.
766 */ 766 */
767 warnx("Unable to get vmtotals from crash dump."); 767 warnx("Unable to get vmtotals from crash dump.");
768 (void)memset(&total, 0, sizeof(total)); 768 (void)memset(&total, 0, sizeof(total));
769 kread(namelist, X_UVMEXP, &uvmexp_kernel, sizeof(uvmexp_kernel)); 769 kread(namelist, X_UVMEXP, &uvmexp_kernel, sizeof(uvmexp_kernel));
770#define COPY(field) uvmexp.field = uvmexp_kernel.field 770#define COPY(field) uvmexp.field = uvmexp_kernel.field
771 COPY(pdreact); 771 COPY(pdreact);
772 COPY(pageins); 772 COPY(pageins);
773 COPY(pgswapout); 773 COPY(pgswapout);
774 COPY(pdfreed); 774 COPY(pdfreed);
775 COPY(pdscans); 775 COPY(pdscans);
776#undef COPY 776#undef COPY
777 } else { 777 } else {
778 size = sizeof(total); 778 size = sizeof(total);
779 if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib), 779 if (sysctl(vmmeter_mib, __arraycount(vmmeter_mib),
780 &total, &size, NULL, 0) == -1) { 780 &total, &size, NULL, 0) == -1) {
781 warn("Can't get vmtotals"); 781 warn("Can't get vmtotals");
782 (void)memset(&total, 0, sizeof(total)); 782 (void)memset(&total, 0, sizeof(total));
783 } 783 }
784 size = sizeof(uvmexp); 784 size = sizeof(uvmexp);
785 if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp, 785 if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp,
786 &size, NULL, 0) == -1) 786 &size, NULL, 0) == -1)
787 warn("sysctl vm.uvmexp2 failed"); 787 warn("sysctl vm.uvmexp2 failed");
788 } 788 }
789 cpucounters(&cpucounter); 789 cpucounters(&cpucounter);
790 ovflw = 0; 790 ovflw = 0;
791 PRWORD(ovflw, " %*d", 2, 1, total.t_rq - 1); 791 PRWORD(ovflw, " %*d", 2, 1, total.t_rq - 1);
792 PRWORD(ovflw, " %*d", 2, 1, total.t_dw + total.t_pw); 792 PRWORD(ovflw, " %*d", 2, 1, total.t_dw + total.t_pw);
793#define pgtok(a) (long)((a) * ((uint32_t)pagesize >> 10)) 793#define pgtok(a) (long)((a) * ((uint32_t)pagesize >> 10))
794#define rate(x) (u_long)(((x) + halfuptime) / uptime) /* round */ 794#define rate(x) (u_long)(((x) + halfuptime) / uptime) /* round */
795 PRWORD(ovflw, " %*ld", 9, 1, pgtok(total.t_avm)); 795 PRWORD(ovflw, " %*ld", 9, 1, pgtok(total.t_avm));
796 PRWORD(ovflw, " %*ld", 7, 1, pgtok(total.t_free)); 796 PRWORD(ovflw, " %*ld", 7, 1, pgtok(total.t_free));
797 PRWORD(ovflw, " %*ld", 5, 1, 797 PRWORD(ovflw, " %*ld", 5, 1,
798 rate(cpucounter.nfault - ocpucounter.nfault)); 798 rate(cpucounter.nfault - ocpucounter.nfault));
799 PRWORD(ovflw, " %*ld", 4, 1, 799 PRWORD(ovflw, " %*ld", 4, 1,
800 rate(uvmexp.pdreact - ouvmexp.pdreact)); 800 rate(uvmexp.pdreact - ouvmexp.pdreact));
801 PRWORD(ovflw, " %*ld", 4, 1, 801 PRWORD(ovflw, " %*ld", 4, 1,
802 rate(uvmexp.pageins - ouvmexp.pageins)); 802 rate(uvmexp.pageins - ouvmexp.pageins));
803 PRWORD(ovflw, " %*ld", 5, 1, 803 PRWORD(ovflw, " %*ld", 5, 1,
804 rate(uvmexp.pgswapout - ouvmexp.pgswapout)); 804 rate(uvmexp.pgswapout - ouvmexp.pgswapout));
805 PRWORD(ovflw, " %*ld", 5, 1, 805 PRWORD(ovflw, " %*ld", 5, 1,
806 rate(uvmexp.pdfreed - ouvmexp.pdfreed)); 806 rate(uvmexp.pdfreed - ouvmexp.pdfreed));
807 PRWORD(ovflw, " %*ld", 6, 2, 807 PRWORD(ovflw, " %*ld", 6, 2,
808 rate(uvmexp.pdscans - ouvmexp.pdscans)); 808 rate(uvmexp.pdscans - ouvmexp.pdscans));
809 drvstats(&ovflw); 809 drvstats(&ovflw);
810 PRWORD(ovflw, " %*ld", 5, 1, 810 PRWORD(ovflw, " %*ld", 5, 1,
811 rate(cpucounter.nintr - ocpucounter.nintr)); 811 rate(cpucounter.nintr - ocpucounter.nintr));
812 PRWORD(ovflw, " %*ld", 5, 1, 812 PRWORD(ovflw, " %*ld", 5, 1,
813 rate(cpucounter.nsyscall - ocpucounter.nsyscall)); 813 rate(cpucounter.nsyscall - ocpucounter.nsyscall));
814 PRWORD(ovflw, " %*ld", 4, 1, 814 PRWORD(ovflw, " %*ld", 4, 1,
815 rate(cpucounter.nswtch - ocpucounter.nswtch)); 815 rate(cpucounter.nswtch - ocpucounter.nswtch));
816 cpustats(&ovflw); 816 cpustats(&ovflw);
817 (void)putchar('\n'); 817 (void)putchar('\n');
818 (void)fflush(stdout); 818 (void)fflush(stdout);
819 if (reps >= 0 && --reps <= 0) 819 if (reps >= 0 && --reps <= 0)
820 break; 820 break;
821 ouvmexp = uvmexp; 821 ouvmexp = uvmexp;
822 ocpucounter = cpucounter; 822 ocpucounter = cpucounter;
823 uptime = interval->tv_sec; 823 uptime = interval->tv_sec;
824 /* 824 /*
825 * We round upward to avoid losing low-frequency events 825 * We round upward to avoid losing low-frequency events
826 * (i.e., >= 1 per interval but < 1 per second). 826 * (i.e., >= 1 per interval but < 1 per second).
827 */ 827 */
828 halfuptime = uptime == 1 ? 0 : (uptime + 1) / 2; 828 halfuptime = uptime == 1 ? 0 : (uptime + 1) / 2;
829 (void)nanosleep(interval, NULL); 829 (void)nanosleep(interval, NULL);
830 } 830 }
831} 831}
832 832
833void 833void
834printhdr(void) 834printhdr(void)
835{ 835{
836 size_t i; 836 size_t i;
837 837
838 (void)printf(" procs memory page%*s", 23, ""); 838 (void)printf(" procs memory page%*s", 23, "");
839 if (ndrives > 0) 839 if (ndrives > 0)
840 (void)printf("%s %*sfaults cpu\n", 840 (void)printf("%s %*sfaults cpu\n",
841 ((ndrives > 1) ? "disks" : "disk"), 841 ((ndrives > 1) ? "disks" : "disk"),
842 ((ndrives > 1) ? ndrives * 3 - 4 : 0), ""); 842 ((ndrives > 1) ? ndrives * 3 - 4 : 0), "");
843 else 843 else
844 (void)printf("%*s faults cpu\n", 844 (void)printf("%*s faults cpu\n",
845 ndrives * 3, ""); 845 ndrives * 3, "");
846 846
847 (void)printf(" r b avm fre flt re pi po fr sr "); 847 (void)printf(" r b avm fre flt re pi po fr sr ");
848 for (i = 0; i < ndrive; i++) 848 for (i = 0; i < ndrive; i++)
849 if (drv_select[i]) 849 if (drv_select[i])
850 (void)printf("%c%c ", dr_name[i][0], 850 (void)printf("%c%c ", dr_name[i][0],
851 dr_name[i][strlen(dr_name[i]) - 1]); 851 dr_name[i][strlen(dr_name[i]) - 1]);
852 (void)printf(" in sy cs us sy id\n"); 852 (void)printf(" in sy cs us sy id\n");
853 hdrcnt = winlines - 2; 853 hdrcnt = winlines - 2;
854} 854}
855 855
856/* 856/*
857 * Force a header to be prepended to the next output. 857 * Force a header to be prepended to the next output.
858 */ 858 */
859void 859void
860/*ARGSUSED*/ 860/*ARGSUSED*/
861needhdr(int dummy) 861needhdr(int dummy)
862{ 862{
863 863
864 hdrcnt = 1; 864 hdrcnt = 1;
865} 865}
866 866
867long 867long
868pct(u_long top, u_long bot) 868pct(u_long top, u_long bot)
869{ 869{
870 long ans; 870 long ans;
871 871
872 if (bot == 0) 872 if (bot == 0)
873 return (0); 873 return (0);
874 ans = (long)((quad_t)top * 100 / bot); 874 ans = (long)((quad_t)top * 100 / bot);
875 return (ans); 875 return (ans);
876} 876}
877 877
878#define PCT(top, bot) (int)pct((u_long)(top), (u_long)(bot)) 878#define PCT(top, bot) (int)pct((u_long)(top), (u_long)(bot))
879 879
880void 880void
881dosum(void) 881dosum(void)
882{ 882{
883 struct nchstats nch_stats; 883 struct nchstats nch_stats;
884 uint64_t nchtotal; 884 uint64_t nchtotal;
885 size_t ssize; 885 size_t ssize;
886 int active_kernel; 886 int active_kernel;
887 struct cpu_counter cc; 887 struct cpu_counter cc;
888 888
889 /* 889 /*
890 * The "active" and "inactive" variables 890 * The "active" and "inactive" variables
891 * are now estimated by the kernel and sadly 891 * are now estimated by the kernel and sadly
892 * can not easily be dug out of a crash dump. 892 * can not easily be dug out of a crash dump.
893 */ 893 */
894 ssize = sizeof(uvmexp); 894 ssize = sizeof(uvmexp);
895 memset(&uvmexp, 0, ssize); 895 memset(&uvmexp, 0, ssize);
896 active_kernel = (memf == NULL); 896 active_kernel = (memf == NULL);
897 if (active_kernel) { 897 if (active_kernel) {
898 /* only on active kernel */ 898 /* only on active kernel */
899 if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp, 899 if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp,
900 &ssize, NULL, 0) == -1) 900 &ssize, NULL, 0) == -1)
901 warn("sysctl vm.uvmexp2 failed"); 901 warn("sysctl vm.uvmexp2 failed");
902 } else { 902 } else {
903 struct uvmexp uvmexp_kernel; 903 struct uvmexp uvmexp_kernel;
904 struct pool pool, *pp = &pool; 904 struct pool pool, *pp = &pool;
905 struct pool_allocator pa; 905 struct pool_allocator pa;
906 TAILQ_HEAD(,pool) pool_head; 906 TAILQ_HEAD(,pool) pool_head;
907 void *addr; 907 void *addr;
908 uint64_t bytes; 908 uint64_t bytes;
909 909
910 kread(namelist, X_UVMEXP, &uvmexp_kernel, sizeof(uvmexp_kernel)); 910 kread(namelist, X_UVMEXP, &uvmexp_kernel, sizeof(uvmexp_kernel));
911#define COPY(field) uvmexp.field = uvmexp_kernel.field 911#define COPY(field) uvmexp.field = uvmexp_kernel.field
912 COPY(pagesize); 912 COPY(pagesize);
913 COPY(ncolors); 913 COPY(ncolors);
914 COPY(npages); 914 COPY(npages);
915 COPY(free); 915 COPY(free);
916 COPY(paging); 916 COPY(paging);
917 COPY(wired); 917 COPY(wired);
918 COPY(reserve_pagedaemon); 918 COPY(reserve_pagedaemon);
919 COPY(reserve_kernel); 919 COPY(reserve_kernel);
920 COPY(anonpages); 920 COPY(anonpages);
921 COPY(filepages); 921 COPY(filepages);
922 COPY(execpages); 922 COPY(execpages);
923 COPY(freemin); 923 COPY(freemin);
924 COPY(freetarg); 924 COPY(freetarg);
925 COPY(wiredmax); 925 COPY(wiredmax);
926 COPY(nswapdev); 926 COPY(nswapdev);
927 COPY(swpages); 927 COPY(swpages);
928 COPY(swpginuse); 928 COPY(swpginuse);
929 COPY(nswget); 929 COPY(nswget);
930 COPY(pageins); 930 COPY(pageins);
931 COPY(pdpageouts); 931 COPY(pdpageouts);
932 COPY(pgswapin); 932 COPY(pgswapin);
933 COPY(pgswapout); 933 COPY(pgswapout);
934 COPY(forks); 934 COPY(forks);
935 COPY(forks_ppwait); 935 COPY(forks_ppwait);
936 COPY(forks_sharevm); 936 COPY(forks_sharevm);
937 COPY(colorhit); 937 COPY(colorhit);
938 COPY(colormiss); 938 COPY(colormiss);
939 COPY(cpuhit); 939 COPY(cpuhit);
940 COPY(cpumiss); 940 COPY(cpumiss);
941 COPY(fltnoram); 941 COPY(fltnoram);
942 COPY(fltnoanon); 942 COPY(fltnoanon);
943 COPY(fltpgwait); 943 COPY(fltpgwait);
944 COPY(fltpgrele); 944 COPY(fltpgrele);
945 COPY(fltrelck); 945 COPY(fltrelck);
946 COPY(fltrelckok); 946 COPY(fltrelckok);
947 COPY(fltanget); 947 COPY(fltanget);
948 COPY(fltanretry); 948 COPY(fltanretry);
949 COPY(fltamcopy); 949 COPY(fltamcopy);
950 COPY(fltamcopy); 950 COPY(fltamcopy);
951 COPY(fltnomap); 951 COPY(fltnomap);
952 COPY(fltlget); 952 COPY(fltlget);
953 COPY(fltget); 953 COPY(fltget);
954 COPY(flt_anon); 954 COPY(flt_anon);
955 COPY(flt_acow); 955 COPY(flt_acow);
956 COPY(flt_obj); 956 COPY(flt_obj);
957 COPY(flt_prcopy); 957 COPY(flt_prcopy);
958 COPY(flt_przero); 958 COPY(flt_przero);
959 COPY(pdwoke); 959 COPY(pdwoke);
960 COPY(pdrevs); 960 COPY(pdrevs);
961 COPY(pdfreed); 961 COPY(pdfreed);
962 COPY(pdscans); 962 COPY(pdscans);
963 COPY(pdanscan); 963 COPY(pdanscan);
964 COPY(pdobscan); 964 COPY(pdobscan);
965 COPY(pdreact); 965 COPY(pdreact);
966 COPY(pdbusy); 966 COPY(pdbusy);
967 COPY(pdpending); 967 COPY(pdpending);
968 COPY(pddeact); 968 COPY(pddeact);
969 COPY(bootpages); 969 COPY(bootpages);
970#undef COPY 970#undef COPY
971 kread(namelist, X_POOLHEAD, &pool_head, sizeof(pool_head)); 971 kread(namelist, X_POOLHEAD, &pool_head, sizeof(pool_head));
972 addr = TAILQ_FIRST(&pool_head); 972 addr = TAILQ_FIRST(&pool_head);
973 uvmexp.poolpages = 0; 973 uvmexp.poolpages = 0;
974 for (; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist)) { 974 for (; addr != NULL; addr = TAILQ_NEXT(pp, pr_poollist)) {
975 deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed"); 975 deref_kptr(addr, pp, sizeof(*pp), "pool chain trashed");
976 deref_kptr(pp->pr_alloc, &pa, sizeof(pa), 976 deref_kptr(pp->pr_alloc, &pa, sizeof(pa),
977 "pool allocator trashed"); 977 "pool allocator trashed");
978 bytes = pp->pr_npages * pa.pa_pagesz; 978 bytes = pp->pr_npages * pa.pa_pagesz;
979 if ((pp->pr_roflags & PR_RECURSIVE) != 0) 979 if ((pp->pr_roflags & PR_RECURSIVE) != 0)
980 bytes -= (pp->pr_nout * pp->pr_size); 980 bytes -= (pp->pr_nout * pp->pr_size);
981 uvmexp.poolpages += bytes / uvmexp.pagesize; 981 uvmexp.poolpages += bytes / uvmexp.pagesize;
982 } 982 }
983 } 983 }
984 984
985 985
986 (void)printf("%9" PRIu64 " bytes per page\n", uvmexp.pagesize); 986 (void)printf("%9" PRIu64 " bytes per page\n", uvmexp.pagesize);
987 987
988 (void)printf("%9" PRIu64 " page color%s\n", 988 (void)printf("%9" PRIu64 " page color%s\n",
989 uvmexp.ncolors, uvmexp.ncolors == 1 ? "" : "s"); 989 uvmexp.ncolors, uvmexp.ncolors == 1 ? "" : "s");
990 990
991 (void)printf("%9" PRIu64 " pages managed\n", uvmexp.npages); 991 (void)printf("%9" PRIu64 " pages managed\n", uvmexp.npages);
992 (void)printf("%9" PRIu64 " pages free\n", uvmexp.free); 992 (void)printf("%9" PRIu64 " pages free\n", uvmexp.free);
993 if (active_kernel) { 993 if (active_kernel) {
994 (void)printf("%9" PRIu64 " pages active\n", uvmexp.active); 994 (void)printf("%9" PRIu64 " pages active\n", uvmexp.active);
995 (void)printf("%9" PRIu64 " pages inactive\n", uvmexp.inactive); 995 (void)printf("%9" PRIu64 " pages inactive\n", uvmexp.inactive);
996 } 996 }
997 (void)printf("%9" PRIu64 " pages paging\n", uvmexp.paging); 997 (void)printf("%9" PRIu64 " pages paging\n", uvmexp.paging);
998 (void)printf("%9" PRIu64 " pages wired\n", uvmexp.wired); 998 (void)printf("%9" PRIu64 " pages wired\n", uvmexp.wired);
999 (void)printf("%9" PRIu64 " reserve pagedaemon pages\n", 999 (void)printf("%9" PRIu64 " reserve pagedaemon pages\n",
1000 uvmexp.reserve_pagedaemon); 1000 uvmexp.reserve_pagedaemon);
1001 (void)printf("%9" PRIu64 " reserve kernel pages\n", uvmexp.reserve_kernel); 1001 (void)printf("%9" PRIu64 " reserve kernel pages\n", uvmexp.reserve_kernel);
1002 (void)printf("%9" PRIu64 " boot kernel pages\n", uvmexp.bootpages); 1002 (void)printf("%9" PRIu64 " boot kernel pages\n", uvmexp.bootpages);
1003 (void)printf("%9" PRIu64 " kernel pool pages\n", uvmexp.poolpages); 1003 (void)printf("%9" PRIu64 " kernel pool pages\n", uvmexp.poolpages);
1004 (void)printf("%9" PRIu64 " anonymous pages\n", uvmexp.anonpages); 1004 (void)printf("%9" PRIu64 " anonymous pages\n", uvmexp.anonpages);
1005 (void)printf("%9" PRIu64 " cached file pages\n", uvmexp.filepages); 1005 (void)printf("%9" PRIu64 " cached file pages\n", uvmexp.filepages);
1006 (void)printf("%9" PRIu64 " cached executable pages\n", uvmexp.execpages); 1006 (void)printf("%9" PRIu64 " cached executable pages\n", uvmexp.execpages);
1007 1007
1008 (void)printf("%9" PRIu64 " minimum free pages\n", uvmexp.freemin); 1008 (void)printf("%9" PRIu64 " minimum free pages\n", uvmexp.freemin);
1009 (void)printf("%9" PRIu64 " target free pages\n", uvmexp.freetarg); 1009 (void)printf("%9" PRIu64 " target free pages\n", uvmexp.freetarg);
1010 (void)printf("%9" PRIu64 " maximum wired pages\n", uvmexp.wiredmax); 1010 (void)printf("%9" PRIu64 " maximum wired pages\n", uvmexp.wiredmax);
1011 1011
1012 (void)printf("%9" PRIu64 " swap devices\n", uvmexp.nswapdev); 1012 (void)printf("%9" PRIu64 " swap devices\n", uvmexp.nswapdev);
1013 (void)printf("%9" PRIu64 " swap pages\n", uvmexp.swpages); 1013 (void)printf("%9" PRIu64 " swap pages\n", uvmexp.swpages);
1014 (void)printf("%9" PRIu64 " swap pages in use\n", uvmexp.swpginuse); 1014 (void)printf("%9" PRIu64 " swap pages in use\n", uvmexp.swpginuse);
1015 (void)printf("%9" PRIu64 " swap allocations\n", uvmexp.nswget); 1015 (void)printf("%9" PRIu64 " swap allocations\n", uvmexp.nswget);
1016 1016
1017 cpucounters(&cc); 1017 cpucounters(&cc);
1018 1018
1019 (void)printf("%9" PRIu64 " total faults taken\n", cc.nfault); 1019 (void)printf("%9" PRIu64 " total faults taken\n", cc.nfault);
1020 (void)printf("%9" PRIu64 " traps\n", cc.ntrap); 1020 (void)printf("%9" PRIu64 " traps\n", cc.ntrap);
1021 (void)printf("%9" PRIu64 " device interrupts\n", cc.nintr); 1021 (void)printf("%9" PRIu64 " device interrupts\n", cc.nintr);
1022 (void)printf("%9" PRIu64 " CPU context switches\n", cc.nswtch); 1022 (void)printf("%9" PRIu64 " CPU context switches\n", cc.nswtch);
1023 (void)printf("%9" PRIu64 " software interrupts\n", cc.nsoft); 1023 (void)printf("%9" PRIu64 " software interrupts\n", cc.nsoft);
1024 (void)printf("%9" PRIu64 " system calls\n", cc.nsyscall); 1024 (void)printf("%9" PRIu64 " system calls\n", cc.nsyscall);
1025 (void)printf("%9" PRIu64 " pagein requests\n", uvmexp.pageins); 1025 (void)printf("%9" PRIu64 " pagein requests\n", uvmexp.pageins);
1026 (void)printf("%9" PRIu64 " pageout requests\n", uvmexp.pdpageouts); 1026 (void)printf("%9" PRIu64 " pageout requests\n", uvmexp.pdpageouts);
1027 (void)printf("%9" PRIu64 " pages swapped in\n", uvmexp.pgswapin); 1027 (void)printf("%9" PRIu64 " pages swapped in\n", uvmexp.pgswapin);
1028 (void)printf("%9" PRIu64 " pages swapped out\n", uvmexp.pgswapout); 1028 (void)printf("%9" PRIu64 " pages swapped out\n", uvmexp.pgswapout);
1029 (void)printf("%9" PRIu64 " forks total\n", uvmexp.forks); 1029 (void)printf("%9" PRIu64 " forks total\n", uvmexp.forks);
1030 (void)printf("%9" PRIu64 " forks blocked parent\n", uvmexp.forks_ppwait); 1030 (void)printf("%9" PRIu64 " forks blocked parent\n", uvmexp.forks_ppwait);
1031 (void)printf("%9" PRIu64 " forks shared address space with parent\n", 1031 (void)printf("%9" PRIu64 " forks shared address space with parent\n",
1032 uvmexp.forks_sharevm); 1032 uvmexp.forks_sharevm);
1033 (void)printf("%9" PRIu64 " pagealloc desired color avail\n", 1033 (void)printf("%9" PRIu64 " pagealloc desired color avail\n",
1034 uvmexp.colorhit); 1034 uvmexp.colorhit);
1035 (void)printf("%9" PRIu64 " pagealloc desired color not avail\n", 1035 (void)printf("%9" PRIu64 " pagealloc desired color not avail\n",
1036 uvmexp.colormiss); 1036 uvmexp.colormiss);
1037 (void)printf("%9" PRIu64 " pagealloc local cpu avail\n", 1037 (void)printf("%9" PRIu64 " pagealloc local cpu avail\n",
1038 uvmexp.cpuhit); 1038 uvmexp.cpuhit);
1039 (void)printf("%9" PRIu64 " pagealloc local cpu not avail\n", 1039 (void)printf("%9" PRIu64 " pagealloc local cpu not avail\n",
1040 uvmexp.cpumiss); 1040 uvmexp.cpumiss);
1041 1041
1042 (void)printf("%9" PRIu64 " faults with no memory\n", uvmexp.fltnoram); 1042 (void)printf("%9" PRIu64 " faults with no memory\n", uvmexp.fltnoram);
1043 (void)printf("%9" PRIu64 " faults with no anons\n", uvmexp.fltnoanon); 1043 (void)printf("%9" PRIu64 " faults with no anons\n", uvmexp.fltnoanon);
1044 (void)printf("%9" PRIu64 " faults had to wait on pages\n", uvmexp.fltpgwait); 1044 (void)printf("%9" PRIu64 " faults had to wait on pages\n", uvmexp.fltpgwait);
1045 (void)printf("%9" PRIu64 " faults found released page\n", uvmexp.fltpgrele); 1045 (void)printf("%9" PRIu64 " faults found released page\n", uvmexp.fltpgrele);
1046 (void)printf("%9" PRIu64 " faults relock (%" PRIu64 " ok)\n", uvmexp.fltrelck, 1046 (void)printf("%9" PRIu64 " faults relock (%" PRIu64 " ok)\n", uvmexp.fltrelck,
1047 uvmexp.fltrelckok); 1047 uvmexp.fltrelckok);
1048 (void)printf("%9" PRIu64 " anon page faults\n", uvmexp.fltanget); 1048 (void)printf("%9" PRIu64 " anon page faults\n", uvmexp.fltanget);
1049 (void)printf("%9" PRIu64 " anon retry faults\n", uvmexp.fltanretry); 1049 (void)printf("%9" PRIu64 " anon retry faults\n", uvmexp.fltanretry);
1050 (void)printf("%9" PRIu64 " amap copy faults\n", uvmexp.fltamcopy); 1050 (void)printf("%9" PRIu64 " amap copy faults\n", uvmexp.fltamcopy);
1051 (void)printf("%9" PRIu64 " neighbour anon page faults\n", uvmexp.fltnamap); 1051 (void)printf("%9" PRIu64 " neighbour anon page faults\n", uvmexp.fltnamap);
1052 (void)printf("%9" PRIu64 " neighbour object page faults\n", uvmexp.fltnomap); 1052 (void)printf("%9" PRIu64 " neighbour object page faults\n", uvmexp.fltnomap);
1053 (void)printf("%9" PRIu64 " locked pager get faults\n", uvmexp.fltlget); 1053 (void)printf("%9" PRIu64 " locked pager get faults\n", uvmexp.fltlget);
1054 (void)printf("%9" PRIu64 " unlocked pager get faults\n", uvmexp.fltget); 1054 (void)printf("%9" PRIu64 " unlocked pager get faults\n", uvmexp.fltget);
1055 (void)printf("%9" PRIu64 " anon faults\n", uvmexp.flt_anon); 1055 (void)printf("%9" PRIu64 " anon faults\n", uvmexp.flt_anon);
1056 (void)printf("%9" PRIu64 " anon copy on write faults\n", uvmexp.flt_acow); 1056 (void)printf("%9" PRIu64 " anon copy on write faults\n", uvmexp.flt_acow);
1057 (void)printf("%9" PRIu64 " object faults\n", uvmexp.flt_obj); 1057 (void)printf("%9" PRIu64 " object faults\n", uvmexp.flt_obj);
1058 (void)printf("%9" PRIu64 " promote copy faults\n", uvmexp.flt_prcopy); 1058 (void)printf("%9" PRIu64 " promote copy faults\n", uvmexp.flt_prcopy);
1059 (void)printf("%9" PRIu64 " promote zero fill faults\n", uvmexp.flt_przero); 1059 (void)printf("%9" PRIu64 " promote zero fill faults\n", uvmexp.flt_przero);
1060 (void)printf("%9" PRIu64 " faults upgraded lock\n", 1060 (void)printf("%9" PRIu64 " faults upgraded lock\n",
1061 uvmexp.fltup); 1061 uvmexp.fltup);
1062 (void)printf("%9" PRIu64 " faults couldn't upgrade lock\n", 1062 (void)printf("%9" PRIu64 " faults couldn't upgrade lock\n",
1063 uvmexp.fltnoup); 1063 uvmexp.fltnoup);
1064 1064
1065 (void)printf("%9" PRIu64 " times daemon wokeup\n",uvmexp.pdwoke); 1065 (void)printf("%9" PRIu64 " times daemon wokeup\n",uvmexp.pdwoke);
1066 (void)printf("%9" PRIu64 " revolutions of the clock hand\n", uvmexp.pdrevs); 1066 (void)printf("%9" PRIu64 " revolutions of the clock hand\n", uvmexp.pdrevs);
1067 (void)printf("%9" PRIu64 " pages freed by daemon\n", uvmexp.pdfreed); 1067 (void)printf("%9" PRIu64 " pages freed by daemon\n", uvmexp.pdfreed);
1068 (void)printf("%9" PRIu64 " pages scanned by daemon\n", uvmexp.pdscans); 1068 (void)printf("%9" PRIu64 " pages scanned by daemon\n", uvmexp.pdscans);
1069 (void)printf("%9" PRIu64 " anonymous pages scanned by daemon\n", 1069 (void)printf("%9" PRIu64 " anonymous pages scanned by daemon\n",
1070 uvmexp.pdanscan); 1070 uvmexp.pdanscan);
1071 (void)printf("%9" PRIu64 " object pages scanned by daemon\n", uvmexp.pdobscan); 1071 (void)printf("%9" PRIu64 " object pages scanned by daemon\n", uvmexp.pdobscan);
1072 (void)printf("%9" PRIu64 " pages reactivated\n", uvmexp.pdreact); 1072 (void)printf("%9" PRIu64 " pages reactivated\n", uvmexp.pdreact);
1073 (void)printf("%9" PRIu64 " pages found busy by daemon\n", uvmexp.pdbusy); 1073 (void)printf("%9" PRIu64 " pages found busy by daemon\n", uvmexp.pdbusy);
1074 (void)printf("%9" PRIu64 " total pending pageouts\n", uvmexp.pdpending); 1074 (void)printf("%9" PRIu64 " total pending pageouts\n", uvmexp.pdpending);
1075 (void)printf("%9" PRIu64 " pages deactivated\n", uvmexp.pddeact); 1075 (void)printf("%9" PRIu64 " pages deactivated\n", uvmexp.pddeact);
1076 (void)printf("%9" PRIu64 " per-cpu stats synced\n", uvmexp.countsyncall); 1076 (void)printf("%9" PRIu64 " per-cpu stats synced\n", uvmexp.countsyncall);
1077 (void)printf("%9" PRIu64 " anon pages possibly dirty\n", uvmexp.anonunknown); 1077 (void)printf("%9" PRIu64 " anon pages possibly dirty\n", uvmexp.anonunknown);
1078 (void)printf("%9" PRIu64 " anon pages dirty\n", uvmexp.anondirty); 1078 (void)printf("%9" PRIu64 " anon pages dirty\n", uvmexp.anondirty);
1079 (void)printf("%9" PRIu64 " anon pages clean\n", uvmexp.anonclean); 1079 (void)printf("%9" PRIu64 " anon pages clean\n", uvmexp.anonclean);
1080 (void)printf("%9" PRIu64 " file pages possibly dirty\n", uvmexp.fileunknown); 1080 (void)printf("%9" PRIu64 " file pages possibly dirty\n", uvmexp.fileunknown);
1081 (void)printf("%9" PRIu64 " file pages dirty\n", uvmexp.filedirty); 1081 (void)printf("%9" PRIu64 " file pages dirty\n", uvmexp.filedirty);
1082 (void)printf("%9" PRIu64 " file pages clean\n", uvmexp.fileclean); 1082 (void)printf("%9" PRIu64 " file pages clean\n", uvmexp.fileclean);
1083 1083
1084 if (active_kernel) { 1084 if (active_kernel) {
1085 ssize = sizeof(nch_stats); 1085 ssize = sizeof(nch_stats);
1086 if (sysctlbyname("vfs.namecache_stats", &nch_stats, &ssize, 1086 if (sysctlbyname("vfs.namecache_stats", &nch_stats, &ssize,
1087 NULL, 0)) { 1087 NULL, 0)) {
1088 warn("vfs.namecache_stats failed"); 1088 warn("vfs.namecache_stats failed");
1089 memset(&nch_stats, 0, sizeof(nch_stats)); 1089 memset(&nch_stats, 0, sizeof(nch_stats));
1090 } 1090 }
1091 } else { 1091 } else {
1092 kread(namelist, X_NCHSTATS, &nch_stats, sizeof(nch_stats)); 1092 kread(namelist, X_NCHSTATS, &nch_stats, sizeof(nch_stats));
1093 } 1093 }
1094 1094
1095 nchtotal = nch_stats.ncs_goodhits + nch_stats.ncs_neghits + 1095 nchtotal = nch_stats.ncs_goodhits + nch_stats.ncs_neghits +
1096 nch_stats.ncs_badhits + nch_stats.ncs_falsehits + 1096 nch_stats.ncs_badhits + nch_stats.ncs_falsehits +
1097 nch_stats.ncs_miss + nch_stats.ncs_long; 1097 nch_stats.ncs_miss + nch_stats.ncs_long;
1098 (void)printf("%9" PRIu64 " total name lookups\n", nchtotal); 1098 (void)printf("%9" PRIu64 " total name lookups\n", nchtotal);
1099 (void)printf("%9" PRIu64 " good hits\n", nch_stats.ncs_goodhits); 1099 (void)printf("%9" PRIu64 " good hits\n", nch_stats.ncs_goodhits);
1100 (void)printf("%9" PRIu64 " negative hits\n", nch_stats.ncs_neghits); 1100 (void)printf("%9" PRIu64 " negative hits\n", nch_stats.ncs_neghits);
1101 (void)printf("%9" PRIu64 " bad hits\n", nch_stats.ncs_badhits); 1101 (void)printf("%9" PRIu64 " bad hits\n", nch_stats.ncs_badhits);
1102 (void)printf("%9" PRIu64 " false hits\n", nch_stats.ncs_falsehits); 1102 (void)printf("%9" PRIu64 " false hits\n", nch_stats.ncs_falsehits);
1103 (void)printf("%9" PRIu64 " miss\n", nch_stats.ncs_miss); 1103 (void)printf("%9" PRIu64 " miss\n", nch_stats.ncs_miss);
1104 (void)printf("%9" PRIu64 " too long\n", nch_stats.ncs_long); 1104 (void)printf("%9" PRIu64 " too long\n", nch_stats.ncs_long);
1105 (void)printf("%9" PRIu64 " pass2 hits\n", nch_stats.ncs_pass2); 1105 (void)printf("%9" PRIu64 " pass2 hits\n", nch_stats.ncs_pass2);
1106 (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes); 1106 (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes);
1107 (void)printf("%9" PRIu64 " reverse hits\n", nch_stats.ncs_revhits); 1107 (void)printf("%9" PRIu64 " reverse hits\n", nch_stats.ncs_revhits);
1108 (void)printf("%9" PRIu64 " reverse miss\n", nch_stats.ncs_revmiss); 1108 (void)printf("%9" PRIu64 " reverse miss\n", nch_stats.ncs_revmiss);
1109 (void)printf("%9" PRIu64 " access denied\n", nch_stats.ncs_denied); 1109 (void)printf("%9" PRIu64 " access denied\n", nch_stats.ncs_denied);
1110 (void)printf( 1110 (void)printf(
1111 "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n", 1111 "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
1112 "", PCT(nch_stats.ncs_goodhits, nchtotal), 1112 "", PCT(nch_stats.ncs_goodhits, nchtotal),
1113 PCT(nch_stats.ncs_neghits, nchtotal), 1113 PCT(nch_stats.ncs_neghits, nchtotal),
1114 PCT(nch_stats.ncs_pass2, nchtotal)); 1114 PCT(nch_stats.ncs_pass2, nchtotal));
1115 (void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "", 1115 (void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "",
1116 PCT(nch_stats.ncs_badhits, nchtotal), 1116 PCT(nch_stats.ncs_badhits, nchtotal),
1117 PCT(nch_stats.ncs_falsehits, nchtotal), 1117 PCT(nch_stats.ncs_falsehits, nchtotal),
1118 PCT(nch_stats.ncs_long, nchtotal)); 1118 PCT(nch_stats.ncs_long, nchtotal));
1119} 1119}
1120 1120
1121void 1121void
1122doforkst(void) 1122doforkst(void)
1123{ 1123{
1124 if (memf != NULL) { 1124 if (memf != NULL) {
1125 struct uvmexp uvmexp_kernel; 1125 struct uvmexp uvmexp_kernel;
1126 kread(namelist, X_UVMEXP, &uvmexp_kernel, sizeof(uvmexp_kernel)); 1126 kread(namelist, X_UVMEXP, &uvmexp_kernel, sizeof(uvmexp_kernel));
1127#define COPY(field) uvmexp.field = uvmexp_kernel.field 1127#define COPY(field) uvmexp.field = uvmexp_kernel.field
1128 COPY(forks); 1128 COPY(forks);
1129 COPY(forks_ppwait); 1129 COPY(forks_ppwait);
1130 COPY(forks_sharevm); 1130 COPY(forks_sharevm);
1131#undef COPY 1131#undef COPY
1132 } else { 1132 } else {
1133 size_t size = sizeof(uvmexp); 1133 size_t size = sizeof(uvmexp);
1134 if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp, 1134 if (sysctl(uvmexp2_mib, __arraycount(uvmexp2_mib), &uvmexp,
1135 &size, NULL, 0) == -1) 1135 &size, NULL, 0) == -1)
1136 warn("sysctl vm.uvmexp2 failed"); 1136 warn("sysctl vm.uvmexp2 failed");
1137 } 1137 }
1138 1138
1139 (void)printf("%" PRIu64 " forks total\n", uvmexp.forks); 1139 (void)printf("%" PRIu64 " forks total\n", uvmexp.forks);
1140 (void)printf("%" PRIu64 " forks blocked parent\n", uvmexp.forks_ppwait); 1140 (void)printf("%" PRIu64 " forks blocked parent\n", uvmexp.forks_ppwait);
1141 (void)printf("%" PRIu64 " forks shared address space with parent\n", 1141 (void)printf("%" PRIu64 " forks shared address space with parent\n",
1142 uvmexp.forks_sharevm); 1142 uvmexp.forks_sharevm);
1143} 1143}
1144 1144
1145void 1145void
1146drvstats(int *ovflwp) 1146drvstats(int *ovflwp)
1147{ 1147{
1148 size_t dn; 1148 size_t dn;
1149 double dtime; 1149 double dtime;
1150 int ovflw = *ovflwp; 1150 int ovflw = *ovflwp;
1151 1151
1152 /* Calculate disk stat deltas. */ 1152 /* Calculate disk stat deltas. */
1153 cpuswap(); 1153 cpuswap();
1154 drvswap(); 1154 drvswap();
1155 tkswap(); 1155 tkswap();
1156 1156
1157 for (dn = 0; dn < ndrive; ++dn) { 1157 for (dn = 0; dn < ndrive; ++dn) {
1158 /* elapsed time for disk stats */ 1158 /* elapsed time for disk stats */
1159 dtime = cur.cp_etime; 1159 dtime = cur.cp_etime;
1160 if (cur.timestamp[dn].tv_sec || cur.timestamp[dn].tv_usec) { 1160 if (cur.timestamp[dn].tv_sec || cur.timestamp[dn].tv_usec) {
1161 dtime = (double)cur.timestamp[dn].tv_sec + 1161 dtime = (double)cur.timestamp[dn].tv_sec +
1162 ((double)cur.timestamp[dn].tv_usec / (double)1000000); 1162 ((double)cur.timestamp[dn].tv_usec / (double)1000000);
1163 } 1163 }
1164 1164
1165 if (!drv_select[dn]) 1165 if (!drv_select[dn])
1166 continue; 1166 continue;
1167 PRWORD(ovflw, " %*.0f", 3, 1, 1167 PRWORD(ovflw, " %*.0f", 3, 1,
1168 (cur.rxfer[dn] + cur.wxfer[dn]) / dtime); 1168 (cur.rxfer[dn] + cur.wxfer[dn]) / dtime);
1169 } 1169 }
1170 *ovflwp = ovflw; 1170 *ovflwp = ovflw;
1171} 1171}
1172 1172
1173void 1173void
1174cpucounters(struct cpu_counter *cc) 1174cpucounters(struct cpu_counter *cc)
1175{ 1175{
1176 static struct cpu_info **cpu_infos; 1176 static struct cpu_info **cpu_infos;
1177 static int initialised; 1177 static int initialised;
1178 struct cpu_info **slot; 1178 struct cpu_info **slot;
1179 1179
1180 if (memf == NULL) { 1180 if (memf == NULL) {
1181 cc->nintr = uvmexp.intrs; 1181 cc->nintr = uvmexp.intrs;
1182 cc->nsyscall = uvmexp.syscalls; 1182 cc->nsyscall = uvmexp.syscalls;
1183 cc->nswtch = uvmexp.swtch; 1183 cc->nswtch = uvmexp.swtch;
1184 cc->nfault = uvmexp.faults; 1184 cc->nfault = uvmexp.faults;
1185 cc->ntrap = uvmexp.traps; 1185 cc->ntrap = uvmexp.traps;
1186 cc->nsoft = uvmexp.softs; 1186 cc->nsoft = uvmexp.softs;
1187 return; 1187 return;
1188 } 1188 }
1189 1189
1190 if (!initialised) { 1190 if (!initialised) {
1191 kread(namelist, X_CPU_INFOS, &cpu_infos, sizeof(cpu_infos)); 1191 kread(namelist, X_CPU_INFOS, &cpu_infos, sizeof(cpu_infos));
1192 initialised = 1; 1192 initialised = 1;
1193 } 1193 }
1194 1194
1195 slot = cpu_infos; 1195 slot = cpu_infos;
1196 1196
1197 memset(cc, 0, sizeof(*cc)); 1197 memset(cc, 0, sizeof(*cc));
1198 1198
1199 for (;;) { 1199 for (;;) {
1200 struct cpu_info tci, *ci = NULL; 1200 struct cpu_info tci, *ci = NULL;
1201 1201
1202 deref_kptr(slot++, &ci, sizeof(ci), "CPU array trashed"); 1202 deref_kptr(slot++, &ci, sizeof(ci), "CPU array trashed");
1203 if (!ci) { 1203 if (!ci) {
1204 break; 1204 break;
1205 } 1205 }
1206 1206
1207 if ((size_t)kvm_read(kd, (u_long)ci, &tci, sizeof(tci)) 1207 if ((size_t)kvm_read(kd, (u_long)ci, &tci, sizeof(tci))
1208 != sizeof(tci)) { 1208 != sizeof(tci)) {
1209 warnx("Can't read cpu info from %p (%s)", 1209 warnx("Can't read cpu info from %p (%s)",
1210 ci, kvm_geterr(kd)); 1210 ci, kvm_geterr(kd));
1211 memset(cc, 0, sizeof(*cc)); 1211 memset(cc, 0, sizeof(*cc));
1212 return; 1212 return;
1213 } 1213 }
1214 cc->nintr += tci.ci_data.cpu_nintr; 1214 cc->nintr += tci.ci_data.cpu_nintr;
1215 cc->nsyscall += tci.ci_data.cpu_nsyscall; 1215 cc->nsyscall += tci.ci_data.cpu_nsyscall;
1216 cc->nswtch = tci.ci_data.cpu_nswtch; 1216 cc->nswtch = tci.ci_data.cpu_nswtch;
1217 cc->nfault = tci.ci_data.cpu_nfault; 1217 cc->nfault = tci.ci_data.cpu_nfault;
1218 cc->ntrap = tci.ci_data.cpu_ntrap; 1218 cc->ntrap = tci.ci_data.cpu_ntrap;
1219 cc->nsoft = tci.ci_data.cpu_nsoft; 1219 cc->nsoft = tci.ci_data.cpu_nsoft;
1220 } 1220 }
1221} 1221}
1222 1222
1223void 1223void
1224cpustats(int *ovflwp) 1224cpustats(int *ovflwp)
1225{ 1225{
1226 int state; 1226 int state;
1227 double pcnt, total; 1227 double pcnt, total;
1228 double stat_us, stat_sy, stat_id; 1228 double stat_us, stat_sy, stat_id;
1229 int ovflw = *ovflwp; 1229 int ovflw = *ovflwp;
1230 1230
1231 total = 0; 1231 total = 0;
1232 for (state = 0; state < CPUSTATES; ++state) 1232 for (state = 0; state < CPUSTATES; ++state)
1233 total += cur.cp_time[state]; 1233 total += cur.cp_time[state];
1234 if (total) 1234 if (total)
1235 pcnt = 100 / total; 1235 pcnt = 100 / total;
1236 else 1236 else
1237 pcnt = 0; 1237 pcnt = 0;
1238 stat_us = (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * pcnt; 1238 stat_us = (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * pcnt;
1239 stat_sy = (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * pcnt; 1239 stat_sy = (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * pcnt;
1240 stat_id = cur.cp_time[CP_IDLE] * pcnt; 1240 stat_id = cur.cp_time[CP_IDLE] * pcnt;
1241 PRWORD(ovflw, " %*.0f", ((stat_sy >= 100) ? 2 : 3), 1, stat_us); 1241 PRWORD(ovflw, " %*.0f", ((stat_sy >= 100) ? 2 : 3), 1, stat_us);
1242 PRWORD(ovflw, " %*.0f", ((stat_us >= 100 || stat_id >= 100) ? 2 : 3), 1, 1242 PRWORD(ovflw, " %*.0f", ((stat_us >= 100 || stat_id >= 100) ? 2 : 3), 1,
1243 stat_sy); 1243 stat_sy);
1244 PRWORD(ovflw, " %*.0f", 3, 1, stat_id); 1244 PRWORD(ovflw, " %*.0f", 3, 1, stat_id);
1245 *ovflwp = ovflw; 1245 *ovflwp = ovflw;
1246} 1246}
1247 1247
1248void 1248void
1249dointr(int verbose) 1249dointr(int verbose)
1250{ 1250{
1251 unsigned long *intrcnt, *ointrcnt; 1251 unsigned long *intrcnt, *ointrcnt;
1252 unsigned long long inttotal, uptime; 1252 unsigned long long inttotal, uptime;
1253 int nintr, inamlen; 1253 int nintr, inamlen;
1254 char *intrname, *ointrname; 1254 char *intrname, *ointrname;
1255 1255
1256 if (memf == NULL) { 1256 if (memf == NULL) {
1257 doevcnt(verbose, EVCNT_TYPE_INTR); 1257 doevcnt(verbose, EVCNT_TYPE_INTR);
1258 return; 1258 return;
1259 } 1259 }
1260 1260
1261 inttotal = 0; 1261 inttotal = 0;
1262 uptime = getuptime(); 1262 uptime = getuptime();
1263 nintr = intrnl[X_EINTRCNT].n_value - intrnl[X_INTRCNT].n_value; 1263 nintr = intrnl[X_EINTRCNT].n_value - intrnl[X_INTRCNT].n_value;
1264 inamlen = intrnl[X_EINTRNAMES].n_value - intrnl[X_INTRNAMES].n_value; 1264 inamlen = intrnl[X_EINTRNAMES].n_value - intrnl[X_INTRNAMES].n_value;
1265 if (nintr != 0 && inamlen != 0) { 1265 if (nintr != 0 && inamlen != 0) {
1266 (void)printf("%-34s %16s %8s\n", "interrupt", "total", "rate"); 1266 (void)printf("%-34s %16s %8s\n", "interrupt", "total", "rate");
1267 1267
1268 ointrcnt = intrcnt = malloc((size_t)nintr); 1268 ointrcnt = intrcnt = malloc((size_t)nintr);
1269 ointrname = intrname = malloc((size_t)inamlen); 1269 ointrname = intrname = malloc((size_t)inamlen);
1270 if (intrcnt == NULL || intrname == NULL) 1270 if (intrcnt == NULL || intrname == NULL)
1271 errx(1, "%s", ""); 1271 errx(1, "%s", "");
1272 kread(intrnl, X_INTRCNT, intrcnt, (size_t)nintr); 1272 kread(intrnl, X_INTRCNT, intrcnt, (size_t)nintr);
1273 kread(intrnl, X_INTRNAMES, intrname, (size_t)inamlen); 1273 kread(intrnl, X_INTRNAMES, intrname, (size_t)inamlen);
1274 nintr /= sizeof(long); 1274 nintr /= sizeof(long);
1275 while (--nintr >= 0) { 1275 while (--nintr >= 0) {
1276 if (*intrcnt || verbose) 1276 if (*intrcnt || verbose)
1277 (void)printf("%-34s %16llu %8llu\n", intrname, 1277 (void)printf("%-34s %16llu %8llu\n", intrname,
1278 (unsigned long long)*intrcnt, 1278 (unsigned long long)*intrcnt,
1279 (unsigned long long) 1279 (unsigned long long)
1280 (*intrcnt / uptime)); 1280 (*intrcnt / uptime));
1281 intrname += strlen(intrname) + 1; 1281 intrname += strlen(intrname) + 1;
1282 inttotal += *intrcnt++; 1282 inttotal += *intrcnt++;
1283 } 1283 }
1284 free(ointrcnt); 1284 free(ointrcnt);
1285 free(ointrname); 1285 free(ointrname);
1286 } 1286 }
1287 1287
1288 doevcnt(verbose, EVCNT_TYPE_INTR); 1288 doevcnt(verbose, EVCNT_TYPE_INTR);
1289} 1289}
1290 1290
1291void 1291void
1292doevcnt(int verbose, int type) 1292doevcnt(int verbose, int type)
1293{ 1293{
1294 static const char * const evtypes [] = { "misc", "intr", "trap" }; 1294 static const char * const evtypes [] = { "misc", "intr", "trap" };
1295 uint64_t counttotal, uptime; 1295 uint64_t counttotal, uptime;
1296 struct evcntlist allevents; 1296 struct evcntlist allevents;
1297 struct evcnt evcnt, *evptr; 1297 struct evcnt evcnt, *evptr;
1298 size_t evlen_max, total_max, rate_max; 1298 size_t evlen_max, total_max, rate_max;
1299 char evgroup[EVCNT_STRING_MAX], evname[EVCNT_STRING_MAX]; 1299 char evgroup[EVCNT_STRING_MAX], evname[EVCNT_STRING_MAX];
1300 1300
1301 counttotal = 0; 1301 counttotal = 0;
1302 uptime = getuptime(); 1302 uptime = getuptime();
1303 1303
1304 if (memf == NULL) do { 1304 if (memf == NULL) do {
1305 const int mib[4] = { CTL_KERN, KERN_EVCNT, type, 1305 const int mib[4] = { CTL_KERN, KERN_EVCNT, type,
1306 verbose ? KERN_EVCNT_COUNT_ANY : KERN_EVCNT_COUNT_NONZERO }; 1306 verbose ? KERN_EVCNT_COUNT_ANY : KERN_EVCNT_COUNT_NONZERO };
1307 size_t buflen0, buflen = 0; 1307 size_t buflen0, buflen = 0;
1308 void *buf0, *buf = NULL; 1308 void *buf0, *buf = NULL;
1309 const struct evcnt_sysctl *evs, *last_evs; 1309 const struct evcnt_sysctl *evs, *last_evs;
1310 for (;;) { 1310 for (;;) {
1311 size_t newlen; 1311 size_t newlen;
1312 int error; 1312 int error;
1313 if (buflen) 1313 if (buflen)
1314 buf = malloc(buflen); 1314 buf = malloc(buflen);
1315 error = sysctl(mib, __arraycount(mib), 1315 error = sysctl(mib, __arraycount(mib),
1316 buf, &newlen, NULL, 0); 1316 buf, &newlen, NULL, 0);
1317 if (error) { 1317 if (error) {
1318 err(1, "kern.evcnt"); 1318 err(1, "kern.evcnt");
1319 if (buf) 1319 if (buf)
1320 free(buf); 1320 free(buf);
1321 return; 1321 return;
1322 } 1322 }
1323 if (newlen <= buflen) { 1323 if (newlen <= buflen) {
1324 buflen = newlen; 1324 buflen = newlen;
1325 break; 1325 break;
1326 } 1326 }
1327 if (buf) 1327 if (buf)
1328 free(buf); 1328 free(buf);
1329 buflen = newlen; 1329 buflen = newlen;
1330 } 1330 }
1331 buflen0 = buflen; 1331 buflen0 = buflen;