]> granicus.if.org Git - procps-ng/commitdiff
top: make '#define GRAPHS_ALIGN' an immutable solution
authorJim Warner <james.warner@comcast.net>
Sun, 22 Jun 2014 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Tue, 24 Jun 2014 10:35:20 +0000 (20:35 +1000)
My original graph modes implementation made no attempt
to align the Cpu & Mem/Swap graphs. I thought, rather,
that such alignment could be best achieved by the user
using top's 'E' memory scaling command toggle. In that
way Mem/Swap prefixes could be reduced by 3 positions,
bringing the beginning '[' into line with the %Cpu(s).

If that proved to be too cumbersome a #define could be
enabled making the Mem/Swap prefix static while adding
a few padding bytes to the %Cpu line(s) for alignment.
It was those waisted bytes that were the most concern.

What I had not counted on was the fact that the memory
lines themselves might become misaligned & that became
likely with more physical memory present. That too can
be cured with the 'E' command but as scaling is raised
we soon reach a meaningless total such as '0.003' even
though the displayed % remains valid (and unchanging).

So this commit implements unconditionally what used to
be conditional. But, instead of waisting padding bytes
we'll put that space to good use with a new 'total %'.

Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements,1
commit 1d171ec74163f3103e7b230ee63818df04b4526f

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c
top/top.h

index 61922b7bfc844f77b80c7e24d73e1367fc42dd31..8fb05d90e58774db547c030bb5e71f2f5666f7be 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -5070,12 +5070,8 @@ static void summary_hlp (CPU_t *cpu, const char *pfx) {
       snprintf(user, sizeof(user), gtab[ix].user, (int)(pct_user + .5), gtab[ix].type);
       snprintf(syst, sizeof(syst), gtab[ix].syst, (int)(pct_syst + .5), gtab[ix].type);
       snprintf(dual, sizeof(dual), "%s%s", user, syst);
-#ifdef GRAPHS_ALIGN
-      show_special(0, fmtmk("%%%s ~3%#5.1f~2/%-#8.1f~3 [~1%-104.104s]~1\n"
-#else
-      show_special(0, fmtmk("%%%s ~3%#5.1f~2/%-#5.1f~3 [~1%-104.104s]~1\n"
-#endif
-         , pfx, pct_user, pct_syst, dual));
+      show_special(0, fmtmk("%%%s ~3%#5.1f~2/%-#5.1f~3 %3.0f[~1%-104.104s]~1\n"
+         , pfx, pct_user, pct_syst, pct_user + pct_syst, dual));
    } else {
       show_special(0, fmtmk(Cpu_States_fmts, pfx
          , (float)u_frme * scale, (float)s_frme * scale
@@ -5229,13 +5225,7 @@ numa_nope:
          snprintf(util, sizeof(util), gtab[ix].swap, (int)(pct_swap + .5), gtab[ix].type);
          prT(bfT(0), mkM(total)); prT(bfT(1), mkS(total));
          show_special(0, fmtmk(
-#ifdef GRAPHS_ALIGN
-         /* note: without this define, cpu and memory graphs can usually be aligned via scaling
-                  (the 'E' command) and without any waisted space preceeding the cpu graphs */
             "%s %s:~3%#5.1f~2/%-9.9s~3[~1%-104.104s]~1\n%s %s:~3%#5.1f~2/%-9.9s~3[~1%-102.102s]~1\n"
-#else
-            "%s %s:~3%#5.1f~2/%-.9s~3[~1%-104.104s]~1\n%s %s:~3%#5.1f~2/%-.9s~3[~1%-102.102s]~1\n"
-#endif
             , scT(label), N_txt(WORD_abv_mem_txt), pct_used + pct_misc, bfT(0), dual
             , scT(label), N_txt(WORD_abv_swp_txt), pct_swap, bfT(1), util));
       } else {
index 5b96263cf1b2699c9a233280e687c587bbc0ad21..6f55b7ee7d2df1d8c4606459aea91edfb56468f7 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -36,7 +36,6 @@
 //#define CASEUP_SUFIX            /* show time/mem/cnts suffix in upper case */
 //#define CPU_ZEROTICS            /* tolerate few tics when cpu off vs. idle */
 //#define EQUCOLHDRYES            /* yes, do equalize column header lengths  */
-//#define GRAPHS_ALIGN            /* force cpu & memory graphs to be aligned */
 //#define INSP_JUSTNOT            /* don't smooth unprintable right margins  */
 //#define INSP_OFFDEMO            /* disable demo screens, issue msg instead */
 //#define INSP_SAVEBUF            /* preserve 'Insp_buf' contents in a file  */