]> granicus.if.org Git - sysstat/commitdiff
Option -y added to iostat.
authorseb <seb@kluane.home>
Tue, 27 Nov 2012 20:23:03 +0000 (21:23 +0100)
committerseb <seb@kluane.home>
Tue, 27 Nov 2012 20:23:03 +0000 (21:23 +0100)
This option tells iostat to not display its first report with statistics
since system boot.
Courtesy Peter Schiffer from RedHat.

Mail from Peter Schiffer 20/11/2012 (pschiffe@redhat.com):

I want to talk to you about one feature of iostat command. When you ran
iostat without any arguments, it prints statistics since boot. This is
OK, and, for example, mpstat is doing the same. However, when you run
let's say iostat 1 5, the first report displays statistics since boot.
This can be a problem in numerous situations. Well, I am not sure when
this behavior is beneficial and usually this first report is removed by
some kind of post-processing. When compared to mpstat, the first report
is skipped and it waits to the next report. And I think this is the
default behavior for all other sysstat tools.

Now, I was wondering about how to make it better. I don't think that it
would be wise to change default behavior - that could break things.
But I was thinking more about some new option which would make iostat
skip the first since boot report.

What do you think about it?

CHANGES
iostat.c
iostat.h
man/iostat.in

diff --git a/CHANGES b/CHANGES
index 4cc5e2871cf6ff1f8bbbec92eb7629a4a416d30e..010020c697212d31623d67f1b4f4af3a4c9daa46 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,8 +1,12 @@
 Changes:
 
 xxxx/xx/xx: Version 10.1.3 - Sebastien Godard (sysstat <at> orange.fr)
+       * [Peter Schiffer]: Added option -y to iostat. This option
+         prevents iostat from displaying its first report with
+         statistics since system boot.
        * Fixed DTD document: If computer has run all day without
          restart, XML output file from sadf -x has no boot elements.
+       * iostat manual page updated.
 
 2012/10/06: Version 10.1.2 - Sebastien Godard (sysstat <at> orange.fr)
        * New field added to sar -u and mpstat: %gnice (time spent
index d9d281262e07140d6294b29cdb087be2aba11811..935f72acd2be8d7acfb78a55929d1ab38df4f7cc 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -85,13 +85,13 @@ void usage(char *progname)
                progname);
 #ifdef DEBUG
        fprintf(stderr, _("Options are:\n"
-                         "[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -z ]\n"
+                         "[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]\n"
                          "[ -j { ID | LABEL | PATH | UUID | ... } ]\n"
                          "[ [ -T ] -g <group_name> ] [ -p [ <device> [,...] | ALL ] ]\n"
                          "[ <device> [...] | ALL ] [ --debuginfo ]\n"));
 #else
        fprintf(stderr, _("Options are:\n"
-                         "[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -z ]\n"
+                         "[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]\n"
                          "[ -j { ID | LABEL | PATH | UUID | ... } ]\n"
                          "[ [ -T ] -g <group_name> ] [ -p [ <device> [,...] | ALL ] ]\n"
                          "[ <device> [...] | ALL ]\n"));
