aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorPhilip Paeps <philip@FreeBSD.org>2019-12-21 05:03:21 +0000
committerPhilip Paeps <philip@FreeBSD.org>2019-12-21 05:03:21 +0000
commitfc8ae86a8f2511af81db68447fa9279d26493725 (patch)
treeb3353b20126fb01ae3f5e04c2e7a233f76fd47fa /usr.bin
parent1c8102d8502ff6efddd242980a8174e51a33fe62 (diff)
downloadsrc-fc8ae86a8f2511af81db68447fa9279d26493725.tar.gz
src-fc8ae86a8f2511af81db68447fa9279d26493725.zip
top: display battery capacity remaining
Submitted by: Antranig Vartanian <antranigv@freebsd.am> Reviewed by: imp, philip Differential Revision: https://reviews.freebsd.org/D22871
Notes
Notes: svn path=/head/; revision=355978
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/top/display.c9
-rw-r--r--usr.bin/top/display.h1
-rw-r--r--usr.bin/top/machine.c16
-rw-r--r--usr.bin/top/machine.h2
-rw-r--r--usr.bin/top/top.c3
5 files changed, 31 insertions, 0 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index 38e6657401d0..5325dde87c24 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -1322,6 +1322,15 @@ i_uptime(struct timeval *bt, time_t *tod)
}
}
+void
+i_battery(int nbat, int batt)
+{
+
+ if (nbat > 0) {
+ printf("; battery: %d%%", batt);
+ }
+}
+
#define SETUPBUFFER_MIN_SCREENWIDTH 80
#define SETUPBUFFER_REQUIRED_ADDBUFSIZ 2
diff --git a/usr.bin/top/display.h b/usr.bin/top/display.h
index ff3ea8d3fe9a..76e88acb4d88 100644
--- a/usr.bin/top/display.h
+++ b/usr.bin/top/display.h
@@ -14,6 +14,7 @@ void i_header(const char *text);
void display_header(int t);
int display_init(struct statics *statics);
void i_arc(int *stats);
+void i_battery(int nbat, int batt);
void i_carc(int *stats);
void i_cpustates(int *states);
void i_loadave(int mpid, double *avenrun);
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index edfe3e659f13..b7186a6c2c2e 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -211,6 +211,10 @@ static long *pcpu_cp_old;
static long *pcpu_cp_diff;
static int *pcpu_cpu_states;
+/* Battery units and states */
+static int battery_units;
+static int battery_life;
+
static int compare_swap(const void *a, const void *b);
static int compare_jid(const void *a, const void *b);
static int compare_pid(const void *a, const void *b);
@@ -373,6 +377,12 @@ machine_init(struct statics *statics)
pcpu_cpu_states = calloc(ncpus * CPUSTATES, sizeof(int));
statics->ncpus = ncpus;
+ /* Allocate state of battery units reported via ACPI. */
+ battery_units = 0;
+ size = sizeof(int);
+ sysctlbyname("hw.acpi.battery.units", &battery_units, &size, NULL, 0);
+ statics->nbatteries = battery_units;
+
update_layout();
/* all done! */
@@ -579,6 +589,12 @@ get_system_info(struct system_info *si)
} else {
si->boottime.tv_sec = -1;
}
+
+ battery_life = 0;
+ if (battery_units > 0) {
+ GETSYSCTL("hw.acpi.battery.life", battery_life);
+ }
+ si->battery = battery_life;
}
#define NOPROC ((void *)-1)
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index c3c7777d910e..c2616e9052e3 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -30,6 +30,7 @@ struct statics
const char * const *carc_names;
const char * const *swap_names;
const char * const *order_names;
+ int nbatteries;
int ncpus;
};
@@ -50,6 +51,7 @@ struct system_info
int *carc;
int *swap;
struct timeval boottime;
+ int battery;
int ncpus;
};
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 3b317fab88b7..9853ecf914b0 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -619,6 +619,9 @@ restart:
(*d_loadave)(system_info.last_pid,
system_info.load_avg);
+ /* display the battery info (if any) */
+ i_battery(statics.nbatteries, system_info.battery);
+
/* display the current time */
/* this method of getting the time SHOULD be fairly portable */
time(&curr_time);