]> granicus.if.org Git - sysstat/commitdiff
sar: Add softnet statistics (part 3): Display statistics
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 28 Oct 2016 15:31:14 +0000 (17:31 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 28 Oct 2016 15:31:14 +0000 (17:31 +0200)
Update sar to display softnet statistics collected by sadc.
Also compute global statistics among all CPU (though these data are not
part of /proc/net/softnet_stat file).

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
pr_stats.c
rd_stats.c

index f17446c08f48c08a3877eb3a6e72e2a5441b5d0f..c0f5cea71ea718a0571437a90c5cba4fde33e1b2 100644 (file)
@@ -1479,7 +1479,7 @@ struct activity softnet_act = {
        .msize          = STATS_SOFTNET_SIZE,
        .opt_flags      = 0,
        .buf            = {NULL, NULL, NULL},
-       .bitmap         = NULL
+       .bitmap         = &cpu_bitmap
 };
 
 #ifdef SOURCE_SADC
index c09c9c6184d02996febf8db2e10a14d1a52d543e..d8685205711987042f5a23ab6b5a22dd22be56a4 100644 (file)
@@ -2740,5 +2740,55 @@ __print_funct_t print_fchost_stats(struct activity *a, int prev, int curr,
 __print_funct_t print_softnet_stats(struct activity *a, int prev, int curr,
                                    unsigned long long itv)
 {
-       /* FIXME */
+       struct stats_softnet
+               *ssnc = (struct stats_softnet *) a->buf[curr],
+               *ssnp = (struct stats_softnet *) a->buf[prev];
+       int i;
+
+       if (dis) {
+               print_hdr_line(timestamp[!curr], a, FIRST, 7, 9);
+       }
+
+       for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
+
+               /*
+                * 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[prev] + i * a->msize);
+
+               /*
+                * 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))) {
+
+                       /* Yes: Display it */
+                       printf("%-11s", timestamp[curr]);
+
+                       if (!i) {
+                               /* This is CPU "all" */
+                               cprintf_in(IS_STR, " %s", "    all", 0);
+                       }
+                       else {
+                               cprintf_in(IS_INT, " %7d", "", i - 1);
+                       }
+
+                       cprintf_f(5, 9, 2,
+                                 S_VALUE(ssnp->processed,    ssnc->processed,    itv),
+                                 S_VALUE(ssnp->dropped,      ssnc->dropped,      itv),
+                                 S_VALUE(ssnp->time_squeeze, ssnc->time_squeeze, itv),
+                                 S_VALUE(ssnp->received_rps, ssnc->received_rps, itv),
+                                 S_VALUE(ssnp->flow_limit,   ssnc->flow_limit,   itv));
+                       printf("\n");
+               }
+       }
 }
index be72dc4b6ac368b9171b83e9de7af6e35af05b83..1df4beffec026886e746d3170cbee4cdda7d74ea 100644 (file)
@@ -2242,12 +2242,20 @@ void read_softnet(struct stats_softnet *st_softnet, int nbr)
        FILE *fp;
        struct stats_softnet *st_softnet_i;
        char line[1024];
-       unsigned int proc_nb = 0;
+       unsigned int proc_nb = 1;
 
+       /* Open /proc/net/softnet_stat file */
        if ((fp = fopen(NET_SOFTNET, "r")) == NULL)
                return;
 
-       while ((fgets(line, sizeof(line), fp) != NULL) && (proc_nb < (nbr - 1))) {
+       /*
+        * Init a structure that will contain the values for CPU "all".
+        * CPU "all" doesn't exist in /proc/net/softnet_stat file, so
+        * we compute its values as the sum of the values of each CPU.
+        */
+       memset(st_softnet, 0, sizeof(struct stats_softnet));
+
+       while ((fgets(line, sizeof(line), fp) != NULL) && (proc_nb < nbr)) {
 
                st_softnet_i = st_softnet + proc_nb++;
                sscanf(line, "%x %x %x %*x %*x %*x %*x %*x %*x %x %x",
@@ -2256,6 +2264,12 @@ void read_softnet(struct stats_softnet *st_softnet, int nbr)
                       &st_softnet_i->time_squeeze,
                       &st_softnet_i->received_rps,
                       &st_softnet_i->flow_limit);
+
+               st_softnet->processed += st_softnet_i->processed;
+               st_softnet->dropped += st_softnet_i->dropped;
+               st_softnet->time_squeeze += st_softnet_i->time_squeeze;
+               st_softnet->received_rps += st_softnet_i->received_rps;
+               st_softnet->flow_limit += st_softnet_i->flow_limit;
        }
 
        fclose(fp);