]> granicus.if.org Git - sysstat/commitdiff
sadf: PCP: Add support for A_PWR_USB activity
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 17 May 2019 13:19:18 +0000 (15:19 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 17 May 2019 13:19:18 +0000 (15:19 +0200)
Add metrics displayed by "sar -m USB" (USB devices) to PCP archive.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
pcp_def_metrics.c
pcp_def_metrics.h
pcp_stats.c
pcp_stats.h
sadf_misc.c

index 6404edea3809495f05c1b761d2dea6eabde5ed4b..8651bdb1328d38d84664a848472657b14a950f3e 100644 (file)
@@ -1709,6 +1709,7 @@ struct activity pwr_usb_act = {
        .f_json_print   = json_print_pwr_usb_stats,
        .f_svg_print    = NULL,
        .f_raw_print    = raw_print_pwr_usb_stats,
+       .f_pcp_print    = pcp_print_pwr_usb_stats,
        .f_count_new    = NULL,
        .item_list      = NULL,
        .desc           = "USB devices",
index 43393857ff7bec1e39ec228ad6e70a5b9a24bef1..cde34d17731dc3dbdf105f26f6e3a29aca34a4bf 100644 (file)
@@ -1427,6 +1427,57 @@ void pcp_def_huge_metrics()
 #endif /* HAVE_PCP */
 }
 
+/*
+ ***************************************************************************
+ * Define PCP metrics for USB devices statistics.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ ***************************************************************************
+ */
+void pcp_def_pwr_usb_metrics(struct activity *a)
+{
+#ifdef HAVE_PCP
+       int inst = 0;
+       static pmInDom indom = PM_INDOM_NULL;
+       char buf[16];
+
+       if (indom == PM_INDOM_NULL) {
+               /* Create domain */
+               indom = pmInDom_build(0, PM_INDOM_USB);
+
+               for (inst = 0; inst < a->item_list_sz; inst++) {
+                       sprintf(buf, "usb%d", inst);
+                       pmiAddInstance(indom,buf, inst);
+               }
+       }
+
+       pmiAddMetric("power.usb.bus",
+                    PM_IN_NULL, PM_TYPE_U32, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.usb.vendorId",
+                    PM_IN_NULL, PM_TYPE_STRING, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.usb.productId",
+                    PM_IN_NULL, PM_TYPE_STRING, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.usb.maxpower",
+                    PM_IN_NULL, PM_TYPE_U32, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.usb.manufacturer",
+                    PM_IN_NULL, PM_TYPE_STRING, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.usb.productName",
+                    PM_IN_NULL, PM_TYPE_STRING, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+#endif /* HAVE_PCP */
+}
+
 /*
  ***************************************************************************
  * Define PCP metrics for filesystem statistics.
index 981d8a126239262694aca571d5360fc85655c8ce..15a4875c2f406bed1b07c3e1b124b81db7465d43 100644 (file)
@@ -40,6 +40,7 @@ void pcp_def_net_icmp6_metrics(void);
 void pcp_def_net_eicmp6_metrics(void);
 void pcp_def_net_udp6_metrics(void);
 void pcp_def_huge_metrics(void);
+void pcp_def_pwr_usb_metrics(struct activity *);
 void pcp_def_filesystem_metrics(struct activity *);
 void pcp_def_fchost_metrics(struct activity *);
 
@@ -51,6 +52,7 @@ void pcp_def_fchost_metrics(struct activity *);
 #define PM_INDOM_INT           4
 #define PM_INDOM_FILESYSTEM    5
 #define PM_INDOM_FCHOST                6
+#define PM_INDOM_USB           7
 
 
 #endif /* _PCP_DEF_METRICS_H */
index cf47962eadc466de442802e26b137fc9d8bbaee7..935042d9e522e0920ed037be7a01a9a5afcc2f2c 100644 (file)
@@ -1772,6 +1772,51 @@ __print_funct_t pcp_print_huge_stats(struct activity *a, int curr, unsigned long
 #endif /* HAVE_PCP */
 }
 
+/*
+ ***************************************************************************
+ * Display USB devices in PCP format.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @itv                Interval of time in 1/100th of a second.
+ * @record_hdr Record header for current sample.
+ ***************************************************************************
+ */
+__print_funct_t pcp_print_pwr_usb_stats(struct activity *a, int curr, unsigned long long itv,
+                                       struct record_header *record_hdr)
+{
+#ifdef HAVE_PCP
+       int i;
+       struct stats_pwr_usb *suc;
+       char buf[64], instance[32];
+
+       for (i = 0; i < a->nr[curr]; i++) {
+
+               suc = (struct stats_pwr_usb *) ((char *) a->buf[curr] + i * a->msize);
+               sprintf(instance, "usb%d", i);
+
+               snprintf(buf, sizeof(buf), "%d", suc->bus_nr);
+               pmiPutValue("power.usb.bus", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%x", suc->vendor_id);
+               pmiPutValue("power.usb.vendorId", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%x", suc->product_id);
+               pmiPutValue("power.usb.productId", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%u", suc->bmaxpower << 1);
+               pmiPutValue("power.usb.maxpower", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%s", suc->manufacturer);
+               pmiPutValue("power.usb.manufacturer", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%s", suc->product);
+               pmiPutValue("power.usb.productName", instance, buf);
+       }
+#endif /* HAVE_PCP */
+}
+
 /*
  ***************************************************************************
  * Display filesystem statistics in PCP format.
index 073d111dab47629ece894eedc7c474293cb83df5..79e1e601b8e4034a71210865732801cc1068483e 100644 (file)
@@ -73,6 +73,8 @@ __print_funct_t pcp_print_pwr_cpufreq_stats
        (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_huge_stats
        (struct activity *, int, unsigned long long, struct record_header *);
+__print_funct_t pcp_print_pwr_usb_stats
+       (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_filesystem_stats
        (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_fchost_stats
index 35000d570e401aebd1d70af20a94a30e4d0dd538..7e33f6f4d39f330f167e84b72112d49801847c3b 100644 (file)
@@ -765,6 +765,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
                                        pcp_def_huge_metrics();
                                        break;
 
+                               case A_PWR_USB:
+                                       pcp_def_pwr_usb_metrics(act[p]);
+                                       break;
+
                                case A_FS:
                                        pcp_def_filesystem_metrics(act[p]);
                                        break;