-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.py
executable file
·198 lines (140 loc) · 5.43 KB
/
parse.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
#!/usr/bin/env python3
# pip3 install pandas
# ./parse.py out kgp math
import pandas as pd
def parse(dir, apr, project):
status = extract_array(dir, apr, project, extract_status, "stt")
time = extract_array(dir, apr, project, extract_real_time, "time")
n_total_variants = extract_array(dir, apr, project, extract_n_total_variants, "v")
n_syntax_valid_variants = extract_array(dir, apr, project, extract_n_syntax_valid_variants, "v-sv")
n_build_succeeded_variants = extract_array(dir, apr, project, extract_n_build_succeeded_variants, "v-bs")
print_arrays([status, \
time, n_total_variants, \
n_syntax_valid_variants, \
n_build_succeeded_variants])
def print_arrays(dfs):
import re
base = dfs.pop(0)
head = list(base.columns.values)
for df in dfs:
base = base.join(df)
head.extend(list(df.columns.values))
head = map(lambda h: re.sub('\d+$', '', h) ,head)
print("", *head, sep='\t')
print(base[1:].to_csv(sep='\t'))
def extract_array(dir, apr, project, func, label):
arr = create_2d_array(dir, apr, project);
files = list_filtered_files(dir, apr, project)
for file in files:
id, seed = extract_id_seed(file, project)
extract_data = func(file)
arr[id][seed] = extract_data
df = pd.DataFrame(arr)
# rename column names
df.columns = ["%s%d" % (label, i) for i in range(df.columns.size)]
return df
def create_2d_array(dir, apr, project):
list_filtered_files(dir, apr, project)
maxId = 0
maxSeed = 0
files = list_filtered_files(dir, apr, project)
for file in files:
id, seed = extract_id_seed(file, project)
maxId = max(maxId, id)
maxSeed = max(maxSeed, seed)
return [[""] * (maxSeed+1) for i in range(maxId+1)]
def list_filtered_files(dir, apr, project):
import glob
import fnmatch
files = sorted(glob.glob(dir + '/*'))
f1 = lambda f: fnmatch.fnmatch(f, '*%s*' % apr)
f2 = lambda f: fnmatch.fnmatch(f, '*%s*' % project)
f = lambda f: f1(f) and f2(f)
return list(filter(f, files))
def extract_n_build_succeeded_variants(file):
''' fileからのbuild_succeededバリアント数の抜き出し '''
total, syntax_valid, build_succeeded = extract_n_variants(file)
return build_succeeded
def extract_n_syntax_valid_variants(file):
''' fileからのsyntax_validバリアント数の抜き出し '''
total, syntax_valid, build_succeeded = extract_n_variants(file)
return syntax_valid
def extract_n_total_variants(file):
''' fileからの生成バリアント数の抜き出し '''
total, syntax_valid, build_succeeded = extract_n_variants(file)
return total
def extract_n_variants(file):
''' fileからのバリアント情報の抜き出し '''
import re
total = ""
build_succeed = ""
for line in open(file):
m = re.search('KGenProgMain - Total Variants: generated (\d+), syntax-valid (\d+), build-succeeded (\d+)', line)
if m:
total = m.group(1)
syntax_valid = m.group(2)
build_succeed = m.group(3)
return (total, syntax_valid, build_succeed)
m = re.search('^NR_GENERATIONS=(\d+)', line)
if m:
total = m.group(1)
m = re.search('^NR_RIGHT_COMPILATIONS=(\d+)', line)
if m:
build_succeed = m.group(1)
if total and build_succeed:
return (total, "", build_succeed)
return "", "", ""
def extract_status(file):
''' fileからの実行結果ステータスの抜き出し '''
import re
is_astor = False
contains_status = False
status = set()
for line in open(file):
# kgp
if re.search('GC overhead limit exceeded', line):
status.add('e:heap')
if re.search('Java heap space', line):
status.add('e:heap')
if re.search('KGenProgMain - found enough solutions', line):
status.add('found')
if re.search('KGenProgMain - reached the time limit', line):
status.add('timeout')
if re.search('^OUTPUT_STATUS=STOP_BY_PATCH_FOUND', line):
status.add('found')
# astor
if re.search('fr.inria.main.evolution.AstorMain', line):
is_astor = True
if re.search('^OUTPUT_STATUS=', line):
contains_status = True
if re.search('^OUTPUT_STATUS=ERROR', line):
status.add('e')
if re.search('^OUTPUT_STATUS=MAX_GENERATION', line):
status.add('maxgen')
#if is_astor and not contains_status:
# status.add('e:timeout')
return list(status)
def extract_real_time(file):
''' fileからの実時間の抜き出し '''
import re
# for line in open(file): # for faster
for line in reversed(list(open(file))):
m = re.search('^real +(.*)$', line)
if m:
return float(m.group(1))
return 0
def extract_id_seed(file, project):
''' fileからのプロジェクトidと乱数シードの抜き出し '''
import re
m = re.search('.*%s(\d+)-(\d+).*' % project, file)
if m:
return int(m.group(1)), int(m.group(2))
else:
raise ValueError(file)
if __name__ == "__main__":
import sys
argv = sys.argv
if (len(argv) != 4):
print("usage: ./parse.py out kgp math")
exit()
parse(dir=argv[1], apr=argv[2], project=argv[3])