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

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

Issue 17390017: Allow for lists of lists when summarizing performance results (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix inconsistent plural in comment Created 7 years, 6 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 | « 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 import sys 6 import sys
7 7
8 import android_commands 8 import android_commands
9 import json 9 import json
10 import logging 10 import logging
11 import math 11 import math
12 12
13 # Valid values of result type. 13 # Valid values of result type.
14 RESULT_TYPES = {'unimportant': 'RESULT ', 14 RESULT_TYPES = {'unimportant': 'RESULT ',
15 'default': '*RESULT ', 15 'default': '*RESULT ',
16 'informational': '', 16 'informational': '',
17 'unimportant-histogram': 'HISTOGRAM ', 17 'unimportant-histogram': 'HISTOGRAM ',
18 'histogram': '*HISTOGRAM '} 18 'histogram': '*HISTOGRAM '}
19 19
20 20
21 def _EscapePerfResult(s): 21 def _EscapePerfResult(s):
22 """Escapes |s| for use in a perf result.""" 22 """Escapes |s| for use in a perf result."""
23 return re.sub('[\:|=/#&,]', '_', s) 23 return re.sub('[\:|=/#&,]', '_', s)
24 24
25 25
26 def _Flatten(values):
27 """Returns a simple list without sub-lists."""
28 ret = []
29 for entry in values:
30 if isinstance(entry, list):
31 ret.extend(_Flatten(entry))
32 else:
33 ret.append(entry)
34 return ret
35
36
26 def GeomMeanAndStdDevFromHistogram(histogram_json): 37 def GeomMeanAndStdDevFromHistogram(histogram_json):
27 histogram = json.loads(histogram_json) 38 histogram = json.loads(histogram_json)
28 # Handle empty histograms gracefully. 39 # Handle empty histograms gracefully.
29 if not 'buckets' in histogram: 40 if not 'buckets' in histogram:
30 return 0.0, 0.0 41 return 0.0, 0.0
31 count = 0 42 count = 0
32 sum_of_logs = 0 43 sum_of_logs = 0
33 for bucket in histogram['buckets']: 44 for bucket in histogram['buckets']:
34 if 'high' in bucket: 45 if 'high' in bucket:
35 bucket['mean'] = (bucket['low'] + bucket['high']) / 2.0 46 bucket['mean'] = (bucket['low'] + bucket['high']) / 2.0
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 def PrintPerfResult(measurement, trace, values, units, result_type='default', 86 def PrintPerfResult(measurement, trace, values, units, result_type='default',
76 print_to_stdout=True): 87 print_to_stdout=True):
77 """Prints numerical data to stdout in the format required by perf tests. 88 """Prints numerical data to stdout in the format required by perf tests.
78 89
79 The string args may be empty but they must not contain any colons (:) or 90 The string args may be empty but they must not contain any colons (:) or
80 equals signs (=). 91 equals signs (=).
81 92
82 Args: 93 Args:
83 measurement: A description of the quantity being measured, e.g. "vm_peak". 94 measurement: A description of the quantity being measured, e.g. "vm_peak".
84 trace: A description of the particular data point, e.g. "reference". 95 trace: A description of the particular data point, e.g. "reference".
85 values: A list of numeric measured values. 96 values: A list of numeric measured values. An N-dimensional list will be
97 flattened and treated as a simple list.
86 units: A description of the units of measure, e.g. "bytes". 98 units: A description of the units of measure, e.g. "bytes".
87 result_type: Accepts values of RESULT_TYPES. 99 result_type: Accepts values of RESULT_TYPES.
88 print_to_stdout: If True, prints the output in stdout instead of returning 100 print_to_stdout: If True, prints the output in stdout instead of returning
89 the output to caller. 101 the output to caller.
90 102
91 Returns: 103 Returns:
92 String of the formated perf result. 104 String of the formated perf result.
93 """ 105 """
94 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type 106 assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type
95 107
96 trace_name = _EscapePerfResult(trace) 108 trace_name = _EscapePerfResult(trace)
97 109
98 if result_type in ['unimportant', 'default', 'informational']: 110 if result_type in ['unimportant', 'default', 'informational']:
99 assert isinstance(values, list) 111 assert isinstance(values, list)
100 assert len(values) 112 assert len(values)
101 assert '/' not in measurement 113 assert '/' not in measurement
102 value, avg, sd = _MeanAndStdDevFromList(values) 114 value, avg, sd = _MeanAndStdDevFromList(_Flatten(values))
103 output = '%s%s: %s%s%s %s' % ( 115 output = '%s%s: %s%s%s %s' % (
104 RESULT_TYPES[result_type], 116 RESULT_TYPES[result_type],
105 _EscapePerfResult(measurement), 117 _EscapePerfResult(measurement),
106 trace_name, 118 trace_name,
107 # Do not show equal sign if the trace is empty. Usually it happens when 119 # Do not show equal sign if the trace is empty. Usually it happens when
108 # measurement is enough clear to describe the result. 120 # measurement is enough clear to describe the result.
109 '= ' if trace_name else '', 121 '= ' if trace_name else '',
110 value, 122 value,
111 units) 123 units)
112 else: 124 else:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 """Resets the original performance mode of the device.""" 193 """Resets the original performance mode of the device."""
182 self._SetScalingGovernorInternal(self._original_scaling_governor) 194 self._SetScalingGovernorInternal(self._original_scaling_governor)
183 195
184 def _SetScalingGovernorInternal(self, value): 196 def _SetScalingGovernorInternal(self, value):
185 for cpu in range(self._kernel_max + 1): 197 for cpu in range(self._kernel_max + 1):
186 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu 198 scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu
187 if self._adb.FileExistsOnDevice(scaling_governor_file): 199 if self._adb.FileExistsOnDevice(scaling_governor_file):
188 logging.info('Writing scaling governor mode \'%s\' -> %s' % 200 logging.info('Writing scaling governor mode \'%s\' -> %s' %
189 (value, scaling_governor_file)) 201 (value, scaling_governor_file))
190 self._adb.SetProtectedFileContents(scaling_governor_file, value) 202 self._adb.SetProtectedFileContents(scaling_governor_file, value)
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