2016-09-19 18:03:58 +00:00
|
|
|
# Copyright 2016 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2016-09-23 18:36:11 +00:00
|
|
|
"""Parses an skpbench result from a line of output text."""
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
class BenchResult:
|
|
|
|
FLOAT_REGEX = '[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?'
|
2016-09-29 13:23:23 +00:00
|
|
|
PATTERN = re.compile('^(?P<accum_pad> *)'
|
2016-09-19 18:03:58 +00:00
|
|
|
'(?P<accum>' + FLOAT_REGEX + ')'
|
2016-09-29 13:23:23 +00:00
|
|
|
'(?P<median_pad> +)'
|
|
|
|
'(?P<median>' + FLOAT_REGEX + ')'
|
2016-09-19 18:03:58 +00:00
|
|
|
'(?P<max_pad> +)'
|
|
|
|
'(?P<max>' + FLOAT_REGEX + ')'
|
|
|
|
'(?P<min_pad> +)'
|
|
|
|
'(?P<min>' + FLOAT_REGEX + ')'
|
|
|
|
'(?P<stddev_pad> +)'
|
|
|
|
'(?P<stddev>' + FLOAT_REGEX + '%)'
|
|
|
|
'(?P<samples_pad> +)'
|
|
|
|
'(?P<samples>\d+)'
|
|
|
|
'(?P<sample_ms_pad> +)'
|
|
|
|
'(?P<sample_ms>\d+)'
|
2016-10-05 15:42:03 +00:00
|
|
|
'(?P<clock_pad> +)'
|
|
|
|
'(?P<clock>[cg]pu)'
|
2016-09-29 13:23:23 +00:00
|
|
|
'(?P<metric_pad> +)'
|
|
|
|
'(?P<metric>ms|fps)'
|
2016-09-19 18:03:58 +00:00
|
|
|
'(?P<config_pad> +)'
|
|
|
|
'(?P<config>[^\s]+)'
|
|
|
|
'(?P<bench_pad> +)'
|
|
|
|
'(?P<bench>[^\s]+)$')
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def match(cls, text):
|
|
|
|
match = cls.PATTERN.search(text)
|
|
|
|
return cls(match) if match else None
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
self.accum = float(match.group('accum'))
|
2016-09-29 13:23:23 +00:00
|
|
|
self.median = float(match.group('median'))
|
2016-09-19 18:03:58 +00:00
|
|
|
self.max = float(match.group('max'))
|
|
|
|
self.min = float(match.group('min'))
|
|
|
|
self.stddev = float(match.group('stddev')[:-1]) # Drop '%' sign.
|
|
|
|
self.samples = int(match.group('samples'))
|
|
|
|
self.sample_ms = int(match.group('sample_ms'))
|
2016-10-05 15:42:03 +00:00
|
|
|
self.clock = match.group('clock')
|
2016-09-29 13:23:23 +00:00
|
|
|
self.metric = match.group('metric')
|
2016-09-19 18:03:58 +00:00
|
|
|
self.config = match.group('config')
|
|
|
|
self.bench = match.group('bench')
|
|
|
|
self._match = match
|
|
|
|
|
|
|
|
def get_string(self, name):
|
|
|
|
return self._match.group(name)
|
|
|
|
|
2016-11-10 15:36:28 +00:00
|
|
|
def format(self, config_suffix=None):
|
2016-09-19 18:03:58 +00:00
|
|
|
if not config_suffix or config_suffix == '':
|
2016-11-10 15:36:28 +00:00
|
|
|
return self._match.group(0)
|
2016-09-19 18:03:58 +00:00
|
|
|
else:
|
|
|
|
values = list()
|
2016-09-29 13:23:23 +00:00
|
|
|
for name in ['accum', 'median', 'max', 'min', 'stddev',
|
2016-10-05 15:42:03 +00:00
|
|
|
'samples', 'sample_ms', 'clock', 'metric', 'config']:
|
2016-09-19 18:03:58 +00:00
|
|
|
values.append(self.get_string(name + '_pad'))
|
|
|
|
values.append(self.get_string(name))
|
|
|
|
values.append(config_suffix)
|
|
|
|
bench_pad = self.get_string('bench_pad')
|
|
|
|
values.append(bench_pad[min(len(config_suffix), len(bench_pad) - 1):])
|
|
|
|
values.append(self.get_string('bench'))
|
2016-11-10 15:36:28 +00:00
|
|
|
return ''.join(values)
|