Hi,

the following patch adds a new flag to iostat(8) to show the read and
write transfers per second, similiar to the iostat view of systat(1).

Though I had a hard time formulating the man page bits. This is how it
looks like:

$ iostat -x -w1 wd0
                   wd0 
  KB/t rt/s wt/s  MB/s 
 19.00  135 2021 39.99 
 21.84  155  978 24.18 
 22.57   62  346  8.99

Or for multiple disks:

$ iostat -x -w 1  
                   wd0                    sd0                    sd1 
  KB/t rt/s wt/s  MB/s   KB/t rt/s wt/s  MB/s   KB/t rt/s wt/s  MB/s 
 19.62    1    5  0.12  32.10    0    0  0.01   0.50    0    0  0.00 
  0.00    0    0  0.00   0.00    0    0  0.00   0.00    0    0  0.00 

Together w/ CPU stats:

$ iostat -Cx -w 1 wd0
                   wd0             cpu
  KB/t rt/s wt/s  MB/s  us ni sy in id
 19.61    1    5  0.12   7  0  4  0 89
  0.00    0    0  0.00   0  0  3  0 97
  0.00    0    0  0.00   0  0  3  0 97


Frank.

Index: iostat.c
===================================================================
RCS file: /cvs/src/usr.sbin/iostat/iostat.c,v
retrieving revision 1.28
diff -u -r1.28 iostat.c
--- iostat.c    26 Jun 2012 21:37:59 -0000      1.28
+++ iostat.c    10 Sep 2012 20:33:27 -0000
@@ -94,6 +94,7 @@
 #define SHOW_TTY       0x0002
 #define SHOW_STATS_1   0x0004
 #define SHOW_STATS_2   0x0008
+#define SHOW_STATS_3   0x0010
 #define SHOW_TOTALS    0x0080
 
 static void cpustats(void);
@@ -115,7 +116,7 @@
        int ch, hdrcnt;
        struct timeval  tv;
 
-       while ((ch = getopt(argc, argv, "Cc:dDIM:N:Tw:")) != -1)
+       while ((ch = getopt(argc, argv, "Cc:dDIM:N:Tw:x")) != -1)
                switch(ch) {
                case 'c':
                        if ((reps = atoi(optarg)) <= 0)
@@ -146,6 +147,9 @@
                        if ((interval = atoi(optarg)) <= 0)
                                errx(1, "interval <= 0.");
                        break;
+               case 'x':
+                       todo |= SHOW_STATS_3;
+                       break;
                case '?':
                default:
                        usage();
@@ -153,7 +157,7 @@
        argc -= optind;
        argv += optind;
 
-       if (!ISSET(todo, SHOW_CPU | SHOW_TTY | SHOW_STATS_1 | SHOW_STATS_2))
+       if (!ISSET(todo, SHOW_CPU | SHOW_TTY | SHOW_STATS_1 | SHOW_STATS_2 | 
SHOW_STATS_3))
                todo |= SHOW_CPU | SHOW_TTY | SHOW_STATS_1;
 
        dkinit(0);
@@ -210,13 +214,18 @@
        if (ISSET(todo, SHOW_STATS_1))
        for (i = 0; i < dk_ndrive; i++)
                if (cur.dk_select[i])
-                       (void)printf(" %14.14s ", cur.dk_name[i]);
+                       (void)printf(" %16.16s ", cur.dk_name[i]);
 
        if (ISSET(todo, SHOW_STATS_2))
        for (i = 0; i < dk_ndrive; i++)
                if (cur.dk_select[i])
                        (void)printf(" %13.13s ", cur.dk_name[i]);
 
+       if (ISSET(todo, SHOW_STATS_3))
+       for (i = 0; i < dk_ndrive; i++)
+               if (cur.dk_select[i])
+                       (void)printf(" %21.21s ", cur.dk_name[i]);
+
        if (ISSET(todo, SHOW_CPU))
                (void)printf("            cpu");
        printf("\n");
@@ -238,6 +247,11 @@
                if (cur.dk_select[i]) {
                        (void)printf("   KB xfr time ");
                }
+       if (ISSET(todo, SHOW_STATS_3))
+       for (i = 0; i < dk_ndrive; i++)
+               if (cur.dk_select[i]) {
+                       (void)printf("  KB/t rt/s wt/s  MB/s ");
+               }
        if (ISSET(todo, SHOW_CPU))
                (void)printf(" us ni sy in id");
        printf("\n");
@@ -306,6 +320,43 @@
 }
 
 static void
