From: Sebastien GODARD Date: Sun, 16 Oct 2016 09:54:10 +0000 (+0200) Subject: sar: Add softnet statistics (part 2): Read statistics X-Git-Tag: v11.5.2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adbef780ce25c0662c22531e93f5ba25764ff717;p=sysstat sar: Add softnet statistics (part 2): Read statistics This patch read softnet statistics from the /proc/net/softnet_stat file. Softnet stats will be collected by default by sadc: So set AO_COLLECTED flag in corresponding activity structure. Also metrics' type is unsigned int (%x) and not unsigned long long. Signed-off-by: Sebastien GODARD --- diff --git a/activity.c b/activity.c index e087e8d..f17446c 100644 --- a/activity.c +++ b/activity.c @@ -1449,7 +1449,7 @@ struct activity fchost_act = { /* Softnet activity */ struct activity softnet_act = { .id = A_NET_SOFT, - .options = AO_CLOSE_MARKUP + AO_GRAPH_PER_ITEM, + .options = AO_COLLECTED + AO_CLOSE_MARKUP + AO_GRAPH_PER_ITEM, .magic = ACTIVITY_MAGIC_BASE, .group = G_DEFAULT, #ifdef SOURCE_SADC @@ -1474,7 +1474,7 @@ struct activity softnet_act = { #endif .nr = -1, .nr2 = 1, - .nr_max = NR_CPUS, + .nr_max = NR_CPUS + 1, .fsize = STATS_SOFTNET_SIZE, .msize = STATS_SOFTNET_SIZE, .opt_flags = 0, diff --git a/rd_stats.c b/rd_stats.c index c9f8895..d5e9ca3 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -2225,5 +2225,41 @@ void read_fchost(struct stats_fchost *st_fc, int nbr) closedir(dir); } +/* + *************************************************************************** + * Read softnet statistics. + * + * IN: + * @st_softnet Structure where stats will be saved. + * @nbr Total number of CPU (including cpu "all"). + * + * OUT: + * @st_softnet Structure with statistics. + *************************************************************************** + */ +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; + + if ((fp = fopen(NET_SOFTNET, "r")) == NULL) + return; + + while ((fgets(line, sizeof(line), fp) != NULL) && (proc_nb < (nbr - 1))) { + + st_softnet_i = st_softnet + proc_nb++; + sscanf(line, "%x %x %x %*x %*x %*x %*x %*x %*x %x %x", + &st_softnet_i->processed, + &st_softnet_i->dropped, + &st_softnet_i->time_squeeze, + &st_softnet_i->received_rps, + &st_softnet_i->flow_limit); + } + + fclose(fp); +} + /*------------------ END: FUNCTIONS USED BY SADC ONLY ---------------------*/ #endif /* SOURCE_SADC */ diff --git a/rd_stats.h b/rd_stats.h index 57d1bdb..c617fa7 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -571,11 +571,11 @@ struct stats_fchost { /* Structure for softnet statistics */ struct stats_softnet { - unsigned long long processed __attribute__ ((aligned (16))); - unsigned long long dropped __attribute__ ((aligned (16))); - unsigned long long time_squeeze __attribute__ ((aligned (16))); - unsigned long long received_rps __attribute__ ((aligned (16))); - unsigned long long flow_limit __attribute__ ((aligned (16))); + unsigned int processed __attribute__ ((aligned (4))); + unsigned int dropped __attribute__ ((packed)); + unsigned int time_squeeze __attribute__ ((packed)); + unsigned int received_rps __attribute__ ((packed)); + unsigned int flow_limit __attribute__ ((packed)); }; #define STATS_SOFTNET_SIZE (sizeof(struct stats_softnet)) @@ -662,5 +662,7 @@ void read_filesystem (struct stats_filesystem *, int); void read_fchost (struct stats_fchost *, int); +void read_softnet + (struct stats_softnet *, int); #endif /* _RD_STATS_H */ diff --git a/sa_wrap.c b/sa_wrap.c index dc5b6cf..ab879fd 100644 --- a/sa_wrap.c +++ b/sa_wrap.c @@ -918,7 +918,7 @@ __read_funct_t wrap_read_softnet(struct activity *a) = (struct stats_softnet *) a->_buf0; /* Read softnet stats */ - /* FIXME */ + read_softnet(st_softnet, a->nr); return; }