summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2004-07-01 09:12:38 +0000
committeralfred <alfred@FreeBSD.org>2004-07-01 09:12:38 +0000
commitbf711ae9b25535d6a475aa2fe661dcd9c0b4e4b5 (patch)
treec715d25705cef277e259078e1d728bc053d10852 /contrib
parente6d783678aceef9e4b0a403a1b995ec353582fa3 (diff)
downloadFreeBSD-src-bf711ae9b25535d6a475aa2fe661dcd9c0b4e4b5.zip
FreeBSD-src-bf711ae9b25535d6a475aa2fe661dcd9c0b4e4b5.tar.gz
New feature, provide a display that shows the amount of IO processes
are doing. Toggle this mode by hitting "m" or passing the command line option "-m io" to top(1). This allows one to identify disk bandwidth hogs much easier.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/top/top.X8
-rw-r--r--contrib/top/top.c51
-rw-r--r--contrib/top/top.h6
3 files changed, 55 insertions, 10 deletions
diff --git a/contrib/top/top.X b/contrib/top/top.X
index 4282f57..fb71060 100644
--- a/contrib/top/top.X
+++ b/contrib/top/top.X
@@ -20,6 +20,8 @@ top \- display and update information about the top cpu processes
] [
.BI \-U username
] [
+.BI \-m io | cpu
+] [
.I number
]
.SH DESCRIPTION
@@ -87,6 +89,9 @@ Do not display the
.I top
process.
.TP
+.BI \-m display
+Display either 'cpu' or 'io' statistics. Default is 'cpu'.
+.TP
.B \-n
Use \*(lqnon-interactive\*(rq mode. This is identical to \*(lqbatch\*(rq
mode.
@@ -214,6 +219,9 @@ will make
.I top
show one final display and then immediately exit.
.TP
+.B m
+Toggle the display between 'cpu' and 'io' modes.
+.TP
.B n or #
Change the number of processes to display (prompt for new number).
.TP
diff --git a/contrib/top/top.c b/contrib/top/top.c
index 5d30e66..8ee9b02 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -99,6 +99,7 @@ extern int (*proc_compares[])();
#else
extern int proc_compare();
#endif
+extern int io_compare();
time_t time();
caddr_t get_process_info();
@@ -192,9 +193,9 @@ char *argv[];
fd_set readfds;
#ifdef ORDER
- static char command_chars[] = "\f qh?en#sdkriIutHo";
+ static char command_chars[] = "\f qh?en#sdkriIutHmo";
#else
- static char command_chars[] = "\f qh?en#sdkriIutH";
+ static char command_chars[] = "\f qh?en#sdkriIutHm";
#endif
/* these defines enumerate the "strchr"s of the commands in command_chars */
#define CMD_redraw 0
@@ -215,8 +216,9 @@ char *argv[];
#define CMD_user 14
#define CMD_selftog 15
#define CMD_thrtog 16
+#define CMD_viewtog 17
#ifdef ORDER
-#define CMD_order 17
+#define CMD_order 18
#endif
/* set the buffer for stdout */
@@ -272,7 +274,7 @@ char *argv[];
optind = 1;
}
- while ((i = getopt(ac, av, "SIHbinquvs:d:U:o:t")) != EOF)
+ while ((i = getopt(ac, av, "SIHbinquvs:d:U:m:o:t")) != EOF)
{
switch(i)
{
@@ -352,6 +354,20 @@ char *argv[];
}
break;
+ case 'm': /* select sort order */
+ if (strcmp(optarg, "io") == 0) {
+ displaymode = DISP_IO;
+ } else if (strcmp(optarg, "cpu") == 0) {
+ displaymode = DISP_CPU;
+ } else {
+ fprintf(stderr,
+ "%s: warning: `-m' option can only take args "
+ "'io' or 'cpu'\n",
+ myname);
+ exit(1);
+ }
+ break;
+
case 'o': /* select sort order */
#ifdef ORDER
order_name = optarg;
@@ -545,18 +561,25 @@ restart:
while ((displays == -1) || (displays-- > 0))
{
+ int (*compare)();
+
+
/* get the current stats */
get_system_info(&system_info);
- /* get the current set of processes */
- processes =
- get_process_info(&system_info,
- &ps,
+ if (displaymode == DISP_CPU) {
#ifdef ORDER
- proc_compares[order_index]);
+ compare = proc_compares[order_index];
#else
- proc_compare);
+ compare = proc_compare;
#endif
+ } else {
+ compare = io_compare;
+ }
+
+ /* get the current set of processes */
+ processes =
+ get_process_info(&system_info, &ps, compare);
/* display the load averages */
(*d_loadave)(system_info.last_pid,
@@ -968,6 +991,14 @@ restart:
ps.thread ? "D" : "Not d");
putchar('\r');
break;
+ case CMD_viewtog:
+ if (++displaymode == DISP_MAX)
+ displaymode = 0;
+ header_text = format_header(uname_field);
+ display_header(Yes);
+ d_header = i_header;
+ reset_display();
+ break;
#ifdef ORDER
case CMD_order:
new_message(MT_standout,
diff --git a/contrib/top/top.h b/contrib/top/top.h
index aeed136..59cdeed 100644
--- a/contrib/top/top.h
+++ b/contrib/top/top.h
@@ -1,4 +1,7 @@
/*
+ * $FreeBSD$
+ */
+/*
* Top - a top users display for Berkeley Unix
*
* General (global) definitions
@@ -34,3 +37,6 @@ char *version_string();
#define NUM_AVERAGES 3
+enum displaymodes { DISP_CPU = 0, DISP_IO, DISP_MAX };
+
+extern enum displaymodes displaymode;
OpenPOWER on IntegriCloud