teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0034-find-debuginfo.sh-Process-files-in-parallel.patch

Igor Gnatenko 082d5d
From aede94115e077e87504b03bf668ef375290200ad Mon Sep 17 00:00:00 2001
Igor Gnatenko 082d5d
From: Michal Marek <mmarek@suse.com>
Igor Gnatenko 082d5d
Date: Sat, 10 Sep 2016 23:13:25 +0200
Igor Gnatenko 082d5d
Subject: [PATCH 34/49] find-debuginfo.sh: Process files in parallel
Mark Wielaard a11f22
Igor Gnatenko 082d5d
Add a -j <n> option, which, when used, will spawn <n> processes to do the
Igor Gnatenko 082d5d
debuginfo extraction in parallel. A pipe is used to dispatch the files among
Igor Gnatenko 082d5d
the processes.
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Signed-off-by: Michal Marek <mmarek@suse.com>
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
(cherry picked from commit 1b338aa84d4c67fefa957352a028eaca1a45d1f6)
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Conflicts:
Igor Gnatenko 082d5d
	macros.in
Igor Gnatenko 082d5d
	scripts/find-debuginfo.sh
Igor Gnatenko 082d5d
---
Igor Gnatenko 082d5d
 macros.in                 |  2 +-
Igor Gnatenko 082d5d
 scripts/find-debuginfo.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++---
Igor Gnatenko 082d5d
 2 files changed, 61 insertions(+), 4 deletions(-)
Mark Wielaard a11f22
Mark Wielaard a11f22
diff --git a/macros.in b/macros.in
Igor Gnatenko 082d5d
index c5b1a0b26..93e360c79 100644
Mark Wielaard a11f22
--- a/macros.in
Mark Wielaard a11f22
+++ b/macros.in
Mark Wielaard a11f22
@@ -180,7 +180,7 @@
Mark Wielaard a11f22
 #	the script.  See the script for details.
Mark Wielaard a11f22
 #
Mark Wielaard a11f22
 %__debug_install_post   \
Mark Wielaard a11f22
-   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_no_recompute_build_ids:-n} %{?_include_minidebuginfo:-m} %{?_include_gdb_index:-i} %{?_unique_build_ids:--ver-rel "%{VERSION}-%{RELEASE}"} %{?_unique_debug_names:--unique-debug-arch "%{_arch}"} %{?_unique_debug_srcs:--unique-debug-src-base "%{name}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Mark Wielaard a11f22
+   %{_rpmconfigdir}/find-debuginfo.sh %{?_smp_mflags} %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_no_recompute_build_ids:-n} %{?_include_minidebuginfo:-m} %{?_include_gdb_index:-i} %{?_unique_build_ids:--ver-rel "%{VERSION}-%{RELEASE}"} %{?_unique_debug_names:--unique-debug-arch "%{_arch}"} %{?_unique_debug_srcs:--unique-debug-src-base "%{name}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Mark Wielaard a11f22
 %{nil}
Mark Wielaard a11f22
 
Mark Wielaard a11f22
 #	Template for debug information sub-package.
Mark Wielaard a11f22
diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh
Igor Gnatenko 082d5d
index c435a02e4..d8b718bdf 100644
Mark Wielaard a11f22
--- a/scripts/find-debuginfo.sh
Mark Wielaard a11f22
+++ b/scripts/find-debuginfo.sh
Igor Gnatenko 082d5d
@@ -74,6 +74,9 @@ unique_debug_arch=
Mark Wielaard a11f22
 # Base given by --unique-debug-src-base
Mark Wielaard a11f22
 unique_debug_src_base=
Mark Wielaard a11f22
 
Mark Wielaard a11f22
+# Number of parallel jobs to spawn
Mark Wielaard a11f22
+n_jobs=1
Mark Wielaard a11f22
+
Mark Wielaard a11f22
 BUILDDIR=.
Mark Wielaard a11f22
 out=debugfiles.list
Mark Wielaard a11f22
 nout=0
Igor Gnatenko 082d5d
@@ -137,6 +140,13 @@ while [ $# -gt 0 ]; do
Mark Wielaard a11f22
   -r)
Mark Wielaard a11f22
     strip_r=true
Mark Wielaard a11f22
     ;;
Mark Wielaard a11f22
+  -j)
Mark Wielaard a11f22
+    n_jobs=$2
Mark Wielaard a11f22
+    shift
Mark Wielaard a11f22
+    ;;
Mark Wielaard a11f22
+  -j*)
Mark Wielaard a11f22
+    n_jobs=${1#-j}
Mark Wielaard a11f22
+    ;;
Mark Wielaard a11f22
   *)
