Skip to content

Commit 572ae53

Browse files
committed
[build-script] Allow to tune dsymutil parallelism
This should enable scaling when using machines with large amount of RAM. To better support machines with lower spec, process one binary per dsymutil invocation (reverting #34149). Add some (limited) facilities to gather the time taken to execute dsymutil to better assist in tuning the parameter. Addresses rdar://71018443
1 parent a9f5107 commit 572ae53

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

utils/build-script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ class BuildScriptInvocation(object):
499499
pipes.quote(opt) for opt in cmake.common_options()),
500500
"--build-args=%s" % ' '.join(
501501
pipes.quote(arg) for arg in cmake.build_args()),
502+
"--dsymutil-jobs", str(args.dsymutil_jobs),
502503
]
503504

504505
# Compute any product specific cmake arguments.

utils/build-script-impl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ KNOWN_SETTINGS=(
7171
swift-tools-num-parallel-lto-link-jobs "" "The number of parallel link jobs to use when compiling swift tools"
7272
use-gold-linker "" "Enable using the gold linker"
7373
workspace "${HOME}/src" "source directory containing llvm, clang, swift"
74+
dsymutil-jobs "1" "number of parallel invocations of dsymutil"
7475

7576
## Build Tools
7677
host-cc "" "the path to CC, the 'clang' compiler for the host platform. **This argument is required**"
@@ -3015,6 +3016,25 @@ for host in "${ALL_HOSTS[@]}"; do
30153016
done
30163017
done
30173018

3019+
function printJSONTimestamp {
3020+
local command=$1
3021+
local kind=$2
3022+
3023+
echo "{ \"command\": \"${command}\", \"${kind}\": \"$(date "+%Y-%m-%dT%H:%M:%S")\" }"
3024+
}
3025+
3026+
function printJSONStartTimestamp {
3027+
local command=$1
3028+
3029+
printJSONTimestamp ${command} "start"
3030+
}
3031+
3032+
function printJSONEndTimestamp {
3033+
local command=$1
3034+
3035+
printJSONTimestamp ${command} "end"
3036+
}
3037+
30183038
for host in "${ALL_HOSTS[@]}"; do
30193039
# Check if we should perform this action.
30203040
if ! [[ $(should_execute_action "${host}-extractsymbols") ]]; then
@@ -3030,6 +3050,7 @@ for host in "${ALL_HOSTS[@]}"; do
30303050
host_install_destdir=$(get_host_install_destdir ${host})
30313051
host_install_prefix=$(get_host_install_prefix ${host})
30323052

3053+
30333054
if [[ "${DARWIN_INSTALL_EXTRACT_SYMBOLS}" ]] && [[ $(host_has_darwin_symbols ${host}) ]]; then
30343055
echo "--- Extracting symbols ---"
30353056

@@ -3047,6 +3068,9 @@ for host in "${ALL_HOSTS[@]}"; do
30473068
# Instead, just echo we do "darwin_intall_extract_symbols".
30483069
if [[ "${DRY_RUN}" ]]; then
30493070
call darwin_install_extract_symbols
3071+
printJSONStartTimestamp dsymutil
3072+
echo xargs -n 1 -P ${DSYMUTIL_JOBS} dsymutil
3073+
printJSONEndTimestamp dsymutil
30503074
else
30513075
set -x
30523076

@@ -3069,13 +3093,16 @@ for host in "${ALL_HOSTS[@]}"; do
30693093
#
30703094
# Exclude shell scripts and static archives.
30713095
# Exclude swift-api-digester dSYM to reduce debug toolchain size.
3072-
# Run sequentially -- dsymutil is multithreaded and can be memory intensive
3096+
# Tweak carefully the amount of parallelism -- dsymutil can be memory intensive and
3097+
# as such too many instance can exhaust the memory and slow down/panic the machine
3098+
printJSONStartTimestamp dsymutil
30733099
(cd "${host_symroot}" &&
30743100
find ./"${CURRENT_PREFIX}" -perm -0111 -type f -print | \
30753101
grep -v '.py$' | \
30763102
grep -v '.a$' | \
30773103
grep -v 'swift-api-digester' | \
3078-
xargs -P 1 ${dsymutil_path})
3104+
xargs -n 1 -P ${DSYMUTIL_JOBS} ${dsymutil_path})
3105+
printJSONEndTimestamp dsymutil
30793106

30803107
# Strip executables, shared libraries and static libraries in
30813108
# `host_install_destdir`.

utils/build_swift/build_swift/defaults.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
__all__ = [
25-
# Command line configuarable
25+
# Command line configurable
2626
'BUILD_VARIANT',
2727
'CMAKE_GENERATOR',
2828
'COMPILER_VENDOR',
@@ -38,6 +38,7 @@
3838
'DARWIN_INSTALL_PREFIX',
3939
'LLVM_MAX_PARALLEL_LTO_LINK_JOBS',
4040
'SWIFT_MAX_PARALLEL_LTO_LINK_JOBS',
41+
'DSYMUTIL_JOBS'
4142

4243
# Constants
4344
]
@@ -62,6 +63,8 @@
6263
DARWIN_INSTALL_PREFIX = ('/Applications/Xcode.app/Contents/Developer/'
6364
'Toolchains/XcodeDefault.xctoolchain/usr')
6465

66+
DSYMUTIL_JOBS = 1
67+
6568

6669
def _system_memory():
6770
"""Returns the system memory as an int. None if the system memory cannot

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ def create_argument_parser():
486486
help='the maximum number of parallel link jobs to use when '
487487
'compiling swift tools.')
488488

489+
option('--dsymutil-jobs', store_int,
490+
default=defaults.DSYMUTIL_JOBS,
491+
metavar='COUNT',
492+
help='the maximum number of parallel dsymutil jobs to use when '
493+
'extracting symbols. Tweak with caution, since dsymutil'
494+
'is memory intensive.')
495+
489496
option('--disable-guaranteed-normal-arguments', store_true,
490497
help='Disable guaranteed normal arguments')
491498

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
'distcc': False,
141141
'sccache': False,
142142
'dry_run': False,
143+
'dsymutil_jobs': defaults.DSYMUTIL_JOBS,
143144
'enable_asan': False,
144145
'enable_experimental_differentiable_programming': True,
145146
'enable_experimental_concurrency': True,
@@ -662,6 +663,7 @@ class BuildScriptImplOption(_BaseOption):
662663
IntOption('--llvm-max-parallel-lto-link-jobs'),
663664
IntOption('--swift-tools-max-parallel-lto-link-jobs'),
664665
IntOption('-j', dest='build_jobs'),
666+
IntOption('--dsymutil-jobs', dest='dsymutil_jobs'),
665667

666668
AppendOption('--cross-compile-hosts'),
667669
AppendOption('--extra-cmake-options'),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: %empty-directory(%t)
2+
# RUN: mkdir -p %t
3+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --darwin-install-extract-symbols --dsymutil-jobs 5 --cmake %cmake 2>&1 | %FileCheck %s
4+
5+
# REQUIRES: standalone_build
6+
7+
# CHECK: --- Extracting symbols ---
8+
# CHECK: { "command": "dsymutil", "start": "
9+
# CHECK-NEXT: xargs -n 1 -P 5 dsymutil
10+
# CHECK-NEXT: { "command": "dsymutil", "end": "

0 commit comments

Comments
 (0)