]> granicus.if.org Git - sysstat/commitdiff
sar: Add discard I/O metrics to "sar -b" output
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 9 Dec 2018 08:52:57 +0000 (09:52 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 9 Dec 2018 08:52:57 +0000 (09:52 +0100)
"sar -b" statistics are calculated as the sum of individual
statistics for each whole device in the system. Since discard I/Os are
now separated from writes in the kernel, take them into account when
calculating "sar -b" statistics.
New fields are added to "sar -b" output: dtps and bdscd/s.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
pr_stats.c
rd_stats.c
rd_stats.h

index 9a01449c2506ea7e28d3b50584b40bec4d93d6fa..32862206f8ed1e59deb60a2dbf9db7022e5c5537 100644 (file)
@@ -307,7 +307,7 @@ struct activity io_act = {
        .f_print_avg    = print_io_stats,
 #endif
 #if defined(SOURCE_SAR) || defined(SOURCE_SADF)
-       .hdr_line       = "tps;rtps;wtps;bread/s;bwrtn/s",
+       .hdr_line       = "tps;rtps;wtps;dtps;bread/s;bwrtn/s;bdscd/s",
 #endif
        .gtypes_nr      = {STATS_IO_ULL, STATS_IO_UL, STATS_IO_U},
        .ftypes_nr      = {0, 0, 0},
index 9353fb3296f39e2cdd2006a3a7aae7ce25972627..af5cff087a870682637fae7b520f1d0d784a9ae8 100644 (file)
@@ -454,17 +454,21 @@ __print_funct_t print_io_stats(struct activity *a, int prev, int curr,
         * We display 0.0 in this case though we should rather tell
         * the user that the value cannot be calculated here.
         */
-       cprintf_f(NO_UNIT, 5, 9, 2,
+       cprintf_f(NO_UNIT, 7, 9, 2,
                  sic->dk_drive < sip->dk_drive ? 0.0 :
                  S_VALUE(sip->dk_drive, sic->dk_drive, itv),
                  sic->dk_drive_rio < sip->dk_drive_rio ? 0.0 :
                  S_VALUE(sip->dk_drive_rio, sic->dk_drive_rio, itv),
                  sic->dk_drive_wio < sip->dk_drive_wio ? 0.0 :
                  S_VALUE(sip->dk_drive_wio, sic->dk_drive_wio, itv),
+                 sic->dk_drive_dio < sip->dk_drive_dio ? 0.0 :
+                 S_VALUE(sip->dk_drive_dio, sic->dk_drive_dio, itv),
                  sic->dk_drive_rblk < sip->dk_drive_rblk ? 0.0 :
                  S_VALUE(sip->dk_drive_rblk, sic->dk_drive_rblk, itv),
                  sic->dk_drive_wblk < sip->dk_drive_wblk ? 0.0 :
-                 S_VALUE(sip->dk_drive_wblk, sic->dk_drive_wblk, itv));
+                 S_VALUE(sip->dk_drive_wblk, sic->dk_drive_wblk, itv),
+                 sic->dk_drive_dblk < sip->dk_drive_dblk ? 0.0 :
+                 S_VALUE(sip->dk_drive_dblk, sic->dk_drive_dblk, itv));
        printf("\n");
 }
 
index 9b011b44beff6413a8fd135c393f2e147da4c9e1..1d4a73841e67a5382536343914b7baab6debbd60 100644 (file)
@@ -722,27 +722,42 @@ __nr_t read_diskstats_io(struct stats_io *st_io)
        char line[1024];
        char dev_name[MAX_NAME_LEN];
        unsigned int major, minor;
-       unsigned long rd_ios, wr_ios, rd_sec, wr_sec;
+       unsigned long rd_ios, wr_ios, dc_ios;
+       unsigned long rd_sec, wr_sec, dc_sec;
 
        if ((fp = fopen(DISKSTATS, "r")) == NULL)
                return 0;
 
        while (fgets(line, sizeof(line), fp) != NULL) {
 
-               if (sscanf(line, "%u %u %s %lu %*u %lu %*u %lu %*u %lu",
+               /* Discard I/O stats may be not available */
+               dc_ios = dc_sec = 0;
+
+               if (sscanf(line,
+                          "%u %u %s "
+                          "%lu %*u %lu %*u "
+                          "%lu %*u %lu %*u "
+                          "%*u %*u %*u "
+                          "%lu %*u %lu",
                           &major, &minor, dev_name,
-                          &rd_ios, &rd_sec, &wr_ios, &wr_sec) == 7) {
+                          &rd_ios, &rd_sec,
+                          &wr_ios, &wr_sec,
+                          &dc_ios, &dc_sec) >= 7) {
 
                        if (is_device(dev_name, IGNORE_VIRTUAL_DEVICES)) {
                                /*
                                 * OK: It's a (real) device and not a partition.
                                 * Note: Structure should have been initialized first!
                                 */
-                               st_io->dk_drive      += (unsigned long long) rd_ios + (unsigned long long) wr_ios;
+                               st_io->dk_drive      += (unsigned long long) rd_ios +
+                                                       (unsigned long long) wr_ios +
+                                                       (unsigned long long) dc_ios;
                                st_io->dk_drive_rio  += rd_ios;
                                st_io->dk_drive_rblk += rd_sec;
                                st_io->dk_drive_wio  += wr_ios;
                                st_io->dk_drive_wblk += wr_sec;
+                               st_io->dk_drive_dio  += dc_ios;
+                               st_io->dk_drive_dblk += dc_sec;
                        }
                }
        }
index 07b853c4f790bdf18e9051d8fc2975217be8c4ff..d49afadea3769876ad3ed19e6a9a753d3fb35a57 100644 (file)
@@ -179,10 +179,12 @@ struct stats_io {
        unsigned long long dk_drive_wio;
        unsigned long long dk_drive_rblk;
        unsigned long long dk_drive_wblk;
+       unsigned long long dk_drive_dio;
+       unsigned long long dk_drive_dblk;
 };
 
 #define STATS_IO_SIZE  (sizeof(struct stats_io))
-#define STATS_IO_ULL   5
+#define STATS_IO_ULL   7
 #define STATS_IO_UL    0
 #define STATS_IO_U     0