]> granicus.if.org Git - sysstat/commitdiff
sadf: Softnet stats: Apply improved support for offline/online CPUs
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 25 Mar 2018 07:55:13 +0000 (09:55 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 25 Mar 2018 07:55:13 +0000 (09:55 +0200)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
json_stats.c
raw_stats.c
rndr_stats.c
svg_stats.c
xml_stats.c

index d7316492b4f4977341fe40771cdf53cf8a73ce74..56990acb7d15ef1e17b68735cca0560b94931563 100644 (file)
@@ -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");
index c176e7987c034062a13d1a52700c5f1168fffc45..642df5d14a7665b24a7031ef1edace1b5ac262a1 100644 (file)
@@ -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));
index 78213bc99dce0bbf8ee8b0bdcd7c36317df7d8f3..90fe25055209b13dafa2ce937f1dc99fd9a8e9eb 100644 (file)
@@ -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,
index aef094a3622297ae6399ea5bdae0afc9af694555..f17896b7d634f81025eeb04fcbb18731d2bef264 100644 (file)
@@ -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 */
index cf6fc4b691c68fcf5611af335abd8c184aea603e..04761bc63213233a270c58992532176611440cf1 100644 (file)
@@ -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" */