From 6924a10cedbf69dd2891925d7c4a07f6935236b2 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Thu, 29 Dec 2022 11:11:09 +0100 Subject: [PATCH] sadf: A_PWR_BAT: Add f_count_new() function This function is aimed at creating a list of battery names that will later be used to create PCP instances. Signed-off-by: Sebastien GODARD --- activity.c | 2 +- sa.h | 2 ++ sadf_misc.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/activity.c b/activity.c index fd4ccff..8b58168 100644 --- a/activity.c +++ b/activity.c @@ -2032,7 +2032,7 @@ struct activity pwr_bat_act = { .f_svg_print = svg_print_pwr_bat_stats, .f_raw_print = raw_print_pwr_bat_stats, .f_pcp_print = NULL, // FIXME - .f_count_new = NULL, + .f_count_new = count_new_bat, .item_list = NULL, .desc = "Batteries capacity", #endif diff --git a/sa.h b/sa.h index 50b6315..4c21283 100644 --- a/sa.h +++ b/sa.h @@ -1388,6 +1388,8 @@ __nr_t count_new_fchost (struct activity *, int); __nr_t count_new_disk (struct activity *, int); +__nr_t count_new_bat + (struct activity *, int); /* Functions used to count number of items */ __nr_t wrap_get_cpu_nr diff --git a/sadf_misc.c b/sadf_misc.c index 432fda0..8e04c5f 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -1691,6 +1691,39 @@ __nr_t count_new_int(struct activity *a, int curr) return nr; } +/* + * ************************************************************************** + * Count the number of new batteries in current sample. If a new + * battery is found then add it to the linked list starting at + * @a->item_list. + * Mainly useful to create a list of battery names (BATx) that will be used + * as instance names for sadf PCP output format. + * + * IN: + * @a Activity structure with statistics. + * @curr Index in array for current sample statistics. + * + * RETURNS: + * Number of new batteries identified in current sample that were not + * previously in the list. + *************************************************************************** + */ +__nr_t count_new_bat(struct activity *a, int curr) +{ + int i, nr = 0; + struct stats_pwr_bat *spbc; + char bat_name[16]; + + for (i = 0; i < a->nr[curr]; i++) { + spbc = (struct stats_pwr_bat *) ((char *) a->buf[curr] + i * a->msize); + + snprintf(bat_name, sizeof(bat_name), "BAT%d", (int) spbc->bat_id); + nr += add_list_item(&(a->item_list), bat_name, sizeof(bat_name)); + } + + return nr; +} + /* *************************************************************************** * Init custom color palette used to draw graphs (sadf -g). -- 2.40.0