tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

patch: parallelized pkg_chk



Hi,

"pkg_chk -uqB" as used by pkg_rolling-replace is quite slow on systems
with many packages installed because it needs to run bmake on in each
package directory to extract PKGNAME and optionally other things.
The attached patch parallelizes this phase up to MAKE_JOBS.

On my 10c/20t system with 804 packages installed the time to run
"pkg_chk -uq" with this patch drops from 10m to 1m24s. Still not fast
but much better. Comments?

Kind regards,
-Tobias
Index: pkg_chk.sh
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_chk/files/pkg_chk.sh,v
retrieving revision 1.76
diff -p -u -r1.76 pkg_chk.sh
--- pkg_chk.sh	10 Nov 2019 10:25:43 -0000	1.76
+++ pkg_chk.sh	12 Mar 2020 19:58:20 -0000
@@ -57,11 +57,40 @@ bin_pkg_info2pkgdb()
     '
     }
 
+cache_pkg_vars()
+    {
+	jobs=0
+	for pkgdir in $* ; do
+	    if [ -n "$opt_B" ];then
+		(
+		    PKGNAME=
+		    extract_pkg_vars $pkgdir PKGNAME FILESDIR PKGDIR DISTINFO_FILE PATCHDIR
+		    if [ -n "${PKGNAME}" ]; then
+			get_build_ver > /dev/null
+		    fi
+		) &
+	    elif [ -n "$opt_s" ] ; then
+		extract_pkg_vars $pkgdir PKGNAME &
+	    else
+		return
+	    fi
+	    jobs=$(expr $jobs + 1)
+	    if [ $jobs -ge $MAKE_JOBS ]; then
+		wait -n
+		jobs=$(expr $jobs - 1)
+	    fi
+	done
+    }
+
 check_packages_installed()
     {
     MISSING_TODO=
     MISMATCH_TODO=
 
+    extract_mk_var MAKE_JOBS 1
+    if [ $MAKE_JOBS -gt 1 ]; then
+	cache_pkg_vars $*
+    fi
     for pkgdir in $* ; do
 
 	if [ -n "$opt_B" ];then
@@ -154,6 +183,8 @@ check_packages_installed()
 cleanup_and_exit()
     {
     rm -f $MY_TMPFILE
+    rm -f $MY_TMPDIR/.mv_*
+    rm -f $MY_TMPDIR/.bv_*
     rmdir $MY_TMPDIR
     exit "$@"
     }
@@ -169,14 +200,21 @@ delete_pkgs()
 
 extract_make_vars()
     {
+    cache=${MY_TMPDIR}/.mv_$(echo "$(pwd) $*" | sed 's/[^a-zA-Z]/_/g')
+    if [ -f $cache ]; then
+	eval "$(cat $cache)"
+	return
+    fi
     MAKEFILE=$1
     shift
     MAKEDATA=".PHONY: x\nx:\n";
     for var in $* ; do
 	MAKEDATA=$MAKEDATA"\t@echo $var=\${$var}\n"
     done
-    eval $(printf "$MAKEDATA" | ${MAKE} -f - -f $MAKEFILE x | \
-					${SED} -e 's/[^=]*=/&"/' -e 's/$/"/')
+    cache_val="$(printf "$MAKEDATA" | ${MAKE} -f - -f $MAKEFILE x | \
+      ${SED} -e 's/[^=]*=/&"/' -e 's/$/"/')"
+    eval "$cache_val"
+    echo "$cache_val" > $cache
     for var in $* ; do
 	verbose_var $var
     done
@@ -331,15 +369,20 @@ get_bin_pkg_info()
 
 get_build_ver()
     {
+    cache=${MY_TMPDIR}/.bv_$(pwd | sed 's/[^a-zA-Z]/_/g')
+    if [ -f $cache ]; then
+	cat $cache
+	return
+    fi
     if [ -n "$opt_b" -a -z "$opt_s" ] ; then
-	${PKG_INFO} -q -b $PACKAGES/$PKGNAME$PKG_SUFX | ${GREP} .
+	${PKG_INFO} -q -b $PACKAGES/$PKGNAME$PKG_SUFX | ${GREP} . > $cache
+	cat $cache
 	return
     fi
     # Unfortunately pkgsrc always outputs to a file, but it does
     # helpfully allows us to specify the name
-    rm -f $MY_TMPFILE
-    ${MAKE} _BUILD_VERSION_FILE=$MY_TMPFILE $MY_TMPFILE
-    cat $MY_TMPFILE
+    ${MAKE} _BUILD_VERSION_FILE=$cache $cache
+    cat $cache
     }
 
 is_binary_available()


Home | Main Index | Thread Index | Old Index