2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1997, 1998, 2000, 2001 Kenneth D. Merry
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Parts of this program are derived from the original FreeBSD iostat
37 * Copyright (c) 1986, 1991, 1993
38 * The Regents of the University of California. All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * Ideas for the new iostat statistics output modes taken from the NetBSD
69 * Copyright (c) 1996 John M. Vinopal
70 * All rights reserved.
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * This product includes software developed for the NetBSD Project
84 * 4. The name of the author may not be used to endorse or promote products
85 * derived from this software without specific prior written permission.
87 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
92 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
93 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
94 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
95 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 #include <sys/param.h>
102 #include <sys/errno.h>
103 #include <sys/resource.h>
104 #include <sys/sysctl.h>
110 #include <inttypes.h>
122 static struct nlist namelist[] = {
124 { .n_name = "_tty_nin",
125 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
127 { .n_name = "_tty_nout",
128 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
130 { .n_name = "_boottime",
131 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
134 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
137 #define IOSTAT_DEFAULT_ROWS 20 /* Traditional default `wrows' */
139 static struct statinfo cur, last;
140 static int num_devices;
141 static struct device_selection *dev_select;
142 static int maxshowdevs;
143 static volatile sig_atomic_t headercount;
144 static volatile sig_atomic_t wresized; /* Tty resized, when non-zero. */
145 static volatile sig_atomic_t alarm_rang;
146 static volatile sig_atomic_t return_requested;
147 static unsigned short wrows; /* Current number of tty rows. */
148 static int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0;
149 static int xflag = 0, zflag = 0;
151 /* local function declarations */
152 static void usage(void);
153 static void needhdr(int signo);
154 static void needresize(int signo);
155 static void needreturn(int signo);
156 static void alarm_clock(int signo);
157 static void doresize(void);
158 static void phdr(void);
159 static void devstats(int perf_select, long double etime, int havelast);
160 static void cpustats(void);
161 static int readvar(kvm_t *kd, const char *name, int nlid, void *ptr,
168 * We also support the following 'traditional' syntax:
169 * iostat [drives] [wait [count]]
170 * This isn't mentioned in the man page, or the usage statement,
171 * but it is supported.
173 fprintf(stderr, "usage: iostat [-CdhIKoTxz?] [-c count] [-M core]"
174 " [-n devs] [-N system]\n"
175 "\t [-t type,if,pass] [-w wait] [drives]\n");
179 main(int argc, char **argv)
182 int tflag = 0, hflag = 0, cflag = 0, wflag = 0, nflag = 0;
183 int count = 0, waittime = 0;
184 char *memf = NULL, *nlistf = NULL;
185 struct devstat_match *matches;
186 struct itimerval alarmspec;
188 char errbuf[_POSIX2_LINE_MAX];
191 int num_devices_specified;
192 int num_selected, num_selections;
193 long select_generation;
194 char **specified_devices;
195 devstat_select_mode select_mode;
202 while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:xz?")) != -1) {
206 count = atoi(optarg);
208 errx(1, "count %d is < 1", count);
230 maxshowdevs = atoi(optarg);
232 errx(1, "number of devices %d is < 0",
243 if (devstat_buildmatch(optarg, &matches,
245 errx(1, "%s", devstat_errbuf);
255 errx(1, "wait time is < 1ms");
273 if (nlistf != NULL || memf != NULL) {
274 kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
277 errx(1, "kvm_openfiles: %s", errbuf);
279 if (kvm_nlist(kd, namelist) == -1)
280 errx(1, "kvm_nlist: %s", kvm_geterr(kd));
284 * Make sure that the userland devstat version matches the kernel
285 * devstat version. If not, exit and print a message informing
286 * the user of his mistake.
288 if (devstat_checkversion(kd) < 0)
289 errx(1, "%s", devstat_errbuf);
292 * Make sure Tflag and/or Cflag are set if dflag == 0. If dflag is
293 * greater than 0, they may be 0 or non-zero.
295 if (dflag == 0 && xflag == 0) {
300 /* find out how many devices we have */
301 if ((num_devices = devstat_getnumdevs(kd)) < 0)
302 err(1, "can't get number of devices");
305 * Figure out how many devices we should display.
309 maxshowdevs = num_devices;
310 else if (oflag > 0) {
311 if ((dflag > 0) && (Cflag == 0) && (Tflag == 0))
313 else if ((dflag > 0) && (Tflag > 0) && (Cflag == 0))
318 if ((dflag > 0) && (Cflag == 0))
325 cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
326 if (cur.dinfo == NULL)
327 err(1, "calloc failed");
329 last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
330 if (last.dinfo == NULL)
331 err(1, "calloc failed");
334 * Grab all the devices. We don't look to see if the list has
335 * changed here, since it almost certainly has. We only look for
338 if (devstat_getdevs(kd, &cur) == -1)
339 errx(1, "%s", devstat_errbuf);
341 num_devices = cur.dinfo->numdevs;
342 generation = cur.dinfo->generation;
345 * If the user specified any devices on the command line, see if
346 * they are in the list of devices we have now.
348 specified_devices = (char **)malloc(sizeof(char *));
349 if (specified_devices == NULL)
350 err(1, "malloc failed");
352 for (num_devices_specified = 0; *argv; ++argv) {
355 num_devices_specified++;
356 specified_devices = (char **)realloc(specified_devices,
358 num_devices_specified);
359 if (specified_devices == NULL)
360 err(1, "realloc failed");
362 specified_devices[num_devices_specified - 1] = *argv;
365 if (nflag == 0 && maxshowdevs < num_devices_specified)
366 maxshowdevs = num_devices_specified;
370 if ((num_devices_specified == 0) && (num_matches == 0))
371 select_mode = DS_SELECT_ADD;
373 select_mode = DS_SELECT_ONLY;
376 * At this point, selectdevs will almost surely indicate that the
377 * device list has changed, so we don't look for return values of 0
378 * or 1. If we get back -1, though, there is an error.
380 if (devstat_selectdevs(&dev_select, &num_selected,
381 &num_selections, &select_generation, generation,
382 cur.dinfo->devices, num_devices, matches,
383 num_matches, specified_devices,
384 num_devices_specified, select_mode, maxshowdevs,
386 errx(1, "%s", devstat_errbuf);
389 * Look for the traditional wait time and count arguments.
395 /* Let the user know he goofed, but keep going anyway */
397 warnx("discarding previous wait interval, using"
398 " %g instead", waittime / 1000.0);
404 warnx("discarding previous count, using %d"
412 * If the user specified a count, but not an interval, we default
413 * to an interval of 1 second.
415 if ((wflag == 0) && (cflag > 0))
419 * If the user specified a wait time, but not a count, we want to
420 * go on ad infinitum. This can be redundant if the user uses the
421 * traditional method of specifying the wait, since in that case we
422 * already set count = -1 above. Oh well.
424 if ((wflag > 0) && (cflag == 0))
427 bzero(cur.cp_time, sizeof(cur.cp_time));
432 * Set the snap time to the system boot time (ie: zero), so the
433 * stats are calculated since system boot.
438 * If the user stops the program (control-Z) and then resumes it,
439 * print out the header again.
441 (void)signal(SIGCONT, needhdr);
444 * If our standard output is a tty, then install a SIGWINCH handler
445 * and set wresized so that our first iteration through the main
446 * iostat loop will peek at the terminal's current rows to find out
447 * how many lines can fit in a screenful of output.
449 if (isatty(fileno(stdout)) != 0) {
451 (void)signal(SIGWINCH, needresize);
454 wrows = IOSTAT_DEFAULT_ROWS;
458 * Register a SIGINT handler so that we can print out final statistics
459 * when we get that signal
461 (void)signal(SIGINT, needreturn);
464 * Register a SIGALRM handler to implement sleeps if the user uses the
467 (void)signal(SIGALRM, alarm_clock);
468 alarmspec.it_interval.tv_sec = waittime / 1000;
469 alarmspec.it_interval.tv_usec = 1000 * (waittime % 1000);
470 alarmspec.it_value.tv_sec = waittime / 1000;
471 alarmspec.it_value.tv_usec = 1000 * (waittime % 1000);
472 setitimer(ITIMER_REAL, &alarmspec, NULL);
474 for (headercount = 1;;) {
475 struct devinfo *tmp_dinfo;
478 sigset_t sigmask, oldsigmask;
481 if ((readvar(kd, "kern.tty_nin", X_TTY_NIN, &cur.tk_nin,
482 sizeof(cur.tk_nin)) != 0)
483 || (readvar(kd, "kern.tty_nout", X_TTY_NOUT,
484 &cur.tk_nout, sizeof(cur.tk_nout))!= 0)) {
486 warnx("disabling TTY statistics");
492 if (readvar(kd, "kern.cp_time", 0,
493 &cur.cp_time, sizeof(cur.cp_time)) != 0)
496 if (kvm_getcptime(kd, cur.cp_time) < 0) {
497 warnx("kvm_getcptime: %s",
503 warnx("disabling CPU time statistics");
506 if (!--headercount) {
513 tmp_dinfo = last.dinfo;
514 last.dinfo = cur.dinfo;
515 cur.dinfo = tmp_dinfo;
517 last.snap_time = cur.snap_time;
520 * Here what we want to do is refresh our device stats.
521 * devstat_getdevs() returns 1 when the device list has changed.
522 * If the device list has changed, we want to go through
523 * the selection process again, in case a device that we
524 * were previously displaying has gone away.
526 switch (devstat_getdevs(kd, &cur)) {
528 errx(1, "%s", devstat_errbuf);
533 num_devices = cur.dinfo->numdevs;
534 generation = cur.dinfo->generation;
535 retval = devstat_selectdevs(&dev_select, &num_selected,
540 num_devices, matches,
543 num_devices_specified,
544 select_mode, maxshowdevs,
548 errx(1, "%s", devstat_errbuf);
566 * We only want to re-select devices if we're in 'top'
567 * mode. This is the only mode where the devices selected
568 * could actually change.
572 retval = devstat_selectdevs(&dev_select, &num_selected,
577 num_devices, matches,
580 num_devices_specified,
581 select_mode, maxshowdevs,
585 errx(1,"%s", devstat_errbuf);
600 cur.tk_nin -= last.tk_nin;
603 cur.tk_nout -= last.tk_nout;
607 etime = cur.snap_time - last.snap_time;
612 for (i = 0; i < CPUSTATES; i++) {
613 tmp = cur.cp_time[i];
614 cur.cp_time[i] -= last.cp_time[i];
615 last.cp_time[i] = tmp;
618 if (xflag == 0 && Tflag > 0)
619 printf("%4.0Lf %5.0Lf", cur.tk_nin / etime,
620 cur.tk_nout / etime);
622 devstats(hflag, etime, havelast);
632 if ((count >= 0 && --count <= 0) || return_requested)
636 * Use sigsuspend to safely sleep until either signal is
640 sigemptyset(&sigmask);
641 sigaddset(&sigmask, SIGINT);
642 sigaddset(&sigmask, SIGALRM);
643 sigprocmask(SIG_BLOCK, &sigmask, &oldsigmask);
644 while (! (alarm_rang || return_requested) ) {
645 sigsuspend(&oldsigmask);
647 sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
656 * Force a header to be prepended to the next output.
659 needhdr(int signo __unused)
666 * When the terminal is resized, force an update of the maximum number of rows
667 * printed between each header repetition. Then force a new header to be
668 * prepended to the next output.
671 needresize(int signo __unused)
679 * Record the alarm so the main loop can break its sleep
682 alarm_clock(int signo __unused)
688 * Request that the main loop exit soon
691 needreturn(int signo __unused)
693 return_requested = 1;
697 * Update the global `wrows' count of terminal rows.
706 status = ioctl(fileno(stdout), TIOCGWINSZ, &w);
707 if (status == -1 && errno == EINTR)
709 else if (status == -1)
712 wrows = w.ws_row - 3;
714 wrows = IOSTAT_DEFAULT_ROWS;
719 * Inhibit doresize() calls until we are rescheduled by SIGWINCH.
731 * If xflag is set, we need a per-loop header, not a page header, so
732 * just return. We'll print the header in devstats().
738 (void)printf(" tty");
739 for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){
741 if ((dev_select[i].selected != 0)
742 && (dev_select[i].selected <= maxshowdevs)) {
743 di = dev_select[i].position;
744 snprintf(devbuf, sizeof(devbuf), "%s%d",
745 cur.dinfo->devices[di].device_name,
746 cur.dinfo->devices[di].unit_number);
748 (void)printf("%13.6s ", devbuf);
750 printf("%16.6s ", devbuf);
755 (void)printf(" cpu\n");
760 (void)printf(" tin tout");
762 for (i=0, printed = 0;(i < num_devices) && (printed < maxshowdevs);i++){
763 if ((dev_select[i].selected != 0)
764 && (dev_select[i].selected <= maxshowdevs)) {
767 (void)printf(" sps tps msps ");
769 (void)printf(" blk xfr msps ");
772 printf(" KB/t tps MB/s ");
774 printf(" KB/t xfrs MB ");
780 (void)printf(" us ni sy in id\n");
787 devstats(int perf_select, long double etime, int havelast)
790 long double transfers_per_second, transfers_per_second_read;
791 long double transfers_per_second_write;
792 long double kb_per_transfer, mb_per_second, mb_per_second_read;
793 long double mb_per_second_write;
794 u_int64_t total_bytes, total_transfers, total_blocks;
795 u_int64_t total_bytes_read, total_transfers_read;
796 u_int64_t total_bytes_write, total_transfers_write;
797 long double busy_pct, busy_time;
799 long double total_mb, blocks_per_second, total_duration;
800 long double ms_per_other, ms_per_read, ms_per_write, ms_per_transaction;
807 printf(" us ni sy in id\n");
811 printf(" extended device statistics ");
816 printf("device r/s w/s kr/s kw/s "
817 " ms/r ms/w ms/o ms/t qlen %%b ");
819 printf("device r/i w/i kr/i"
820 " kw/i qlen tsvc_t/i sb/i ");
827 for (dn = 0; dn < num_devices; dn++) {
830 if (((perf_select == 0) && (dev_select[dn].selected == 0))
831 || (dev_select[dn].selected > maxshowdevs))
834 di = dev_select[dn].position;
836 if (devstat_compute_statistics(&cur.dinfo->devices[di],
837 havelast ? &last.dinfo->devices[di] : NULL, etime,
838 DSM_TOTAL_BYTES, &total_bytes,
839 DSM_TOTAL_BYTES_READ, &total_bytes_read,
840 DSM_TOTAL_BYTES_WRITE, &total_bytes_write,
841 DSM_TOTAL_TRANSFERS, &total_transfers,
842 DSM_TOTAL_TRANSFERS_READ, &total_transfers_read,
843 DSM_TOTAL_TRANSFERS_WRITE, &total_transfers_write,
844 DSM_TOTAL_BLOCKS, &total_blocks,
845 DSM_KB_PER_TRANSFER, &kb_per_transfer,
846 DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
847 DSM_TRANSFERS_PER_SECOND_READ, &transfers_per_second_read,
848 DSM_TRANSFERS_PER_SECOND_WRITE, &transfers_per_second_write,
849 DSM_MB_PER_SECOND, &mb_per_second,
850 DSM_MB_PER_SECOND_READ, &mb_per_second_read,
851 DSM_MB_PER_SECOND_WRITE, &mb_per_second_write,
852 DSM_BLOCKS_PER_SECOND, &blocks_per_second,
853 DSM_MS_PER_TRANSACTION, &ms_per_transaction,
854 DSM_MS_PER_TRANSACTION_READ, &ms_per_read,
855 DSM_MS_PER_TRANSACTION_WRITE, &ms_per_write,
856 DSM_MS_PER_TRANSACTION_OTHER, &ms_per_other,
857 DSM_BUSY_PCT, &busy_pct,
858 DSM_QUEUE_LENGTH, &queue_len,
859 DSM_TOTAL_DURATION, &total_duration,
860 DSM_TOTAL_BUSY_TIME, &busy_time,
862 errx(1, "%s", devstat_errbuf);
864 if (perf_select != 0) {
865 dev_select[dn].bytes = total_bytes;
866 if ((dev_select[dn].selected == 0)
867 || (dev_select[dn].selected > maxshowdevs))
871 if (Kflag > 0 || xflag > 0) {
872 int block_size = cur.dinfo->devices[di].block_size;
873 total_blocks = total_blocks * (block_size ?
874 block_size : 512) / 1024;
878 if (asprintf(&devicename, "%s%d",
879 cur.dinfo->devices[di].device_name,
880 cur.dinfo->devices[di].unit_number) == -1)
883 * If zflag is set, skip any devices with zero I/O.
885 if (zflag == 0 || transfers_per_second_read > 0.05 ||
886 transfers_per_second_write > 0.05 ||
887 mb_per_second_read > ((long double).0005)/1024 ||
888 mb_per_second_write > ((long double).0005)/1024 ||
891 printf("%-8.8s %7d %7d %8.1Lf "
892 "%8.1Lf %5d %5d %5d %5d "
893 "%4" PRIu64 " %3.0Lf ",
895 (int)transfers_per_second_read,
896 (int)transfers_per_second_write,
897 mb_per_second_read * 1024,
898 mb_per_second_write * 1024,
899 (int)ms_per_read, (int)ms_per_write,
901 (int)ms_per_transaction,
902 queue_len, busy_pct);
904 printf("%-8.8s %11.1Lf %11.1Lf "
905 "%12.1Lf %12.1Lf %4" PRIu64
908 (long double)total_transfers_read,
909 (long double)total_transfers_write,
911 total_bytes_read / 1024,
913 total_bytes_write / 1024,
915 total_duration, busy_time);
918 * If this is the first device
919 * we're printing, also print
920 * CPU or TTY stats if requested.
924 printf("%4.0Lf%5.0Lf",
926 cur.tk_nout / etime);
931 } else if (oflag > 0) {
932 int msdig = (ms_per_transaction < 99.94) ? 1 : 0;
935 printf("%4.0Lf%4.0Lf%5.*Lf ",
937 transfers_per_second,
941 printf("%4.1" PRIu64 "%4.1" PRIu64 "%5.*Lf ",
948 printf(" %4.*Lf %4.0Lf %5.*Lf ",
949 kb_per_transfer >= 100 ? 0 : 1,
951 transfers_per_second,
952 mb_per_second >= 1000 ? 0 : 1,
955 total_mb = total_bytes;
956 total_mb /= 1024 * 1024;
958 printf(" %4.1Lf %4.1" PRIu64 " %5.2Lf ",
965 if (xflag > 0 && zflag > 0 && firstline == 1 &&
966 (Tflag > 0 || Cflag > 0)) {
968 * If zflag is set and we did not print any device
969 * lines I/O because they were all zero,
970 * print TTY/CPU stats.
974 printf("%4.0Lf %5.0Lf", cur.tk_nin / etime,
975 cur.tk_nout / etime);
990 for (state = 0; state < CPUSTATES; ++state)
991 cptime += cur.cp_time[state];
992 for (state = 0; state < CPUSTATES; ++state)
994 rint(100. * cur.cp_time[state] / (cptime ? cptime : 1)));
998 readvar(kvm_t *kd, const char *name, int nlid, void *ptr, size_t len)
1003 nbytes = kvm_read(kd, namelist[nlid].n_value, ptr, len);
1006 warnx("kvm_read(%s): %s", namelist[nlid].n_name,
1009 } else if ((size_t)nbytes != len) {
1010 warnx("kvm_read(%s): expected %zu bytes, got %zd bytes",
1011 namelist[nlid].n_name, len, nbytes);
1017 if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
1018 warn("sysctl(%s...) failed", name);
1022 warnx("sysctl(%s...): expected %lu, got %lu", name,
1023 (unsigned long)len, (unsigned long)nlen);