def initialize(self, seconds_period=20., pdash_note=''): """Perform necessary initialization prior to power test run. @param seconds_period: float of probing interval in seconds. @param pdash_note: note of the current run to send to power dashboard. @var backlight: power_utils.Backlight object. @var keyvals: dictionary of result keyvals. @var status: power_status.SysStat object. @var _checkpoint_logger: power_status.CheckpointLogger to track checkpoint data. @var _plog: power_status.PowerLogger object to monitor power. @var _psr: power_utils.DisplayPanelSelfRefresh object to monitor PSR. @var _services: service_stopper.ServiceStopper object. @var _start_time: float of time in seconds since Epoch test started. @var _stats: power_status.StatoMatic object. @var _tlog: power_status.TempLogger object to monitor temperatures. @var _clog: power_status.CPUStatsLogger object to monitor CPU(s) frequencies and c-states. @var _meas_logs: list of power_status.MeasurementLoggers """ super(power_Test, self).initialize() self.backlight = power_utils.Backlight() self.backlight.set_default() self.keyvals = dict() self.status = power_status.get_status() self._checkpoint_logger = power_status.CheckpointLogger() measurements = [] if not self.status.on_ac(): measurements.append( power_status.SystemPower(self.status.battery_path)) if power_utils.has_powercap_support(): measurements += power_rapl.create_powercap() elif power_utils.has_rapl_support(): measurements += power_rapl.create_rapl() self._plog = power_status.PowerLogger( measurements, seconds_period=seconds_period, checkpoint_logger=self._checkpoint_logger) self._psr = power_utils.DisplayPanelSelfRefresh() self._services = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._services.stop_services() self._stats = power_status.StatoMatic() self._tlog = power_status.TempLogger( [], seconds_period=seconds_period, checkpoint_logger=self._checkpoint_logger) self._clog = power_status.CPUStatsLogger( seconds_period=seconds_period, checkpoint_logger=self._checkpoint_logger) self._meas_logs = [self._plog, self._tlog, self._clog] self._pdash_note = pdash_note
def run_once(self, idle_time=120, sleep=10, bt_warmup_time=20): """Collect power stats when bluetooth adapter is on or off. """ with chrome.Chrome(): self._backlight = power_utils.Backlight() self._backlight.set_default() t0 = time.time() self._start_time = t0 self._psr = power_utils.DisplayPanelSelfRefresh(init_time=t0) self.status = power_status.get_status() self._stats = power_status.StatoMatic() measurements = [] if not self.status.on_ac(): measurements.append( power_status.SystemPower(self.status.battery_path)) if power_utils.has_powercap_support(): measurements += power_rapl.create_powercap() elif power_utils.has_rapl_support(): measurements += power_rapl.create_rapl() self._plog = power_status.PowerLogger(measurements, seconds_period=sleep) self._tlog = power_status.TempLogger([], seconds_period=sleep) self._plog.start() self._tlog.start() for _ in xrange(0, idle_time, sleep): time.sleep(sleep) self.status.refresh() self.status.refresh() self._plog.checkpoint('bluetooth_adapter_off', self._start_time) self._tlog.checkpoint('', self._start_time) self._psr.refresh() # Turn on bluetooth adapter. bt_device = bluetooth_device_xmlrpc_server \ .BluetoothDeviceXmlRpcDelegate() # If we cannot start bluetoothd, fail gracefully and still write # data with bluetooth adapter off to file, as we are interested in # just that data too. start_bluetoothd() already logs the error so # not logging any error here. if not bt_device.start_bluetoothd(): return if not bt_device.set_powered(True): logging.warning("Cannot turn on bluetooth adapter.") return time.sleep(bt_warmup_time) if not bt_device._is_powered_on(): logging.warning("Bluetooth adapter is off.") return t1 = time.time() time.sleep(idle_time) self._plog.checkpoint('bluetooth_adapter_on', t1) bt_device.set_powered(False) bt_device.stop_bluetoothd()
def test_power(self, local_path): """ Runs the video power consumption test. @param local_path: the path to the video file. @return a dictionary that contains the test result. """ self._backlight = power_utils.Backlight() self._backlight.set_default() self._service_stopper = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._service_stopper.stop_services() current_power_status = power_status.get_status() # We expect the DUT is powered by battery now. But this is not always # true due to other bugs. Disable this test temporarily as workaround. # TODO(kcwu): remove this workaround after AC control is stable # crbug.com/723968 if current_power_status.on_ac(): logging.warning('Still powered by AC. Skip this test') return {} # Verify that the battery is sufficiently charged. current_power_status.assert_battery_state(BATTERY_INITIAL_CHARGED_MIN) measurements = [power_status.SystemPower( current_power_status.battery_path)] def get_power(cr): power_logger = power_status.PowerLogger(measurements) power_logger.start() time.sleep(STABILIZATION_DURATION) start_time = time.time() time.sleep(MEASUREMENT_DURATION) power_logger.checkpoint('result', start_time) keyval = power_logger.calc() # save_results() will save <fname_prefix>_raw.txt and # <fname_prefix>_summary.txt, where the former contains raw data. fname_prefix = 'result_%.0f' % time.time() power_logger.save_results(self.resultsdir, fname_prefix) metric_name = 'result_' + measurements[0].domain with open(os.path.join( self.resultsdir, fname_prefix + '_raw.txt')) as f: for line in f.readlines(): if line.startswith(metric_name): split_data = line.split('\t') # split_data[0] is metric_name, [1:] are raw data. return [float(data) for data in split_data[1:]] # Return a list contains the average power only for fallback. return [keyval[metric_name + '_pwr_avg']] return self.test_webrtc(local_path, get_power)
def test_power(self, local_path): """ Runs the video power consumption test. @param local_path: the path to the video file. @return a dictionary that contains the test result. """ self._backlight = power_utils.Backlight() self._backlight.set_default() self._service_stopper = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._service_stopper.stop_services() self._power_status = power_status.get_status() # We expect the DUT is powered by battery now. But this is not always # true due to other bugs. Disable this test temporarily as workaround. # TODO(kcwu): remove this workaround after AC control is stable # crbug.com/723968 if self._power_status.on_ac(): logging.warning('Still powered by AC. Skip this test') return {} # Verify that the battery is sufficiently charged. self._power_status.assert_battery_state(BATTERY_INITIAL_CHARGED_MIN) measurements = [ power_status.SystemPower(self._power_status.battery_path) ] if power_utils.has_rapl_support(): measurements += power_rapl.create_rapl() def get_power(cr): power_logger = power_status.PowerLogger(measurements) power_logger.start() time.sleep(STABILIZATION_DURATION) start_time = time.time() time.sleep(MEASUREMENT_DURATION) power_logger.checkpoint('result', start_time) keyval = power_logger.calc() keyval = { key: keyval[key] for key in keyval if key.endswith('_pwr') } return keyval return self.test_playback(local_path, get_power)
def __enter__(self): self._backlight = power_utils.Backlight() self._backlight.set_default() self._service_stopper = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._service_stopper.stop_services() status = power_status.get_status() # Verify that we are running on battery and the battery is sufficiently # charged. status.assert_battery_state(BATTERY_INITIAL_CHARGED_MIN) self._system_power = power_status.SystemPower(status.battery_path) self._power_logger = power_status.PowerLogger([self._system_power]) return self
def run_power_test(self, browser, test_url, ac_ok): """Runs the webgl power consumption test and reports the perf results. @param browser: The Browser object to run the test with. @param test_url: The URL to the aquarium test site. @param ac_ok: Boolean on whether its ok to have AC power supplied. """ self._backlight = power_utils.Backlight() self._backlight.set_default() self._service_stopper = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._service_stopper.stop_services() if not ac_ok: self._power_status = power_status.get_status() # Verify that we are running on battery and the battery is # sufficiently charged. self._power_status.assert_battery_state(BATTERY_INITIAL_CHARGED_MIN) measurements = [ power_status.SystemPower(self._power_status.battery_path) ] def get_power(): power_logger = power_status.PowerLogger(measurements) power_logger.start() time.sleep(STABILIZATION_DURATION) start_time = time.time() time.sleep(MEASUREMENT_DURATION) power_logger.checkpoint('result', start_time) keyval = power_logger.calc() logging.info('Power output %s', keyval) return keyval['result_' + measurements[0].domain + '_pwr'] self.run_fish_test(browser, test_url, 1000, perf_log=False) if not ac_ok: energy_rate = get_power() # This is a power specific test so we are not capturing # avg_fps and avg_render_time in this test. self.perf_keyval[POWER_DESCRIPTION] = energy_rate self.output_perf_value( description=POWER_DESCRIPTION, value=energy_rate, units='W', higher_is_better=False)
def run_power_test(self, audio_type): """ Captures power usage and reports it to the perf dashboard. @param audio_type: audio format label to attach with perf keyval. """ self._backlight = power_utils.Backlight() self._backlight.set_default() self._service_stopper = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._service_stopper.stop_services() self._power_status = power_status.get_status() # Verify that we are running on battery and the battery is sufficiently # charged. self._power_status.assert_battery_state(BATTERY_INITIAL_CHARGED_MIN) measurements = [ power_status.SystemPower(self._power_status.battery_path) ] def get_power(): power_logger = power_status.PowerLogger(measurements) power_logger.start() time.sleep(STABILIZATION_DURATION) start_time = time.time() time.sleep(MEASUREMENT_DURATION) power_logger.checkpoint('result', start_time) keyval = power_logger.calc() logging.info('Power output %s', keyval) return keyval['result_' + measurements[0].domain + '_pwr'] energy_rate = get_power() perf_keyval = {} perf_keyval[POWER_DESCRIPTION + audio_type] = energy_rate self.output_perf_value(description=POWER_DESCRIPTION + audio_type, value=energy_rate, units='W', higher_is_better=False) self.write_perf_keyval(perf_keyval)
def test_power(self): """ Runs the video power consumption test. @return a dictionary that contains the test result. """ self._backlight = power_utils.Backlight() self._backlight.set_level(0) self._power_status = power_status.get_status() self._use_ec = True if not power_utils.charge_control_by_ectool(is_charge=False): logging.warning('Can\'t stop charging') return {} if not self._power_status.battery: raise error.TestFail('No valid battery') # Verify that the battery is sufficiently charged. percent_initial_charge = self._power_status.percent_current_charge() if percent_initial_charge < BATTERY_INITIAL_CHARGED_MIN: logging.warning( 'Initial charge (%f) less than min (%f)', (percent_initial_charge, BATTERY_INITIAL_CHARGED_MIN)) return {} measurements = [ power_status.SystemPower(self._power_status.battery_path) ] def get_power(): power_logger = power_status.PowerLogger(measurements) power_logger.start() start_time = time.time() time.sleep(MEASUREMENT_DURATION) power_logger.checkpoint('result', start_time) keyval = power_logger.calc() return keyval['result_' + measurements[0].domain + '_pwr_avg'] return self.test_decode(get_power)
def run_once(self): status = power_status.get_status() statomatic = power_status.StatoMatic() meas = [power_status.SystemPower(status.battery_path)] plog = power_status.PowerLogger(meas, seconds_period=1) tlog = power_status.TempLogger(None, seconds_period=1) plog.start() tlog.start() time.sleep(2) logging.info("battery_energy: %f" % status.battery[0].energy) logging.info("linepower_online: %s" % status.on_ac()) keyvals = plog.calc() keyvals.update(tlog.calc()) keyvals.update(statomatic.publish()) for k in sorted(keyvals.keys()): logging.info("%s: %s", k, keyvals[k]) plog.save_results(self.resultsdir) tlog.save_results(self.resultsdir)
def __enter__(self): status = power_status.get_status() # We expect the DUT is powered by battery now. But this is not always # true due to other bugs. Disable this test temporarily as workaround. # TODO(johnylin): remove this workaround after AC control is stable # crbug.com/914211 if status.on_ac(): logging.warning('Still powered by AC. Skip this test') raise error.TestNAError('Unable to disable AC.') # Verify that we are running on battery and the battery is sufficiently # charged. status.assert_battery_state(BATTERY_INITIAL_CHARGED_MIN) self._backlight = power_utils.Backlight() self._backlight.set_default() self._service_stopper = service_stopper.ServiceStopper( service_stopper.ServiceStopper.POWER_DRAW_SERVICES) self._service_stopper.stop_services() self._system_power = power_status.SystemPower(status.battery_path) self._power_logger = power_status.PowerLogger([self._system_power]) return self
def run_once(self): """Test main loop.""" t0 = time.time() # record the PSR related info. psr = power_utils.DisplayPanelSelfRefresh(init_time=t0) try: self._keyboard_backlight = power_utils.KbdBacklight() self._set_keyboard_backlight_level() except power_utils.KbdBacklightException as e: logging.info("Assuming no keyboard backlight due to :: %s", str(e)) self._keyboard_backlight = None measurements = [] if self._power_status.battery: measurements += \ [power_status.SystemPower(self._power_status.battery_path)] if power_utils.has_powercap_support(): measurements += power_rapl.create_powercap() elif power_utils.has_rapl_support(): measurements += power_rapl.create_rapl() self._checkpoint_logger = power_status.CheckpointLogger() self._plog = power_status.PowerLogger(measurements, seconds_period=20, checkpoint_logger=self._checkpoint_logger) self._tlog = power_status.TempLogger([], seconds_period=20, checkpoint_logger=self._checkpoint_logger) self._clog = power_status.CPUStatsLogger( seconds_period=20, checkpoint_logger=self._checkpoint_logger) self._meas_logs = [self._plog, self._tlog, self._clog] for log in self._meas_logs: log.start() if self._log_mem_bandwidth: self._mlog = memory_bandwidth_logger.MemoryBandwidthLogger( raw=False, seconds_period=2) self._mlog.start() # record start time and end time for each task self._task_tracker = [] ext_path = os.path.join(os.path.dirname(__file__), 'extension') self._tmp_keyvals['username'] = self._username arc_mode = arc_common.ARC_MODE_DISABLED if utils.is_arc_available(): arc_mode = arc_common.ARC_MODE_ENABLED try: self._browser = chrome.Chrome(extension_paths=[ext_path], gaia_login=self._gaia_login, username=self._username, password=self._password, arc_mode=arc_mode) except exceptions.LoginException: # already failed guest login if not self._gaia_login: raise self._gaia_login = False logging.warn("Unable to use GAIA acct %s. Using GUEST instead.\n", self._username) self._browser = chrome.Chrome(extension_paths=[ext_path], gaia_login=self._gaia_login) if not self._gaia_login: self._tmp_keyvals['username'] = '******' extension = self._browser.get_extension(ext_path) for k in params_dict: if getattr(self, params_dict[k]) is not '': extension.ExecuteJavaScript('var %s = %s;' % (k, getattr(self, params_dict[k]))) # This opens a trap start page to capture tabs opened for first login. # It will be closed when startTest is run. extension.ExecuteJavaScript('chrome.windows.create(null, null);') for i in range(self._loop_count): start_time = time.time() extension.ExecuteJavaScript('startTest();') # the power test extension will report its status here latch = self._testServer.add_wait_url('/status') # this starts a thread in the server that listens to log # information from the script script_logging = self._testServer.add_wait_url(url='/log') # dump any log entry that comes from the script into # the debug log self._testServer.add_url_handler(url='/log',\ handler_func=(lambda handler, forms, loop_counter=i:\ _extension_log_handler(handler, forms, loop_counter))) pagetime_tracking = self._testServer.add_wait_url(url='/pagetime') self._testServer.add_url_handler(url='/pagetime',\ handler_func=(lambda handler, forms, test_instance=self, loop_counter=i:\ _extension_page_time_info_handler(handler, forms, loop_counter, test_instance))) # setup a handler to simulate waking up the base of a detachable # on user interaction. On scrolling, wake for 1s, on page # navigation, wake for 10s. self._testServer.add_url(url='/pagenav') self._testServer.add_url(url='/scroll') self._testServer.add_url_handler(url='/pagenav', handler_func=(lambda handler, args, plt=self: plt._detachable_handler.wake_base(10000))) self._testServer.add_url_handler(url='/scroll', handler_func=(lambda handler, args, plt=self: plt._detachable_handler.wake_base(1000))) # reset backlight level since powerd might've modified it # based on ambient light self._set_backlight_level() self._set_lightbar_level() if self._keyboard_backlight: self._set_keyboard_backlight_level() audio_helper.set_volume_levels(self._volume_level, self._mic_gain) low_battery = self._do_wait(self._verbose, self._loop_time, latch) script_logging.set() pagetime_tracking.set() self._log_loop_checkpoint(i, start_time, time.time()) if self._verbose: logging.debug('loop %d completed', i) if low_battery: logging.info('Exiting due to low battery') break # done with logging from the script, so we can collect that thread t1 = time.time() psr.refresh() self._tmp_keyvals['minutes_battery_life_tested'] = (t1 - t0) / 60 self._tmp_keyvals.update(psr.get_keyvals())
def run_once(self, video_url, video_short_name): """Runs the graphics_VideoRenderingPower test. @param video_url: URL with autoplay video inside. It's assumed that there's just one <video> in the HTML, and that it fits in the viewport. @param video_short_name: short string describing the video; itt will be presented as part of the dashboard entry name. """ # TODO(mcasas): Extend this test to non-Intel platforms. if not power_utils.has_rapl_support(): logging.warning( 'This board has no RAPL power measurement support, ' 'skipping test.') return rapl = [] if power_utils.has_battery(): rapl.append( power_status.SystemPower(self._power_status.battery_path)) else: logging.warning('This board has no battery.') rapl += power_rapl.create_rapl() for test_name_and_flags in TEST_NAME_AND_FLAGS: logging.info('Test case: %s', test_name_and_flags[0]) # Launch Chrome with the appropriate flag combination. with chrome.Chrome(extra_browser_args=test_name_and_flags[1], init_network_controller=True) as cr: if not utils.wait_for_idle_cpu(IDLE_CPU_WAIT_TIMEOUT_SECONDS, IDLE_CPU_LOAD_PERCENTAGE): raise error.TestFail('Failed: Could not get idle CPU.') if not utils.wait_for_cool_machine(): raise error.TestFail('Failed: Could not get cold machine.') tab = cr.browser.tabs[0] tab.Navigate(video_url) tab.WaitForDocumentReadyStateToBeComplete() tab.EvaluateJavaScript( 'document.' 'getElementsByTagName(\'video\')[0].scrollIntoView(true)') # Disabling hardware overlays is difficult because the flag is # already in the browser. Instead, scroll a bit down to make the # video bleed out of the viewport. if '--enable-hardware-overlays=' in test_name_and_flags[1]: tab.EvaluateJavaScript('window.scrollBy(0, 1)') power_logger = power_status.PowerLogger(rapl) power_logger.start() time.sleep(PREAMBLE_DURATION_SECONDS) start_time = time.time() time.sleep(MEASUREMENT_DURATION_SECONDS) power_logger.checkpoint('result', start_time) measurements = power_logger.calc() logging.debug(measurements) for category in sorted(measurements): if category.endswith('_pwr'): description = '%s_%s_%s' % ( video_short_name, test_name_and_flags[0], category) self.output_perf_value(description=description, value=measurements[category], units='W', higher_is_better=False, graph=GRAPH_NAME) if category.endswith('_pwr_avg'): # write_perf_keyval() wants units (W) first in lowercase. description = '%s_%s_%s' % ( video_short_name, test_name_and_flags[0], category) self.write_perf_keyval( {'w_' + description: measurements[category]})