top: provide the means to adjust scaled summary memory

Earlier this year, the switch from KiB to Mib as shown
in top's summary area was postponed to those occasions
when KiB exceeded 8 digits. In hindsight that may have
moved top in the wrong direction, given the difficulty
of digesting such large numbers of digits at a glance.

This commit adds a new 'E' interactive command used to
cycle the displayed memory amounts ranging from KiB to
TiB. Thus, users can choose the radix they wish shown.

p.s. and it will be rcfile preserved for any restarts!

(now that we know a '.' + 2 spaces is squeezed to one)
(everything's perfectly justified, but it's just luck)

Reference(s):
http://www.freelists.org/post/procps/top-regression-reports

commit 95f2201730
Author: James Cloos <cloos@jhcloos.com>
Date:   Mon Feb 6 00:00:00 2012 -0500

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2012-12-14 00:00:00 -06:00
committed by Craig Small
parent 407d1fc8f2
commit bc46f67f9a
5 changed files with 86 additions and 43 deletions

View File

@ -3065,7 +3065,7 @@ static void configs_read (void) {
} // end: for (GROUPSMAX)
// any new addition(s) last, for older rcfiles compatibility...
fscanf(fp, "Fixed_widest=%d\n", &Rc.fixed_widest);
fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d\n", &Rc.fixed_widest, &Rc.summ_mscale);
try_inspect_entries:
@ -3653,7 +3653,7 @@ static void file_writerc (void) {
}
// any new addition(s) last, for older rcfiles compatibility...
fprintf(fp, "Fixed_widest=%d\n", Rc.fixed_widest);
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d\n", Rc.fixed_widest, Rc.summ_mscale);
if (Inspect.raw)
fputs(Inspect.raw, fp);
@ -3769,6 +3769,10 @@ static void keys_global (int ch) {
if (-1 < tmp) Rc.delay_time = tmp;
}
break;
case 'E':
// current summary_show limits: 0 == kilo through 3 == tera
if (++Rc.summ_mscale > 3) Rc.summ_mscale = 0;
break;
case 'F':
case 'f':
fields_utility();
@ -4307,7 +4311,7 @@ static void do_key (int ch) {
char keys[SMLBUFSIZ];
} key_tab[] = {
{ keys_global,
{ '?', 'B', 'd', 'F', 'f', 'g', 'H', 'h', 'I', 'k', 'r', 's', 'X', 'Y', 'Z'
{ '?', 'B', 'd', 'E', 'F', 'f', 'g', 'H', 'h', 'I', 'k', 'r', 's', 'X', 'Y', 'Z'
, kbd_ENTER, kbd_SPACE, '\0' } },
{ keys_summary,
{ '1', 'C', 'l', 'm', 't', '\0' } },
@ -4461,23 +4465,47 @@ static void summary_show (void) {
// Display Memory and Swap stats
if (isROOM(View_MEMORY, 2)) {
#define mkM(x) (unsigned long)(kb_main_ ## x >> shift)
#define mkS(x) (unsigned long)(kb_swap_ ## x >> shift)
const char *which = N_txt(AMT_kilobyte_txt);
int shift = 0;
#define bfT(n) buftab[n].buf
#define scT(e) scaletab[Rc.summ_mscale]. e
#define mkM(x) (float)kb_main_ ## x / scT(div)
#define mkS(x) (float)kb_swap_ ## x / scT(div)
#define prT(b,z) { if (9 < snprintf(b, 10, scT(fmts), z)) b[8] = '+'; }
static struct {
float div;
const char *fmts;
const char *label;
} scaletab[] = {
{ 1, "%8.0f ", NULL }, // kilo
{ 1024.0, "%#5.2f ", NULL }, // mega
{ 1024.0*1024, "%#4.3f ", NULL }, // giga
{ 1024.0*1024*1024, "%#3.4f ", NULL } // tera
};
struct {
// after snprintf, contents of each buf: 'nnnnnnnn 0'
// and prT macro might replace space at buf[8] with: ---> +
char buf[10]; // MEMORY_lines_fmt provides for 8+1 bytes
} buftab[8];
/*** hotplug_acclimated ***/
if (kb_main_total > 99999999)
{ which = N_txt(AMT_megabyte_txt); shift = 10; }
if (kb_main_total > 9999999999ull)
{ which = N_txt(AMT_gigabyte_txt); shift = 20; }
if (!scaletab[0].label) {
scaletab[0].label = N_txt(AMT_kilobyte_txt);
scaletab[1].label = N_txt(AMT_megabyte_txt);
scaletab[2].label = N_txt(AMT_gigabyte_txt);
scaletab[3].label = N_txt(AMT_terabyte_txt);
}
prT(bfT(0), mkM(total)); prT(bfT(1), mkM(used));
prT(bfT(2), mkM(free)); prT(bfT(3), mkM(buffers));
prT(bfT(4), mkS(total)); prT(bfT(5), mkS(used));
prT(bfT(6), mkS(free)); prT(bfT(7), mkM(cached));
show_special(0, fmtmk(N_unq(MEMORY_lines_fmt)
, which, mkM(total), mkM(used), mkM(free), mkM(buffers)
, which, mkS(total), mkS(used), mkS(free), mkM(cached)));
, scT(label), &bfT(0), &bfT(1), &bfT(2), &bfT(3)
, scT(label), &bfT(4), &bfT(5), &bfT(6), &bfT(7)));
Msg_row += 2;
#undef bfT
#undef scT
#undef mkM
#undef mkS
#undef prT
}
#undef isROOM