diff options
author | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 20:32:49 +0000 |
---|---|---|
committer | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 20:32:49 +0000 |
commit | 5032bd16100e6e97fbc4287b33354856995c38dc (patch) | |
tree | 71c42d7f416f2581fa5ddf0214ce688b0c9042c1 /build/android/perf_tests_helper.py | |
parent | 668647aaf2deb9cad425602a99613470e5917b76 (diff) | |
download | chromium_src-5032bd16100e6e97fbc4287b33354856995c38dc.zip chromium_src-5032bd16100e6e97fbc4287b33354856995c38dc.tar.gz chromium_src-5032bd16100e6e97fbc4287b33354856995c38dc.tar.bz2 |
Upstream: Android Test scripts (phase 3)
BUG=
TEST=
Review URL: http://codereview.chromium.org/8383020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/perf_tests_helper.py')
-rw-r--r-- | build/android/perf_tests_helper.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/build/android/perf_tests_helper.py b/build/android/perf_tests_helper.py new file mode 100644 index 0000000..39bf587 --- /dev/null +++ b/build/android/perf_tests_helper.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import re + + +def _EscapePerfResult(s): + """Escapes |s| for use in a perf result.""" + # Colons (:) and equal signs (=) are not allowed, and we chose an arbitrary + # limit of 40 chars. + return re.sub(':|=', '_', s[:40]) + + +def PrintPerfResult(measurement, trace, values, units, important=True, + print_to_stdout=True): + """Prints numerical data to stdout in the format required by perf tests. + + The string args may be empty but they must not contain any colons (:) or + equals signs (=). + + Args: + measurement: A description of the quantity being measured, e.g. "vm_peak". + trace: A description of the particular data point, e.g. "reference". + values: A list of numeric measured values. + units: A description of the units of measure, e.g. "bytes". + important: If True, the output line will be specially marked, to notify the + post-processor. + + Returns: + String of the formated perf result. + """ + important_marker = '*' if important else '' + + assert isinstance(values, list) + assert len(values) + assert '/' not in measurement + avg = None + if len(values) > 1: + try: + value = '[%s]' % ','.join([str(v) for v in values]) + avg = sum([float(v) for v in values]) / len(values) + except ValueError: + value = ", ".join(values) + else: + value = values[0] + + output = '%sRESULT %s: %s= %s %s' % (important_marker, + _EscapePerfResult(measurement), + _EscapePerfResult(trace), + value, units) + if avg: + output += '\nAvg %s: %d%s' % (measurement, avg, units) + if print_to_stdout: + print output + return output |