updated to version We for top

This commit is contained in:
csmall 2002-07-24 22:25:34 +00:00
parent 8875fa0010
commit 52b97b8d3f
3 changed files with 2273 additions and 498 deletions

2647
top.1

File diff suppressed because it is too large Load Diff

89
top.c
View File

@ -112,8 +112,9 @@ static int Screen_cols, Screen_rows, Max_lines;
static int Msg_row;
/* Global/Non-windows mode stuff that IS persistent (in rcfile) */
static int Show_altscr; /* 'A' - 'Alt' display mode (multi windows) */
static int Show_irixps = 1; /* 'I' - Irix vs. Solaris mode (SMP-only) */
static int Mode_altscr; /* 'A' - 'Alt' display mode (multi windows) */
/* next toggle physically alters a proc_t, it CANNOT be window based */
static int Mode_irixps = 1; /* 'I' - Irix vs. Solaris mode (SMP-only) */
static float Delay_time = DEF_DELAY; /* how long to sleep between updates */
/* Global/Non-windows mode stuff that is NOT persistent */
@ -949,7 +950,7 @@ static void before (char *me)
* ordinary users are allowed to do. */
/* '$HOME/RCfile' contains multiple lines - 2 global + 3 per window.
* line 1: a shameless advertisement
* line 2: an id, Show_altcsr, Show_irixps, Delay_time and Curwin.
* line 2: an id, Mode_altcsr, Mode_irixps, Delay_time and Curwin.
* If running in secure mode via the /etc/rcfile,
* Delay_time will be ignored except for root.
* For each of the 4 windows:
@ -985,8 +986,8 @@ static void configs_read (void)
if (fp) {
fgets(fbuf, sizeof(fbuf), fp); /* ignore shameless advertisement */
if (5 != (fscanf(fp, "Id:%c, "
"Show_altscr=%d, Show_irixps=%d, Delay_time=%f, Curwin=%d\n"
, &id, &Show_altscr, &Show_irixps, &delay, &i)))
"Mode_altscr=%d, Mode_irixps=%d, Delay_time=%f, Curwin=%d\n"
, &id, &Mode_altscr, &Mode_irixps, &delay, &i)))
std_err(fmtmk(err_rc, RCfile));
/* you saw that, right? (fscanf stickin' it to 'i') */
@ -1286,7 +1287,7 @@ static void win_colsheads (WIN_t *q)
/* build a preliminary columns header not to exceed screen width
(and account for a possible leading window number) */
if (Show_altscr) strcpy(q->columnhdr, " "); else q->columnhdr[0] = '\0';
if (Mode_altscr) strcpy(q->columnhdr, " "); else q->columnhdr[0] = '\0';
for (i = 0; i < q->maxpflgs; i++) {
h = Fieldstab[q->procflags[i]].head;
/* oops, won't fit -- we're outta here... */
@ -1304,7 +1305,7 @@ static void win_colsheads (WIN_t *q)
/* now we can build the true run-time columns header and format the
command column heading if P_CMD is really being displayed --
show_a_task is aware of the addition of winnum to the header */
sprintf(q->columnhdr, "%s", Show_altscr ? fmtmk("%d", q->winnum) : "");
sprintf(q->columnhdr, "%s", Mode_altscr ? fmtmk("%d", q->winnum) : "");
for (i = 0; i < q->maxpflgs; i++) {
/* are we gonna' need the kernel symbol table? */
if (P_WCHAN == q->procflags[i]) needpsdb = 1;
@ -1630,7 +1631,7 @@ static void windows_stage1 (void)
Winstk[3]->next = Winstk[0];
Winstk[0]->prev = Winstk[3];
Curwin = Winstk[0];
Show_altscr = 0;
Mode_altscr = 0;
}
@ -1643,7 +1644,7 @@ static void windows_stage2 (void)
int i;
if (Batch) {
Show_altscr = 0;
Mode_altscr = 0;
OFFw(Curwin, Show_COLORS);
}
wins_resize(0);
@ -1781,7 +1782,7 @@ static void frame_states (proc_t **p, int show)
if (this->pcpu > 999) this->pcpu = 999;
/* if in Solaris mode, adjust cpu percentage not only for the cpu
the process is running on, but for all cpus together */
if (!Show_irixps) this->pcpu /= Cpu_tot;
if (!Mode_irixps) this->pcpu /= Cpu_tot;
total++;
} /* end: while 'pids' */
@ -1823,7 +1824,7 @@ static void frame_states (proc_t **p, int show)
for (i = 0; i < Cpu_tot; i++) {
sprintf(tmp, "%-6scpu%-2d:" /* [ cpu states as ] */
, i ? " " : "State" /* 'State cpu0 : ... ' */
, Show_irixps ? i : Cpu_map[i]); /* ' cpu1 : ... ' */
, Mode_irixps ? i : Cpu_map[i]); /* ' cpu1 : ... ' */
cpudo(fp, CPU_FMTS_MULTI, &smpcpu[i], tmp);
Msg_row += 1;
}
@ -1928,7 +1929,7 @@ static void show_a_task (WIN_t *q, proc_t *task)
/* since win_colsheads adds a number to the window's column header,
we must begin a row with that in mind... */
pad = Show_altscr;
pad = Mode_altscr;
if (pad) strcpy(rbuf, " "); else rbuf[0] = '\0';
for (i = 0; i < q->maxpflgs; i++) {
@ -2121,40 +2122,42 @@ static void do_key (unsigned c)
switch (c) {
/* begin windows grouping /////////////////////////// */
case '=': /* 'Equals' lower case --------------------- */
/* special Key: equalize current window (& make viz) ...
. began life as 'windows' oriented and restricted to Mode_altscr!
. but symbiosis of documenting and further testing led to lifting
of restrictions -- we feel MUCH better now, thank-you-SO-much! */
Curwin->maxtasks = 0;
SETw(Curwin, Show_IDLEPS | VISIBLE_tsk);
/* special Provision:
. escape from monitoring selected pids ('-p' cmdline switch)
-- just seems to go naturally with these new provisions
. and who knows, maybe the man doc will NOT be overlooked */
Monpidsidx = 0;
break;
case '+': /* 'Equals' upper case --------------------- */
if (Mode_altscr) /* equalize ALL task wins (& make viz) .... */
SETw(Curwin, EQUWINS_cwo);
break;
case '-': /* 'Dash' lower case ----------------------- */
if (Show_altscr)
if (Mode_altscr)
TOGw(Curwin, VISIBLE_tsk);
break;
case '_': /* 'Dash' upper case ----------------------- */
if (Show_altscr) /* switcharoo, all viz & inviz ............. */
if (Mode_altscr) /* switcharoo, all viz & inviz ............ */
wins_reflag(Flags_TOG, VISIBLE_tsk);
break;
case '=': /* 'Equals' lower case --------------------- */
if (Show_altscr) { /* equalize task display ................... */
Curwin->maxtasks = 0;
SETw(Curwin, Show_IDLEPS | VISIBLE_tsk);
}
break;
case '+': /* 'Equals' upper case --------------------- */
/* Special New Provision:
. escape from monitoring selected pids ('-p' cmdline switch)
-- just seems to go naturally with this new '+' command key
. and who knows, maybe the documentation will NOT be overlooked */
Monpidsidx = 0;
if (Show_altscr) /* equalize ALL task windows (& make viz) .. */
SETw(Curwin, EQUWINS_cwo);
break;
case 'A':
Show_altscr = !Show_altscr;
Mode_altscr = !Mode_altscr;
wins_resize(0);
break;
case 'a':
if (Show_altscr) Curwin = Curwin->next;
if (Mode_altscr) Curwin = Curwin->next;
break;
case 'F':
@ -2163,7 +2166,7 @@ static void do_key (unsigned c)
break;
case 'g':
if (Show_altscr) {
if (Mode_altscr) {
char tmp[GETBUFSIZ];
strcpy(tmp, ask4str(fmtmk("Rename window '%s' to (0-3 chars)"
, Curwin->winname)));
@ -2172,7 +2175,7 @@ static void do_key (unsigned c)
break;
case 'w':
if (Show_altscr) Curwin = Curwin->prev;
if (Mode_altscr) Curwin = Curwin->prev;
break;
/* end windows grouping ///////////////////////////// */
case 'b':
@ -2204,13 +2207,13 @@ static void do_key (unsigned c)
case 'I':
#ifdef WARN_NOT_SMP
if (Cpu_tot > 1) {
Show_irixps = !Show_irixps;
show_msg(fmtmk("Irix mode %s", Show_irixps ? "On" : "Off"));
Mode_irixps = !Mode_irixps;
show_msg(fmtmk("Irix mode %s", Mode_irixps ? "On" : "Off"));
} else
show_msg(err_smp);
#else
Show_irixps = !Show_irixps;
show_msg(fmtmk("Irix mode %s", Show_irixps ? "On" : "Off"));
Mode_irixps = !Mode_irixps;
show_msg(fmtmk("Irix mode %s", Mode_irixps ? "On" : "Off"));
#endif
break;
@ -2316,9 +2319,9 @@ static void do_key (unsigned c)
fprintf(fp, "RCfile for \"%s with windows\"\t\t# shameless braggin'\n"
, Myname);
fprintf(fp, "Id:%c, "
"Show_altscr=%d, Show_irixps=%d, Delay_time=%.1f, Curwin=%d\n"
"Mode_altscr=%d, Mode_irixps=%d, Delay_time=%.1f, Curwin=%d\n"
, RCF_FILEID
, Show_altscr, Show_irixps, Delay_time, Curwin - Winstk[0]);
, Mode_altscr, Mode_irixps, Delay_time, Curwin - Winstk[0]);
for (i = 0; i < GROUPSMAX; i++) {
fprintf(fp, "%s\tfieldscur=%s\n"
, Winstk[i]->winname, Winstk[i]->fieldscur);
@ -2459,7 +2462,7 @@ static proc_t **do_summary (void)
/*
** Display Load averages */
if (CHKw(Curwin, View_LOADAV)) {
if (!Show_altscr)
if (!Mode_altscr)
show_special(fmtmk(LOADAV_line, Myname, sprint_uptime()));
else
show_special(fmtmk(CHKw(Curwin, VISIBLE_tsk)
@ -2618,7 +2621,7 @@ static void so_lets_see_em (void)
/* sure hope each window's columns header begins with a newline... */
putp(tg2(0, Msg_row));
if (!Show_altscr) {
if (!Mode_altscr) {
/* only 1 window to show so, piece o' cake */
Curwin->winlines = Curwin->maxtasks;
do_window(ppt, Curwin, &scrlins);

35
top.h
View File

@ -211,9 +211,9 @@ enum pflag {
#define TOGw(q,f) q->winflags ^= (f)
#define SETw(q,f) q->winflags |= (f)
#define OFFw(q,f) q->winflags &= ~(f)
#define VIZCHKc (!Show_altscr || Curwin->winflags & VISIBLE_tsk) \
#define VIZCHKc (!Mode_altscr || Curwin->winflags & VISIBLE_tsk) \
? 1 : win_warn()
#define VIZTOGc(f) (!Show_altscr || Curwin->winflags & VISIBLE_tsk) \
#define VIZTOGc(f) (!Mode_altscr || Curwin->winflags & VISIBLE_tsk) \
? TOGw(Curwin, f) : win_warn()
/* This structure stores configurable information for each window.
@ -258,7 +258,7 @@ typedef struct win {
/*###### Display Support *Data* ########################################*/
/* An rcfile 'footprint' used to invalidate existing */
#define RCF_FILEID 'd'
#define RCF_FILEID 'e'
/* The default fields displayed and their order,
if nothing is specified by the loser, oops user */
@ -268,13 +268,11 @@ typedef struct win {
#define MEM_FIELDS "AMNOPQRSTUWbcdefiklxyVGHJ"
#define USR_FIELDS "CDEFABWghiknopqrstuxyLJMV"
/* These are the possible fscanf formats used in /proc/stat
reads during history processing. */
#define CPU_FMTS_MULTI "cpu%*d %lu %lu %lu %lu\n"
#define CPU_FMTS_JUST1 "cpu %lu %lu %lu %lu\n"
/* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define LOADAV_line "%s -%s\n"
@ -402,26 +400,26 @@ typedef struct win {
/* Windows/Field Group Help specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define WINDOWS_help \
"%s's \01Help for Windows and Field Groups\02 - \"Current\" = \01 %s \06\n" \
"%s's \01Help for Windows / Field Groups\02 - \"Current\" = \01 %s \06\n" \
"\n" \
". Use multiple \01windows\02, each with separate config opts (color,fields,sort,etc)\n" \
". The '\01Current\05' window controls the \01Summary Area\02 and responds to your \01Commands\02\n" \
". The 'current' window controls the \01Summary Area\02 and responds to your \01Commands\02\n" \
" . that window's \01task display\02 can be turned \01Off\02 & \01On\02, growing/shrinking others\n" \
" . with \01NO\02 task display, some commands will be \01disabled\02 ('i','R','n','c', etc)\n" \
" until a \01different window\02 has been activated, making it the '\01Current\05' window\n" \
". You \01change\02 a '\01Current\05' window by: \01 1\02) cycling forward/backward; \01 2\02) choosing\n" \
" a specific window with 'O' or 'F'; or \01 3\02) exiting the color mapping screen\n" \
". Commands \01available anytime\02 -------------\n" \
" until a \01different window\02 has been activated, making it the 'current' window\n" \
". You \01change\02 the 'current' window by: \01 1\02) cycling forward/backward;\01 2\02) choosing\n" \
" a specific window with 'O' or 'F'; or\01 3\02) exiting the color mapping screen\n" \
". Commands \01available anytime -------------\02\n" \
" \01A\02 . Alternate display mode toggle, show \01Single\02 / \01Multiple\02 windows\n" \
" O or F . Choose another field group and make it '\01Current\05', or change now\n" \
" by selecting a number: \01 1\02 :%s; \01 2\02 :%s; \01 3\02 :%s; \01 4\02 :%s\n" \
". Commands \01requiring\02 '\01A\02' mode -----------\n" \
" g . Change the '\01Current\05' window name (field group)\n" \
" \01*\04 a , w . Cycle through all four windows: \01a\02 Forward; \01w\02 Backward\n" \
" \01*\04 - , _ . Show/Hide: '\01-\05' \01Current\02 window; '\01_\05' all \01Visible\02/\01Invisible\02\n" \
" O or F . Choose another field group and make it 'current', or change now\n" \
" by selecting a number from: \01 1\02 =%s;\01 2\02 =%s;\01 3\02 =%s; or\01 4\02 =%s\n" \
". Commands \01requiring\02 '\01A\02' mode\01 -------------\02\n" \
" g . Change the \01Name\05 of the 'current' window/field group\n" \
" \01*\04 a , w . Cycle through all four windows: '\01a\05' Forward; '\01w\05' Backward\n" \
" \01*\04 - , _ . Show/Hide: '\01-\05' \01Current\02 window; '\01_\05' all \01Visible\02/\01Invisible\02\n" \
" The screen will be divided evenly between task displays. But you can make\n" \
" some \01larger\02 or \01smaller\02, using '\01n\02' and '\01i\02' commands. Then later you could:\n" \
" \01*\04 = , + . Rebalance tasks: '\01=\05' \01Current\02 window; '\01+\05' \01Every\02 window\n" \
" \01*\04 = , + . Rebalance tasks: '\01=\05' \01Current\02 window; '\01+\05' \01Every\02 window\n" \
" (this also forces the \01current\02 or \01every\02 window to become visible)\n" \
"\n" \
"In '\01A\02' mode, '\01*\04' keys are your \01essential\02 commands. Please try the '\01a\02' and '\01w\02'\n" \
@ -506,7 +504,6 @@ typedef struct win {
/*------ Entry point ---------------------------------------------------*/
// int main (int dont_care_argc, char **argv);
/* just sanity check(s)... */
#if USRNAMSIZ < GETBUFSIZ
#error "Jeeze, USRNAMSIZ Must NOT be less than GETBUFSIZ !"