Commit fe6e03d8 authored by jim warner's avatar jim warner Committed by Craig Small

top: show fewer decimal places for memory (by default)

After much reflection I've come to the conclusion that
displaying 3 decimal places (usually) when memory data
had been scaled is no longer optimal with today's ever
increasing amounts. And given that not all task memory
fields are the same widths, inconsistencies can easily
arise as illustrated and discussed in the issue below.

Instead of unilaterally reducing the number of decimal
places, this commit will sneak in such a change via an
existing configure option that was very likely unused.

The former 'disable-wide-memory' option has now become
'enable-wide-memory', which can be used if the current
behavior (3 decimal places) is preferred. Without that
option, whenever memory is scaled beyond KiB, just one
decimal place will be shown in Summary and Task areas.

And Task area field width will no longer be changed by
this revised configure option. Instead, all such field
widths will now be fixed at the former maximum values.

Reference(s):
#50Signed-off-by: jim warner's avatarJim Warner <james.warner@comcast.net>
parent ddcdba18
......@@ -11,6 +11,7 @@ procps-ng-NEXT
* pgrep: warn about 15+ char name only if -f not used
* pkill: Return 0 only if we can kill process Debian #852758
* kill: -l space between name parses correctly Debian #854407
* top: show fewer memory decimal places (configurable)
procps-ng-3.3.12
----------------
......
......@@ -201,11 +201,11 @@ if test "x$enable_wide_percent" = xyes; then
fi
AC_ARG_ENABLE([wide-memory],
AS_HELP_STRING([--disable-wide-memory], [disable extra precision under memory fields for top]),
[], [enable_wide_memory=yes]
AS_HELP_STRING([--enable-wide-memory], [provide extra precision under memory fields for top]),
[], [enable_wide_memory=no]
)
if test "x$enable_wide_memory" = xno; then
AC_DEFINE(NOBOOST_MEMS, 1, [disable extra precision under memory fields for top])
if test "x$enable_wide_memory" = xyes; then
AC_DEFINE(BOOST_MEMORY, 1, [provide extra precision under memory fields for top])
fi
AC_ARG_ENABLE([modern-top],
......
......@@ -1548,11 +1548,11 @@ static inline const char *make_str (const char *str, int width, int justr, int c
* We'll interpret 'num' as a kibibytes quantity and try to
* format it to reach 'target' while also fitting 'width'. */
static const char *scale_mem (int target, unsigned long num, int width, int justr) {
#ifndef NOBOOST_MEMS
// SK_Kb SK_Mb SK_Gb SK_Tb SK_Pb SK_Eb
#ifdef BOOST_MEMORY
static const char *fmttab[] = { "%.0f", "%#.1f%c", "%#.3f%c", "%#.3f%c", "%#.3f%c", NULL };
#else
static const char *fmttab[] = { "%.0f", "%.0f%c", "%.0f%c", "%.0f%c", "%.0f%c", NULL };
static const char *fmttab[] = { "%.0f", "%.1f%c", "%.1f%c", "%.1f%c", "%.1f%c", NULL };
#endif
static char buf[SMLBUFSIZ];
float scaled_num;
......@@ -1757,21 +1757,12 @@ static FLD_t Fieldstab[] = {
#else
{ 4, -1, A_right, SF(RES), L_statm }, // EU_MEM slot
#endif
#ifndef NOBOOST_MEMS
{ 7, SK_Kb, A_right, SF(VRT), L_statm },
{ 6, SK_Kb, A_right, SF(SWP), L_status },
{ 6, SK_Kb, A_right, SF(RES), L_statm },
{ 6, SK_Kb, A_right, SF(COD), L_statm },
{ 7, SK_Kb, A_right, SF(DAT), L_statm },
{ 6, SK_Kb, A_right, SF(SHR), L_statm },
#else
{ 5, SK_Kb, A_right, SF(VRT), L_statm },
{ 4, SK_Kb, A_right, SF(SWP), L_status },
{ 4, SK_Kb, A_right, SF(RES), L_statm },
{ 4, SK_Kb, A_right, SF(COD), L_statm },
{ 5, SK_Kb, A_right, SF(DAT), L_statm },
{ 4, SK_Kb, A_right, SF(SHR), L_statm },
#endif
{ 4, -1, A_right, SF(FL1), L_stat },
{ 4, -1, A_right, SF(FL2), L_stat },
{ 4, -1, A_right, SF(DRT), L_statm },
......@@ -1788,11 +1779,7 @@ static FLD_t Fieldstab[] = {
{ -1, -1, A_left, SF(ENV), L_ENVIRON },
{ 3, -1, A_right, SF(FV1), L_stat },
{ 3, -1, A_right, SF(FV2), L_stat },
#ifndef NOBOOST_MEMS
{ 6, SK_Kb, A_right, SF(USE), L_status },
#else
{ 4, SK_Kb, A_right, SF(USE), L_status },
#endif
{ 10, -1, A_right, SF(NS1), L_NS }, // IPCNS
{ 10, -1, A_right, SF(NS2), L_NS }, // MNTNS
{ 10, -1, A_right, SF(NS3), L_NS }, // NETNS
......@@ -1800,17 +1787,10 @@ static FLD_t Fieldstab[] = {
{ 10, -1, A_right, SF(NS5), L_NS }, // USERNS
{ 10, -1, A_right, SF(NS6), L_NS }, // UTSNS
{ 8, -1, A_left, SF(LXC), L_LXC },
#ifndef NOBOOST_MEMS
{ 6, SK_Kb, A_right, SF(RZA), L_status },
{ 6, SK_Kb, A_right, SF(RZF), L_status },
{ 6, SK_Kb, A_right, SF(RZL), L_status },
{ 6, SK_Kb, A_right, SF(RZS), L_status },
#else
{ 4, SK_Kb, A_right, SF(RZA), L_status },
{ 4, SK_Kb, A_right, SF(RZF), L_status },
{ 4, SK_Kb, A_right, SF(RZL), L_status },
{ 4, SK_Kb, A_right, SF(RZS), L_status },
#endif
{ -1, -1, A_left, SF(CGN), L_CGROUP }
#undef SF
#undef A_left
......@@ -5254,12 +5234,20 @@ numa_nope:
const char *fmts;
const char *label;
} scaletab[] = {
{ 1, "%1.0f ", NULL }, // kibibytes
{ 1024.0, "%#4.3f ", NULL }, // mebibytes
{ 1024.0*1024, "%#4.3f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#4.3f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#4.3f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#4.3f ", NULL } // exbibytes
{ 1, "%.0f ", NULL }, // kibibytes
#ifdef BOOST_MEMORY
{ 1024.0, "%#.3f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.3f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.3f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.3f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.3f ", NULL } // exbibytes
#else
{ 1024.0, "%#.1f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.1f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.1f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.1f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.1f ", NULL } // exbibytes
#endif
};
struct { // 0123456789
// snprintf contents of each buf (after SK_Kb): 'nnnn.nnn 0'
......
......@@ -23,8 +23,8 @@
#include "../proc/readproc.h"
/* Defines represented in configure.ac ----------------------------- */
//#define BOOST_PERCNT /* enable extra precision for two % fields */
//#define NOBOOST_MEMS /* disable extra precision for mem fields */
//#define BOOST_MEMORY /* enable extra precision for mem fields */
//#define BOOST_PERCNT /* enable extra precision for 2 % fields */
//#define NUMA_DISABLE /* disable summary area NUMA/Nodes display */
//#define ORIG_TOPDEFS /* with no rcfile retain original defaults */
//#define SIGNALS_LESS /* favor reduced signal load over response */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment