From 73137628aad7adafdab65fb5dcefcda830b595cd Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 28 Dec 2022 14:23:30 +0100 Subject: [PATCH] sadf: A_PWR_BAT: Display batteries stats in db/ppc formats Signed-off-by: Sebastien GODARD --- activity.c | 2 +- common.h | 3 +++ rndr_stats.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ rndr_stats.h | 2 ++ sadf.c | 9 +++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/activity.c b/activity.c index decd14c..9b8f679 100644 --- a/activity.c +++ b/activity.c @@ -2026,7 +2026,7 @@ struct activity pwr_bat_act = { .gtypes_nr = {STATS_PWR_BAT_ULL, STATS_PWR_BAT_UL, STATS_PWR_BAT_U}, .ftypes_nr = {0, 0, 0}, #ifdef SOURCE_SADF - .f_render = NULL, // FIXME + .f_render = render_pwr_bat_stats, .f_xml_print = NULL, // FIXME .f_json_print = NULL, // FIXME .f_svg_print = NULL, // FIXME diff --git a/common.h b/common.h index c0d9839..4c1d184 100644 --- a/common.h +++ b/common.h @@ -129,6 +129,9 @@ enum { BAT_STS_FULL = 4 }; +/* Number of different statuses */ +#define BAT_STS_NR 5 + /* *************************************************************************** * Macro functions definitions. diff --git a/rndr_stats.c b/rndr_stats.c index 7897375..e6ed374 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -38,6 +38,7 @@ char *seps[] = {"\t", ";"}; extern uint64_t flags; +extern char bat_status[][16]; /* *************************************************************************** @@ -3449,3 +3450,53 @@ __print_funct_t render_psimem_stats(struct activity *a, int isdb, char *pre, ((double) psic->full_mem_total - psip->full_mem_total) / (100 * itv), NULL); } + +/* + * ************************************************************************** + * Display battery statistics in selected format. + * + * IN: + * @a Activity structure with statistics. + * @isdb Flag, true if db printing, false if ppc printing. + * @pre Prefix string for output entries + * @curr Index in array for current sample statistics. + * @itv Interval of time in 1/100th of a second. + *************************************************************************** + */ +__print_funct_t render_pwr_bat_stats(struct activity *a, int isdb, char *pre, + int curr, unsigned long long itv) +{ + int i; + struct stats_pwr_bat *spbc, *spbp; + int pt_newlin + = PT_NOFLAG + (DISPLAY_HORIZONTALLY(flags) ? 0 : PT_NEWLIN); + + 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); + + render(isdb, pre, PT_USEINT, + "BAT%d\t%%cap", "%d", + cons(iv, spbc->bat_id, NOVAL), + (unsigned int) spbc->capacity, + NOVAL, NULL); + + render(isdb, pre, PT_NOFLAG, + "BAT%d\t%%cap/min", NULL, + cons(iv, spbc->bat_id, NOVAL), + NOVAL, + (double) (spbc->capacity - spbp->capacity) * 6000 / itv, + NULL); + + /* Battery status code should not be greater than or equal to BAT_STS_NR */ + if (spbc->status >= BAT_STS_NR) { + spbc->status = 0; + } + render(isdb, pre, PT_USESTR | pt_newlin, + "BAT%d\tstatus", NULL, + cons(iv, spbc->bat_id, NOVAL), + NOVAL, NOVAL, + bat_status[(unsigned int) spbc->status]); + } +} diff --git a/rndr_stats.h b/rndr_stats.h index b749d3c..23cbe10 100644 --- a/rndr_stats.h +++ b/rndr_stats.h @@ -130,5 +130,7 @@ __print_funct_t render_psiio_stats (struct activity *, int, char *, int, unsigned long long); __print_funct_t render_psimem_stats (struct activity *, int, char *, int, unsigned long long); +__print_funct_t render_pwr_bat_stats + (struct activity *, int, char *, int, unsigned long long); #endif /* _RNDR_STATS_H */ diff --git a/sadf.c b/sadf.c index 29fdc5d..6fe4d00 100644 --- a/sadf.c +++ b/sadf.c @@ -96,6 +96,15 @@ char my_tzname[TZNAME_LEN]; extern struct activity *act[]; extern struct report_format *fmt[]; +/* Battery status */ +char bat_status[][16] = { + "Unknown", + "Charging", + "Discharging", + "NotCharging", + "Full" +}; + /* *************************************************************************** * Print usage and exit. -- 2.50.1