Skip to content

Commit

Permalink
Fix for issue #362
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
fsundermeyer committed Jun 9, 2016
1 parent 0f4fb6d commit 53270b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
26 changes: 23 additions & 3 deletions bin/daps.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions lib/daps_functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 53270b6

Please sign in to comment.