| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: iostat.c,v 1.53 2009/04/15 10:05:41 lukem Exp $ */ | | 1 | /* $NetBSD: iostat.c,v 1.54 2011/01/07 03:12:27 jakllsch 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,54 +61,57 @@ | | | @@ -61,54 +61,57 @@ |
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.53 2009/04/15 10:05:41 lukem Exp $"); | | 74 | __RCSID("$NetBSD: iostat.c,v 1.54 2011/01/07 03:12:27 jakllsch 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> |
88 | #include <string.h> | | 88 | #include <string.h> |
89 | #include <unistd.h> | | 89 | #include <unistd.h> |
| | | 90 | #include <math.h> |
90 | | | 91 | |
91 | #include "drvstats.h" | | 92 | #include "drvstats.h" |
92 | | | 93 | |
93 | /* Namelist and memory files. */ | | 94 | /* Namelist and memory files. */ |
94 | char *nlistf, *memf; | | 95 | char *nlistf, *memf; |
95 | | | 96 | |
96 | int hz, reps, interval; | | 97 | int hz, reps, interval; |
97 | static int todo = 0; | | 98 | static int todo = 0; |
98 | static int defdrives; | | 99 | static int defdrives; |
99 | static int winlines = 20; | | 100 | static int winlines = 20; |
100 | static int wincols = 80; | | 101 | static int wincols = 80; |
101 | | | 102 | |
| | | 103 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
| | | 104 | |
102 | #define ISSET(x, a) ((x) & (a)) | | 105 | #define ISSET(x, a) ((x) & (a)) |
103 | #define SHOW_CPU (1<<0) | | 106 | #define SHOW_CPU (1<<0) |
104 | #define SHOW_TTY (1<<1) | | 107 | #define SHOW_TTY (1<<1) |
105 | #define SHOW_STATS_1 (1<<2) | | 108 | #define SHOW_STATS_1 (1<<2) |
106 | #define SHOW_STATS_2 (1<<3) | | 109 | #define SHOW_STATS_2 (1<<3) |
107 | #define SHOW_STATS_X (1<<4) | | 110 | #define SHOW_STATS_X (1<<4) |
108 | #define SHOW_TOTALS (1<<7) | | 111 | #define SHOW_TOTALS (1<<7) |
109 | #define SHOW_STATS_ALL (SHOW_STATS_1 | SHOW_STATS_2 | SHOW_STATS_X) | | 112 | #define SHOW_STATS_ALL (SHOW_STATS_1 | SHOW_STATS_2 | SHOW_STATS_X) |
110 | | | 113 | |
111 | static void cpustats(void); | | 114 | static void cpustats(void); |
112 | static void drive_stats(double); | | 115 | static void drive_stats(double); |
113 | static void drive_stats2(double); | | 116 | static void drive_stats2(double); |
114 | static void drive_statsx(double); | | 117 | static void drive_statsx(double); |
| @@ -329,27 +332,29 @@ drive_stats(double etime) | | | @@ -329,27 +332,29 @@ drive_stats(double etime) |
329 | (void)printf(" %4.0f", | | 332 | (void)printf(" %4.0f", |
330 | (cur.rxfer[dn] + cur.wxfer[dn]) / etime); | | 333 | (cur.rxfer[dn] + cur.wxfer[dn]) / etime); |
331 | | | 334 | |
332 | /* time busy in drive activity */ | | 335 | /* time busy in drive activity */ |
333 | atime = (double)cur.time[dn].tv_sec + | | 336 | atime = (double)cur.time[dn].tv_sec + |
334 | ((double)cur.time[dn].tv_usec / (double)1000000); | | 337 | ((double)cur.time[dn].tv_usec / (double)1000000); |
335 | | | 338 | |
336 | /* Megabytes per second. */ | | 339 | /* Megabytes per second. */ |
337 | if (atime != 0.0) | | 340 | if (atime != 0.0) |
338 | mbps = (cur.rbytes[dn] + cur.wbytes[dn]) / | | 341 | mbps = (cur.rbytes[dn] + cur.wbytes[dn]) / |
339 | (double)(1024 * 1024); | | 342 | (double)(1024 * 1024); |
340 | else | | 343 | else |
341 | mbps = 0; | | 344 | mbps = 0; |
342 | (void)printf(" %5.2f ", mbps / etime); | | 345 | mbps /= etime; |
| | | 346 | (void)printf(" %5.*f ", |
| | | 347 | MAX(0,3-(int)floor(log10(fabs(fmax(1.0,mbps))))), mbps); |
343 | } | | 348 | } |
344 | } | | 349 | } |
345 | | | 350 | |
346 | static void | | 351 | static void |
347 | drive_stats2(double etime) | | 352 | drive_stats2(double etime) |
348 | { | | 353 | { |
349 | size_t dn; | | 354 | size_t dn; |
350 | double atime; | | 355 | double atime; |
351 | | | 356 | |
352 | for (dn = 0; dn < ndrive; ++dn) { | | 357 | for (dn = 0; dn < ndrive; ++dn) { |
353 | if (!cur.select[dn]) | | 358 | if (!cur.select[dn]) |
354 | continue; | | 359 | continue; |
355 | | | 360 | |