2013-06-14 18:53:02 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-06-21 20:45:17 +08:00
|
|
|
"""
|
|
|
|
This script can generate XLS reports from OpenCV tests' XML output files.
|
|
|
|
|
|
|
|
To use it, first, create a directory for each machine you ran tests on.
|
|
|
|
Each such directory will become a sheet in the report. Put each XML file
|
|
|
|
into the corresponding directory.
|
|
|
|
|
|
|
|
Then, create your configuration file(s). You can have a global configuration
|
|
|
|
file (specified with the -c option), and per-sheet configuration files, which
|
|
|
|
must be called sheet.conf and placed in the directory corresponding to the sheet.
|
|
|
|
The settings in the per-sheet configuration file will override those in the
|
|
|
|
global configuration file, if both are present.
|
|
|
|
|
|
|
|
A configuration file must consist of a Python dictionary. The following keys
|
|
|
|
will be recognized:
|
|
|
|
|
|
|
|
* 'comparisons': [{'from': string, 'to': string}]
|
|
|
|
List of configurations to compare performance between. For each item,
|
|
|
|
the sheet will have a column showing speedup from configuration named
|
|
|
|
'from' to configuration named "to".
|
|
|
|
|
|
|
|
* 'configuration_matchers': [{'properties': {string: object}, 'name': string}]
|
|
|
|
Instructions for matching test run property sets to configuration names.
|
|
|
|
|
|
|
|
For each found XML file:
|
|
|
|
|
|
|
|
1) All attributes of the root element starting with the prefix 'cv_' are
|
|
|
|
placed in a dictionary, with the cv_ prefix stripped and the cv_module_name
|
|
|
|
element deleted.
|
|
|
|
|
|
|
|
2) The first matcher for which the XML's file property set contains the same
|
|
|
|
keys with equal values as its 'properties' dictionary is searched for.
|
|
|
|
A missing property can be matched by using None as the value.
|
|
|
|
|
|
|
|
Corollary 1: you should place more specific matchers before less specific
|
|
|
|
ones.
|
|
|
|
|
|
|
|
Corollary 2: an empty 'properties' dictionary matches every property set.
|
|
|
|
|
|
|
|
3) If a matching matcher is found, its 'name' string is presumed to be the name
|
2013-07-04 22:19:33 +08:00
|
|
|
of the configuration the XML file corresponds to. A warning is printed if
|
|
|
|
two different property sets match to the same configuration name.
|
|
|
|
|
|
|
|
4) If a such a matcher isn't found, if --include-unmatched was specified, the
|
|
|
|
configuration name is assumed to be the relative path from the sheet's
|
|
|
|
directory to the XML file's containing directory. If the XML file isinstance
|
|
|
|
directly inside the sheet's directory, the configuration name is instead
|
|
|
|
a dump of all its properties. If --include-unmatched wasn't specified,
|
|
|
|
the XML file is ignored and a warning is printed.
|
2013-06-21 20:45:17 +08:00
|
|
|
|
|
|
|
* 'configurations': [string]
|
|
|
|
List of names for compile-time and runtime configurations of OpenCV.
|
|
|
|
Each item will correspond to a column of the sheet.
|
|
|
|
|
|
|
|
* 'module_colors': {string: string}
|
|
|
|
Mapping from module name to color name. In the sheet, cells containing module
|
|
|
|
names from this mapping will be colored with the corresponding color. You can
|
|
|
|
find the list of available colors here:
|
|
|
|
<http://www.simplistix.co.uk/presentations/python-excel.pdf>.
|
|
|
|
|
|
|
|
* 'sheet_name': string
|
|
|
|
Name for the sheet. If this parameter is missing, the name of sheet's directory
|
|
|
|
will be used.
|
|
|
|
|
2013-07-05 20:10:28 +08:00
|
|
|
* 'sheet_properties': [(string, string)]
|
|
|
|
List of arbitrary (key, value) pairs that somehow describe the sheet. Will be
|
|
|
|
dumped into the first row of the sheet in string form.
|
|
|
|
|
2013-06-21 20:45:17 +08:00
|
|
|
Note that all keys are optional, although to get useful results, you'll want to
|
|
|
|
specify at least 'configurations' and 'configuration_matchers'.
|
|
|
|
|
|
|
|
Finally, run the script. Use the --help option for usage information.
|
|
|
|
"""
|
|
|
|
|
2013-06-14 18:53:02 +08:00
|
|
|
from __future__ import division
|
|
|
|
|
|
|
|
import ast
|
2013-07-04 22:03:03 +08:00
|
|
|
import errno
|
2013-06-20 23:34:32 +08:00
|
|
|
import fnmatch
|
2013-06-14 18:53:02 +08:00
|
|
|
import logging
|
2013-06-20 18:27:51 +08:00
|
|
|
import numbers
|
2013-06-14 18:53:02 +08:00
|
|
|
import os, os.path
|
|
|
|
import re
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from glob import glob
|
|
|
|
from itertools import ifilter
|
|
|
|
|
|
|
|
import xlwt
|
|
|
|
|
|
|
|
from testlog_parser import parseLogFile
|
|
|
|
|
|
|
|
re_image_size = re.compile(r'^ \d+ x \d+$', re.VERBOSE)
|
|
|
|
re_data_type = re.compile(r'^ (?: 8 | 16 | 32 | 64 ) [USF] C [1234] $', re.VERBOSE)
|
|
|
|
|
|
|
|
time_style = xlwt.easyxf(num_format_str='#0.00')
|
|
|
|
no_time_style = xlwt.easyxf('pattern: pattern solid, fore_color gray25')
|
2014-02-17 21:01:23 +08:00
|
|
|
failed_style = xlwt.easyxf('pattern: pattern solid, fore_color red')
|
|
|
|
noimpl_style = xlwt.easyxf('pattern: pattern solid, fore_color orange')
|
|
|
|
style_dict = {"failed": failed_style, "noimpl":noimpl_style}
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
speedup_style = time_style
|
|
|
|
good_speedup_style = xlwt.easyxf('font: color green', num_format_str='#0.00')
|
|
|
|
bad_speedup_style = xlwt.easyxf('font: color red', num_format_str='#0.00')
|
|
|
|
no_speedup_style = no_time_style
|
|
|
|
error_speedup_style = xlwt.easyxf('pattern: pattern solid, fore_color orange')
|
2013-06-18 01:06:02 +08:00
|
|
|
header_style = xlwt.easyxf('font: bold true; alignment: horizontal centre, vertical top, wrap True')
|
2013-07-10 18:50:51 +08:00
|
|
|
subheader_style = xlwt.easyxf('alignment: horizontal centre, vertical top')
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-06-20 23:34:32 +08:00
|
|
|
class Collector(object):
|
2013-07-04 22:19:33 +08:00
|
|
|
def __init__(self, config_match_func, include_unmatched):
|
2013-06-20 23:34:32 +08:00
|
|
|
self.__config_cache = {}
|
|
|
|
self.config_match_func = config_match_func
|
2013-07-04 22:19:33 +08:00
|
|
|
self.include_unmatched = include_unmatched
|
2013-06-20 23:34:32 +08:00
|
|
|
self.tests = {}
|
2013-07-04 22:19:33 +08:00
|
|
|
self.extra_configurations = set()
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-06-21 17:43:16 +08:00
|
|
|
# Format a sorted sequence of pairs as if it was a dictionary.
|
|
|
|
# We can't just use a dictionary instead, since we want to preserve the sorted order of the keys.
|
|
|
|
@staticmethod
|
2013-07-04 22:19:33 +08:00
|
|
|
def __format_config_cache_key(pairs, multiline=False):
|
|
|
|
return (
|
|
|
|
('{\n' if multiline else '{') +
|
|
|
|
(',\n' if multiline else ', ').join(
|
|
|
|
(' ' if multiline else '') + repr(k) + ': ' + repr(v) for (k, v) in pairs) +
|
|
|
|
('\n}\n' if multiline else '}')
|
|
|
|
)
|
|
|
|
|
|
|
|
def collect_from(self, xml_path, default_configuration):
|
2013-06-20 23:34:32 +08:00
|
|
|
run = parseLogFile(xml_path)
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-06-20 23:34:32 +08:00
|
|
|
module = run.properties['module_name']
|
|
|
|
|
|
|
|
properties = run.properties.copy()
|
|
|
|
del properties['module_name']
|
|
|
|
|
|
|
|
props_key = tuple(sorted(properties.iteritems())) # dicts can't be keys
|
|
|
|
|
|
|
|
if props_key in self.__config_cache:
|
|
|
|
configuration = self.__config_cache[props_key]
|
|
|
|
else:
|
|
|
|
configuration = self.config_match_func(properties)
|
|
|
|
|
|
|
|
if configuration is None:
|
2013-07-04 22:19:33 +08:00
|
|
|
if self.include_unmatched:
|
|
|
|
if default_configuration is not None:
|
|
|
|
configuration = default_configuration
|
|
|
|
else:
|
|
|
|
configuration = Collector.__format_config_cache_key(props_key, multiline=True)
|
|
|
|
|
|
|
|
self.extra_configurations.add(configuration)
|
|
|
|
else:
|
|
|
|
logging.warning('failed to match properties to a configuration: %s',
|
|
|
|
Collector.__format_config_cache_key(props_key))
|
|
|
|
|
2013-06-20 23:34:32 +08:00
|
|
|
else:
|
|
|
|
same_config_props = [it[0] for it in self.__config_cache.iteritems() if it[1] == configuration]
|
|
|
|
if len(same_config_props) > 0:
|
2013-06-21 17:43:16 +08:00
|
|
|
logging.warning('property set %s matches the same configuration %r as property set %s',
|
|
|
|
Collector.__format_config_cache_key(props_key),
|
|
|
|
configuration,
|
|
|
|
Collector.__format_config_cache_key(same_config_props[0]))
|
2013-06-20 23:34:32 +08:00
|
|
|
|
|
|
|
self.__config_cache[props_key] = configuration
|
|
|
|
|
|
|
|
if configuration is None: return
|
|
|
|
|
2013-07-04 22:52:10 +08:00
|
|
|
module_tests = self.tests.setdefault(module, {})
|
2013-06-20 23:34:32 +08:00
|
|
|
|
|
|
|
for test in run.tests:
|
|
|
|
test_results = module_tests.setdefault((test.shortName(), test.param()), {})
|
2013-07-04 23:59:26 +08:00
|
|
|
new_result = test.get("gmean") if test.status == 'run' else test.status
|
|
|
|
test_results[configuration] = min(
|
|
|
|
test_results.get(configuration), new_result,
|
|
|
|
key=lambda r: (1, r) if isinstance(r, numbers.Number) else
|
|
|
|
(2,) if r is not None else
|
|
|
|
(3,)
|
|
|
|
) # prefer lower result; prefer numbers to errors and errors to nothing
|
2013-06-20 23:34:32 +08:00
|
|
|
|
|
|
|
def make_match_func(matchers):
|
|
|
|
def match_func(properties):
|
|
|
|
for matcher in matchers:
|
|
|
|
if all(properties.get(name) == value
|
|
|
|
for (name, value) in matcher['properties'].iteritems()):
|
|
|
|
return matcher['name']
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return match_func
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
def main():
|
|
|
|
arg_parser = ArgumentParser(description='Build an XLS performance report.')
|
|
|
|
arg_parser.add_argument('sheet_dirs', nargs='+', metavar='DIR', help='directory containing perf test logs')
|
|
|
|
arg_parser.add_argument('-o', '--output', metavar='XLS', default='report.xls', help='name of output file')
|
|
|
|
arg_parser.add_argument('-c', '--config', metavar='CONF', help='global configuration file')
|
2013-07-04 22:19:33 +08:00
|
|
|
arg_parser.add_argument('--include-unmatched', action='store_true',
|
|
|
|
help='include results from XML files that were not recognized by configuration matchers')
|
2013-07-10 18:50:51 +08:00
|
|
|
arg_parser.add_argument('--show-times-per-pixel', action='store_true',
|
|
|
|
help='for tests that have an image size parameter, show per-pixel time, as well as total time')
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
args = arg_parser.parse_args()
|
|
|
|
|
|
|
|
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
|
|
|
|
|
|
|
|
if args.config is not None:
|
|
|
|
with open(args.config) as global_conf_file:
|
|
|
|
global_conf = ast.literal_eval(global_conf_file.read())
|
|
|
|
else:
|
|
|
|
global_conf = {}
|
|
|
|
|
|
|
|
wb = xlwt.Workbook()
|
|
|
|
|
|
|
|
for sheet_path in args.sheet_dirs:
|
|
|
|
try:
|
|
|
|
with open(os.path.join(sheet_path, 'sheet.conf')) as sheet_conf_file:
|
|
|
|
sheet_conf = ast.literal_eval(sheet_conf_file.read())
|
2013-07-04 22:03:03 +08:00
|
|
|
except IOError as ioe:
|
|
|
|
if ioe.errno != errno.ENOENT: raise
|
2013-06-14 18:53:02 +08:00
|
|
|
sheet_conf = {}
|
2013-06-20 23:39:02 +08:00
|
|
|
logging.debug('no sheet.conf for %s', sheet_path)
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
sheet_conf = dict(global_conf.items() + sheet_conf.items())
|
|
|
|
|
2013-06-20 23:34:32 +08:00
|
|
|
config_names = sheet_conf.get('configurations', [])
|
|
|
|
config_matchers = sheet_conf.get('configuration_matchers', [])
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-07-04 22:19:33 +08:00
|
|
|
collector = Collector(make_match_func(config_matchers), args.include_unmatched)
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-06-20 23:34:32 +08:00
|
|
|
for root, _, filenames in os.walk(sheet_path):
|
|
|
|
logging.info('looking in %s', root)
|
|
|
|
for filename in fnmatch.filter(filenames, '*.xml'):
|
2013-07-04 22:19:33 +08:00
|
|
|
if os.path.normpath(sheet_path) == os.path.normpath(root):
|
|
|
|
default_conf = None
|
|
|
|
else:
|
|
|
|
default_conf = os.path.relpath(root, sheet_path)
|
|
|
|
collector.collect_from(os.path.join(root, filename), default_conf)
|
|
|
|
|
|
|
|
config_names.extend(sorted(collector.extra_configurations - set(config_names)))
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
sheet = wb.add_sheet(sheet_conf.get('sheet_name', os.path.basename(os.path.abspath(sheet_path))))
|
|
|
|
|
2013-07-05 20:10:28 +08:00
|
|
|
sheet_properties = sheet_conf.get('sheet_properties', [])
|
|
|
|
|
|
|
|
sheet.write(0, 0, 'Properties:')
|
|
|
|
|
|
|
|
sheet.write(0, 1,
|
|
|
|
'N/A' if len(sheet_properties) == 0 else
|
|
|
|
' '.join(str(k) + '=' + repr(v) for (k, v) in sheet_properties))
|
|
|
|
|
|
|
|
sheet.row(2).height = 800
|
2013-06-14 18:53:02 +08:00
|
|
|
sheet.panes_frozen = True
|
|
|
|
sheet.remove_splits = True
|
|
|
|
|
|
|
|
sheet_comparisons = sheet_conf.get('comparisons', [])
|
|
|
|
|
2013-07-10 18:50:51 +08:00
|
|
|
row = 2
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-07-10 18:50:51 +08:00
|
|
|
col = 0
|
2013-06-14 18:53:02 +08:00
|
|
|
|
2013-07-10 18:50:51 +08:00
|
|
|
for (w, caption) in [
|
|
|
|
(2500, 'Module'),
|
|
|
|
(10000, 'Test'),
|
2013-08-07 17:43:03 +08:00
|
|
|
(2000, 'Image\nwidth'),
|
|
|
|
(2000, 'Image\nheight'),
|
2013-07-10 18:50:51 +08:00
|
|
|
(2000, 'Data\ntype'),
|
|
|
|
(7500, 'Other parameters')]:
|
|
|
|
sheet.col(col).width = w
|
|
|
|
if args.show_times_per_pixel:
|
|
|
|
sheet.write_merge(row, row + 1, col, col, caption, header_style)
|
|
|
|
else:
|
|
|
|
sheet.write(row, col, caption, header_style)
|
|
|
|
col += 1
|
|
|
|
|
|
|
|
for config_name in config_names:
|
|
|
|
if args.show_times_per_pixel:
|
|
|
|
sheet.col(col).width = 3000
|
|
|
|
sheet.col(col + 1).width = 3000
|
|
|
|
sheet.write_merge(row, row, col, col + 1, config_name, header_style)
|
|
|
|
sheet.write(row + 1, col, 'total, ms', subheader_style)
|
|
|
|
sheet.write(row + 1, col + 1, 'per pixel, ns', subheader_style)
|
|
|
|
col += 2
|
|
|
|
else:
|
|
|
|
sheet.col(col).width = 4000
|
|
|
|
sheet.write(row, col, config_name, header_style)
|
|
|
|
col += 1
|
|
|
|
|
|
|
|
col += 1 # blank column between configurations and comparisons
|
|
|
|
|
|
|
|
for comp in sheet_comparisons:
|
|
|
|
sheet.col(col).width = 4000
|
|
|
|
caption = comp['to'] + '\nvs\n' + comp['from']
|
|
|
|
if args.show_times_per_pixel:
|
|
|
|
sheet.write_merge(row, row + 1, col, col, caption, header_style)
|
|
|
|
else:
|
|
|
|
sheet.write(row, col, caption, header_style)
|
2013-07-22 16:48:43 +08:00
|
|
|
col += 1
|
2013-07-10 18:50:51 +08:00
|
|
|
|
|
|
|
row += 2 if args.show_times_per_pixel else 1
|
|
|
|
|
|
|
|
sheet.horz_split_pos = row
|
|
|
|
sheet.horz_split_first_visible = row
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
module_colors = sheet_conf.get('module_colors', {})
|
|
|
|
module_styles = {module: xlwt.easyxf('pattern: pattern solid, fore_color {}'.format(color))
|
|
|
|
for module, color in module_colors.iteritems()}
|
|
|
|
|
2013-06-20 23:34:32 +08:00
|
|
|
for module, tests in sorted(collector.tests.iteritems()):
|
2013-07-04 22:52:10 +08:00
|
|
|
for ((test, param), configs) in sorted(tests.iteritems()):
|
2013-06-18 17:36:20 +08:00
|
|
|
sheet.write(row, 0, module, module_styles.get(module, xlwt.Style.default_style))
|
|
|
|
sheet.write(row, 1, test)
|
|
|
|
|
2013-07-05 22:41:03 +08:00
|
|
|
param_list = param[1:-1].split(', ') if param.startswith('(') and param.endswith(')') else [param]
|
2013-06-18 17:36:20 +08:00
|
|
|
|
2013-07-05 22:41:03 +08:00
|
|
|
image_size = next(ifilter(re_image_size.match, param_list), None)
|
|
|
|
if image_size is not None:
|
2013-08-07 17:43:03 +08:00
|
|
|
(image_width, image_height) = map(int, image_size.split('x', 1))
|
|
|
|
sheet.write(row, 2, image_width)
|
|
|
|
sheet.write(row, 3, image_height)
|
2013-07-05 22:41:03 +08:00
|
|
|
del param_list[param_list.index(image_size)]
|
|
|
|
|
|
|
|
data_type = next(ifilter(re_data_type.match, param_list), None)
|
|
|
|
if data_type is not None:
|
2013-08-07 17:43:03 +08:00
|
|
|
sheet.write(row, 4, data_type)
|
2013-07-05 22:41:03 +08:00
|
|
|
del param_list[param_list.index(data_type)]
|
|
|
|
|
2013-08-07 17:43:03 +08:00
|
|
|
sheet.row(row).write(5, ' | '.join(param_list))
|
2013-07-10 18:50:51 +08:00
|
|
|
|
2013-08-07 17:43:03 +08:00
|
|
|
col = 6
|
2013-07-10 18:50:51 +08:00
|
|
|
|
|
|
|
for c in config_names:
|
2013-06-18 17:36:20 +08:00
|
|
|
if c in configs:
|
2014-02-17 21:01:23 +08:00
|
|
|
sheet.write(row, col, configs[c], style_dict.get(configs[c], time_style))
|
2013-06-18 17:36:20 +08:00
|
|
|
else:
|
2013-07-10 18:50:51 +08:00
|
|
|
sheet.write(row, col, None, no_time_style)
|
|
|
|
col += 1
|
|
|
|
if args.show_times_per_pixel:
|
|
|
|
sheet.write(row, col,
|
2013-08-07 17:43:03 +08:00
|
|
|
xlwt.Formula('{0} * 1000000 / ({1} * {2})'.format(
|
2013-07-10 18:50:51 +08:00
|
|
|
xlwt.Utils.rowcol_to_cell(row, col - 1),
|
2013-08-07 17:43:03 +08:00
|
|
|
xlwt.Utils.rowcol_to_cell(row, 2),
|
|
|
|
xlwt.Utils.rowcol_to_cell(row, 3)
|
|
|
|
)),
|
|
|
|
time_style
|
|
|
|
)
|
2013-07-10 18:50:51 +08:00
|
|
|
col += 1
|
|
|
|
|
|
|
|
col += 1 # blank column
|
|
|
|
|
|
|
|
for comp in sheet_comparisons:
|
2013-06-20 18:27:51 +08:00
|
|
|
cmp_from = configs.get(comp["from"])
|
|
|
|
cmp_to = configs.get(comp["to"])
|
2013-06-18 17:36:20 +08:00
|
|
|
|
2013-06-20 18:27:51 +08:00
|
|
|
if isinstance(cmp_from, numbers.Number) and isinstance(cmp_to, numbers.Number):
|
2013-06-18 17:36:20 +08:00
|
|
|
try:
|
2013-06-20 18:27:51 +08:00
|
|
|
speedup = cmp_from / cmp_to
|
2013-06-18 17:36:20 +08:00
|
|
|
sheet.write(row, col, speedup, good_speedup_style if speedup > 1.1 else
|
|
|
|
bad_speedup_style if speedup < 0.9 else
|
|
|
|
speedup_style)
|
|
|
|
except ArithmeticError as e:
|
|
|
|
sheet.write(row, col, None, error_speedup_style)
|
|
|
|
else:
|
|
|
|
sheet.write(row, col, None, no_speedup_style)
|
|
|
|
|
2013-07-10 18:50:51 +08:00
|
|
|
col += 1
|
|
|
|
|
2013-06-18 17:36:20 +08:00
|
|
|
row += 1
|
|
|
|
if row % 1000 == 0: sheet.flush_row_data()
|
2013-06-14 18:53:02 +08:00
|
|
|
|
|
|
|
wb.save(args.output)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|