top: preserved those new '4' and '!' toggles in rcfile

This patch will address Craig's feedback regarding the
original implementation of top's two new toggles. It's
likely other users would have questioned why they were
not saved also, once they discover these new features.

And, since the minimum terminal width was just lowered
to 80 columns, the default for window #1 is also being
changed to show the individual cpu graphs two abreast.

[ assuming no '--disable-modern-top' for ./configure ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/172
https://www.freelists.org/post/procps/two-major-changes-to-top,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2020-05-29 00:00:00 -05:00 committed by Craig Small
parent ad6917e3cf
commit f858e563b7
3 changed files with 42 additions and 36 deletions

View File

@ -2226,7 +2226,7 @@ While not intended to be edited manually, here is the general layout:
global # line 1: the program name/alias notation global # line 1: the program name/alias notation
" # line 2: id,altscr,irixps,delay,curwin " # line 2: id,altscr,irixps,delay,curwin
per ea # line a: winname,fieldscur per ea # line a: winname,fieldscur
window # line b: winflags,sortindx,maxtasks,graph modes window # line b: winflags,sortindx,maxtasks,etc
" # line c: summclr,msgsclr,headclr,taskclr " # line c: summclr,msgsclr,headclr,taskclr
global # line 15: additional miscellaneous settings global # line 15: additional miscellaneous settings
" # any remaining lines are devoted to optional " # any remaining lines are devoted to optional

View File

@ -1950,8 +1950,8 @@ static void adj_geometry (void) {
if (Graph_len >= 0) Graph_len = GRAPH_actual; if (Graph_len >= 0) Graph_len = GRAPH_actual;
else if (Screen_cols > 80) Graph_len = Screen_cols - GRAPH_prefix - GRAPH_suffix; else if (Screen_cols > 80) Graph_len = Screen_cols - GRAPH_prefix - GRAPH_suffix;
else Graph_len = 80 - GRAPH_prefix - GRAPH_suffix; else Graph_len = 80 - GRAPH_prefix - GRAPH_suffix;
if (Screen_cols < DOUBLE_limit) Curwin->double_up = 0; if (Screen_cols < DOUBLE_limit) Curwin->rc.double_up = 0;
if (Curwin->double_up) { if (Curwin->rc.double_up) {
Graph_len = (Screen_cols - DOUBLE_space - (2 * (GRAPH_prefix + + GRAPH_suffix))) / 2; Graph_len = (Screen_cols - DOUBLE_space - (2 * (GRAPH_prefix + + GRAPH_suffix))) / 2;
if (Graph_len > GRAPH_actual) Graph_len = GRAPH_actual; if (Graph_len > GRAPH_actual) Graph_len = GRAPH_actual;
} }
@ -3957,8 +3957,10 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
#error Hey, fix the above fscanf 'PFLAGSSIZ' dependency ! #error Hey, fix the above fscanf 'PFLAGSSIZ' dependency !
#endif #endif
// be tolerant of missing release 3.3.10 graph modes additions // be tolerant of missing release 3.3.10 graph modes additions
if (3 > fscanf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d\n" if (3 > fscanf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d"
, &w->rc.winflags, &w->rc.sortindx, &w->rc.maxtasks, &w->rc.graph_cpus, &w->rc.graph_mems)) ", double_up=%d, combine_cpus=%d\n"
, &w->rc.winflags, &w->rc.sortindx, &w->rc.maxtasks, &w->rc.graph_cpus, &w->rc.graph_mems
, &w->rc.double_up, &w->rc.combine_cpus))
return p; return p;
if (w->rc.sortindx < 0 || w->rc.sortindx >= EU_MAXPFLGS) if (w->rc.sortindx < 0 || w->rc.sortindx >= EU_MAXPFLGS)
return p; return p;
@ -3968,6 +3970,11 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
return p; return p;
if (w->rc.graph_mems < 0 || w->rc.graph_mems > 2) if (w->rc.graph_mems < 0 || w->rc.graph_mems > 2)
return p; return p;
if (w->rc.double_up < 0 || w->rc.double_up > 1)
return p;
// can't check upper bounds until smp_num_cpus known
if (w->rc.combine_cpus < 0)
return p;
if (4 != fscanf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n" if (4 != fscanf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, &w->rc.summclr, &w->rc.msgsclr, &w->rc.headclr, &w->rc.taskclr)) , &w->rc.summclr, &w->rc.msgsclr, &w->rc.headclr, &w->rc.taskclr))
@ -3994,10 +4001,10 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) {
// these next 2 are really global, but best documented here // these next 2 are really global, but best documented here
Rc.summ_mscale = Rc.task_mscale = SK_Kb; Rc.summ_mscale = Rc.task_mscale = SK_Kb;
// fall through // fall through
case 'i': // actual RCF_VERSION_ID case 'i': // from 3.3.10 thru 3.3.16
scat(w->rc.fieldscur, RCF_PLUS_J); scat(w->rc.fieldscur, RCF_PLUS_J);
// fall through // fall through
case 'j': // and the next version case 'j': // current RCF_VERSION_ID
default: default:
if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1) if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
return p; return p;
@ -4071,7 +4078,7 @@ static int configs_path (const char *const fmts, ...) {
* line 2 : an id, Mode_altcsr, Mode_irixps, Delay_time, Curwin. * line 2 : an id, Mode_altcsr, Mode_irixps, Delay_time, Curwin.
* For each of the 4 windows: * For each of the 4 windows:
* line a: contains w->winname, fieldscur * line a: contains w->winname, fieldscur
* line b: contains w->winflags, sortindx, maxtasks, graph modes * line b: contains w->winflags, sortindx, maxtasks, etc
* line c: contains w->summclr, msgsclr, headclr, taskclr * line c: contains w->summclr, msgsclr, headclr, taskclr
* line 15 : miscellaneous additional global settings * line 15 : miscellaneous additional global settings
* Any remaining lines are devoted to the optional entries * Any remaining lines are devoted to the optional entries
@ -4428,7 +4435,7 @@ static void win_reset (WIN_t *q) {
// NOHISEL_xxx is redundant (already turned off by osel_clear) // NOHISEL_xxx is redundant (already turned off by osel_clear)
OFFw(q, NOHIFND_xxx | NOHISEL_xxx); OFFw(q, NOHIFND_xxx | NOHISEL_xxx);
#endif #endif
q->combine_cpus = 0; q->rc.combine_cpus = 0;
} // end: win_reset } // end: win_reset
@ -4675,6 +4682,8 @@ static void wins_stage_2 (void) {
capsmk(&Winstk[i]); capsmk(&Winstk[i]);
Winstk[i].findstr = alloc_c(FNDBUFSIZ); Winstk[i].findstr = alloc_c(FNDBUFSIZ);
Winstk[i].findlen = 0; Winstk[i].findlen = 0;
if (Winstk[i].rc.combine_cpus >= smp_num_cpus)
Winstk[i].rc.combine_cpus = 0;
} }
if (!Batch) if (!Batch)
putp((Cursor_state = Cap_curs_hide)); putp((Cursor_state = Cap_curs_hide));
@ -5075,9 +5084,11 @@ static void write_rcfile (void) {
for (i = 0 ; i < GROUPSMAX; i++) { for (i = 0 ; i < GROUPSMAX; i++) {
fprintf(fp, "%s\tfieldscur=%s\n" fprintf(fp, "%s\tfieldscur=%s\n"
, Winstk[i].rc.winname, Winstk[i].rc.fieldscur); , Winstk[i].rc.winname, Winstk[i].rc.fieldscur);
fprintf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d\n" fprintf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d"
", double_up=%d, combine_cpus=%d\n"
, Winstk[i].rc.winflags, Winstk[i].rc.sortindx, Winstk[i].rc.maxtasks , Winstk[i].rc.winflags, Winstk[i].rc.sortindx, Winstk[i].rc.maxtasks
, Winstk[i].rc.graph_cpus, Winstk[i].rc.graph_mems); , Winstk[i].rc.graph_cpus, Winstk[i].rc.graph_mems
, Winstk[i].rc.double_up, Winstk[i].rc.combine_cpus);
fprintf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n" fprintf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, Winstk[i].rc.summclr, Winstk[i].rc.msgsclr , Winstk[i].rc.summclr, Winstk[i].rc.msgsclr
, Winstk[i].rc.headclr, Winstk[i].rc.taskclr); , Winstk[i].rc.headclr, Winstk[i].rc.taskclr);
@ -5251,9 +5262,9 @@ static void keys_summary (int ch) {
if (CHKw(w, View_CPUSUM) || CHKw(w, View_CPUNOD)) if (CHKw(w, View_CPUSUM) || CHKw(w, View_CPUNOD))
show_msg(N_txt(XTRA_modebad_txt)); show_msg(N_txt(XTRA_modebad_txt));
else { else {
if (!w->combine_cpus) w->combine_cpus = 1; if (!w->rc.combine_cpus) w->rc.combine_cpus = 1;
else w->combine_cpus *= 2; else w->rc.combine_cpus *= 2;
if (w->combine_cpus >= Cpu_faux_tot) w->combine_cpus = 0; if (w->rc.combine_cpus >= Cpu_faux_tot) w->rc.combine_cpus = 0;
} }
break; break;
case '1': case '1':
@ -5261,7 +5272,7 @@ static void keys_summary (int ch) {
else TOGw(w, View_CPUSUM); else TOGw(w, View_CPUSUM);
OFFw(w, View_CPUNOD); OFFw(w, View_CPUNOD);
SETw(w, View_STATES); SETw(w, View_STATES);
w->double_up = 0; w->rc.double_up = 0;
break; break;
case '2': case '2':
if (!Numa_node_tot) if (!Numa_node_tot)
@ -5271,7 +5282,7 @@ static void keys_summary (int ch) {
if (!CHKw(w, View_CPUNOD)) SETw(w, View_CPUSUM); if (!CHKw(w, View_CPUNOD)) SETw(w, View_CPUSUM);
SETw(w, View_STATES); SETw(w, View_STATES);
Numa_node_sel = -1; Numa_node_sel = -1;
w->double_up = 0; w->rc.double_up = 0;
} }
break; break;
case '3': case '3':
@ -5284,24 +5295,24 @@ static void keys_summary (int ch) {
Numa_node_sel = num; Numa_node_sel = num;
SETw(w, View_CPUNOD | View_STATES); SETw(w, View_CPUNOD | View_STATES);
OFFw(w, View_CPUSUM); OFFw(w, View_CPUSUM);
w->double_up = 0; w->rc.double_up = 0;
} else } else
show_msg(N_txt(NUMA_nodebad_txt)); show_msg(N_txt(NUMA_nodebad_txt));
} }
} }
break; break;
case '4': case '4':
w->double_up = !w->double_up; w->rc.double_up = !w->rc.double_up;
if (w->double_up && Screen_cols < DOUBLE_limit) { if (w->rc.double_up && Screen_cols < DOUBLE_limit) {
show_msg(N_txt(XTRA_size2up_txt)); show_msg(N_txt(XTRA_size2up_txt));
w->double_up = 0; w->rc.double_up = 0;
break; break;
} }
#ifdef TOG4_NOFORCE #ifdef TOG4_NOFORCE
if (CHKw(w, (View_CPUSUM | View_CPUNOD))) if (CHKw(w, (View_CPUSUM | View_CPUNOD)))
w->double_up = 0; w->rc.double_up = 0;
#else #else
if (w->double_up) if (w->rc.double_up)
OFFw(w, (View_CPUSUM | View_CPUNOD)); OFFw(w, (View_CPUSUM | View_CPUNOD));
#endif #endif
break; break;
@ -5716,7 +5727,7 @@ static inline int cpu_prt (const char *str, int nobuf) {
char *p; char *p;
p = scat(row, str); p = scat(row, str);
if (nobuf || !Curwin->double_up) if (nobuf || !Curwin->rc.double_up)
goto flush_it; goto flush_it;
if (!tog) { if (!tog) {
scat(p, Double_sp); scat(p, Double_sp);
@ -5823,7 +5834,7 @@ static int cpu_unify (CPU_t *cpu, int nobuf) {
accum.sav.y += cpu->sav.y; accum.sav.z += cpu->sav.z; accum.sav.y += cpu->sav.y; accum.sav.z += cpu->sav.z;
if (!ix) beg = cpu->id; if (!ix) beg = cpu->id;
if (nobuf || ix >= Curwin->combine_cpus) { if (nobuf || ix >= Curwin->rc.combine_cpus) {
snprintf(pfx, sizeof(pfx), "%-7.7s:", fmtmk("%d-%d", beg, cpu->id)); snprintf(pfx, sizeof(pfx), "%-7.7s:", fmtmk("%d-%d", beg, cpu->id));
n = cpu_tics(&accum, pfx, nobuf); n = cpu_tics(&accum, pfx, nobuf);
memset(&accum, 0, sizeof(CPU_t)); memset(&accum, 0, sizeof(CPU_t));
@ -5979,7 +5990,7 @@ numa_nope:
Msg_row += cpu_tics(&Cpu_tics[smp_num_cpus], N_txt(WORD_allcpus_txt), 1); Msg_row += cpu_tics(&Cpu_tics[smp_num_cpus], N_txt(WORD_allcpus_txt), 1);
} else { } else {
// display each cpu's states separately, screen height permitting... // display each cpu's states separately, screen height permitting...
if (w->combine_cpus) { if (w->rc.combine_cpus) {
for (i = 0; i < Cpu_faux_tot; i++) { for (i = 0; i < Cpu_faux_tot; i++) {
Msg_row += cpu_unify(&Cpu_tics[i], (i+1 >= Cpu_faux_tot)); Msg_row += cpu_unify(&Cpu_tics[i], (i+1 >= Cpu_faux_tot));
if (!isROOM(anyFLG, 1)) break; if (!isROOM(anyFLG, 1)) break;

View File

@ -373,6 +373,8 @@ typedef struct RCW_t { // the 'window' portion of an rcfile
maxtasks, // user requested maximum, 0 equals all maxtasks, // user requested maximum, 0 equals all
graph_cpus, // 't' - View_STATES supplementary vals graph_cpus, // 't' - View_STATES supplementary vals
graph_mems, // 'm' - View_MEMORY supplememtary vals graph_mems, // 'm' - View_MEMORY supplememtary vals
double_up, // '4' - show individual cpus 2 abreast
combine_cpus, // '!' - keep combining additional cpus
summclr, // a colors 'number' used for summ info summclr, // a colors 'number' used for summ info
msgsclr, // " in msgs/pmts msgsclr, // " in msgs/pmts
headclr, // " in cols head headclr, // " in cols head
@ -437,8 +439,6 @@ typedef struct WIN_t {
int osel_tot; // total of other selection criteria int osel_tot; // total of other selection criteria
char *findstr; // window's current/active search string char *findstr; // window's current/active search string
int findlen; // above's strlen, without call overhead int findlen; // above's strlen, without call overhead
int double_up; // show individual cpus 2 abreast
int combine_cpus; // keep combining additional cpus
proc_t **ppt; // this window's proc_t ptr array proc_t **ppt; // this window's proc_t ptr array
struct WIN_t *next, // next window in window stack struct WIN_t *next, // next window in window stack
*prev; // prior window in window stack *prev; // prior window in window stack
@ -595,13 +595,8 @@ typedef struct WIN_t {
#define SYS_RCDEFAULTS "/etc/topdefaultrc" #define SYS_RCDEFAULTS "/etc/topdefaultrc"
#define RCF_EYECATCHER "Config File (Linux processes with windows)\n" #define RCF_EYECATCHER "Config File (Linux processes with windows)\n"
#define RCF_PLUS_H "\\]^_`abcdefghij" #define RCF_PLUS_H "\\]^_`abcdefghij"
#ifdef VER_J_RCFILE
#define RCF_PLUS_J "klmnopqrstuvwxyz" #define RCF_PLUS_J "klmnopqrstuvwxyz"
#define RCF_VERSION_ID 'j' #define RCF_VERSION_ID 'j'
#else
#define RCF_VERSION_ID 'i'
#define RCF_PLUS_J ""
#endif
/* The default fields displayed and their order, if nothing is /* The default fields displayed and their order, if nothing is
specified by the loser, oops user. specified by the loser, oops user.
@ -630,16 +625,16 @@ typedef struct WIN_t {
/* The default values for the local config file */ /* The default values for the local config file */
#define DEF_RCFILE { \ #define DEF_RCFILE { \
RCF_VERSION_ID, 0, 1, DEF_DELAY, 0, { \ RCF_VERSION_ID, 0, 1, DEF_DELAY, 0, { \
{ EU_CPU, DEF_WINFLGS, 0, DEF_GRAPHS2, \ { EU_CPU, DEF_WINFLGS, 0, DEF_GRAPHS2, 1, 0, \
COLOR_RED, COLOR_RED, COLOR_YELLOW, COLOR_RED, \ COLOR_RED, COLOR_RED, COLOR_YELLOW, COLOR_RED, \
"Def", DEF_FIELDS }, \ "Def", DEF_FIELDS }, \
{ EU_PID, ALT_WINFLGS, 0, ALT_GRAPHS2, \ { EU_PID, ALT_WINFLGS, 0, ALT_GRAPHS2, 0, 0, \
COLOR_CYAN, COLOR_CYAN, COLOR_WHITE, COLOR_CYAN, \ COLOR_CYAN, COLOR_CYAN, COLOR_WHITE, COLOR_CYAN, \
"Job", JOB_FIELDS }, \ "Job", JOB_FIELDS }, \
{ EU_MEM, ALT_WINFLGS, 0, ALT_GRAPHS2, \ { EU_MEM, ALT_WINFLGS, 0, ALT_GRAPHS2, 0, 0, \
COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLUE, COLOR_MAGENTA, \ COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLUE, COLOR_MAGENTA, \
"Mem", MEM_FIELDS }, \ "Mem", MEM_FIELDS }, \
{ EU_UEN, ALT_WINFLGS, 0, ALT_GRAPHS2, \ { EU_UEN, ALT_WINFLGS, 0, ALT_GRAPHS2, 0, 0, \
COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \ COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \
"Usr", USR_FIELDS } \ "Usr", USR_FIELDS } \
}, 0, DEF_SCALES2, 0 } }, 0, DEF_SCALES2, 0 }