diff options
-rwxr-xr-x | build/android/buildbot/bb_device_status_check.py | 21 | ||||
-rw-r--r-- | build/android/pylib/instrumentation/test_runner.py | 14 | ||||
-rw-r--r-- | build/android/pylib/perf_tests_helper.py | 160 | ||||
-rw-r--r-- | build/util/lib/common/perf_tests_results_helper.py | 5 | ||||
-rw-r--r-- | tools/telemetry/telemetry/page/perf_tests_helper.py | 11 |
5 files changed, 32 insertions, 179 deletions
diff --git a/build/android/buildbot/bb_device_status_check.py b/build/android/buildbot/bb_device_status_check.py index d0fdab2..a5ef54b3 100755 --- a/build/android/buildbot/bb_device_status_check.py +++ b/build/android/buildbot/bb_device_status_check.py @@ -15,10 +15,14 @@ import urllib import bb_annotations +sys.path.append(os.path.join(os.path.dirname(__file__), + os.pardir, os.pardir, 'util', 'lib', + 'common')) +import perf_tests_results_helper # pylint: disable=F0401 + sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from pylib import android_commands from pylib import constants -from pylib import perf_tests_helper from pylib.cmd_helper import GetCmdOutput @@ -244,14 +248,15 @@ def main(): SendDeviceStatusAlert(msg) if options.device_status_dashboard: - perf_tests_helper.PrintPerfResult('BotDevices', 'OnlineDevices', - [len(devices)], 'devices') - perf_tests_helper.PrintPerfResult('BotDevices', 'OfflineDevices', - [len(offline_devices)], 'devices', - 'unimportant') + perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', + [len(devices)], 'devices') + perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', + [len(offline_devices)], 'devices', + 'unimportant') for serial, battery in zip(devices, batteries): - perf_tests_helper.PrintPerfResult('DeviceBattery', serial, [battery], '%', - 'unimportant') + perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, + [battery], '%', + 'unimportant') if False in fail_step_lst: # TODO(navabi): Build fails on device status check step if there exists any diff --git a/build/android/pylib/instrumentation/test_runner.py b/build/android/pylib/instrumentation/test_runner.py index 21a5c45..74d25b1 100644 --- a/build/android/pylib/instrumentation/test_runner.py +++ b/build/android/pylib/instrumentation/test_runner.py @@ -7,12 +7,18 @@ import logging import os import re +import sys import time + +sys.path.append(os.path.join(sys.path[0], + os.pardir, os.pardir, 'build', 'util', 'lib', + 'common')) +import perf_tests_results_helper + from pylib import android_commands from pylib import constants from pylib import flag_changer -from pylib import perf_tests_helper from pylib import valgrind_tools from pylib.base import base_test_result from pylib.base import base_test_runner @@ -283,9 +289,9 @@ class TestRunner(base_test_runner.BaseTestRunner): # Process the performance data result = json_perf_parser.GetAverageRunInfoFromJSONString(json_string, perf_set[0]) - perf_tests_helper.PrintPerfResult(perf_set[1], perf_set[2], - [result['average']], - result['units']) + perf_tests_results_helper.PrintPerfResult(perf_set[1], perf_set[2], + [result['average']], + result['units']) def _SetupIndividualTestTimeoutScale(self, test): timeout_scale = self._GetIndividualTestTimeoutScale(test) diff --git a/build/android/pylib/perf_tests_helper.py b/build/android/pylib/perf_tests_helper.py deleted file mode 100644 index 93cabcd..0000000 --- a/build/android/pylib/perf_tests_helper.py +++ /dev/null @@ -1,160 +0,0 @@ -# Copyright (c) 2012 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 json -import logging -import math -import re -import sys - -import android_commands - -from perf import cache_control -from perf import perf_control - - -# Valid values of result type. -RESULT_TYPES = {'unimportant': 'RESULT ', - 'default': '*RESULT ', - 'informational': '', - 'unimportant-histogram': 'HISTOGRAM ', - 'histogram': '*HISTOGRAM '} - - -def _EscapePerfResult(s): - """Escapes |s| for use in a perf result.""" - return re.sub('[\:|=/#&,]', '_', s) - - -def _Flatten(values): - """Returns a simple list without sub-lists.""" - ret = [] - for entry in values: - if isinstance(entry, list): - ret.extend(_Flatten(entry)) - else: - ret.append(entry) - return ret - - -def GeomMeanAndStdDevFromHistogram(histogram_json): - histogram = json.loads(histogram_json) - # Handle empty histograms gracefully. - if not 'buckets' in histogram: - return 0.0, 0.0 - count = 0 - sum_of_logs = 0 - for bucket in histogram['buckets']: - if 'high' in bucket: - bucket['mean'] = (bucket['low'] + bucket['high']) / 2.0 - else: - bucket['mean'] = bucket['low'] - if bucket['mean'] > 0: - sum_of_logs += math.log(bucket['mean']) * bucket['count'] - count += bucket['count'] - - if count == 0: - return 0.0, 0.0 - - sum_of_squares = 0 - geom_mean = math.exp(sum_of_logs / count) - for bucket in histogram['buckets']: - if bucket['mean'] > 0: - sum_of_squares += (bucket['mean'] - geom_mean) ** 2 * bucket['count'] - return geom_mean, math.sqrt(sum_of_squares / count) - - -def _MeanAndStdDevFromList(values): - avg = None - sd = 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) - sqdiffs = [(float(v) - avg) ** 2 for v in values] - variance = sum(sqdiffs) / (len(values) - 1) - sd = math.sqrt(variance) - except ValueError: - value = ", ".join(values) - else: - value = values[0] - return value, avg, sd - - -def PrintPages(page_list): - """Prints list of pages to stdout in the format required by perf tests.""" - print 'Pages: [%s]' % ','.join([_EscapePerfResult(p) for p in page_list]) - - -def PrintPerfResult(measurement, trace, values, units, result_type='default', - 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. An N-dimensional list will be - flattened and treated as a simple list. - units: A description of the units of measure, e.g. "bytes". - result_type: Accepts values of RESULT_TYPES. - print_to_stdout: If True, prints the output in stdout instead of returning - the output to caller. - - Returns: - String of the formated perf result. - """ - assert result_type in RESULT_TYPES, 'result type: %s is invalid' % result_type - - trace_name = _EscapePerfResult(trace) - - if result_type in ['unimportant', 'default', 'informational']: - assert isinstance(values, list) - assert len(values) - assert '/' not in measurement - value, avg, sd = _MeanAndStdDevFromList(_Flatten(values)) - output = '%s%s: %s%s%s %s' % ( - RESULT_TYPES[result_type], - _EscapePerfResult(measurement), - trace_name, - # Do not show equal sign if the trace is empty. Usually it happens when - # measurement is enough clear to describe the result. - '= ' if trace_name else '', - value, - units) - else: - assert(result_type in ['histogram', 'unimportant-histogram']) - assert isinstance(values, list) - # The histograms can only be printed individually, there's no computation - # across different histograms. - assert len(values) == 1 - value = values[0] - output = '%s%s: %s= %s %s' % ( - RESULT_TYPES[result_type], - _EscapePerfResult(measurement), - trace_name, - value, - units) - avg, sd = GeomMeanAndStdDevFromHistogram(value) - - if avg: - output += '\nAvg %s: %f%s' % (measurement, avg, units) - if sd: - output += '\nSd %s: %f%s' % (measurement, sd, units) - if print_to_stdout: - print output - sys.stdout.flush() - return output - - -# TODO(bulach): remove once all references to PerfControl are fixed. -class CacheControl(cache_control.CacheControl): - def __init__(self, adb): - super(CacheControl, self).__init__(adb) - -class PerfControl(perf_control.PerfControl): - def __init__(self, adb): - super(PerfControl, self).__init__(adb) diff --git a/build/util/lib/common/perf_tests_results_helper.py b/build/util/lib/common/perf_tests_results_helper.py index 733cbf9..cacf54e 100644 --- a/build/util/lib/common/perf_tests_results_helper.py +++ b/build/util/lib/common/perf_tests_results_helper.py @@ -134,11 +134,12 @@ def PrintPerfResult(measurement, trace, values, units, # across different histograms. assert len(values) == 1 value = values[0] - output = '%s%s: %s= %s' % ( + output = '%s%s: %s= %s %s' % ( RESULT_TYPES[result_type], _EscapePerfResult(measurement), trace_name, - value) + value, + units) avg, sd = GeomMeanAndStdDevFromHistogram(value) if avg: diff --git a/tools/telemetry/telemetry/page/perf_tests_helper.py b/tools/telemetry/telemetry/page/perf_tests_helper.py index d72835d..651d157 100644 --- a/tools/telemetry/telemetry/page/perf_tests_helper.py +++ b/tools/telemetry/telemetry/page/perf_tests_helper.py @@ -5,13 +5,14 @@ from __future__ import absolute_import from telemetry.core import util -util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') -from pylib import perf_tests_helper # pylint: disable=F0401 +util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'util', 'lib', + 'common') +import perf_tests_results_helper # pylint: disable=F0401 GeomMeanAndStdDevFromHistogram = \ - perf_tests_helper.GeomMeanAndStdDevFromHistogram + perf_tests_results_helper.GeomMeanAndStdDevFromHistogram PrintPerfResult = \ - perf_tests_helper.PrintPerfResult + perf_tests_results_helper.PrintPerfResult PrintPages = \ - perf_tests_helper.PrintPages + perf_tests_results_helper.PrintPages |