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

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: Fixed Created 8 years 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: Accepts values of ['unimportant', 'default',
bulach 2012/11/23 10:09:53 ops, sorry, I didn't spot RESULT_TYPES before, so
marja 2012/11/23 10:36:03 Done.
80 'informational']. 'unimportant' prints RESULT, 'default' prints *RESULT 81 'informational', 'unimportant-histogram', 'histogram'].
81 and 'informational' prints nothing.
82 print_to_stdout: If True, prints the output in stdout instead of returning 82 print_to_stdout: If True, prints the output in stdout instead of returning
83 the output to caller. 83 the output to caller.
84 84
85 Returns: 85 Returns:
86 String of the formated perf result. 86 String of the formated perf result.
87 """ 87 """
88 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type 88 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type
89 89
90 trace_name = _EscapePerfResult(trace)
91
90 if result_type in ['unimportant', 'default', 'informational']: 92 if result_type in ['unimportant', 'default', 'informational']:
91 assert isinstance(values, list) 93 assert isinstance(values, list)
92 assert len(values) 94 assert len(values)
93 assert '/' not in measurement 95 assert '/' not in measurement
94 value, avg, sd = _MeanAndStdDevFromList(values) 96 value, avg, sd = _MeanAndStdDevFromList(values)
97 output = '%s%s: %s%s%s %s' % (
98 RESULT_TYPES[result_type],
99 _EscapePerfResult(measurement),
100 trace_name,
101 # Do not show equal sign if the trace is empty. Usually it happens when
102 # measurement is enough clear to describe the result.
103 '= ' if trace_name else '',
104 value,
105 units)
95 else: 106 else:
96 value = values[0] 107 assert(result_type in ['histogram', 'unimportant-histogram'])
97 # We can't print the units, otherwise parsing the histogram json output 108 assert isinstance(values, list)
98 # can't be parsed easily. 109 assert len(values)
99 units = '' 110 # Print out each histogram separately. We can't print the units, otherwise
100 avg, sd = GeomMeanAndStdDevFromHistogram(value) 111 # the histogram json output can't be parsed easily.
112 output = ''
113 ix = 1
114 for value in values:
115 name = '%s.%s_%d' % (_EscapePerfResult(measurement), trace_name, ix)
116 output += '%s%s%s : %s = %s' % (
117 '\n' if ix > 1 else '',
118 RESULT_TYPES[result_type],
119 name,
120 name,
121 value)
122 ix += 1
123 measurement = '%s.%s' % (measurement, trace_name)
124 means_and_sds = [GeomMeanAndStdDevFromHistogram(value) for value in values]
125 _, avg, sd = _MeanAndStdDevFromList([mean for (mean, _) in means_and_sds ])
101 126
102 trace_name = _EscapePerfResult(trace)
103 output = '%s%s: %s%s%s %s' % (
104 RESULT_TYPES[result_type],
105 _EscapePerfResult(measurement),
106 trace_name,
107 # Do not show equal sign if the trace is empty. Usually it happens when
108 # measurement is enough clear to describe the result.
109 '= ' if trace_name else '',
110 value,
111 units)
112 if avg: 127 if avg:
113 output += '\nAvg %s: %f%s' % (measurement, avg, units) 128 output += '\nAvg %s: %f%s' % (measurement, avg, units)
114 if sd: 129 if sd:
115 output += '\nSd %s: %f%s' % (measurement, sd, units) 130 output += '\nSd %s: %f%s' % (measurement, sd, units)
116 if print_to_stdout: 131 if print_to_stdout:
117 print output 132 print output
118 return output 133 return output
119 134
120 135
121 class PerfTestSetup(object): 136 class PerfTestSetup(object):
(...skipping 28 matching lines...) Expand all
150 def TearDown(self): 165 def TearDown(self):
151 """Tears down performance tests.""" 166 """Tears down performance tests."""
152 if self._original_scaling_governor: 167 if self._original_scaling_governor:
153 self._SetScalingGovernorInternal(self._original_scaling_governor) 168 self._SetScalingGovernorInternal(self._original_scaling_governor)
154 self._original_scaling_governor = None 169 self._original_scaling_governor = None
155 170
156 def _SetScalingGovernorInternal(self, value): 171 def _SetScalingGovernorInternal(self, value):
157 for cpu in range(self._num_cpus): 172 for cpu in range(self._num_cpus):
158 self._adb.RunShellCommand( 173 self._adb.RunShellCommand(
159 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) 174 ('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