]> granicus.if.org Git - sysstat/commitdiff
sadf: Allow user to select block devices to display
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 16 May 2018 12:50:29 +0000 (14:50 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 16 May 2018 12:50:29 +0000 (14:50 +0200)
Add new option "--dev=<dev_list>". 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 <sysstat@users.noreply.github.com>
json_stats.c
raw_stats.c
rndr_stats.c
sadf.c
svg_stats.c
xml_stats.c

index 20f2de6a85d88a84dec74093d2687aa7666a10e5..aa3ed6184c8d36b0a15c85555244796ee5074a77 100644 (file)
@@ -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");
                }
index 4e253eb6f03c6d32974cbcd963cea43594fa8aba..2e7bfdbc52fc79a390a511b86ef6a917e37cfe6c 100644 (file)
@@ -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);
index 237fd3b8e27b190a67f9621524101a666ff8dbc6..1e5b4ad275feb56f4805f29ab31e01ebebef4726 100644 (file)
@@ -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 7e447aa349b85f51608c24c62b07d62610d82480..da9f7dc1a6a44530d60587db58cdbed8137be2e9 100644 (file)
--- 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 <opts> [,...] ] [ -P { <cpu> [,...] | ALL } ]\n"
-                         "[ --iface=<iface_list> ] [ -s [ <hh:mm[:ss]> ] ] [ -e [ <hh:mm[:ss]> ] ]\n"
+                         "[ --dev=<dev_list> ] [ --iface=<iface_list> ]\n"
+                         "[ -s [ <hh:mm[:ss]> ] ] [ -e [ <hh:mm[:ss]> ] ]\n"
                          "[ -- <sar_options> ]\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,
index cffeebab8b16ca9e016be067df2892ed7577957c..527d6733625f3372df56f7b5506298dfefb1244b 100644 (file)
@@ -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,
index c00afae63207458b0295d0c0e91b0691b3a7a249..399a583c4d7aeeaeb2e9c82d27fc858d538e9390 100644 (file)
@@ -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, "<disk-device dev=\"%s\" "
                        "tps=\"%.2f\" "
                        "rd_sec=\"%.2f\" "