top: provide -E command line switch for memory scaling

In their 3.2.7 version of top, Redhat introduced an -M
switch to automatically scale Summary Area memory data
to avoid truncation (and the resulting '+' indicator).

The procps-ng top does not employ suffixes with memory
data nor does it allow for different scaling with each
separate value. Rather, scaling appears at line start.

If built without ./configure --disable-modern-top, the
Summary Area memory will be scaled at GiB which should
lessen chance of truncation. Otherwise KiB was used to
reflect such memory, increasing the truncation chance.

And while 'W' can be used to preserve some appropriate
scaling value, there are arguments against such rcfile
approaches as cited in the issue and bug report below.

So this commit will bump the Summary Area memory scale
factor from KiB to MiB when using --disable-modern-top
as a concession to that Redhat bug report noted below.

And it also introduces a new command line switch which
can force any desired scaling regardless of the rcfile
or which ./configure option might have been specified.

[ for top's help text we'll show 'E' as if it were a ]
[ switch without arguments in order to keep the help ]
[ text displayable without wrap in an 80x24 terminal ]

[ the man page, however, will show all k-e arguments ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/53
https://bugzilla.redhat.com/show_bug.cgi?id=1034466

[ this patch has been adapted from the master branch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2017-03-13 04:00:00 -05:00
committed by Craig Small
parent f318be467b
commit b2bd65407a
6 changed files with 50 additions and 26 deletions

View File

@ -3191,6 +3191,15 @@ static void parse_args (char **args) {
if (0 > tmp_delay)
error_exit(N_txt(DELAY_badarg_txt));
break;
case 'E':
{ const char *get = "kmgtpe", *got;
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if (!(got = strchr(get, tolower(*cp))))
error_exit(fmtmk(N_fmt(BAD_memscale_fmt), *cp));
Rc.summ_mscale = (int)(got - get);
} break;
case 'H':
Thread_mode = 1;
break;
@ -3286,7 +3295,6 @@ static void parse_args (char **args) {
default :
error_exit(fmtmk(N_fmt(UNKNOWN_opts_fmt)
, *cp, Myname, N_txt(USAGE_abbrev_txt)));
} // end: switch (*cp)
// advance cp and jump over any numerical args used above