cvs commit: src/usr.bin/top machine.c

Bruce Evans bde at zeta.org.au
Sun Apr 17 22:58:20 PDT 2005


On Sun, 17 Apr 2005, Giorgos Keramidas wrote:

> On 2005-04-17 23:01, Bruce Evans <bde at zeta.org.au> wrote:
>> Just removing the CPU column doesn't seem right.  ps has a -C flag to
>> switch between WCPU and CPU.
>
> We can add a new toggle command to top, i.e. 'C', that toggles between
> displaying WCPU or CPU.  This should regain us a lot of the space lost
> from COMMAND after I added THR.

I like that.

> Index: contrib/top/commands.c
> ===================================================================
> RCS file: /home/ncvs/src/contrib/top/commands.c,v
> retrieving revision 1.11
> diff -u -r1.11 commands.c
> --- contrib/top/commands.c	14 Apr 2005 15:02:03 -0000	1.11
> +++ contrib/top/commands.c	17 Apr 2005 13:53:19 -0000
> @@ -71,6 +71,7 @@
> 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\
> +C       - toggle the displaying of weighted CPU percentage\n\
> H       - toggle the displaying of threads\n\
> k       - kill processes; send a signal to a list of processes\n\
> m       - toggle the display between 'cpu' and 'io' modes\n\

Further unsorting of a sorted list.  The list was previously unsorted by
adding H after I.

> Index: contrib/top/machine.h
> ===================================================================
> RCS file: /home/ncvs/src/contrib/top/machine.h,v
> retrieving revision 1.6
> diff -u -r1.6 machine.h
> --- contrib/top/machine.h	17 Jul 2003 23:56:40 -0000	1.6
> +++ contrib/top/machine.h	17 Apr 2005 13:37:40 -0000
> @@ -60,6 +60,7 @@
>     int self;		/* show self */
>     int system;		/* show system processes */
>     int thread;		/* show threads */
> +    int wcpu;		/* show weighted cpu */
>     int uid;		/* only this uid (unless uid == -1) */
>     char *command;	/* only this command (unless == NULL) */
> };

More unsorting of a sorted list.

My mail program doesn't corrupt whitespace.  Something apparently corrupted
it before it got here.

> Index: contrib/top/top.c
> ===================================================================
> RCS file: /home/ncvs/src/contrib/top/top.c,v
> retrieving revision 1.16
> diff -u -r1.16 top.c
> --- contrib/top/top.c	14 Apr 2005 15:02:03 -0000	1.16
> +++ contrib/top/top.c	17 Apr 2005 13:43:26 -0000
> @@ -193,9 +193,9 @@
>     fd_set readfds;
>
> #ifdef ORDER
> -    static char command_chars[] = "\f qh?en#sdkriIutHmSo";
> +    static char command_chars[] = "\f qh?en#sdkriIutHCmSo";
> #else
> -    static char command_chars[] = "\f qh?en#sdkriIutHmS";
> +    static char command_chars[] = "\f qh?en#sdkriIutHCmS";
> #endif

Unsorting of unsorted lists.

> /* these defines enumerate the "strchr"s of the commands in command_chars */
> #define CMD_redraw	0
> @@ -216,10 +216,11 @@
> #define CMD_user	14
> #define CMD_selftog	15
> #define CMD_thrtog	16
> -#define CMD_viewtog	17
> -#define CMD_viewsys	18
> +#define	CMD_wcputog	17
> +#define CMD_viewtog	18
> +#define CMD_viewsys	19
> #ifdef ORDER
> -#define CMD_order       19
> +#define CMD_order       20
> #endif
>
>     /* set the buffer for stdout */

Adding at the end of this list would be acceptable, to avoid renumbering
everything.  But iterations of that is apparently how the order of
command_chars[] became random (historical).

No comment on other unsortings.

> Index: usr.bin/top/machine.c
> ===================================================================
> RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
> retrieving revision 1.71
> diff -u -r1.71 machine.c
> --- usr.bin/top/machine.c	16 Apr 2005 15:43:38 -0000	1.71
> +++ usr.bin/top/machine.c	17 Apr 2005 13:51:12 -0000

I thought that you would have to change the sorting method to switch
between WCPU and CPU, but the existing sorting is only on CPU.  It is
just more bogus to sort on CPU while only displaying WCPU.

> @@ -780,8 +780,7 @@
> 	    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),

Excessive parentheses.

Bruce


More information about the cvs-src mailing list