blob: 5fc5aa330c2bf4a83100ef457fada7663798135a [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS 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 logging
class NetperfWiFiPerfLogger(object):
"""Delegate object to write netperf keyvals in a standard format."""
def channel_label(self):
"""@return string like 'ch011' corresponding to configured channel."""
return 'ch%03d' %
def powersave_label(self):
"""@return string 'PSon' if powersave mode is on, 'PSoff' otherwise."""
return 'PS%s' % ('on' if self._wifi_client.powersave_on else 'off')
def __init__(self, ap_config, wifi_client, keyval_recorder):
"""Construct a NetperfWiFiPerfLogger.
@param ap_config a HostapConfig object representing the state
of the AP that netperf is being run against.
@param wifi_client a WiFiClient representing the DUT in the test.
@param keyval_recorder a function that takes a single argument which
is a dict of keyvals. For instance, this could be the
|write_perf_keyvals| function from a test object.
self._ap_config = ap_config
self._wifi_client = wifi_client
self.write_perf_keyval = keyval_recorder
def record_signal_keyval(self, descriptive_tag=None):
"""Records the current WiFi signal level as a keyval.
@param descriptive_tag string concise whitespace free string to be
embedded in keyval keys.
tag_pieces = [self._wifi_client.machine_id, 'signal',
if descriptive_tag:
signal_level_key = '_'.join(tag_pieces)
signal_level = self._wifi_client.wifi_signal_level
if signal_level is None:
logging.warning('Could not obtain signal level for logging.')
self.write_perf_keyval({signal_level_key: signal_level})
logging.debug('Signal level for channel %d is %d dBm',, signal_level)
def record_keyvals_for_result(self, result, descriptive_tag=None):
"""Records result data keyvals.
@param result NetperfResult object.
@param descriptive_tag string concise whitespace free string to be
embedded in keyval keys.
mode = self._ap_config.printable_mode
mode = 'mode%s' % mode.replace('+', 'p').replace('-', 'm')
suffix = '_'.join([self.powersave_label,
descriptive_tag or result.tag])
keyvals = result.get_keyval(prefix=self._wifi_client.machine_id,