@@ -1205,6 +1205,12 @@ void write_stats(int curr, struct tm *rectime)
 void rw_io_stat_loop(long int count, struct tm *rectime)
 {
        int curr = 1;
+       int skip = 0;
+       
+       /* Should we skip first report? */
+       if (DISPLAY_OMIT_SINCE_BOOT(flags) && interval > 0) {
+               skip = 1;
+       }
 
        /* Don't buffer data if redirected to a pipe */
        setbuf(stdout, NULL);
@@ -1261,12 +1267,19 @@ void rw_io_stat_loop(long int count, struct tm *rectime)
                /* Get time */
                get_localtime(rectime, 0);
 
-               /* Print results */
-               write_stats(curr, rectime);
-
-               if (count > 0) {
-                       count--;
+               /* Check whether we should skip first report */
+               if (!skip) {
+                       /* Print results */
+                       write_stats(curr, rectime);
+                       
+                       if (count > 0) {
+                               count--;
+                       }
                }
+               else {
+                       skip = 0;
+               }
+
                if (count) {
                        curr ^= 1;
                        pause();
@@ -1458,6 +1471,11 @@ int main(int argc, char **argv)
                                        /* Display extended stats */
                                        flags |= I_D_EXTENDED;
                                        break;
+
+                               case 'y':
+                                       /* Don't display stats since system restart */
+                                       flags |= I_D_OMIT_SINCE_BOOT;
+                                       break;
                                        
                                case 'z':
                                        /* Omit output for devices with no activity */
index e01f058742a17c2c5057ec4b3cf6fb38efd5a1bd..2ad3e96c4607e733839e11aee6c63e44509fe2f7 100644 (file)
--- a/iostat.h
+++ b/iostat.h
@@ -23,7 +23,7 @@
 #define I_F_HAS_DISKSTATS      0x00800
 #define I_D_HUMAN_READ         0x01000
 #define I_D_PERSIST_NAME       0x02000
-/* Unused                      0x04000 */
+#define I_D_OMIT_SINCE_BOOT    0x04000
 /* Unused                      0x08000 */
 #define I_D_DEVMAP_NAME                0x10000
 #define I_D_ISO                        0x20000
@@ -44,6 +44,7 @@
 #define HAS_DISKSTATS(m)               (((m) & I_F_HAS_DISKSTATS)    == I_F_HAS_DISKSTATS)
 #define DISPLAY_HUMAN_READ(m)          (((m) & I_D_HUMAN_READ)       == I_D_HUMAN_READ)
 #define DISPLAY_PERSIST_NAME_I(m)      (((m) & I_D_PERSIST_NAME)     == I_D_PERSIST_NAME)
+#define DISPLAY_OMIT_SINCE_BOOT(m)     (((m) & I_D_OMIT_SINCE_BOOT)  == I_D_OMIT_SINCE_BOOT)
 #define DISPLAY_DEVMAP_NAME(m)         (((m) & I_D_DEVMAP_NAME)      == I_D_DEVMAP_NAME)
 #define DISPLAY_ISO(m)                 (((m) & I_D_ISO)              == I_D_ISO)
 #define DISPLAY_GROUP_TOTAL_ONLY(m)    (((m) & I_D_GROUP_TOTAL_ONLY) == I_D_GROUP_TOTAL_ONLY)
index 415271d3beae9f8120fb08e8ae975c85e84e2490..bcc694dff249de0dcf221958c05c3dbf2172e321 100644 (file)
@@ -1,10 +1,10 @@
-.TH IOSTAT 1 "JULY 2012" Linux "Linux User's Manual" -*- nroff -*-
+.TH IOSTAT 1 "NOVEMBER 2012" Linux "Linux User's Manual" -*- nroff -*-
 .SH NAME
 iostat \- Report Central Processing Unit (CPU) statistics and input/output
 statistics for devices and partitions.
 .SH SYNOPSIS
 .ie 'yes'@WITH_DEBUG@' \{
-.B iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -z ]
+.B iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]
 .B [ -j { ID | LABEL | PATH | UUID | ... } ]
 .B [ [ -T ] -g
 .I group_name
@@ -19,7 +19,7 @@ statistics for devices and partitions.
 .B ] ]
 .\}
 .el \{
-.B iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -z ]
+.B iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]
 .B [ -j { ID | LABEL | PATH | UUID | ... } ]
 .B [ [ -T ] -g
 .I group_name
@@ -47,7 +47,10 @@ the input/output load between physical disks.
 The first report generated by the
 .B iostat
 command provides statistics
-concerning the time since the system was booted. Each subsequent report
+concerning the time since the system was booted, unless the
+.B -y
+option is used (in this case, this first report is omitted).
+Each subsequent report
 covers the time since the previous report. All statistics are reported
 each time the iostat command is run. The report consists of a
 CPU header row followed by a row of
@@ -60,7 +63,10 @@ The
 .I interval
 parameter specifies the amount of time in seconds between
 each report. The first report contains statistics for the time since
-system startup (boot). Each subsequent report contains statistics
+system startup (boot), unless the
+.B -y
+option is used (in this case, this report is omitted).
+Each subsequent report contains statistics
 collected during the interval since the previous report. The
 .I count
 parameter can be specified in conjunction with the
@@ -326,6 +332,9 @@ on the value of the S_TIME_FORMAT environment variable (see below).
 Print version number then exit.
 .IP -x
 Display extended statistics.
+.IP -y
+Omit first report with statistics since system boot, if displaying
+multiple records at given interval.
 .IP -z
 Tell iostat to omit output for any devices for which there was no activity
 during the sample period.