From 6bb60ec445389326c8f89802b0ef15d67efb7a19 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 28 Dec 2022 16:11:25 +0100 Subject: [PATCH] sadf: A_PWR_BAT: Display batteries stats in SVG format Signed-off-by: Sebastien GODARD --- activity.c | 2 +- svg_stats.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ svg_stats.h | 3 ++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/activity.c b/activity.c index 961e7b2..23a2520 100644 --- a/activity.c +++ b/activity.c @@ -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, diff --git a/svg_stats.c b/svg_stats.c index f5b1b4e..5cb99aa 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -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. diff --git a/svg_stats.h b/svg_stats.h index 634bbf7..ee53d34 100644 --- a/svg_stats.h +++ b/svg_stats.h @@ -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 */ -- 2.40.0