Merge the CPU and WCPU columns in a single %6.2f column, add a new 'C'

command that toggles between the two and update the ORDER_PCTCPU()
macro to sort correctly by the visible "cpu" value.

This saves 6 more columns in 80-column terminals, making things a lot
better for the COMMAND column.

Tested on:	i386, sparc64 (panther), amd64 (sledge)
Approved by:	davidxu (in principle)
This commit is contained in:
Giorgos Keramidas 2005-05-18 13:30:08 +00:00
parent 8d44de8fdf
commit bbf750fbff
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=146342
4 changed files with 47 additions and 24 deletions

View file

@ -68,6 +68,7 @@ sophisticated enough to handle those commands gracefully.\n\n", stdout);
else
{
fputs("\
C - toggle the displaying of weighted CPU percentage\n\
d - change number of displays to show\n\
e - list errors generated by last \"kill\" or \"renice\" command\n\
i or I - toggle the displaying of idle processes\n\

View file

@ -61,6 +61,7 @@ struct process_select
int system; /* show system processes */
int thread; /* show threads */
int uid; /* only this uid (unless uid == -1) */
int wcpu; /* show weighted cpu */
char *command; /* only this command (unless == NULL) */
};

View file

@ -193,9 +193,9 @@ char *argv[];
fd_set readfds;
#ifdef ORDER
static char command_chars[] = "\f qh?en#sdkriIutHmSo";
static char command_chars[] = "\f qh?en#sdkriIutHmSCo";
#else
static char command_chars[] = "\f qh?en#sdkriIutHmS";
static char command_chars[] = "\f qh?en#sdkriIutHmSC";
#endif
/* these defines enumerate the "strchr"s of the commands in command_chars */
#define CMD_redraw 0
@ -218,8 +218,9 @@ char *argv[];
#define CMD_thrtog 16
#define CMD_viewtog 17
#define CMD_viewsys 18
#define CMD_wcputog 19
#ifdef ORDER
#define CMD_order 19
#define CMD_order 20
#endif
/* set the buffer for stdout */
@ -250,6 +251,7 @@ char *argv[];
ps.system = No;
ps.uid = -1;
ps.thread = No;
ps.wcpu = 1;
ps.command = NULL;
/* get preset options from the environment */
@ -275,7 +277,7 @@ char *argv[];
optind = 1;
}
while ((i = getopt(ac, av, "SIHbinquvs:d:U:m:o:t")) != EOF)
while ((i = getopt(ac, av, "CSIHbinquvs:d:U:m:o:t")) != EOF)
{
switch(i)
{
@ -383,15 +385,19 @@ char *argv[];
case 't':
ps.self = (ps.self == -1) ? getpid() : -1;
break;
case 'C':
ps.wcpu = !ps.wcpu;
break;
case 'H':
ps.thread = !ps.thread;
break;
default:
fprintf(stderr, "\
Top version %s\n\
Usage: %s [-HISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
Usage: %s [-CHISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
version_string(), myname);
exit(1);
}
@ -993,6 +999,15 @@ Usage: %s [-HISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
reset_display();
putchar('\r');
break;
case CMD_wcputog:
ps.wcpu = !ps.wcpu;
new_message(MT_standout | MT_delayed,
"Displaying %sCPU",
ps.wcpu ? "W" : "");
header_text = format_header(uname_field);
reset_display();
putchar('\r');
break;
case CMD_viewtog:
if (++displaymode == DISP_MAX)
displaymode = 0;

View file

@ -105,20 +105,20 @@ static char io_header[] =
"%5d %-*.*s %6ld %6ld %6ld %6ld %6ld %6ld %6.2f%% %.*s"
static char smp_header_thr[] =
" PID %-*.*s THR PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND";
" PID %-*.*s THR PRI NICE SIZE RES STATE C TIME %6s COMMAND";
static char smp_header[] =
" PID %-*.*s " "PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND";
" PID %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND";
#define smp_Proc_format \
"%5d %-*.*s %s%3d %4d%7s %6s %-6.6s %1x%7s %5.2f%% %5.2f%% %.*s"
"%5d %-*.*s %s%3d %4d%7s %6s %-6.6s %1x%7s %5.2f%% %.*s"
static char up_header_thr[] =
" PID %-*.*s THR PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
" PID %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND";
static char up_header[] =
" PID %-*.*s " "PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
" PID %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND";
#define up_Proc_format \
"%5d %-*.*s %s%3d %4d%7s %6s %-6.6s%.0d%7s %5.2f%% %5.2f%% %.*s"
"%5d %-*.*s %s%3d %4d%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s"
/* process state names for the "STATE" column of the display */
@ -298,17 +298,17 @@ format_header(char *uname_field)
prehead = smpmode ?
(ps.thread ? smp_header : smp_header_thr) :
(ps.thread ? up_header : up_header_thr);
snprintf(Header, sizeof(Header), prehead,
namelength, namelength, uname_field,
ps.wcpu ? "WCPU" : "CPU");
break;
case DISP_IO:
prehead = io_header;
snprintf(Header, sizeof(Header), prehead,
namelength, namelength, uname_field);
break;
}
snprintf(Header, sizeof(Header), prehead,
namelength, namelength, uname_field);
cmdlengthdelta = strlen(Header) - 7;
return (Header);
}
@ -780,8 +780,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int))
status,
smpmode ? pp->ki_lastcpu : 0,
format_time(cputime),
100.0 * weighted_cpu(pct, pp),
100.0 * pct,
ps.wcpu ? 100.0 * weighted_cpu(pct, pp) : 100.0 * pct,
screen_width > cmdlengthdelta ?
screen_width - cmdlengthdelta :
0,
@ -845,10 +844,17 @@ static int sorted_state[] =
};
#define ORDERKEY_PCTCPU(a, b) do { \
long diff = (long)(b)->ki_pctcpu - (long)(a)->ki_pctcpu; \
if (diff != 0) \
return (diff > 0 ? 1 : -1); \
#define ORDERKEY_PCTCPU(a, b) do { \
long diff; \
if (ps.wcpu) \
diff = floor(1.0E6 * weighted_cpu(pctdouble((b)->ki_pctcpu), (b))) - \
floor(1.0E6 * weighted_cpu(pctdouble((a)->ki_pctcpu), (a))); \
else \
diff = (long)(b)->ki_pctcpu - (long)(a)->ki_pctcpu; \
/* fprintf(stderr, "XXX: wcpu %d a %p (%s) b %p (%s) foo %lf\n", \
ps.wcpu, (a), (a)->ki_comm, (b), (b)->ki_comm, foo); */ \
if (diff != 0) \
return (diff > 0 ? 1 : -1); \
} while (0)
#define ORDERKEY_CPTICKS(a, b) do { \