18d2fbde5SJustin T. Gibbs /* 28d2fbde5SJustin T. Gibbs * Copyright (c) 1997, 1998 Kenneth D. Merry. 38d2fbde5SJustin T. Gibbs * All rights reserved. 48d2fbde5SJustin T. Gibbs * 58d2fbde5SJustin T. Gibbs * Redistribution and use in source and binary forms, with or without 68d2fbde5SJustin T. Gibbs * modification, are permitted provided that the following conditions 78d2fbde5SJustin T. Gibbs * are met: 88d2fbde5SJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright 98d2fbde5SJustin T. Gibbs * notice, this list of conditions and the following disclaimer. 108d2fbde5SJustin T. Gibbs * 2. Redistributions in binary form must reproduce the above copyright 118d2fbde5SJustin T. Gibbs * notice, this list of conditions and the following disclaimer in the 128d2fbde5SJustin T. Gibbs * documentation and/or other materials provided with the distribution. 138d2fbde5SJustin T. Gibbs * 3. The name of the author may not be used to endorse or promote products 148d2fbde5SJustin T. Gibbs * derived from this software without specific prior written permission. 158d2fbde5SJustin T. Gibbs * 168d2fbde5SJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 178d2fbde5SJustin T. Gibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 188d2fbde5SJustin T. Gibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 198d2fbde5SJustin T. Gibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 208d2fbde5SJustin T. Gibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 218d2fbde5SJustin T. Gibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 228d2fbde5SJustin T. Gibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 238d2fbde5SJustin T. Gibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 248d2fbde5SJustin T. Gibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258d2fbde5SJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 268d2fbde5SJustin T. Gibbs * SUCH DAMAGE. 278743d3dcSPhilippe Charnier * 288743d3dcSPhilippe Charnier * $FreeBSD$ 298d2fbde5SJustin T. Gibbs */ 308d2fbde5SJustin T. Gibbs /* 318d2fbde5SJustin T. Gibbs * Parts of this program are derived from the original FreeBSD iostat 328d2fbde5SJustin T. Gibbs * program: 338d2fbde5SJustin T. Gibbs */ 34dea673e9SRodney W. Grimes /*- 35dea673e9SRodney W. Grimes * Copyright (c) 1986, 1991, 1993 36dea673e9SRodney W. Grimes * The Regents of the University of California. All rights reserved. 37dea673e9SRodney W. Grimes * 38dea673e9SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 39dea673e9SRodney W. Grimes * modification, are permitted provided that the following conditions 40dea673e9SRodney W. Grimes * are met: 41dea673e9SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 42dea673e9SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 43dea673e9SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 44dea673e9SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 45dea673e9SRodney W. Grimes * documentation and/or other materials provided with the distribution. 46dea673e9SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 47dea673e9SRodney W. Grimes * must display the following acknowledgement: 48dea673e9SRodney W. Grimes * This product includes software developed by the University of 49dea673e9SRodney W. Grimes * California, Berkeley and its contributors. 50dea673e9SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 51dea673e9SRodney W. Grimes * may be used to endorse or promote products derived from this software 52dea673e9SRodney W. Grimes * without specific prior written permission. 53dea673e9SRodney W. Grimes * 54dea673e9SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55dea673e9SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56dea673e9SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57dea673e9SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58dea673e9SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59dea673e9SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60dea673e9SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61dea673e9SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62dea673e9SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63dea673e9SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64dea673e9SRodney W. Grimes * SUCH DAMAGE. 65dea673e9SRodney W. Grimes */ 668d2fbde5SJustin T. Gibbs /* 678d2fbde5SJustin T. Gibbs * Ideas for the new iostat statistics output modes taken from the NetBSD 688d2fbde5SJustin T. Gibbs * version of iostat: 698d2fbde5SJustin T. Gibbs */ 708d2fbde5SJustin T. Gibbs /* 718d2fbde5SJustin T. Gibbs * Copyright (c) 1996 John M. Vinopal 728d2fbde5SJustin T. Gibbs * All rights reserved. 738d2fbde5SJustin T. Gibbs * 748d2fbde5SJustin T. Gibbs * Redistribution and use in source and binary forms, with or without 758d2fbde5SJustin T. Gibbs * modification, are permitted provided that the following conditions 768d2fbde5SJustin T. Gibbs * are met: 778d2fbde5SJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright 788d2fbde5SJustin T. Gibbs * notice, this list of conditions and the following disclaimer. 798d2fbde5SJustin T. Gibbs * 2. Redistributions in binary form must reproduce the above copyright 808d2fbde5SJustin T. Gibbs * notice, this list of conditions and the following disclaimer in the 818d2fbde5SJustin T. Gibbs * documentation and/or other materials provided with the distribution. 828d2fbde5SJustin T. Gibbs * 3. All advertising materials mentioning features or use of this software 838d2fbde5SJustin T. Gibbs * must display the following acknowledgement: 848d2fbde5SJustin T. Gibbs * This product includes software developed for the NetBSD Project 858d2fbde5SJustin T. Gibbs * by John M. Vinopal. 868d2fbde5SJustin T. Gibbs * 4. The name of the author may not be used to endorse or promote products 878d2fbde5SJustin T. Gibbs * derived from this software without specific prior written permission. 888d2fbde5SJustin T. Gibbs * 898d2fbde5SJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 908d2fbde5SJustin T. Gibbs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 918d2fbde5SJustin T. Gibbs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 928d2fbde5SJustin T. Gibbs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 938d2fbde5SJustin T. Gibbs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 948d2fbde5SJustin T. Gibbs * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 958d2fbde5SJustin T. Gibbs * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 968d2fbde5SJustin T. Gibbs * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 978d2fbde5SJustin T. Gibbs * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 988d2fbde5SJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 998d2fbde5SJustin T. Gibbs * SUCH DAMAGE. 1008d2fbde5SJustin T. Gibbs */ 101dea673e9SRodney W. Grimes 102dea673e9SRodney W. Grimes 103dea673e9SRodney W. Grimes #include <sys/param.h> 1048d2fbde5SJustin T. Gibbs #include <sys/errno.h> 105dea673e9SRodney W. Grimes #include <sys/dkstat.h> 1065fc5ae5cSThomas Moestl #include <sys/sysctl.h> 107dea673e9SRodney W. Grimes 108dea673e9SRodney W. Grimes #include <err.h> 109dea673e9SRodney W. Grimes #include <ctype.h> 110dea673e9SRodney W. Grimes #include <fcntl.h> 111dea673e9SRodney W. Grimes #include <kvm.h> 112dea673e9SRodney W. Grimes #include <stdio.h> 113dea673e9SRodney W. Grimes #include <stdlib.h> 114dea673e9SRodney W. Grimes #include <string.h> 115dea673e9SRodney W. Grimes #include <unistd.h> 1168d2fbde5SJustin T. Gibbs #include <limits.h> 1178d2fbde5SJustin T. Gibbs #include <devstat.h> 118dea673e9SRodney W. Grimes 119dea673e9SRodney W. Grimes struct nlist namelist[] = { 1208d2fbde5SJustin T. Gibbs #define X_TK_NIN 0 121dea673e9SRodney W. Grimes { "_tk_nin" }, 1228d2fbde5SJustin T. Gibbs #define X_TK_NOUT 1 123dea673e9SRodney W. Grimes { "_tk_nout" }, 1248d2fbde5SJustin T. Gibbs #define X_CP_TIME 2 125dea673e9SRodney W. Grimes { "_cp_time" }, 1268d2fbde5SJustin T. Gibbs #define X_HZ 3 127dea673e9SRodney W. Grimes { "_hz" }, 1288d2fbde5SJustin T. Gibbs #define X_STATHZ 4 129dea673e9SRodney W. Grimes { "_stathz" }, 1308d2fbde5SJustin T. Gibbs #define X_END 4 131dea673e9SRodney W. Grimes { NULL }, 132dea673e9SRodney W. Grimes }; 133dea673e9SRodney W. Grimes 1348d2fbde5SJustin T. Gibbs struct statinfo cur, last; 1358d2fbde5SJustin T. Gibbs int num_devices; 1368d2fbde5SJustin T. Gibbs struct device_selection *dev_select; 1378d2fbde5SJustin T. Gibbs int maxshowdevs; 1382fa4aaa0SMatthew Dillon int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0; 139dea673e9SRodney W. Grimes 140dea673e9SRodney W. Grimes #define nlread(x, v) \ 141dea673e9SRodney W. Grimes kvm_read(kd, namelist[x].n_value, &(v), sizeof(v)) 142dea673e9SRodney W. Grimes 1438d2fbde5SJustin T. Gibbs /* local function declarations */ 1448d2fbde5SJustin T. Gibbs static void usage(void); 1458d2fbde5SJustin T. Gibbs static void phdr(int signo); 1465fc5ae5cSThomas Moestl static void devstats(int perf_select,double etime, int havelast); 1478d2fbde5SJustin T. Gibbs static void cpustats(void); 1485fc5ae5cSThomas Moestl static void getsysctl(const char *, void *, size_t); 149dea673e9SRodney W. Grimes 1508d2fbde5SJustin T. Gibbs static void 1518d2fbde5SJustin T. Gibbs usage(void) 1528d2fbde5SJustin T. Gibbs { 1538d2fbde5SJustin T. Gibbs /* 1548d2fbde5SJustin T. Gibbs * We also support the following 'traditional' syntax: 1558d2fbde5SJustin T. Gibbs * iostat [drives] [wait [count]] 1568d2fbde5SJustin T. Gibbs * This isn't mentioned in the man page, or the usage statement, 1578d2fbde5SJustin T. Gibbs * but it is supported. 1588d2fbde5SJustin T. Gibbs */ 1598743d3dcSPhilippe Charnier fprintf(stderr, "usage: iostat [-CdhIKoT?] [-c count] [-M core]" 1608743d3dcSPhilippe Charnier " [-n devs] [-N system]\n" 1618743d3dcSPhilippe Charnier "\t [-t type,if,pass] [-w wait] [drives]\n"); 1628d2fbde5SJustin T. Gibbs } 163dea673e9SRodney W. Grimes 164dea673e9SRodney W. Grimes int 1658d2fbde5SJustin T. Gibbs main(int argc, char **argv) 166dea673e9SRodney W. Grimes { 1678d2fbde5SJustin T. Gibbs int c; 168dea673e9SRodney W. Grimes register int i; 1698d2fbde5SJustin T. Gibbs int tflag = 0, hflag = 0, cflag = 0, wflag = 0, nflag = 0; 1708d2fbde5SJustin T. Gibbs int count = 0, waittime = 0; 1718d2fbde5SJustin T. Gibbs char *memf = NULL, *nlistf = NULL; 1728d2fbde5SJustin T. Gibbs struct devstat_match *matches; 1738d2fbde5SJustin T. Gibbs int num_matches = 0; 174dea673e9SRodney W. Grimes char errbuf[_POSIX2_LINE_MAX]; 1755fc5ae5cSThomas Moestl kvm_t *kd = NULL; 1768d2fbde5SJustin T. Gibbs int hz, stathz; 1778d2fbde5SJustin T. Gibbs int headercount; 178bcc6a3daSKenneth D. Merry long generation; 1798d2fbde5SJustin T. Gibbs int num_devices_specified; 180bcc6a3daSKenneth D. Merry int num_selected, num_selections; 181bcc6a3daSKenneth D. Merry long select_generation; 1828d2fbde5SJustin T. Gibbs char **specified_devices; 1838d2fbde5SJustin T. Gibbs devstat_select_mode select_mode; 1845fc5ae5cSThomas Moestl int use_kvm, havelast = 0; 1855fc5ae5cSThomas Moestl struct clockinfo clkinfo; 186dea673e9SRodney W. Grimes 1878d2fbde5SJustin T. Gibbs matches = NULL; 1888d2fbde5SJustin T. Gibbs maxshowdevs = 3; 1898d2fbde5SJustin T. Gibbs 1908743d3dcSPhilippe Charnier while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:?")) != -1) { 1918d2fbde5SJustin T. Gibbs switch(c) { 192dea673e9SRodney W. Grimes case 'c': 1938d2fbde5SJustin T. Gibbs cflag++; 1948d2fbde5SJustin T. Gibbs count = atoi(optarg); 1958d2fbde5SJustin T. Gibbs if (count < 1) 1968d2fbde5SJustin T. Gibbs errx(1, "count %d is < 1", count); 1978d2fbde5SJustin T. Gibbs break; 1988d2fbde5SJustin T. Gibbs case 'C': 1998d2fbde5SJustin T. Gibbs Cflag++; 2008d2fbde5SJustin T. Gibbs break; 2018d2fbde5SJustin T. Gibbs case 'd': 2028d2fbde5SJustin T. Gibbs dflag++; 2038d2fbde5SJustin T. Gibbs break; 2048d2fbde5SJustin T. Gibbs case 'h': 2058d2fbde5SJustin T. Gibbs hflag++; 2068d2fbde5SJustin T. Gibbs break; 2078d2fbde5SJustin T. Gibbs case 'I': 2088d2fbde5SJustin T. Gibbs Iflag++; 209dea673e9SRodney W. Grimes break; 210e4d7fe02SKenneth D. Merry case 'K': 211e4d7fe02SKenneth D. Merry Kflag++; 212e4d7fe02SKenneth D. Merry break; 213dea673e9SRodney W. Grimes case 'M': 214dea673e9SRodney W. Grimes memf = optarg; 215dea673e9SRodney W. Grimes break; 2168d2fbde5SJustin T. Gibbs case 'n': 2178d2fbde5SJustin T. Gibbs nflag++; 2188d2fbde5SJustin T. Gibbs maxshowdevs = atoi(optarg); 2198d2fbde5SJustin T. Gibbs if (maxshowdevs < 0) 2205d4a8fa9SPhilippe Charnier errx(1, "number of devices %d is < 0", 2218d2fbde5SJustin T. Gibbs maxshowdevs); 2228d2fbde5SJustin T. Gibbs break; 223dea673e9SRodney W. Grimes case 'N': 224dea673e9SRodney W. Grimes nlistf = optarg; 225dea673e9SRodney W. Grimes break; 2268d2fbde5SJustin T. Gibbs case 'o': 2278d2fbde5SJustin T. Gibbs oflag++; 228dea673e9SRodney W. Grimes break; 2298d2fbde5SJustin T. Gibbs case 't': 2308d2fbde5SJustin T. Gibbs tflag++; 2315fc5ae5cSThomas Moestl if (devstat_buildmatch(optarg, &matches, 2328d2fbde5SJustin T. Gibbs &num_matches) != 0) 2338d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 2348d2fbde5SJustin T. Gibbs break; 2358d2fbde5SJustin T. Gibbs case 'T': 2368d2fbde5SJustin T. Gibbs Tflag++; 2378d2fbde5SJustin T. Gibbs break; 2388d2fbde5SJustin T. Gibbs case 'w': 2398d2fbde5SJustin T. Gibbs wflag++; 2408d2fbde5SJustin T. Gibbs waittime = atoi(optarg); 2418d2fbde5SJustin T. Gibbs if (waittime < 1) 2428d2fbde5SJustin T. Gibbs errx(1, "wait time is < 1"); 2438d2fbde5SJustin T. Gibbs break; 244dea673e9SRodney W. Grimes default: 245dea673e9SRodney W. Grimes usage(); 2468743d3dcSPhilippe Charnier exit(1); 2478d2fbde5SJustin T. Gibbs break; 248dea673e9SRodney W. Grimes } 2498d2fbde5SJustin T. Gibbs } 2508d2fbde5SJustin T. Gibbs 251dea673e9SRodney W. Grimes argc -= optind; 252dea673e9SRodney W. Grimes argv += optind; 253dea673e9SRodney W. Grimes 2545fc5ae5cSThomas Moestl if (nlistf == NULL && memf == NULL) { 2555fc5ae5cSThomas Moestl use_kvm = 0; 2565fc5ae5cSThomas Moestl getsysctl("kern.clockrate", &clkinfo, sizeof(clkinfo)); 2575fc5ae5cSThomas Moestl hz = clkinfo.hz; 2585fc5ae5cSThomas Moestl } else { 2595fc5ae5cSThomas Moestl use_kvm = 1; 2605fc5ae5cSThomas Moestl kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); 2615fc5ae5cSThomas Moestl 2625fc5ae5cSThomas Moestl if (kd == 0) 2635fc5ae5cSThomas Moestl errx(1, "kvm_openfiles: %s", errbuf); 2645fc5ae5cSThomas Moestl 2655fc5ae5cSThomas Moestl if (kvm_nlist(kd, namelist) == -1) 2665fc5ae5cSThomas Moestl errx(1, "kvm_nlist: %s", kvm_geterr(kd)); 2675fc5ae5cSThomas Moestl 2685fc5ae5cSThomas Moestl (void)nlread(X_HZ, hz); 2695fc5ae5cSThomas Moestl (void)nlread(X_STATHZ, stathz); 2705fc5ae5cSThomas Moestl if (stathz) 2715fc5ae5cSThomas Moestl hz = stathz; 2725fc5ae5cSThomas Moestl } 273dea673e9SRodney W. Grimes 2748d2fbde5SJustin T. Gibbs /* 2758d2fbde5SJustin T. Gibbs * Make sure that the userland devstat version matches the kernel 2768d2fbde5SJustin T. Gibbs * devstat version. If not, exit and print a message informing 2778d2fbde5SJustin T. Gibbs * the user of his mistake. 2788d2fbde5SJustin T. Gibbs */ 2795fc5ae5cSThomas Moestl if (devstat_checkversion(kd) < 0) 2808d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 2818d2fbde5SJustin T. Gibbs 2828d2fbde5SJustin T. Gibbs /* 2838d2fbde5SJustin T. Gibbs * Figure out how many devices we should display. 2848d2fbde5SJustin T. Gibbs */ 2858d2fbde5SJustin T. Gibbs if (nflag == 0) { 2868d2fbde5SJustin T. Gibbs if (oflag > 0) { 2878d2fbde5SJustin T. Gibbs if ((dflag > 0) && (Cflag == 0) && (Tflag == 0)) 2888d2fbde5SJustin T. Gibbs maxshowdevs = 5; 2898d2fbde5SJustin T. Gibbs else if ((dflag > 0) && (Tflag > 0) && (Cflag == 0)) 2908d2fbde5SJustin T. Gibbs maxshowdevs = 5; 2918d2fbde5SJustin T. Gibbs else 2928d2fbde5SJustin T. Gibbs maxshowdevs = 4; 2938d2fbde5SJustin T. Gibbs } else { 2948d2fbde5SJustin T. Gibbs if ((dflag > 0) && (Cflag == 0)) 2958d2fbde5SJustin T. Gibbs maxshowdevs = 4; 2968d2fbde5SJustin T. Gibbs else 2978d2fbde5SJustin T. Gibbs maxshowdevs = 3; 2988d2fbde5SJustin T. Gibbs } 2998d2fbde5SJustin T. Gibbs } 3008d2fbde5SJustin T. Gibbs 3018d2fbde5SJustin T. Gibbs /* find out how many devices we have */ 3025fc5ae5cSThomas Moestl if ((num_devices = devstat_getnumdevs(kd)) < 0) 3038d2fbde5SJustin T. Gibbs err(1, "can't get number of devices"); 3048d2fbde5SJustin T. Gibbs 305b673f44dSChris D. Faulhaber if ((cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo))) == 306b673f44dSChris D. Faulhaber NULL) 307b673f44dSChris D. Faulhaber err(1, "devinfo malloc failed"); 308b673f44dSChris D. Faulhaber if ((last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo))) == 309b673f44dSChris D. Faulhaber NULL) 310b673f44dSChris D. Faulhaber err(1, "devinfo malloc failed"); 3118d2fbde5SJustin T. Gibbs bzero(cur.dinfo, sizeof(struct devinfo)); 3128d2fbde5SJustin T. Gibbs bzero(last.dinfo, sizeof(struct devinfo)); 3138d2fbde5SJustin T. Gibbs 3148d2fbde5SJustin T. Gibbs /* 3158d2fbde5SJustin T. Gibbs * Grab all the devices. We don't look to see if the list has 3168d2fbde5SJustin T. Gibbs * changed here, since it almost certainly has. We only look for 3178d2fbde5SJustin T. Gibbs * errors. 3188d2fbde5SJustin T. Gibbs */ 3195fc5ae5cSThomas Moestl if (devstat_getdevs(kd, &cur) == -1) 3208d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 3218d2fbde5SJustin T. Gibbs 3228d2fbde5SJustin T. Gibbs num_devices = cur.dinfo->numdevs; 3238d2fbde5SJustin T. Gibbs generation = cur.dinfo->generation; 3248d2fbde5SJustin T. Gibbs 3258d2fbde5SJustin T. Gibbs /* 3268d2fbde5SJustin T. Gibbs * If the user specified any devices on the command line, see if 3278d2fbde5SJustin T. Gibbs * they are in the list of devices we have now. 3288d2fbde5SJustin T. Gibbs */ 329b673f44dSChris D. Faulhaber if ((specified_devices = (char **)malloc(sizeof(char *))) == NULL) 330b673f44dSChris D. Faulhaber err(1, "specified_devices malloc failed"); 3318d2fbde5SJustin T. Gibbs for (num_devices_specified = 0; *argv; ++argv) { 3328d2fbde5SJustin T. Gibbs if (isdigit(**argv)) 3338d2fbde5SJustin T. Gibbs break; 3348d2fbde5SJustin T. Gibbs num_devices_specified++; 3358d2fbde5SJustin T. Gibbs specified_devices = (char **)realloc(specified_devices, 3368d2fbde5SJustin T. Gibbs sizeof(char *) * 3378d2fbde5SJustin T. Gibbs num_devices_specified); 3388d2fbde5SJustin T. Gibbs specified_devices[num_devices_specified - 1] = *argv; 3398d2fbde5SJustin T. Gibbs 3408d2fbde5SJustin T. Gibbs } 3412fa4aaa0SMatthew Dillon if (nflag == 0 && maxshowdevs < num_devices_specified) 3422fa4aaa0SMatthew Dillon maxshowdevs = num_devices_specified; 3438d2fbde5SJustin T. Gibbs 3448d2fbde5SJustin T. Gibbs dev_select = NULL; 3458d2fbde5SJustin T. Gibbs 3468d2fbde5SJustin T. Gibbs if ((num_devices_specified == 0) && (num_matches == 0)) 3478d2fbde5SJustin T. Gibbs select_mode = DS_SELECT_ADD; 3488d2fbde5SJustin T. Gibbs else 3498d2fbde5SJustin T. Gibbs select_mode = DS_SELECT_ONLY; 3508d2fbde5SJustin T. Gibbs 3518d2fbde5SJustin T. Gibbs /* 3528d2fbde5SJustin T. Gibbs * At this point, selectdevs will almost surely indicate that the 3538d2fbde5SJustin T. Gibbs * device list has changed, so we don't look for return values of 0 3548d2fbde5SJustin T. Gibbs * or 1. If we get back -1, though, there is an error. 3558d2fbde5SJustin T. Gibbs */ 3565fc5ae5cSThomas Moestl if (devstat_selectdevs(&dev_select, &num_selected, 3575fc5ae5cSThomas Moestl &num_selections, &select_generation, generation, 3585fc5ae5cSThomas Moestl cur.dinfo->devices, num_devices, matches, 3595fc5ae5cSThomas Moestl num_matches, specified_devices, 3605fc5ae5cSThomas Moestl num_devices_specified, select_mode, maxshowdevs, 3615fc5ae5cSThomas Moestl hflag) == -1) 3628d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 3638d2fbde5SJustin T. Gibbs 3648d2fbde5SJustin T. Gibbs /* 3658d2fbde5SJustin T. Gibbs * Look for the traditional wait time and count arguments. 3668d2fbde5SJustin T. Gibbs */ 3678d2fbde5SJustin T. Gibbs if (*argv) { 3688d2fbde5SJustin T. Gibbs waittime = atoi(*argv); 3698d2fbde5SJustin T. Gibbs 3708d2fbde5SJustin T. Gibbs /* Let the user know he goofed, but keep going anyway */ 3718d2fbde5SJustin T. Gibbs if (wflag != 0) 3728d2fbde5SJustin T. Gibbs warnx("discarding previous wait interval, using" 3738d2fbde5SJustin T. Gibbs " %d instead", waittime); 3748d2fbde5SJustin T. Gibbs wflag++; 3758d2fbde5SJustin T. Gibbs 3768d2fbde5SJustin T. Gibbs if (*++argv) { 3778d2fbde5SJustin T. Gibbs count = atoi(*argv); 3788d2fbde5SJustin T. Gibbs if (cflag != 0) 3798d2fbde5SJustin T. Gibbs warnx("discarding previous count, using %d" 3808d2fbde5SJustin T. Gibbs " instead", count); 3818d2fbde5SJustin T. Gibbs cflag++; 3828d2fbde5SJustin T. Gibbs } else 3838d2fbde5SJustin T. Gibbs count = -1; 3848d2fbde5SJustin T. Gibbs } 3858d2fbde5SJustin T. Gibbs 3868d2fbde5SJustin T. Gibbs /* 3878d2fbde5SJustin T. Gibbs * If the user specified a count, but not an interval, we default 3888d2fbde5SJustin T. Gibbs * to an interval of 1 second. 3898d2fbde5SJustin T. Gibbs */ 3908d2fbde5SJustin T. Gibbs if ((wflag == 0) && (cflag > 0)) 3918d2fbde5SJustin T. Gibbs waittime = 1; 3928d2fbde5SJustin T. Gibbs 3938d2fbde5SJustin T. Gibbs /* 3948d2fbde5SJustin T. Gibbs * If the user specified a wait time, but not a count, we want to 3958d2fbde5SJustin T. Gibbs * go on ad infinitum. This can be redundant if the user uses the 3968d2fbde5SJustin T. Gibbs * traditional method of specifying the wait, since in that case we 3978d2fbde5SJustin T. Gibbs * already set count = -1 above. Oh well. 3988d2fbde5SJustin T. Gibbs */ 3998d2fbde5SJustin T. Gibbs if ((wflag > 0) && (cflag == 0)) 4008d2fbde5SJustin T. Gibbs count = -1; 4018d2fbde5SJustin T. Gibbs 402dea673e9SRodney W. Grimes /* 4038d2fbde5SJustin T. Gibbs * If the user stops the program (control-Z) and then resumes it, 4048d2fbde5SJustin T. Gibbs * print out the header again. 405dea673e9SRodney W. Grimes */ 406dea673e9SRodney W. Grimes (void)signal(SIGCONT, phdr); 407dea673e9SRodney W. Grimes 4088d2fbde5SJustin T. Gibbs for (headercount = 1;;) { 4098d2fbde5SJustin T. Gibbs struct devinfo *tmp_dinfo; 4108d2fbde5SJustin T. Gibbs long tmp; 4118d2fbde5SJustin T. Gibbs double etime; 4128d2fbde5SJustin T. Gibbs 4138d2fbde5SJustin T. Gibbs if (!--headercount) { 414dea673e9SRodney W. Grimes phdr(0); 4158d2fbde5SJustin T. Gibbs headercount = 20; 416dea673e9SRodney W. Grimes } 4175fc5ae5cSThomas Moestl if (use_kvm) { 418dea673e9SRodney W. Grimes (void)kvm_read(kd, namelist[X_TK_NIN].n_value, 419dea673e9SRodney W. Grimes &cur.tk_nin, sizeof(cur.tk_nin)); 420dea673e9SRodney W. Grimes (void)kvm_read(kd, namelist[X_TK_NOUT].n_value, 421dea673e9SRodney W. Grimes &cur.tk_nout, sizeof(cur.tk_nout)); 422dea673e9SRodney W. Grimes (void)kvm_read(kd, namelist[X_CP_TIME].n_value, 423dea673e9SRodney W. Grimes cur.cp_time, sizeof(cur.cp_time)); 4245fc5ae5cSThomas Moestl } else { 4255fc5ae5cSThomas Moestl getsysctl("kern.tty_nin", &cur.tk_nin, 4265fc5ae5cSThomas Moestl sizeof(cur.tk_nin)); 4275fc5ae5cSThomas Moestl getsysctl("kern.tty_nout", &cur.tk_nout, 4285fc5ae5cSThomas Moestl sizeof(cur.tk_nout)); 4295fc5ae5cSThomas Moestl getsysctl("kern.cp_time", &cur.cp_time, 4305fc5ae5cSThomas Moestl sizeof(cur.cp_time)); 4315fc5ae5cSThomas Moestl } 4328d2fbde5SJustin T. Gibbs 4338d2fbde5SJustin T. Gibbs tmp_dinfo = last.dinfo; 4348d2fbde5SJustin T. Gibbs last.dinfo = cur.dinfo; 4358d2fbde5SJustin T. Gibbs cur.dinfo = tmp_dinfo; 4368d2fbde5SJustin T. Gibbs 4378d2fbde5SJustin T. Gibbs last.busy_time = cur.busy_time; 4388d2fbde5SJustin T. Gibbs 4398d2fbde5SJustin T. Gibbs /* 4408d2fbde5SJustin T. Gibbs * Here what we want to do is refresh our device stats. 4415fc5ae5cSThomas Moestl * devstat_getdevs() returns 1 when the device list has changed. 4428d2fbde5SJustin T. Gibbs * If the device list has changed, we want to go through 4438d2fbde5SJustin T. Gibbs * the selection process again, in case a device that we 4448d2fbde5SJustin T. Gibbs * were previously displaying has gone away. 4458d2fbde5SJustin T. Gibbs */ 4465fc5ae5cSThomas Moestl switch (devstat_getdevs(kd, &cur)) { 4478d2fbde5SJustin T. Gibbs case -1: 4488d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 4498d2fbde5SJustin T. Gibbs break; 4508d2fbde5SJustin T. Gibbs case 1: { 4518d2fbde5SJustin T. Gibbs int retval; 4528d2fbde5SJustin T. Gibbs 4538d2fbde5SJustin T. Gibbs num_devices = cur.dinfo->numdevs; 4548d2fbde5SJustin T. Gibbs generation = cur.dinfo->generation; 4555fc5ae5cSThomas Moestl retval = devstat_selectdevs(&dev_select, &num_selected, 4565fc5ae5cSThomas Moestl &num_selections, 4575fc5ae5cSThomas Moestl &select_generation, 4585fc5ae5cSThomas Moestl generation, 4595fc5ae5cSThomas Moestl cur.dinfo->devices, 4605fc5ae5cSThomas Moestl num_devices, matches, 4615fc5ae5cSThomas Moestl num_matches, 4628d2fbde5SJustin T. Gibbs specified_devices, 4638d2fbde5SJustin T. Gibbs num_devices_specified, 4645fc5ae5cSThomas Moestl select_mode, maxshowdevs, 4655fc5ae5cSThomas Moestl hflag); 4668d2fbde5SJustin T. Gibbs switch(retval) { 4678d2fbde5SJustin T. Gibbs case -1: 4688d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 4698d2fbde5SJustin T. Gibbs break; 4708d2fbde5SJustin T. Gibbs case 1: 4718d2fbde5SJustin T. Gibbs phdr(0); 4728d2fbde5SJustin T. Gibbs headercount = 20; 4738d2fbde5SJustin T. Gibbs break; 4748d2fbde5SJustin T. Gibbs default: 4758d2fbde5SJustin T. Gibbs break; 476dea673e9SRodney W. Grimes } 4778d2fbde5SJustin T. Gibbs break; 4788d2fbde5SJustin T. Gibbs } 4798d2fbde5SJustin T. Gibbs default: 4808d2fbde5SJustin T. Gibbs break; 4818d2fbde5SJustin T. Gibbs } 4828d2fbde5SJustin T. Gibbs 4838d2fbde5SJustin T. Gibbs /* 4848d2fbde5SJustin T. Gibbs * We only want to re-select devices if we're in 'top' 4858d2fbde5SJustin T. Gibbs * mode. This is the only mode where the devices selected 4868d2fbde5SJustin T. Gibbs * could actually change. 4878d2fbde5SJustin T. Gibbs */ 4888d2fbde5SJustin T. Gibbs if (hflag > 0) { 4898d2fbde5SJustin T. Gibbs int retval; 4905fc5ae5cSThomas Moestl retval = devstat_selectdevs(&dev_select, &num_selected, 4915fc5ae5cSThomas Moestl &num_selections, 4925fc5ae5cSThomas Moestl &select_generation, 4935fc5ae5cSThomas Moestl generation, 4945fc5ae5cSThomas Moestl cur.dinfo->devices, 4955fc5ae5cSThomas Moestl num_devices, matches, 4965fc5ae5cSThomas Moestl num_matches, 4978d2fbde5SJustin T. Gibbs specified_devices, 4988d2fbde5SJustin T. Gibbs num_devices_specified, 4995fc5ae5cSThomas Moestl select_mode, maxshowdevs, 5005fc5ae5cSThomas Moestl hflag); 5018d2fbde5SJustin T. Gibbs switch(retval) { 5028d2fbde5SJustin T. Gibbs case -1: 5038d2fbde5SJustin T. Gibbs errx(1,"%s", devstat_errbuf); 5048d2fbde5SJustin T. Gibbs break; 5058d2fbde5SJustin T. Gibbs case 1: 5068d2fbde5SJustin T. Gibbs phdr(0); 5078d2fbde5SJustin T. Gibbs headercount = 20; 5088d2fbde5SJustin T. Gibbs break; 5098d2fbde5SJustin T. Gibbs default: 5108d2fbde5SJustin T. Gibbs break; 5118d2fbde5SJustin T. Gibbs } 5128d2fbde5SJustin T. Gibbs } 5138d2fbde5SJustin T. Gibbs 514dea673e9SRodney W. Grimes tmp = cur.tk_nin; 515dea673e9SRodney W. Grimes cur.tk_nin -= last.tk_nin; 516dea673e9SRodney W. Grimes last.tk_nin = tmp; 517dea673e9SRodney W. Grimes tmp = cur.tk_nout; 518dea673e9SRodney W. Grimes cur.tk_nout -= last.tk_nout; 519dea673e9SRodney W. Grimes last.tk_nout = tmp; 5208d2fbde5SJustin T. Gibbs 5218d2fbde5SJustin T. Gibbs etime = 0.0; 5228d2fbde5SJustin T. Gibbs 5238d2fbde5SJustin T. Gibbs #define X(fld) tmp = cur.fld[i]; cur.fld[i] -= last.fld[i]; last.fld[i] = tmp 5248d2fbde5SJustin T. Gibbs 525dea673e9SRodney W. Grimes for (i = 0; i < CPUSTATES; i++) { 526dea673e9SRodney W. Grimes X(cp_time); 527dea673e9SRodney W. Grimes etime += cur.cp_time[i]; 528dea673e9SRodney W. Grimes } 5295fc5ae5cSThomas Moestl etime /= (float)hz; 530dea673e9SRodney W. Grimes if (etime == 0.0) 531dea673e9SRodney W. Grimes etime = 1.0; 5328d2fbde5SJustin T. Gibbs if ((dflag == 0) || (Tflag > 0)) 5338d2fbde5SJustin T. Gibbs printf("%4.0f%5.0f", cur.tk_nin / etime, 5348d2fbde5SJustin T. Gibbs cur.tk_nout/etime); 5355fc5ae5cSThomas Moestl devstats(hflag, etime, havelast); 5368d2fbde5SJustin T. Gibbs if ((dflag == 0) || (Cflag > 0)) 537dea673e9SRodney W. Grimes cpustats(); 5388d2fbde5SJustin T. Gibbs printf("\n"); 5398d2fbde5SJustin T. Gibbs fflush(stdout); 540dea673e9SRodney W. Grimes 5418d2fbde5SJustin T. Gibbs if (count >= 0 && --count <= 0) 542dea673e9SRodney W. Grimes break; 5438d2fbde5SJustin T. Gibbs 5448d2fbde5SJustin T. Gibbs sleep(waittime); 5455fc5ae5cSThomas Moestl havelast = 1; 546dea673e9SRodney W. Grimes } 5478d2fbde5SJustin T. Gibbs 548dea673e9SRodney W. Grimes exit(0); 549dea673e9SRodney W. Grimes } 550dea673e9SRodney W. Grimes 5518d2fbde5SJustin T. Gibbs static void 5528d2fbde5SJustin T. Gibbs phdr(int signo) 553dea673e9SRodney W. Grimes { 554dea673e9SRodney W. Grimes register int i; 5558d2fbde5SJustin T. Gibbs int printed; 556dea673e9SRodney W. Grimes 5578d2fbde5SJustin T. Gibbs if ((dflag == 0) || (Tflag > 0)) 558dea673e9SRodney W. Grimes (void)printf(" tty"); 5598d2fbde5SJustin T. Gibbs for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){ 5608d2fbde5SJustin T. Gibbs int di; 5618d2fbde5SJustin T. Gibbs if ((dev_select[i].selected != 0) 5628d2fbde5SJustin T. Gibbs && (dev_select[i].selected <= maxshowdevs)) { 5638d2fbde5SJustin T. Gibbs di = dev_select[i].position; 5648d2fbde5SJustin T. Gibbs if (oflag > 0) 5658d2fbde5SJustin T. Gibbs (void)printf("%12.6s%d ", 5668d2fbde5SJustin T. Gibbs cur.dinfo->devices[di].device_name, 5678d2fbde5SJustin T. Gibbs cur.dinfo->devices[di].unit_number); 5688d2fbde5SJustin T. Gibbs else 5698d2fbde5SJustin T. Gibbs printf("%15.6s%d ", 5708d2fbde5SJustin T. Gibbs cur.dinfo->devices[di].device_name, 5718d2fbde5SJustin T. Gibbs cur.dinfo->devices[di].unit_number); 5728d2fbde5SJustin T. Gibbs printed++; 5738d2fbde5SJustin T. Gibbs } 5748d2fbde5SJustin T. Gibbs } 5758d2fbde5SJustin T. Gibbs if ((dflag == 0) || (Cflag > 0)) 5768d2fbde5SJustin T. Gibbs (void)printf(" cpu\n"); 5778d2fbde5SJustin T. Gibbs else 5788d2fbde5SJustin T. Gibbs (void)printf("\n"); 5798d2fbde5SJustin T. Gibbs 5808d2fbde5SJustin T. Gibbs if ((dflag == 0) || (Tflag > 0)) 5818d2fbde5SJustin T. Gibbs (void)printf(" tin tout"); 5828d2fbde5SJustin T. Gibbs 5838d2fbde5SJustin T. Gibbs for (i=0, printed = 0;(i < num_devices) && (printed < maxshowdevs);i++){ 5848d2fbde5SJustin T. Gibbs if ((dev_select[i].selected != 0) 5858d2fbde5SJustin T. Gibbs && (dev_select[i].selected <= maxshowdevs)) { 5862fa4aaa0SMatthew Dillon if (oflag > 0) { 5878d2fbde5SJustin T. Gibbs if (Iflag == 0) 588dea673e9SRodney W. Grimes (void)printf(" sps tps msps "); 5898d2fbde5SJustin T. Gibbs else 5908d2fbde5SJustin T. Gibbs (void)printf(" blk xfr msps "); 5912fa4aaa0SMatthew Dillon } else { 5928d2fbde5SJustin T. Gibbs if (Iflag == 0) 5938d2fbde5SJustin T. Gibbs printf(" KB/t tps MB/s "); 5948d2fbde5SJustin T. Gibbs else 5958d2fbde5SJustin T. Gibbs printf(" KB/t xfrs MB "); 5962fa4aaa0SMatthew Dillon } 5978d2fbde5SJustin T. Gibbs printed++; 5988d2fbde5SJustin T. Gibbs } 5998d2fbde5SJustin T. Gibbs } 6008d2fbde5SJustin T. Gibbs if ((dflag == 0) || (Cflag > 0)) 601936d754aSAndrey A. Chernov (void)printf(" us ni sy in id\n"); 6028d2fbde5SJustin T. Gibbs else 6038d2fbde5SJustin T. Gibbs printf("\n"); 6048d2fbde5SJustin T. Gibbs 605dea673e9SRodney W. Grimes } 606dea673e9SRodney W. Grimes 6078d2fbde5SJustin T. Gibbs static void 6085fc5ae5cSThomas Moestl devstats(int perf_select, double etime, int havelast) 609dea673e9SRodney W. Grimes { 610dea673e9SRodney W. Grimes register int dn; 6118d2fbde5SJustin T. Gibbs long double transfers_per_second; 6128d2fbde5SJustin T. Gibbs long double kb_per_transfer, mb_per_second; 6138d2fbde5SJustin T. Gibbs u_int64_t total_bytes, total_transfers, total_blocks; 6148d2fbde5SJustin T. Gibbs long double busy_seconds; 6158d2fbde5SJustin T. Gibbs long double total_mb; 6168d2fbde5SJustin T. Gibbs long double blocks_per_second, ms_per_transaction; 617dea673e9SRodney W. Grimes 6188d2fbde5SJustin T. Gibbs /* 6198d2fbde5SJustin T. Gibbs * Calculate elapsed time up front, since it's the same for all 6208d2fbde5SJustin T. Gibbs * devices. 6218d2fbde5SJustin T. Gibbs */ 6225fc5ae5cSThomas Moestl if (havelast) 6235fc5ae5cSThomas Moestl busy_seconds = devstat_compute_etime(cur.busy_time, 6245fc5ae5cSThomas Moestl last.busy_time); 6255fc5ae5cSThomas Moestl else 6265fc5ae5cSThomas Moestl busy_seconds = etime; 6278d2fbde5SJustin T. Gibbs 6288d2fbde5SJustin T. Gibbs for (dn = 0; dn < num_devices; dn++) { 6298d2fbde5SJustin T. Gibbs int di; 6308d2fbde5SJustin T. Gibbs 6318d2fbde5SJustin T. Gibbs if (((perf_select == 0) && (dev_select[dn].selected == 0)) 6328d2fbde5SJustin T. Gibbs || (dev_select[dn].selected > maxshowdevs)) 633dea673e9SRodney W. Grimes continue; 634dea673e9SRodney W. Grimes 6358d2fbde5SJustin T. Gibbs di = dev_select[dn].position; 636dea673e9SRodney W. Grimes 6375fc5ae5cSThomas Moestl if (devstat_compute_statistics(&cur.dinfo->devices[di], 6385fc5ae5cSThomas Moestl havelast ? &last.dinfo->devices[di] : NULL, busy_seconds, 6395fc5ae5cSThomas Moestl DSM_TOTAL_BYTES, &total_bytes, 6405fc5ae5cSThomas Moestl DSM_TOTAL_TRANSFERS, &total_transfers, 6415fc5ae5cSThomas Moestl DSM_TOTAL_BLOCKS, &total_blocks, 6425fc5ae5cSThomas Moestl DSM_KB_PER_TRANSFER, &kb_per_transfer, 6435fc5ae5cSThomas Moestl DSM_TRANSFERS_PER_SECOND, &transfers_per_second, 6445fc5ae5cSThomas Moestl DSM_MB_PER_SECOND, &mb_per_second, 6455fc5ae5cSThomas Moestl DSM_BLOCKS_PER_SECOND, &blocks_per_second, 6465fc5ae5cSThomas Moestl DSM_MS_PER_TRANSACTION, &ms_per_transaction, 6475fc5ae5cSThomas Moestl DSM_NONE) != 0) 6488d2fbde5SJustin T. Gibbs errx(1, "%s", devstat_errbuf); 6498d2fbde5SJustin T. Gibbs 6508d2fbde5SJustin T. Gibbs if (perf_select != 0) { 6518d2fbde5SJustin T. Gibbs dev_select[dn].bytes = total_bytes; 6528d2fbde5SJustin T. Gibbs if ((dev_select[dn].selected == 0) 6538d2fbde5SJustin T. Gibbs || (dev_select[dn].selected > maxshowdevs)) 6548d2fbde5SJustin T. Gibbs continue; 6558d2fbde5SJustin T. Gibbs } 6568d2fbde5SJustin T. Gibbs 6572fa4aaa0SMatthew Dillon if (Kflag) { 6582fa4aaa0SMatthew Dillon int block_size = cur.dinfo->devices[di].block_size; 659e4d7fe02SKenneth D. Merry total_blocks = total_blocks * (block_size ? 660e4d7fe02SKenneth D. Merry block_size : 512) / 1024; 6612fa4aaa0SMatthew Dillon } 6622fa4aaa0SMatthew Dillon 6638d2fbde5SJustin T. Gibbs if (oflag > 0) { 6642fa4aaa0SMatthew Dillon int msdig = (ms_per_transaction < 100.0) ? 1 : 0; 6658d2fbde5SJustin T. Gibbs 6668d2fbde5SJustin T. Gibbs if (Iflag == 0) 6672fa4aaa0SMatthew Dillon printf("%4.0Lf%4.0Lf%5.*Lf ", 6688d2fbde5SJustin T. Gibbs blocks_per_second, 6698d2fbde5SJustin T. Gibbs transfers_per_second, 6702fa4aaa0SMatthew Dillon msdig, 6718d2fbde5SJustin T. Gibbs ms_per_transaction); 672dea673e9SRodney W. Grimes else 6732fa4aaa0SMatthew Dillon printf("%4.1qu%4.1qu%5.*Lf ", 6748d2fbde5SJustin T. Gibbs total_blocks, 6758d2fbde5SJustin T. Gibbs total_transfers, 6762fa4aaa0SMatthew Dillon msdig, 6778d2fbde5SJustin T. Gibbs ms_per_transaction); 6788d2fbde5SJustin T. Gibbs } else { 6798d2fbde5SJustin T. Gibbs if (Iflag == 0) 6808d2fbde5SJustin T. Gibbs printf(" %5.2Lf %3.0Lf %5.2Lf ", 6818d2fbde5SJustin T. Gibbs kb_per_transfer, 6828d2fbde5SJustin T. Gibbs transfers_per_second, 6838d2fbde5SJustin T. Gibbs mb_per_second); 6848d2fbde5SJustin T. Gibbs else { 6858d2fbde5SJustin T. Gibbs total_mb = total_bytes; 6868d2fbde5SJustin T. Gibbs total_mb /= 1024 * 1024; 6878d2fbde5SJustin T. Gibbs 6888d2fbde5SJustin T. Gibbs printf(" %5.2Lf %3.1qu %5.2Lf ", 6898d2fbde5SJustin T. Gibbs kb_per_transfer, 6908d2fbde5SJustin T. Gibbs total_transfers, 6918d2fbde5SJustin T. Gibbs total_mb); 6928d2fbde5SJustin T. Gibbs } 6938d2fbde5SJustin T. Gibbs } 694dea673e9SRodney W. Grimes } 695dea673e9SRodney W. Grimes } 696dea673e9SRodney W. Grimes 6978d2fbde5SJustin T. Gibbs static void 6988d2fbde5SJustin T. Gibbs cpustats(void) 699dea673e9SRodney W. Grimes { 700dea673e9SRodney W. Grimes register int state; 701dea673e9SRodney W. Grimes double time; 702dea673e9SRodney W. Grimes 7038d2fbde5SJustin T. Gibbs time = 0.0; 7048d2fbde5SJustin T. Gibbs 705dea673e9SRodney W. Grimes for (state = 0; state < CPUSTATES; ++state) 706dea673e9SRodney W. Grimes time += cur.cp_time[state]; 707dea673e9SRodney W. Grimes for (state = 0; state < CPUSTATES; ++state) 7088d2fbde5SJustin T. Gibbs printf("%3.0f", 709dea673e9SRodney W. Grimes 100. * cur.cp_time[state] / (time ? time : 1)); 710dea673e9SRodney W. Grimes } 7115fc5ae5cSThomas Moestl 7125fc5ae5cSThomas Moestl static void 7135fc5ae5cSThomas Moestl getsysctl(const char *name, void *ptr, size_t len) 7145fc5ae5cSThomas Moestl { 7155fc5ae5cSThomas Moestl size_t nlen = len; 7165fc5ae5cSThomas Moestl 7175fc5ae5cSThomas Moestl if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) 7185fc5ae5cSThomas Moestl err(1, "sysctl(%s...) failed", name); 7195fc5ae5cSThomas Moestl if (nlen != len) 7205fc5ae5cSThomas Moestl errx(1, "sysctl(%s...): expected %lu, got %lu", name, 7215fc5ae5cSThomas Moestl (unsigned long)len, (unsigned long)nlen); 7225fc5ae5cSThomas Moestl } 723