-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyco_proc
executable file
·172 lines (145 loc) · 5.35 KB
/
pyco_proc
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
#!/usr/bin/env python3
import argparse
import csv
import sys
from tabulate import tabulate
# fmt = 'text'
fmt = 'csv'
# number of parameters of execution
PARAMS_NUM = 1
###########################################
def proc_res(fd, args):
"""proc_res(fd, args) -> _|_
processes results of pycobench from file descriptor 'fd' using command line
arguments 'args'
"""
reader = csv.reader(
fd, delimiter=';', quotechar='"',
doublequote=False, quoting=csv.QUOTE_MINIMAL)
engines = list()
engines_outs = dict()
results = dict()
for row in reader:
assert len(row) >= 1 + 1 + PARAMS_NUM # status + engine name + params
status, eng = row[0], row[1]
params = tuple(row[2:(PARAMS_NUM+2)])
row_tail = row[(PARAMS_NUM+2):]
if params not in results:
results[params] = dict()
if eng not in engines:
engines.append(eng)
engines_outs[eng] = list()
# we don't have some results twice
assert eng not in results[params]
if status == 'finished':
retcode, out, err, runtime = row_tail[0], row_tail[1], \
row_tail[2], row_tail[3]
eng_res = dict()
eng_res["runtime"] = runtime
eng_res["retcode"] = retcode
eng_res["error"] = err
eng_res["output"] = dict()
out_lines = out.split("###")
for line in out_lines:
spl = line.split(':', 1)
if len(spl) != 2: # jump over lines not in the format
continue
name, val = spl[0], spl[1]
assert name not in eng_res["output"]
if name not in engines_outs[eng]:
engines_outs[eng].append(name)
eng_res["output"][name] = val
results[params][eng] = eng_res
if status == 'error':
results[params][eng] = "ERR"
if status == 'timeout':
results[params][eng] = "TO"
list_ptrns = list()
for bench in results:
all_engs = True
ls = list(bench)
for eng in engines:
out_len = len(engines_outs[eng]) + 1 # +1 = time
if eng in results[bench]:
bench_res = results[bench][eng]
if bench_res == "ERR":
for i in range(out_len):
ls.append("ERR")
elif bench_res == "TO":
for i in range(out_len):
ls.append("TO")
else:
assert type(bench_res) == dict
assert "output" in bench_res
ls.append(bench_res["runtime"])
for out in engines_outs[eng]:
if out in bench_res["output"]:
ls.append(bench_res["output"][out])
else:
sys.stderr.write("Warning: in {} and {}: "
"element {} not in {}\n".format(bench, eng,
out, bench_res["output"]))
ls.append("MISSING")
# assert False
else:
all_engs = False
for i in range(out_len):
ls.append("MISSING")
# prepend with status of the benchmark
if args.tick:
if all_engs:
ls = ["T"] + ls
else:
ls = ["F"] + ls
list_ptrns.append(ls)
header = list()
if args.tick:
header += ["T"]
header += ['name']
for eng in engines:
header += [eng + "-runtime"]
for out in engines_outs[eng]:
header += [eng + "-" + out]
fmt = "text"
if args.csv:
fmt = "csv"
if args.text:
fmt = "text"
if args.html:
fmt = "html"
if fmt == 'html':
print(tabulate(list_ptrns, header, tablefmt='html'))
elif fmt == 'text':
print(tabulate(list_ptrns, header, tablefmt='text'))
elif fmt == 'csv':
writer = csv.writer(
sys.stdout, delimiter=';', quotechar='"', escapechar='\\',
doublequote=False, quoting=csv.QUOTE_MINIMAL)
writer.writerow(header)
writer.writerows(list_ptrns)
else:
raise Exception('Invalid output format: "{}"'.format(fmt))
return
###############################
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='''proc_results.py - \
Processes results of benchmarks from pycobench''')
parser.add_argument('results', metavar='result-file', nargs='?',
help='file with results (output of pycobench);'
'if not provided stdin is used')
parser.add_argument('--csv', action="store_true",
help='output in CSV')
parser.add_argument('--text', action="store_true",
help='output in text')
parser.add_argument('--html', action="store_true",
help='output in HTML')
parser.add_argument('--tick', action="store_true",
help='tick finished benchmarks (usable for filtering)')
args = parser.parse_args()
if args.results:
fd = open(args.results, "r")
else:
fd = sys.stdin
proc_res(fd, args)
if args.results:
fd.close()