Skip to content

Commit f612607

Browse files
shahmishalahoppen
authored andcommitted
[Build System] Add support to log build times for each products
1 parent bf4dfe6 commit f612607

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
@@ -283,15 +283,6 @@ for component in ${components[@]} ; do
283283
)
284284
done
285285

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

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

305296
SECONDS=0
306297
if [[ ! ${DRY_RUN} ]]; then
307-
log_event "start" "$(quoted_print "$@")" "${SECONDS}"
308298
{ set -x; } 2>/dev/null
309299
"$@"
310300
{ set +x; } 2>/dev/null
311-
log_event "finish" "$(quoted_print "$@")" "${SECONDS}"
312301
fi
313302
}
314303

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
@@ -764,10 +769,13 @@ def _execute_merged_host_lipo_core_action(self):
764769
self._execute_action("merged-hosts-lipo-core")
765770

766771
def _execute_action(self, action_name):
772+
log_time('start', action_name)
773+
t_start = time.time()
767774
shell.call_without_sleeping(
768775
[BUILD_SCRIPT_IMPL_PATH] + self.impl_args +
769776
["--only-execute", action_name],
770777
env=self.impl_env, echo=self.args.verbose_build)
778+
log_time('end', action_name, time.time() - t_start)
771779

772780
def execute_product_build_steps(self, product_class, host_target):
773781
product_source = product_class.product_source_name()
@@ -784,14 +792,26 @@ def execute_product_build_steps(self, product_class, host_target):
784792
source_dir=self.workspace.source_dir(product_source),
785793
build_dir=build_dir)
786794
if product.should_clean(host_target):
787-
print("--- Cleaning %s ---" % product_name)
795+
log_message = "Cleaning %s" % product_name
796+
print("--- {} ---".format(log_message))
797+
t_start = time.time()
798+
log_time('start', log_message)
788799
product.clean(host_target)
800+
log_time('end', log_message, time.time() - t_start)
789801
if product.should_build(host_target):
790-
print("--- Building %s ---" % product_name)
802+
log_message = "Building %s" % product_name
803+
print("--- {} ---".format(log_message))
804+
t_start = time.time()
805+
log_time('start', log_message, '0')
791806
product.build(host_target)
807+
log_time('end', log_message, time.time() - t_start)
792808
if product.should_test(host_target):
793-
print("--- Running tests for %s ---" % product_name)
809+
log_message = "Running tests for %s" % product_name
810+
print("--- {} ---".format(log_message))
811+
t_start = time.time()
812+
log_time('start', log_message)
794813
product.test(host_target)
814+
log_time('end', log_message, time.time() - t_start)
795815
print("--- Finished tests for %s ---" % product_name)
796816
# Install the product if it should be installed specifically, or
797817
# if it should be built and `install_all` is set to True.
@@ -801,5 +821,9 @@ def execute_product_build_steps(self, product_class, host_target):
801821
if product.should_install(host_target) or \
802822
(self.install_all and product.should_build(host_target) and
803823
not product.is_ignore_install_all_product()):
804-
print("--- Installing %s ---" % product_name)
824+
log_message = "Installing %s" % product_name
825+
print("--- {} ---".format(log_message))
826+
t_start = time.time()
827+
log_time('start', log_message)
805828
product.install(host_target)
829+
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)