]> granicus.if.org Git - sysstat/commitdiff
SVG: Add SVG output for voltage inputs statistics
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 12 Jun 2016 10:10:01 +0000 (12:10 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 12 Jun 2016 10:10:01 +0000 (12:10 +0200)
These graphs correspond to the output of "sar -m IN".

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

index 881ed3ee1ee6a1d096a6b112e19a71296d134002..36955fe58b887693c2c7f07968f501852c2f4d1d 100644 (file)
@@ -1166,7 +1166,7 @@ struct activity pwr_temp_act = {
 /* Voltage inputs */
 struct activity pwr_in_act = {
        .id             = A_PWR_IN,
-       .options        = AO_NULL,
+       .options        = AO_GRAPH_PER_ITEM,
        .magic          = ACTIVITY_MAGIC_BASE,
        .group          = G_POWER,
 #ifdef SOURCE_SADC
@@ -1182,9 +1182,10 @@ struct activity pwr_in_act = {
        .f_render       = render_pwr_in_stats,
        .f_xml_print    = xml_print_pwr_in_stats,
        .f_json_print   = json_print_pwr_in_stats,
+       .f_svg_print    = svg_print_pwr_in_stats,
        .hdr_line       = "IN;DEVICE;inV;%in",
        .name           = "A_PWR_IN",
-       .g_nr           = 0,
+       .g_nr           = 2,
 #endif
        .nr             = -1,
        .nr2            = 1,
index c0727285a5e344f6094195eddbc215e9fef3cd85..1fb750a6ecdb051ae67fc6ebd07a0732b0538c4e 100644 (file)
@@ -3500,6 +3500,104 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio
        }
 }
 
+/*
+ ***************************************************************************
+ * Display voltage inputs statistics in SVG.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @action     Action expected from current function.
+ * @svg_p      SVG specific parameters: Current graph number (.@graph_no),
+ *             flag indicating that a restart record has been previously
+ *             found (.@restart) and time used for the X axis origin
+ *             (@ust_time_ref).
+ * @itv                Interval of time in jiffies (only with F_MAIN action).
+ * @record_hdr Pointer on record header of current stats sample.
+ ***************************************************************************
+ */
+__print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p,
+                                      unsigned long long g_itv, struct record_header *record_hdr)
+{
+       struct stats_pwr_in *spc;
+       int group[] = {1};
+       char *title1[] = {"Voltage inputs (1)"};
+       char *title2[] = {"Voltage inputs (2)"};
+       char *g1_title[] = {"inV"};
+       char *g2_title[] = {"%in"};
+       static double *spmin, *spmax;
+       static char **out;
+       static int *outsize;
+       char item_name[MAX_SENSORS_DEV_LEN + 8];
+       int i;
+       double tval;
+
+       if (action & F_BEGIN) {
+               /*
+                * Allocate arrays that will contain the graphs data
+                * and the min/max values.
+                */
+               out = allocate_graph_lines(2 * a->nr, &outsize, &spmin, &spmax);
+       }
+
+       if (action & F_MAIN) {
+               /* For each temperature  sensor */
+               for (i = 0; i < a->nr; i++) {
+
+                       spc = (struct stats_pwr_in *) ((char *) a->buf[curr]  + i * a->msize);
+
+                       /* Look for min/max values */
+                       if (spc->in < *(spmin + 2 * i)) {
+                               *(spmin + 2 * i) = spc->in;
+                       }
+                       if (spc->in > *(spmax + 2 * i)) {
+                               *(spmax + 2 * i) = spc->in;
+                       }
+                       tval = (spc->in_max - spc->in_min) ?
+                              (spc->in - spc->in_min) / (spc->in_max - spc->in_min) * 100 :
+                              0.0;
+                       if (tval < *(spmin + 2 * i + 1)) {
+                               *(spmin + 2 * i + 1) = tval;
+                       }
+                       if (tval > *(spmax + 2 * i + 1)) {
+                               *(spmax + 2 * i + 1) = tval;
+                       }
+
+                       /* inV */
+                       lnappend(record_hdr->ust_time - svg_p->ust_time_ref,
+                                (double) spc->in,
+                                out + 2 * i, outsize + 2 * i, svg_p->restart);
+                       /* %in */
+                       brappend(record_hdr->ust_time - svg_p->ust_time_ref,
+                                0.0, tval,
+                                out + 2 * i + 1, outsize + 2 * i + 1, svg_p->dt);
+               }
+       }
+
+       if (action & F_END) {
+               for (i = 0; i < a->nr; i++) {
+
+                       spc = (struct stats_pwr_in *) ((char *) a->buf[curr]  + i * a->msize);
+
+                       snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
+                       item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+
+                       draw_activity_graphs(1, SVG_LINE_GRAPH,
+                                            title1, g1_title, item_name, group,
+                                            spmin + 2 * i, spmax + 2 * i, out + 2 * i, outsize + 2 * i,
+                                            svg_p, record_hdr);
+                       draw_activity_graphs(1, SVG_BAR_GRAPH,
+                                            title2, g2_title, item_name, group,
+                                            spmin + 2 * i + 1, spmax + 2 * i + 1,
+                                            out + 2 * i + 1, outsize + 2 * i + 1,
+                                            svg_p, record_hdr);
+               }
+
+               /* Free remaining structures */
+               free_graphs(out, outsize, spmin, spmax);
+       }
+}
+
 /*
  ***************************************************************************
  * Display huge pages statistics in SVG.
index b04fd2140452f6601ff426839fb2398004fdb7ce..994699bb43ce6c147867daba31ae9334c662e6d2 100644 (file)
@@ -92,6 +92,9 @@ __print_funct_t svg_print_pwr_fan_stats
 __print_funct_t svg_print_pwr_temp_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);
+__print_funct_t svg_print_pwr_in_stats
+       (struct activity *, int, int, struct svg_parm *, unsigned long long,
+        struct record_header *);
 __print_funct_t svg_print_huge_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);