Re: svn commit: r355978 - head/usr.bin/top
On 2020-01-16 04:09:58 (+1000), Tijl Coosemans wrote: On Sat, 21 Dec 2019 05:03:21 + (UTC) Philip Paeps wrote: Author: philip Date: Sat Dec 21 05:03:21 2019 New Revision: 355978 URL: https://svnweb.freebsd.org/changeset/base/355978 Log: top: display battery capacity remaining Submitted by: Antranig Vartanian Reviewed by: imp, philip Differential Revision:https://reviews.freebsd.org/D22871 Modified: head/usr.bin/top/display.c head/usr.bin/top/display.h head/usr.bin/top/machine.c head/usr.bin/top/machine.h head/usr.bin/top/top.c Modified: head/usr.bin/top/display.c == --- head/usr.bin/top/display.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/display.c Sat Dec 21 05:03:21 2019(r355978) @@ -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); It doesn't fit. There's only room for "; b": last pid: 33047; load averages: 1.17, 1.25, 1.34; b up 3+07:35:37 19:08:41 Whoops. Yeah. I just noticed too. (I only did very cursory testing of this patch - I tend not to run FreeBSD on battery-powered devices often). I'll shuffle this around a bit. Philip -- Philip Paeps Senior Reality Engineer Alternative Enterprises ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355978 - head/usr.bin/top
On Wed, Jan 15, 2020 at 07:09:58PM +0100, T??l Coosemans wrote: > On Sat, 21 Dec 2019 05:03:21 + (UTC) Philip Paeps wrote: > > New Revision: 355978 > > URL: https://svnweb.freebsd.org/changeset/base/355978 > > > > Log: > > top: display battery capacity remaining > > > > Submitted by: Antranig Vartanian > > Reviewed by: imp, philip > > Differential Revision:https://reviews.freebsd.org/D22871 > > > > @@ -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); > > It doesn't fit. There's only room for "; b": > > last pid: 33047; load averages: 1.17, 1.25, 1.34; b up 3+07:35:37 ... TBH, I don't think it belongs in that line in the first place (leaving aside the argument whether it belongs to the top(1) at all). At least it should probably be printed on its own line, with potential other power/green-related metrics, and hidden by default. ./danfe ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355978 - head/usr.bin/top
On Sat, 21 Dec 2019 05:03:21 + (UTC) Philip Paeps wrote: > Author: philip > Date: Sat Dec 21 05:03:21 2019 > New Revision: 355978 > URL: https://svnweb.freebsd.org/changeset/base/355978 > > Log: > top: display battery capacity remaining > > Submitted by: Antranig Vartanian > Reviewed by: imp, philip > Differential Revision:https://reviews.freebsd.org/D22871 > > Modified: > head/usr.bin/top/display.c > head/usr.bin/top/display.h > head/usr.bin/top/machine.c > head/usr.bin/top/machine.h > head/usr.bin/top/top.c > > Modified: head/usr.bin/top/display.c > == > --- head/usr.bin/top/display.cSat Dec 21 04:44:17 2019 > (r355977) > +++ head/usr.bin/top/display.cSat Dec 21 05:03:21 2019 > (r355978) > @@ -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); It doesn't fit. There's only room for "; b": last pid: 33047; load averages: 1.17, 1.25, 1.34; b up 3+07:35:37 19:08:41 ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r355978 - head/usr.bin/top
nice addition On Sat, 21 Dec 2019 06:03:21 +0100, Philip Paeps wrote: Author: philip Date: Sat Dec 21 05:03:21 2019 New Revision: 355978 URL: https://svnweb.freebsd.org/changeset/base/355978 Log: top: display battery capacity remaining Submitted by: Antranig Vartanian Reviewed by: imp, philip Differential Revision:https://reviews.freebsd.org/D22871 Modified: head/usr.bin/top/display.c head/usr.bin/top/display.h head/usr.bin/top/machine.c head/usr.bin/top/machine.h head/usr.bin/top/top.c Modified: head/usr.bin/top/display.c == --- head/usr.bin/top/display.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/display.c Sat Dec 21 05:03:21 2019(r355978) @@ -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 Modified: head/usr.bin/top/display.h == --- head/usr.bin/top/display.h Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/display.h Sat Dec 21 05:03:21 2019(r355978) @@ -14,6 +14,7 @@ void i_header(const char *text); voiddisplay_header(int t); int display_init(struct statics *statics); voidi_arc(int *stats); +voidi_battery(int nbat, int batt); voidi_carc(int *stats); voidi_cpustates(int *states); voidi_loadave(int mpid, double *avenrun); Modified: head/usr.bin/top/machine.c == --- head/usr.bin/top/machine.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/machine.c Sat Dec 21 05:03:21 2019(r355978) @@ -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) Modified: head/usr.bin/top/machine.h == --- head/usr.bin/top/machine.h Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/machine.h Sat Dec 21 05:03:21 2019(r355978) @@ -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; +intbattery; intncpus; }; Modified: head/usr.bin/top/top.c == --- head/usr.bin/top/top.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/top.c Sat Dec 21 05:03:21 2019(r355978) @@ -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); ___ svn-src-...@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org" ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r355978 - head/usr.bin/top
Author: philip Date: Sat Dec 21 05:03:21 2019 New Revision: 355978 URL: https://svnweb.freebsd.org/changeset/base/355978 Log: top: display battery capacity remaining Submitted by: Antranig Vartanian Reviewed by: imp, philip Differential Revision:https://reviews.freebsd.org/D22871 Modified: head/usr.bin/top/display.c head/usr.bin/top/display.h head/usr.bin/top/machine.c head/usr.bin/top/machine.h head/usr.bin/top/top.c Modified: head/usr.bin/top/display.c == --- head/usr.bin/top/display.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/display.c Sat Dec 21 05:03:21 2019(r355978) @@ -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 Modified: head/usr.bin/top/display.h == --- head/usr.bin/top/display.h Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/display.h Sat Dec 21 05:03:21 2019(r355978) @@ -14,6 +14,7 @@ void i_header(const char *text); voiddisplay_header(int t); int display_init(struct statics *statics); voidi_arc(int *stats); +voidi_battery(int nbat, int batt); voidi_carc(int *stats); voidi_cpustates(int *states); voidi_loadave(int mpid, double *avenrun); Modified: head/usr.bin/top/machine.c == --- head/usr.bin/top/machine.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/machine.c Sat Dec 21 05:03:21 2019(r355978) @@ -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) Modified: head/usr.bin/top/machine.h == --- head/usr.bin/top/machine.h Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/machine.h Sat Dec 21 05:03:21 2019(r355978) @@ -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; +intbattery; intncpus; }; Modified: head/usr.bin/top/top.c == --- head/usr.bin/top/top.c Sat Dec 21 04:44:17 2019(r355977) +++ head/usr.bin/top/top.c Sat Dec 21 05:03:21 2019(r355978) @@ -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); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"