]> granicus.if.org Git - sysstat/commitdiff
sadf: JSON: Add PSI support
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 12 Apr 2020 14:09:12 +0000 (16:09 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 12 Apr 2020 14:09:12 +0000 (16:09 +0200)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
json_stats.c
json_stats.h

index 74c9e0a3fc25f6526818a12f3ffa077702ba8520..be7e230ac4d11d82eb74a3d4e07f320c09616d85 100644 (file)
@@ -1896,7 +1896,7 @@ struct activity psi_cpu_act = {
 #ifdef SOURCE_SADF
        .f_render       = render_psicpu_stats,
        .f_xml_print    = xml_print_psicpu_stats,
-//FIXME        .f_json_print   = json_print_psicpu_stats,
+       .f_json_print   = json_print_psicpu_stats,
 //FIXME        .f_svg_print    = svg_print_psicpu_stats,
        .f_raw_print    = raw_print_psicpu_stats,
 //FIXME        .f_pcp_print    = pcp_print_psicpu_stats,
@@ -1942,7 +1942,7 @@ struct activity psi_io_act = {
 #ifdef SOURCE_SADF
        .f_render       = render_psiio_stats,
        .f_xml_print    = xml_print_psiio_stats,
-//FIXME        .f_json_print   = json_print_psiio_stats,
+       .f_json_print   = json_print_psiio_stats,
 //FIXME        .f_svg_print    = svg_print_psiio_stats,
        .f_raw_print    = raw_print_psiio_stats,
 //FIXME        .f_pcp_print    = pcp_print_psiio_stats,
@@ -1988,7 +1988,7 @@ struct activity psi_mem_act = {
 #ifdef SOURCE_SADF
        .f_render       = render_psimem_stats,
        .f_xml_print    = xml_print_psimem_stats,
-//FIXME        .f_json_print   = json_print_psimem_stats,
+       .f_json_print   = json_print_psimem_stats,
 //FIXME        .f_svg_print    = svg_print_psimem_stats,
        .f_raw_print    = raw_print_psimem_stats,
 //FIXME        .f_pcp_print    = pcp_print_psimem_stats,
index f16e285cd7076709ab38016798e07669902f8349..ce9c93f78a42e80179da953258fd5493ec132c34 100644 (file)
@@ -93,6 +93,34 @@ void json_markup_power_management(int tab, int action)
        }
 }
 
+/*
+ ***************************************************************************
+ * Open or close "psi" markup.
+ *
+ * IN:
+ * @tab                Number of tabulations.
+ * @action     Open or close action.
+ ***************************************************************************
+ */
+void json_markup_psi(int tab, int action)
+{
+       static int markup_state = CLOSE_JSON_MARKUP;
+
+       if (action == markup_state)
+               return;
+       markup_state = action;
+
+       if (action == OPEN_JSON_MARKUP) {
+               /* Open markup */
+               xprintf(tab, "\"psi\": {");
+       }
+       else {
+               /* Close markup */
+               printf("\n");
+               xprintf0(tab, "}");
+       }
+}
+
 /*
  ***************************************************************************
  * Display CPU statistics in JSON.
@@ -2409,3 +2437,142 @@ close_json_markup:
                json_markup_network(tab, CLOSE_JSON_MARKUP);
        }
 }
+
+/*
+ ***************************************************************************
+ * Display pressure-stall CPU statistics in JSON.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @tab                Indentation in output.
+ * @itv                Interval of time in 1/100th of a second.
+ ***************************************************************************
+ */
+__print_funct_t json_print_psicpu_stats(struct activity *a, int curr, int tab,
+                                       unsigned long long itv)
+{
+       struct stats_psi_cpu
+               *psic = (struct stats_psi_cpu *) a->buf[curr],
+               *psip = (struct stats_psi_cpu *) a->buf[!curr];
+
+       if (!IS_SELECTED(a->options))
+               goto close_json_markup;
+
+       json_markup_psi(tab, OPEN_JSON_MARKUP);
+       tab++;
+
+       xprintf0(tab, "\"psi-cpu\": {"
+                "\"some_avg10\": %.2f, "
+                "\"some_avg60\": %.2f, "
+                "\"some_avg300\": %.2f, "
+                "\"some_total\": %.2f}",
+                (double) psic->some_acpu_10  / 100,
+                (double) psic->some_acpu_60  / 100,
+                (double) psic->some_acpu_300 / 100,
+                S_VALUE(psip->some_cpu_total, psic->some_cpu_total, itv));
+       tab--;
+
+close_json_markup:
+       if (CLOSE_MARKUP(a->options)) {
+               json_markup_psi(tab, CLOSE_JSON_MARKUP);
+       }
+}
+
+/*
+ ***************************************************************************
+ * Display pressure-stall I/O statistics in JSON.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @tab                Indentation in output.
+ * @itv                Interval of time in 1/100th of a second.
+ ***************************************************************************
+ */
+__print_funct_t json_print_psiio_stats(struct activity *a, int curr, int tab,
+                                      unsigned long long itv)
+{
+       struct stats_psi_io
+               *psic = (struct stats_psi_io *) a->buf[curr],
+               *psip = (struct stats_psi_io *) a->buf[!curr];
+
+       if (!IS_SELECTED(a->options))
+               goto close_json_markup;
+
+       json_markup_psi(tab, OPEN_JSON_MARKUP);
+       tab++;
+
+       xprintf0(tab, "\"psi-io\": {"
+                "\"some_avg10\": %.2f, "
+                "\"some_avg60\": %.2f, "
+                "\"some_avg300\": %.2f, "
+                "\"some_total\": %.2f, "
+                "\"full_avg10\": %.2f, "
+                "\"full_avg60\": %.2f, "
+                "\"full_avg300\": %.2f, "
+                "\"full_total\": %.2f}",
+                (double) psic->some_aio_10  / 100,
+                (double) psic->some_aio_60  / 100,
+                (double) psic->some_aio_300 / 100,
+                S_VALUE(psip->some_io_total, psic->some_io_total, itv),
+                (double) psic->full_aio_10  / 100,
+                (double) psic->full_aio_60  / 100,
+                (double) psic->full_aio_300 / 100,
+                S_VALUE(psip->full_io_total, psic->full_io_total, itv));
+       tab--;
+
+close_json_markup:
+       if (CLOSE_MARKUP(a->options)) {
+               json_markup_psi(tab, CLOSE_JSON_MARKUP);
+       }
+}
+
+/*
+ ***************************************************************************
+ * Display pressure-stall memory statistics in JSON.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @tab                Indentation in output.
+ * @itv                Interval of time in 1/100th of a second.
+ ***************************************************************************
+ */
+__print_funct_t json_print_psimem_stats(struct activity *a, int curr, int tab,
+                                       unsigned long long itv)
+{
+       struct stats_psi_mem
+               *psic = (struct stats_psi_mem *) a->buf[curr],
+               *psip = (struct stats_psi_mem *) a->buf[!curr];
+
+       if (!IS_SELECTED(a->options))
+               goto close_json_markup;
+
+       json_markup_psi(tab, OPEN_JSON_MARKUP);
+       tab++;
+
+       xprintf0(tab, "\"psi-mem\": {"
+                "\"some_avg10\": %.2f, "
+                "\"some_avg60\": %.2f, "
+                "\"some_avg300\": %.2f, "
+                "\"some_total\": %.2f, "
+                "\"full_avg10\": %.2f, "
+                "\"full_avg60\": %.2f, "
+                "\"full_avg300\": %.2f, "
+                "\"full_total\": %.2f}",
+                (double) psic->some_amem_10  / 100,
+                (double) psic->some_amem_60  / 100,
+                (double) psic->some_amem_300 / 100,
+                S_VALUE(psip->some_mem_total, psic->some_mem_total, itv),
+                (double) psic->full_amem_10  / 100,
+                (double) psic->full_amem_60  / 100,
+                (double) psic->full_amem_300 / 100,
+                S_VALUE(psip->full_mem_total, psic->full_mem_total, itv));
+       tab--;
+
+close_json_markup:
+       if (CLOSE_MARKUP(a->options)) {
+               json_markup_psi(tab, CLOSE_JSON_MARKUP);
+       }
+}
index 3272a9a11f5435282a55fd379b67adac4d3fc480..90a7e2fd42dc88aaf925d1b345919a950dc73da7 100644 (file)
@@ -93,5 +93,11 @@ __print_funct_t json_print_fchost_stats
        (struct activity *, int, int, unsigned long long);
 __print_funct_t json_print_softnet_stats
        (struct activity *, int, int, unsigned long long);
+__print_funct_t json_print_psicpu_stats
+       (struct activity *, int, int, unsigned long long);
+__print_funct_t json_print_psiio_stats
+       (struct activity *, int, int, unsigned long long);
+__print_funct_t json_print_psimem_stats
+       (struct activity *, int, int, unsigned long long);
 
 #endif /* _JSON_STATS_H */