svn commit: r183781 - in user/edwin/top/top-3.8b1: contrib/top usr.bin/top

Edwin Groothuis edwin at FreeBSD.org
Sun Oct 12 09:15:07 UTC 2008


Author: edwin
Date: Sun Oct 12 09:15:05 2008
New Revision: 183781
URL: http://svn.freebsd.org/changeset/base/183781

Log:
  All collected changes to with regarding to the feedback received
  on the announcement of top 3.8b1 on -stable and -current as version
  B.
  
  This is considered the final version and submitted to mentor (bde@)
  for commit approval.

Modified:
  user/edwin/top/top-3.8b1/contrib/top/ap_snprintf.c
  user/edwin/top/top-3.8b1/contrib/top/boolean.h
  user/edwin/top/top-3.8b1/contrib/top/color.c
  user/edwin/top/top-3.8b1/contrib/top/color.h
  user/edwin/top/top-3.8b1/contrib/top/commands.c
  user/edwin/top/top-3.8b1/contrib/top/commands.h
  user/edwin/top/top-3.8b1/contrib/top/display.h
  user/edwin/top/top-3.8b1/contrib/top/getopt.c
  user/edwin/top/top-3.8b1/contrib/top/globalstate.h
  user/edwin/top/top-3.8b1/contrib/top/hash.c
  user/edwin/top/top-3.8b1/contrib/top/hash.h
  user/edwin/top/top-3.8b1/contrib/top/loadavg.h
  user/edwin/top/top-3.8b1/contrib/top/machine.h
  user/edwin/top/top-3.8b1/contrib/top/message.h
  user/edwin/top/top-3.8b1/contrib/top/os.h
  user/edwin/top/top-3.8b1/contrib/top/screen.h
  user/edwin/top/top-3.8b1/contrib/top/top.1.in
  user/edwin/top/top-3.8b1/contrib/top/top.c
  user/edwin/top/top-3.8b1/contrib/top/username.h
  user/edwin/top/top-3.8b1/contrib/top/utils.h
  user/edwin/top/top-3.8b1/contrib/top/version.c
  user/edwin/top/top-3.8b1/contrib/top/version.h
  user/edwin/top/top-3.8b1/usr.bin/top/Makefile
  user/edwin/top/top-3.8b1/usr.bin/top/config.h.in
  user/edwin/top/top-3.8b1/usr.bin/top/machine.c
  user/edwin/top/top-3.8b1/usr.bin/top/machine.man

Modified: user/edwin/top/top-3.8b1/contrib/top/ap_snprintf.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/ap_snprintf.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/ap_snprintf.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -15,6 +15,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  * This code is based on, and used with the permission of, the
  * SIO stdio-replacement strx_* functions by Panos Tsirigotis
  * <panos at alumni.cs.colorado.edu> for xinetd.

Modified: user/edwin/top/top-3.8b1/contrib/top/boolean.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/boolean.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/boolean.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -1,3 +1,7 @@
+/*
+ * $FreeBSD$
+ */
+
 /* My favorite names for boolean values */
 #define  No	0
 #define  Yes	1

Modified: user/edwin/top/top-3.8b1/contrib/top/color.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/color.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/color.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  *  Top users/processes display for Unix
  *  Version 3
  */

Modified: user/edwin/top/top-3.8b1/contrib/top/color.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/color.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/color.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  * Top - a top users display for Unix
  *
  * Definition of the color interface.

Modified: user/edwin/top/top-3.8b1/contrib/top/commands.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/commands.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/commands.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,7 +31,7 @@
  */
 
 /*
- *  $FreeBSD$
+ * $FreeBSD$
  */
 
 /*
@@ -641,6 +641,35 @@ cmd_delay(globalstate *gstate)
 }
 
 int
+cmd_pidonly(globalstate *gstate)
+
+{
+    int newval;
+    char tmpbuf[20];
+
+    message_prompt("PID to show: ");
+    newval = readline(tmpbuf, 8, Yes);
+    if ((gstate->pselect.pidonly = newval) <= 0) {
+	gstate->pselect.pidonly = -1;
+	message_error(" Showing all processes");
+    } else {
+	gstate->pselect.pidonly = newval;
+	message_error(" Showing only PID %d", gstate->pselect.pidonly);
+    }
+    return CMD_REFRESH;
+}
+
+int
+cmd_persecond(globalstate *gstate)
+
+{
+    gstate->pselect.persecond = !gstate->pselect.persecond;
+    message_error(" Displaying IO stats per %s.",
+		  gstate->pselect.persecond ? "second" : "delay period");
+    return CMD_REFRESH;
+}
+
+int
 cmd_idle(globalstate *gstate)
 
 {
@@ -688,9 +717,9 @@ int
 cmd_thisprocess(globalstate *gstate)
 
 {
-    gstate->pselect.self = !gstate->pselect.self;
+    gstate->pselect.self = (gstate->pselect.self == -1) ? getpid() : -1;
     message_error(" %sisplaying self.",
-		  gstate->pselect.self ? "D" : "Not d");
+		  (gstate->pselect.self != -1 ) ? "Not d" : "D");
     return CMD_REFRESH;
 }
 
@@ -758,6 +787,10 @@ cmd_order(globalstate *gstate)
     return CMD_OK;
 }
 
+#ifdef nomore
+/*
+ * This can be done via the order function
+ */
 int
 cmd_order_x(globalstate *gstate, char *name, ...)
 
