Skip to content

Commit 9c998d7

Browse files
committed
[leaks-runner] Get more accurate results by subtracting two differing iteration counts.
Previously, we had some white listing lists for allocations that were assigned into globals during a benchmarks running. Now we instead run two different iterations with the second running an additional time. Then we subtract the counts. This enables me to get rid of the whitelist.
1 parent ae745cc commit 9c998d7

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

benchmark/scripts/Benchmark_RuntimeLeaksRunner.in

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@ import perf_test_driver
2626
XFAIL_LIST = [
2727
]
2828

29-
# A list of Functions mapped to the number of globals in that function. These
30-
# show up as leaks. But we can count them, whitelist them, and then ignore them.
31-
FUNC_TO_GLOBAL_COUNTS = {
32-
'Ackermann': {"swift_count": 1, "objc_count": 0},
33-
'AngryPhonebook': {"swift_count": 1, "objc_count": 0},
34-
'GlobalClass': {'swift_count': 1, 'objc_count': 0},
35-
'Histogram': {'swift_count': 1, 'objc_count': 0},
36-
'Phonebook': {'swift_count': 1, 'objc_count': 0},
37-
'RC4': {'swift_count': 1, 'objc_count': 0},
38-
'RGBHistogram': {'swift_count': 1, 'objc_count': 0},
39-
'SortStrings': {'swift_count': 1, 'objc_count': 0},
40-
'TwoSum': {'swift_count': 1, 'objc_count': 0},
41-
}
42-
4329
# Global objective-c classes created by various frameworks. We do not care about these.
4430
IGNORABLE_GLOBAL_OBJC_CLASSES = set([
4531
'__NSPlaceholderDate',
@@ -93,18 +79,15 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
9379
def prepare_input(self, name):
9480
return {'num_samples': self.num_samples, 'num_iters': self.num_iters}
9581

96-
def process_input(self, data):
97-
test_name = '({},{})'.format(data['opt'], data['test_name'])
98-
print("Running {}...".format(test_name))
99-
sys.stdout.flush()
82+
def run_test(self, data, num_iters):
10083
try:
10184
p = subprocess.Popen([data['path'], "--run-all", "--num-samples={}".format(data['num_samples']),
102-
"--num-iters={}".format(data['num_iters']), data['test_name']],
85+
"--num-iters={}".format(num_iters), data['test_name']],
10386
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10487
error_out = p.communicate()[1].split("\n")
10588
except OSError:
10689
print("Child Process Failed! (%s,%s)" % (data['path'], data['test_name']))
107-
return LeaksRunnerResult(test_name)
90+
return None
10891

10992
try:
11093
# We grab the second line since swift globals get lazily created in the
@@ -113,16 +96,24 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
11396
d['objc_objects'] = [x for x in d['objc_objects'] if x not in IGNORABLE_GLOBAL_OBJC_CLASSES]
11497
d['objc_count'] = len(d['objc_objects'])
11598

116-
# Subtract out known global counts.
117-
if data['test_name'] in FUNC_TO_GLOBAL_COUNTS:
118-
d['swift_count'] -= FUNC_TO_GLOBAL_COUNTS[data['test_name']]['swift_count']
119-
d['objc_count'] -= FUNC_TO_GLOBAL_COUNTS[data['test_name']]['objc_count']
120-
12199
total_count = d['objc_count'] + d['swift_count']
122-
return LeaksRunnerResult(test_name, total_count)
100+
return total_count
123101
except (KeyError, ValueError):
124102
print("Failed parse output! (%s,%s)" % (data['path'], data['test_name']))
103+
return None
104+
105+
106+
def process_input(self, data):
107+
test_name = '({},{})'.format(data['opt'], data['test_name'])
108+
print("Running {}...".format(test_name))
109+
sys.stdout.flush()
110+
total_count1 = self.run_test(data, data['num_iters'])
111+
if total_count1 is None:
112+
return LeaksRunnerResult(test_name)
113+
total_count2 = self.run_test(data, data['num_iters']+1)
114+
if total_count2 is None:
125115
return LeaksRunnerResult(test_name)
116+
return LeaksRunnerResult(test_name, total_count2 - total_count1)
126117

127118
SWIFT_BIN_DIR = os.path.dirname(os.path.abspath(__file__))
128119

0 commit comments

Comments
 (0)