From 27432c55b457e976e82f94090cdbdc781a95f373 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 16 May 2018 14:41:55 +0200 Subject: [PATCH] sar: Allow user to select block devices to display Add new option "--dev=" to allow the user to specify which block devices to display. This option is to be used with option -d. Sample output: $ sar -dp Linux 4.4.14-200.fc22.x86_64 (home) 05/12/18 _x86_64_ (8 CPU) 10:35:29 DEV tps rkB/s wkB/s areq-sz [...] 10:35:31 sda 17.00 142.00 14.00 9.18 10:35:31 sda1 0.00 0.00 0.00 0.00 10:35:31 sda2 0.00 0.00 0.00 0.00 10:35:31 sda3 0.00 0.00 0.00 0.00 10:35:31 sda4 0.00 0.00 0.00 0.00 10:35:31 sda5 0.00 0.00 0.00 0.00 10:35:31 sda6 0.00 0.00 0.00 0.00 10:35:31 sda7 0.00 0.00 0.00 0.00 10:35:31 sda8 15.50 142.00 4.00 9.42 10:35:31 sda9 0.00 0.00 0.00 0.00 10:35:31 sda10 0.00 0.00 0.00 0.00 10:35:31 sda11 1.50 0.00 10.00 6.67 [...] $ sar -dp --dev=sda,sda8 Linux 4.4.14-200.fc22.x86_64 (home) 05/12/18 _x86_64_ (8 CPU) 10:35:29 DEV tps rkB/s wkB/s areq-sz [...] 10:35:31 sda 17.00 142.00 14.00 9.18 10:35:31 sda8 15.50 142.00 4.00 9.42 [...] Signed-off-by: Sebastien GODARD --- pr_stats.c | 15 ++++++++++++--- sar.c | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/pr_stats.c b/pr_stats.c index 8015e41..a30b949 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -42,7 +42,9 @@ extern int dis; extern char timestamp[][TIMESTAMP_LEN]; extern unsigned long avg_count; extern struct sa_dlist *st_iface_list; +extern struct sa_dlist *st_dev_list; extern int dlst_iface_idx; +extern int dlst_dev_idx; /* *************************************************************************** @@ -1051,9 +1053,6 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, int curr, if (DISPLAY_ZERO_OMIT(flags) && !memcmp(sdp, sdc, STATS_DISK_SIZE)) continue; - /* Compute service time, etc. */ - compute_ext_disk_stats(sdc, sdp, itv, &xds); - dev_name = NULL; persist_dev_name = NULL; @@ -1075,6 +1074,16 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, 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; + } + + /* Compute service time, etc. */ + compute_ext_disk_stats(sdc, sdp, itv, &xds); + printf("%-11s", timestamp[curr]); if (!DISPLAY_HUMAN_READ(flags)) { diff --git a/sar.c b/sar.c index e4daf41..7029801 100644 --- a/sar.c +++ b/sar.c @@ -77,8 +77,8 @@ struct record_header record_hdr[3]; unsigned int id_seq[NR_ACT]; /* 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; struct tm rectime; @@ -124,7 +124,7 @@ void usage(char *progname) "[ -v ] [ -W ] [ -w ] [ -y ] [ -z ]\n" "[ -I { | SUM | ALL } ] [ -P { | ALL } ]\n" "[ -m { [,...] | ALL } ] [ -n { [,...] | ALL } ]\n" - "[ --dec={ 0 | 1 | 2 } ] [ --iface= ]\n" + "[ --dec={ 0 | 1 | 2 } ] [ --dev= ] [ --iface= ]\n" "[ --help ] [ --human ] [ --sadc ]\n" "[ -j { ID | LABEL | PATH | UUID | ... } ]\n" "[ -f [ ] | -o [ ] | -[0-9]+ ]\n" @@ -1276,6 +1276,12 @@ int main(int argc, char **argv) which_sadc(); } + 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, @@ -1515,6 +1521,9 @@ int main(int argc, char **argv) if (st_iface_list) { free(st_iface_list); } + if (st_dev_list) { + free(st_dev_list); + } return 0; } @@ -1642,6 +1651,9 @@ int main(int argc, char **argv) if (st_iface_list) { free(st_iface_list); } + if (st_dev_list) { + free(st_dev_list); + } return 0; } -- 2.40.0