Skip to content

Commit 54c24dc

Browse files
committed
[Build System] Add support to log build times for each products
1 parent c8ab423 commit 54c24dc

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

utils/build-script-impl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,6 @@ for component in ${components[@]} ; do
285285
)
286286
done
287287

288-
function log_event() {
289-
build_script_log_path=${BUILD_DIR}/.build_script_log
290-
event_type=$1
291-
event_command=$2
292-
evnet_duration=$3
293-
294-
build_event="{\"event\":\"${event_type}\", \"command\":\"${event_command}\", \"duration\":\"${evnet_duration}\"}"
295-
echo "${build_event}" >> ${build_script_log_path}
296-
}
297288

298289
# Centralized access point for traced command invocation.
299290
# Every operation that might mutates file system should be called via
@@ -306,11 +297,9 @@ function call() {
306297

307298
SECONDS=0
308299
if [[ ! ${DRY_RUN} ]]; then
309-
log_event "start" "$(quoted_print "$@")" "${SECONDS}"
310300
{ set -x; } 2>/dev/null
311301
"$@"
312302
{ set +x; } 2>/dev/null
313-
log_event "finish" "$(quoted_print "$@")" "${SECONDS}"
314303
fi
315304
}
316305

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import pipes
1515
import platform
16+
import time
1617

1718
from build_swift.build_swift import argparse
1819
from build_swift.build_swift.constants import BUILD_SCRIPT_IMPL_PATH
@@ -33,9 +34,11 @@
3334
import ProductPipelineListBuilder
3435
from swift_build_support.swift_build_support.targets \
3536
import StdlibDeploymentTarget
37+
from swift_build_support.swift_build_support.utils import clear_log_time
3638
from swift_build_support.swift_build_support.utils \
3739
import exit_rejecting_arguments
3840
from swift_build_support.swift_build_support.utils import fatal_error
41+
from swift_build_support.swift_build_support.utils import log_time
3942

4043

4144
class BuildScriptInvocation(object):
@@ -52,6 +55,8 @@ def __init__(self, toolchain, args):
5255

5356
self.build_libparser_only = args.build_libparser_only
5457

58+
clear_log_time()
59+
5560
@property
5661
def install_all(self):
5762
return self.args.install_all or self.args.infer_dependencies
@@ -766,10 +771,13 @@ def _execute_merged_host_lipo_core_action(self):
766771
self._execute_action("merged-hosts-lipo-core")
767772

768773
def _execute_action(self, action_name):
774+
log_time('start', action_name)
775+
t_start = time.time()
769776
shell.call_without_sleeping(
770777
[BUILD_SCRIPT_IMPL_PATH] + self.impl_args +
771778
["--only-execute", action_name],
772779
env=self.impl_env, echo=self.args.verbose_build)
780+
log_time('end', action_name, time.time() - t_start)
773781

774782
def execute_product_build_steps(self, product_class, host_target):
775783
product_source = product_class.product_source_name()
@@ -786,14 +794,26 @@ def execute_product_build_steps(self, product_class, host_target):
786794
source_dir=self.workspace.source_dir(product_source),
787795
build_dir=build_dir)
788796
if product.should_clean(host_target):
789-
print("--- Cleaning %s ---" % product_name)
797+
log_message = "Cleaning %s" % product_name
798+
print("--- {} ---".format(log_message))
799+
t_start = time.time()
800+
log_time('start', log_message)
790801
product.clean(host_target)
802+
log_time('end', log_message, time.time() - t_start)
791803
if product.should_build(host_target):
792-
print("--- Building %s ---" % product_name)
804+
log_message = "Building %s" % product_name
805+
print("--- {} ---".format(log_message))
806+
t_start = time.time()
807+
log_time('start', log_message, '0')
793808
product.build(host_target)
809+
log_time('end', log_message, time.time() - t_start)
794810
if product.should_test(host_target):
795-
print("--- Running tests for %s ---" % product_name)
811+
log_message = "Running tests for %s" % product_name
812+
print("--- {} ---".format(log_message))
813+
t_start = time.time()
814+
log_time('start', log_message)
796815
product.test(host_target)
816+
log_time('end', log_message, time.time() - t_start)
797817
print("--- Finished tests for %s ---" % product_name)
798818
# Install the product if it should be installed specifically, or
799819
# if it should be built and `install_all` is set to True.
@@ -803,5 +823,9 @@ def execute_product_build_steps(self, product_class, host_target):
803823
if product.should_install(host_target) or \
804824
(self.install_all and product.should_build(host_target) and
805825
not product.is_ignore_install_all_product()):
806-
print("--- Installing %s ---" % product_name)
826+
log_message = "Installing %s" % product_name
827+
print("--- {} ---".format(log_message))
828+
t_start = time.time()
829+
log_time('start', log_message)
807830
product.install(host_target)
831+
log_time('end', log_message, time.time() - t_start)

utils/swift_build_support/swift_build_support/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212

1313
from __future__ import absolute_import, print_function, unicode_literals
1414

15+
import json
16+
import os
1517
import sys
1618

1719

20+
from build_swift.build_swift.constants import SWIFT_BUILD_ROOT
21+
22+
1823
def fatal_error(message, stream=sys.stderr):
1924
"""Writes a message to the given stream and exits. By default this
2025
function outputs to stderr.
@@ -30,3 +35,25 @@ def exit_rejecting_arguments(message, parser=None):
3035
if parser:
3136
parser.print_usage(sys.stderr)
3237
sys.exit(2) # 2 is the same as `argparse` error exit code.
38+
39+
40+
def log_time_path():
41+
return os.path.join(SWIFT_BUILD_ROOT, '.build_script_log')
42+
43+
44+
def clear_log_time():
45+
f = open(log_time_path(), "w")
46+
f.close()
47+
48+
49+
def log_time(event, command, duration=0):
50+
f = open(log_time_path(), "a")
51+
52+
log_event = {
53+
"event": event,
54+
"command": command,
55+
"duration": "%.2f" % float(duration),
56+
}
57+
58+
f.write("{}\n".format(json.dumps(log_event)))
59+
f.close()

0 commit comments

Comments
 (0)