From 6090d88690895ad2b01a9cb4130081aad5e8a886 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 28 Dec 2022 15:18:51 +0100 Subject: [PATCH] sadf: A_PWR_BAT: Display batteries stats in XML format Signed-off-by: Sebastien GODARD --- activity.c | 2 +- xml_stats.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ xml_stats.h | 2 ++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/activity.c b/activity.c index 9b8f679..df57586 100644 --- a/activity.c +++ b/activity.c @@ -2027,7 +2027,7 @@ struct activity pwr_bat_act = { .ftypes_nr = {0, 0, 0}, #ifdef SOURCE_SADF .f_render = render_pwr_bat_stats, - .f_xml_print = NULL, // FIXME + .f_xml_print = xml_print_pwr_bat_stats, .f_json_print = NULL, // FIXME .f_svg_print = NULL, // FIXME .f_raw_print = NULL, // FIXME diff --git a/xml_stats.c b/xml_stats.c index d48524f..635c78e 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -36,6 +36,7 @@ #endif extern uint64_t flags; +extern char bat_status[][16]; /* *************************************************************************** @@ -2472,3 +2473,56 @@ close_xml_markup: xml_markup_psi(tab, CLOSE_XML_MARKUP); } } + +/* + * ************************************************************************** + * Display battery statistics in XML. + * + * IN: + * @a Activity structure with statistics. + * @curr Index in array for current sample statistics. + * @tab Indentation in XML output. + * @itv Interval of time in 1/100th of a second. + *************************************************************************** + */ +__print_funct_t xml_print_pwr_bat_stats(struct activity *a, int curr, int tab, + unsigned long long itv) +{ + int i; + struct stats_pwr_bat *spbc, *spbp; + + if (!IS_SELECTED(a->options) || (a->nr[curr] <= 0)) + goto close_xml_markup; + + xml_markup_power_management(tab, OPEN_XML_MARKUP); + tab++; + + xprintf(tab++, ""); + + for (i = 0; i < a->nr[curr]; i++) { + + spbc = (struct stats_pwr_bat *) ((char *) a->buf[curr] + i * a->msize); + spbp = (struct stats_pwr_bat *) ((char *) a->buf[!curr] + i * a->msize); + + /* Battery status code should not be greater than or equal to BAT_STS_NR */ + if (spbc->status >= BAT_STS_NR) { + spbc->status = 0; + } + xprintf(tab, "", + spbc->bat_id, + (unsigned int) spbc->capacity, + (double) (spbc->capacity - spbp->capacity) * 6000 / itv, + bat_status[(unsigned int) spbc->status]); + } + + xprintf(--tab, ""); + tab--; + +close_xml_markup: + if (CLOSE_MARKUP(a->options)) { + xml_markup_power_management(tab, CLOSE_XML_MARKUP); + } +} diff --git a/xml_stats.h b/xml_stats.h index aa1cf69..6c7c2f3 100644 --- a/xml_stats.h +++ b/xml_stats.h @@ -99,5 +99,7 @@ __print_funct_t xml_print_psiio_stats (struct activity *, int, int, unsigned long long); __print_funct_t xml_print_psimem_stats (struct activity *, int, int, unsigned long long); +__print_funct_t xml_print_pwr_bat_stats + (struct activity *, int, int, unsigned long long); #endif /* _XML_STATS_H */ -- 2.40.0