From 93ed25697b5a59574bb6e8b91f39e89d197c03d2 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 9 Dec 2018 09:52:57 +0100 Subject: [PATCH] sar: Add discard I/O metrics to "sar -b" output "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 --- activity.c | 2 +- pr_stats.c | 8 ++++++-- rd_stats.c | 23 +++++++++++++++++++---- rd_stats.h | 4 +++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/activity.c b/activity.c index 9a01449..3286220 100644 --- a/activity.c +++ b/activity.c @@ -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}, diff --git a/pr_stats.c b/pr_stats.c index 9353fb3..af5cff0 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -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"); } diff --git a/rd_stats.c b/rd_stats.c index 9b011b4..1d4a738 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -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; } } } diff --git a/rd_stats.h b/rd_stats.h index 07b853c..d49afad 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -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 -- 2.40.0