Skip to content

Commit c8905a1

Browse files
authored
Merge pull request #14199 from gottesmm/pr-218c78fa7dd83f5a1e09ccb82777f0c5012b733f
2 parents fbdcee4 + 70251a3 commit c8905a1

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

benchmark/scripts/Benchmark_RuntimeLeaksRunner.in

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,35 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
8181
def prepare_input(self, name):
8282
return {'num_samples': self.num_samples, 'num_iters': self.num_iters}
8383

84+
def run_test_inner(self, data, num_iters):
85+
p = subprocess.Popen([
86+
data['path'],
87+
"--num-samples={}".format(data['num_samples']),
88+
"--num-iters={}".format(num_iters), data['test_name']],
89+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
90+
error_out = p.communicate()[1].split("\n")
91+
result = p.returncode
92+
if result is None:
93+
raise RuntimeError("Expected one line of output")
94+
if result != 0:
95+
raise RuntimeError("Process segfaulted")
96+
return error_out
97+
8498
def run_test(self, data, num_iters):
8599
try:
86-
p = subprocess.Popen([
87-
data['path'],
88-
"--num-samples={}".format(data['num_samples']),
89-
"--num-iters={}".format(num_iters), data['test_name']],
90-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
91-
error_out = p.communicate()[1].split("\n")
92-
result = p.returncode
93-
if result is None:
94-
raise RuntimeError("Expected one line of output")
95-
if result != 0:
96-
raise RuntimeError("Process segfaulted")
97-
except Exception:
98-
sys.stderr.write("Child Process Failed! (%s,%s)\n" % (
99-
data['path'], data['test_name']))
100+
args = [data, num_iters]
101+
result = perf_test_driver.run_with_timeout(self.run_test_inner,
102+
args)
103+
except Exception, e:
104+
sys.stderr.write("Child Process Failed! (%s,%s). Error: %s\n" % (
105+
data['path'], data['test_name'], e))
100106
sys.stderr.flush()
101107
return None
102108

103109
try:
104110
# We grab the second line since swift globals get lazily created in
105111
# the first iteration.
106-
d = json.loads(error_out[1])
112+
d = json.loads(result[1])
107113
d['objc_objects'] = [x for x in d['objc_objects']
108114
if x not in IGNORABLE_GLOBAL_OBJC_CLASSES]
109115
d['objc_count'] = len(d['objc_objects'])

benchmark/scripts/perf_test_driver/perf_test_driver.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ def print_data(self, max_test_len):
5757
print(fmt.format(self.get_name(), self.get_result()))
5858

5959

60+
def run_with_timeout(func, args):
61+
# We timeout after 10 minutes.
62+
timeout_seconds = 10 * 60
63+
64+
# We just use this to create a timeout since we use an older python. Once
65+
# we update to use python >= 3.3, use the timeout API on communicate
66+
# instead.
67+
import multiprocessing.dummy
68+
fakeThreadPool = multiprocessing.dummy.Pool(1)
69+
try:
70+
result = fakeThreadPool.apply_async(func, args=args)
71+
return result.get(timeout_seconds)
72+
except multiprocessing.TimeoutError:
73+
fakeThreadPool.terminate()
74+
raise RuntimeError("Child process aborted due to timeout. "
75+
"Timeout: %s seconds" % timeout_seconds)
76+
77+
6078
def _unwrap_self(args):
6179
return type(args[0]).process_input(*args)
6280

0 commit comments

Comments
 (0)