@@ -822,6 +855,7 @@ cmd_order_time(globalstate *gstate)
 {
     return cmd_order_x(gstate, "time");
 }
+#endif
 
 #ifdef ENABLE_KILL
 
@@ -970,11 +1004,14 @@ command command_table[] = {
     { 'H', cmd_threads, "toggle the display of individual threads" },
     { 'j', cmd_jailid, "toggle the displaying of jail ID" },
     { 'J', cmd_jailfilter, "display processes by jail ID" },
+#ifdef nomore
     { 'M', cmd_order_mem, "sort by memory usage" },
     { 'N', cmd_order_pid, "sort by process id" },
     { 'P', cmd_order_cpu, "sort by CPU usage" },
-    { 'S', cmd_system, "toggle the display of system processes" },
     { 'T', cmd_order_time, "sort by CPU time" },
+#endif
+    { 'P', cmd_pidonly, "show only this PID" },
+    { 'S', cmd_system, "toggle the display of system processes" },
     { 'U', cmd_useruid, "toggle the display of usernames or uids" },
     { 'c', cmd_command, "display processes by command name" },
     { 'd', cmd_displays, "change number of displays to show" },
@@ -993,6 +1030,7 @@ command command_table[] = {
     { 'r', cmd_renice, "renice a process" },
 #endif
     { 's', cmd_delay, "change number of seconds to delay between updates" },
+    { 'p', cmd_persecond, "change IO stats per second instead of per delay" },
     { 't', cmd_thisprocess, "toggle the display of this process" },
     { 'u', cmd_user, "display processes for only one user (+ selects all users)" },
     { '\0', NULL, NULL },

Modified: user/edwin/top/top-3.8b1/contrib/top/commands.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/commands.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/commands.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 /* call specifications for commands.c */
 
 int command_process(globalstate *gstate, int cmd);

Modified: user/edwin/top/top-3.8b1/contrib/top/display.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/display.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/display.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 /* interface declaration for display.c */
 
 #ifndef _DISPLAY_H

Modified: user/edwin/top/top-3.8b1/contrib/top/getopt.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/getopt.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/getopt.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  * "getopt" routine customized for top.
  */
 

Modified: user/edwin/top/top-3.8b1/contrib/top/globalstate.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/globalstate.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/globalstate.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  * The global state of top is described in this structure.  It is passed
  * to routines that may need to examine or alter it.
  */

Modified: user/edwin/top/top-3.8b1/contrib/top/hash.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/hash.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/hash.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 /* hash.m4c */
 
 /* The file hash.c is generated from hash.m4c via the preprocessor M4 */

Modified: user/edwin/top/top-3.8b1/contrib/top/hash.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/hash.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/hash.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 /* hash.m4h */
 
 /* Interface definition for hash.c */

Modified: user/edwin/top/top-3.8b1/contrib/top/loadavg.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/loadavg.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/loadavg.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  *  Top - a top users display for Berkeley Unix
  *
  *  Defines required to access load average figures.

Modified: user/edwin/top/top-3.8b1/contrib/top/machine.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/machine.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/machine.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -108,6 +108,7 @@ struct process_select
 {
     int idle;		/* show idle processes */
     int self;		/* show self */
+    int pidonly;	/* only show this PID */
     int system;		/* show system processes */
     int fullcmd;	/* show full command */
     int usernames;      /* show usernames */
@@ -117,6 +118,7 @@ struct process_select
     int threads;	/* show threads separately */
     int jailid;		/* show jail ID */
     int jailfilter;	/* only this jail ID (unless jailfilter == -1) */
+    int persecond;	/* show IO stats per second */
 };
 
 /* routines defined by the machine dependent module */

Modified: user/edwin/top/top-3.8b1/contrib/top/message.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/message.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/message.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 /* interface declaration for display messages */
 /* This is a small subset of the interface from display.c that
    just contains the calls for displaying messages.  Do not include

Modified: user/edwin/top/top-3.8b1/contrib/top/os.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/os.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/os.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 #include "config.h"
 
 #include <sys/types.h>

Modified: user/edwin/top/top-3.8b1/contrib/top/screen.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/screen.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/screen.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  *  top - a top users display for Unix 4.2
  *
  *  This file contains all the definitions necessary to use the hand-written

Modified: user/edwin/top/top-3.8b1/contrib/top/top.1.in
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/top.1.in	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/top.1.in	Sun Oct 12 09:15:05 2008	(r183781)
@@ -399,6 +399,10 @@ memory, given in kilobytes.
 Current state (typically one of \*(lqsleep\*(rq,
 \*(lqrun\*(rq, \*(lqidl\*(rq, \*(lqzomb\*(rq, or \*(lqstop\*(rq).
 .TP
+.B FLG 
+Same as the ps(1) "STAT" column.
+See the explanation of "state" in the man-page of ps(1).
+.TP
 .B TIME
 Number of system and user cpu seconds that the process has used.
 .TP

Modified: user/edwin/top/top-3.8b1/contrib/top/top.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/top.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/top.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -206,7 +206,7 @@ sig_tstop(int i)	/* SIGTSTP handler */
     /* NOTREACHED */
 }
 
-#ifdef SIGWINCH
+#ifdef TOPSIGWINCH
 RETSIGTYPE
 sig_winch(int i)		/* SIGWINCH handler */
 
@@ -232,7 +232,7 @@ hold_signals()
     sigaddset(&signalset, SIGINT);
     sigaddset(&signalset, SIGQUIT);
     sigaddset(&signalset, SIGTSTP);
-#ifdef SIGWINCH
+#ifdef TOPSIGWINCH
     sigaddset(&signalset, SIGWINCH);
 #endif
     sigprocmask(SIG_BLOCK, &signalset, NULL);
@@ -243,7 +243,7 @@ hold_signals()
     sighold(SIGINT);
     sighold(SIGQUIT);
     sighold(SIGTSTP);
-#ifdef SIGWINCH
+#ifdef TOPSIGWINCH
     sighold(SIGWINCH);
     return NULL;
 #endif
@@ -251,7 +251,7 @@ hold_signals()
 
 #ifdef BSD_SIGNALS
     int mask;
-#ifdef SIGWINCH
+#ifdef TOPSIGWINCH
     mask = sigblock(sigmask(SIGINT) | sigmask(SIGQUIT) |
 		    sigmask(SIGTSTP) | sigmask(SIGWINCH));
 #else
@@ -269,7 +269,7 @@ set_signals()
     (void) set_signal(SIGINT, sig_leave);
     (void) set_signal(SIGQUIT, sig_leave);
     (void) set_signal(SIGTSTP, sig_tstop);
-#ifdef SIGWINCH
+#ifdef TOPSIGWINCH
     (void) set_signal(SIGWINCH, sig_winch);
 #endif
 }
