top: afford each window its own cpu/memory graph modes

When those new cpu/memory graphs modes were introduced
they had global impact. In other words, the modes that
were chosen for a 'current' window affect Summary Area
appearance for every other window as well, even though
each window sets unique View_STATES/View_MEMORY flags.

I do not know how widespread the use of top's separate
window provisions is, but I do know that documentation
promises every window (field group) provides "a unique
separately configurable summary area". And even though
that promise does not include memory scaling (separate
'E' command) the graph modes are integral to 't' & 'm'
and those were already observed on a per window basis.

So this patch just takes the cpu and memory graph mode
values out of global scope in the configuration file &
gives each window its own unique pair of graph values.

Reference(s):
commit 1d171ec741

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2014-06-27 00:00:00 -05:00 committed by Craig Small
parent 805532ac32
commit 96c330e3b3
3 changed files with 47 additions and 45 deletions

View File

@ -2046,7 +2046,7 @@ 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
window # line b: winflags,sortindx,maxtasks,graph modes
" # line c: summclr,msgsclr,headclr,taskclr
global # line 15: additional miscellaneous settings
" # any remaining lines are devoted to the

View File

@ -3457,7 +3457,7 @@ static int config_cvt (WIN_t *q) {
* 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
* line b: contains w->winflags, sortindx, maxtasks, graph modes
* line c: contains w->summclr, msgsclr, headclr, taskclr
* line 15 : miscellaneous additional global settings
* Any remaining lines are devoted to the 'Inspect Other' feature */
@ -3511,8 +3511,9 @@ static void configs_read (void) {
// too bad fscanf is not as flexible with his format string as snprintf
# error Hey, fix the above fscanf 'PFLAGSSIZ' dependency !
#endif
if (3 != fscanf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d\n"
, &w->rc.winflags, &w->rc.sortindx, &w->rc.maxtasks))
// 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))
goto default_or_error;
if (4 != fscanf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, &w->rc.summclr, &w->rc.msgsclr
@ -3522,13 +3523,16 @@ static void configs_read (void) {
switch (Rc.id) {
case 'a': // 3.2.8 (former procps)
if (config_cvt(w))
goto default_or_error; // fall through !
case 'f': // 3.3.0 thru 3.3.3 (procps-ng)
SETw(w, Show_JRNUMS); // fall through !
case 'g': // 3.3.4 thru 3.3.8
scat(w->rc.fieldscur, RCF_PLUS_H); // fall through !
case 'h': // current RCF_VERSION_ID
default: // and future versions?
goto default_or_error;
case 'f': // 3.3.0 thru 3.3.3 (ng)
SETw(w, Show_JRNUMS);
case 'g': // from 3.3.4 thru 3.3.8
scat(w->rc.fieldscur, RCF_PLUS_H);
case 'h': // this is release 3.3.9
/* w->rc.graph_cpus = 0; */// for documentation only, since
/* w->rc.graph_mems = 0; */// DEF_RCFILE zeroes them for us
case 'i': // actual RCF_VERSION_ID
default: // and a future version?
if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
goto default_or_error;
for (x = 0; x < EU_MAXPFLGS; ++x)
@ -3542,9 +3546,8 @@ static void configs_read (void) {
} // end: for (GROUPSMAX)
// any new addition(s) last, for older rcfiles compatibility...
if (fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d, Graph_cpus=%d, Graph_mems=%d\n"
, &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress
, &Rc.graph_cpus, &Rc.graph_mems))
if (fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress))
; // avoid -Wunused-result
try_inspect_entries:
@ -4349,18 +4352,17 @@ 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\n"
, Winstk[i].rc.winflags, Winstk[i].rc.sortindx
, Winstk[i].rc.maxtasks);
fprintf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d\n"
, Winstk[i].rc.winflags, Winstk[i].rc.sortindx, Winstk[i].rc.maxtasks
, Winstk[i].rc.graph_cpus, Winstk[i].rc.graph_mems);
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);
}
// any new addition(s) last, for older rcfiles compatibility...
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d, Graph_cpus=%d, Graph_mems=%d\n"
, Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress
, Rc.graph_cpus, Rc.graph_mems);
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress);
if (Inspect.raw)
fputs(Inspect.raw, fp);
@ -4544,16 +4546,16 @@ static void keys_summary (int ch) {
case 'm':
if (!CHKw(w, View_MEMORY))
SETw(w, View_MEMORY);
else if (++Rc.graph_mems > 2) {
Rc.graph_mems = 0;;
else if (++w->rc.graph_mems > 2) {
w->rc.graph_mems = 0;;
OFFw(w, View_MEMORY);
}
break;
case 't':
if (!CHKw(w, View_STATES))
SETw(w, View_STATES);
else if (++Rc.graph_cpus > 2) {
Rc.graph_cpus = 0;;
else if (++w->rc.graph_cpus > 2) {
w->rc.graph_cpus = 0;;
OFFw(w, View_STATES);
}
break;
@ -5080,7 +5082,7 @@ static void summary_hlp (CPU_t *cpu, const char *pfx) {
/* display some kinda' cpu state percentages
(who or what is explained by the passed prefix) */
if (Rc.graph_cpus) {
if (Curwin->rc.graph_cpus) {
static struct {
const char *user, *syst, *type;
} gtab[] = {
@ -5088,7 +5090,7 @@ static void summary_hlp (CPU_t *cpu, const char *pfx) {
{ "%-.*s~4", "%-.*s~6", Graph_blks }
};
char user[SMLBUFSIZ], syst[SMLBUFSIZ], dual[MEDBUFSIZ];
int ix = Rc.graph_cpus - 1;
int ix = Curwin->rc.graph_cpus - 1;
float pct_user = (float)(u_frme + n_frme) * scale,
pct_syst = (float)s_frme * scale;
snprintf(user, sizeof(user), gtab[ix].user, (int)((pct_user * Graph_adj) + .5), gtab[ix].type);
@ -5231,7 +5233,7 @@ numa_nope:
}
kb_main_my_used = kb_main_used - kb_main_buffers - kb_main_cached;
if (Rc.graph_mems) {
if (w->rc.graph_mems) {
static struct {
const char *used, *misc, *swap, *type;
} gtab[] = {
@ -5239,7 +5241,7 @@ numa_nope:
{ "%-.*s~4", "%-.*s~6", "%-.*s~6", Graph_blks }
};
char used[SMLBUFSIZ], util[SMLBUFSIZ], dual[MEDBUFSIZ];
int ix = Rc.graph_mems - 1;
int ix = w->rc.graph_mems - 1;
float pct_used = (float)kb_main_my_used * (100.0 / (float)kb_main_total),
pct_misc = (float)(kb_main_buffers + kb_main_cached) * (100.0 / (float)kb_main_total),
pct_swap = (float)kb_swap_used * (100.0 / (float)kb_swap_total);

View File

@ -343,15 +343,17 @@ enum warn_enum {
/* This type helps support both a window AND the rcfile */
typedef struct RCW_t { // the 'window' portion of an rcfile
int sortindx, // sort field, represented as a procflag
winflags, // 'view', 'show' and 'sort' mode flags
maxtasks, // user requested maximum, 0 equals all
summclr, // color num used in summ info
msgsclr, // " in msgs/pmts
headclr, // " in cols head
taskclr; // " in task rows
char winname [WINNAMSIZ], // window name, user changeable
fieldscur [PFLAGSSIZ]; // fields displayed and ordered
int sortindx, // sort field (represented as procflag)
winflags, // 'view', 'show' and 'sort' mode flags
maxtasks, // user requested maximum, 0 equals all
graph_cpus, // 't' - View_STATES supplementary vals
graph_mems, // 'm' - View_MEMORY supplememtary vals
summclr, // a colors 'number' used for summ info
msgsclr, // " in msgs/pmts
headclr, // " in cols head
taskclr; // " in task rows
char winname [WINNAMSIZ], // name for the window, user changeable
fieldscur [PFLAGSSIZ]; // the fields for display & their order
} RCW_t;
/* This represents the complete rcfile */
@ -366,8 +368,6 @@ typedef struct RCF_t {
int summ_mscale; // 'E' - scaling of summary memory values
int task_mscale; // 'e' - scaling of process memory values
int zero_suppress; // '0' - suppress scaled zeros toggle
int graph_cpus; // 't' - View_STATES supplementary values
int graph_mems; // 'm' - View_MEMORY supplememtary values
} RCF_t;
/* This structure stores configurable information for each window.
@ -569,7 +569,7 @@ typedef struct WIN_t {
/* Configuration files support */
#define SYS_RCFILESPEC "/etc/toprc"
#define RCF_EYECATCHER "Config File (Linux processes with windows)\n"
#define RCF_VERSION_ID 'h'
#define RCF_VERSION_ID 'i'
#define RCF_PLUS_H "\\]^_`abcdefghij"
/* The default fields displayed and their order, if nothing is
@ -600,19 +600,19 @@ 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, \
{ EU_CPU, DEF_WINFLGS, 0, 0, 0, \
COLOR_RED, COLOR_RED, COLOR_YELLOW, COLOR_RED, \
"Def", DEF_FIELDS }, \
{ EU_PID, DEF_WINFLGS, 0, \
{ EU_PID, DEF_WINFLGS, 0, 0, 0, \
COLOR_CYAN, COLOR_CYAN, COLOR_WHITE, COLOR_CYAN, \
"Job", JOB_FIELDS }, \
{ EU_MEM, DEF_WINFLGS, 0, \
{ EU_MEM, DEF_WINFLGS, 0, 0, 0, \
COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLUE, COLOR_MAGENTA, \
"Mem", MEM_FIELDS }, \
{ EU_UEN, DEF_WINFLGS, 0, \
{ EU_UEN, DEF_WINFLGS, 0, 0, 0, \
COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \
"Usr", USR_FIELDS } \
}, 0, SK_Kb, SK_Kb, 0, 0, 0 }
}, 0, SK_Kb, SK_Kb, 0 }
/* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */