Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Jul 2008 09:43:03 +0300
From:      "V.Chukharev" <chukharev@mail.ru>
To:        dinoex@freebsd.org
Cc:        "freebsd-ports@freebsd.org" <freebsd-ports@freebsd.org>
Subject:   Mk/bsd.openssl.mk optimization
Message-ID:  <op.ueqfl1xy0g54sc@localhost>

next in thread | raw e-mail | index | archive | help
Dear maintainer,

I have noticed that most time of 'make index' on my system takes a grep for libssl.
The following is done while 'make index' was running.

$ ps axww | grep libssl
23119  p1  IN+    0:00,00 sh -c grep -l -r "^lib/libssl.so." "/var/db/pkg" |  while read contents; do  sslprefix=`grep "^@cwd " "${contents}" | /usr/bin/head -n 1`;  if test "${sslprefix}" = "@cwd /usr/local" ; then  echo "${contents}"; break; fi; done
23124  p1  DN+    0:00,84 grep -l -r ^lib/libssl.so. /var/db/pkg
23125  p1  IN+    0:00,00 sh -c grep -l -r "^lib/libssl.so." "/var/db/pkg" |  while read contents; do  sslprefix=`grep "^@cwd " "${contents}" | /usr/bin/head -n 1`;  if test "${sslprefix}" = "@cwd /usr/local" ; then  echo "${contents}"; break; fi; done
24555  p1  IN+    0:00,00 sh -c grep -l -r "^lib/libssl.so." "/var/db/pkg" |  while read contents; do  sslprefix=`grep "^@cwd " "${contents}" | /usr/bin/head -n 1`;  if test "${sslprefix}" = "@cwd /usr/local" ; then  echo "${contents}"; break; fi; done
24556  p1  DN+    0:00,41 grep -l -r ^lib/libssl.so. /var/db/pkg
24557  p1  IN+    0:00,00 sh -c grep -l -r "^lib/libssl.so." "/var/db/pkg" |  while read contents; do  sslprefix=`grep "^@cwd " "${contents}" | /usr/bin/head -n 1`;  if test "${sslprefix}" = "@cwd /usr/local" ; then  echo "${contents}"; break; fi; done

So I looked through some Mk stuff, and tryed to optimize it. Since I do not
know any magic of bsd.*.mk, I did just a simple test. And with the below shown
patch the time is only 1500 s, while with the original version the time is more
than 15000 s. I guess the time depens very much on number of installed ports,
I have about 1300.

The resulting INDEX* files are identical.

I should confess I do not understand how my patch works. I expected to see a 
file /usr/ports/.openssl_installed or /tmp/index_something/.openssl_installed
or similar, but could not see it... But I hope this patch will inspire you 
to do something really working. 


chu@chu:/usr/ports 22:08:17 $ sudo time nice make index
Generating INDEX-7 - please wait..Warning: Duplicate INDEX entry: apr-gdbm-db42-1.3.2
Warning: Duplicate INDEX entry: mod_rpaf-ap2-0.6
Done.
    1503.11 real       988.23 user       116.09 sys
chu@chu:/usr/ports 22:33:49 $ diff -u Mk/bsd.openssl.mk.orig Mk/bsd.openssl.mk
--- Mk/bsd.openssl.mk.orig	2008-05-18 01:34:41.000000000 +0300
+++ Mk/bsd.openssl.mk	2008-07-22 22:07:31.000000000 +0300
@@ -121,11 +121,15 @@
	exists(${DESTDIR}/${LOCALBASE}/lib/libcrypto.so)
# find installed port and use it for dependency
PKG_DBDIR?=		${DESTDIR}/var/db/pkg
+.if exists(${WRKDIR}/.openssl_installed)
+OPENSSL_INSTALLED!=	cat ${WRKDIR}/.openssl_installed
+.else
OPENSSL_INSTALLED!=	grep -l -r "^lib/libssl.so." "${PKG_DBDIR}" | \
			while read contents; do \
				sslprefix=`grep "^@cwd " "$${contents}" | ${HEAD} -n 1`; \
				if test "$${sslprefix}" = "@cwd ${LOCALBASE}" ; then \
-					echo "$${contents}"; break; fi; done
+					echo "$${contents}" | tee ${WRKDIR}/.openssl_installed; break; fi; done
+.endif
OPENSSL_PORT!=		grep "^@comment ORIGIN:" "${OPENSSL_INSTALLED}" | ${CUT} -d : -f 2
OPENSSL_SHLIBFILE!=	grep "^lib/libssl.so." "${OPENSSL_INSTALLED}"
OPENSSL_SHLIBVER?=	${OPENSSL_SHLIBFILE:E}


Without the patch:

chu@chu:/usr/ports 22:43:24 $ sudo time nice make index
Generating INDEX-7 - please wait..Warning: Duplicate INDEX entry: apr-gdbm-db42-1.3.2
Warning: Duplicate INDEX entry: mod_rpaf-ap2-0.6
Done.
   15216.17 real      1045.99 user       261.20 sys



-- 
V. Chukharev



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