| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: iostat.c,v 1.67 2018/04/08 11:37:31 mlelstv Exp $ */ | | 1 | /* $NetBSD: iostat.c,v 1.68 2022/06/17 01:47:45 kre Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996 John M. Vinopal | | 4 | * Copyright (c) 1996 John M. Vinopal |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -61,27 +61,27 @@ | | | @@ -61,27 +61,27 @@ |
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) 1986, 1991, 1993\ | | 66 | __COPYRIGHT("@(#) Copyright (c) 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 |
72 | static char sccsid[] = "@(#)iostat.c 8.3 (Berkeley) 4/28/95"; | | 72 | static char sccsid[] = "@(#)iostat.c 8.3 (Berkeley) 4/28/95"; |
73 | #else | | 73 | #else |
74 | __RCSID("$NetBSD: iostat.c,v 1.67 2018/04/08 11:37:31 mlelstv Exp $"); | | 74 | __RCSID("$NetBSD: iostat.c,v 1.68 2022/06/17 01:47:45 kre Exp $"); |
75 | #endif | | 75 | #endif |
76 | #endif /* not lint */ | | 76 | #endif /* not lint */ |
77 | | | 77 | |
78 | #include <sys/types.h> | | 78 | #include <sys/types.h> |
79 | #include <sys/ioctl.h> | | 79 | #include <sys/ioctl.h> |
80 | #include <sys/sched.h> | | 80 | #include <sys/sched.h> |
81 | #include <sys/time.h> | | 81 | #include <sys/time.h> |
82 | | | 82 | |
83 | #include <err.h> | | 83 | #include <err.h> |
84 | #include <ctype.h> | | 84 | #include <ctype.h> |
85 | #include <signal.h> | | 85 | #include <signal.h> |
86 | #include <stdio.h> | | 86 | #include <stdio.h> |
87 | #include <stdlib.h> | | 87 | #include <stdlib.h> |
| @@ -114,27 +114,27 @@ static int wincols = 80; | | | @@ -114,27 +114,27 @@ static int wincols = 80; |
114 | static void cpustats(void); | | 114 | static void cpustats(void); |
115 | static double drive_time(double, int); | | 115 | static double drive_time(double, int); |
116 | static void drive_stats(double); | | 116 | static void drive_stats(double); |
117 | static void drive_stats2(double); | | 117 | static void drive_stats2(double); |
118 | static void drive_statsx(double); | | 118 | static void drive_statsx(double); |
119 | static void drive_statsy(double); | | 119 | static void drive_statsy(double); |
120 | static void drive_statsy_io(double, double, double); | | 120 | static void drive_statsy_io(double, double, double); |
121 | static void drive_statsy_q(double, double, double, double, double, double); | | 121 | static void drive_statsy_q(double, double, double, double, double, double); |
122 | static void sig_header(int); | | 122 | static void sig_header(int); |
123 | static volatile int do_header; | | 123 | static volatile int do_header; |
124 | static void header(void); | | 124 | static void header(void); |
125 | __dead static void usage(void); | | 125 | __dead static void usage(void); |
126 | static void display(void); | | 126 | static void display(void); |
127 | static int selectdrives(int, char *[]); | | 127 | static int selectdrives(int, char *[], int); |
128 | | | 128 | |
129 | int | | 129 | int |
130 | main(int argc, char *argv[]) | | 130 | main(int argc, char *argv[]) |
131 | { | | 131 | { |
132 | int ch, hdrcnt, hdroffset, ndrives, lines; | | 132 | int ch, hdrcnt, hdroffset, ndrives, lines; |
133 | struct timespec tv; | | 133 | struct timespec tv; |
134 | struct ttysize ts; | | 134 | struct ttysize ts; |
135 | | | 135 | |
136 | while ((ch = getopt(argc, argv, "Cc:dDITw:xy")) != -1) | | 136 | while ((ch = getopt(argc, argv, "Cc:dDITw:xy")) != -1) |
137 | switch (ch) { | | 137 | switch (ch) { |
138 | case 'c': | | 138 | case 'c': |
139 | if ((reps = atoi(optarg)) <= 0) | | 139 | if ((reps = atoi(optarg)) <= 0) |
140 | errx(1, "repetition count <= 0."); | | 140 | errx(1, "repetition count <= 0."); |
| @@ -193,27 +193,27 @@ main(int argc, char *argv[]) | | | @@ -193,27 +193,27 @@ main(int argc, char *argv[]) |
193 | wincols = ts.ts_cols; | | 193 | wincols = ts.ts_cols; |
194 | } | | 194 | } |
195 | | | 195 | |
196 | defdrives = wincols; | | 196 | defdrives = wincols; |
197 | if (ISSET(todo, SHOW_CPU)) | | 197 | if (ISSET(todo, SHOW_CPU)) |
198 | defdrives -= 16; /* XXX magic number */ | | 198 | defdrives -= 16; /* XXX magic number */ |
199 | if (ISSET(todo, SHOW_TTY)) | | 199 | if (ISSET(todo, SHOW_TTY)) |
200 | defdrives -= 10; /* XXX magic number */ | | 200 | defdrives -= 10; /* XXX magic number */ |
201 | defdrives /= 18; /* XXX magic number */ | | 201 | defdrives /= 18; /* XXX magic number */ |
202 | | | 202 | |
203 | drvinit(0); | | 203 | drvinit(0); |
204 | cpureadstats(); | | 204 | cpureadstats(); |
205 | drvreadstats(); | | 205 | drvreadstats(); |
206 | ndrives = selectdrives(argc, argv); | | 206 | ndrives = selectdrives(argc, argv, 1); |
207 | if (ndrives == 0) { | | 207 | if (ndrives == 0) { |
208 | /* No drives are selected. No need to show drive stats. */ | | 208 | /* No drives are selected. No need to show drive stats. */ |
209 | todo &= ~SHOW_STATS_ALL; | | 209 | todo &= ~SHOW_STATS_ALL; |
210 | if (todo == 0) | | 210 | if (todo == 0) |
211 | errx(1, "no drives"); | | 211 | errx(1, "no drives"); |
212 | } | | 212 | } |
213 | tv.tv_sec = interval; | | 213 | tv.tv_sec = interval; |
214 | tv.tv_nsec = 0; | | 214 | tv.tv_nsec = 0; |
215 | | | 215 | |
216 | /* print a new header on sigcont */ | | 216 | /* print a new header on sigcont */ |
217 | (void)signal(SIGCONT, sig_header); | | 217 | (void)signal(SIGCONT, sig_header); |
218 | | | 218 | |
219 | for (hdrcnt = 1;;) { | | 219 | for (hdrcnt = 1;;) { |
| @@ -235,27 +235,27 @@ main(int argc, char *argv[]) | | | @@ -235,27 +235,27 @@ main(int argc, char *argv[]) |
235 | cpuswap(); | | 235 | cpuswap(); |
236 | drvswap(); | | 236 | drvswap(); |
237 | tkswap(); | | 237 | tkswap(); |
238 | } | | 238 | } |
239 | | | 239 | |
240 | display(); | | 240 | display(); |
241 | | | 241 | |
242 | if (reps >= 0 && --reps <= 0) | | 242 | if (reps >= 0 && --reps <= 0) |
243 | break; | | 243 | break; |
244 | nanosleep(&tv, NULL); | | 244 | nanosleep(&tv, NULL); |
245 | cpureadstats(); | | 245 | cpureadstats(); |
246 | drvreadstats(); | | 246 | drvreadstats(); |
247 | | | 247 | |
248 | ndrives = selectdrives(argc, argv); | | 248 | ndrives = selectdrives(argc, argv, 0); |
249 | } | | 249 | } |
250 | exit(0); | | 250 | exit(0); |
251 | } | | 251 | } |
252 | | | 252 | |
253 | static void | | 253 | static void |
254 | sig_header(int signo) | | 254 | sig_header(int signo) |
255 | { | | 255 | { |
256 | do_header = 1; | | 256 | do_header = 1; |
257 | } | | 257 | } |
258 | | | 258 | |
259 | static void | | 259 | static void |
260 | header(void) | | 260 | header(void) |
261 | { | | 261 | { |
| @@ -604,27 +604,27 @@ display(void) | | | @@ -604,27 +604,27 @@ display(void) |
604 | } | | 604 | } |
605 | | | 605 | |
606 | | | 606 | |
607 | if (ISSET(todo, SHOW_CPU)) | | 607 | if (ISSET(todo, SHOW_CPU)) |
608 | cpustats(); | | 608 | cpustats(); |
609 | | | 609 | |
610 | (void)printf("\n"); | | 610 | (void)printf("\n"); |
611 | | | 611 | |
612 | out: | | 612 | out: |
613 | (void)fflush(stdout); | | 613 | (void)fflush(stdout); |
614 | } | | 614 | } |
615 | | | 615 | |
616 | static int | | 616 | static int |
617 | selectdrives(int argc, char *argv[]) | | 617 | selectdrives(int argc, char *argv[], int first) |
618 | { | | 618 | { |
619 | int i, maxdrives, ndrives, tried; | | 619 | int i, maxdrives, ndrives, tried; |
620 | | | 620 | |
621 | /* | | 621 | /* |
622 | * Choose drives to be displayed. Priority goes to (in order) drives | | 622 | * Choose drives to be displayed. Priority goes to (in order) drives |
623 | * supplied as arguments and default drives. If everything isn't | | 623 | * supplied as arguments and default drives. If everything isn't |
624 | * filled in and there are drives not taken care of, display the first | | 624 | * filled in and there are drives not taken care of, display the first |
625 | * few that fit. | | 625 | * few that fit. |
626 | * | | 626 | * |
627 | * The backward compatibility #ifdefs permit the syntax: | | 627 | * The backward compatibility #ifdefs permit the syntax: |
628 | * iostat [ drives ] [ interval [ count ] ] | | 628 | * iostat [ drives ] [ interval [ count ] ] |
629 | */ | | 629 | */ |
630 | | | 630 | |
| @@ -653,27 +653,27 @@ selectdrives(int argc, char *argv[]) | | | @@ -653,27 +653,27 @@ selectdrives(int argc, char *argv[]) |
653 | (int)ndrive < defdrives) | | 653 | (int)ndrive < defdrives) |
654 | ? (int)(ndrive) : defdrives; | | 654 | ? (int)(ndrive) : defdrives; |
655 | for (i = 0; i < maxdrives; i++) { | | 655 | for (i = 0; i < maxdrives; i++) { |
656 | cur.select[i] = 1; | | 656 | cur.select[i] = 1; |
657 | | | 657 | |
658 | ++ndrives; | | 658 | ++ndrives; |
659 | if (!ISSET(todo, SHOW_STATS_X | SHOW_STATS_Y) && | | 659 | if (!ISSET(todo, SHOW_STATS_X | SHOW_STATS_Y) && |
660 | ndrives == defdrives) | | 660 | ndrives == defdrives) |
661 | break; | | 661 | break; |
662 | } | | 662 | } |
663 | } | | 663 | } |
664 | | | 664 | |
665 | #ifdef BACKWARD_COMPATIBILITY | | 665 | #ifdef BACKWARD_COMPATIBILITY |
666 | if (*argv) { | | 666 | if (first && *argv) { |
667 | interval = atoi(*argv); | | 667 | interval = atoi(*argv); |
668 | if (*++argv) | | 668 | if (*++argv) |
669 | reps = atoi(*argv); | | 669 | reps = atoi(*argv); |
670 | } | | 670 | } |
671 | #endif | | 671 | #endif |
672 | | | 672 | |
673 | if (interval) { | | 673 | if (interval) { |
674 | if (!reps) | | 674 | if (!reps) |
675 | reps = -1; | | 675 | reps = -1; |
676 | } else | | 676 | } else |
677 | if (reps) | | 677 | if (reps) |
678 | interval = 1; | | 678 | interval = 1; |
679 | | | 679 | |