Add new activity A_PWR_BAT.
It will enable the user to monitor battery capacity, variation and
status.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
.buf = {NULL, NULL, NULL},
.bitmap = NULL
};
-/* wrap_detect_psi */
+
+/* Battery capacity */
+struct activity pwr_bat_act = {
+ .id = A_PWR_BAT,
+ .options = AO_COUNTED + AO_GRAPH_PER_ITEM,
+ .magic = ACTIVITY_MAGIC_BASE,
+ .group = G_POWER,
+#ifdef SOURCE_SADC
+ .f_count_index = 13, /* wrap_get_bat_nr() */
+ .f_count2_index = -1,
+ .f_read = wrap_read_bat,
+#endif
+#ifdef SOURCE_SAR
+ .f_print = print_pwr_bat_stats,
+ .f_print_avg = print_avg_pwr_bat_stats,
+#endif
+#if defined(SOURCE_SAR) || defined(SOURCE_SADF)
+ .hdr_line = "BAT;%cap;%cap/min;sts",
+#endif
+ .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_xml_print = NULL, // FIXME
+ .f_json_print = NULL, // FIXME
+ .f_svg_print = NULL, // FIXME
+ .f_raw_print = NULL, // FIXME
+ .f_pcp_print = NULL, // FIXME
+ .f_count_new = NULL,
+ .item_list = NULL,
+ .desc = "Batteries capacity",
+#endif
+ .name = "A_PWR_BAT",
+ .item_list_sz = 0,
+ .g_nr = 1,
+ .nr_ini = -1,
+ .nr2 = 1,
+ .nr_max = MAX_NR_BATS,
+ .nr = {-1, -1, -1},
+ .nr_allocated = 0,
+ .fsize = STATS_PWR_BAT_SIZE,
+ .msize = STATS_PWR_BAT_SIZE,
+ .opt_flags = 0,
+ .buf = {NULL, NULL, NULL},
+ .bitmap = NULL
+};
+
#ifdef SOURCE_SADC
/*
* Array of functions used to count number of items.
wrap_get_filesystem_nr, /* 9 */
wrap_get_fchost_nr, /* 10 */
wrap_detect_psi, /* 11 */
- wrap_get_freq_nr /* 12 */
+ wrap_get_freq_nr, /* 12 */
+ wrap_get_bat_nr /* 13 */
};
#endif
&pwr_temp_act,
&pwr_in_act,
&pwr_wghfreq_act,
+ &pwr_bat_act,
&pwr_usb_act, /* AO_CLOSE_MARKUP */
/* </power-management> */
&filesystem_act,
char sc_item_name[MAX_SGR_LEN] = C_LIGHT_GREEN;
char sc_sa_restart[MAX_SGR_LEN] = C_LIGHT_RED;
char sc_sa_comment[MAX_SGR_LEN] = C_LIGHT_YELLOW;
+char sc_trend_pos[MAX_SGR_LEN] = C_BOLD_GREEN;
+char sc_trend_neg[MAX_SGR_LEN] = C_BOLD_RED;
char sc_normal[MAX_SGR_LEN] = C_NORMAL;
/*
strcpy(sc_item_name, "");
strcpy(sc_sa_comment, "");
strcpy(sc_sa_restart, "");
+ strcpy(sc_trend_pos, "");
+ strcpy(sc_trend_neg, "");
strcpy(sc_normal, "");
return;
case 'R':
snprintf(sc_sa_restart, MAX_SGR_LEN, "\e[%sm", p + 2);
break;
+ case '+':
+ snprintf(sc_trend_pos, MAX_SGR_LEN, "\e[%sm", p + 2);
+ break;
+ case '-':
+ snprintf(sc_trend_neg, MAX_SGR_LEN, "\e[%sm", p + 2);
+ break;
}
}
}
printf("%s", sc_normal);
}
+/*
+ * **************************************************************************
+ * Print trend string using selected color.
+ *
+ * IN:
+ * @trend Trend (TRUE: positive; FALSE: negative).
+ * @format Output format.
+ * @tstring String to display.
+ ***************************************************************************
+ */
+void cprintf_tr(int trend, char *format, char *tstring)
+{
+ if (trend) {
+ printf("%s", sc_trend_pos);
+ }
+ else {
+ printf("%s", sc_trend_neg);
+ }
+
+ printf(format, tstring);
+
+ printf("%s", sc_normal);
+}
+
/*
***************************************************************************
* Parse a string containing a numerical value (e.g. CPU or IRQ number).
#define DIGITS "0123456789"
#define XDIGITS "0123456789-"
+/* Batteries status */
+enum {
+ BAT_STS_UNKNOWN = 0,
+ BAT_STS_CHARGING = 1,
+ BAT_STS_DISCHARGING = 2,
+ BAT_STS_NOTCHARGING = 3,
+ BAT_STS_FULL = 4
+};
+
/*
***************************************************************************
* Macro functions definitions.
#define C_LIGHT_RED "\e[31;22m"
#define C_BOLD_RED "\e[31;1m"
#define C_LIGHT_GREEN "\e[32;22m"
+#define C_BOLD_GREEN "\e[32;1m"
#define C_LIGHT_YELLOW "\e[33;22m"
#define C_BOLD_MAGENTA "\e[35;1m"
#define C_BOLD_BLUE "\e[34;1m"
(int, int, int, ...);
void cprintf_x
(int, int, ...);
+void cprintf_tr
+ (int, char *, char *);
char *device_name
(char *);
char *get_device_name
*/
/* Number of activities */
-#define NR_ACT 42
+#define NR_ACT 43
/* The value below is used for sanity check */
#define MAX_NR_ACT 256
/* Number of functions used to count items */
-#define NR_F_COUNT 13
+#define NR_F_COUNT 14
/* Activities */
enum {
A_NET_SOFT = 39,
A_PSI_CPU = 40,
A_PSI_IO = 41,
- A_PSI_MEM = 42
+ A_PSI_MEM = 42,
+ A_PWR_BAT = 43
};
/* Macro used to flag an activity that should be collected */
#define K_IPV6 "IPV6"
#define K_POWER "POWER"
#define K_USB "USB"
+#define K_BAT "BAT"
#define K_SKIP_EMPTY "skipempty"
#define K_AUTOSCALE "autoscale"
#define MAX_NR_USB 65536
#define MAX_NR_FS (65536 * 4096)
#define MAX_NR_FCHOSTS 65536
+#define MAX_NR_BATS 4096
/* NR_MAX is the upper limit used for unknown activities */
#define NR_MAX (65536 * 4096)
(struct activity *);
__nr_t wrap_detect_psi
(struct activity *);
+__nr_t wrap_get_bat_nr
+ (struct activity *);
/* Functions used to read activities statistics */
__read_funct_t wrap_read_stat_cpu
(struct activity *);
__read_funct_t wrap_read_psimem
(struct activity *);
+__read_funct_t wrap_read_bat
+ (struct activity *);
/* Other functions */
int check_alt_sa_dir
else if (!strcmp(t, K_USB)) {
SELECT_ACTIVITY(A_PWR_USB);
}
+ else if (!strcmp(t, K_BAT)) {
+ SELECT_ACTIVITY(A_PWR_BAT);
+ }
else if (!strcmp(t, K_ALL)) {
SELECT_ACTIVITY(A_PWR_CPU);
SELECT_ACTIVITY(A_PWR_FAN);
SELECT_ACTIVITY(A_PWR_TEMP);
SELECT_ACTIVITY(A_PWR_FREQ);
SELECT_ACTIVITY(A_PWR_USB);
+ SELECT_ACTIVITY(A_PWR_BAT);
}
else
return 1;
printf(_("\t-m { <keyword> [,...] | ALL }\n"
"\t\tPower management statistics [A_PWR_...]\n"
"\t\tKeywords are:\n"
+ "\t\tBatteries capacity\n"
"\t\tCPU\tCPU instantaneous clock frequency\n"
"\t\tFAN\tFans speed\n"
"\t\tFREQ\tCPU average clock frequency\n"