Skip to content

Commit dbd1ec6

Browse files
authored
Merge pull request #1400 from swiftwasm/master
[pull] swiftwasm from master
2 parents 0211512 + e1094f7 commit dbd1ec6

31 files changed

+15020
-2353
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,25 @@ class BenchmarkDriver(object):
7373
def test_harness(self):
7474
"""Full path to test harness binary."""
7575
suffix = self.args.optimization if hasattr(self.args, "optimization") else "O"
76-
return os.path.join(self.args.tests, "Benchmark_" + suffix)
76+
if hasattr(self.args, "architecture") and self.args.architecture:
77+
suffix += "-" + self.args.architecture + "*"
78+
pattern = os.path.join(self.args.tests, "Benchmark_" + suffix)
79+
executables = []
80+
if hasattr(self._subprocess, "test_mode") and self._subprocess.test_mode:
81+
executables = [pattern]
82+
else:
83+
executables = glob.glob(pattern)
84+
if len(executables) == 0:
85+
raise ValueError(
86+
"No benchmark executable for file name pattern " +
87+
pattern + " found")
88+
if len(executables) > 1:
89+
raise ValueError(
90+
"Multiple benchmark executables for file name pattern " +
91+
pattern + " found\n" +
92+
str(executables) +
93+
"\nSpecify the architecture to select the right benchmark executable")
94+
return executables[0]
7795

7896
def _git(self, cmd):
7997
"""Execute the Git command in the `swift-repo`."""

benchmark/scripts/run_smoke_bench

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ VERBOSE = False
4848
class DriverArgs(object):
4949
"""Arguments for BenchmarkDriver."""
5050

51-
def __init__(self, tests, optimization="O"):
51+
def __init__(self, tests, optimization="O", architecture=None):
5252
"""Initialize with path to the build-dir and optimization level."""
5353
self.benchmarks = None
5454
self.filters = None
5555
self.tests = os.path.join(tests, "bin")
5656
self.optimization = optimization
57+
self.architecture = architecture
5758

5859

5960
def log(msg):
@@ -126,6 +127,12 @@ def main():
126127
help="The number of re-runs until it's assumed to be a real change",
127128
default=8,
128129
)
130+
argparser.add_argument(
131+
"-arch",
132+
type=str,
133+
help="The architecture. The default is x86_64",
134+
default="x86_64",
135+
)
129136
argparser.add_argument(
130137
"-platform", type=str, help="The benchmark build platform", default="macosx"
131138
)
@@ -158,6 +165,7 @@ def test_opt_levels(args):
158165
args.num_samples,
159166
args.num_reruns,
160167
output_file,
168+
args.arch
161169
):
162170
changes = True
163171

@@ -167,6 +175,7 @@ def test_opt_levels(args):
167175
opt_level,
168176
args.oldbuilddir[0],
169177
args.newbuilddir[0],
178+
args.arch,
170179
args.platform,
171180
output_file,
172181
):
@@ -177,6 +186,7 @@ def test_opt_levels(args):
177186
"swiftlibs",
178187
args.oldbuilddir[0],
179188
args.newbuilddir[0],
189+
args.arch,
180190
args.platform,
181191
output_file,
182192
):
@@ -221,7 +231,8 @@ def merge(results, other_results):
221231

222232

223233
def test_performance(
224-
opt_level, old_dir, new_dir, threshold, num_samples, num_reruns, output_file
234+
opt_level, old_dir, new_dir, threshold, num_samples, num_reruns,
235+
output_file, arch
225236
):
226237
"""Detect performance changes in benchmarks.
227238
@@ -231,7 +242,7 @@ def test_performance(
231242

232243
i, unchanged_length_count = 0, 0
233244
old, new = [
234-
BenchmarkDriver(DriverArgs(dir, optimization=opt_level))
245+
BenchmarkDriver(DriverArgs(dir, optimization=opt_level, architecture=arch))
235246
for dir in [old_dir, new_dir]
236247
]
237248
results = [measure(driver, driver.tests, i) for driver in [old, new]]
@@ -260,12 +271,13 @@ def test_performance(
260271
)
261272

262273

263-
def report_code_size(opt_level, old_dir, new_dir, platform, output_file):
274+
def report_code_size(opt_level, old_dir, new_dir, architecture, platform, output_file):
264275
if opt_level == "swiftlibs":
265276
files = glob.glob(os.path.join(old_dir, "lib", "swift", platform, "*.dylib"))
266277
else:
267278
files = glob.glob(
268-
os.path.join(old_dir, opt_level + "-*" + platform + "*", "*.o")
279+
os.path.join(old_dir, opt_level + "-" + architecture + "*" +
280+
platform + "*", "*.o")
269281
)
270282

271283
idx = 1
@@ -370,8 +382,8 @@ performance team (@eeckstein).
370382

371383

372384
def check_added(args, output_file=None):
373-
old = BenchmarkDriver(DriverArgs(args.oldbuilddir[0]))
374-
new = BenchmarkDriver(DriverArgs(args.newbuilddir[0]))
385+
old = BenchmarkDriver(DriverArgs(args.oldbuilddir[0], architecture=args.arch))
386+
new = BenchmarkDriver(DriverArgs(args.newbuilddir[0], architecture=args.arch))
375387
added = set(new.tests).difference(set(old.tests))
376388
new.tests = list(added)
377389
doctor = BenchmarkDoctor(args, driver=new)

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ def record_and_respond(self, args, stdin, stdout, stderr, shell):
198198
self.calls.append(args)
199199
return self.respond.get(args, "")
200200

201+
def test_mode():
202+
return True
203+
201204

202205
class TestBenchmarkDriverInitialization(unittest.TestCase):
203206
def setUp(self):
@@ -206,13 +209,19 @@ def setUp(self):
206209

207210
def test_test_harness(self):
208211
self.assertEqual(
209-
BenchmarkDriver(self.args, tests=["ignored"]).test_harness,
212+
BenchmarkDriver(
213+
self.args,
214+
tests=["ignored"],
215+
_subprocess=self.subprocess_mock).test_harness,
210216
"/benchmarks/Benchmark_O",
211217
)
212218
self.args.tests = "/path"
213219
self.args.optimization = "Suffix"
214220
self.assertEqual(
215-
BenchmarkDriver(self.args, tests=["ignored"]).test_harness,
221+
BenchmarkDriver(
222+
self.args,
223+
tests=["ignored"],
224+
_subprocess=self.subprocess_mock).test_harness,
216225
"/path/Benchmark_Suffix",
217226
)
218227

@@ -271,6 +280,7 @@ def test_log_file(self):
271280
swift_repo=None,
272281
),
273282
tests=["ignored"],
283+
_subprocess=self.subprocess_mock
274284
)
275285
self.assertEqual(driver.log_file, "/path/Benchmark_Suffix-" + now + ".log")
276286

0 commit comments

Comments
 (0)