From: Sebastien GODARD Date: Sun, 25 Mar 2018 07:55:13 +0000 (+0200) Subject: sadf: Softnet stats: Apply improved support for offline/online CPUs X-Git-Tag: v11.7.3~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=144e1bc938de671f04ef12f82e0154a4181a80e9;p=sysstat sadf: Softnet stats: Apply improved support for offline/online CPUs Signed-off-by: Sebastien GODARD --- diff --git a/json_stats.c b/json_stats.c index d731649..56990ac 100644 --- a/json_stats.c +++ b/json_stats.c @@ -2294,6 +2294,7 @@ __print_funct_t json_print_softnet_stats(struct activity *a, int curr, int tab, struct stats_softnet *ssnc, *ssnp; int sep = FALSE; char cpuno[8]; + unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0}; if (!IS_SELECTED(a->options) || (a->nr[curr] <= 0)) goto close_json_markup; @@ -2303,31 +2304,37 @@ __print_funct_t json_print_softnet_stats(struct activity *a, int curr, int tab, xprintf(tab++, "\"softnet\": ["); - for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) { + /* @nr[curr] cannot normally be greater than @nr_ini */ + if (a->nr[curr] > a->nr_ini) { + a->nr_ini = a->nr[curr]; + } - /* - * The size of a->buf[...] CPU structure may be different from the default - * sizeof(struct stats_pwr_cpufreq) value if data have been read from a file! - * That's why we don't use a syntax like: - * ssnc = (struct stats_softnet *) a->buf[...] + i; - */ - ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); - ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + /* Compute statistics for CPU "all" */ + get_global_soft_statistics(a, !curr, curr, flags, offline_cpu_bitmap); + + for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) { /* + * Should current CPU (including CPU "all") be displayed? * Note: a->nr is in [1, NR_CPUS + 1]. * Bitmap size is provided for (NR_CPUS + 1) CPUs. * Anyway, NR_CPUS may vary between the version of sysstat * used by sadc to create a file, and the version of sysstat * used by sar to read it... */ - - /* Should current CPU (including CPU "all") be displayed? */ - if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) + if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) || + offline_cpu_bitmap[i >> 3] & (1 << (i & 0x07))) /* No */ continue; - /* Yes: Display current CPU stats */ + /* + * The size of a->buf[...] CPU structure may be different from the default + * sizeof(struct stats_pwr_cpufreq) value if data have been read from a file! + * That's why we don't use a syntax like: + * ssnc = (struct stats_softnet *) a->buf[...] + i; + */ + ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); + ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); if (sep) { printf(",\n"); diff --git a/raw_stats.c b/raw_stats.c index c176e79..642df5d 100644 --- a/raw_stats.c +++ b/raw_stats.c @@ -1570,7 +1570,13 @@ __print_funct_t raw_print_softnet_stats(struct activity *a, char *timestr, int c int i; struct stats_softnet *ssnc, *ssnp; - for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) { + /* @nr[curr] cannot normally be greater than @nr_ini */ + if (a->nr[curr] > a->nr_ini) { + a->nr_ini = a->nr[curr]; + } + + /* Don't display CPU "all" which doesn't exist in file */ + for (i = 1; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) { /* * The size of a->buf[...] CPU structure may be different from the default @@ -1595,7 +1601,16 @@ __print_funct_t raw_print_softnet_stats(struct activity *a, char *timestr, int c continue; /* Yes: Display current CPU stats */ - printf("%s; %s; %d;", timestr, pfield(a->hdr_line, FIRST), i - 1); + printf("%s; %s", timestr, pfield(a->hdr_line, FIRST)); + if (DISPLAY_DEBUG_MODE(flags) && i) { + if (ssnc->processed + ssnc->dropped + ssnc->time_squeeze + + ssnc->received_rps + ssnc->flow_limit == 0) { + /* CPU is considered offline */ + printf(" [OFF]"); + } + } + printf("; %d;", i - 1); + printf(" %s", pfield(NULL, 0)); pval((unsigned long long) ssnp->processed, (unsigned long long) ssnc->processed); printf(" %s", pfield(NULL, 0)); diff --git a/rndr_stats.c b/rndr_stats.c index 78213bc..90fe250 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -3037,19 +3037,19 @@ __print_funct_t render_softnet_stats(struct activity *a, int isdb, char *pre, { int i; struct stats_softnet *ssnc, *ssnp; + unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0}; int pt_newlin = (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN); - for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) { + /* @nr[curr] cannot normally be greater than @nr_ini */ + if (a->nr[curr] > a->nr_ini) { + a->nr_ini = a->nr[curr]; + } - /* - * The size of a->buf[...] CPU structure may be different from the default - * sizeof(struct stats_pwr_cpufreq) value if data have been read from a file! - * That's why we don't use a syntax like: - * ssnc = (struct stats_softnet *) a->buf[...] + i; - */ - ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); - ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + /* Compute statistics for CPU "all" */ + get_global_soft_statistics(a, !curr, curr, flags, offline_cpu_bitmap); + + for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) { /* * Note: a->nr is in [1, NR_CPUS + 1]. @@ -3058,12 +3058,20 @@ __print_funct_t render_softnet_stats(struct activity *a, int isdb, char *pre, * used by sadc to create a file, and the version of sysstat * used by sar to read it... */ - - /* Should current CPU (including CPU "all") be displayed? */ - if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) + if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) || + offline_cpu_bitmap[i >> 3] & (1 << (i & 0x07))) /* No */ continue; + /* + * The size of a->buf[...] CPU structure may be different from the default + * sizeof(struct stats_pwr_cpufreq) value if data have been read from a file! + * That's why we don't use a syntax like: + * ssnc = (struct stats_softnet *) a->buf[...] + i; + */ + ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); + ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + if (!i) { /* This is CPU "all" */ render(isdb, pre, PT_NOFLAG, diff --git a/svg_stats.c b/svg_stats.c index aef094a..f17896b 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -5012,6 +5012,7 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action static char **out; static int *outsize; char item_name[8]; + unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0}; int i, pos; if (action & F_BEGIN) { @@ -5023,17 +5024,26 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action } if (action & F_MAIN) { - /* For each CPU */ - for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) { + /* @nr[curr] cannot normally be greater than @nr_ini */ + if (a->nr[curr] > a->nr_ini) { + a->nr_ini = a->nr[curr]; + } - ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); - ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + /* Compute statistics for CPU "all" */ + get_global_soft_statistics(a, !curr, curr, flags, offline_cpu_bitmap); + + /* For each CPU */ + for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) { /* Should current CPU (including CPU "all") be displayed? */ - if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) + if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) || + offline_cpu_bitmap[i >> 3] & (1 << (i & 0x07))) /* No */ continue; + ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); + ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + pos = i * 5; /* Check for min/max values */ diff --git a/xml_stats.c b/xml_stats.c index cf6fc4b..04761bc 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -2182,6 +2182,7 @@ __print_funct_t xml_print_softnet_stats(struct activity *a, int curr, int tab, int i; struct stats_softnet *ssnc, *ssnp; char cpuno[8]; + unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0}; if (!IS_SELECTED(a->options) || (a->nr[curr] <= 0)) goto close_xml_markup; @@ -2189,16 +2190,25 @@ __print_funct_t xml_print_softnet_stats(struct activity *a, int curr, int tab, xml_markup_network(tab, OPEN_XML_MARKUP); tab++; - for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) { + /* @nr[curr] cannot normally be greater than @nr_ini */ + if (a->nr[curr] > a->nr_ini) { + a->nr_ini = a->nr[curr]; + } - ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); - ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + /* Compute statistics for CPU "all" */ + get_global_soft_statistics(a, !curr, curr, flags, offline_cpu_bitmap); + + for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) { /* Should current CPU (including CPU "all") be displayed? */ - if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) + if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) || + offline_cpu_bitmap[i >> 3] & (1 << (i & 0x07))) /* No */ continue; + ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize); + ssnp = (struct stats_softnet *) ((char *) a->buf[!curr] + i * a->msize); + /* Yes: Display it */ if (!i) { /* This is CPU "all" */