]> granicus.if.org Git - sysstat/commitdiff
sadf: A_PWR_BAT: Add f_count_new() function
authorSebastien GODARD <sysstat@users.noreply.github.com>
Thu, 29 Dec 2022 10:11:09 +0000 (11:11 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Thu, 29 Dec 2022 10:11:09 +0000 (11:11 +0100)
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 <sysstat@users.noreply.github.com>
activity.c
sa.h
sadf_misc.c

index fd4ccffa90bd156fd4c9831b52e5f56139397f9f..8b58168e4f6d91d5b79dd8a52e22e984c1af1786 100644 (file)
@@ -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 50b6315bde06794303817e2c437938e61da9134f..4c212839c0560f02ba646e945457a6b7f2d79b9d 100644 (file)
--- 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
index 432fda04f0e10709c62d09092b2c5ab6d6d0c1f3..8e04c5f6954861983459469db8f6e4b4a10ae699 100644 (file)
@@ -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).