skiaperf.py revision 9c2249f51c861f3d0db089fbba38b8ac1d63d160
1#!/usr/bin/env python 2 3# Copyright 2016 Google Inc. 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8from __future__ import print_function 9from _benchresult import BenchResult 10from argparse import ArgumentTypeError, ArgumentParser 11from collections import defaultdict 12import json 13import sys 14 15__argparse = ArgumentParser(description=""" 16 17Formats skpbench.py outputs for Skia Perf. 18 19""") 20 21__argparse.add_argument('sources', 22 nargs='+', help="source files that contain skpbench results") 23__argparse.add_argument('--properties', 24 nargs='*', default=list(), 25 help="space-separated key/value pairs identifying the run") 26__argparse.add_argument('--key', 27 nargs='*', default=list(), 28 help="space-separated key/value pairs identifying the builder") 29__argparse.add_argument('-o', '--outfile', 30 default='-', help="output file ('-' for stdout)") 31 32FLAGS = __argparse.parse_args() 33 34def parse_key_value_pairs(args): 35 if not args: 36 return dict() 37 if len(args) % 2: 38 raise ArgumentTypeError("uneven number of key/value arguments.") 39 return {k:v for k,v in zip(args[::2], args[1::2])} 40 41def skiaperf_result(benchresult): 42 result = {x:benchresult.get_string(x) for x in ('accum', 'median')} 43 result['options'] = {x:benchresult.get_string(x) 44 for x in ('clock', 'metric', 'sample_ms')} 45 return result 46 47def emit_as_json(data, outfile): 48 json.dump(data, outfile, indent=4, separators=(',', ' : '), sort_keys=True) 49 print('', file=outfile) 50 51def main(): 52 data = parse_key_value_pairs( 53 FLAGS.properties + [ 54 'key', parse_key_value_pairs(FLAGS.key), 55 'results', defaultdict(dict)]) 56 57 for src in FLAGS.sources: 58 with open(src, mode='r') as infile: 59 for line in infile: 60 match = BenchResult.match(line) 61 if match: 62 data['results'][match.bench][match.config] = skiaperf_result(match) 63 64 if FLAGS.outfile != '-': 65 with open(FLAGS.outfile, 'w+') as outfile: 66 emit_as_json(data, outfile) 67 else: 68 emit_as_json(data, sys.stdout) 69 70if __name__ == '__main__': 71 main() 72