From fd854260ed7407b87ffd2712847edd9e10901987 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 16 May 2018 14:50:29 +0200 Subject: [PATCH] sadf: Allow user to select block devices to display Add new option "--dev=". It has the same meaning as for sar. This may be especially useful for SVG output for which it is difficult to "grep" a particular device. Using this new option makes it possible for the user to draw graphs only for the desired block device(s) and not for all of them. Signed-off-by: Sebastien GODARD --- json_stats.c | 15 ++++++++++++--- raw_stats.c | 39 ++++++++++++++++++++++++--------------- rndr_stats.c | 15 ++++++++++++--- sadf.c | 13 ++++++++++--- svg_stats.c | 9 +++++++++ xml_stats.c | 15 ++++++++++++--- 6 files changed, 79 insertions(+), 27 deletions(-) diff --git a/json_stats.c b/json_stats.c index 20f2de6..aa3ed61 100644 --- a/json_stats.c +++ b/json_stats.c @@ -38,7 +38,9 @@ extern unsigned int flags; extern unsigned int dm_major; extern struct sa_dlist *st_iface_list; +extern struct sa_dlist *st_dev_list; extern int dlst_iface_idx; +extern int dlst_dev_idx; /* *************************************************************************** @@ -729,9 +731,6 @@ __print_funct_t json_print_disk_stats(struct activity *a, int curr, int tab, sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize); } - /* Compute extended statistics values */ - compute_ext_disk_stats(sdc, sdp, itv, &xds); - dev_name = NULL; persist_dev_name = NULL; @@ -753,6 +752,16 @@ __print_funct_t json_print_disk_stats(struct activity *a, int curr, int tab, } } + if (dlst_dev_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + /* Device not found */ + continue; + } + + /* Compute extended statistics values */ + compute_ext_disk_stats(sdc, sdp, itv, &xds); + if (sep) { printf(",\n"); } diff --git a/raw_stats.c b/raw_stats.c index 4e253eb..2e7bfdb 100644 --- a/raw_stats.c +++ b/raw_stats.c @@ -31,7 +31,9 @@ extern unsigned int flags; extern unsigned int dm_major; extern struct sa_dlist *st_iface_list; +extern struct sa_dlist *st_dev_list; extern int dlst_iface_idx; +extern int dlst_dev_idx; /* *************************************************************************** @@ -530,21 +532,6 @@ __print_funct_t raw_print_disk_stats(struct activity *a, char *timestr, int curr sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize); - printf("%s; major; %u; minor; %u; %s", - timestr, sdc->major, sdc->minor, pfield(a->hdr_line, FIRST)); - - j = check_disk_reg(a, curr, !curr, i); - if (j < 0) { - /* This is a newly registered interface. Previous stats are zero */ - sdp = &sdpzero; - if (DISPLAY_DEBUG_MODE(flags)) { - printf(" [%s]", j == -1 ? "NEW" : "BCK"); - } - } - else { - sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize); - } - dev_name = NULL; persist_dev_name = NULL; @@ -566,6 +553,28 @@ __print_funct_t raw_print_disk_stats(struct activity *a, char *timestr, int curr } } + if (dlst_dev_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + /* Device not found */ + continue; + } + + printf("%s; major; %u; minor; %u; %s", + timestr, sdc->major, sdc->minor, pfield(a->hdr_line, FIRST)); + + j = check_disk_reg(a, curr, !curr, i); + if (j < 0) { + /* This is a newly registered interface. Previous stats are zero */ + sdp = &sdpzero; + if (DISPLAY_DEBUG_MODE(flags)) { + printf(" [%s]", j == -1 ? "NEW" : "BCK"); + } + } + else { + sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize); + } + printf("; %s;", dev_name); printf(" %s", pfield(NULL, 0)); pval(sdp->nr_ios, sdc->nr_ios); diff --git a/rndr_stats.c b/rndr_stats.c index 237fd3b..1e5b4ad 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -40,7 +40,9 @@ char *seps[] = {"\t", ";"}; extern unsigned int flags; extern unsigned int dm_major; extern struct sa_dlist *st_iface_list; +extern struct sa_dlist *st_dev_list; extern int dlst_iface_idx; +extern int dlst_dev_idx; /* *************************************************************************** @@ -1079,9 +1081,6 @@ __print_funct_t render_disk_stats(struct activity *a, int isdb, char *pre, sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize); } - /* Compute extended stats (service time, etc.) */ - compute_ext_disk_stats(sdc, sdp, itv, &xds); - dev_name = NULL; persist_dev_name = NULL; @@ -1103,6 +1102,16 @@ __print_funct_t render_disk_stats(struct activity *a, int isdb, char *pre, } } + if (dlst_dev_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + /* Device not found */ + continue; + } + + /* Compute extended stats (service time, etc.) */ + compute_ext_disk_stats(sdc, sdp, itv, &xds); + render(isdb, pre, PT_NOFLAG, "%s\ttps", "%s", cons(sv, dev_name, NULL), diff --git a/sadf.c b/sadf.c index 7e447aa..da9f7dc 100644 --- a/sadf.c +++ b/sadf.c @@ -78,8 +78,8 @@ struct tstamp tm_start, tm_end; char *args[MAX_ARGV_NR]; /* Devices entered on the command line */ -struct sa_dlist *st_iface_list = NULL; -int dlst_iface_idx = 0; +struct sa_dlist *st_iface_list = NULL, *st_dev_list = NULL; +int dlst_iface_idx = 0, dlst_dev_idx = 0; extern struct activity *act[]; extern struct report_format *fmt[]; @@ -101,7 +101,8 @@ void usage(char *progname) fprintf(stderr, _("Options are:\n" "[ -C ] [ -c | -d | -g | -j | -p | -r | -x ] [ -H ] [ -h ] [ -T | -t | -U ] [ -V ]\n" "[ -O [,...] ] [ -P { [,...] | ALL } ]\n" - "[ --iface= ] [ -s [ ] ] [ -e [ ] ]\n" + "[ --dev= ] [ --iface= ]\n" + "[ -s [ ] ] [ -e [ ] ]\n" "[ -- ]\n")); exit(1); } @@ -1425,6 +1426,12 @@ int main(int argc, char **argv) } } + else if (!strncmp(argv[opt], "--dev=", 6)) { + /* Parse devices entered on the command line */ + parse_sa_devices(argc, argv, &st_dev_list, + &dlst_dev_idx, &opt, 6); + } + else if (!strncmp(argv[opt], "--iface=", 8)) { /* Parse devices entered on the command line */ parse_sa_devices(argc, argv, &st_iface_list, diff --git a/svg_stats.c b/svg_stats.c index cffeeba..527d673 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -40,7 +40,9 @@ extern unsigned int flags; extern unsigned int dm_major; extern struct sa_dlist *st_iface_list; +extern struct sa_dlist *st_dev_list; extern int dlst_iface_idx; +extern int dlst_dev_idx; unsigned int svg_colors[] = {0x00cc00, 0xff00bf, 0x00ffff, 0xff0000, 0xe85f00, 0x0000ff, 0x006020, 0x7030a0, @@ -2253,6 +2255,13 @@ __print_funct_t svg_print_disk_stats(struct activity *a, int curr, int action, s } } + if (dlst_dev_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlst_dev_idx, item_name)) + /* Device not found */ + continue; + } + draw_activity_graphs(a->g_nr, g_type, title, g_title, item_name, group, spmin + pos, spmax + pos, out + pos, outsize + pos, diff --git a/xml_stats.c b/xml_stats.c index c00afae..399a583 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -38,7 +38,9 @@ extern unsigned int flags; extern unsigned int dm_major; extern struct sa_dlist *st_iface_list; +extern struct sa_dlist *st_dev_list; extern int dlst_iface_idx; +extern int dlst_dev_idx; /* *************************************************************************** @@ -714,9 +716,6 @@ __print_funct_t xml_print_disk_stats(struct activity *a, int curr, int tab, sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize); } - /* Compute extended statistics values */ - compute_ext_disk_stats(sdc, sdp, itv, &xds); - dev_name = NULL; persist_dev_name = NULL; @@ -738,6 +737,16 @@ __print_funct_t xml_print_disk_stats(struct activity *a, int curr, int tab, } } + if (dlst_dev_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + /* Device not found */ + continue; + } + + /* Compute extended statistics values */ + compute_ext_disk_stats(sdc, sdp, itv, &xds); + xprintf(tab, "