From 901d9753c8a1a0b172ecc453ee71d176276fcfde Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 13 May 2018 15:56:39 +0200 Subject: [PATCH] sar: "--iface=" option: Small optimization Don't look for previous statistics sample if current network device will not be displayed. Signed-off-by: Sebastien GODARD --- pr_stats.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pr_stats.c b/pr_stats.c index a0f106d..8499d35 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -1134,6 +1134,14 @@ __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr, for (i = 0; i < a->nr[curr]; i++) { sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); + if (dlist_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlist_idx, sndc->interface, + A_NET_DEV)) + /* Device not found */ + continue; + } + if (!WANT_SINCE_BOOT(flags)) { j = check_net_dev_reg(a, curr, prev, i); } @@ -1154,14 +1162,6 @@ __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr, if (DISPLAY_ZERO_OMIT(flags) && !memcmp(sndp, sndc, STATS_NET_DEV_SIZE2CMP)) continue; - if (dlist_idx) { - /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlist_idx, sndc->interface, - A_NET_DEV)) - /* Device not found */ - continue; - } - printf("%-11s", timestamp[curr]); if (!DISPLAY_HUMAN_READ(flags)) { @@ -1215,6 +1215,14 @@ __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr, for (i = 0; i < a->nr[curr]; i++) { snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); + if (dlist_idx) { + /* A list of devices has been entered on the command line */ + if (!search_sa_dlist(st_dev_list, dlist_idx, snedc->interface, + A_NET_DEV)) + /* Device not found */ + continue; + } + if (!WANT_SINCE_BOOT(flags)) { j = check_net_edev_reg(a, curr, prev, i); } @@ -1235,14 +1243,6 @@ __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr, if (DISPLAY_ZERO_OMIT(flags) && !memcmp(snedp, snedc, STATS_NET_EDEV_SIZE2CMP)) continue; - if (dlist_idx) { - /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlist_idx, snedc->interface, - A_NET_DEV)) - /* Device not found */ - continue; - } - printf("%-11s", timestamp[curr]); if (!DISPLAY_HUMAN_READ(flags)) { -- 2.40.0