Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Sep 2001 10:50:06 +0100 (BST)
From:      Nick Hibma <n_hibma@FreeBSD.ORG>
To:        Thomas Quinot <thomas@cuivre.fr.eu.org>
Cc:        <current@FreeBSD.ORG>
Subject:   Re: top(1) takes ages to start up
Message-ID:  <20010908104633.P575-100000@heather.plazza.uk>
In-Reply-To: <20010907163406.A18904@melusine.cuivre.fr.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help

Why don't you add an early-out for namelength => 15 or put the
if-statement in the loop:

Index: machine.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.44
diff -u -r1.44 machine.c
--- machine.c   2001/05/31 22:36:51     1.44
+++ machine.c   2001/09/08 09:48:03
@@ -216,13 +216,16 @@
     while ((pw = getpwent()) != NULL) {
        if (strlen(pw->pw_name) > namelength)
            namelength = strlen(pw->pw_name);
+       if (smpmode && namelength > 13) {
+           namelength = 13;
+           break;
+       } else if (namelength > 15) {
+           namelength = 15;
+           break;
+       }
     }
     if (namelength < 8)
        namelength = 8;
-    if (smpmode && namelength > 13)
-       namelength = 13;
-    else if (namelength > 15)
-       namelength = 15;

     if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
"kvm_open")) == NULL)
        return -1;


On Fri, 7 Sep 2001, Thomas Quinot wrote:

> ... because it walks through the entire NIS db just to find out what the
> longest user name is (/src/usr.bin/top/machine.c 1.5). At this site,
> this means 2800 RPC calls and dozens of seconds when the network and/or
> NIS server are busy.
>
> What do others think of the following patch?
>
> Thomas.
>
> --- machine.c.dist	Fri Jun  1 00:36:51 2001
> +++ machine.c	Fri Sep  7 16:31:45 2001
> @@ -212,7 +212,7 @@
>           sysctlbyname("kern.smp.active", &smpmode, &modelen, NULL, 0) < 0) ||
>  	modelen != sizeof(smpmode))
>  	    smpmode = 0;
> -
> +#ifndef NO_GETPWENT
>      while ((pw = getpwent()) != NULL) {
>  	if (strlen(pw->pw_name) > namelength)
>  	    namelength = strlen(pw->pw_name);
> @@ -223,6 +223,9 @@
>  	namelength = 13;
>      else if (namelength > 15)
>  	namelength = 15;
> +#else
> +    namelength = 8;
> +#endif
>
>      if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open")) == NULL)
>  	return -1;
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-current" in the body of the message
>


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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010908104633.P575-100000>