From 600278927f5ac8a3b3493556ac763e155e1e94ee Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 28 Jun 2019 08:54:36 +0200 Subject: [PATCH] sar: Better handle the case when FB hosts are added to the system If a new Fibre Channel host is registered in the system, now display its statistics even for the interval during which it has been registered. In this case, its initial counters values are considered as 0. Signed-off-by: Sebastien GODARD --- json_stats.c | 10 +++++++--- pcp_stats.c | 10 +++++++--- pr_stats.c | 10 +++++++--- raw_stats.c | 13 ++++++++++--- rd_stats.c | 6 +++--- rndr_stats.c | 10 +++++++--- svg_stats.c | 9 ++++++--- xml_stats.c | 10 +++++++--- 8 files changed, 54 insertions(+), 24 deletions(-) diff --git a/json_stats.c b/json_stats.c index 1638abe..2b8a828 100644 --- a/json_stats.c +++ b/json_stats.c @@ -2237,12 +2237,14 @@ __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab, unsigned long long itv) { int i, j, j0, found; - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; int sep = FALSE; if (!IS_SELECTED(a->options) || (a->nr[curr] <= 0)) goto close_json_markup; + memset(&sfczero, 0, sizeof(struct stats_fchost)); + json_markup_network(tab, OPEN_JSON_MARKUP); tab++; @@ -2277,8 +2279,10 @@ __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab, while (j != j0); } - if (!found) - continue; + if (!found) { + /* This is a newly registered host */ + sfcp = &sfczero; + } if (sep) printf(",\n"); diff --git a/pcp_stats.c b/pcp_stats.c index 836ab7b..6d08479 100644 --- a/pcp_stats.c +++ b/pcp_stats.c @@ -2185,9 +2185,11 @@ __print_funct_t pcp_print_fchost_stats(struct activity *a, int curr, unsigned lo { #ifdef HAVE_PCP int i, j, j0, found; - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; char buf[64]; + memset(&sfczero, 0, sizeof(struct stats_fchost)); + for (i = 0; i < a->nr[curr]; i++) { found = FALSE; @@ -2217,8 +2219,10 @@ __print_funct_t pcp_print_fchost_stats(struct activity *a, int curr, unsigned lo while (j != j0); } - if (!found) - continue; + if (!found) { + /* This is a newly registered host */ + sfcp = &sfczero; + } snprintf(buf, sizeof(buf), "%f", S_VALUE(sfcp->f_rxframes, sfcc->f_rxframes, itv)); diff --git a/pr_stats.c b/pr_stats.c index 319630d..bb321ac 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -2879,7 +2879,9 @@ __print_funct_t print_fchost_stats(struct activity *a, int prev, int curr, unsigned long long itv) { int i, j, j0, found; - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; + + memset(&sfczero, 0, sizeof(struct stats_fchost)); if (dish) { print_hdr_line(timestamp[!curr], a, FIRST, -1, 9); @@ -2920,8 +2922,10 @@ __print_funct_t print_fchost_stats(struct activity *a, int prev, int curr, } } - if (!found) - continue; + if (!found) { + /* This is a newly registered host */ + sfcp = &sfczero; + } printf("%-11s", timestamp[curr]); cprintf_f(NO_UNIT, 4, 9, 2, diff --git a/raw_stats.c b/raw_stats.c index efa1f81..254227e 100644 --- a/raw_stats.c +++ b/raw_stats.c @@ -1534,7 +1534,9 @@ __print_funct_t raw_print_filesystem_stats(struct activity *a, char *timestr, in __print_funct_t raw_print_fchost_stats(struct activity *a, char *timestr, int curr) { int i, j, j0, found; - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; + + memset(&sfczero, 0, sizeof(struct stats_fchost)); for (i = 0; i < a->nr[curr]; i++) { @@ -1565,8 +1567,13 @@ __print_funct_t raw_print_fchost_stats(struct activity *a, char *timestr, int cu while (j != j0); } - if (!found) - continue; + if (!found) { + /* This is a newly registered host. Previous stats are zero */ + sfcp = &sfczero; + if (DISPLAY_DEBUG_MODE(flags)) { + printf(" [NEW]"); + } + } printf("%s; %s; %s;", timestr, pfield(a->hdr_line, FIRST), sfcc->fchost_name); printf(" %s", pfield(NULL, 0)); diff --git a/rd_stats.c b/rd_stats.c index 02a1d9a..68e2799 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -2596,14 +2596,14 @@ __nr_t read_fchost(struct stats_fchost *st_fc, __nr_t nr_alloc) unsigned long rx_frames, tx_frames, rx_words, tx_words; /* Each host, if present, will have its own hostX entry within SYSFS_FCHOST */ - if ((dir = opendir(SYSFS_FCHOST)) == NULL) + if ((dir = __opendir(SYSFS_FCHOST)) == NULL) return 0; /* No FC hosts */ /* * Read each of the counters via sysfs, where they are * returned as hex values (e.g. 0x72400). */ - while ((drd = readdir(dir)) != NULL) { + while ((drd = __readdir(dir)) != NULL) { rx_frames = tx_frames = rx_words = tx_words = 0; if (!strncmp(drd->d_name, "host", 4)) { @@ -2659,7 +2659,7 @@ __nr_t read_fchost(struct stats_fchost *st_fc, __nr_t nr_alloc) } } - closedir(dir); + __closedir(dir); return fch_read; } diff --git a/rndr_stats.c b/rndr_stats.c index 56cb5a2..1136c93 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -2999,7 +2999,9 @@ __print_funct_t render_fchost_stats(struct activity *a, int isdb, char *pre, int curr, unsigned long long itv) { int i, j, j0, found; - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; + + memset(&sfczero, 0, sizeof(struct stats_fchost)); for (i = 0; i < a->nr[curr]; i++) { @@ -3030,8 +3032,10 @@ __print_funct_t render_fchost_stats(struct activity *a, int isdb, char *pre, while (j != j0); } - if (!found) - continue; + if (!found) { + /* This is a newly registered host */ + sfcp = &sfczero; + } render(isdb, pre, PT_NOFLAG , "%s\tfch_rxf/s", diff --git a/svg_stats.c b/svg_stats.c index cd471c5..ad5b74a 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -4937,7 +4937,7 @@ __print_funct_t svg_print_filesystem_stats(struct activity *a, int curr, int act __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p, unsigned long long itv, struct record_header *record_hdr) { - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; int group[] = {2, 2}; int g_type[] = {SVG_LINE_GRAPH, SVG_LINE_GRAPH}; char *title[] = {"Fibre Channel HBA statistics (1)", "Fibre Channel HBA statistics (2)"}; @@ -4963,6 +4963,7 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, } if (action & F_MAIN) { + memset(&sfczero, 0, sizeof(struct stats_fchost)); restart = svg_p->restart; /* * Mark previously registered interfaces as now @@ -5032,8 +5033,10 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, while (j != j0); } - if (!found) - continue; + if (!found) { + /* This is a newly registered host */ + sfcp = &sfczero; + } /* * If current interface was marked as previously unregistered, diff --git a/xml_stats.c b/xml_stats.c index cc3a65c..d658fb1 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -2140,11 +2140,13 @@ __print_funct_t xml_print_fchost_stats(struct activity *a, int curr, int tab, unsigned long long itv) { int i, j, j0, found; - struct stats_fchost *sfcc, *sfcp; + struct stats_fchost *sfcc, *sfcp, sfczero; if (!IS_SELECTED(a->options) || (a->nr[curr] <= 0)) goto close_xml_markup; + memset(&sfczero, 0, sizeof(struct stats_fchost)); + xml_markup_network(tab, OPEN_XML_MARKUP); tab++; @@ -2177,8 +2179,10 @@ __print_funct_t xml_print_fchost_stats(struct activity *a, int curr, int tab, while (j != j0); } - if (!found) - continue; + if (!found) { + /* This is a newly registered host */ + sfcp = &sfczero; + } xprintf(tab, "