Skip to content

Commit 622d855

Browse files
authored
Merge pull request swiftlang#550 from apple/add-xcode-build-time-report
Add '--report-time-path=abs.path' option to record xcode projects bui…
2 parents bec912d + ebf6eb0 commit 622d855

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

project_future.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ def set_swift_branch(branch):
4444
swift_branch = branch
4545
common.set_swift_branch(branch)
4646

47+
class TimeReporter(object):
48+
def __init__(self, file_path):
49+
self._file_path = file_path
50+
self._time_data = {}
51+
52+
def update(self, project, elapsed):
53+
self._time_data[project + '.compile_time'] = elapsed
54+
55+
def __del__(self):
56+
if self._file_path and self._time_data:
57+
with open(self._file_path, 'w+') as f:
58+
json.dump(self._time_data, f)
4759

4860
class ProjectTarget(object):
4961
"""An abstract project target."""
@@ -164,6 +176,21 @@ def get_test_command(self, incremental=False):
164176

165177
return command
166178

179+
def build(self, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr,
180+
incremental=False, time_reporter=None):
181+
"""Build the project target."""
182+
183+
start_time = None
184+
if time_reporter:
185+
start_time = time.time()
186+
returncode = common.check_execute(self.get_build_command(incremental=incremental),
187+
sandbox_profile=sandbox_profile,
188+
stdout=stdout, stderr=stdout)
189+
if returncode == 0 and time_reporter:
190+
elapsed = time.time() - start_time
191+
time_reporter.update(self._target, elapsed)
192+
193+
return returncode
167194

168195
def get_stdlib_platform_path(swiftc, destination):
169196
"""Return the corresponding stdlib name for a destination."""
@@ -277,7 +304,7 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
277304
added_swift_flags, added_xcodebuild_flags,
278305
build_config, should_strip_resource_phases=False,
279306
stdout=sys.stdout, stderr=sys.stderr,
280-
incremental=False):
307+
incremental=False, time_reporter = None):
281308
"""Call functions corresponding to actions."""
282309

283310
substitutions = action.copy()
@@ -377,7 +404,8 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
377404
if match.group(1) == 'Build':
378405
return xcode_target.build(sandbox_profile_xcodebuild,
379406
stdout=stdout, stderr=stderr,
380-
incremental=incremental)
407+
incremental=incremental,
408+
time_reporter=time_reporter)
381409
else:
382410
return xcode_target.test(sandbox_profile_xcodebuild,
383411
stdout=stdout, stderr=stderr,
@@ -551,6 +579,9 @@ def add_arguments(parser):
551579
metavar='PATH',
552580
type=os.path.abspath,
553581
default='project_cache')
582+
parser.add_argument("--report-time-path",
583+
help='export time for building each xcode build target to the specified json file',
584+
type=os.path.abspath)
554585

555586
def add_minimal_arguments(parser):
556587
"""Add common arguments to parser."""
@@ -918,6 +949,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
918949
skip_clean, build_config,
919950
strip_resource_phases,
920951
project_cache_path,
952+
time_reporter,
921953
action, project):
922954
self.swiftc = swiftc
923955
self.swift_version = swift_version
@@ -934,6 +966,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
934966
self.skip_clean = skip_clean
935967
self.build_config = build_config
936968
self.strip_resource_phases = strip_resource_phases
969+
self.time_reporter = time_reporter
937970
self.init()
938971

939972
def init(self):
@@ -991,6 +1024,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
9911024
self.added_xcodebuild_flags,
9921025
self.build_config,
9931026
incremental=self.skip_clean,
1027+
time_reporter=self.time_reporter,
9941028
stdout=stdout, stderr=stderr)
9951029
except common.ExecuteCommandFailure as error:
9961030
return self.failed(identifier, error)
@@ -1029,6 +1063,7 @@ def __init__(self,
10291063
strip_resource_phases,
10301064
only_latest_versions,
10311065
project_cache_path,
1066+
time_reporter,
10321067
action, version, project):
10331068
super(CompatActionBuilder, self).__init__(
10341069
swiftc, swift_version, swift_branch,
@@ -1039,6 +1074,7 @@ def __init__(self,
10391074
skip_clean, build_config,
10401075
strip_resource_phases,
10411076
project_cache_path,
1077+
time_reporter,
10421078
action, project
10431079
)
10441080
self.only_latest_versions = only_latest_versions
@@ -1065,6 +1101,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
10651101
self.build_config,
10661102
incremental=self.skip_clean,
10671103
should_strip_resource_phases=self.strip_resource_phases,
1104+
time_reporter=self.time_reporter,
10681105
stdout=stdout, stderr=stderr)
10691106
except common.ExecuteCommandFailure as error:
10701107
return self.failed(identifier, error)
@@ -1210,6 +1247,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
12101247
sandbox_profile_package,
12111248
added_swift_flags, build_config,
12121249
strip_resource_phases,
1250+
time_reporter,
12131251
project, action):
12141252
super(IncrementalActionBuilder,
12151253
self).__init__(swiftc, swift_version, swift_branch,
@@ -1219,6 +1257,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
12191257
skip_clean=True,
12201258
build_config=build_config,
12211259
strip_resource_phases=strip_resource_phases,
1260+
time_reporter=time_reporter,
12221261
project=project,
12231262
action=action)
12241263
self.proj_path = os.path.join(self.root_path, self.project['path'])
@@ -1324,6 +1363,7 @@ def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr
13241363
self.added_xcodebuild_flags,
13251364
self.build_config,
13261365
should_strip_resource_phases=False,
1366+
time_reporter=self.time_reporter,
13271367
stdout=stdout, stderr=stderr,
13281368
incremental=incremental)
13291369
except common.ExecuteCommandFailure as error:

runner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def main():
4444

4545
swift_flags = args.add_swift_flags
4646

47+
time_reporter = None
48+
if args.report_time_path:
49+
time_reporter = project_future.TimeReporter(args.report_time_path)
50+
4751
index = json.loads(open(args.projects).read())
4852
result = project_future.ProjectListBuilder(
4953
args.include_repos,
@@ -69,7 +73,8 @@ def main():
6973
args.build_config,
7074
args.strip_resource_phases,
7175
args.only_latest_versions,
72-
args.project_cache_path
76+
args.project_cache_path,
77+
time_reporter
7378
),
7479
),
7580
),

0 commit comments

Comments
 (0)