top: provide -1 command line switch as 'Cpu(s)' toggle

If built without ./configure --disable-modern-top, the
program displays each cpu individually providing there
is sufficient vertical screen real estate. For massive
SMP environments this will necessitate use of a config
file where the cpu summary toggle ('1') could be saved
via the 'W' command. But, an rcfile may not be viable.

So this commit introduces a '1' command line switch to
emulate exactly the effects of the interactive toggle.

And since it is our first numeric switch some existing
parsing logic had to be changed slightly. Such changes
are, in truth, an improvement. For example, instead of
seeing "inappropriate '2'" with ./top -2 we'll now see
the vastly more appropriate error "unknown option '2'.

References(s):
https://gitlab.com/procps-ng/procps/issues/55

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-03-10 00:00:00 -06:00 committed by Craig Small
parent fb48b5d9fb
commit 89db82d143
4 changed files with 22 additions and 6 deletions

1
NEWS
View File

@ -13,6 +13,7 @@ procps-ng-NEXT
* kill: -l space between name parses correctly Debian #854407 * kill: -l space between name parses correctly Debian #854407
* top: show fewer memory decimal places (configurable) * top: show fewer memory decimal places (configurable)
* top: provide command line switch for memory scaling * top: provide command line switch for memory scaling
* top: provide command line switch for CPU States
procps-ng-3.3.12 procps-ng-3.3.12
---------------- ----------------

View File

@ -32,7 +32,7 @@
.ds CI interactive command .ds CI interactive command
\# - Note: our 'Command Line' used in 2 places \# - Note: our 'Command Line' used in 2 places
\# ( and managed to fit in an 80x24 terminal ) \# ( and managed to fit in an 80x24 terminal )
.ds CL \-\fBhv\fR|\-\fBbcEHiOSs\fR \-\fBd\fR secs \-\fBn\fR max \ .ds CL \-\fBhv\fR|\-\fBbcEHiOSs1\fR \-\fBd\fR secs \-\fBn\fR max \
\-\fBu\fR|\fBU\fR user \-\fBp\fR pid \-\fBo\fR fld \-\fBw\fR [cols] \fR \-\fBu\fR|\fBU\fR user \-\fBp\fR pid \-\fBo\fR fld \-\fBw\fR [cols] \fR
.ds CO command\-line option .ds CO command\-line option
.ds CT command toggle .ds CT command toggle
@ -252,7 +252,7 @@ All are explained in detail in the sections that follow.
l \- Load Avg/Uptime On (thus program name) l \- Load Avg/Uptime On (thus program name)
t \- Task/Cpu states On (1+1 lines, see `1') t \- Task/Cpu states On (1+1 lines, see `1')
m \- Mem/Swap usage On (2 lines worth) m \- Mem/Swap usage On (2 lines worth)
1 \- Single Cpu Off (thus multiple cpus) * 1 \- Single Cpu Off (thus multiple cpus)
\fITask-Area-defaults\fR \fITask-Area-defaults\fR
b \- Bold hilite Off (use `reverse') b \- Bold hilite Off (use `reverse')
* c \- Command line Off (name, not cmdline) * c \- Command line Off (name, not cmdline)
@ -486,6 +486,15 @@ in Batch mode actual terminal dimensions can never be exceeded.
\*(NT Without the use of this \*(CO, output width is always based on the \*(NT Without the use of this \*(CO, output width is always based on the
terminal at which \*(We was invoked whether or not in Batch mode. terminal at which \*(We was invoked whether or not in Batch mode.
.TP 5
\-\fB1\fR\ \ :\fISingle/Separate-Cpu-States\fR toggle \fR
Starts \*(We with the last remembered Cpu States portion of the \*(SA reversed.
Either all \*(Pu information will be displayed in a single line or
each \*(Pu will be displayed separately, depending on the state of the NUMA Node
\*(CT ('2').
\*(XC `1' and '2' \*(CIs for additional information.
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
.SH 2. SUMMARY Display .SH 2. SUMMARY Display
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------

View File

@ -3650,6 +3650,7 @@ static void parse_args (char **args) {
. bunched args are actually handled properly and none are ignored . bunched args are actually handled properly and none are ignored
. we tolerate NO whitespace and NO switches -- maybe too tolerant? */ . we tolerate NO whitespace and NO switches -- maybe too tolerant? */
static const char numbs_str[] = "+,-.0123456789"; static const char numbs_str[] = "+,-.0123456789";
static const char wrong_str[] = "+,-.";
float tmp_delay = FLT_MAX; float tmp_delay = FLT_MAX;
int i; int i;
@ -3666,10 +3667,16 @@ static void parse_args (char **args) {
case '-': case '-':
if (cp[1]) ++cp; if (cp[1]) ++cp;
else if (*args) cp = *args++; else if (*args) cp = *args++;
if (strspn(cp, numbs_str)) if (strspn(cp, wrong_str))
error_exit(fmtmk(N_fmt(WRONG_switch_fmt) error_exit(fmtmk(N_fmt(WRONG_switch_fmt)
, cp, Myname, N_txt(USAGE_abbrev_txt))); , cp, Myname, N_txt(USAGE_abbrev_txt)));
continue; continue;
case '1': // ensure behavior identical to run-time toggle
if (CHKw(Curwin, View_CPUNOD)) OFFw(Curwin, View_CPUSUM);
else TOGw(Curwin, View_CPUSUM);
OFFw(Curwin, View_CPUNOD);
SETw(Curwin, View_STATES);
break;
case 'b': case 'b':
Batch = 1; Batch = 1;
break; break;
@ -3769,8 +3776,7 @@ static void parse_args (char **args) {
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch)); else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if ((errmsg = user_certify(Curwin, cp, ch))) error_exit(errmsg); if ((errmsg = user_certify(Curwin, cp, ch))) error_exit(errmsg);
cp += strlen(cp); cp += strlen(cp);
break; } break;
}
case 'w': case 'w':
{ const char *pn = NULL; { const char *pn = NULL;
int ai = 0, ci = 0; int ai = 0, ci = 0;

View File

@ -338,7 +338,7 @@ static void build_norm_nlstab (void) {
Norm_nlstab[OFF_one_word_txt] = _("Off"); Norm_nlstab[OFF_one_word_txt] = _("Off");
/* Translation Hint: Only the following words should be translated /* Translation Hint: Only the following words should be translated
. secs (seconds), max (maximum), user, field, cols (columns)*/ . secs (seconds), max (maximum), user, field, cols (columns)*/
Norm_nlstab[USAGE_abbrev_txt] = _(" -hv | -bcEHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]"); Norm_nlstab[USAGE_abbrev_txt] = _(" -hv | -bcEHiOSs1 -d secs -n max -u|U user -p pid(s) -o field -w [cols]");
Norm_nlstab[FAIL_statget_txt] = _("failed /proc/stat read"); Norm_nlstab[FAIL_statget_txt] = _("failed /proc/stat read");
Norm_nlstab[FOREST_modes_fmt] = _("Forest mode %s"); Norm_nlstab[FOREST_modes_fmt] = _("Forest mode %s");
Norm_nlstab[FAIL_tty_get_txt] = _("failed tty get"); Norm_nlstab[FAIL_tty_get_txt] = _("failed tty get");