From: Sebastien GODARD Date: Sun, 20 May 2018 14:26:28 +0000 (+0200) Subject: sar: Allow user to select filesystems to display X-Git-Tag: v11.7.4~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3118a992c857999fa868c768663eb304cab51d5;p=sysstat sar: Allow user to select filesystems to display Add new option "--fs=" to allow the user to specify which filesystems to display. This option is to be used with option -F. Sample output: $ sar -F Linux 4.4.14-200.fc22.x86_64 (home) 05/20/18 _x86_64_ (8 CPU) 16:15:20 [...] %fsused %ufsused Ifree Iused %Iused FILESYSTEM 16:20:00 51.59 56.75 1673107 248253 12.92 /dev/sda11 16:20:00 14.74 21.56 63602 398 0.62 /dev/sda5 16:20:00 1.87 6.96 19056634 145414 0.76 /dev/sda7 16:20:00 26.54 31.64 6341145 64999 1.01 /dev/sda8 16:20:00 5.31 10.39 19201270 778 0.00 /dev/sda6 [...] $ sar -F --fs=/dev/sda5,/dev/sda8 Linux 4.4.14-200.fc22.x86_64 (home) 05/20/18 _x86_64_ (8 CPU) 16:15:20 [...] %fsused %ufsused Ifree Iused %Iused FILESYSTEM 16:20:00 14.74 21.56 63602 398 0.62 /dev/sda5 16:20:00 26.54 31.64 6341145 64999 1.01 /dev/sda8 [...] Signed-off-by: Sebastien GODARD --- diff --git a/pr_stats.c b/pr_stats.c index a30b949..913d2f8 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -43,8 +43,10 @@ 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 struct sa_dlist *st_fs_list; extern int dlst_iface_idx; extern int dlst_dev_idx; +extern int dlst_fs_idx; /* *************************************************************************** @@ -2748,6 +2750,14 @@ __print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int cu for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); + if (dlst_fs_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_fs_list, dlst_fs_idx, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + /* Device not found */ + continue; + } + found = FALSE; if (DISPLAY_ZERO_OMIT(flags) && !dispavg) { diff --git a/sar.c b/sar.c index 582f603..589c6c6 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, *st_dev_list = NULL; -int dlst_iface_idx = 0, dlst_dev_idx = 0; +struct sa_dlist *st_iface_list = NULL, *st_dev_list = NULL, *st_fs_list = NULL; +int dlst_iface_idx = 0, dlst_dev_idx = 0, dlst_fs_idx = 0; struct tm rectime; @@ -124,8 +124,8 @@ 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 } ] [ --dev= ] [ --iface= ]\n" - "[ --help ] [ --human ] [ --sadc ]\n" + "[ --dev= ] [ --fs= ] [ --iface= ]\n" + "[ --dec={ 0 | 1 | 2 } ] [ --help ] [ --human ] [ --sadc ]\n" "[ -j { ID | LABEL | PATH | UUID | ... } ]\n" "[ -f [ ] | -o [ ] | -[0-9]+ ]\n" "[ -i ] [ -s [ ] ] [ -e [ ] ]\n")); @@ -1282,6 +1282,12 @@ int main(int argc, char **argv) &dlst_dev_idx, &opt, 6); } + else if (!strncmp(argv[opt], "--fs=", 5)) { + /* Parse devices entered on the command line */ + parse_sa_devices(argv[opt], &st_fs_list, + &dlst_fs_idx, &opt, 5); + } + else if (!strncmp(argv[opt], "--iface=", 8)) { /* Parse devices entered on the command line */ parse_sa_devices(argv[opt], &st_iface_list, @@ -1518,12 +1524,6 @@ int main(int argc, char **argv) /* Free stuctures and activity bitmaps */ free_bitmaps(act); free_structures(act); - if (st_iface_list) { - free(st_iface_list); - } - if (st_dev_list) { - free(st_dev_list); - } return 0; } @@ -1648,12 +1648,6 @@ int main(int argc, char **argv) /* Free structures and activity bitmaps */ free_bitmaps(act); free_structures(act); - if (st_iface_list) { - free(st_iface_list); - } - if (st_dev_list) { - free(st_dev_list); - } return 0; }