Skip to content

Commit 982a57f

Browse files
authored
Merge pull request #5675 from graydon/rdar-29090287-failing-scale-test-tmpdir
[Compile perf] Use lit tmpdir in scale-test, rdar://29090287
2 parents d6f8f14 + 2a89323 commit 982a57f

File tree

3 files changed

+58
-43
lines changed

3 files changed

+58
-43
lines changed

test/lit.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,9 @@ config.substitutions.append(('%utils', config.swift_utils))
976976
config.substitutions.append(('%line-directive', config.line_directive))
977977
config.substitutions.append(('%gyb', config.gyb))
978978
config.substitutions.append(('%rth', config.rth))
979-
config.substitutions.append(('%scale-test', config.scale_test))
980-
979+
config.substitutions.append(('%scale-test',
980+
'{} --swiftc-binary={} --tmpdir=%t'.format(
981+
config.scale_test, config.swiftc)))
981982
config.substitutions.append(('%target-sil-opt', config.target_sil_opt))
982983
config.substitutions.append(('%target-sil-extract', config.target_sil_extract))
983984
config.substitutions.append(

utils/scale-test

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@
1212
# values.
1313
#
1414

15-
import gyb, os, os.path, subprocess
15+
import argparse
16+
import json
17+
import os
18+
import os.path
19+
import shutil
20+
import subprocess
21+
import sys
22+
import tempfile
23+
import gyb
24+
1625

1726
def find_which(p):
1827
for d in os.environ["PATH"].split(os.pathsep):
19-
full = os.path.join(d,p)
28+
full = os.path.join(d, p)
2029
if os.path.isfile(full) and os.access(full, os.X_OK):
2130
return full
2231
return p
2332

33+
2434
# Evidently the debug-symbol reader in dtrace is sufficiently slow and/or buggy
2535
# that attempting to inject probes into a binary w/ debuginfo is asking for a
2636
# failed run (possibly racing with probe insertion, or probing the stabs
2737
# entries, see rdar://problem/7037927 or rdar://problem/11490861 respectively),
2838
# so we sniff the presence of debug symbols here.
2939
def has_debuginfo(swiftc):
3040
swiftc = find_which(swiftc)
31-
for line in subprocess.check_output(["dwarfdump", "--file-stats", swiftc]).splitlines():
41+
for line in subprocess.check_output(
42+
["dwarfdump", "--file-stats", swiftc]).splitlines():
3243
if '%' not in line:
3344
continue
3445
fields = line.split()
@@ -38,20 +49,22 @@ def has_debuginfo(swiftc):
3849

3950

4051
def write_input_file(args, ast, d, n):
41-
ifile = os.path.join(d, "in%d.swift" % n)
42-
with open(ifile,'w+') as f:
52+
fname = "in%d.swift" % n
53+
pathname = os.path.join(d, fname)
54+
with open(pathname, 'w+') as f:
4355
f.write(gyb.execute_template(ast, '', N=n))
44-
return ifile
56+
return fname
4557

4658

4759
def run_once_with_primary(args, ast, rng, primary_idx):
48-
import sys, shutil, tempfile, json
4960
r = {}
5061
try:
51-
d = tempfile.mkdtemp()
62+
if args.tmpdir is not None and not os.path.exists(args.tmpdir):
63+
os.makedirs(args.tmpdir, 0700)
64+
d = tempfile.mkdtemp(dir=args.tmpdir)
5265
inputs = [write_input_file(args, ast, d, i) for i in rng]
5366
primary = inputs[primary_idx]
54-
ofile = os.path.join(d, "out.o")
67+
ofile = "out.o"
5568

5669
mode = "-c"
5770
if args.parse:
@@ -81,31 +94,32 @@ def run_once_with_primary(args, ast, rng, primary_idx):
8194
print "running: " + " ".join(command)
8295

8396
if args.dtrace:
84-
trace = os.path.join(d, "trace.txt")
85-
script = "pid$target:swiftc:*%s*:entry { @[probefunc] = count() }" % args.select
97+
trace = "trace.txt"
98+
script = ("pid$target:swiftc:*%s*:entry { @[probefunc] = count() }"
99+
% args.select)
86100
subprocess.check_call(
87101
["sudo", "dtrace", "-q",
88102
"-o", trace,
89103
"-b", "256",
90104
"-n", script,
91-
"-c", " ".join(command)])
105+
"-c", " ".join(command)], cwd=d)
92106
r = {fields[0]: int(fields[1]) for fields in
93-
[line.split() for line in open(trace)]
107+
[line.split() for line in open(os.path.join(d, trace))]
94108
if len(fields) == 2}
95109
else:
96110
if args.debug:
97111
command = ["lldb", "--"] + command
98-
stats = os.path.join(d, "stats.json")
112+
stats = "stats.json"
99113
argv = command + ["-Xllvm", "-stats",
100114
"-Xllvm", "-stats-json",
101115
"-Xllvm", "-info-output-file=" + stats]
102-
subprocess.check_call(argv)
103-
with open(stats) as f:
116+
subprocess.check_call(argv, cwd=d)
117+
with open(os.path.join(d, stats)) as f:
104118
r = json.load(f)
105119
finally:
106120
shutil.rmtree(d)
107121

