From 53270b6c16c4ee152d8cd53a00ecf7155569e86a Mon Sep 17 00:00:00 2001 From: Frank Sundermeyer Date: Thu, 9 Jun 2016 16:02:23 +0200 Subject: [PATCH] Fix for issue #362 The new global switch --jobs lets you specify how mny parallel jobs to use when processing XML and image with DAPS. If not specified, the number is set to the number of CPU cores (as was done in previous versions). --- bin/daps.in | 26 +++++++++++++++++++++++--- lib/daps_functions | 12 +++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/bin/daps.in b/bin/daps.in index 9febf6943..545c52c31 100755 --- a/bin/daps.in +++ b/bin/daps.in @@ -265,6 +265,11 @@ else VERBOSITY=0 fi +# Set the maximum number of concurrent jobs to the number of cores +# If egrep does not return somethiong usefule, set it to "2" as a sane default +JOBS=$(egrep -s -m1 "cpu cores\s*:" /proc/cpuinfo 2>/dev/null | sed 's/cpu cores\s*:\s*//') +[[ -z $JOBS ]] && JOBS=2 + #--------------------------------------------------- # SUBCOMMANDS # @@ -677,17 +682,24 @@ Global Options: --fb_styleroot Fallback styleroot directories. Can only be used in conjunction with --styleroot. By default, the DocBook stylesheets are used as a fallback if - custom styles for an output format are not present. + custom styles for an output format are not present. With this option you can specify a list of alternative fallbacks (space separated absolute paths). The directories will be tested in the order specified, the first one that applies to the requested format, will be used. The original DocBook stylesheets will be used as a last resort. - Useful if you have forks of your custom stylesheets. + Useful if you have forks of your custom + stylesheets. --force Force a rebuild of the document even when an up-to-date version exists. --help, -h Help + --jobs Specify how many parallel jobs to use. Higher + numbers will significantly increase the processing + speed, but will also set your machine under heavy + load, up to a point where it may become + (temporarily) unresponsive. + Default: Use as man jobs as available CPU cores. --main, -m Path to the main file defining your document. Note: Options --main and --docconfig exclude each other. @@ -1079,7 +1091,7 @@ export POSIXLY_CORRECT=1 # Therefore we need to save each variable twice in order to recover the # original value. -ARGS=$(getopt -o d:e:hm:v:: -l builddir:,color:,colour:,commands,debug,docconfig:,dapsroot:,envfile:,fb_styleroot:,force,help,main:,schema:,styleroot:,verbosity::,version,xsltprocessor: -n "$ME" -- "$@") +ARGS=$(getopt -o d:e:hm:v:: -l builddir:,color:,colour:,commands,debug,docconfig:,dapsroot:,envfile:,fb_styleroot:,force,help,jobs:,main:,schema:,styleroot:,verbosity::,version,xsltprocessor: -n "$ME" -- "$@") # Exit when getopt returns errors # @@ -1159,6 +1171,14 @@ while true ; do CALL_SCMDHELP=1 fi ;; + --jobs) + if [[ $2 =~ ^[0-9][0-9]*$ ]]; then + JOBS="$2" + else + exit_on_error "Wrong value ($2) for --jobs. Must be a numeric" + fi + shift 2 + ;; -m|--main) # make path absolute and strip trailing slash sanitize_path "$2" "MAIN_CMDL" diff --git a/lib/daps_functions b/lib/daps_functions index d23e05392..9c9389b09 100644 --- a/lib/daps_functions +++ b/lib/daps_functions @@ -528,11 +528,13 @@ function call_make { MAKE_OPTIONS="$MAKE_OPTIONS --debug=b" fi fi + + # By default the number of parallel jobs for make is set to the number of + # CPU cores. This can be overwritten with --jobs. + # If verbosity 3 (-v3) is set, "make -j1" is forced + # if [[ 0 = "$VERBOSITY" || 1 = "$VERBOSITY" || 2 = "$VERBOSITY" ]]; then - # calculate Number of CPUs (cores) for -j option, set to "1" if empty - CORE_NO=$(egrep -s -m1 "cpu cores\s*:" /proc/cpuinfo 2>/dev/null | sed 's/cpu cores\s*:\s*//') - [[ -z "$CORE_NO" ]] && CORE_NO=1 - MAKE_OPTIONS="$MAKE_OPTIONS -j${CORE_NO}" + MAKE_OPTIONS="$MAKE_OPTIONS -j${JOBS}" [[ 1 != "$DEBUG" || 1 = "$SILENT" ]] && MAKE_OPTIONS="$MAKE_OPTIONS -s" else # highest verbosity level - use -j1 for a better readability @@ -655,7 +657,7 @@ function call_make { echo # Misc - for V in MAKECMD XSLTPROCESSOR XML_CATALOG_FILES; do + for V in MAKE_CMD XSLTPROCESSOR XML_CATALOG_FILES; do printf "%${COLWIDTH}s: %s\n" "$V" "${!V}" done echo -e "\n---------------\n"