Skip to content

Commit 13da9ba

Browse files
authored
Merge pull request swiftlang#37050 from apple/cherry-pick-build_script_log
Add build_script_log file to help us understand the build times for each command
2 parents 15ccd18 + 39b048a commit 13da9ba

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

utils/build-script

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,12 @@ def main_normal():
13791379
# Create build directory.
13801380
shell.makedirs(invocation.workspace.build_root)
13811381

1382+
# Create .build_script_log
1383+
if not args.dry_run:
1384+
build_script_log = os.path.join(invocation.workspace.build_root,
1385+
".build_script_log")
1386+
open(build_script_log, 'w').close()
1387+
13821388
# Build ninja if required, which will update the toolchain.
13831389
if args.build_ninja:
13841390
invocation.build_ninja()

utils/build-script-impl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ for component in ${components[@]} ; do
260260
)
261261
done
262262

263+
function log_event() {
264+
build_script_log_path=${BUILD_DIR}/.build_script_log
265+
event_type=$1
266+
event_command=$2
267+
evnet_duration=$3
268+
269+
build_event="{\"event\":\"${event_type}\", \"command\":\"${event_command}\", \"duration\":\"${evnet_duration}\"}"
270+
echo "${build_event}" >> ${build_script_log_path}
271+
}
272+
263273
# Centralized access point for traced command invocation.
264274
# Every operation that might mutates file system should be called via
265275
# these functions.
@@ -268,10 +278,14 @@ function call() {
268278
if [[ ${DRY_RUN} ]] || [[ "${VERBOSE_BUILD}" ]]; then
269279
echo "${PS4}"$(quoted_print "$@")
270280
fi
281+
282+
SECONDS=0
271283
if [[ ! ${DRY_RUN} ]]; then
284+
log_event "start" "$(quoted_print "$@")" "${SECONDS}"
272285
{ set -x; } 2>/dev/null
273286
"$@"
274287
{ set +x; } 2>/dev/null
288+
log_event "finish" "$(quoted_print "$@")" "${SECONDS}"
275289
fi
276290
}
277291

0 commit comments

Comments
 (0)