| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import re | |
| 6 | |
| 7 | |
| 8 def _EscapePerfResult(s): | |
| 9 """Escapes |s| for use in a perf result.""" | |
| 10 # Colons (:) and equal signs (=) are not allowed, and we chose an arbitrary | |
| 11 # limit of 40 chars. | |
| 12 return re.sub(':|=', '_', s[:40]) | |
| 13 | |
| 14 | |
| 15 def PrintPerfResult(measurement, trace, values, units, important=True, | |
| 16 print_to_stdout=True): | |
| 17 """Prints numerical data to stdout in the format required by perf tests. | |
| 18 | |
| 19 The string args may be empty but they must not contain any colons (:) or | |
| 20 equals signs (=). | |
| 21 | |
| 22 Args: | |
| 23 measurement: A description of the quantity being measured, e.g. "vm_peak". | |
| 24 trace: A description of the particular data point, e.g. "reference". | |
| 25 values: A list of numeric measured values. | |
| 26 units: A description of the units of measure, e.g. "bytes". | |
| 27 important: If True, the output line will be specially marked, to notify the | |
| 28 post-processor. | |
| 29 | |
| 30 Returns: | |
| 31 String of the formated perf result. | |
| 32 """ | |
| 33 important_marker = '*' if important else '' | |
| 34 | |
| 35 assert isinstance(values, list) | |
| 36 assert len(values) | |
| 37 assert '/' not in measurement | |
| 38 avg = None | |
| 39 if len(values) > 1: | |
| 40 try: | |
| 41 value = '[%s]' % ','.join([str(v) for v in values]) | |
| 42 avg = sum([float(v) for v in values]) / len(values) | |
| 43 except ValueError: | |
| 44 value = ", ".join(values) | |
| 45 else: | |
| 46 value = values[0] | |
| 47 | |
| 48 output = '%sRESULT %s: %s= %s %s' % (important_marker, | |
| 49 _EscapePerfResult(measurement), | |
| 50 _EscapePerfResult(trace), | |
| 51 value, units) | |
| 52 if avg: | |
| 53 output += '\nAvg %s: %d%s' % (measurement, avg, units) | |
| 54 if print_to_stdout: | |
| 55 print output | |
| 56 return output | |
| OLD | NEW |