8from __future__
import print_function
9from _benchresult
import BenchResult
10from argparse
import ArgumentParser
11from collections
import defaultdict, namedtuple
12from datetime
import datetime
21__argparse = ArgumentParser(description=
"""
23Formats skpbench.py outputs as csv.
25This script can also be used to generate a Google sheet:
27(1) Install the "Office Editing for Docs, Sheets & Slides" Chrome extension:
28 https://chrome.google.com/webstore/detail/office-editing-for-docs-s/gbkeegbaiigmenfmjfclcdgdpimamgkj
30(2) Update your global OS file associations to use Chrome for .csv files.
32(3) Run parseskpbench.py with the --open flag.
36__argparse.add_argument(
'-r',
'--result',
37 choices=[
'accum',
'median',
'max',
'min'], default=
'accum',
38 help=
"result to use for cell values")
39__argparse.add_argument(
'-f',
'--force',
40 action=
'store_true', help=
'silently ignore warnings')
41__argparse.add_argument(
'-o',
'--open',
43 help=
"generate a temp file and open it (theoretically in a web browser)")
44__argparse.add_argument(
'-n',
'--name',
45 default=
'skpbench_%s' % datetime.now().strftime(
'%Y-%m-%d_%H.%M.%S.csv'),
46 help=
"if using --open, a name for the temp file")
47__argparse.add_argument(
'sources',
48 nargs=
'+', help=
"source files that contain skpbench results ('-' for stdin)")
50FLAGS = __argparse.parse_args()
52RESULT_QUALIFIERS = (
'sample_ms',
'clock',
'metric')
54class FullConfig(namedtuple(
'fullconfig', (
'config',) + RESULT_QUALIFIERS)):
57 {x:getattr(self, x)
for x
in qualifiers})
63 args = (
'%s=%s' % (k,v)
for k,v
in qualifiers.iteritems())
64 return '%s (%s)' % (name,
' '.join(args))
71 self.
rows = defaultdict(dict)
72 self.
cols = defaultdict(dict)
76 match = BenchResult.match(line)
81 for x
in FullConfig._fields))
88 elif value != match.get_string(qualifier):
92 self.
rows[match.bench][fullconfig] = match.get_string(FLAGS.result)
93 self.
cols[fullconfig][match.bench] = getattr(match, FLAGS.result)
100 outfile.write(
'bench,')
106 for bench, row
in self.
rows.iteritems():
107 outfile.write(
'%s,' % bench)
109 if fullconfig
in row:
110 outfile.write(
'%s,' % row[fullconfig])
112 outfile.write(
'NULL,')
114 raise ValueError(
"%s: missing value for %s. (use --force to ignore)" %
120 if len(self.
rows) > 1:
123 lambda col: reduce(operator.add, col.values()) / len(col),
126 lambda col: reduce(operator.mul, col.values()) ** (1.0 / len(col)),
130 outfile.write(
'%s,' % name)
132 if len(self.
cols[fullconfig]) != len(self.
rows):
133 outfile.write(
'NULL,')
135 outfile.write(
'%.4g,' % func(self.
cols[fullconfig]))
142 for src
in FLAGS.sources:
144 parser.parse_file(sys.stdin)
146 with open(src, mode=
'r')
as infile:
147 parser.parse_file(infile)
153 dirname = tempfile.mkdtemp()
154 basename = FLAGS.name
155 if os.path.splitext(basename)[1] !=
'.csv':
157 pathname = os.path.join(dirname, basename)
158 with open(pathname, mode=
'w')
as tmpfile:
159 parser.print_csv(outfile=tmpfile)
160 fileuri = urlparse.urljoin(
'file:', urllib.pathname2url(pathname))
161 print(
'opening %s' % fileuri)
162 webbrowser.open(fileuri)
165if __name__ ==
'__main__':
static void append(char **dst, size_t *count, const char *src, size_t n)