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

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

Issue 11413144: Fix histogram printing for Telemetry tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 | « no previous file | no next file » | 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 import android_commands 7 import android_commands
8 import json 8 import json
9 import math 9 import math
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 try: 54 try:
55 value = '[%s]' % ','.join([str(v) for v in values]) 55 value = '[%s]' % ','.join([str(v) for v in values])
56 avg = sum([float(v) for v in values]) / len(values) 56 avg = sum([float(v) for v in values]) / len(values)
57 sqdiffs = [(float(v) - avg) ** 2 for v in values] 57 sqdiffs = [(float(v) - avg) ** 2 for v in values]
58 variance = sum(sqdiffs) / (len(values) - 1) 58 variance = sum(sqdiffs) / (len(values) - 1)
59 sd = math.sqrt(variance) 59 sd = math.sqrt(variance)
60 except ValueError: 60 except ValueError:
61 value = ", ".join(values) 61 value = ", ".join(values)
62 else: 62 else:
63 value = values[0] 63 value = values[0]
64 avg = values[0]
64 return value, avg, sd 65 return value, avg, sd
65 66
66 67
67 def PrintPerfResult(measurement, trace, values, units, result_type='default', 68 def PrintPerfResult(measurement, trace, values, units, result_type='default',
68 print_to_stdout=True): 69 print_to_stdout=True):
69 """Prints numerical data to stdout in the format required by perf tests. 70 """Prints numerical data to stdout in the format required by perf tests.
70 71
71 The string args may be empty but they must not contain any colons (:) or 72 The string args may be empty but they must not contain any colons (:) or
72 equals signs (=). 73 equals signs (=).
73 74
74 Args: 75 Args:
75 measurement: A description of the quantity being measured, e.g. "vm_peak". 76 measurement: A description of the quantity being measured, e.g. "vm_peak".
76 trace: A description of the particular data point, e.g. "reference". 77 trace: A description of the particular data point, e.g. "reference".
77 values: A list of numeric measured values. 78 values: A list of numeric measured values.
78 units: A description of the units of measure, e.g. "bytes". 79 units: A description of the units of measure, e.g. "bytes".
79 result_type: A tri-state that accepts values of ['unimportant', 'default', 80 result_type: A tri-state that accepts values of ['unimportant', 'default',
bulach 2012/11/22 18:21:59 nit: only noticed now, but it needs updating :)
marja 2012/11/23 09:08:33 Done.
80 'informational']. 'unimportant' prints RESULT, 'default' prints *RESULT 81 'informational']. 'unimportant' prints RESULT, 'default' prints *RESULT
81 and 'informational' prints nothing. 82 and 'informational' prints nothing.
82 print_to_stdout: If True, prints the output in stdout instead of returning 83 print_to_stdout: If True, prints the output in stdout instead of returning
83 the output to caller. 84 the output to caller.
84 85
85 Returns: 86 Returns:
86 String of the formated perf result. 87 String of the formated perf result.
87 """ 88 """
88 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type 89 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type
89 90
90 if result_type in ['unimportant', 'default', 'informational']: 91 trace_name = _EscapePerfResult(trace)
92 if result_type in ['histogram', 'unimportant-histogram']:
91 assert isinstance(values, list) 93 assert isinstance(values, list)
92 assert len(values) 94 assert len(values)
93 assert '/' not in measurement 95 # Print out each histogram separately. We can't print the units, otherwise
94 value, avg, sd = _MeanAndStdDevFromList(values) 96 # the histogram json output can't be parsed easily.
97 output = ''
98 ix = 1
99 for value in values:
100 name = '%s.%s_%d' % (_EscapePerfResult(measurement), trace_name, ix)
101 output += '%s%s%s : %s = %s' % (
102 '\n' if ix > 1 else '',
103 RESULT_TYPES[result_type],
104 name,
105 name,
106 value)
107 ix += 1
108 means_and_sds = [GeomMeanAndStdDevFromHistogram(value) for value in values]
109 print means_and_sds
110 _, avg, sd = _MeanAndStdDevFromList([mean for (mean, _) in means_and_sds ])
95 else: 111 else:
96 value = values[0] 112 if result_type in ['unimportant', 'default', 'informational']:
97 # We can't print the units, otherwise parsing the histogram json output 113 assert isinstance(values, list)
98 # can't be parsed easily. 114 assert len(values)
99 units = '' 115 assert '/' not in measurement
100 avg, sd = GeomMeanAndStdDevFromHistogram(value) 116 value, avg, sd = _MeanAndStdDevFromList(values)
101 117 else:
102 trace_name = _EscapePerfResult(trace) 118 value = values[0]
bulach 2012/11/22 18:21:59 nit: is this possible to reach this? my understand
marja 2012/11/23 09:08:33 Done. Yes, I had misinterpreted the association of
103 output = '%s%s: %s%s%s %s' % ( 119 output = '%s%s: %s%s%s %s' % (
104 RESULT_TYPES[result_type], 120 RESULT_TYPES[result_type],
105 _EscapePerfResult(measurement), 121 _EscapePerfResult(measurement),
106 trace_name, 122 trace_name,
107 # Do not show equal sign if the trace is empty. Usually it happens when 123 # Do not show equal sign if the trace is empty. Usually it happens when
108 # measurement is enough clear to describe the result. 124 # measurement is enough clear to describe the result.
109 '= ' if trace_name else '', 125 '= ' if trace_name else '',
110 value, 126 value,
111 units) 127 units)
112 if avg: 128 if avg:
113 output += '\nAvg %s: %f%s' % (measurement, avg, units) 129 output += '\nAvg %s: %f%s' % (measurement, avg, units)
114 if sd: 130 if sd:
115 output += '\nSd %s: %f%s' % (measurement, sd, units) 131 output += '\nSd %s: %f%s' % (measurement, sd, units)
116 if print_to_stdout: 132 if print_to_stdout:
117 print output 133 print output
118 return output 134 return output
119 135
120 136
121 class PerfTestSetup(object): 137 class PerfTestSetup(object):
(...skipping 28 matching lines...) Expand all
150 def TearDown(self): 166 def TearDown(self):
151 """Tears down performance tests.""" 167 """Tears down performance tests."""
152 if self._original_scaling_governor: 168 if self._original_scaling_governor:
153 self._SetScalingGovernorInternal(self._original_scaling_governor) 169 self._SetScalingGovernorInternal(self._original_scaling_governor)
154 self._original_scaling_governor = None 170 self._original_scaling_governor = None
155 171
156 def _SetScalingGovernorInternal(self, value): 172 def _SetScalingGovernorInternal(self, value):
157 for cpu in range(self._num_cpus): 173 for cpu in range(self._num_cpus):
158 self._adb.RunShellCommand( 174 self._adb.RunShellCommand(
159 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) 175 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698