svn commit: r335539 - head/usr.bin/top

Baptiste Daroussin bapt at FreeBSD.org
Fri Jun 22 11:02:40 UTC 2018


On Fri, Jun 22, 2018 at 09:21:02AM +0000, Eitan Adler wrote:
> Author: eadler
> Date: Fri Jun 22 09:21:01 2018
> New Revision: 335539
> URL: https://svnweb.freebsd.org/changeset/base/335539
> 
> Log:
>   top(1): reimplement header formatting as sbuf
>   
>   The current header formatting is a giant format string that changes
>   global state during the format process.
>   
>   Make the following changes:
>   - use sbuf to build up the header rather than use the above
>   pseudo-dynamic one
>   - Change name length to 10
>   - Reduce size of RES and SIZE by making humanize more aggressive
>   - Restore a version number line to the copyright. This may be required
>   by the copyright (and may not be; its unclear)
>   
>   This is also a pre-req to implementing TOPCOLOR from newer versions of
>   top(1)
>   
>   Discussed with:	allanjude, rpolka, danfe, rgrimes
>   Differential Revision: https://reviews.freebsd.org/D15801
> 
> Modified:
>   head/usr.bin/top/Makefile
>   head/usr.bin/top/commands.c
>   head/usr.bin/top/machine.c
>   head/usr.bin/top/machine.h
>   head/usr.bin/top/utils.c
> 
> Modified: head/usr.bin/top/Makefile
> ==============================================================================
> --- head/usr.bin/top/Makefile	Fri Jun 22 09:20:50 2018	(r335538)
> +++ head/usr.bin/top/Makefile	Fri Jun 22 09:21:01 2018	(r335539)
> @@ -16,5 +16,5 @@ NO_WERROR=
>  .endif
>  CFLAGS.clang=-Wno-error=incompatible-pointer-types-discards-qualifiers -Wno-error=cast-qual
>  
> -LIBADD=	ncursesw m kvm jail util
> +LIBADD=	ncursesw m kvm jail util sbuf
>  .include <bsd.prog.mk>
> 
> Modified: head/usr.bin/top/commands.c
> ==============================================================================
> --- head/usr.bin/top/commands.c	Fri Jun 22 09:20:50 2018	(r335538)
> +++ head/usr.bin/top/commands.c	Fri Jun 22 09:21:01 2018	(r335539)
> @@ -1,5 +1,6 @@
>  /*
>   *  Top users/processes display for Unix
> + *  Version 3
>   *
>   *  This program may be freely redistributed,
>   *  but this entire comment MUST remain intact.
> 
> Modified: head/usr.bin/top/machine.c
> ==============================================================================
> --- head/usr.bin/top/machine.c	Fri Jun 22 09:20:50 2018	(r335538)
> +++ head/usr.bin/top/machine.c	Fri Jun 22 09:21:01 2018	(r335539)
> @@ -22,6 +22,7 @@
>  #include <sys/priority.h>
>  #include <sys/proc.h>
>  #include <sys/resource.h>
> +#include <sys/sbuf.h>
>  #include <sys/sysctl.h>
>  #include <sys/time.h>
>  #include <sys/user.h>
> @@ -49,18 +50,14 @@
>  #include "layout.h"
>  
>  #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
> -#define	SMPUNAMELEN	13
> -#define	UPUNAMELEN	15
>  
>  extern struct timeval timeout;
>  static int smpmode;
>  enum displaymodes displaymode;
> -static int namelength = 8;
> +static const int namelength = 10;
>  /* TOP_JID_LEN based on max of 999999 */
> -#define TOP_JID_LEN 7
> -#define TOP_SWAP_LEN 6
> -static int jidlength;
> -static int swaplength;
> +#define TOP_JID_LEN 6
> +#define TOP_SWAP_LEN 5
>  static int cmdlengthdelta;
>  
>  /* get_process_info passes back a handle.  This is what it looks like: */
> @@ -92,24 +89,12 @@ static const char io_header[] =
>  static const char io_Proc_format[] =
>      "%5d%*s %-*.*s %6ld %6ld %6ld %6ld %6ld %6ld %6.2f%% %.*s";
>  
> -/* XXX: build up header instead of statically defining them.
> - * This will also allow for a "format string" to be supplied
> - * as an argument to top(1) instead of having predefined options */
> -static const char smp_header_thr_and_pid[] =
> -    "  %s%*s %-*.*s  THR PRI NICE   SIZE    RES%*s STATE   C   TIME %7s COMMAND";
> -static const char smp_header_id_only[] =
> -    "  %s%*s %-*.*s  PRI NICE   SIZE    RES%*s STATE   C   TIME %7s COMMAND";
>  static const char smp_Proc_format[] =
> -    "%5d%*s %-*.*s %s%3d %4s%7s %6s%*.*s %-6.6s %2d%7s %6.2f%% %.*s";
> +    "%5d%*s %-*.*s %s%3d %4s%6s %5s%*.*s %-6.6s %2d%7s %6.2f%% %.*s";
>  
> -static char up_header_thr_and_pid[] =
> -    "  %s%*s %-*.*s  THR PRI NICE   SIZE    RES%*s STATE    TIME %7s COMMAND";
> -static char up_header_id_only[] =
> -    "  %s%*s %-*.*s   PRI NICE   SIZE    RES%*s STATE    TIME %7s COMMAND";
>  static char up_Proc_format[] =
> -    "%5d%*s %-*.*s %s%3d %4s%7s %6s%*.*s %-6.6s%.0d%7s %6.2f%% %.*s";
> +    "%5d%*s %-*.*s %s%3d %4s%6s %5s%*.*s %-6.6s%.0d%7s %6.2f%% %.*s";
>  
> -
>  /* process state names for the "STATE" column of the display */
>  /* the extra nulls in the string "run" are for adding a slash and
>     the processor number when needed */
> @@ -325,12 +310,6 @@ machine_init(struct statics *statics)
>  	    NULL, 0) == 0 && carc_en == 1)
>  		carc_enabled = 1;
>  
> -	namelength = MAXLOGNAME;
> -	if (smpmode && namelength > SMPUNAMELEN)
> -		namelength = SMPUNAMELEN;
> -	else if (namelength > UPUNAMELEN)
> -		namelength = UPUNAMELEN;
> -
>  	kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
>  	if (kd == NULL)
>  		return (-1);
> @@ -407,63 +386,46 @@ machine_init(struct statics *statics)
>  	return (0);
>  }
>  
> -const char *
> +char *
>  format_header(const char *uname_field)
>  {
> -	static char Header[128];
> -	const char *prehead;
> +	static struct sbuf* header = NULL;
>  
> -	if (ps.jail)
> -		jidlength = TOP_JID_LEN + 1;	/* +1 for extra left space. */
> -	else
> -		jidlength = 0;
> +	/* clean up from last time. */
> +	if (header != NULL) {
> +		sbuf_delete(header);

wouldn't it be better with a sbuf_clear here?

if != null: clear else new_auto

Best regards,
Bapt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20180622/c2939809/attachment.sig>


More information about the svn-src-all mailing list