2 * Copyright (c) 1997, 1998, 2000, 2001 Kenneth D. Merry
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Parts of this program are derived from the original FreeBSD iostat
35 * Copyright (c) 1986, 1991, 1993
36 * The Regents of the University of California. All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * Ideas for the new iostat statistics output modes taken from the NetBSD
67 * Copyright (c) 1996 John M. Vinopal
68 * All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 * must display the following acknowledgement:
80 * This product includes software developed for the NetBSD Project
82 * 4. The name of the author may not be used to endorse or promote products
83 * derived from this software without specific prior written permission.
85 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
87 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
88 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
89 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
90 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
91 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
92 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
93 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
94 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 #include <sys/param.h>
100 #include <sys/errno.h>
101 #include <sys/resource.h>
102 #include <sys/sysctl.h>
108 #include <inttypes.h>
120 static struct nlist namelist[] = {
122 { .n_name = "_tk_nin",
123 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
125 { .n_name = "_tk_nout",
126 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
128 { .n_name = "_boottime",
129 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
132 .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
135 #define IOSTAT_DEFAULT_ROWS 20 /* Traditional default `wrows' */
137 static struct statinfo cur, last;
138 static int num_devices;
139 static struct device_selection *dev_select;
140 static int maxshowdevs;
141 static volatile sig_atomic_t headercount;
142 static volatile sig_atomic_t wresized; /* Tty resized, when non-zero. */
143 static volatile sig_atomic_t alarm_rang;
144 static volatile sig_atomic_t return_requested;
145 static unsigned short wrows; /* Current number of tty rows. */
146 static int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0;
147 static int xflag = 0, zflag = 0;
149 /* local function declarations */
150 static void usage(void);
151 static void needhdr(int signo);
152 static void needresize(int signo);
153 static void needreturn(int signo);
154 static void alarm_clock(int signo);
155 static void doresize(void);
156 static void phdr(void);
157 static void devstats(int perf_select, long double etime, int havelast);
158 static void cpustats(void);
159 static int readvar(kvm_t *kd, const char *name, int nlid, void *ptr,
166 * We also support the following 'traditional' syntax:
167 * iostat [drives] [wait [count]]
168 * This isn't mentioned in the man page, or the usage statement,
169 * but it is supported.
171 fprintf(stderr, "usage: iostat [-CdhIKoTxz?] [-c count] [-M core]"
172 " [-n devs] [-N system]\n"
173 "\t [-t type,if,pass] [-w wait] [drives]\n");
177 main(int argc, char **argv)
180 int tflag = 0, hflag = 0, cflag = 0, wflag = 0, nflag = 0;
181 int count = 0, waittime = 0;
182 char *memf = NULL, *nlistf = NULL;
183 struct devstat_match *matches;
184 struct itimerval alarmspec;
186 char errbuf[_POSIX2_LINE_MAX];
189 int num_devices_specified;
190 int num_selected, num_selections;
191 long select_generation;
192 char **specified_devices;
193 devstat_select_mode select_mode;
200 while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:xz?")) != -1) {
204 count = atoi(optarg);
206 errx(1, "count %d is < 1", count);
228 maxshowdevs = atoi(optarg);
230 errx(1, "number of devices %d is < 0",
241 if (devstat_buildmatch(optarg, &matches,
243 errx(1, "%s", devstat_errbuf);
253 errx(1, "wait time is < 1ms");
271 if (nlistf != NULL || memf != NULL) {
272 kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
275 errx(1, "kvm_openfiles: %s", errbuf);
277 if (kvm_nlist(kd, namelist) == -1)
278 errx(1, "kvm_nlist: %s", kvm_geterr(kd));
282 * Make sure that the userland devstat version matches the kernel
283 * devstat version. If not, exit and print a message informing
284 * the user of his mistake.
286 if (devstat_checkversion(kd) < 0)
287 errx(1, "%s", devstat_errbuf);
290 * Make sure Tflag and/or Cflag are set if dflag == 0. If dflag is
291 * greater than 0, they may be 0 or non-zero.
293 if (dflag == 0 && xflag == 0) {
298 /* find out how many devices we have */
299 if ((num_devices = devstat_getnumdevs(kd)) < 0)
300 err(1, "can't get number of devices");
303 * Figure out how many devices we should display.
307 maxshowdevs = num_devices;
308 else if (oflag > 0) {
309 if ((dflag > 0) && (Cflag == 0) && (Tflag == 0))
311 else if ((dflag > 0) && (Tflag > 0) && (Cflag == 0))
316 if ((dflag > 0) && (Cflag == 0))
323 cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
324 if (cur.dinfo == NULL)
325 err(1, "calloc failed");
327 last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
328 if (last.dinfo == NULL)
329 err(1, "calloc failed");
332 * Grab all the devices. We don't look to see if the list has
333 * changed here, since it almost certainly has. We only look for
336 if (devstat_getdevs(kd, &cur) == -1)
337 errx(1, "%s", devstat_errbuf);
339 num_devices = cur.dinfo->numdevs;
340 generation = cur.dinfo->generation;
343 * If the user specified any devices on the command line, see if
344 * they are in the list of devices we have now.
346 specified_devices = (char **)malloc(sizeof(char *));
347 if (specified_devices == NULL)
348 err(1, "malloc failed");
350 for (num_devices_specified = 0; *argv; ++argv) {
353 num_devices_specified++;
354 specified_devices = (char **)realloc(specified_devices,
356 num_devices_specified);
357 if (specified_devices == NULL)
358 err(1, "realloc failed");
360 specified_devices[num_devices_specified - 1] = *argv;
363 if (nflag == 0 && maxshowdevs < num_devices_specified)
364 maxshowdevs = num_devices_specified;
368 if ((num_devices_specified == 0) && (num_matches == 0))
369 select_mode = DS_SELECT_ADD;
371 select_mode = DS_SELECT_ONLY;
374 * At this point, selectdevs will almost surely indicate that the
375 * device list has changed, so we don't look for return values of 0
376 * or 1. If we get back -1, though, there is an error.
378 if (devstat_selectdevs(&dev_select, &num_selected,
379 &num_selections, &select_generation, generation,
380 cur.dinfo->devices, num_devices, matches,
381 num_matches, specified_devices,
382 num_devices_specified, select_mode, maxshowdevs,
384 errx(1, "%s", devstat_errbuf);
387 * Look for the traditional wait time and count arguments.
393 /* Let the user know he goofed, but keep going anyway */
395 warnx("discarding previous wait interval, using"
396 " %g instead", waittime / 1000.0);
402 warnx("discarding previous count, using %d"
410 * If the user specified a count, but not an interval, we default
411 * to an interval of 1 second.
413 if ((wflag == 0) && (cflag > 0))
417 * If the user specified a wait time, but not a count, we want to
418 * go on ad infinitum. This can be redundant if the user uses the
419 * traditional method of specifying the wait, since in that case we
420 * already set count = -1 above. Oh well.
422 if ((wflag > 0) && (cflag == 0))
425 bzero(cur.cp_time, sizeof(cur.cp_time));
430 * Set the snap time to the system boot time (ie: zero), so the
431 * stats are calculated since system boot.
436 * If the user stops the program (control-Z) and then resumes it,
437 * print out the header again.
439 (void)signal(SIGCONT, needhdr);
442 * If our standard output is a tty, then install a SIGWINCH handler
443 * and set wresized so that our first iteration through the main
444 * iostat loop will peek at the terminal's current rows to find out
445 * how many lines can fit in a screenful of output.
447 if (isatty(fileno(stdout)) != 0) {
449 (void)signal(SIGWINCH, needresize);
452 wrows = IOSTAT_DEFAULT_ROWS;
456 * Register a SIGINT handler so that we can print out final statistics
457 * when we get that signal
459 (void)signal(SIGINT, needreturn);
462 * Register a SIGALRM handler to implement sleeps if the user uses the
465 (void)signal(SIGALRM, alarm_clock);
466 alarmspec.it_interval.tv_sec = waittime / 1000;
467 alarmspec.it_interval.tv_usec = 1000 * (waittime % 1000);
468 alarmspec.it_value.tv_sec = waittime / 1000;
469 alarmspec.it_value.tv_usec = 1000 * (waittime % 1000);
470 setitimer(ITIMER_REAL, &alarmspec, NULL);
472 for (headercount = 1;;) {
473 struct devinfo *tmp_dinfo;
476 sigset_t sigmask, oldsigmask;
479 if ((readvar(kd, "kern.tty_nin", X_TK_NIN, &cur.tk_nin,
480 sizeof(cur.tk_nin)) != 0)
481 || (readvar(kd, "kern.tty_nout", X_TK_NOUT,
482 &cur.tk_nout, sizeof(cur.tk_nout))!= 0)) {
484 warnx("disabling TTY statistics");
490 if (readvar(kd, "kern.cp_time", 0,
491 &cur.cp_time, sizeof(cur.cp_time)) != 0)
494 if (kvm_getcptime(kd, cur.cp_time) < 0) {
495 warnx("kvm_getcptime: %s",
501 warnx("disabling CPU time statistics");
504 if (!--headercount) {
511 tmp_dinfo = last.dinfo;
512 last.dinfo = cur.dinfo;
513 cur.dinfo = tmp_dinfo;
515 last.snap_time = cur.snap_time;
518 * Here what we want to do is refresh our device stats.
519 * devstat_getdevs() returns 1 when the device list has changed.
520 * If the device list has changed, we want to go through
521 * the selection process again, in case a device that we
522 * were previously displaying has gone away.
524 switch (devstat_getdevs(kd, &cur)) {
526 errx(1, "%s", devstat_errbuf);
531 num_devices = cur.dinfo->numdevs;
532 generation = cur.dinfo->generation;
533 retval = devstat_selectdevs(&dev_select, &num_selected,
538 num_devices, matches,
541 num_devices_specified,
542 select_mode, maxshowdevs,
546 errx(1, "%s", devstat_errbuf);
564 * We only want to re-select devices if we're in 'top'
565 * mode. This is the only mode where the devices selected
566 * could actually change.
570 retval = devstat_selectdevs(&dev_select, &num_selected,
575 num_devices, matches,
578 num_devices_specified,
579 select_mode, maxshowdevs,
583 errx(1,"%s", devstat_errbuf);
598 cur.tk_nin -= last.tk_nin;
601 cur.tk_nout -= last.tk_nout;
605 etime = cur.snap_time - last.snap_time;
610 for (i = 0; i < CPUSTATES; i++) {
611 tmp = cur.cp_time[i];
612 cur.cp_time[i] -= last.cp_time[i];
613 last.cp_time[i] = tmp;
616 if (xflag == 0 && Tflag > 0)
617 printf("%4.0Lf %5.0Lf", cur.tk_nin / etime,
618 cur.tk_nout / etime);
620 devstats(hflag, etime, havelast);
630 if ((count >= 0 && --count <= 0) || return_requested)
634 * Use sigsuspend to safely sleep until either signal is
638 sigemptyset(&sigmask);
639 sigaddset(&sigmask, SIGINT);
640 sigaddset(&sigmask, SIGALRM);
641 sigprocmask(SIG_BLOCK, &sigmask, &oldsigmask);
642 while (! (alarm_rang || return_requested) ) {
643 sigsuspend(&oldsigmask);
645 sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
654 * Force a header to be prepended to the next output.
657 needhdr(int signo __unused)
664 * When the terminal is resized, force an update of the maximum number of rows
665 * printed between each header repetition. Then force a new header to be
666 * prepended to the next output.
669 needresize(int signo __unused)
677 * Record the alarm so the main loop can break its sleep
680 alarm_clock(int signo __unused)
686 * Request that the main loop exit soon
689 needreturn(int signo __unused)
691 return_requested = 1;
695 * Update the global `wrows' count of terminal rows.
704 status = ioctl(fileno(stdout), TIOCGWINSZ, &w);
705 if (status == -1 && errno == EINTR)
707 else if (status == -1)
710 wrows = w.ws_row - 3;
712 wrows = IOSTAT_DEFAULT_ROWS;
717 * Inhibit doresize() calls until we are rescheduled by SIGWINCH.
729 * If xflag is set, we need a per-loop header, not a page header, so
730 * just return. We'll print the header in devstats().
736 (void)printf(" tty");
737 for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){
739 if ((dev_select[i].selected != 0)
740 && (dev_select[i].selected <= maxshowdevs)) {
741 di = dev_select[i].position;
742 snprintf(devbuf, sizeof(devbuf), "%s%d",
743 cur.dinfo->devices[di].device_name,
744 cur.dinfo->devices[di].unit_number);
746 (void)printf("%13.6s ", devbuf);
748 printf("%16.6s ", devbuf);
753 (void)printf(" cpu\n");
758 (void)printf(" tin tout");
760 for (i=0, printed = 0;(i < num_devices) && (printed < maxshowdevs);i++){
761 if ((dev_select[i].selected != 0)
762 && (dev_select[i].selected <= maxshowdevs)) {
765 (void)printf(" sps tps msps ");
767 (void)printf(" blk xfr msps ");
770 printf(" KB/t tps MB/s ");
772 printf(" KB/t xfrs MB ");
778 (void)printf(" us ni sy in id\n");
785 devstats(int perf_select, long double etime, int havelast)
788 long double transfers_per_second, transfers_per_second_read, transfers_per_second_write;
789 long double kb_per_transfer, mb_per_second, mb_per_second_read, mb_per_second_write;
790 u_int64_t total_bytes, total_transfers, total_blocks;
791 u_int64_t total_bytes_read, total_transfers_read;
792 u_int64_t total_bytes_write, total_transfers_write;
793 long double busy_pct, busy_time;
795 long double total_mb;
796 long double blocks_per_second, ms_per_transaction, total_duration;
801 printf(" extended device statistics ");
808 printf("device r/s w/s kr/s kw/s qlen "
811 printf("device r/i w/i kr/i"
812 " kw/i qlen tsvc_t/i sb/i ");
817 printf("us ni sy in id ");
821 for (dn = 0; dn < num_devices; dn++) {
824 if (((perf_select == 0) && (dev_select[dn].selected == 0))
825 || (dev_select[dn].selected > maxshowdevs))
828 di = dev_select[dn].position;
830 if (devstat_compute_statistics(&cur.dinfo->devices[di],
831 havelast ? &last.dinfo->devices[di] : NULL, etime,
832 DSM_TOTAL_BYTES, &total_bytes,
833 DSM_TOTAL_BYTES_READ, &total_bytes_read,
834 DSM_TOTAL_BYTES_WRITE, &total_bytes_write,
835 DSM_TOTAL_TRANSFERS, &total_transfers,
836 DSM_TOTAL_TRANSFERS_READ, &total_transfers_read,
837 DSM_TOTAL_TRANSFERS_WRITE, &total_transfers_write,
838 DSM_TOTAL_BLOCKS, &total_blocks,
839 DSM_KB_PER_TRANSFER, &kb_per_transfer,
840 DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
841 DSM_TRANSFERS_PER_SECOND_READ, &transfers_per_second_read,
842 DSM_TRANSFERS_PER_SECOND_WRITE, &transfers_per_second_write,
843 DSM_MB_PER_SECOND, &mb_per_second,
844 DSM_MB_PER_SECOND_READ, &mb_per_second_read,
845 DSM_MB_PER_SECOND_WRITE, &mb_per_second_write,
846 DSM_BLOCKS_PER_SECOND, &blocks_per_second,
847 DSM_MS_PER_TRANSACTION, &ms_per_transaction,
848 DSM_BUSY_PCT, &busy_pct,
849 DSM_QUEUE_LENGTH, &queue_len,
850 DSM_TOTAL_DURATION, &total_duration,
851 DSM_TOTAL_BUSY_TIME, &busy_time,
853 errx(1, "%s", devstat_errbuf);
855 if (perf_select != 0) {
856 dev_select[dn].bytes = total_bytes;
857 if ((dev_select[dn].selected == 0)
858 || (dev_select[dn].selected > maxshowdevs))
862 if (Kflag > 0 || xflag > 0) {
863 int block_size = cur.dinfo->devices[di].block_size;
864 total_blocks = total_blocks * (block_size ?
865 block_size : 512) / 1024;
869 if (asprintf(&devicename, "%s%d",
870 cur.dinfo->devices[di].device_name,
871 cur.dinfo->devices[di].unit_number) == -1)
874 * If zflag is set, skip any devices with zero I/O.
876 if (zflag == 0 || transfers_per_second_read > 0.05 ||
877 transfers_per_second_write > 0.05 ||
878 mb_per_second_read > ((long double).0005)/1024 ||
879 mb_per_second_write > ((long double).0005)/1024 ||
882 printf("%-8.8s %5.1Lf %5.1Lf %7.1Lf %7.1Lf %4" PRIu64 " %5.1Lf %3.0Lf ",
884 transfers_per_second_read,
885 transfers_per_second_write,
886 mb_per_second_read * 1024,
887 mb_per_second_write * 1024,
889 ms_per_transaction, busy_pct);
891 printf("%-8.8s %11.1Lf %11.1Lf "
892 "%12.1Lf %12.1Lf %4" PRIu64
895 (long double)total_transfers_read,
896 (long double)total_transfers_write,
898 total_bytes_read / 1024,
900 total_bytes_write / 1024,
902 total_duration, busy_time);
905 * If this is the first device
906 * we're printing, also print
907 * CPU or TTY stats if requested.
911 printf("%4.0Lf%5.0Lf",
913 cur.tk_nout / etime);
920 } else if (oflag > 0) {
921 int msdig = (ms_per_transaction < 100.0) ? 1 : 0;
924 printf("%4.0Lf%4.0Lf%5.*Lf ",
926 transfers_per_second,
930 printf("%4.1" PRIu64 "%4.1" PRIu64 "%5.*Lf ",
937 printf(" %5.2Lf %3.0Lf %5.2Lf ",
939 transfers_per_second,
942 total_mb = total_bytes;
943 total_mb /= 1024 * 1024;
945 printf(" %5.2Lf %3.1" PRIu64 " %5.2Lf ",
952 if (xflag > 0 && zflag > 0 && firstline == 1 &&
953 (Tflag > 0 || Cflag > 0)) {
955 * If zflag is set and we did not print any device
956 * lines I/O because they were all zero,
957 * print TTY/CPU stats.
961 printf("%4.0Lf %5.0Lf", cur.tk_nin / etime,
962 cur.tk_nout / etime);
977 for (state = 0; state < CPUSTATES; ++state)
978 cptime += cur.cp_time[state];
979 for (state = 0; state < CPUSTATES; ++state)
981 rint(100. * cur.cp_time[state] / (cptime ? cptime : 1)));
985 readvar(kvm_t *kd, const char *name, int nlid, void *ptr, size_t len)
990 nbytes = kvm_read(kd, namelist[nlid].n_value, ptr, len);
993 warnx("kvm_read(%s): %s", namelist[nlid].n_name,
996 } else if ((size_t)nbytes != len) {
997 warnx("kvm_read(%s): expected %zu bytes, got %zd bytes",
998 namelist[nlid].n_name, len, nbytes);
1004 if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
1005 warn("sysctl(%s...) failed", name);
1009 warnx("sysctl(%s...): expected %lu, got %lu", name,
1010 (unsigned long)len, (unsigned long)nlen);