From f858e563b7e5013352a8c8316a90c702afd0e1a0 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 29 May 2020 00:00:00 -0500 Subject: [PATCH] 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 --- top/top.1 | 2 +- top/top.c | 59 +++++++++++++++++++++++++++++++++---------------------- top/top.h | 17 ++++++---------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/top/top.1 b/top/top.1 index 3a762cdd..7f19f601 100644 --- a/top/top.1 +++ b/top/top.1 @@ -2226,7 +2226,7 @@ While not intended to be edited manually, here is the general layout: global # line 1: the program name/alias notation " # line 2: id,altscr,irixps,delay,curwin 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 global # line 15: additional miscellaneous settings " # any remaining lines are devoted to optional diff --git a/top/top.c b/top/top.c index 46ec92c8..5c106183 100644 --- a/top/top.c +++ b/top/top.c @@ -1950,8 +1950,8 @@ static void adj_geometry (void) { if (Graph_len >= 0) Graph_len = GRAPH_actual; else if (Screen_cols > 80) Graph_len = Screen_cols - GRAPH_prefix - GRAPH_suffix; else Graph_len = 80 - GRAPH_prefix - GRAPH_suffix; - if (Screen_cols < DOUBLE_limit) Curwin->double_up = 0; - if (Curwin->double_up) { + if (Screen_cols < DOUBLE_limit) Curwin->rc.double_up = 0; + if (Curwin->rc.double_up) { Graph_len = (Screen_cols - DOUBLE_space - (2 * (GRAPH_prefix + + GRAPH_suffix))) / 2; 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 ! #endif // 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" - , &w->rc.winflags, &w->rc.sortindx, &w->rc.maxtasks, &w->rc.graph_cpus, &w->rc.graph_mems)) + if (3 > fscanf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d" + ", 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; if (w->rc.sortindx < 0 || w->rc.sortindx >= EU_MAXPFLGS) return p; @@ -3968,6 +3970,11 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) { return p; if (w->rc.graph_mems < 0 || w->rc.graph_mems > 2) 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" , &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 Rc.summ_mscale = Rc.task_mscale = SK_Kb; // 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); // fall through - case 'j': // and the next version + case 'j': // current RCF_VERSION_ID default: if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1) 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. * For each of the 4 windows: * 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 15 : miscellaneous additional global settings * 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) OFFw(q, NOHIFND_xxx | NOHISEL_xxx); #endif - q->combine_cpus = 0; + q->rc.combine_cpus = 0; } // end: win_reset @@ -4675,6 +4682,8 @@ static void wins_stage_2 (void) { capsmk(&Winstk[i]); Winstk[i].findstr = alloc_c(FNDBUFSIZ); Winstk[i].findlen = 0; + if (Winstk[i].rc.combine_cpus >= smp_num_cpus) + Winstk[i].rc.combine_cpus = 0; } if (!Batch) putp((Cursor_state = Cap_curs_hide)); @@ -5075,9 +5084,11 @@ static void write_rcfile (void) { for (i = 0 ; i < GROUPSMAX; i++) { fprintf(fp, "%s\tfieldscur=%s\n" , 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.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" , Winstk[i].rc.summclr, Winstk[i].rc.msgsclr , 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)) show_msg(N_txt(XTRA_modebad_txt)); else { - if (!w->combine_cpus) w->combine_cpus = 1; - else w->combine_cpus *= 2; - if (w->combine_cpus >= Cpu_faux_tot) w->combine_cpus = 0; + if (!w->rc.combine_cpus) w->rc.combine_cpus = 1; + else w->rc.combine_cpus *= 2; + if (w->rc.combine_cpus >= Cpu_faux_tot) w->rc.combine_cpus = 0; } break; case '1': @@ -5261,7 +5272,7 @@ static void keys_summary (int ch) { else TOGw(w, View_CPUSUM); OFFw(w, View_CPUNOD); SETw(w, View_STATES); - w->double_up = 0; + w->rc.double_up = 0; break; case '2': if (!Numa_node_tot) @@ -5271,7 +5282,7 @@ static void keys_summary (int ch) { if (!CHKw(w, View_CPUNOD)) SETw(w, View_CPUSUM); SETw(w, View_STATES); Numa_node_sel = -1; - w->double_up = 0; + w->rc.double_up = 0; } break; case '3': @@ -5284,24 +5295,24 @@ static void keys_summary (int ch) { Numa_node_sel = num; SETw(w, View_CPUNOD | View_STATES); OFFw(w, View_CPUSUM); - w->double_up = 0; + w->rc.double_up = 0; } else show_msg(N_txt(NUMA_nodebad_txt)); } } break; case '4': - w->double_up = !w->double_up; - if (w->double_up && Screen_cols < DOUBLE_limit) { + w->rc.double_up = !w->rc.double_up; + if (w->rc.double_up && Screen_cols < DOUBLE_limit) { show_msg(N_txt(XTRA_size2up_txt)); - w->double_up = 0; + w->rc.double_up = 0; break; } #ifdef TOG4_NOFORCE if (CHKw(w, (View_CPUSUM | View_CPUNOD))) - w->double_up = 0; + w->rc.double_up = 0; #else - if (w->double_up) + if (w->rc.double_up) OFFw(w, (View_CPUSUM | View_CPUNOD)); #endif break; @@ -5716,7 +5727,7 @@ static inline int cpu_prt (const char *str, int nobuf) { char *p; p = scat(row, str); - if (nobuf || !Curwin->double_up) + if (nobuf || !Curwin->rc.double_up) goto flush_it; if (!tog) { 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; 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)); n = cpu_tics(&accum, pfx, nobuf); 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); } else { // 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++) { Msg_row += cpu_unify(&Cpu_tics[i], (i+1 >= Cpu_faux_tot)); if (!isROOM(anyFLG, 1)) break; diff --git a/top/top.h b/top/top.h index 6d67cf31..34c085b3 100644 --- a/top/top.h +++ b/top/top.h @@ -373,6 +373,8 @@ typedef struct RCW_t { // the 'window' portion of an rcfile maxtasks, // user requested maximum, 0 equals all graph_cpus, // 't' - View_STATES supplementary 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 msgsclr, // " in msgs/pmts headclr, // " in cols head @@ -437,8 +439,6 @@ typedef struct WIN_t { int osel_tot; // total of other selection criteria char *findstr; // window's current/active search string 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 struct WIN_t *next, // next window in window stack *prev; // prior window in window stack @@ -595,13 +595,8 @@ typedef struct WIN_t { #define SYS_RCDEFAULTS "/etc/topdefaultrc" #define RCF_EYECATCHER "Config File (Linux processes with windows)\n" #define RCF_PLUS_H "\\]^_`abcdefghij" -#ifdef VER_J_RCFILE #define RCF_PLUS_J "klmnopqrstuvwxyz" #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 specified by the loser, oops user. @@ -630,16 +625,16 @@ typedef struct WIN_t { /* The default values for the local config file */ #define DEF_RCFILE { \ 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, \ "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, \ "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, \ "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, \ "Usr", USR_FIELDS } \ }, 0, DEF_SCALES2, 0 }