1# Lint as: python2, python3 2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import json 7import logging 8import sys 9 10# TODO (b/206008069), remove this when migrated to new env 11sys.path.insert(0, 12 '/usr/local/lib/python2.7/dist-packages/six-1.16.0-py2.7.egg') 13try: 14 # This is weird. But it seems something is bringing in six earlier 15 # Going to force a reload after the egg is inserted. 16 import six 17 if six.PY2: 18 reload(six) 19 else: 20 import importlib 21 importlib.reload(six) 22 logging.debug("six version is {}".format(six.__version__)) 23 if six.__version__ != '1.16.0': 24 logging.debug(sys.path) 25except ImportError as e: 26 logging.warning("Could not import six due to %s", e) 27 28from autotest_lib.server import test 29from autotest_lib.server.cros import telemetry_runner 30from autotest_lib.server.cros.crosperf import device_setup_utils 31 32 33class telemetry_Benchmarks(test.test): 34 """Run a telemetry benchmark.""" 35 version = 1 36 37 38 def run_once(self, host=None, benchmark=None, args={}): 39 """Run a telemetry benchmark. 40 41 @param host: hostname(ip address) to run the telemetry benchmark on. 42 @param benchmark: telemetry benchmark test to run. 43 """ 44 local = args.get("local") == "True" 45 optional = {} 46 telemetry_on_dut = args.get("telemetry_on_dut") 47 if telemetry_on_dut: 48 optional["telemetry_on_dut"] = telemetry_on_dut == "True" 49 50 dut_config_str = args.get("dut_config", "{}") 51 dut_config = json.loads(dut_config_str) 52 if dut_config: 53 device_setup_utils.setup_device(host, dut_config) 54 55 with telemetry_runner.TelemetryRunnerFactory().get_runner( 56 host, local, **optional) as telemetry: 57 perf_value_writer = self 58 extra_args = args.get("extra_args", []) 59 repeat = args.get("pageset_repeat") 60 if repeat is not None: 61 extra_args.append('--pageset-repeat=%s' % repeat) 62 63 telemetry.run_telemetry_benchmark(benchmark, perf_value_writer, 64 *extra_args) 65