Synched top.[ch1] to Jims Wg release

This commit is contained in:
csmall 2002-08-26 00:55:30 +00:00
parent 52b97b8d3f
commit d32861b68f
3 changed files with 106 additions and 98 deletions

98
top.1
View File

@ -22,20 +22,20 @@
.igEND .igEND
. .
.\" Setup //////////////////////////////////////////////////////////////// .\" Setup ////////////////////////////////////////////////////////////////
. \" ** Comment out 'll' to eliminate WIDTH fiddlin', 1 of 3 \# ** Comment out '.nr' or set to 0 to eliminate WIDTH fiddlin' !
. ll +8 .nr half_xtra 4
.
. ll +(\n[half_xtra] + \n[half_xtra])
. .
\# Special right justify macros --------------------- \# Special right justify macros ---------------------
\# - right justify start \# - right justify start
. de Rjb . de Rjb
. \" ** Comment out 'll' to eliminate WIDTH fiddlin', 2 of 3 . ll -\n[half_xtra]
. ll -4
. rj \\$1 . rj \\$1
.. ..
\# - right justify end \# - right justify end
. de Rje . de Rje
. \" ** Comment out 'll' to eliminate WIDTH fiddlin', 3 of 3 . ll +\n[half_xtra]
. ll +4
.. ..
\# Jimmy's darn Bullet style ------------------------ \# Jimmy's darn Bullet style ------------------------
. de Jbu . de Jbu
@ -225,7 +225,7 @@ columns get misaligned.
personal \*(CF, including any changes made on a per-window basis. personal \*(CF, including any changes made on a per-window basis.
Thus, once you personalize things they\fB remain personalized\fR until Thus, once you personalize things they\fB remain personalized\fR until
you decide to change them again. you decide to change them again.
This \*(ME has been completely cured of: This \*(Me has been completely cured of:
.Rjb 2 .Rjb 2
i-cant-remember-so-please-do-that-all-over-again i-cant-remember-so-please-do-that-all-over-again
( and again, and again ... ) ( and again, and again ... )
@ -239,14 +239,13 @@ go bye-bye.
.New .New
You have complete program\fB naming freedom\fR with no internal ties to a You have complete program\fB naming freedom\fR with no internal ties to a
specific \*(CF. specific personal \*(CF.
Thus, if you have permission to create symbolic links to /usr/bin (or can bribe Symbolic links could be used to establish different \*(CFs reflecting
the system administrator), these symlinks could be used to establish\fB the different personalities of your customized "\*(Mes", under whatever
different\fR \*(CFs reflecting the different\fB personalities\fR of your aliases you've used.
customized "\*(Mes", under whatever aliases you've used.
Thus, you could have an alias for running \*(Me in 'Batch mode', another for when Thus, you could have an alias for running \*(Me in 'Batch mode', another for
you work from the Linux console and maybe a third used with X-Windows. when you work from the Linux console and maybe a third used with X-Windows.
All of that, yet still just a single binary image! All of that, yet still just a single binary image!
.\" ...................................................................... .\" ......................................................................
@ -289,7 +288,7 @@ more distinct).
.I Columns_Header\fR: .I Columns_Header\fR:
Shows a\fB new\fR field and some\fB changed\fR labels (unseen to the right). Shows a\fB new\fR field and some\fB changed\fR labels (unseen to the right).
Precious horizontal space is no longer squandered unlike your former top. Precious horizontal space is no longer squandered.
.Scr .Scr
All of that, however, is just the tip of the old iceberg. All of that, however, is just the tip of the old iceberg.
@ -318,7 +317,7 @@ in this document...
( or windows &\fB each\fR )| 6725 root 9 0 0.0 0:00.03 : ( or windows &\fB each\fR )| 6725 root 9 0 0.0 0:00.03 :
( could be shown in )| 6232 root 7 -10 1.9 4:25.86 : ( could be shown in )| 6232 root 7 -10 1.9 4:25.86 :
( this way, or show )| 5561 root 9 0 0.0 0:00.33 : ( this way, or show )| 5561 root 9 0 0.0 0:00.33 :
( \fBall concurrently\fR! )| 5560 xfs 9 0 0.0 0:00.01 : (\fB all concurrently\fR! )| 5560 xfs 9 0 0.0 0:00.01 :
| 5325 root 9 0 0.0 0:00.05 : | 5325 root 9 0 0.0 0:00.05 :
( will\fI change\fR often )| 4634 root 9 0 0.0 0:04.23 : ( will\fI change\fR often )| 4634 root 9 0 0.0 0:04.23 :
-*-\fBRow hilites-->\fR |\fB 1803 jgnome 9 0 0.0 1:55.30\fR : -*-\fBRow hilites-->\fR |\fB 1803 jgnome 9 0 0.0 1:55.30\fR :
@ -333,7 +332,7 @@ assuming no \*(CF, thus no user customizations.
However, items shown with an \*(AS could be overridden through the\fB However, items shown with an \*(AS could be overridden through the\fB
command line\fR \*(EM a subject soon to be dealt with. command line\fR \*(EM a subject soon to be dealt with.
\fISystem_defaults\fR \fIGlobal_defaults\fR
'A' - Alt display \fBOff\fR (full-screen) 'A' - Alt display \fBOff\fR (full-screen)
* 'd' - Delay time 3.0 seconds * 'd' - Delay time 3.0 seconds
'I' - Irix mode On\ \ (no, 'solaris' smp) 'I' - Irix mode On\ \ (no, 'solaris' smp)
@ -362,7 +361,7 @@ for a successful\fB close-encounter-of-the-1st-kind\fR with \*(Us.
You need remember just the\fB help key\fR ('h' or '?') to survive You need remember just the\fB help key\fR ('h' or '?') to survive
\*(EM nay, prosper! \*(EM nay, prosper!
What about quitting, you ask? What about quitting, you ask?
Well, of course there's the 'Q' \*(CI, but then \*(ME does quite well Well, of course there's the 'Q' \*(CI, but then \*(Me does quite well
with\fB signals\fR. with\fB signals\fR.
So just zap him with the traditional \fI^C\fR when you're done. So just zap him with the traditional \fI^C\fR when you're done.
.br .br
@ -746,8 +745,8 @@ then be\fB shown\fR as part of the \*(TD (screen width permitting).
This will also be indicated by a leading \*(AS, as in this excerpt: This will also be indicated by a leading \*(AS, as in this excerpt:
\fR... \fR...
\fR* J: %CPU = CPU usage \fR* J: %CPU = CPU usage
\fR K: TIME = CPU Time \fR k: TIME = CPU Time
\fR L: TIME+ = CPU Time, hundredths \fR l: TIME+ = CPU Time, hundredths
\fR* M: %MEM = Memory usage (RES) \fR* M: %MEM = Memory usage (RES)
\fR* N: VIRT = Virtual Image (kb) \fR* N: VIRT = Virtual Image (kb)
\fR... \fR...
@ -768,8 +767,8 @@ letter.
.SH 3. INTERACTIVE Commands .SH 3. INTERACTIVE Commands
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
Listed below is a brief index of commands within categories. Listed below is a brief index of commands within categories.
Some commands appear more than once and, while their meaning is consistent, Some commands appear more than once \*(EM their meaning or scope may vary
the scope may vary depending on the context in which they are issued. depending on the context in which they are issued.
3a.\fI GLOBAL_Commands\fR 3a.\fI GLOBAL_Commands\fR
?, ^L, <Sp>, =, A, d, F, h, O, I, k, Q, r, s, W, Z ?, ^L, <Sp>, =, A, d, F, h, O, I, k, Q, r, s, W, Z
@ -783,7 +782,7 @@ the scope may vary depending on the context in which they are issued.
3d.\fI COLOR_Mapping\fR 3d.\fI COLOR_Mapping\fR
<Enter>, a, b, H, M, q, S, T, w, z, 0 - 7 <Enter>, a, b, H, M, q, S, T, w, z, 0 - 7
4b.\fI COMMANDS_for_Windows\fR 4b.\fI COMMANDS_for_Windows\fR
-, _, =, +, A, F, g, O -, _, =, +, A, a, F, g, O, w
.\" ...................................................................... .\" ......................................................................
.SS 3a. GLOBAL Commands .SS 3a. GLOBAL Commands
@ -827,8 +826,9 @@ When operating in \*(AM this command has a slightly broader meaning.
.TP 7 .TP 7
\ \ \'\fBA\fR\' :\fIAlternate_Display_Mode_toggle\fR \ \ \'\fBA\fR\' :\fIAlternate_Display_Mode_toggle\fR
This command will switch between \*(FM and \*(AM This command will switch between \*(FM and \*(AM.
(see 4. ALTERNATE\-DISPLAY Mode). See 4. ALTERNATE\-DISPLAY Mode and the 'F' or 'O' \*(CIs for insight into
\*(CWs and field groups.
.TP 7 .TP 7
*\ \'\fBd\fR\' or \'\fBs\fR\' :\fIChange_Delay_Time_interval\fR *\ \'\fBd\fR\' or \'\fBs\fR\' :\fIChange_Delay_Time_interval\fR
@ -936,8 +936,8 @@ When you see 'Cpu(s) state:' in the \*(SA, the '1' toggle is \*O and all
Otherwise, each \*(Pu is displayed separately as: 'cpu0, cpu1, ...' Otherwise, each \*(Pu is displayed separately as: 'cpu0, cpu1, ...'
.in +4 .in +4
\*(NT If you receive a fatal error message in response to this command, \*(NT If you receive a fatal error message in response to this command, your
your version of the kernel does not provide summary \*(Pu data in '/proc/stat'. version of the kernel does not provide separate \*(Pu data in '/proc/stat'.
You can either avoid issuing this command or recompile \*(Me with the You can either avoid issuing this command or recompile \*(Me with the
appropriate #define enabled so the command will be restricted to SMP. appropriate #define enabled so the command will be restricted to SMP.
.in .in
@ -985,7 +985,8 @@ your-brand-new-top and you'll make the program author a happy guy.
\ \ \'\fBz\fR\' :\fIColor/Monochrome_toggle\fR \ \ \'\fBz\fR\' :\fIColor/Monochrome_toggle\fR
Switches the \*(CW between your last used color scheme and the older form Switches the \*(CW between your last used color scheme and the older form
of black-on-white or white-on-black. of black-on-white or white-on-black.
It does not affect the state of the 'x', 'y' or 'b' toggles. This command will alter both the \*(SA and \*(TA but does not affect the
state of the 'x', 'y' or 'b' toggles.
.PP .PP
.\" ......................... .\" .........................
@ -1066,21 +1067,26 @@ Lose no sleep over 'reverse' and 'normal', ok?
.TP 7 .TP 7
\ \ \fB\ 7\fR\ \ upper case letters which \fISelect_a_Sort_Column\fR: \ \ \fB\ 7\fR\ \ upper case letters which \fISelect_a_Sort_Column\fR:
\'C\fR\'\ \ :Sort by Command\fB line\fR or program\fB name\fR, \'\fBC\fR\'\ \ :Sort by Command\fB line\fR or program\fB name\fR,
.br .br
\ \ \ \ \ \ depending on the state of the 'c' toggle \ \ \ \ \ \ depending on the state of the 'c' toggle
.br .br
\'E\'\ \ :Sort by USER \'\fBE\fR\'\ \ :Sort by USER
.br .br
\'M\'\ \ :Sort by %MEM and/or RES \'\fBM\fR\'\ \ :Sort by %MEM and/or RES
.br .br
\'P\'\ \ :Sort by PID \'\fBP\fR\'\ \ :Sort by PID
.br .br
\'T\'\ \ :Sort by TIME and/or TIME+ \'\fBT\fR\'\ \ :Sort by TIME and/or TIME+
.br .br
\'U\'\ \ :Sort by %CPU \'\fBU\fR\'\ \ :Sort by %CPU
.br .br
\'Y\'\ \ :Sort by TTY \'\fBY\fR\'\ \ :Sort by TTY
.PP
If you forget which field \*(Me is sorting, the '\fBR\fR' or '\fBx\fR'
\*(CIs could be used for a quick visual reminder, without changing the
selected sort column.
.\" ...................................................................... .\" ......................................................................
.SS 3d. COLOR Mapping .SS 3d. COLOR Mapping
@ -1196,9 +1202,10 @@ Come on, let's hear it, who ya gonna' blame, huh?
.TP 7 .TP 7
\ \ \'\fB-\fR\' or \'\fB_\fR\' :\fIShow/Hide_Window(s)_toggle\fR \ \ \'\fB-\fR\' or \'\fB_\fR\' :\fIShow/Hide_Window(s)_toggle\fR
The '-' (minus) key turns the \*(CW's \*(TD \*O and \*F. The '-' (minus) key turns the \*(CW's \*(TD \*O and \*F.
When \*O, that \*(TA will show a minimum of 1 task and the columns header When \*O, that \*(TA will show a minimum of the columns header you've
you've established with the 'f' and 'o' commands. established with the 'f' and 'o' commands.
It will also reflect any other \*(TA options/toggles you've applied. It will also reflect any other \*(TA options/toggles you've applied yielding
zero or more tasks.
The '_' (upper case minus) key does the same for\fB all\fR \*(TDs. The '_' (upper case minus) key does the same for\fB all\fR \*(TDs.
In other words, it switches between the currently visible \*(TD(s) and any In other words, it switches between the currently visible \*(TD(s) and any
@ -1403,7 +1410,7 @@ empty rows...
.Img .Img
1:Def\fI no\fR highlight, +\fB--------------------------------------\fR+ 1:Def\fI no\fR highlight, +\fB--------------------------------------\fR+
thus disabled cmds: |1:Def - 15:50:32 up 16:29, 9 users, : thus disabled cmds: |1:Def - 15:50:32 up 16:29, 9 users, :
b,i,n,u,x,y,z, etc. |Tasks: \fB 75\fR total, \fB 2\fR running, \fB 73\fR sle: b,i,n,u,x,y, etc. |Tasks: \fB 75\fR total, \fB 2\fR running, \fB 73\fR sle:
& m = lost Mem/Swap |Cpu(s) state: \fB 10.6%\fR user, \fB 0.0%\fR syst: & m = lost Mem/Swap |Cpu(s) state: \fB 10.6%\fR user, \fB 0.0%\fR syst:
|______________________________________: |______________________________________:
2:Job was very busy: |\fI2__PID__PPID_Command____________TIME+_\fR: 2:Job was very busy: |\fI2__PID__PPID_Command____________TIME+_\fR:
@ -1471,15 +1478,14 @@ not successfully, ha ha):
\fBs\fR or\fB d\fR Change\fB delay/update\fR interval \fBs\fR or\fB d\fR Change\fB delay/update\fR interval
The system \*(CF is\fB not\fR created by \*(Me. The system \*(CF is\fB not\fR created by \*(Me.
Rather,\fB you create this file manually\fR and place it in the\fI /etc\fR directory. Rather,\fB you create this file manually\fR and place it in the \fI/etc\fR
Its name must agree with 'your-name-for-top'\ +\ 'rc' and must have\fI directory.
no\fR leading '.' (period). Its name must be 'toprc' and must have\fI no\fR leading '.' (period).
It must have\fI only_two_lines\fR. It must have only\fI two lines\fR.
Here is an example of a system \*(CF placed in\fI /etc\fR Here is an example of the contents of\fI /etc/toprc\fR:
as\fI top\fBrc\fR:\ \ /etc/\fItop\fBrc\fR
\fBs\fR # line 1: 'secure' mode switch \fBs\fR # line 1: 'secure' mode switch
\fB5.0\fR # line 2: 'delay'\ \ interval (secs) \fB5.0\fR # line 2: 'delay'\ \ interval in seconds
.\" ...................................................................... .\" ......................................................................
.SS 5b. PERSONAL Configuration File .SS 5b. PERSONAL Configuration File

76
top.c
View File

@ -72,12 +72,11 @@ static struct termios Savedtty,
Rawtty; Rawtty;
static int Ttychanged = 0; static int Ttychanged = 0;
/* Program name used in error messages and 'rc' file names */ /* Program name used in error messages and local 'rc' file name */
static char *Myname; static char *Myname;
/* The Name of the config file(s), dynamically constructed */ /* The Name of the local config file, dynamically constructed */
static char RCfile [OURPATHSZ], static char RCfile [OURPATHSZ];
RCfile_Sys [SMLBUFSIZ];
/* The run-time acquired page size */ /* The run-time acquired page size */
static int Page_size; static int Page_size;
@ -380,7 +379,11 @@ static void bye_bye (int eno, const char *str)
"\nbye_bye's Summary report:" "\nbye_bye's Summary report:"
"\n\tProgram" "\n\tProgram"
"\n\t Page_size = %d, Cpu_tot = %d" "\n\t Page_size = %d, Cpu_tot = %d"
"\n\tTerminal: %s" "\n\t %s, Hertz = %u (size %u bytes, %u-bit time)"
"\n\t sizeof(CPUS_t) = %u, sizeof(HIST_t) = %u (%u HIST_t's/Page)"
"\n\t CPU_FMTS_JUST1 = %s"
" \t CPU_FMTS_MULTI = %s"
" \tTerminal: %s"
"\n\t device = %s, ncurses = v%s" "\n\t device = %s, ncurses = v%s"
"\n\t max_colors = %d, max_pairs = %d" "\n\t max_colors = %d, max_pairs = %d"
"\n\t Cap_can_goto = %s" "\n\t Cap_can_goto = %s"
@ -388,7 +391,7 @@ static void bye_bye (int eno, const char *str)
"\n\t Max_lines = %d" "\n\t Max_lines = %d"
"\n\tWindows and Curwin->" "\n\tWindows and Curwin->"
"\n\t sizeof(WIN_t) = %u, GROUPSMAX = %d" "\n\t sizeof(WIN_t) = %u, GROUPSMAX = %d"
"\n\t winname = %s, grpname = %s," "\n\t winname = %s, grpname = %s"
#ifdef CASEUP_HEXES #ifdef CASEUP_HEXES
"\n\t winflags = %08X, maxpflgs = %d" "\n\t winflags = %08X, maxpflgs = %d"
#else #else
@ -399,6 +402,9 @@ static void bye_bye (int eno, const char *str)
"\n\t sorttype = %c" "\n\t sorttype = %c"
"\n" "\n"
, Page_size, Cpu_tot , Page_size, Cpu_tot
, procps_version, (unsigned)Hertz, sizeof(Hertz), sizeof(Hertz) * 8
, sizeof(CPUS_t), sizeof(HIST_t), Page_size / sizeof(HIST_t)
, CPU_FMTS_JUST1, CPU_FMTS_MULTI
#ifdef PRETENDNOCAP #ifdef PRETENDNOCAP
, "dumb" , "dumb"
#else #else
@ -787,12 +793,12 @@ static char *scale_tics (TICS_t tics, const unsigned width)
/* try successively higher units until it fits */ /* try successively higher units until it fits */
t = tics / Hertz; t = tics / Hertz;
sprintf(buf, "%d:%02d.%02d" /* minutes:seconds.tenths */ sprintf(buf, "%u:%02u.%02u" /* minutes:seconds.hundredths */
, t/60, t%60, (int)((tics*100)/Hertz)%100); , t/60, t%60, (unsigned)((tics*100)/Hertz)%100);
if (strlen(buf) <= width) if (strlen(buf) <= width)
return buf; return buf;
sprintf(buf, "%d:%02d", t/60, t%60); /* minutes:seconds */ sprintf(buf, "%u:%02u", t/60, t%60); /* minutes:seconds */
if (strlen(buf) <= width) if (strlen(buf) <= width)
return buf; return buf;
@ -944,8 +950,8 @@ static void before (char *me)
/* /*
* Build the two RC file names then try to read 'em. */ * Build the local RC file name then try to read both of 'em. */
/* '/etc/RCfile_Sys' contains two lines consisting of the secure /* 'SYS_RCFILE' contains two lines consisting of the secure
* mode switch and an update interval. It's presence limits what * mode switch and an update interval. It's presence limits what
* ordinary users are allowed to do. */ * ordinary users are allowed to do. */
/* '$HOME/RCfile' contains multiple lines - 2 global + 3 per window. /* '$HOME/RCfile' contains multiple lines - 2 global + 3 per window.
@ -966,12 +972,11 @@ static void configs_read (void)
char id; char id;
int i; int i;
strcpy(RCfile_Sys, fmtmk("/etc/%src", Myname));
if (getenv("HOME")) if (getenv("HOME"))
strcpy(RCfile, fmtmk("%s%c", getenv("HOME"), '/')); strcpy(RCfile, fmtmk("%s%c", getenv("HOME"), '/'));
strcat(RCfile, fmtmk(".%src", Myname)); strcat(RCfile, fmtmk(".%src", Myname));
fp = fopen(RCfile_Sys, "r"); fp = fopen(SYS_RCFILE, "r");
if (fp) { if (fp) {
fbuf[0] = '\0'; fbuf[0] = '\0';
fgets(fbuf, sizeof(fbuf), fp); /* sys rc file, line #1 */ fgets(fbuf, sizeof(fbuf), fp); /* sys rc file, line #1 */
@ -1079,7 +1084,7 @@ static void parse_args (char **args)
if (cp[1]) cp++; if (cp[1]) cp++;
else if (*args) cp = *args++; else if (*args) cp = *args++;
else std_err("-n requires argument"); else std_err("-n requires argument");
if (1 != sscanf(cp, "%d", &Loops) || 0 > Loops) if (1 != sscanf(cp, "%d", &Loops) || 1 > Loops)
std_err(fmtmk("bad iterations arg '%s'", cp)); std_err(fmtmk("bad iterations arg '%s'", cp));
break; break;
case 'p': case 'p':
@ -1113,7 +1118,7 @@ static void parse_args (char **args)
} /* end: switch (*cp) */ } /* end: switch (*cp) */
/* advance cp and jump over any numerical args used above */ /* advance cp and jump over any numerical args used above */
if (*cp) cp += strspn(++cp, "- ,.1234567890"); if (*cp) cp += strspn(&cp[1], "- ,.1234567890") + 1;
} /* end: while (*cp) */ } /* end: while (*cp) */
} /* end: while (*args) */ } /* end: while (*args) */
@ -1184,13 +1189,15 @@ static void display_fields (void)
too lazy to handle his own asterisk (*) logic */ too lazy to handle his own asterisk (*) logic */
putp(Cap_bold); putp(Cap_bold);
for (i = 0; i < MAXtbl(Fieldstab); ++i) { for (i = 0; i < MAXtbl(Fieldstab); ++i) {
int b = (NULL != strchr(Curwin->fieldscur, i + 'A'));
/* advance past any leading spaces */ /* advance past any leading spaces */
for (p = Fieldstab[i].head; ' ' == *p; ++p) for (p = Fieldstab[i].head; ' ' == *p; ++p)
; ;
printf("%s%c %c: %-10s = %s" printf("%s%c %c: %-10s = %s"
, tg2((i / rmax) * cmax, (i % rmax) + yRSVD) , tg2((i / rmax) * cmax, (i % rmax) + yRSVD)
, strchr(Curwin->fieldscur, i + 'A') ? '*' : ' ' , b ? '*' : ' '
, i + 'A' , b ? i + 'A' : i + 'a'
, p , p
, Fieldstab[i].desc); , Fieldstab[i].desc);
} }
@ -1670,9 +1677,9 @@ static void cpudo (FILE *fp, const char *fmt, CPUS_t *cpu, const char *pfx)
{ {
/* we'll trim to zero if we get negative time ticks, /* we'll trim to zero if we get negative time ticks,
which has happened with some SMP kernels (pre-2.4?) */ which has happened with some SMP kernels (pre-2.4?) */
#define TRIMz(x) ((tz = (long)x) < 0 ? 0 : tz) #define TRIMz(x) ((tz = (STIC_t)x) < 0 ? 0 : tz)
TICS_t u_tics, s_tics, n_tics, i_tics; TICS_t u_tics, s_tics, n_tics, i_tics;
long u_frme, s_frme, n_frme, i_frme, tot_frme, tz; STIC_t u_frme, s_frme, n_frme, i_frme, tot_frme, tz;
#ifdef PRETEND4CPUS #ifdef PRETEND4CPUS
rewind(fp); rewind(fp);
@ -1696,6 +1703,7 @@ static void cpudo (FILE *fp, const char *fmt, CPUS_t *cpu, const char *pfx)
, (float)s_frme * 100 / tot_frme , (float)s_frme * 100 / tot_frme
, (float)n_frme * 100 / tot_frme , (float)n_frme * 100 / tot_frme
, (float)i_frme * 100 / tot_frme)); , (float)i_frme * 100 / tot_frme));
Msg_row += 1;
/* remember for next time around */ /* remember for next time around */
cpu->u = u_tics; cpu->u = u_tics;
@ -1716,7 +1724,6 @@ static void frame_states (proc_t **p, int show)
{ {
static HIST_t *hist_sav = NULL; static HIST_t *hist_sav = NULL;
static unsigned hist_siz; static unsigned hist_siz;
static int viewsav;
static CPUS_t *smpcpu; static CPUS_t *smpcpu;
HIST_t *hist_new; HIST_t *hist_new;
unsigned total, running, sleeping, stopped, zombie; unsigned total, running, sleeping, stopped, zombie;
@ -1725,14 +1732,12 @@ static void frame_states (proc_t **p, int show)
if (!hist_sav) { if (!hist_sav) {
Frame_maxtask = 0; Frame_maxtask = 0;
/* room for 512 HIST_t's (if Page_size == 4k) */
hist_siz = (Page_size / sizeof(HIST_t)); hist_siz = (Page_size / sizeof(HIST_t));
hist_sav = alloc_c(hist_siz); hist_sav = alloc_c(hist_siz);
/* note: we allocate one more CPUS_t than Cpu_tot so that the last /* note: we allocate one more CPUS_t than Cpu_tot so that the last
slot can hold tics representing the /proc/stat cpu summary slot can hold tics representing the /proc/stat cpu summary
(first line read) -- that slot supports summary cpu info */ (first line read) -- that slot supports summary cpu info */
smpcpu = alloc_c((1 + Cpu_tot) * sizeof(CPUS_t)); smpcpu = alloc_c((1 + Cpu_tot) * sizeof(CPUS_t));
viewsav = CHKw(Curwin, View_CPUSUM);
} }
hist_new = alloc_c(hist_siz); hist_new = alloc_c(hist_siz);
total = running = sleeping = stopped = zombie = 0; total = running = sleeping = stopped = zombie = 0;
@ -1796,37 +1801,23 @@ static void frame_states (proc_t **p, int show)
, total, running, sleeping, stopped, zombie)); , total, running, sleeping, stopped, zombie));
Msg_row += 1; Msg_row += 1;
/* clean old histories if we've changed modes */
if (CHKw(Curwin, View_CPUSUM) != viewsav) {
if (CHKw(Curwin, View_CPUSUM))
/* fresh start for the last slot in the history area */
memset(&smpcpu[Cpu_tot], '\0', sizeof(CPUS_t));
else
/* fresh start for the true smpcpu history area */
memset(smpcpu, '\0', Cpu_tot * sizeof(CPUS_t));
viewsav = CHKw(Curwin, View_CPUSUM);
}
if (!(fp = fopen("/proc/stat", "r"))) if (!(fp = fopen("/proc/stat", "r")))
std_err(fmtmk("Failed /proc/stat open: %s", strerror(errno))); std_err(fmtmk("Failed /proc/stat open: %s", strerror(errno)));
if (CHKw(Curwin, View_CPUSUM)) { if (CHKw(Curwin, View_CPUSUM)) {
/* retrieve and display just the 1st /proc/stat line */ /* retrieve and display just the 1st /proc/stat line */
cpudo(fp, CPU_FMTS_JUST1, &smpcpu[Cpu_tot], "Cpu(s) state:"); cpudo(fp, CPU_FMTS_JUST1, &smpcpu[Cpu_tot], "Cpu(s) state:");
Msg_row += 1;
} else { } else {
char tmp[SMLBUFSIZ]; char tmp[SMLBUFSIZ];
/* skip the 1st line, which reflects total cpu states */ /* skip the 1st line, which reflects total cpu states */
if (!fgets(tmp, sizeof(tmp), fp)) if (!fgets(tmp, sizeof(tmp), fp)) std_err("Failed /proc/stat read");
std_err("Failed /proc/stat read");
/* now do each cpu's states separately */ /* now do each cpu's states separately */
for (i = 0; i < Cpu_tot; i++) { for (i = 0; i < Cpu_tot; i++) {
sprintf(tmp, "%-6scpu%-2d:" /* [ cpu states as ] */ sprintf(tmp, "%-6scpu%-2d:" /* [ cpu states as ] */
, i ? " " : "State" /* 'State cpu0 : ... ' */ , i ? " " : "State" /* 'State cpu0 : ... ' */
, Mode_irixps ? i : Cpu_map[i]); /* ' cpu1 : ... ' */ , Mode_irixps ? i : Cpu_map[i]); /* ' cpu1 : ... ' */
cpudo(fp, CPU_FMTS_MULTI, &smpcpu[i], tmp); cpudo(fp, CPU_FMTS_MULTI, &smpcpu[i], tmp);
Msg_row += 1;
} }
} }
fclose(fp); fclose(fp);
@ -2168,7 +2159,7 @@ static void do_key (unsigned c)
case 'g': case 'g':
if (Mode_altscr) { if (Mode_altscr) {
char tmp[GETBUFSIZ]; char tmp[GETBUFSIZ];
strcpy(tmp, ask4str(fmtmk("Rename window '%s' to (0-3 chars)" strcpy(tmp, ask4str(fmtmk("Rename window '%s' to (1-3 chars)"
, Curwin->winname))); , Curwin->winname)));
if (tmp[0]) win_names(Curwin, tmp); if (tmp[0]) win_names(Curwin, tmp);
} }
@ -2319,7 +2310,7 @@ static void do_key (unsigned c)
fprintf(fp, "RCfile for \"%s with windows\"\t\t# shameless braggin'\n" fprintf(fp, "RCfile for \"%s with windows\"\t\t# shameless braggin'\n"
, Myname); , Myname);
fprintf(fp, "Id:%c, " fprintf(fp, "Id:%c, "
"Mode_altscr=%d, Mode_irixps=%d, Delay_time=%.1f, Curwin=%d\n" "Mode_altscr=%d, Mode_irixps=%d, Delay_time=%.3f, Curwin=%d\n"
, RCF_FILEID , RCF_FILEID
, Mode_altscr, Mode_irixps, Delay_time, Curwin - Winstk[0]); , Mode_altscr, Mode_irixps, Delay_time, Curwin - Winstk[0]);
for (i = 0; i < GROUPSMAX; i++) { for (i = 0; i < GROUPSMAX; i++) {
@ -2553,7 +2544,7 @@ static void do_window (proc_t **ppt, WIN_t *q, int *lscr)
* -- i swear that's the whole truth, so-help-me ! */ * -- i swear that's the whole truth, so-help-me ! */
static void sohelpme (int wix, int max) static void sohelpme (int wix, int max)
{ {
WIN_t *w; WIN_t *w = Winstk[wix];
int i, rsvd, size, wins; int i, rsvd, size, wins;
/* calc remaining number of visible windows + total 'user' lines */ /* calc remaining number of visible windows + total 'user' lines */
@ -2656,7 +2647,9 @@ static void so_lets_see_em (void)
* it just SPLENDIDLY! You go right on doing it EXACTLY the SAME! * it just SPLENDIDLY! You go right on doing it EXACTLY the SAME!
*/ */
int main (int dont_care_argc, char **argv) int main (int dont_care_argc, char **argv)
{ /* {
before(*argv);
/*
Ok, she's gone now. Don't you mind her, she means well but yes, she is Ok, she's gone now. Don't you mind her, she means well but yes, she is
a bit of a busy-body. Always playing the matchmaker role, trying to do a bit of a busy-body. Always playing the matchmaker role, trying to do
away with unmarried windows and bachelors. So, back to business buddy! away with unmarried windows and bachelors. So, back to business buddy!
@ -2668,7 +2661,6 @@ int main (int dont_care_argc, char **argv)
Well then, here, try THIS sandwich... Well then, here, try THIS sandwich...
+-------------+ */ +-------------+ */
windows_stage1(); /* top (sic) slice */ windows_stage1(); /* top (sic) slice */
before(*argv); /* > seasonings, < */
configs_read(); /* > spread etc, < */ configs_read(); /* > spread etc, < */
parse_args(&argv[1]); /* > lean stuff, < */ parse_args(&argv[1]); /* > lean stuff, < */
whack_terminal(); /* > onions etc. < */ whack_terminal(); /* > onions etc. < */

30
top.h
View File

@ -25,10 +25,11 @@
/* Defines intended to be experimented with ------------------------ */ /* Defines intended to be experimented with ------------------------ */
//#define CASEUP_HEXES /* show any hex values in upper case */ //#define CASEUP_HEXES /* show any hex values in upper case */
//#define CASEUP_SCALE /* show scaled times & memory upper case */ //#define CASEUP_SCALE /* show scaled time/num suffix upper case */
//#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */ //#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */
//#define QUIT_NORMALQ /* use 'q' to quit, not new default 'Q' */ //#define QUIT_NORMALQ /* use 'q' to quit, not new default 'Q' */
//#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */ //#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */
//#define TICS_64_BITS /* accommodate Linux 2.5.xx 64-bit jiffies */
//#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */ //#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */
//#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */ //#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */
@ -101,8 +102,14 @@
/*###### Some Typedef's and Enum's #####################################*/ /*###### Some Typedef's and Enum's #####################################*/
/* This typedef attempts to ensure consistent 'ticks' handling. */ /* These typedefs attempt to ensure consistent 'ticks' handling */
#ifdef TICS_64_BITS
typedef unsigned long long TICS_t;
typedef long long STIC_t;
#else
typedef unsigned long TICS_t; typedef unsigned long TICS_t;
typedef long STIC_t;
#endif
/* This structure consolidates the information that's used /* This structure consolidates the information that's used
in a variety of display roles. */ in a variety of display roles. */
@ -257,8 +264,10 @@ typedef struct win {
/*###### Display Support *Data* ########################################*/ /*###### Display Support *Data* ########################################*/
/* An rcfile 'footprint' used to invalidate existing */ /* An rcfile 'footprint' used to invalidate existing local rcfile
#define RCF_FILEID 'e' and the global rcfile path + name */
#define RCF_FILEID 'g'
#define SYS_RCFILE "/etc/toprc"
/* The default fields displayed and their order, /* The default fields displayed and their order,
if nothing is specified by the loser, oops user */ if nothing is specified by the loser, oops user */
@ -270,8 +279,13 @@ typedef struct win {
/* These are the possible fscanf formats used in /proc/stat /* These are the possible fscanf formats used in /proc/stat
reads during history processing. */ reads during history processing. */
#ifdef TICS_64_BITS
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu\n"
#define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu\n"
#else
#define CPU_FMTS_MULTI "cpu%*d %lu %lu %lu %lu\n" #define CPU_FMTS_MULTI "cpu%*d %lu %lu %lu %lu\n"
#define CPU_FMTS_JUST1 "cpu %lu %lu %lu %lu\n" #define CPU_FMTS_JUST1 "cpu %lu %lu %lu %lu\n"
#endif
/* Summary Lines specially formatted string(s) -- /* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */ see 'show_special' for syntax details + other cautions. */
@ -338,8 +352,8 @@ typedef struct win {
"%s's - \01Help for Interactive Commands\02 - %s\n" \ "%s's - \01Help for Interactive Commands\02 - %s\n" \
"Window %s\06: \01Cumulative mode \03%s\02. \01System\06: \01Delay time \03%.1f secs\02; \01Secure mode \03%s\02.\n" \ "Window %s\06: \01Cumulative mode \03%s\02. \01System\06: \01Delay time \03%.1f secs\02; \01Secure mode \03%s\02.\n" \
" sp or ^L Redraw screen\n" \ " sp or ^L Redraw screen\n" \
" o Rearrange current window's fields\n" \ " o . Rearrange current window's fields\n" \
" f Add and remove current window's fields\n" \ " f . Add and remove current window's fields\n" \
" Z Change color mappings for any window\05\n" \ " Z Change color mappings for any window\05\n" \
"\n" \ "\n" \
"(7 letters) . Sort: \01C\02) cmd; \01M\02) mem; \01P\02) pid; \01T\02) time; \01U\02) cpu; \01Y\02) tty; \01E\02) user\n" \ "(7 letters) . Sort: \01C\02) cmd; \01M\02) mem; \01P\02) pid; \01T\02) time; \01U\02) cpu; \01Y\02) tty; \01E\02) user\n" \
@ -391,10 +405,6 @@ typedef struct win {
" 0x00040000 PF_KERNTHREAD (2.5)\n" \ " 0x00040000 PF_KERNTHREAD (2.5)\n" \
" 0x00100000 PF_USEDFPU (thru 2.4)\n" \ " 0x00100000 PF_USEDFPU (thru 2.4)\n" \
" 0x00400000 PF_ATOMICALLOC\n" \ " 0x00400000 PF_ATOMICALLOC\n" \
"\n" \
"Memory notes:\n" \
" VIRT = SWAP + RES\n" \
" RES = CODE + DATA\n" \
"" ""
/* Windows/Field Group Help specially formatted string(s) -- /* Windows/Field Group Help specially formatted string(s) --