Skip to content

Commit 99fefc3

Browse files
committed
[Build System] Add support to log build times for each products
1 parent 97b1e3b commit 99fefc3

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
@@ -292,15 +292,6 @@ for component in ${components[@]} ; do
292292
)
293293
done
294294

295-
function log_event() {
296-
build_script_log_path=${BUILD_DIR}/.build_script_log
297-
event_type=$1
298-
event_command=$2
299-
evnet_duration=$3
300-
301-
build_event="{\"event\":\"${event_type}\", \"command\":\"${event_command}\", \"duration\":\"${evnet_duration}\"}"
302-
echo "${build_event}" >> ${build_script_log_path}
303-
}
304295

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

314305
SECONDS=0
315306
if [[ ! ${DRY_RUN} ]]; then
316-
log_event "start" "$(quoted_print "$@")" "${SECONDS}"
317307
{ set -x; } 2>/dev/null
318308
"$@"
319309
{ set +x; } 2>/dev/null
320-
log_event "finish" "$(quoted_print "$@")" "${SECONDS}"
321310
fi
322311
}
323312

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
@@ -31,9 +32,11 @@
3132
import ProductPipelineListBuilder
3233
from swift_build_support.swift_build_support.targets \
3334
import StdlibDeploymentTarget
35+
from swift_build_support.swift_build_support.utils import clear_log_time
3436
from swift_build_support.swift_build_support.utils \
3537
import exit_rejecting_arguments
3638
from swift_build_support.swift_build_support.utils import fatal_error
39+
from swift_build_support.swift_build_support.utils import log_time
3740

3841

3942
class BuildScriptInvocation(object):
@@ -50,6 +53,8 @@ def __init__(self, toolchain, args):
5053

5154
self.build_libparser_only = args.build_libparser_only
5255

56+
clear_log_time()
57+
5358
@property
5459
def install_all(self):
5560
return self.args.install_all or self.args.infer_dependencies
@@ -776,10 +781,13 @@ def _execute_merged_host_lipo_core_action(self):
776781
self._execute_action("merged-hosts-lipo-core")
777782

778783
def _execute_action(self, action_name):
784+
log_time('start', action_name)
785+
t_start = time.time()
779786
shell.call_without_sleeping(
780787
[BUILD_SCRIPT_IMPL_PATH] + self.impl_args +
781788
["--only-execute", action_name],
782789
env=self.impl_env, echo=self.args.verbose_build)
790+
log_time('end', action_name, time.time() - t_start)
783791

784792
def execute_product_build_steps(self, product_class, host_target):
785793
product_source = product_class.product_source_name()
@@ -796,14 +804,26 @@ def execute_product_build_steps(self, product_class, host_target):
796804
source_dir=self.workspace.source_dir(product_source),
797805
build_dir=build_dir)
798806
if product.should_clean(host_target):
799-
print("--- Cleaning %s ---" % product_name)
807+
log_message = "Cleaning %s" % product_name
808+
print("--- {} ---".format(log_message))
809+
t_start = time.time()
810+
log_time('start', log_message)
800811
product.clean(host_target)
812+
log_time('end', log_message, time.time() - t_start)
801813
if product.should_build(host_target):
802-
print("--- Building %s ---" % product_name)
814+
log_message = "Building %s" % product_name
815+
print("--- {} ---".format(log_message))
816+
t_start = time.time()
817+
log_time('start', log_message, '0')
803818
product.build(host_target)
819+
log_time('end', log_message, time.time() - t_start)
804820
if product.should_test(host_target):
805-
print("--- Running tests for %s ---" % product_name)
821+
log_message = "Running tests for %s" % product_name
822+
print("--- {} ---".format(log_message))
823+
t_start = time.time()
824+
log_time('start', log_message)
806825
product.test(host_target)
826+
log_time('end', log_message, time.time() - t_start)
807827
print("--- Finished tests for %s ---" % product_name)
808828
# Install the product if it should be installed specifically, or
809829
# if it should be built and `install_all` is set to True.
@@ -813,5 +833,9 @@ def execute_product_build_steps(self, product_class, host_target):
813833
if product.should_install(host_target) or \
814834
(self.install_all and product.should_build(host_target) and
815835
not product.is_ignore_install_all_product()):
816-
print("--- Installing %s ---" % product_name)
836+
log_message = "Installing %s" % product_name
837+
print("--- {} ---".format(log_message))
838+
t_start = time.time()
839+
log_time('start', log_message)
817840
product.install(host_target)
841+
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
@@ -10,9 +10,14 @@
1010
#
1111
# ===---------------------------------------------------------------------===#
1212

13+
import json
14+
import os
1315
import sys
1416

1517

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

0 commit comments

Comments
 (0)