108-
return {k:v for (k,v) in r.items() if args.select in k}
122+
return {k: v for (k, v) in r.items() if args.select in k}
109123

110124

111125
def run_once(args, ast, rng):
@@ -122,6 +136,7 @@ def run_once(args, ast, rng):
122136
else:
123137
return run_once_with_primary(args, ast, rng, -1)
124138

139+
125140
def run_many(args):
126141

127142
if args.dtrace and has_debuginfo(args.swiftc_binary):
@@ -145,25 +160,24 @@ def run_many(args):
145160

146161

147162
def linear_regression(x, y):
148-
# By the book: https://en.wikipedia.org/wiki/Simple_linear_regression
149-
n = len(x)
150-
assert n == len(y)
151-
if n == 0:
152-
return 0, 0
153-
prod_sum = 0
154-
sum_x = sum(x)
155-
sum_y = sum(y)
156-
sum_prod = sum(a * b for a, b in zip(x, y))
157-
sum_x_sq = sum(a ** 2 for a in x)
158-
mean_x = sum_x/n
159-
mean_y = sum_y/n
160-
mean_prod = sum_prod/n
161-
mean_x_sq = sum_x_sq/n
162-
covar_xy = mean_prod - mean_x * mean_y
163-
var_x = mean_x_sq - mean_x**2
164-
slope = covar_xy / var_x
165-
inter = mean_y - slope * mean_x
166-
return slope, inter
163+
# By the book: https://en.wikipedia.org/wiki/Simple_linear_regression
164+
n = len(x)
165+
assert n == len(y)
166+
if n == 0:
167+
return 0, 0
168+
sum_x = sum(x)
169+
sum_y = sum(y)
170+
sum_prod = sum(a * b for a, b in zip(x, y))
171+
sum_x_sq = sum(a ** 2 for a in x)
172+
mean_x = sum_x/n
173+
mean_y = sum_y/n
174+
mean_prod = sum_prod/n
175+
mean_x_sq = sum_x_sq/n
176+
covar_xy = mean_prod - mean_x * mean_y
177+
var_x = mean_x_sq - mean_x**2
178+
slope = covar_xy / var_x
179+
inter = mean_y - slope * mean_x
180+
return slope, inter
167181

168182

169183
def report(args, rng, runs):
@@ -196,7 +210,6 @@ def report(args, rng, runs):
196210

197211

198212
def main():
199-
import argparse, sys
200213
parser = argparse.ArgumentParser()
201214
parser.add_argument(
202215
'file', type=argparse.FileType(),
@@ -241,9 +254,12 @@ def main():
241254
parser.add_argument(
242255
'--swiftc-binary',
243256
default="swiftc", help='swift binary to execute')
257+
parser.add_argument(
258+
'--tmpdir', type=str,
259+
default=None, help='directory to create tempfiles in')
244260
parser.add_argument(
245261
'--select',
246-
default="", help='substring of counters/symbols to restrict attention to')
262+
default="", help='substring of counters/symbols to limit attention to')
247263
parser.add_argument(
248264
'--debug', action='store_true',
249265
default=False, help='invoke lldb on each scale test')
@@ -273,5 +289,6 @@ def main():
273289
exit(1)
274290
exit(0)
275291

292+
276293
if __name__ == '__main__':
277294
main()

validation-test/compiler_scale/scale_neighbouring_getset.gyb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %scale-test --sum-multi --parse --begin 5 --end 16 --step 5 --select typeCheckAbstractFunctionBody %s
22
// REQUIRES: OS=macosx, tools-release
33

4-
// FIXME: this test has been failing in CI
5-
// REQUIRES: rdar29090287
6-
74
struct Struct${N} {
85
% if int(N) > 1:
96
var Field : Struct${int(N)-1}?

0 commit comments

Comments
 (0)