]> granicus.if.org Git - sysstat/commitdiff
sadf: PCP: Add support for A_PWR_CPU activity
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 6 Apr 2019 15:14:31 +0000 (17:14 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 6 Apr 2019 15:14:31 +0000 (17:14 +0200)
Add metrics displayed by "sar -m CPU" (CPU frequency statistics) to PCP
archive.

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

index bafa38eacbc928cfca1258b320594cb919711749..0fc8d6f39dd0e9dc069deb225b4edba9a457892a 100644 (file)
@@ -1437,6 +1437,7 @@ struct activity pwr_cpufreq_act = {
        .f_json_print   = json_print_pwr_cpufreq_stats,
        .f_svg_print    = svg_print_pwr_cpufreq_stats,
        .f_raw_print    = raw_print_pwr_cpufreq_stats,
+       .f_pcp_print    = pcp_print_pwr_cpufreq_stats,
        .f_count_new    = NULL,
        .item_list      = NULL,
        .desc           = "CPU clock frequency",
index 04a0e3619785fb568908d0ad5e1f82c272a571e7..fd8b89e9ee7880bb8fb1397a43c1261f7e4acb5a 100644 (file)
@@ -40,9 +40,9 @@
 void pcp_def_cpu_metrics(struct activity *a)
 {
 #ifdef HAVE_PCP
-       int i, first = TRUE;
+       int i, first = TRUE, create = FALSE;
        char buf[64];
-       pmInDom indom;
+       static pmInDom indom = PM_INDOM_NULL;
 
        for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) {
 
@@ -56,94 +56,121 @@ void pcp_def_cpu_metrics(struct activity *a)
                        continue;
 
                if (!i) {
-                       /* This is CPU "all" */
-                       pmiAddMetric("kernel.all.cpu.user",
+                       if (a->id == A_CPU) {
+                               /* This is CPU "all" */
+                               pmiAddMetric("kernel.all.cpu.user",
                                     PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
                                     pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.nice",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.nice",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.sys",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.sys",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.idle",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.idle",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.iowait",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.iowait",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.steal",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.steal",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.hardirq",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.hardirq",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.softirq",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.softirq",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.guest",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.guest",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
 
-                       pmiAddMetric("kernel.all.cpu.guest_nice",
-                                    PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
-                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               pmiAddMetric("kernel.all.cpu.guest_nice",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                       }
+
+                       else if (a->id == A_PWR_CPU) {
+                               /* Create metric for A_PWR_CPU */
+                               pmiAddMetric("kernel.all.cpu.freqMHz",
+                                            PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT,
+                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                       }
                }
                else {
-                       if (first) {
+                       /* This is not CPU "all" */
+                       if (indom == PM_INDOM_NULL) {
+                               /* Create domain */
                                indom = pmInDom_build(0, PM_INDOM_CPU);
+                               create = TRUE;
+                       }
+                       if (create) {
+                               /* Create instance for current CPU */
+                               sprintf(buf, "cpu%d", i - 1);
+                               pmiAddInstance(indom, buf, i - 1);
+                       }
 
-                               pmiAddMetric("kernel.percpu.cpu.user",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                       if (first) {
+                               if (a->id == A_CPU) {
+                                       /* Create metrics for A_CPU */
+                                       pmiAddMetric("kernel.percpu.cpu.user",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.nice",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.nice",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.sys",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.sys",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.idle",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.idle",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.iowait",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.iowait",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.steal",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.steal",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.hardirq",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.hardirq",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.softirq",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.softirq",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.guest",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.guest",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
 
-                               pmiAddMetric("kernel.percpu.cpu.guest_nice",
-                                            PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
-                                            pmiUnits(0, 0, 0, 0, 0, 0));
+                                       pmiAddMetric("kernel.percpu.cpu.guest_nice",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               }
+
+                               else if (a->id == A_PWR_CPU) {
+                                       /* Create metric for A_PWR_CPU */
+                                       pmiAddMetric("kernel.percpu.cpu.freqMHz",
+                                                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                                                    pmiUnits(0, 0, 0, 0, 0, 0));
+                               }
                                first = FALSE;
                        }
-                       sprintf(buf, "cpu%d", i - 1);
-                       pmiAddInstance(indom, buf, i - 1);
                }
        }
 #endif /* HAVE_PCP */
index 653a041a47ddf46ae51eb78336f7a27192ae3637..cc6a3ce6a558c5fcd5545d0b4274878b4b92b8ea 100644 (file)
@@ -1691,3 +1691,47 @@ __print_funct_t pcp_print_net_udp6_stats(struct activity *a, int curr, unsigned
        pmiPutValue("network.snmp.udp6.udpInErrors", NULL, buf);
 #endif /* HAVE_PCP */
 }
+
+/*
+ ***************************************************************************
+ * Display CPU frequency statistics 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_cpufreq_stats(struct activity *a, int curr, unsigned long long itv,
+                                           struct record_header *record_hdr)
+{
+#ifdef HAVE_PCP
+       int i;
+       struct stats_pwr_cpufreq *spc;
+       char buf[64], cpuno[64];
+       char *str;
+
+       for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) {
+
+               spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr] + i * a->msize);
+
+               /* Should current CPU (including CPU "all") be displayed? */
+               if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))))
+                       /* No */
+                       continue;
+
+               if (!i) {
+                       /* This is CPU "all" */
+                       str = NULL;
+               }
+               else {
+                       sprintf(cpuno, "cpu%d", i - 1);
+                       str = cpuno;
+               }
+
+               snprintf(buf, sizeof(buf), "%f", ((double) spc->cpufreq) / 100);
+               pmiPutValue(i ? "kernel.percpu.cpu.freqMHz" : "kernel.all.cpu.freqMHz", str, buf);
+       }
+#endif /* HAVE_PCP */
+}
index 7634e8c8c0f75e1136f20caf2bdde8738c051e7a..17e378c9a6125f6bc3f7525f4a6c784369158342 100644 (file)
@@ -69,5 +69,7 @@ __print_funct_t pcp_print_net_eicmp6_stats
        (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_net_udp6_stats
        (struct activity *, int, unsigned long long, struct record_header *);
+__print_funct_t pcp_print_pwr_cpufreq_stats
+       (struct activity *, int, unsigned long long, struct record_header *);
 
 #endif /* _PCP_STATS_H */
index c98b03ce858533ffcab277abf9443b36535184f8..30f924b6cf39716915373aefb5cbbe1c8ac31ef4 100644 (file)
@@ -501,6 +501,7 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
                        switch (act[p]->id) {
 
                                case A_CPU:
+                               case A_PWR_CPU:
                                        pcp_def_cpu_metrics(act[p]);
                                        break;