-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.py
executable file
·221 lines (189 loc) · 6.7 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import fnmatch
import json
import os
from glob import glob
import re
import pandas
def recursive_find(base, pattern="*experiment.json"):
"""recursive find will yield python files in all directory levels
below a base path.
Arguments:
- base (str) : the base directory to search
- pattern: a pattern to match, defaults to *.py
"""
for root, _, filenames in os.walk(base):
for filename in fnmatch.filter(filenames, pattern):
yield os.path.join(root, filename)
def read_json(filename):
with open(filename, "r") as fd:
content = json.loads(fd.read())
return content
def create_results_table(experiments, filename=False):
"""
Given experiments data files, iterate through and create a results table that includes splice details
"""
columns = [
"original",
"changed",
"analysis",
"compiler",
"seconds",
"predictor",
"prediction",
]
if filename:
columns.append("file")
df = pandas.DataFrame(columns=columns)
def add_prediction_row(original, changed, compiler, res, p, predictor, e):
"""
Given a result, add a row to the data frame.
"""
# Different predictors use different data
prediction = p.get("prediction", False)
seconds = p.get("seconds") or "unknown"
# symbols has two diff cases
analysis = "abi-compliance-tester"
if predictor == "symbols":
analysis = p["command"]
elif predictor == "libabigail":
analysis = "abidiff"
# Smeagle results not included in this paper
elif predictor == "smeagle":
return
row = [
original,
changed,
analysis,
compiler,
seconds,
predictor,
prediction,
]
if filename:
row.append(e)
df.loc[len(df.index), :] = row
# Of the splice successes, now look into results
for e in experiments:
compiler = e.split("/")[-2]
data = read_json(e)
for res in data:
# Split on right repo name to get relative path
original = (
res["original"][0].rsplit("splice-experiment-runs")[-1].strip("/")
)
changed = res["spliced"][0].rsplit("splice-experiment-runs")[-1].strip("/")
for predictor, listing in res["predictions"].items():
for p in listing:
add_prediction_row(
original, changed, compiler, res, p, predictor, e
)
return df
def create_fedora_results_table(experiments, filename=False):
"""
Given experiments data files, iterate through and create a results table that includes splice details
"""
columns = [
"a",
"b",
"original",
"changed",
"analysis",
"seconds",
"predictor",
"prediction",
"size_original",
"size_changed",
]
if filename:
columns.append("file")
df = pandas.DataFrame(columns=columns)
def add_prediction_row(before, after, original, changed, p, predictor, e):
"""
Given a result, add a row to the data frame.
"""
# Different predictors use different data
prediction = p.get("prediction", False)
seconds = p.get("seconds") or p.get("time") or "unknown"
# symbols has two diff cases
analysis = "abi-compliance-tester"
if predictor == "symbols":
analysis = p["command"]
elif predictor == "libabigail":
analysis = "abidiff"
# ABI lab generate pass/fail results even when it can't find a debug file
# The debug files are present. This appears to be a bug in ABI lab.
if analysis == "abi-compliance-tester":
if re.search("ERROR: can't find debug info in object", p["message"], re.DOTALL):
prediction = "NODEBUG"
row = [
before,
after,
original,
changed,
analysis,
seconds,
predictor,
prediction,
p["size_original"],
p["size_changed"],
]
if filename:
row.append(e)
df.loc[len(df.index), :] = row
# Of the splice successes, now look into results
for e in experiments:
basename = os.path.basename(e)
libname, comparison = basename.split("-", 1)
comparison = comparison.replace(".json", "")
comparison = [
(f"fedora{x}").strip("-") for x in comparison.rsplit("fedora") if x
]
before = comparison[-2]
after = comparison[-1]
data = read_json(e)
# Symbols libs have one result per file - flattened
if "fedora/symbols" in e:
data = [data]
for res in data:
# Add size to table
size_lookup = res["stats"]["sizes_bytes"]
# If we don't have predictions, it's a full (non symbols) result
if "predictions" not in res:
continue
else:
size_original = size_lookup[res["original"][0]]
size_changed = size_lookup[res["spliced"][0]]
# Split on right repo name to get relative path
original = (
res["original"][0].rsplit("splice-experiment-runs")[-1].strip("/")
)
changed = (
res["spliced"][0].rsplit("splice-experiment-runs")[-1].strip("/")
)
for predictor, listing in res["predictions"].items():
for p in listing:
# ABI lab has several terminated results for "stack smashing"
if (
"message" in p
and isinstance(p["message"], str)
and "***: terminated" in p["message"].lower()
):
p["prediction"] = "Terminated"
p["size_original"] = size_original
p["size_changed"] = size_changed
add_prediction_row(
before, after, original, changed, p, predictor, e
)
return df
def create_sizes_table(experiments):
"""
Keep track of all binary sizes
(this is currently not used)
"""
sizes = pandas.DataFrame(columns=["name", "size_bytes"])
for e in experiments:
data = read_json(e)
for res in data:
for libname, size in res["stats"]["sizes_bytes"].items():
sizes.loc[len(sizes.index), :] = [libname, size]
return sizes