]> granicus.if.org Git - sysstat/commitdiff
sadf: A_PWR_BAT: Display batteries stats in SVG format
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 28 Dec 2022 15:11:25 +0000 (16:11 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 28 Dec 2022 15:11:25 +0000 (16:11 +0100)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
svg_stats.c
svg_stats.h

index 961e7b2dfabb9259b4c4a40705dc7f440d34dc50..23a25209f849e6850b050c9b177c70573c52c515 100644 (file)
@@ -2029,7 +2029,7 @@ struct activity pwr_bat_act = {
        .f_render       = render_pwr_bat_stats,
        .f_xml_print    = xml_print_pwr_bat_stats,
        .f_json_print   = json_print_pwr_bat_stats,
-       .f_svg_print    = NULL, // FIXME
+       .f_svg_print    = svg_print_pwr_bat_stats,
        .f_raw_print    = NULL, // FIXME
        .f_pcp_print    = NULL, // FIXME
        .f_count_new    = NULL,
index f5b1b4e18f3fc8bfe089708ab5c1f816d990d53e..5cb99aa8946923e9922454a2bb308a1a0403748b 100644 (file)
@@ -4660,6 +4660,91 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action,
        }
 }
 
+/*
+ * **************************************************************************
+ * Display batteries 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 1/100th of a second.
+ * @record_hdr Pointer on record header of current stats sample.
+ ***************************************************************************
+ */
+__print_funct_t svg_print_pwr_bat_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p,
+                                       unsigned long long itv, struct record_header *record_hdr)
+{
+       struct stats_pwr_bat *spbc;
+       int group[] = {1};
+       int g_type[] = {SVG_BAR_GRAPH};
+       char *title[] = {"Batteries capacity"};
+       char *g_title[] = {"~%cap"};
+       static double *spmin, *spmax;
+       static char **out;
+       static int *outsize;
+       char item_name[16];
+       int i;
+
+       if (action & F_BEGIN) {
+               /*
+                * Allocate arrays that will contain the graphs data
+                * and the min/max values.
+                */
+               out = allocate_graph_lines(a->item_list_sz, &outsize, &spmin, &spmax);
+       }
+
+       if (action & F_MAIN) {
+               /* For each battery */
+               for (i = 0; i < a->nr[curr]; i++) {
+
+                       spbc = (struct stats_pwr_bat *) ((char *) a->buf[curr] + i * a->msize);
+
+                       /* Look for min/max values */
+                       if (spbc->capacity < *(spmin + i)) {
+                               *(spmin + i) = spbc->capacity;
+                       }
+                       if (spbc->capacity > *(spmax + i)) {
+                               *(spmax + i) = spbc->capacity;
+                       }
+
+                       /* %cap */
+                       brappend(record_hdr->ust_time - svg_p->ust_time_ref,
+                                0.0,
+                                (unsigned int) spbc->capacity,
+                                out + i, outsize + i,
+                                svg_p->dt);
+               }
+       }
+
+       if (action & F_END) {
+               int xid = 0;
+
+               for (i = 0; i < a->item_list_sz; i++) {
+
+                       spbc = (struct stats_pwr_bat *) ((char *) a->buf[curr] + i * a->msize);
+
+                       snprintf(item_name, sizeof(item_name), "BAT%d", (int) spbc->bat_id);
+                       item_name[sizeof(item_name) - 1] = '\0';
+
+                       if (draw_activity_graphs(a->g_nr, g_type,
+                                                title, g_title, item_name, group,
+                                                spmin + i, spmax + i,
+                                                out + i, outsize + i,
+                                                svg_p, record_hdr, FALSE, a, xid)) {
+                               xid++;
+                       }
+               }
+
+               /* Free remaining structures */
+               free_graphs(out, outsize, spmin, spmax);
+       }
+}
+
 /*
  ***************************************************************************
  * Display huge pages statistics in SVG.
index 634bbf7541cb9cb053dc424b42d8b8b1333df333..ee53d3438ab096cdc95a216f45f5f191228d3469 100644 (file)
@@ -127,5 +127,8 @@ __print_funct_t svg_print_psiio_stats
 __print_funct_t svg_print_psimem_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);
+__print_funct_t svg_print_pwr_bat_stats
+       (struct activity *, int, int, struct svg_parm *, unsigned long long,
+        struct record_header *);
 
 #endif /* _SVG_STATS_H */