@@ -286,7 +286,7 @@ release_signals(void *parm)
     sigrelse(SIGINT);
     sigrelse(SIGQUIT);
     sigrelse(SIGTSTP);
-#ifdef SIGWINCH
+#ifdef TOPSIGWINCH
     sigrelse(SIGWINCH);
 #endif
 #endif
@@ -339,9 +339,9 @@ do_arguments(globalstate *gstate, int ac
     optind = 1;
 
 #ifdef HAVE_GETOPT_LONG
-    while ((i = getopt_long(ac, av, "CDEHSIJ:Tabcijnqtuvs:d:U:o:m:P", longopts, NULL)) != -1)
+    while ((i = getopt_long(ac, av, "CDEHSIJ:Tabcijnpqtuvs:d:U:o:m:P", longopts, NULL)) != -1)
 #else
-    while ((i = getopt(ac, av, "CDEHSIJ:Tabcijnqtuvs:d:U:o:m:P")) != EOF)
+    while ((i = getopt(ac, av, "CDEHSIJ:Tabcijnpqtuvs:d:U:o:m:P")) != EOF)
 #endif
     {
 	switch(i)
@@ -468,7 +468,11 @@ do_arguments(globalstate *gstate, int ac
 	    break;
 
 	case 't':
-	    gstate->pselect.self = !gstate->pselect.self;
+	    gstate->pselect.self = (gstate->pselect.self == -1) ? getpid() : -1;
+	    break;
+
+	case 'p':
+	    gstate->pselect.persecond = !gstate->pselect.persecond;
 	    break;
 
 	case 'q':		/* be quick about it */
@@ -491,7 +495,7 @@ do_arguments(globalstate *gstate, int ac
 	default:
 	    fprintf(stderr,
 "Top version %s\n"
-"Usage: %s [-HIPSTabcijnqu] [-d x] [-s x] [-o field] [-U username] [-J jid] [number]\n",
+"Usage: %s [-HIPSTabCcijnpqu] [-d x] [-s x] [-o field] [-U username] [-J jid] [number]\n",
 		    version_string(), myname);
 	    exit(EX_USAGE);
 	}
@@ -800,6 +804,8 @@ main(int argc, char *argv[])
     /* preset defaults for process selection */
     gstate->pselect.idle = Yes;
     gstate->pselect.self = -1;
+    gstate->pselect.pidonly = -1;
+    gstate->pselect.persecond = No;
     gstate->pselect.threads = No;
     gstate->pselect.jailid = No;
     gstate->pselect.jailfilter = -1;
@@ -928,7 +934,6 @@ main(int argc, char *argv[])
     }
 
     /* check for infinity and for overflowed screen */
-    gstate->topn = gstate->max_topn;
     if (gstate->topn == Infinity)
     {
 	gstate->topn = INT_MAX;

Modified: user/edwin/top/top-3.8b1/contrib/top/username.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/username.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/username.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -30,6 +30,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * $FreeBSD$
+ */
+
 /* interface for username.c */
 
 #ifndef _USERNAME_H_

Modified: user/edwin/top/top-3.8b1/contrib/top/utils.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/utils.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/utils.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  *  Top users/processes display for Unix
  */
 

Modified: user/edwin/top/top-3.8b1/contrib/top/version.c
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/version.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/version.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  *  Top users/processes display for Unix
  *  Version 3
  */

Modified: user/edwin/top/top-3.8b1/contrib/top/version.h
==============================================================================
--- user/edwin/top/top-3.8b1/contrib/top/version.h	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/contrib/top/version.h	Sun Oct 12 09:15:05 2008	(r183781)
@@ -31,6 +31,10 @@
  */
 
 /*
+ * $FreeBSD$
+ */
+
+/*
  *  Top users/processes display for Unix
  */
 

Modified: user/edwin/top/top-3.8b1/usr.bin/top/Makefile
==============================================================================
--- user/edwin/top/top-3.8b1/usr.bin/top/Makefile	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/usr.bin/top/Makefile	Sun Oct 12 09:15:05 2008	(r183781)
@@ -7,7 +7,7 @@ PROG=	top
 SRCS=	commands.c display.c machine.c screen.c top.c \
 	username.c utils.c version.c color.c hash.c
 SRCS+=	sigdesc.h config.h
-CFLAGS+= -DHAVE_GETOPT -DHAVE_STRERROR -DORDER -DSIGWINCH -DHAS_SHOWTHREADS
+CFLAGS+= -DHAVE_GETOPT -DHAVE_STRERROR -DORDER -DTOPSIGWINCH -DHAS_SHOWTHREADS
 CFLAGS+= -I${.CURDIR} -I${TOPDIR} -I. -Wall -g
 
 #
@@ -51,7 +51,7 @@ CPU!=	uname -m
 config.h: config.h.in
 	@${ECHO} Making config.h from config.h.in
 	sed \
-		-e 's/@DEFAULT_TOPN@/30/' \
+		-e 's/@DEFAULT_TOPN@/-1/' \
 		-e 's/@DEFAULT_DELAY@/2/' \
 		-e 's/@HAVE_GETOPT_LONG@/1/' \
 		-e 's/@ENABLE_KILL@/1/' \
@@ -62,7 +62,7 @@ CLEANFILES+= top.1.local
 top.1.local: top.1.in
 	@${ECHO} Making top.1.local from top.1.in
 	@sed \
-		-e 's/@DEFAULT_TOPN@/30/' \
+		-e 's/@DEFAULT_TOPN@/-1/' \
 		-e 's/@DEFAULT_DELAY@/2/' \
 		-e 's/@HAVE_GETOPT_LONG@/1/' \
 		-e 's/@ENABLE_KILL@/1/' \
@@ -70,6 +70,9 @@ top.1.local: top.1.in
 
 CLEANFILES+= top.1
 top.1: top.1.local machine.man
-	cat ${.ALLSRC} > ${.TARGET}
+	L=`grep -n MAN_SUPPLEMENT top.1.local | awk -F: '{ print $$1 }'`; \
+	(head -`expr $$L - 1` top.1.local; \
+	 cat machine.man; \
+	 tail +`expr $$L + 1` top.1.local) > top.1
 
 .include <bsd.prog.mk>

Modified: user/edwin/top/top-3.8b1/usr.bin/top/config.h.in
==============================================================================
--- user/edwin/top/top-3.8b1/usr.bin/top/config.h.in	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/usr.bin/top/config.h.in	Sun Oct 12 09:15:05 2008	(r183781)
@@ -214,7 +214,7 @@
 #define MODULE "freebsd"
 
 /* Default number of processes to display on non-terminals when topn is all */
-#define NOMINAL_TOPN 40
+#define NOMINAL_TOPN -1
 
 /* Define the major OS revision number. */
 #define OSMAJOR 7

Modified: user/edwin/top/top-3.8b1/usr.bin/top/machine.c
==============================================================================
--- user/edwin/top/top-3.8b1/usr.bin/top/machine.c	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/usr.bin/top/machine.c	Sun Oct 12 09:15:05 2008	(r183781)
@@ -180,6 +180,7 @@ struct handle
 
 /* calculate a per-second rate using milliseconds */
 #define per_second(n, msec)   (((n) * 1000) / (msec))
+#define per_timeperiod(n, msec, timeperiod)   (((n) * timeperiod) / (msec))
 
 /* process state names for the "STATE" column of the display */
 /* the extra nulls in the string "run" are for adding a slash and
@@ -392,12 +393,15 @@ static int show_threads = 0;
 
 /* sorting orders. first is default */
 char *ordernames[] = {
-    "cpu", "size", "res", "time", "pri", "nice", "io", "pid", "jid", NULL
+    "cpu", "size", "res", "time", "pri", "nice", "io", "pid", "jid",
+    "vcsw", "ivcsw", "read", "write", "fault", NULL
 };
 
 /* compare routines */
 int proc_compare(), compare_size(), compare_res(), compare_time(),
-    compare_prio(), compare_nice(), compare_io(), compare_pid(), compare_jid();
+    compare_prio(), compare_nice(), compare_io(), compare_pid(),
+    compare_jid(), compare_vcsw(), compare_ivcsw(),
+    compare_read(), compare_write(), compare_fault();
 
 int (*proc_compares[])() = {
     proc_compare,
@@ -409,6 +413,11 @@ int (*proc_compares[])() = {
     compare_io,
     compare_pid,
     compare_jid,
+    compare_vcsw,
+    compare_ivcsw,
+    compare_read,
+    compare_write,
+    compare_fault,
     NULL
 };
 
@@ -724,6 +733,7 @@ fmt_command(char *buf, int sz, struct ki
     char cmd[MAX_COLS];
     char *bufp;
     char **args;
+    char *ps;
     int argc;
 
 #if OSMAJOR <= 4
@@ -737,7 +747,7 @@ fmt_command(char *buf, int sz, struct ki
         /* get the pargs structure */
         if ((args = kvm_getargv(kd, pp, sz)) != NULL)
         {
-	    /* successfull retrieval: now convert nulls in to spaces */
+	    /* successfull retrieval: now convert nulls and cr/lf in to spaces */
 	    bufp = cmd;
 	    cmd[0] = '\0';
 	    argc = 0;
@@ -748,6 +758,13 @@ fmt_command(char *buf, int sz, struct ki
 		strcat(cmd, args[argc++]);
 	    }
 
+	    while ((ps = strchr(cmd, '\r')) != NULL) {
+		*ps = ' ';
+	    }
+	    while ((ps = strchr(cmd, '\n')) != NULL) {
+		*ps = ' ';
+	    }
+
 	    /* format cmd as our answer */
 	    return snprintf(buf, sz, "%s", cmd);
         }
@@ -758,45 +775,82 @@ fmt_command(char *buf, int sz, struct ki
 }
 
 int
-fmt_vcsw(char *buf, int sz, struct kinfo_proc *pp)
+fmt_vcsw(char *buf, int sz, struct kinfo_proc *pp, int duration)
 
 {
-    return snprintf(buf, sz, "%6ld", per_second(SP(pp, vcsw), elapsed_msecs));
+    return snprintf(buf, sz, "%6ld", per_timeperiod(SP(pp, vcsw),
+	elapsed_msecs, duration));
+}
+int fmt_vcsw_ps(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_vcsw(buf, sz, pp, 1000);
+}
+int fmt_vcsw_pd(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_vcsw(buf, sz, pp, elapsed_msecs);
 }
 
 int
-fmt_ivcsw(char *buf, int sz, struct kinfo_proc *pp)
+fmt_ivcsw(char *buf, int sz, struct kinfo_proc *pp, int duration)
 
 {
-    return snprintf(buf, sz, "%6ld", per_second(SP(pp, ivcsw), elapsed_msecs));
+    return snprintf(buf, sz, "%6ld", per_timeperiod(SP(pp, ivcsw), elapsed_msecs, duration));
+}
+int fmt_ivcsw_ps(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_ivcsw(buf, sz, pp, 1000);
+}
+int fmt_ivcsw_pd(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_ivcsw(buf, sz, pp, elapsed_msecs);
 }
 
 int
-fmt_read(char *buf, int sz, struct kinfo_proc *pp)
+fmt_read(char *buf, int sz, struct kinfo_proc *pp, int duration)
 
 {
-    return snprintf(buf, sz, "%6ld", per_second(SP(pp, inblock), elapsed_msecs));
+    return snprintf(buf, sz, "%6ld", per_timeperiod(SP(pp, inblock), elapsed_msecs, duration));
+}
+int fmt_read_ps(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_read(buf, sz, pp, 1000);
+}
+int fmt_read_pd(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_read(buf, sz, pp, elapsed_msecs);
 }
 
 int
-fmt_write(char *buf, int sz, struct kinfo_proc *pp)
+fmt_write(char *buf, int sz, struct kinfo_proc *pp, int duration)
 
 {
-    return snprintf(buf, sz, "%6ld", per_second(SP(pp, oublock), elapsed_msecs));
+    return snprintf(buf, sz, "%6ld", per_timeperiod(SP(pp, oublock), elapsed_msecs, duration));
+}
+int fmt_write_ps(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_write(buf, sz, pp, 1000);
+}
+int fmt_write_pd(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_write(buf, sz, pp, elapsed_msecs);
 }
 
 int
-fmt_fault(char *buf, int sz, struct kinfo_proc *pp)
+fmt_fault(char *buf, int sz, struct kinfo_proc *pp, int duration)
 
 {
-    return snprintf(buf, sz, "%6ld", per_second(SP(pp, majflt), elapsed_msecs));
+    return snprintf(buf, sz, "%6ld", per_timeperiod(SP(pp, majflt), elapsed_msecs, duration));
+}
+int fmt_fault_ps(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_fault(buf, sz, pp, 1000);
+}
+int fmt_fault_pd(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_fault(buf, sz, pp, elapsed_msecs);
 }
 
 int
-fmt_iototal(char *buf, int sz, struct kinfo_proc *pp)
+fmt_iototal(char *buf, int sz, struct kinfo_proc *pp, int duration)
 
 {
-    return snprintf(buf, sz, "%6ld", per_second(SP(pp, totalio), elapsed_msecs));
+    return snprintf(buf, sz, "%6ld", per_timeperiod(SP(pp, totalio), elapsed_msecs, duration));
+}
+int fmt_iototal_ps(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_iototal(buf, sz, pp, 1000);
+}
+int fmt_iototal_pd(char *buf, int sz, struct kinfo_proc *pp) {
+	return fmt_iototal(buf, sz, pp, elapsed_msecs);
 }
 
 int
@@ -815,12 +869,14 @@ enum proc_fields {
 	FIELD_PID = 0, FIELD_JID, FIELD_USERNAME, FIELD_UID,
 	FIELD_THR, FIELD_PRI, FIELD_NICE, FIELD_SIZE, FIELD_RES,
 	FIELD_STATE, FIELD_FLG, FIELD_C, FIELD_TIME, FIELD_CPU,
-	FIELD_COMMAND, FIELD_VCSW, FIELD_IVCSW, FIELD_READ,
-	FIELD_WRITE, FIELD_FAULT, FIELD_TOTAL, FIELD_PERCENT
+	FIELD_COMMAND, FIELD_VCSW_PS, FIELD_IVCSW_PS, FIELD_READ_PS,
+	FIELD_WRITE_PS, FIELD_FAULT_PS, FIELD_TOTAL_PS, FIELD_PERCENT,
+	FIELD_VCSW_PD, FIELD_IVCSW_PD, FIELD_READ_PD,
+	FIELD_WRITE_PD, FIELD_FAULT_PD, FIELD_TOTAL_PD
 
 };
 
-#define MAX_FIELDS 25
+#define MAX_FIELDS 31
 struct proc_field proc_field[MAX_FIELDS] = {
     { "PID", 6, 1, 0, fmt_pid },
     { "JID", 3, 1, 0, fmt_jid },
@@ -837,13 +893,19 @@ struct proc_field proc_field[MAX_FIELDS]
     { "TIME", 6, 1, 0, fmt_time },
     { "CPU", 6, 1, 0, fmt_cpu },
     { "COMMAND", 7, 0, 0, fmt_command },
-    { "VCSW", 6, 1, 0, fmt_vcsw },
-    { "IVCSW", 6, 1, 0, fmt_ivcsw },
-    { "READ", 6, 1, 0, fmt_read },
-    { "WRITE", 6, 1, 0, fmt_write },
-    { "FAULT", 6, 1, 0, fmt_fault },
-    { "TOTAL", 6, 1, 0, fmt_iototal },
+    { "VCSW", 6, 1, 0, fmt_vcsw_ps },
+    { "IVCSW", 6, 1, 0, fmt_ivcsw_ps },
+    { "READ", 6, 1, 0, fmt_read_ps },
+    { "WRITE", 6, 1, 0, fmt_write_ps },
+    { "FAULT", 6, 1, 0, fmt_fault_ps },
+    { "TOTAL", 6, 1, 0, fmt_iototal_ps },
     { "PERCENT", 7, 1, 0, fmt_iopct },
+    { "VCSW", 6, 1, 0, fmt_vcsw_pd },
+    { "IVCSW", 6, 1, 0, fmt_ivcsw_pd },
+    { "READ", 6, 1, 0, fmt_read_pd },
+    { "WRITE", 6, 1, 0, fmt_write_pd },
+    { "FAULT", 6, 1, 0, fmt_fault_pd },
+    { "TOTAL", 6, 1, 0, fmt_iototal_pd },
     { NULL, 0, 0, 0, NULL }
 };
 
@@ -1179,6 +1241,7 @@ get_process_info(struct system_info *si,
     /* these are copied out of sel for speed */
     int show_idle;
     int show_self;
+    int show_pidonly;
     int show_system;
     int show_jailfilter;
     int show_uid;
@@ -1230,7 +1293,8 @@ get_process_info(struct system_info *si,
 
     /* set up flags which define what we are going to select */
     show_idle = sel->idle;
-    show_self = 0;
+    show_self = sel->self != -1;
+    show_pidonly = sel->pidonly != -1;
     show_system = sel->system;
     show_uid = sel->uid != -1;
     show_fullcmd = sel->fullcmd;
@@ -1347,6 +1411,8 @@ get_process_info(struct system_info *si,
 		 (PP(pp, stat) == SRUN)) &&
 		(!show_uid || PRUID(pp) == (uid_t)sel->uid) &&
 		(!show_jailfilter || PP(pp, jid) == sel->jailfilter) &&
+		(!show_self || PP(pp, pid) != sel->self) &&
+		(!show_pidonly || PP(pp, pid) == sel->pidonly) &&
 		(show_command == NULL ||
 		 strcasestr(PP(pp, comm), show_command) != NULL))
 	    {
@@ -1368,8 +1434,12 @@ get_process_info(struct system_info *si,
 			PP(parent, runtime) += PP(pp, runtime);
 			PPCPU(parent) += PPCPU(pp);
 		    } else {
-			printf("Cannot happen");
-			exit(0);
+			/*
+			 * XXX - Ignore it for now
+			 * It happens when you have threaded applications
+			 * while not showing idle processes.
+			 */
+			continue;
 			/* This shouldn't happen! */
 			PP(prev_pp, pctcpu) += PP(pp, pctcpu);
 			PP(prev_pp, runtime) += PP(pp, runtime);
@@ -1435,6 +1505,23 @@ format_process_header(struct process_sel
 	mode0_display :
 	mode1_display;
 
+    /* Show per second instead of per delay */
+    if (sel->persecond) {
+	field_subst(fi, FIELD_VCSW_PD, FIELD_VCSW_PS);
+	field_subst(fi, FIELD_IVCSW_PD, FIELD_IVCSW_PS);
+	field_subst(fi, FIELD_READ_PD, FIELD_READ_PS);
+	field_subst(fi, FIELD_WRITE_PD, FIELD_WRITE_PS);
+	field_subst(fi, FIELD_FAULT_PD, FIELD_FAULT_PS);
+	field_subst(fi, FIELD_TOTAL_PD, FIELD_TOTAL_PS);
+    } else {
+	field_subst(fi, FIELD_VCSW_PS, FIELD_VCSW_PD);
+	field_subst(fi, FIELD_IVCSW_PS, FIELD_IVCSW_PD);
+	field_subst(fi, FIELD_READ_PS, FIELD_READ_PD);
+	field_subst(fi, FIELD_WRITE_PS, FIELD_WRITE_PD);
+	field_subst(fi, FIELD_FAULT_PS, FIELD_FAULT_PD);
+	field_subst(fi, FIELD_TOTAL_PS, FIELD_TOTAL_PD);
+    }
+
     /* set username field correctly */
     if (!sel->usernames)
     {
@@ -1622,6 +1709,21 @@ static unsigned char sorted_state[] =
 #define ORDERKEY_JID \
   if ( (result = PP(p2, jid) - PP(p1, jid)) == 0)
 
+#define ORDERKEY_VCSW \
+  if ( (result = SP(p2, vcsw) - SP(p1, vcsw)) == 0)
+
+#define ORDERKEY_IVCSW \
+  if ( (result = SP(p2, ivcsw) - SP(p1, ivcsw)) == 0)
+
+#define ORDERKEY_READ \
+  if ( (result = SP(p2, inblock) - SP(p1, inblock)) == 0)
+
+#define ORDERKEY_WRITE \
+  if ( (result = SP(p2, oublock) - SP(p1, oublock)) == 0)
+
+#define ORDERKEY_FAULT \
+  if ( (result = SP(p2, majflt) - SP(p1, majflt)) == 0)
+
 /* compare_cpu - the comparison function for sorting by cpu percentage */
 
 int
@@ -1826,7 +1928,107 @@ compare_pid(struct proc **pp1, struct pr
     return(result);
 }
 
-/* compare_jid - the comparison function for sorting by jail id */
+/* compare_vcsw - the comparison function for sorting by jail id */
+
+int
+compare_vcsw(struct proc **pp1, struct proc **pp2)
+
+{
+    struct kinfo_proc *p1;
+    struct kinfo_proc *p2;
+    int result;
+
+    /* remove one level of indirection */
+    p1 = *(struct kinfo_proc **) pp1;
+    p2 = *(struct kinfo_proc **) pp2;
+
+    ORDERKEY_VCSW
+    ;
+
+    return(result);
+}
+
+/* compare_ivcsw - the comparison function for sorting by vcsw */
+
+int
+compare_ivcsw(struct proc **pp1, struct proc **pp2)
+
+{
+    struct kinfo_proc *p1;
+    struct kinfo_proc *p2;
+    int result;
+
+    /* remove one level of indirection */
+    p1 = *(struct kinfo_proc **) pp1;
+    p2 = *(struct kinfo_proc **) pp2;
+
+    ORDERKEY_IVCSW
+    ;
+
+    return(result);
+}
+
+/* compare_read - the comparison function for sorting by ivcsw */
+
+int
+compare_read(struct proc **pp1, struct proc **pp2)
+
+{
+    struct kinfo_proc *p1;
+    struct kinfo_proc *p2;
+    int result;
+
+    /* remove one level of indirection */
+    p1 = *(struct kinfo_proc **) pp1;
+    p2 = *(struct kinfo_proc **) pp2;
+
+    ORDERKEY_READ
+    ;
+
+    return(result);
+}
+
+/* compare_write - the comparison function for sorting by read */
+
+int
+compare_write(struct proc **pp1, struct proc **pp2)
+
+{
+    struct kinfo_proc *p1;
+    struct kinfo_proc *p2;
+    int result;
+
+    /* remove one level of indirection */
+    p1 = *(struct kinfo_proc **) pp1;
+    p2 = *(struct kinfo_proc **) pp2;
+
+    ORDERKEY_WRITE
+    ;
+
+    return(result);
+}
+
+/* compare_fault - the comparison function for sorting by write */
+
+int
+compare_fault(struct proc **pp1, struct proc **pp2)
+
+{
+    struct kinfo_proc *p1;
+    struct kinfo_proc *p2;
+    int result;
+
+    /* remove one level of indirection */
+    p1 = *(struct kinfo_proc **) pp1;
+    p2 = *(struct kinfo_proc **) pp2;
+
+    ORDERKEY_FAULT
+    ;
+
+    return(result);
+}
+
+/* compare_jid - the comparison function for sorting by fault */
 
 int
 compare_jid(struct proc **pp1, struct proc **pp2)

Modified: user/edwin/top/top-3.8b1/usr.bin/top/machine.man
==============================================================================
--- user/edwin/top/top-3.8b1/usr.bin/top/machine.man	Sun Oct 12 09:12:05 2008	(r183780)
+++ user/edwin/top/top-3.8b1/usr.bin/top/machine.man	Sun Oct 12 09:15:05 2008	(r183781)
@@ -1,3 +1,6 @@
+.\"
+.\" $FreeBSD
+.\"
 .SH "FreeBSD NOTES"
 Priorities are shown the same as they exist in process data structures,
 ranging from 0 to 255.  Note that this is not the same as the ps(1) 
@@ -20,8 +23,8 @@ Time sharing user threads
 Idle user threads
 
 .SH "FreeBSD THREADS"
-Starting with FreeBSD 8.0 the display of individual threads can be
-toggled with the synonymous commands
+Starting with FreeBSD 7.1 and 8.0 the display of individual threads
+can be toggled with the synonymous commands
 .B t
 and
 .BR H.


More information about the svn-src-user mailing list