Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Nov 2000 12:43:12 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        hackers@FreeBSD.org
Subject:   Fixes to top(1) to use the full width of the screen for p_comm
Message-ID:  <XFMail.001128124312.jhb@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Hey gang,

One of my favorite tools to use during the SMPng stuff is top(1) as I get to
see all the Happy Little Processes bouncing around on CPU's and getting stuck
in SMTX, etc.  One annoyance is that even if the window is wider than 80 chars,
top(1) will only use 80 chars of data.  Notably, if someone adds some NIS user
to your network one day with a 16 character username *cough*, then suddently
you only get to see the first 6 characters of p_comm for each process, even if
you widen the window.  I looked around and found out that top was needlessly
assuming that the window width was always 80 chars, so I worked up a little
patch at http://www.FreeBSD.org/~jhb/patches/top.patch to teach top to use the
full window width for p_comm.  I'd like to commit this in a day or two if no
one objects.  Note that the change is in machine.c, so I _will_ _not_ _be_
_pulling_ _a_ _file_ _off_ _of_ _a_ _vendor_ _branch_.

Index: machine.c
===================================================================
RCS file: /host/ares/usr/home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.30
diff -u -r1.30 machine.c
--- machine.c   2000/09/07 01:32:38     1.30
+++ machine.c   2000/11/28 19:39:50
@@ -53,6 +53,7 @@
 
 #include "top.h"
 #include "machine.h"
+#include "screen.h"
 
 static int check_nlist __P((struct nlist *));
 static int getkval __P((unsigned long, int *, int, char *));
@@ -60,7 +61,7 @@
 int swapmode __P((int *retavail, int *retfree));
 static int smpmode;
 static int namelength;
-static int cmdlength;
+static int cmdlengthdelta;
 
 
 /* get_process_info passes back a handle.  This is what it looks like: */
@@ -315,7 +316,7 @@
     snprintf(Header, sizeof(Header), smpmode ? smp_header : up_header,
             namelength, namelength, uname_field);
 
-    cmdlength = 80 - strlen(Header) + 6;
+    cmdlengthdelta = strlen(Header) - 7;
 
     return Header;
 }
@@ -628,7 +629,9 @@
            format_time(cputime),
            100.0 * weighted_cpu(pct, pp),
            100.0 * pct,
-           cmdlength,
+           screen_width > cmdlengthdelta ?
+               screen_width - cmdlengthdelta :
+               0,
            printable(PP(pp, p_comm)));
 
     /* return the result */

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.001128124312.jhb>