+disk_stats3(double etime)
+{
+       int dn;
+       double atime, mbps;
+
+       for (dn = 0; dn < dk_ndrive; ++dn) {
+               if (!cur.dk_select[dn])
+                       continue;
+
+               /* average Kbytes per transfer. */
+               if (cur.dk_rxfer[dn] + cur.dk_wxfer[dn])
+                       mbps = ((cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) /
+                           (1024.0)) / (cur.dk_rxfer[dn] + cur.dk_wxfer[dn]);
+               else
+                       mbps = 0.0;
+
+               (void)printf(" %5.2f", mbps);
+
+               /* average transfers per second. */
+               (void)printf(" %4.0f", cur.dk_rxfer[dn] / etime);
+               (void)printf(" %4.0f", cur.dk_wxfer[dn] / etime);
+
+               /* time busy in disk activity */
+               atime = (double)cur.dk_time[dn].tv_sec +
+                       ((double)cur.dk_time[dn].tv_usec / (double)1000000);
+
+               /* Megabytes per second. */
+               if (atime != 0.0)
+                       mbps = (cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) /
+                           (double)(1024 * 1024);
+               else
+                       mbps = 0;
+               (void)printf(" %5.2f ", mbps / etime);
+       }
+}
+
+static void
 cpustats(void)
 {
        int state;
@@ -324,7 +375,7 @@
 usage(void)
 {
        (void)fprintf(stderr,
-"usage: iostat [-CDdIT] [-c count] [-M core] [-N system] [-w wait] 
[drives]\n");
+"usage: iostat [-CDdITx] [-c count] [-M core] [-N system] [-w wait] 
[drives]\n");
        exit(1);
 }
 
@@ -358,6 +409,9 @@
 
        if (ISSET(todo, SHOW_STATS_2))
                disk_stats2(etime);
+
+       if (ISSET(todo, SHOW_STATS_3))
+               disk_stats3(etime);
 
        if (ISSET(todo, SHOW_CPU))
                cpustats();
Index: iostat.8
===================================================================
RCS file: /cvs/src/usr.sbin/iostat/iostat.8,v
retrieving revision 1.25
diff -u -r1.25 iostat.8
--- iostat.8    10 Feb 2011 14:52:35 -0000      1.25
+++ iostat.8    10 Sep 2012 20:33:27 -0000
@@ -38,7 +38,7 @@
 .Nd report I/O statistics
 .Sh SYNOPSIS
 .Nm iostat
-.Op Fl CDdIT
+.Op Fl CDdITx
 .Op Fl c Ar count
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -119,6 +119,11 @@
 option,
 .Nm
 will display output until it is interrupted.
+.It Fl x
+Similiar to
+.Fl d
+but shows the number of read and write transfers per second instead of
+the sum of all transfers per second.
 .El
 .Pp
 .Nm
@@ -149,6 +154,19 @@
 Transfers per second
 .It MB/s
 Megabytes transferred per second
+.Pp
+.El
+The extended disk statistics (selected with
+.Fl x ) ,
+displays the same values as above but splits up
+.Em t/s
+into two values, namely:
+.Pp
+.Bl -tag -width indent -compact
+.It rt/s
+Read transfers per second
+.It wt/s
+Write transfers per second
 .Pp
 .El
 The alternate display format, (selected with

-- 
Frank Brodbeck <[email protected]>

Reply via email to