summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/top/commands.c1
-rw-r--r--contrib/top/machine.h1
-rw-r--r--contrib/top/top.c29
-rw-r--r--usr.bin/top/machine.c40
4 files changed, 47 insertions, 24 deletions
diff --git a/contrib/top/commands.c b/contrib/top/commands.c
index 8d7f331..200f0cc 100644
--- a/contrib/top/commands.c
+++ b/contrib/top/commands.c
@@ -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\
diff --git a/contrib/top/machine.h b/contrib/top/machine.h
index 62b321c..17e48cd 100644
--- a/contrib/top/machine.h
+++ b/contrib/top/machine.h
@@ -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) */
};
diff --git a/contrib/top/top.c b/contrib/top/top.c
index 2f7fa2f..00acd85 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -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 @@ restart:
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;
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 070ac87..335710f 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -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 { \
OpenPOWER on IntegriCloud