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

1
NEWS
View File

@ -11,6 +11,7 @@ procps-ng-NEXT
* pgrep: warn about 15+ char name only if -f not used * pgrep: warn about 15+ char name only if -f not used
* pkill: Return 0 only if we can kill process Debian #852758 * pkill: Return 0 only if we can kill process Debian #852758
* top: show fewer memory decimal places (configurable) * top: show fewer memory decimal places (configurable)
* top: provide command line switch for memory scaling
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|\-\fBbcHiOSs\fR \-\fBd\fR secs \-\fBn\fR max \ .ds CL \-\fBhv\fR|\-\fBbcEHiOSs\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
@ -69,7 +69,7 @@
. .
.\" Document ///////////////////////////////////////////////////////////// .\" Document /////////////////////////////////////////////////////////////
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
.TH TOP 1 "January 2017" "procps-ng" "User Commands" .TH TOP 1 "March 2017" "procps-ng" "User Commands"
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
@ -392,6 +392,20 @@ last update will not be displayed.
For additional information regarding this toggle For additional information regarding this toggle
\*(Xt 4c. TASK AREA Commands, SIZE. \*(Xt 4c. TASK AREA Commands, SIZE.
.TP 5
\-\fBE\fR\ \ :\fIExtend-Memory-Scaling\fR as:\ \ \fB-E k\fR | \fBm\fR | \fBg\fR | \fBt\fR | \fBp\fR | \fBe\fR
Instructs \*(We to force \*(SA memory to be scaled as:
.nf
k \- kibibytes
m \- mebibytes
g \- gibibytes
t \- tebibytes
p \- pebibytes
e \- exbibytes
.fi
Later this can be changed with the `E' \*(CT.
.TP 5 .TP 5
\-\fBn\fR\ \ :\fINumber-of-iterations\fR limit as:\fB\ \ \-n number \fR \-\fBn\fR\ \ :\fINumber-of-iterations\fR limit as:\fB\ \ \-n number \fR
Specifies the maximum number of iterations, or frames, \*(We should Specifies the maximum number of iterations, or frames, \*(We should

View File

@ -3191,6 +3191,15 @@ static void parse_args (char **args) {
if (0 > tmp_delay) if (0 > tmp_delay)
error_exit(N_txt(DELAY_badarg_txt)); error_exit(N_txt(DELAY_badarg_txt));
break; 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': case 'H':
Thread_mode = 1; Thread_mode = 1;
break; break;
@ -3286,7 +3295,6 @@ static void parse_args (char **args) {
default : default :
error_exit(fmtmk(N_fmt(UNKNOWN_opts_fmt) error_exit(fmtmk(N_fmt(UNKNOWN_opts_fmt)
, *cp, Myname, N_txt(USAGE_abbrev_txt))); , *cp, Myname, N_txt(USAGE_abbrev_txt)));
} // end: switch (*cp) } // end: switch (*cp)
// advance cp and jump over any numerical args used above // advance cp and jump over any numerical args used above

View File

@ -250,7 +250,7 @@ typedef long long SIC_t;
| Show_HIBOLD | Show_HIROWS | Show_IDLEPS | Show_TASKON | Show_JRNUMS \ | Show_HIBOLD | Show_HIROWS | Show_IDLEPS | Show_TASKON | Show_JRNUMS \
| Qsrt_NORMAL ) | Qsrt_NORMAL )
#define DEF_GRAPHS2 0, 0 #define DEF_GRAPHS2 0, 0
#define DEF_SCALES2 SK_Kb, SK_Kb #define DEF_SCALES2 SK_Mb, SK_Kb
#define ALT_WINFLGS DEF_WINFLGS #define ALT_WINFLGS DEF_WINFLGS
#define ALT_GRAPHS2 0, 0 #define ALT_GRAPHS2 0, 0
#else #else

View File

@ -336,7 +336,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 | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]"); Norm_nlstab[USAGE_abbrev_txt] = _(" -hv | -bcEHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]");
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");
Norm_nlstab[FAIL_tty_set_fmt] = _("failed tty set: %s"); Norm_nlstab[FAIL_tty_set_fmt] = _("failed tty set: %s");
@ -485,6 +485,7 @@ static void build_norm_nlstab (void) {
Norm_nlstab[LIB_errormem_fmt] = _("library failed memory statistics, at %d"); Norm_nlstab[LIB_errormem_fmt] = _("library failed memory statistics, at %d");
Norm_nlstab[LIB_errorcpu_fmt] = _("library failed cpu statistics, at %d"); Norm_nlstab[LIB_errorcpu_fmt] = _("library failed cpu statistics, at %d");
Norm_nlstab[LIB_errorpid_fmt] = _("library failed pids statistics, at %d"); Norm_nlstab[LIB_errorpid_fmt] = _("library failed pids statistics, at %d");
Norm_nlstab[BAD_memscale_fmt] = _("bad memory scaling arg '%c'");
} }

View File

@ -64,27 +64,27 @@ extern const char *Uniq_nlstab[];
enum norm_nls { enum norm_nls {
AMT_exxabyte_txt, AMT_gigabyte_txt, AMT_kilobyte_txt, AMT_megabyte_txt, AMT_exxabyte_txt, AMT_gigabyte_txt, AMT_kilobyte_txt, AMT_megabyte_txt,
AMT_petabyte_txt, AMT_terabyte_txt, BAD_delayint_fmt, BAD_integers_txt, AMT_petabyte_txt, AMT_terabyte_txt, BAD_delayint_fmt, BAD_integers_txt,
BAD_max_task_txt, BAD_mon_pids_fmt, BAD_niterate_fmt, BAD_numfloat_txt, BAD_max_task_txt, BAD_memscale_fmt, BAD_mon_pids_fmt, BAD_niterate_fmt,
BAD_signalid_txt, BAD_username_txt, BAD_widtharg_fmt, CHOOSE_group_txt, BAD_numfloat_txt, BAD_signalid_txt, BAD_username_txt, BAD_widtharg_fmt,
COLORS_nomap_txt, DELAY_badarg_txt, DELAY_change_fmt, DELAY_secure_txt, CHOOSE_group_txt, COLORS_nomap_txt, DELAY_badarg_txt, DELAY_change_fmt,
DISABLED_cmd_txt, DISABLED_win_fmt, EXIT_signals_fmt, FAIL_alloc_c_txt, DELAY_secure_txt, DISABLED_cmd_txt, DISABLED_win_fmt, EXIT_signals_fmt,
FAIL_alloc_r_txt, FAIL_rc_open_fmt, FAIL_re_nice_fmt, FAIL_signals_fmt, FAIL_alloc_c_txt, FAIL_alloc_r_txt, FAIL_rc_open_fmt, FAIL_re_nice_fmt,
FAIL_tty_get_txt, FAIL_tty_set_fmt, FAIL_widecpu_txt, FAIL_widepid_txt, FAIL_signals_fmt, FAIL_tty_get_txt, FAIL_tty_set_fmt, FAIL_widecpu_txt,
FIND_no_find_fmt, FIND_no_next_txt, FOREST_modes_fmt, FOREST_views_txt, FAIL_widepid_txt, FIND_no_find_fmt, FIND_no_next_txt, FOREST_modes_fmt,
GET_find_str_txt, GET_max_task_fmt, GET_nice_num_fmt, GET_pid2kill_fmt, FOREST_views_txt, GET_find_str_txt, GET_max_task_fmt, GET_nice_num_fmt,
GET_pid2nice_fmt, GET_sigs_num_fmt, GET_user_ids_txt, HELP_cmdline_fmt, GET_pid2kill_fmt, GET_pid2nice_fmt, GET_sigs_num_fmt, GET_user_ids_txt,
IRIX_curmode_fmt, LIB_errorcpu_fmt, LIB_errormem_fmt, LIB_errorpid_fmt, HELP_cmdline_fmt, IRIX_curmode_fmt, LIB_errorcpu_fmt, LIB_errormem_fmt,
LIMIT_exceed_fmt, MISSING_args_fmt, NAME_windows_fmt, NOT_onsecure_txt, LIB_errorpid_fmt, LIMIT_exceed_fmt, MISSING_args_fmt, NAME_windows_fmt,
NOT_smp_cpus_txt, NUMA_nodebad_txt, NUMA_nodeget_fmt, NUMA_nodenam_fmt, NOT_onsecure_txt, NOT_smp_cpus_txt, NUMA_nodebad_txt, NUMA_nodeget_fmt,
NUMA_nodenot_txt, OFF_one_word_txt, ON_word_only_txt, OSEL_casenot_txt, NUMA_nodenam_fmt, NUMA_nodenot_txt, OFF_one_word_txt, ON_word_only_txt,
OSEL_caseyes_txt, OSEL_errdelm_fmt, OSEL_errdups_txt, OSEL_errvalu_fmt, OSEL_casenot_txt, OSEL_caseyes_txt, OSEL_errdelm_fmt, OSEL_errdups_txt,
OSEL_prompts_fmt, OSEL_statlin_fmt, RC_bad_entry_fmt, RC_bad_files_fmt, OSEL_errvalu_fmt, OSEL_prompts_fmt, OSEL_statlin_fmt, RC_bad_entry_fmt,
SCROLL_coord_fmt, SELECT_clash_txt, THREADS_show_fmt, TIME_accumed_fmt, RC_bad_files_fmt, SCROLL_coord_fmt, SELECT_clash_txt, THREADS_show_fmt,
UNKNOWN_cmds_txt, UNKNOWN_opts_fmt, USAGE_abbrev_txt, WORD_abv_mem_txt, TIME_accumed_fmt, UNKNOWN_cmds_txt, UNKNOWN_opts_fmt, USAGE_abbrev_txt,
WORD_abv_swp_txt, WORD_allcpus_txt, WORD_another_txt, WORD_eachcpu_fmt, WORD_abv_mem_txt, WORD_abv_swp_txt, WORD_allcpus_txt, WORD_another_txt,
WORD_exclude_txt, WORD_include_txt, WORD_noneone_txt, WORD_process_txt, WORD_eachcpu_fmt, WORD_exclude_txt, WORD_include_txt, WORD_noneone_txt,
WORD_threads_txt, WRITE_rcfile_fmt, WRONG_switch_fmt, XTRA_badflds_fmt, WORD_process_txt, WORD_threads_txt, WRITE_rcfile_fmt, WRONG_switch_fmt,
XTRA_fixwide_fmt, XTRA_warncfg_txt, XTRA_winsize_txt, XTRA_badflds_fmt, XTRA_fixwide_fmt, XTRA_warncfg_txt, XTRA_winsize_txt,
#ifndef INSP_OFFDEMO #ifndef INSP_OFFDEMO
YINSP_demo01_txt, YINSP_demo02_txt, YINSP_demo03_txt, YINSP_deqfmt_txt, YINSP_demo01_txt, YINSP_demo02_txt, YINSP_demo03_txt, YINSP_deqfmt_txt,
YINSP_deqtyp_txt, YINSP_dstory_txt, YINSP_deqtyp_txt, YINSP_dstory_txt,