Mark Wielaard a11f22
     BUILDDIR=$1
Mark Wielaard a11f22
     shift
Igor Gnatenko 082d5d
@@ -389,9 +399,56 @@ do_file()
Mark Wielaard a11f22
   fi
Mark Wielaard a11f22
 }
Mark Wielaard a11f22
 
Mark Wielaard a11f22
-while read nlinks inum f; do
Mark Wielaard a11f22
-  do_file "$nlinks" "$inum" "$f"
Mark Wielaard a11f22
-done <"$temp/primary"
Mark Wielaard a11f22
+# 16^6 - 1 or about 16 milion files
Mark Wielaard a11f22
+FILENUM_DIGITS=6
Mark Wielaard a11f22
+run_job()
Mark Wielaard a11f22
+{
Mark Wielaard a11f22
+  local jobid=$1 filenum
Mark Wielaard a11f22
+  local SOURCEFILE=$temp/debugsources.$jobid ELFBINSFILE=$temp/elfbins.$jobid
Mark Wielaard a11f22
+
Mark Wielaard a11f22
+  >"$SOURCEFILE"
Mark Wielaard a11f22
+  >"$ELFBINSFILE"
Mark Wielaard a11f22
+  # can't use read -n <n>, because it reads bytes one by one, allowing for
Mark Wielaard a11f22
+  # races
Mark Wielaard a11f22
+  while :; do
Mark Wielaard a11f22
+    filenum=$(dd bs=$(( FILENUM_DIGITS + 1 )) count=1 status=none)
Mark Wielaard a11f22
+    if test -z "$filenum"; then
Mark Wielaard a11f22
+      break
Mark Wielaard a11f22
+    fi
Mark Wielaard a11f22
+    do_file $(sed -n "$(( 0x$filenum )) p" "$temp/primary")
Mark Wielaard a11f22
+  done
Mark Wielaard a11f22
+  echo 0 >"$temp/res.$jobid"
Mark Wielaard a11f22
+}
Mark Wielaard a11f22
+
Mark Wielaard a11f22
+n_files=$(wc -l <"$temp/primary")
Mark Wielaard a11f22
+if [ $n_jobs -gt $n_files ]; then
Mark Wielaard a11f22
+  n_jobs=$n_files
Mark Wielaard a11f22
+fi
Mark Wielaard a11f22
+if [ $n_jobs -le 1 ]; then
Mark Wielaard a11f22
+  while read nlinks inum f; do
Mark Wielaard a11f22
+    do_file "$nlinks" "$inum" "$f"
Mark Wielaard a11f22
+  done <"$temp/primary"
Mark Wielaard a11f22
+else
Mark Wielaard a11f22
+  for ((i = 1; i <= n_files; i++)); do
Mark Wielaard a11f22
+    printf "%0${FILENUM_DIGITS}x\\n" $i
Mark Wielaard a11f22
+  done | (
Mark Wielaard a11f22
+    exec 3<&0
Mark Wielaard a11f22
+    for ((i = 0; i < n_jobs; i++)); do
Mark Wielaard a11f22
+      # The shell redirects stdin to /dev/null for background jobs. Work
Mark Wielaard a11f22
+      # around this by duplicating fd 0
Mark Wielaard a11f22
+      run_job $i <&3 &
Mark Wielaard a11f22
+    done
Mark Wielaard a11f22
+    wait
Mark Wielaard a11f22
+  )
Mark Wielaard a11f22
+  for f in "$temp"/res.*; do
Mark Wielaard a11f22
+    res=$(< "$f")
Mark Wielaard a11f22
+    if [ "$res" !=  "0" ]; then
Mark Wielaard a11f22
+      exit 1
Mark Wielaard a11f22
+    fi
Mark Wielaard a11f22
+  done
Mark Wielaard a11f22
+  cat "$temp"/debugsources.* >"$SOURCEFILE"
Mark Wielaard a11f22
+  cat "$temp"/elfbins.* >"$ELFBINSFILE"
Mark Wielaard a11f22
+fi
Mark Wielaard a11f22
 
Mark Wielaard a11f22
 # Invoke the DWARF Compressor utility.
Mark Wielaard a11f22
 if $run_dwz \
Igor Gnatenko 082d5d
-- 
Igor Gnatenko 082d5d
2.13.2
Igor Gnatenko 082d5d