Skip to content

Commit 8fc2598

Browse files
authored
[build-script] Allow to tune dsymutil parallelism (#34795)
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 -- these are printed in JSON format in the log to allow for easier scraping ``` { "command": "dsymutil", "start": "2020-11-18T18:10:47" } { "command": "dsymutil", "end": "2020-11-18T18:14:45" } ``` Addresses rdar://71018443
1 parent 7180e8d commit 8fc2598

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

utils/build-script

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

506507
# Compute any product specific cmake arguments.

utils/build-script-impl

Lines changed: 28 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
@@ -3047,6 +3067,9 @@ for host in "${ALL_HOSTS[@]}"; do
30473067
# Instead, just echo we do "darwin_intall_extract_symbols".
30483068
if [[ "${DRY_RUN}" ]]; then
30493069
call darwin_install_extract_symbols
3070+
printJSONStartTimestamp dsymutil
3071+
echo xargs -n 1 -P ${DSYMUTIL_JOBS} dsymutil
3072+
printJSONEndTimestamp dsymutil
30503073
else
30513074
set -x
30523075

@@ -3069,13 +3092,16 @@ for host in "${ALL_HOSTS[@]}"; do
30693092
#
30703093
# Exclude shell scripts and static archives.
30713094
# Exclude swift-api-digester dSYM to reduce debug toolchain size.
3072-
# Run sequentially -- dsymutil is multithreaded and can be memory intensive
3095+
# Tweak carefully the amount of parallelism -- dsymutil can be memory intensive and
3096+
# as such too many instance can exhaust the memory and slow down/panic the machine
3097+
printJSONStartTimestamp dsymutil
30733098
(cd "${host_symroot}" &&
30743099
find ./"${CURRENT_PREFIX}" -perm -0111 -type f -print | \
30753100
grep -v '.py$' | \
30763101
grep -v '.a$' | \
30773102
grep -v 'swift-api-digester' | \
3078-
xargs -P 1 ${dsymutil_path})
3103+
xargs -n 1 -P ${DSYMUTIL_JOBS} ${dsymutil_path})
3104+
printJSONEndTimestamp dsymutil
30793105

30803106
# Strip executables, shared libraries and static libraries in
30813107
# `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,OS=macosx
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)