Skip to content

Commit 2a89323

Browse files
committed
[Compile perf] flake8 fixes for scale-test.
1 parent 3d8f8e0 commit 2a89323

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

utils/scale-test

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

15-
import gyb, os, os.path, shutil, 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()
@@ -40,16 +51,15 @@ def has_debuginfo(swiftc):
4051
def write_input_file(args, ast, d, n):
4152
fname = "in%d.swift" % n
4253
pathname = os.path.join(d, fname)
43-
with open(pathname,'w+') as f:
54+
with open(pathname, 'w+') as f:
4455
f.write(gyb.execute_template(ast, '', N=n))
4556
return fname
4657

4758

4859
def run_once_with_primary(args, ast, rng, primary_idx):
49-
import sys, tempfile, json
5060
r = {}
5161
try:
52-
if args.tmpdir != None and not os.path.exists(args.tmpdir):
62+
if args.tmpdir is not None and not os.path.exists(args.tmpdir):
5363
os.makedirs(args.tmpdir, 0700)
5464
d = tempfile.mkdtemp(dir=args.tmpdir)
5565
inputs = [write_input_file(args, ast, d, i) for i in rng]
@@ -85,7 +95,8 @@ def run_once_with_primary(args, ast, rng, primary_idx):
8595

8696
if args.dtrace:
8797
trace = "trace.txt"
88-
script = "pid$target:swiftc:*%s*:entry { @[probefunc] = count() }" % args.select
98+
script = ("pid$target:swiftc:*%s*:entry { @[probefunc] = count() }"
99+
% args.select)
89100
subprocess.check_call(
90101
["sudo", "dtrace", "-q",
91102
"-o", trace,
@@ -108,7 +119,7 @@ def run_once_with_primary(args, ast, rng, primary_idx):
108119
finally:
109120
shutil.rmtree(d)
110121

111-
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}
112123

113124

114125
def run_once(args, ast, rng):
@@ -125,6 +136,7 @@ def run_once(args, ast, rng):
125136
else:
126137
return run_once_with_primary(args, ast, rng, -1)
127138

139+
128140
def run_many(args):
129141

130142
if args.dtrace and has_debuginfo(args.swiftc_binary):
@@ -148,25 +160,24 @@ def run_many(args):
148160

149161

150162
def linear_regression(x, y):
151-
# By the book: https://en.wikipedia.org/wiki/Simple_linear_regression
152-
n = len(x)
153-
assert n == len(y)
154-
if n == 0:
155-
return 0, 0
156-
prod_sum = 0
157-
sum_x = sum(x)
158-
sum_y = sum(y)
159-
sum_prod = sum(a * b for a, b in zip(x, y))
160-
sum_x_sq = sum(a ** 2 for a in x)
161-
mean_x = sum_x/n
162-
mean_y = sum_y/n
163-
mean_prod = sum_prod/n
164-
mean_x_sq = sum_x_sq/n
165-
covar_xy = mean_prod - mean_x * mean_y
166-
var_x = mean_x_sq - mean_x**2
167-
slope = covar_xy / var_x
168-
inter = mean_y - slope * mean_x
169-
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
170181

171182

172183
def report(args, rng, runs):
@@ -199,7 +210,6 @@ def report(args, rng, runs):
199210

200211

201212
def main():
202-
import argparse, sys
203213
parser = argparse.ArgumentParser()
204214
parser.add_argument(
205215
'file', type=argparse.FileType(),
@@ -249,7 +259,7 @@ def main():
249259
default=None, help='directory to create tempfiles in')
250260
parser.add_argument(
251261
'--select',
252-
default="", help='substring of counters/symbols to restrict attention to')
262+
default="", help='substring of counters/symbols to limit attention to')
253263
parser.add_argument(
254264
'--debug', action='store_true',
255265
default=False, help='invoke lldb on each scale test')
@@ -279,5 +289,6 @@ def main():
279289
exit(1)
280290
exit(0)
281291

292+
282293
if __name__ == '__main__':
283294
main()

0 commit comments

Comments
 (0)