top: enhance memory graphs two abreast summary display

This patch introduces a new #define TOG4_MEM_FIX which
serves to turn off the new feature it also implements.

The feature, on by default, provides a flexible memory
graph approach which strives to always keep its visual
separator in alignment with cpu separators seen above.

Below is a summary of the algorithm implementing this:

1) First, ascertain the widest graph which corresponds
to the largest number of cpu graphs but doesn't exceed
maximum allowable graph width (i.e. GRAPH_length_max).

2) Next, apply that to the graphed 'Mem' portion which
is likely to remain entirely visible. However, it will
grow or shrink depending on total adjacent cpu graphs.

3) Last, the same width is used for the 'Swap' portion
but that graph is considered sacrificial and very well
could be truncated depending on the width of a screen.

[ along the way, when the cpu graphs revert to their ]
[ abbreviated form, the memory graphs will also show ]
[ an abbreviated prefix. in this way the widths will ]
[ also be maximized, reducing potential distortions. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-09-18 00:00:00 -05:00 committed by Craig Small
parent bf916fdf04
commit 602146a623
2 changed files with 53 additions and 5 deletions

View File

@ -2083,21 +2083,46 @@ static void adj_geometry (void) {
if (Curwin->rc.double_up) {
int num = (Curwin->rc.double_up + 1);
int pfx = (Curwin->rc.double_up < 2) ? GRAPH_prefix_std : GRAPH_prefix_abv;
Graph_cpus->length = (Screen_cols - (ADJOIN_space * Curwin->rc.double_up) - (num * (pfx + GRAPH_suffix))) / num;
Graph_mems->length = (Screen_cols - ADJOIN_space - (2 * (GRAPH_prefix_std + GRAPH_suffix))) / 2;
if (Graph_cpus->length > GRAPH_length_max) Graph_cpus->length = GRAPH_length_max;
if (Graph_cpus->length < GRAPH_length_min) Graph_cpus->length = GRAPH_length_min;
Graph_mems->length = (Screen_cols - ADJOIN_space - (2 * (pfx + GRAPH_suffix))) / 2;
if (Graph_mems->length > GRAPH_length_max) Graph_mems->length = GRAPH_length_max;
if (Graph_mems->length < GRAPH_length_min) Graph_mems->length = GRAPH_length_min;
#if !defined(TOG4_MEM_FIX) && !defined(TOG4_MEM_1UP)
if (num > 2) {
#define cpuGRAPH ( GRAPH_prefix_abv + Graph_cpus->length + GRAPH_suffix )
#define nxtGRAPH ( cpuGRAPH + ADJOIN_space )
int len = cpuGRAPH;
for (;;) {
if (len + nxtGRAPH > GRAPH_length_max) break;
len += nxtGRAPH;
}
len -= (GRAPH_prefix_abv + ADJOIN_space);
Graph_mems->length = len;
#undef cpuGRAPH
#undef nxtGRAPH
}
#endif
} else {
Graph_cpus->length = Screen_cols - (GRAPH_prefix_std + GRAPH_length_max + GRAPH_suffix);
if (Graph_cpus->length >= 0) Graph_cpus->length = GRAPH_length_max;
else Graph_cpus->length = Screen_cols - GRAPH_prefix_std - GRAPH_suffix;
if (Graph_cpus->length < GRAPH_length_min) Graph_cpus->length = GRAPH_length_min;
#ifdef TOG4_MEM_1UP
Graph_mems->length = (Screen_cols - (GRAPH_prefix_std + GRAPH_suffix));
if (Graph_mems->length > GRAPH_length_max) Graph_mems->length = GRAPH_length_max;
if (Graph_mems->length < GRAPH_length_min) Graph_mems->length = GRAPH_length_min;
#else
Graph_mems->length = Graph_cpus->length;
#endif
}
if (Graph_cpus->length < GRAPH_length_min) Graph_cpus->length = GRAPH_length_min;
if (Graph_cpus->length > GRAPH_length_max) Graph_cpus->length = GRAPH_length_max;
Graph_cpus->adjust = (float)Graph_cpus->length / 100.0;
Graph_cpus->style = Curwin->rc.graph_cpus;
if (Graph_mems->length < GRAPH_length_min) Graph_mems->length = GRAPH_length_min;
if (Graph_mems->length > GRAPH_length_max) Graph_mems->length = GRAPH_length_max;
Graph_mems->adjust = (float)Graph_mems->length / 100.0;
Graph_mems->style = Curwin->rc.graph_mems;
@ -6468,18 +6493,40 @@ static void do_memory (void) {
Graph_mems->part1 = my_misc;
Graph_mems->part2 = my_used;
rx = sum_rx(Graph_mems);
#ifdef TOG4_MEM_1UP
prT(bfT(0), mkM(MEM_VAL(mem_TOT)));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_mem_txt), rx->pcnt_tot, bfT(0), rx->graph);
#else
if (Curwin->rc.double_up > 1)
snprintf(row, sizeof(row), "%s %s~3%3.0f%s"
, scT(label), N_txt(WORD_abv_mem_txt), rx->pcnt_tot, rx->graph);
else {
prT(bfT(0), mkM(MEM_VAL(mem_TOT)));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_mem_txt), rx->pcnt_tot, bfT(0), rx->graph);
}
#endif
Msg_row += sum_see(row, mem2UP);
Graph_mems->total = MEM_VAL(swp_TOT);
Graph_mems->part1 = 0;
Graph_mems->part2 = MEM_VAL(swp_USE);
rx = sum_rx(Graph_mems);
#ifdef TOG4_MEM_1UP
prT(bfT(1), mkM(MEM_VAL(swp_TOT)));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_two, bfT(1), rx->graph);
#else
if (Curwin->rc.double_up > 1)
snprintf(row, sizeof(row), "%s %s~3%3.0f%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_tot, rx->graph);
else {
prT(bfT(1), mkM(MEM_VAL(swp_TOT)));
snprintf(row, sizeof(row), "%s %s:~3%#5.1f~2/%-9.9s~3%s"
, scT(label), N_txt(WORD_abv_swp_txt), rx->pcnt_two, bfT(1), rx->graph);
}
#endif
Msg_row += sum_see(row, 1);
} else {

View File

@ -61,6 +61,7 @@
//#define THREADED_MEM /* separate background thread for mem updt */
//#define THREADED_TSK /* separate background thread for tsk updt */
//#define TOG4_MEM_1UP /* don't show two abreast memory statistic */
//#define TOG4_MEM_FIX /* no variable mem graphs, thus misaligned */
//#define TOG4_SEP_OFF /* don't show two abreast visual separator */
//#define TOG4_SEP_STD /* normal mem sep if 2 abreast & no graphs */
//#define TREE_NORESET /* sort keys should not force 'V' view off */