Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: build/android/pylib/perf_tests_helper.py

Issue 10689132: [android] Upstream / sync most of build/android and build/android/pylib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/io_stats_parser.py ('k') | build/android/pylib/ports.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import re 5 import re
6 6
7 7
8 # Valid values of result type.
9 RESULT_TYPES = {'unimportant': 'RESULT ',
10 'default': '*RESULT ',
11 'informational': ''}
12
13
8 def _EscapePerfResult(s): 14 def _EscapePerfResult(s):
9 """Escapes |s| for use in a perf result.""" 15 """Escapes |s| for use in a perf result."""
10 # Colons (:) and equal signs (=) are not allowed, and we chose an arbitrary 16 # Colons (:) and equal signs (=) are not allowed, and we chose an arbitrary
11 # limit of 40 chars. 17 # limit of 40 chars.
12 return re.sub(':|=', '_', s[:40]) 18 return re.sub(':|=', '_', s[:40])
13 19
14 20
15 def PrintPerfResult(measurement, trace, values, units, important=True, 21 def PrintPerfResult(measurement, trace, values, units, result_type='default',
16 print_to_stdout=True): 22 print_to_stdout=True):
17 """Prints numerical data to stdout in the format required by perf tests. 23 """Prints numerical data to stdout in the format required by perf tests.
18 24
19 The string args may be empty but they must not contain any colons (:) or 25 The string args may be empty but they must not contain any colons (:) or
20 equals signs (=). 26 equals signs (=).
21 27
22 Args: 28 Args:
23 measurement: A description of the quantity being measured, e.g. "vm_peak". 29 measurement: A description of the quantity being measured, e.g. "vm_peak".
24 trace: A description of the particular data point, e.g. "reference". 30 trace: A description of the particular data point, e.g. "reference".
25 values: A list of numeric measured values. 31 values: A list of numeric measured values.
26 units: A description of the units of measure, e.g. "bytes". 32 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 33 result_type: A tri-state that accepts values of ['unimportant', 'default',
28 post-processor. 34 'informational']. 'unimportant' prints RESULT, 'default' prints *RESULT
35 and 'informational' prints nothing.
36 print_to_stdout: If True, prints the output in stdout instead of returning
37 the output to caller.
29 38
30 Returns: 39 Returns:
31 String of the formated perf result. 40 String of the formated perf result.
32 """ 41 """
33 important_marker = '*' if important else '' 42 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type
34 43
35 assert isinstance(values, list) 44 assert isinstance(values, list)
36 assert len(values) 45 assert len(values)
37 assert '/' not in measurement 46 assert '/' not in measurement
38 avg = None 47 avg = None
39 if len(values) > 1: 48 if len(values) > 1:
40 try: 49 try:
41 value = '[%s]' % ','.join([str(v) for v in values]) 50 value = '[%s]' % ','.join([str(v) for v in values])
42 avg = sum([float(v) for v in values]) / len(values) 51 avg = sum([float(v) for v in values]) / len(values)
43 except ValueError: 52 except ValueError:
44 value = ", ".join(values) 53 value = ", ".join(values)
45 else: 54 else:
46 value = values[0] 55 value = values[0]
47 56
48 output = '%sRESULT %s: %s= %s %s' % (important_marker, 57 trace_name = _EscapePerfResult(trace)
49 _EscapePerfResult(measurement), 58 output = '%s%s: %s%s%s %s' % (
50 _EscapePerfResult(trace), 59 RESULT_TYPES[result_type],
51 value, units) 60 _EscapePerfResult(measurement),
61 trace_name,
62 # Do not show equal sign if the trace is empty. Usually it happens when
63 # measurement is enough clear to describe the result.
64 '= ' if trace_name else '',
65 value,
66 units)
52 if avg: 67 if avg:
53 output += '\nAvg %s: %d%s' % (measurement, avg, units) 68 output += '\nAvg %s: %f%s' % (measurement, avg, units)
54 if print_to_stdout: 69 if print_to_stdout:
55 print output 70 print output
56 return output 71 return output
OLDNEW
« no previous file with comments | « build/android/pylib/io_stats_parser.py ('k') | build/android/pylib/ports.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698