-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_codegen_data.py
More file actions
198 lines (168 loc) · 7.2 KB
/
Copy pathgen_codegen_data.py
File metadata and controls
198 lines (168 loc) · 7.2 KB
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
from collections import defaultdict
import json
import os
import re
import subprocess
import sys
import statistics
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ESTORE_DIR = os.path.join(REPO_ROOT, "estore")
PLUGIN_COORD = "org.estore:estore-maven-plugin:1.0-SNAPSHOT:codegen"
MVN_TEST_FLAGS = "-Dprofile=true -Dsurefire.redirectTestOutputToFile=false"
NUMBER_OF_RUNS = 5
QUERIES = {
"Snb01": ["InteractiveDeleteQuery2", "InteractiveDeleteQuery3", "InteractiveDeleteQuery5", "InteractiveShortQuery1", "InteractiveShortQuery5", "InteractiveUpdateQuery2", "InteractiveUpdateQuery3", "InteractiveUpdateQuery5", "InteractiveUpdateQuery8"],
"Fin001": ["Tw1", "Tw2", "Tw3", "Tw4", "Tw8", "Tw9", "Tw13", "Tsr1"]
}
QUERIES_MAP = {
"Snb01": {
"SNBQueryA": "InteractiveDeleteQuery2",
"SNBQueryB": "InteractiveDeleteQuery3",
"SNBQueryC": "InteractiveDeleteQuery5",
"SNBQueryD": "InteractiveShortQuery1",
"SNBQueryE": "InteractiveShortQuery5",
"SNBQueryF": "InteractiveUpdateQuery2",
"SNBQueryG": "InteractiveUpdateQuery3",
"SNBQueryH": "InteractiveUpdateQuery5",
"SNBQueryI": "InteractiveUpdateQuery8",
},
}
def extract_times_sorted(output):
pattern = r'(\w+)\nTime: (\d+\.\d+)ms'
matches = re.findall(pattern, output)
queries = [match[0] for match in matches]
times = [match[1] for match in matches]
return queries, times
def extract_time(output):
pattern = r'Time: (\d+\.\d+)ms'
match = re.search(pattern, output)
return float(match.group(1)) if match else None
def extract_overhead_times(output):
method_pattern = r"Time taken for method test(\w+): (\d+) ms"
total_time_pattern = r"Total Time taken: (\d+) ms"
method_data = re.findall(method_pattern, output)
total_time_match = re.search(total_time_pattern, output)
total_time = int(total_time_match.group(1)) if total_time_match else None
results = {}
for method, time in method_data:
results[method] = int(time)
results["total"] = total_time
return results
def run_command(command, cwd=ESTORE_DIR):
result = subprocess.run(command, shell=True, capture_output=True, text=True, cwd=cwd)
output = (result.stdout + "\n" + result.stderr).strip()
if result.returncode != 0:
print(output)
sys.exit(result.returncode)
return output
def install_codegen_plugin():
run_command("mvn -pl estore-maven-plugin -am install -DskipTests", cwd=REPO_ROOT)
def run_codegen():
return run_command("mvn " + PLUGIN_COORD)
def generate_json_sequence():
install_codegen_plugin()
run_codegen()
def run_test(test_name):
times = []
for _ in range(NUMBER_OF_RUNS):
output = run_command(f"mvn test -Dtest={test_name} {MVN_TEST_FLAGS}")
_, run_times = extract_times_sorted(output)
times.append([float(time) for time in run_times])
return times
original_times = run_test("Snb01Test")
transformed_times = run_test("TransformedSnb01Test")
# Calculate averages
avg_original = [statistics.mean(t) for t in zip(*original_times)]
avg_transformed = [statistics.mean(t) for t in zip(*transformed_times)]
result = {
"original": avg_original,
"transformed": avg_transformed
}
with open('codegen-sequence.json', 'w') as f:
json.dump(result, f, indent=2)
def generate_json_standalone():
install_codegen_plugin()
run_codegen()
results = {
"original": defaultdict(lambda: defaultdict(lambda: defaultdict(float))),
"transformed": defaultdict(lambda: defaultdict(lambda: defaultdict(float)))
}
for run in range(NUMBER_OF_RUNS):
for version in ["original", "transformed"]:
for bench, queries in QUERIES.items():
for query in queries:
test_class = f"{'Transformed' if version == 'transformed' else ''}{bench}Test"
command = f"mvn test -Dtest={test_class}#test{query} {MVN_TEST_FLAGS}"
output = run_command(command)
time = extract_time(output)
if time is not None:
results[version][bench][query][str(run)] = time
else:
print(f"Error: {version} {bench} {query} failed")
print(output)
sys.exit(1)
print(f"Run {run + 1}/{NUMBER_OF_RUNS}: {version} {bench} {query} completed")
# Calculate averages
for version in results:
for bench in results[version]:
for query, runs in results[version][bench].items():
run_times = [time for run, time in runs.items() if run != "average"]
if run_times:
runs["average"] = round(sum(run_times) / len(run_times), 2)
else:
runs["average"] = 0 # or None, depending on how you want to handle missing data
results["queries"] = QUERIES_MAP["Snb01"]
# Save results to JSON file
with open('codegen-standalone.json', 'w') as f:
json.dump(results, f, indent=2)
print("Results have been saved to codegen-standalone.json")
def generate_json_overhead():
install_codegen_plugin()
results = {}
averages = {}
for run in range(NUMBER_OF_RUNS):
output = run_codegen()
data = extract_overhead_times(output)
for bench, quries in QUERIES.items():
for query in quries:
if query not in data:
print(f"Error: missing codegen time for {query}")
print(output)
sys.exit(1)
if bench not in results:
results[bench] = {}
averages[bench] = {}
if query not in results[bench]:
results[bench][query] = {}
averages[bench][query] = []
results[bench][query][str(run)] = data[query]
averages[bench][query].append(data[query])
if data["total"] is None:
print("Error: missing Total Time taken")
print(output)
sys.exit(1)
if "total" not in results:
results["total"] = {}
averages["total"] = []
results["total"][str(run)] = data["total"]
averages["total"].append(data["total"])
# Calculate averages
for bench in averages:
if bench == "total":
results["total"]["average"] = statistics.mean(averages["total"])
else:
for query in averages[bench]:
results[bench][query]["average"] = statistics.mean(averages[bench][query])
with open('codegen-overhead.json', 'w') as f:
json.dump(results, f, indent=2)
print("Results have been saved to codegen-overhead.json")
if __name__ == '__main__':
if len(sys.argv) != 2 or sys.argv[1] not in ['standalone', 'sequence', 'overhead']:
print("Usage: python scripts/gen_codegen_data.py [standalone|sequence|overhead]")
sys.exit(1)
if sys.argv[1] == 'sequence':
generate_json_sequence()
if sys.argv[1] == 'standalone':
generate_json_standalone()
if sys.argv[1] == 'overhead':
generate_json_overhead()