]> granicus.if.org Git - sysstat/commitdiff
sadf: A_PWR_BAT: Display batteries stats in db/ppc formats
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 28 Dec 2022 13:23:30 +0000 (14:23 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 28 Dec 2022 13:23:30 +0000 (14:23 +0100)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
common.h
rndr_stats.c
rndr_stats.h
sadf.c

index decd14c674ba98090533adf81330aa94a6fc6405..9b8f679d3de829c9a6984648b0f2aac3f166ba62 100644 (file)
@@ -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
index c0d98396d2c74855c4177fb1fc16b49b107f0d2d..4c1d184333744b6503d4dc45b60ee02cfee8bd2d 100644 (file)
--- 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.
index 7897375320530458fee3bbdfbb76dd9137d6f9c9..e6ed3744a65217a5f8ecab69d7c25ba328c0e08a 100644 (file)
@@ -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]);
+       }
+}
index b749d3ca815b4dbec3182ad3809e84f8802cf6de..23cbe106d4bfc495905d5a82e0fa96e3acf6f50a 100644 (file)
@@ -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 29fdc5d1d6d895911aa69014e275e059877e6a03..6fe4d0010109f158ea45be51e474387b625f688b 100644 (file)
--- 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.