Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/ts/misc/chart.py
16344 views
1
#!/usr/bin/env python
2
3
import testlog_parser, sys, os, xml, re
4
from table_formatter import *
5
from optparse import OptionParser
6
7
cvsize_re = re.compile("^\d+x\d+$")
8
cvtype_re = re.compile("^(CV_)(8U|8S|16U|16S|32S|32F|64F)(C\d{1,3})?$")
9
10
def keyselector(a):
11
if cvsize_re.match(a):
12
size = [int(d) for d in a.split('x')]
13
return size[0] * size[1]
14
elif cvtype_re.match(a):
15
if a.startswith("CV_"):
16
a = a[3:]
17
depth = 7
18
if a[0] == '8':
19
depth = (0, 1) [a[1] == 'S']
20
elif a[0] == '1':
21
depth = (2, 3) [a[2] == 'S']
22
elif a[2] == 'S':
23
depth = 4
24
elif a[0] == '3':
25
depth = 5
26
elif a[0] == '6':
27
depth = 6
28
cidx = a.find('C')
29
if cidx < 0:
30
channels = 1
31
else:
32
channels = int(a[a.index('C') + 1:])
33
#return (depth & 7) + ((channels - 1) << 3)
34
return ((channels-1) & 511) + (depth << 9)
35
return a
36
37
convert = lambda text: int(text) if text.isdigit() else text
38
alphanum_keyselector = lambda key: [ convert(c) for c in re.split('([0-9]+)', str(keyselector(key))) ]
39
40
def getValueParams(test):
41
param = test.get("value_param")
42
if not param:
43
return []
44
if param.startswith("("):
45
param = param[1:]
46
if param.endswith(")"):
47
param = param[:-1]
48
args = []
49
prev_pos = 0
50
start = 0
51
balance = 0
52
while True:
53
idx = param.find(",", prev_pos)
54
if idx < 0:
55
break
56
idxlb = param.find("(", prev_pos, idx)
57
while idxlb >= 0:
58
balance += 1
59
idxlb = param.find("(", idxlb+1, idx)
60
idxrb = param.find(")", prev_pos, idx)
61
while idxrb >= 0:
62
balance -= 1
63
idxrb = param.find(")", idxrb+1, idx)
64
assert(balance >= 0)
65
if balance == 0:
66
args.append(param[start:idx].strip())
67
start = idx + 1
68
prev_pos = idx + 1
69
args.append(param[start:].strip())
70
return args
71
#return [p.strip() for p in param.split(",")]
72
73
def nextPermutation(indexes, lists, x, y):
74
idx = len(indexes)-1
75
while idx >= 0:
76
while idx == x or idx == y:
77
idx -= 1
78
if idx < 0:
79
return False
80
v = indexes[idx] + 1
81
if v < len(lists[idx]):
82
indexes[idx] = v;
83
return True;
84
else:
85
indexes[idx] = 0;
86
idx -= 1
87
return False
88
89
def getTestWideName(sname, indexes, lists, x, y):
90
name = sname + "::("
91
for i in range(len(indexes)):
92
if i > 0:
93
name += ", "
94
if i == x:
95
name += "X"
96
elif i == y:
97
name += "Y"
98
else:
99
name += lists[i][indexes[i]]
100
return str(name + ")")
101
102
def getTest(stests, x, y, row, col):
103
for pair in stests:
104
if pair[1][x] == row and pair[1][y] == col:
105
return pair[0]
106
return None
107
108
if __name__ == "__main__":
109
parser = OptionParser()
110
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto")
111
parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), us, ns or ticks)", metavar="UNITS", default="ms")
112
parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean")
113
parser.add_option("-x", "", dest="x", help="argument number for rows", metavar="ROW", default=1)
114
parser.add_option("-y", "", dest="y", help="argument number for columns", metavar="COL", default=0)
115
parser.add_option("-f", "--filter", dest="filter", help="regex to filter tests", metavar="REGEX", default=None)
116
(options, args) = parser.parse_args()
117
118
if len(args) != 1:
119
print >> sys.stderr, "Usage:\n", os.path.basename(sys.argv[0]), "<log_name1>.xml"
120
exit(1)
121
122
options.generateHtml = detectHtmlOutputType(options.format)
123
if options.metric not in metrix_table:
124
options.metric = "gmean"
125
if options.metric.endswith("%"):
126
options.metric = options.metric[:-1]
127
getter = metrix_table[options.metric][1]
128
129
tests = testlog_parser.parseLogFile(args[0])
130
if options.filter:
131
expr = re.compile(options.filter)
132
tests = [(t,getValueParams(t)) for t in tests if expr.search(str(t))]
133
else:
134
tests = [(t,getValueParams(t)) for t in tests]
135
136
args[0] = os.path.basename(args[0])
137
138
if not tests:
139
print >> sys.stderr, "Error - no tests matched"
140
exit(1)
141
142
argsnum = len(tests[0][1])
143
sname = tests[0][0].shortName()
144
145
arglists = []
146
for i in range(argsnum):
147
arglists.append({})
148
149
names = set()
150
names1 = set()
151
for pair in tests:
152
sn = pair[0].shortName()
153
if len(pair[1]) > 1:
154
names.add(sn)
155
else:
156
names1.add(sn)
157
if sn == sname:
158
if len(pair[1]) != argsnum:
159
print >> sys.stderr, "Error - unable to create chart tables for functions having different argument numbers"
160
sys.exit(1)
161
for i in range(argsnum):
162
arglists[i][pair[1][i]] = 1
163
164
if names1 or len(names) != 1:
165
print >> sys.stderr, "Error - unable to create tables for functions from different test suits:"
166
i = 1
167
for name in sorted(names):
168
print >> sys.stderr, "%4s: %s" % (i, name)
169
i += 1
170
if names1:
171
print >> sys.stderr, "Other suits in this log (can not be chosen):"
172
for name in sorted(names1):
173
print >> sys.stderr, "%4s: %s" % (i, name)
174
i += 1
175
sys.exit(1)
176
177
if argsnum < 2:
178
print >> sys.stderr, "Error - tests from %s have less than 2 parameters" % sname
179
exit(1)
180
181
for i in range(argsnum):
182
arglists[i] = sorted([str(key) for key in arglists[i].iterkeys()], key=alphanum_keyselector)
183
184
if options.generateHtml and options.format != "moinwiki":
185
htmlPrintHeader(sys.stdout, "Report %s for %s" % (args[0], sname))
186
187
indexes = [0] * argsnum
188
x = int(options.x)
189
y = int(options.y)
190
if x == y or x < 0 or y < 0 or x >= argsnum or y >= argsnum:
191
x = 1
192
y = 0
193
194
while True:
195
stests = []
196
for pair in tests:
197
t = pair[0]
198
v = pair[1]
199
for i in range(argsnum):
200
if i != x and i != y:
201
if v[i] != arglists[i][indexes[i]]:
202
t = None
203
break
204
if t:
205
stests.append(pair)
206
207
tbl = table(metrix_table[options.metric][0] + " for\n" + getTestWideName(sname, indexes, arglists, x, y))
208
tbl.newColumn("x", "X\Y")
209
for col in arglists[y]:
210
tbl.newColumn(col, col, align="center")
211
for row in arglists[x]:
212
tbl.newRow()
213
tbl.newCell("x", row)
214
for col in arglists[y]:
215
case = getTest(stests, x, y, row, col)
216
if case:
217
status = case.get("status")
218
if status != "run":
219
tbl.newCell(col, status, color = "red")
220
else:
221
val = getter(case, None, options.units)
222
if isinstance(val, float):
223
tbl.newCell(col, "%.2f %s" % (val, options.units), val)
224
else:
225
tbl.newCell(col, val, val)
226
else:
227
tbl.newCell(col, "-")
228
229
if options.generateHtml:
230
tbl.htmlPrintTable(sys.stdout, options.format == "moinwiki")
231
else:
232
tbl.consolePrintTable(sys.stdout)
233
if not nextPermutation(indexes, arglists, x, y):
234
break
235
236
if options.generateHtml and options.format != "moinwiki":
237
htmlPrintFooter(sys.stdout)
238
239