]> granicus.if.org Git - sysstat/commitdiff
Add printing+reading of new FC stats.
authorSteve Kay <stevekay@gmail.com>
Tue, 7 Apr 2015 21:10:15 +0000 (14:10 -0700)
committerSteve Kay <stevekay@gmail.com>
Tue, 7 Apr 2015 21:10:15 +0000 (14:10 -0700)
pr_stats.c
pr_stats.h
rd_stats.c
rd_stats.h

index d3cf6f8299340ff43ad2bf90dd15f583dbc91622..8fbe546d70ea1e4af1ac5b626a7d82e66f6c104f 100644 (file)
@@ -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);
+}
index 1474cfad64c1308b6ed874dcbcd8842985e88ce1..cf76bf8484352df8be5f91aeeb8910994b1dc5d5 100644 (file)
@@ -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 */
index 83e389e143db5b2fea5af6ba7a7903611f6b1cea..14b885ed49e6d3f5139bb381caff9bd9f9c6f3f5 100644 (file)
@@ -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 */
index a614292d2bff92cb3f15cd164c045cf7b432b6bc..b39e000419a282f26fad3025aa509c492c8ee3d1 100644 (file)
@@ -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 */