From: Steve Kay Date: Tue, 7 Apr 2015 21:10:15 +0000 (-0700) Subject: Add printing+reading of new FC stats. X-Git-Tag: 11.1.5~24^2~1^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a871266110c6afa3286cc5cea9ea01cd21a35904;p=sysstat Add printing+reading of new FC stats. --- diff --git a/pr_stats.c b/pr_stats.c index d3cf6f8..8fbe546 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -2582,3 +2582,75 @@ __print_funct_t print_avg_filesystem_stats(struct activity *a, int prev, int cur { stub_print_filesystem_stats(a, 2, TRUE); } + +/* + *************************************************************************** + * Display Fibre Channel HBA statistics. This function is used to + * display instantaneous and average statistics. + * + * IN: + * @a Activity structure with statistics. + * @curr Index in array for current sample statistics. + * @dispavg TRUE if displaying average statistics. + * @itv Interval of time in jiffies. + *************************************************************************** + */ +__print_funct_t stub_print_fc_stats(struct activity *a, int prev, int curr, int dispavg, unsigned long long itv) +{ + int i; + struct stats_fc *sfcc,*sfcp; + + + if (dis) { + printf("\n%-11s FCHBA hba_rxf/s hba_txf/s hba_rxw/s hba_txw/s\n", + (dispavg ? _("Summary:") : timestamp[curr])); + } + + for (i = 0; i < a->nr; i++) { + sfcc = (struct stats_fc *) ((char *) a->buf[curr] + i * a->msize); + sfcp = (struct stats_fc *) ((char *) a->buf[prev] + i * a->msize); + + printf("%-11s %10s %11.2f %11.2f %11.2f %11.2f\n", + (dispavg ? _("Average:") : timestamp[curr]), + sfcc->hba_name, + S_VALUE(sfcp->f_rxframes, sfcc->f_rxframes, itv), + S_VALUE(sfcp->f_txframes, sfcc->f_txframes, itv), + S_VALUE(sfcp->f_rxwords, sfcc->f_rxwords, itv), + S_VALUE(sfcp->f_txwords, sfcc->f_txwords, itv)); + } + printf("\n"); +} + +/* + *************************************************************************** + * Display Fibre Channel HBA statistics. + * + * IN: + * @a Activity structure with statistics. + * @prev Index in array where stats used as reference are. + * @curr Index in array for current sample statistics. + * @itv Interval of time in jiffies. + *************************************************************************** + */ +__print_funct_t print_fc_stats(struct activity *a, int prev, int curr, + unsigned long long itv) +{ + stub_print_fc_stats(a, prev, curr, FALSE, itv); +} + +/* + *************************************************************************** + * Display average Fibre Channel HBA statistics. + * + * IN: + * @a Activity structure with statistics. + * @prev Index in array where stats used as reference are. + * @curr Index in array for current sample statistics. + * @itv Interval of time in jiffies. + *************************************************************************** + */ +__print_funct_t print_avg_hba_stats(struct activity *a, int prev, int curr, + unsigned long long itv) +{ + stub_print_fc_stats(a, prev, curr, TRUE, itv); +} diff --git a/pr_stats.h b/pr_stats.h index 1474cfa..cf76bf8 100644 --- a/pr_stats.h +++ b/pr_stats.h @@ -90,6 +90,8 @@ extern __print_funct_t print_pwr_usb_stats (struct activity *, int, int, unsigned long long); extern __print_funct_t print_filesystem_stats (struct activity *, int, int, unsigned long long); +extern __print_funct_t print_fc_stats + (struct activity *, int, int, unsigned long long); /* Functions used to display average statistics */ extern __print_funct_t print_avg_memory_stats @@ -116,5 +118,7 @@ extern __print_funct_t print_avg_pwr_usb_stats (struct activity *, int, int, unsigned long long); extern __print_funct_t print_avg_filesystem_stats (struct activity *, int, int, unsigned long long); +extern __print_funct_t print_avg_hba_stats + (struct activity *, int, int, unsigned long long); #endif /* _PR_STATS_H */ diff --git a/rd_stats.c b/rd_stats.c index 83e389e..14b885e 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -2120,5 +2120,85 @@ void read_filesystem(struct stats_filesystem *st_filesystem, int nbr) fclose(fp); } +/* + *************************************************************************** + * Read Fibre Channel HBA statistics. + * + * IN: + * @st_fc Structure where stats will be saved. + * @nbr Total number of HBAs. + * + * OUT: + * @st_fc Structure with statistics. + *************************************************************************** + */ +void read_hba(struct stats_fc *st_fc, int nbr) +{ + DIR *dir; + FILE *fp; + struct dirent *drd; + struct stats_fc *st_fc_i; + int hba = 0; + char fcstat_filename[MAX_FS_LEN]; + char line[256]; + unsigned long rx_frames, + tx_frames, + rx_words, + tx_words; + + /* Each HBA, if present, will have its own hostX entry within SYSFS_FCHBA */ + if ((dir = opendir(SYSFS_FCHBA)) == NULL) + return; /* No HBAs */ + + /* Read each of the counters via sysfs, where they are + * returned as hex values (e.g. 0x72400) */ + while ((drd = readdir(dir)) != NULL) { + rx_frames = tx_frames = rx_words = tx_words = 0; + + if (strncmp(drd->d_name,"host",4) == 0) { + sprintf(fcstat_filename,"%s/%s/statistics/rx_frames", + SYSFS_FCHBA,drd->d_name); + if ((fp = fopen(fcstat_filename, "r"))) { + if (fgets(line,sizeof(line),fp)) + sscanf(line, "%lx",&rx_frames); + fclose(fp); + } + + sprintf(fcstat_filename,"%s/%s/statistics/tx_frames", + SYSFS_FCHBA,drd->d_name); + if ((fp = fopen(fcstat_filename, "r"))) { + if (fgets(line,sizeof(line),fp)) + sscanf(line, "%lx",&tx_frames); + fclose(fp); + } + + sprintf(fcstat_filename,"%s/%s/statistics/rx_words", + SYSFS_FCHBA,drd->d_name); + if ((fp = fopen(fcstat_filename, "r"))) { + if (fgets(line,sizeof(line),fp)) + sscanf(line, "%lx",&rx_words); + fclose(fp); + } + + sprintf(fcstat_filename,"%s/%s/statistics/tx_words", + SYSFS_FCHBA,drd->d_name); + if ((fp = fopen(fcstat_filename, "r"))) { + if (fgets(line,sizeof(line),fp)) + sscanf(line, "%lx",&tx_words); + fclose(fp); + } + + st_fc_i = st_fc + hba++; + st_fc_i->f_rxframes = rx_frames; + st_fc_i->f_txframes = tx_frames; + st_fc_i->f_rxwords = rx_words; + st_fc_i->f_txwords = tx_words; + strcpy(st_fc_i->hba_name, drd->d_name); + } + + } + closedir(dir); +} + /*------------------ END: FUNCTIONS USED BY SADC ONLY ---------------------*/ #endif /* SOURCE_SADC */ diff --git a/rd_stats.h b/rd_stats.h index a614292..b39e000 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -548,6 +548,17 @@ struct stats_filesystem { #define STATS_FILESYSTEM_SIZE (sizeof(struct stats_filesystem)) +/* Structure for Fibre Channel HBA statistics */ +struct stats_fc { + unsigned long f_rxframes __attribute__ ((aligned (16))); + unsigned long f_txframes __attribute__ ((aligned (16))); + unsigned long f_rxwords __attribute__ ((aligned (16))); + unsigned long f_txwords __attribute__ ((aligned (16))); + char hba_name[16] __attribute__ ((aligned (16))); +}; + +#define STATS_FC_SIZE (sizeof(struct stats_fc)) + /* *************************************************************************** * Prototypes for functions used to read system statistics @@ -630,5 +641,7 @@ extern void read_bus_usb_dev(struct stats_pwr_usb *, int); extern void read_filesystem(struct stats_filesystem *, int); +extern void + read_hba(struct stats_fc *, int); #endif /* _RD_STATS_H */