diff options
author | alfred <alfred@FreeBSD.org> | 2004-07-01 09:12:38 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2004-07-01 09:12:38 +0000 |
commit | bf711ae9b25535d6a475aa2fe661dcd9c0b4e4b5 (patch) | |
tree | c715d25705cef277e259078e1d728bc053d10852 /contrib/top/top.c | |
parent | e6d783678aceef9e4b0a403a1b995ec353582fa3 (diff) | |
download | FreeBSD-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/top/top.c')
-rw-r--r-- | contrib/top/top.c | 51 |
1 files changed, 41 insertions, 10 deletions
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, |