svn commit: r198848 - head/bin/ps

Xin LI delphij at delphij.net
Fri Nov 6 23:52:38 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bruce Evans wrote:
> On Tue, 3 Nov 2009, Xin LI wrote:
> 
>> Log:
>>  Increase width for %CPU, RSS and VSZ columns for now.  Modern systems
>>  tend to have larger memory, larger process, and more CPU.
> 
> This uses space that is not available.  Command names(+args) are now
> truncated to 9 columns in "ps l" output :-(.  They used to be truncated to
> 11 columns recently (down from 12 columns in FreeBSD-5.2).

I think we may have to live with this, even if we can cut down CPU
percentage part, the memory column's width is still too narrow for
modern systems.  I have actually thought about having the numbers
humanized but I'm afraid it would break some existing scripts :(

[...]
> There seems to be no better fix than to further granulate and dehumanize
> the numbers so that they fit in the available space.  E.g., a %CPU of
>> = 100 and < 9999 should be displayed in %4.0f format; this only
> involvues granulation, but above 9999 it needs to be dehumanized as
> well and displayed in k or M or larger granularity (it can be > 9999
> with 100 CPUs and > 999k with 10000 CPUs).  A VSZ of >= 10000 (k
> implicit) needs to be displayed in M or larger granularity (M explicit).

Will it sound reasonable to divide pcpu by ncpu and cap the number at 100?

Cheers,
- --
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!	       Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.13 (FreeBSD)

iEYEARECAAYFAkr0trIACgkQi+vbBBjt66CxkwCeLjSGhfB438LAsqFcK6vCgdmY
0OIAn2OmQLRttIhvMYVjqQvYviLzgVBc
=C87q
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: keyword.c
===================================================================
--- keyword.c	(revision 199006)
+++ keyword.c	(working copy)
@@ -70,7 +70,7 @@
 
 /* PLEASE KEEP THE TABLE BELOW SORTED ALPHABETICALLY!!! */
 static VAR var[] = {
-	{"%cpu", "%CPU", NULL, 0, pcpu, NULL, 5, 0, CHAR, NULL, 0},
+	{"%cpu", "%CPU", NULL, 0, pcpu, NULL, 4, 0, CHAR, NULL, 0},
 	{"%mem", "%MEM", NULL, 0, pmem, NULL, 4, 0, CHAR, NULL, 0},
 	{"acflag", "ACFLG", NULL, 0, kvar, NULL, 3, KOFF(ki_acflag), USHORT,
 		"x", 0},
Index: nlist.c
===================================================================
--- nlist.c	(revision 199006)
+++ nlist.c	(working copy)
@@ -47,6 +47,7 @@
 int	nlistread;			/* if nlist already read. */
 unsigned long	mempages;		/* number of pages of phys. memory */
 int	fscale;				/* kernel _fscale variable */
+int	ncpu;				/* number of cpus */
 
 int
 donlist(void)
@@ -62,6 +63,9 @@
 	oldlen = sizeof(mempages);
 	if (sysctlbyname("hw.availpages", &mempages, &oldlen, NULL, 0) == -1)
 		return (1);
+	oldlen = sizeof(ncpu);
+	if (sysctlbyname("hw.ncpu", &ncpu, &oldlen, NULL, 0) == -1)
+		return (1);
 	nlistread = 1;
 	return (0);
 }
Index: extern.h
===================================================================
--- extern.h	(revision 199006)
+++ extern.h	(working copy)
@@ -36,7 +36,7 @@
 struct varent;
 
 extern fixpt_t ccpu;
-extern int cflag, eval, fscale, nlistread, rawcpu;
+extern int cflag, eval, fscale, ncpu, nlistread, rawcpu;
 extern unsigned long mempages;
 extern time_t now;
 extern int showthreads, sumrusage, termwidth, totwidth;
Index: print.c
===================================================================
--- print.c	(revision 199006)
+++ print.c	(working copy)
@@ -642,10 +642,13 @@
 void
 pcpu(KINFO *k, VARENT *ve)
 {
-	VAR *v;
+	VAR *v = ve->var;
+	double pctcpu = getpcpu(k);
 
-	v = ve->var;
-	(void)printf("%*.1f", v->width, getpcpu(k));
+	if (pctcpu / ncpu >= 100.0)
+		(void)printf(" 100");
+	else
+		(void)printf("%*.1f", v->width, pctcpu / ncpu);
 }
 
 static double


More information about the svn-src-all mailing list