aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skpbench/skiaperf.py
diff options
context:
space:
mode:
authorGravatar Kevin Lubick <kjlubick@google.com>2016-11-10 14:19:00 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-10 20:00:56 +0000
commit9c2249f51c861f3d0db089fbba38b8ac1d63d160 (patch)
tree5a828c25ad3e8a557afb47ecc8ac507fe56fdc1d /tools/skpbench/skiaperf.py
parent399bbd96ac1b68caf91635e2eb4fdbbb30baef3c (diff)
skpbench: add utility to format results for Skia Perf
Adds skiaperf.py for formatting skpbench.py outputs for Skia Perf. Also renames parseskpbench.py to sheet.py. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4657 Change-Id: I758678e1c589b15ec2d07c43e4921663e919b47b Reviewed-on: https://skia-review.googlesource.com/4657 Commit-Queue: Kevin Lubick <kjlubick@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
Diffstat (limited to 'tools/skpbench/skiaperf.py')
-rwxr-xr-xtools/skpbench/skiaperf.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/skpbench/skiaperf.py b/tools/skpbench/skiaperf.py
new file mode 100755
index 0000000000..cfbd49d6c1
--- /dev/null
+++ b/tools/skpbench/skiaperf.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from __future__ import print_function
+from _benchresult import BenchResult
+from argparse import ArgumentTypeError, ArgumentParser
+from collections import defaultdict
+import json
+import sys
+
+__argparse = ArgumentParser(description="""
+
+Formats skpbench.py outputs for Skia Perf.
+
+""")
+
+__argparse.add_argument('sources',
+ nargs='+', help="source files that contain skpbench results")
+__argparse.add_argument('--properties',
+ nargs='*', default=list(),
+ help="space-separated key/value pairs identifying the run")
+__argparse.add_argument('--key',
+ nargs='*', default=list(),
+ help="space-separated key/value pairs identifying the builder")
+__argparse.add_argument('-o', '--outfile',
+ default='-', help="output file ('-' for stdout)")
+
+FLAGS = __argparse.parse_args()
+
+def parse_key_value_pairs(args):
+ if not args:
+ return dict()
+ if len(args) % 2:
+ raise ArgumentTypeError("uneven number of key/value arguments.")
+ return {k:v for k,v in zip(args[::2], args[1::2])}
+
+def skiaperf_result(benchresult):
+ result = {x:benchresult.get_string(x) for x in ('accum', 'median')}
+ result['options'] = {x:benchresult.get_string(x)
+ for x in ('clock', 'metric', 'sample_ms')}
+ return result
+
+def emit_as_json(data, outfile):
+ json.dump(data, outfile, indent=4, separators=(',', ' : '), sort_keys=True)
+ print('', file=outfile)
+
+def main():
+ data = parse_key_value_pairs(
+ FLAGS.properties + [
+ 'key', parse_key_value_pairs(FLAGS.key),
+ 'results', defaultdict(dict)])
+
+ for src in FLAGS.sources:
+ with open(src, mode='r') as infile:
+ for line in infile:
+ match = BenchResult.match(line)
+ if match:
+ data['results'][match.bench][match.config] = skiaperf_result(match)
+
+ if FLAGS.outfile != '-':
+ with open(FLAGS.outfile, 'w+') as outfile:
+ emit_as_json(data, outfile)
+ else:
+ emit_as_json(data, sys.stdout)
+
+if __name__ == '__main__':
+ main()