]> granicus.if.org Git - sysstat/commitdiff
SVG: Add SVG output for temperature sensors statistics
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 15 Apr 2016 12:50:48 +0000 (14:50 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 15 Apr 2016 12:50:48 +0000 (14:50 +0200)
These graphs correspond to the output of "sar -m TEMP".

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

index a3fc1e38991dabd641c976007866d5476e1e5e76..46cbac08f925b31441895ca05b2324bd94f7ae9e 100644 (file)
@@ -1116,7 +1116,7 @@ struct activity pwr_fan_act = {
 /* Temperature */
 struct activity pwr_temp_act = {
        .id             = A_PWR_TEMP,
-       .options        = AO_NULL,
+       .options        = AO_GRAPH_PER_ITEM,
        .magic          = ACTIVITY_MAGIC_BASE,
        .group          = G_POWER,
 #ifdef SOURCE_SADC
@@ -1132,9 +1132,10 @@ struct activity pwr_temp_act = {
        .f_render       = render_pwr_temp_stats,
        .f_xml_print    = xml_print_pwr_temp_stats,
        .f_json_print   = json_print_pwr_temp_stats,
+       .f_svg_print    = svg_print_pwr_temp_stats,
        .hdr_line       = "TEMP;DEVICE;degC;%temp",
        .name           = "A_PWR_TEMP",
-       .g_nr           = 0,
+       .g_nr           = 2,
 #endif
        .nr             = -1,
        .nr2            = 1,
index 32155800849a723592766b9a2036e140fb572014..3e642ef4142bb941c41e5eb8ac57ca01506207f7 100644 (file)
@@ -1926,3 +1926,100 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action
                free_graphs(out, outsize, spmin, spmax);
        }
 }
+
+/*
+ ***************************************************************************
+ * Display temperature 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 a pointer on a record header structure
+ *             (.@record_hdr) containing the first stats sample.
+ * @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_temp_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_temp *spc;
+       int group[] = {1};
+       char *title[] = {"Device temperature"};
+       char *g1_title[] = {"~degC"};
+       char *g2_title[] = {"%temp"};
+       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_temp *) ((char *) a->buf[curr]  + i * a->msize);
+
+                       /* Look for min/max values */
+                       if (spc->temp < *(spmin + 2 * i)) {
+                               *(spmin + 2 * i) = spc->temp;
+                       }
+                       if (spc->temp > *(spmax + 2 * i)) {
+                               *(spmax + 2 * i) = spc->temp;
+                       }
+                       tval = (spc->temp_max - spc->temp_min) ?
+                              (spc->temp - spc->temp_min) / (spc->temp_max - spc->temp_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;
+                       }
+
+                       /* degC */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                (double) spc->temp,
+                                out + 2 * i, outsize + 2 * i, svg_p->restart);
+                       /* %temp */
+                       brappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                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_temp *) ((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,
+                                            title, 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,
+                                            title, 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);
+       }
+}
index 467951bee39af11ab4b5c35192317e2c4bc88cba..815c7c2830a24103d2bedb5437771a46f3343100 100644 (file)
@@ -41,5 +41,8 @@ __print_funct_t svg_print_pwr_cpufreq_stats
 __print_funct_t svg_print_pwr_fan_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);
+__print_funct_t svg_print_pwr_temp_stats
+       (struct activity *, int, int, struct svg_parm *, unsigned long long,
+        struct record_header *);
        
 #endif /* _SVG_STATS_H */