Skip to content

Commit e6f1cda

Browse files
authored
Merge pull request swiftlang#51 from graydon/stats-and-incremental-cleanups
Stats and incremental cleanups
2 parents eb28ba2 + ac65235 commit e6f1cda

File tree

3 files changed

+122
-120
lines changed

3 files changed

+122
-120
lines changed

Diff for: build_incremental.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def main():
4646
args.swift_branch,
4747
args.sandbox_profile_xcodebuild,
4848
args.sandbox_profile_package,
49-
args.add_swift_flags,
50-
args.check_stats,
51-
args.show_stats
49+
args.add_swift_flags
5250
),
5351
),
5452
index

Diff for: project.py

+19-111
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def clean_swift_package(path, swiftc, sandbox_profile,
203203

204204
def build_swift_package(path, swiftc, configuration, sandbox_profile,
205205
stdout=sys.stdout, stderr=sys.stderr,
206-
incremental=False,
207-
stats_path=None):
206+
added_swift_flags=None,
207+
incremental=False):
208208
"""Build a Swift package manager project."""
209209
swift = swiftc[:-1]
210210
if not incremental:
@@ -214,12 +214,12 @@ def build_swift_package(path, swiftc, configuration, sandbox_profile,
214214
env['SWIFT_EXEC'] = swiftc
215215
command = [swift, 'build', '-C', path, '--verbose',
216216
'--configuration', configuration]
217-
if stats_path is not None:
218-
command += ['-Xswiftc', '-stats-output-dir',
219-
'-Xswiftc', stats_path]
220217
if (swift_branch not in ['swift-3.0-branch',
221218
'swift-3.1-branch']):
222219
command.insert(2, '--disable-sandbox')
220+
if added_swift_flags is not None:
221+
for flag in added_swift_flags.split():
222+
command += ["-Xswiftc", flag]
223223
return common.check_execute(command, timeout=3600,
224224
sandbox_profile=sandbox_profile,
225225
stdout=stdout, stderr=stderr,
@@ -228,18 +228,18 @@ def build_swift_package(path, swiftc, configuration, sandbox_profile,
228228

229229
def test_swift_package(path, swiftc, sandbox_profile,
230230
stdout=sys.stdout, stderr=sys.stderr,
231-
incremental=False,
232-
stats_path=None):
231+
added_swift_flags=None,
232+
incremental=False):
233233
"""Test a Swift package manager project."""
234234
swift = swiftc[:-1]
235235
if not incremental:
236236
clean_swift_package(path, swiftc, sandbox_profile)
237237
env = os.environ
238238
env['SWIFT_EXEC'] = swiftc
239239
command = [swift, 'test', '-C', path, '--verbose']
240-
if stats_path is not None:
241-
command += ['-Xswiftc', '-stats-output-dir',
242-
'-Xswiftc', stats_path]
240+
if added_swift_flags is not None:
241+
for flag in added_swift_flags.split():
242+
command += ["-Xswiftc", flag]
243243
return common.check_execute(command, timeout=3600,
244244
sandbox_profile=sandbox_profile,
245245
stdout=stdout, stderr=stderr,
@@ -274,31 +274,24 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
274274
sandbox_profile_xcodebuild, sandbox_profile_package,
275275
added_swift_flags, should_strip_resource_phases=False,
276276
stdout=sys.stdout, stderr=sys.stderr,
277-
incremental=False,
278-
stats_path=None):
277+
incremental=False):
279278
"""Call functions corresponding to actions."""
280279

281-
if stats_path is not None:
282-
if os.path.exists(stats_path):
283-
shutil.rmtree(stats_path)
284-
common.check_execute(['mkdir', '-p', stats_path],
285-
stdout=stdout, stderr=stderr)
286-
287280
if action['action'] == 'BuildSwiftPackage':
288281
return build_swift_package(os.path.join(root_path, repo['path']),
289282
swiftc,
290283
action['configuration'],
291284
sandbox_profile_package,
292285
stdout=stdout, stderr=stderr,
293-
incremental=incremental,
294-
stats_path=stats_path)
286+
added_swift_flags=added_swift_flags,
287+
incremental=incremental)
295288
elif action['action'] == 'TestSwiftPackage':
296289
return test_swift_package(os.path.join(root_path, repo['path']),
297290
swiftc,
298291
sandbox_profile_package,
299292
stdout=stdout, stderr=stderr,
300-
incremental=incremental,
301-
stats_path=stats_path)
293+
added_swift_flags=added_swift_flags,
294+
incremental=incremental)
302295
elif re.match(r'^(Build|Test)Xcode(Workspace|Project)(Scheme|Target)$',
303296
action['action']):
304297
match = re.match(
@@ -315,8 +308,6 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
315308
if swift_version:
316309
other_swift_flags += ['-swift-version', swift_version]
317310
build_settings['SWIFT_VERSION'] = swift_version
318-
if stats_path is not None:
319-
other_swift_flags += ['-stats-output-dir', stats_path]
320311
if added_swift_flags:
321312
other_swift_flags.append(added_swift_flags)
322313
if other_swift_flags:
@@ -438,12 +429,6 @@ def add_arguments(parser):
438429
parser.add_argument("--test-incremental",
439430
help='test incremental-mode over multiple commits',
440431
action='store_true')
441-
parser.add_argument("--check-stats",
442-
help='collect stats and compare to expectations',
443-
action='store_true')
444-
parser.add_argument("--show-stats",
445-
metavar='PATTERN',
446-
help='report stats matching PATTERN')
447432
parser.add_argument("--add-swift-flags",
448433
metavar="FLAGS",
449434
help='add flags to each Swift invocation',
@@ -1008,59 +993,13 @@ def have_same_trees(full, incr, d):
1008993
ok = have_same_trees(full, incr, sub) and ok
1009994
return ok
1010995

1011-
class StatsSummary:
1012-
1013-
def __init__(self):
1014-
self.commits = {}
1015-
1016-
def add_stats_from_json(self, seq, sha, j):
1017-
key = (seq, sha)
1018-
if key not in self.commits:
1019-
self.commits[key] = {}
1020-
for (k, v) in j.items():
1021-
if k.startswith("time."):
1022-
continue
1023-
e = self.commits[key].get(k, 0)
1024-
self.commits[key][k] = int(v) + e
1025-
1026-
def check_against_expected(self, seq, sha, expected):
1027-
key = (seq, sha)
1028-
if key in self.commits:
1029-
for (k, ev) in expected.items():
1030-
if k in self.commits[key]:
1031-
gv = self.commits[key][k]
1032-
if ev < gv:
1033-
message = ("Expected %s of %s, got %s" %
1034-
(k, str(ev), str(gv)) )
1035-
raise EarlyExit(ActionResult(Result.FAIL, message))
1036-
1037-
def add_stats_from_file(self, seq, sha, f):
1038-
with open(f) as fp:
1039-
self.add_stats_from_json(seq, sha, json.load(fp))
1040-
1041-
def add_stats_from_dir(self, seq, sha, path):
1042-
for root, dirs, files in os.walk(path):
1043-
for f in files:
1044-
if not f.endswith(".json"):
1045-
continue
1046-
self.add_stats_from_file(seq, sha, os.path.join(root, f))
1047-
1048-
def dump(self, pattern):
1049-
return json.dumps([ {"commit": sha,
1050-
"stats": { k: v for (k, v) in self.commits[(seq, sha)].items()
1051-
if re.match(pattern, k) } }
1052-
for (seq, sha) in sorted(self.commits.keys()) ],
1053-
sort_keys=False,
1054-
indent=2)
1055996

1056997
class IncrementalActionBuilder(ActionBuilder):
1057998

1058999
def __init__(self, swiftc, swift_version, swift_branch,
10591000
sandbox_profile_xcodebuild,
10601001
sandbox_profile_package,
10611002
added_swift_flags,
1062-
check_stats,
1063-
show_stats,
10641003
project, action):
10651004
super(IncrementalActionBuilder,
10661005
self).__init__(swiftc, swift_version, swift_branch,
@@ -1070,15 +1009,8 @@ def __init__(self, swiftc, swift_version, swift_branch,
10701009
skip_clean=True,
10711010
project=project,
10721011
action=action)
1073-
self.check_stats = check_stats
1074-
self.show_stats = show_stats
1075-
self.stats_path = None
1076-
self.stats_summ = None
10771012
self.proj_path = os.path.join(self.root_path, self.project['path'])
10781013
self.incr_path = self.proj_path + "-incr"
1079-
if self.check_stats or (self.show_stats is not None):
1080-
self.stats_path = os.path.join(self.proj_path, "swift-stats")
1081-
self.stats_summ = StatsSummary()
10821014

10831015
def curr_build_state_path(self):
10841016
if self.action['action'] == 'BuildSwiftPackage':
@@ -1111,10 +1043,6 @@ def saved_build_state_path(self, seq, flav, sha):
11111043
return os.path.join(self.incr_path, ("build-state-%03d-%s-%.7s" %
11121044
(seq, flav, sha)))
11131045

1114-
def saved_build_stats_path(self, seq, flav, sha):
1115-
return os.path.join(self.incr_path, ("build-stats-%03d-%s-%.7s" %
1116-
(seq, flav, sha)))
1117-
11181046
def restore_saved_build_state(self, seq, flav, sha, stdout=sys.stdout):
11191047
src = self.saved_build_state_path(seq, flav, sha)
11201048
dst = self.curr_build_state_path()
@@ -1125,7 +1053,7 @@ def restore_saved_build_state(self, seq, flav, sha, stdout=sys.stdout):
11251053
shutil.rmtree(dst)
11261054
shutil.copytree(src, dst, symlinks=True)
11271055

1128-
def save_build_state(self, seq, flav, sha, stats, stdout=sys.stdout):
1056+
def save_build_state(self, seq, flav, sha, stdout=sys.stdout):
11291057
src = self.curr_build_state_path()
11301058
dst = self.saved_build_state_path(seq, flav, sha)
11311059
proj = self.project['path']
@@ -1134,17 +1062,6 @@ def save_build_state(self, seq, flav, sha, stats, stdout=sys.stdout):
11341062
if os.path.exists(dst):
11351063
shutil.rmtree(dst)
11361064
shutil.copytree(src, dst, symlinks=True)
1137-
if self.stats_summ is not None:
1138-
self.stats_summ.add_stats_from_dir(seq, sha, self.stats_path)
1139-
src = self.stats_path
1140-
dst = self.saved_build_stats_path(seq, flav, sha)
1141-
common.debug_print("Saving %s stats #%d of %s to %s" %
1142-
(flav, seq, proj, dst), stderr=stdout)
1143-
if os.path.exists(dst):
1144-
shutil.rmtree(dst)
1145-
shutil.copytree(src, dst, symlinks=True)
1146-
if stats is not None and self.check_stats:
1147-
self.stats_summ.check_against_expected(seq, sha, stats)
11481065

11491066
def check_full_vs_incr(self, seq, sha, stdout=sys.stdout):
11501067
full = self.saved_build_state_path(seq, 'full', sha)
@@ -1182,9 +1099,6 @@ def build(self, stdout=sys.stdout):
11821099
stdout=stdout)
11831100
except EarlyExit as error:
11841101
action_result = error.value
1185-
if self.show_stats is not None:
1186-
common.debug_print("Stats summary:", stderr=stdout)
1187-
common.debug_print(self.stats_summ.dump(self.show_stats), stderr=stdout)
11881102
return action_result
11891103

11901104
def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr):
@@ -1197,8 +1111,7 @@ def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr
11971111
self.added_swift_flags,
11981112
should_strip_resource_phases=False,
11991113
stdout=stdout, stderr=stderr,
1200-
incremental=incremental,
1201-
stats_path=self.stats_path)
1114+
incremental=incremental)
12021115
except common.ExecuteCommandFailure as error:
12031116
return self.failed(identifier, error)
12041117
else:
@@ -1222,12 +1135,7 @@ def build_incremental(self, identifier, commits, stdout=sys.stdout):
12221135
prev = None
12231136
seq = 0
12241137
action_result = ActionResult(Result.PASS, "")
1225-
for commit in commits:
1226-
sha = commit
1227-
stats = None
1228-
if type(commit) is dict:
1229-
sha = commit['commit']
1230-
stats = commit.get('stats', None)
1138+
for sha in commits:
12311139
proj = self.project['path']
12321140
ident = "%s-%03d-%.7s" % (identifier, seq, sha)
12331141
if prev is None:
@@ -1244,7 +1152,7 @@ def build_incremental(self, identifier, commits, stdout=sys.stdout):
12441152
common.git_submodule_update(self.proj_path, stdout=stdout, stderr=stdout)
12451153
action_result = self.dispatch_or_raise(ident, incremental=True,
12461154
stdout=stdout, stderr=stdout)
1247-
self.save_build_state(seq, 'incr', sha, stats, stdout=stdout)
1155+
self.save_build_state(seq, 'incr', sha, stdout=stdout)
12481156
prev = sha
12491157
seq += 1
12501158
return action_result

0 commit comments

Comments
 (0)