def install(instrument):
    """
    This will look for methods (or any callable members) with specific names
    in the instrument and hook them up to the corresponding signals.

    :param instrument: Instrument instance to install.

    """
    logger.debug('Installing instrument %s.', instrument)
    if is_installed(instrument):
        raise ValueError('Instrument {} is already installed.'.format(instrument.name))
    for attr_name in dir(instrument):
        priority = 0
        stripped_attr_name = attr_name
        for key, value in PRIORITY_MAP.iteritems():
            if attr_name.startswith(key):
                stripped_attr_name = attr_name[len(key):]
                priority = value
                break
        if stripped_attr_name in SIGNAL_MAP:
            attr = getattr(instrument, attr_name)
            if not callable(attr):
                raise ValueError('Attribute {} not callable in {}.'.format(attr_name, instrument))
            arg_num = len(inspect.getargspec(attr).args)
            if not arg_num == 2:
                raise ValueError('{} must take exactly 2 arguments; {} given.'.format(attr_name, arg_num))

            logger.debug('\tConnecting %s to %s', attr.__name__, SIGNAL_MAP[stripped_attr_name])
            mc = ManagedCallback(instrument, attr)
            _callbacks.append(mc)
            signal.connect(mc, SIGNAL_MAP[stripped_attr_name], priority=priority)
    installed.append(instrument)
 def on_run_start(self, context):
     signal.connect(self.get_start_time,
                    signal.BEFORE_WORKLOAD_EXECUTION,
                    priority=self.priority)
     signal.connect(self.get_stop_time,
                    signal.AFTER_WORKLOAD_EXECUTION,
                    priority=self.priority)
Exemple #3
0
 def initialize(self, context):
     status, devices = self._execute_command('list_devices')
     if status == daq.Status.OK and not devices:
         raise InstrumentError(
             'DAQ: server did not report any devices registered with the driver.'
         )
     self._results = OrderedDict()
     self.gpio_path = None
     if self.gpio_sync:
         if not self.device.file_exists(GPIO_ROOT):
             raise InstrumentError('GPIO sysfs not enabled on the device.')
         try:
             export_path = self.device.path.join(GPIO_ROOT, 'export')
             self.device.set_sysfile_value(export_path,
                                           self.gpio_sync,
                                           verify=False)
             pin_root = self.device.path.join(
                 GPIO_ROOT, 'gpio{}'.format(self.gpio_sync))
             direction_path = self.device.path.join(pin_root, 'direction')
             self.device.set_sysfile_value(direction_path, 'out')
             self.gpio_path = self.device.path.join(pin_root, 'value')
             self.device.set_sysfile_value(self.gpio_path, 0, verify=False)
             signal.connect(self.insert_start_marker,
                            signal.BEFORE_WORKLOAD_EXECUTION,
                            priority=11)
             signal.connect(self.insert_stop_marker,
                            signal.AFTER_WORKLOAD_EXECUTION,
                            priority=11)
         except DeviceError as e:
             raise InstrumentError(
                 'Could not configure GPIO on device: {}'.format(e))
    def __init__(self):
        self.logger = logging.getLogger('gem5Device')

        # The gem5 subprocess
        self.gem5 = None
        self.gem5_port = -1
        self.gem5outdir = os.path.join(settings.output_directory, "gem5")
        self.m5_path = 'm5'
        self.stdout_file = None
        self.stderr_file = None
        self.stderr_filename = None
        self.sckt = None

        # Find the first one that does not exist. Ensures that we do not re-use
        # the directory used by someone else.
        for i in xrange(sys.maxint):
            directory = os.path.join(self.temp_dir, "wa_{}".format(i))
            try:
                os.stat(directory)
                continue
            except OSError:
                break
        self.temp_dir = directory
        self.logger.debug("Using {} as the temporary directory.".format(self.temp_dir))

        # Start the gem5 simulation when WA starts a run using a signal.
        sig.connect(self.init_gem5, sig.RUN_START)
Exemple #5
0
    def __init__(self):
        self.logger = logging.getLogger('gem5Device')

        # The gem5 subprocess
        self.gem5 = None
        self.gem5_port = -1
        self.gem5outdir = os.path.join(settings.output_directory, "gem5")
        self.m5_path = 'm5'
        self.stdout_file = None
        self.stderr_file = None
        self.stderr_filename = None
        self.sckt = None

        # Find the first one that does not exist. Ensures that we do not re-use
        # the directory used by someone else.
        for i in xrange(sys.maxint):
            directory = os.path.join(self.temp_dir, "wa_{}".format(i))
            try:
                os.stat(directory)
                continue
            except OSError:
                break
        self.temp_dir = directory
        self.logger.debug("Using {} as the temporary directory.".format(
            self.temp_dir))

        # Start the gem5 simulation when WA starts a run using a signal.
        sig.connect(self.init_gem5, sig.RUN_START)
 def on_run_init(self, context):
     if not self.device.is_rooted:
         raise InstrumentError('trace-cmd instrument cannot be used on an unrooted device.')
     if not self.no_install:
         host_file = context.resolver.get(Executable(self, self.device.abi, 'trace-cmd'))
         self.trace_cmd = self.device.install_executable(host_file)
     else:
         if not self.device.is_installed('trace-cmd'):
             raise ConfigError('No trace-cmd found on device and no_install=True is specified.')
         self.trace_cmd = 'trace-cmd'
     # Register ourselves as absolute last event before and
     #   first after so we can mark the trace at the right time
     signal.connect(self.insert_start_mark, signal.BEFORE_WORKLOAD_EXECUTION, priority=11)
     signal.connect(self.insert_end_mark, signal.AFTER_WORKLOAD_EXECUTION, priority=11)
 def initialize(self, context):
     # pylint: disable=attribute-defined-outside-init
     device = context.device
     for modname in ['cpuidle', 'cpufreq']:
         if not device.has(modname):
             message = 'Device does not appear to have {} capability; is the right module installed?'
             raise ConfigError(message.format(modname))
     if not device.core_names:
         message = '{} requires"core_names" and "core_clusters" to be specified for the device.'
         raise ConfigError(message.format(self.name))
     self.core_names = device.core_names
     self.core_clusters = device.core_clusters
     idle_states = {s.id: s.desc for s in device.get_cpuidle_states()}
     self.idle_state_names = [idle_states[i] for i in sorted(idle_states.keys())]
     self.num_idle_states = len(self.idle_state_names)
     self.iteration_reports = OrderedDict()
     self.max_freq_list = []
     # priority -19: just higher than the slow_start of instrumentation
     signal.connect(self.set_initial_state, signal.BEFORE_WORKLOAD_EXECUTION, priority=-19)
 def initialize(self, context):
     # pylint: disable=attribute-defined-outside-init
     device = context.device
     for modname in ['cpuidle', 'cpufreq']:
         if not device.has(modname):
             message = 'Device does not appear to have {} capability; is the right module installed?'
             raise ConfigError(message.format(modname))
     if not device.core_names:
         message = '{} requires"core_names" and "core_clusters" to be specified for the device.'
         raise ConfigError(message.format(self.name))
     self.core_names = device.core_names
     self.core_clusters = device.core_clusters
     idle_states = {s.id: s.desc for s in device.get_cpuidle_states()}
     self.idle_state_names = [idle_states[i] for i in sorted(idle_states.keys())]
     self.num_idle_states = len(self.idle_state_names)
     self.iteration_reports = OrderedDict()
     self.max_freq_list = []
     # priority -19: just higher than the slow_start of instrumentation
     signal.connect(self.set_initial_state, signal.BEFORE_WORKLOAD_EXECUTION, priority=-19)
def install(instrument):
    """
    This will look for methods (or any callable members) with specific names
    in the instrument and hook them up to the corresponding signals.

    :param instrument: Instrument instance to install.

    """
    logger.debug('Installing instrument %s.', instrument)
    if is_installed(instrument):
        raise ValueError('Instrument {} is already installed.'.format(
            instrument.name))
    for attr_name in dir(instrument):
        priority = 0
        stripped_attr_name = attr_name
        for key, value in PRIORITY_MAP.iteritems():
            if attr_name.startswith(key):
                stripped_attr_name = attr_name[len(key):]
                priority = value
                break
        if stripped_attr_name in SIGNAL_MAP:
            attr = getattr(instrument, attr_name)
            if not callable(attr):
                raise ValueError('Attribute {} not callable in {}.'.format(
                    attr_name, instrument))
            argspec = inspect.getargspec(attr)
            arg_num = len(argspec.args)
            # Instrument callbacks will be passed exactly two arguments: self
            # (the instrument instance to which the callback is bound) and
            # context. However, we also allow callbacks to capture the context
            # in variable arguments (declared as "*args" in the definition).
            if arg_num > 2 or (arg_num < 2 and argspec.varargs is None):
                message = '{} must take exactly 2 positional arguments; {} given.'
                raise ValueError(message.format(attr_name, arg_num))

            logger.debug('\tConnecting %s to %s', attr.__name__,
                         SIGNAL_MAP[stripped_attr_name])
            mc = ManagedCallback(instrument, attr)
            _callbacks.append(mc)
            signal.connect(mc,
                           SIGNAL_MAP[stripped_attr_name],
                           priority=priority)
    installed.append(instrument)
Exemple #10
0
 def initialize(self, context):
     status, devices = self._execute_command('list_devices')
     if status == daq.Status.OK and not devices:
         raise InstrumentError('DAQ: server did not report any devices registered with the driver.')
     self._results = OrderedDict()
     self.gpio_path = None
     if self.gpio_sync:
         if not self.device.file_exists(GPIO_ROOT):
             raise InstrumentError('GPIO sysfs not enabled on the device.')
         try:
             export_path = self.device.path.join(GPIO_ROOT, 'export')
             self.device.set_sysfile_value(export_path, self.gpio_sync, verify=False)
             pin_root = self.device.path.join(GPIO_ROOT, 'gpio{}'.format(self.gpio_sync))
             direction_path = self.device.path.join(pin_root, 'direction')
             self.device.set_sysfile_value(direction_path, 'out')
             self.gpio_path = self.device.path.join(pin_root, 'value')
             self.device.set_sysfile_value(self.gpio_path, 0, verify=False)
             signal.connect(self.insert_start_marker, signal.BEFORE_WORKLOAD_EXECUTION, priority=11)
             signal.connect(self.insert_stop_marker, signal.AFTER_WORKLOAD_EXECUTION, priority=11)
         except DeviceError as e:
             raise InstrumentError('Could not configure GPIO on device: {}'.format(e))
Exemple #11
0
 def on_run_init(self, context):
     if not self.device.is_rooted:
         raise InstrumentError(
             'trace-cmd instrument cannot be used on an unrooted device.')
     if not self.no_install:
         host_file = context.resolver.get(
             Executable(self, self.device.abi, 'trace-cmd'))
         self.trace_cmd = self.device.install_executable(host_file)
     else:
         if not self.device.is_installed('trace-cmd'):
             raise ConfigError(
                 'No trace-cmd found on device and no_install=True is specified.'
             )
         self.trace_cmd = 'trace-cmd'
     # Register ourselves as absolute last event before and
     #   first after so we can mark the trace at the right time
     signal.connect(self.insert_start_mark,
                    signal.BEFORE_WORKLOAD_EXECUTION,
                    priority=11)
     signal.connect(self.insert_end_mark,
                    signal.AFTER_WORKLOAD_EXECUTION,
                    priority=11)
def install(instrument):
    """
    This will look for methods (or any callable members) with specific names
    in the instrument and hook them up to the corresponding signals.

    :param instrument: Instrument instance to install.

    """
    logger.debug('Installing instrument %s.', instrument)
    if is_installed(instrument):
        raise ValueError('Instrument {} is already installed.'.format(instrument.name))
    for attr_name in dir(instrument):
        priority = 0
        stripped_attr_name = attr_name
        for key, value in PRIORITY_MAP.iteritems():
            if attr_name.startswith(key):
                stripped_attr_name = attr_name[len(key):]
                priority = value
                break
        if stripped_attr_name in SIGNAL_MAP:
            attr = getattr(instrument, attr_name)
            if not callable(attr):
                raise ValueError('Attribute {} not callable in {}.'.format(attr_name, instrument))
            argspec = inspect.getargspec(attr)
            arg_num = len(argspec.args)
            # Instrument callbacks will be passed exactly two arguments: self
            # (the instrument instance to which the callback is bound) and
            # context. However, we also allow callbacks to capture the context
            # in variable arguments (declared as "*args" in the definition).
            if arg_num > 2 or (arg_num < 2 and argspec.varargs is None):
                message = '{} must take exactly 2 positional arguments; {} given.'
                raise ValueError(message.format(attr_name, arg_num))

            logger.debug('\tConnecting %s to %s', attr.__name__, SIGNAL_MAP[stripped_attr_name])
            mc = ManagedCallback(instrument, attr)
            _callbacks.append(mc)
            signal.connect(mc, SIGNAL_MAP[stripped_attr_name], priority=priority)
    installed.append(instrument)
 def __init__(self):
     Instrument.__init__(self, None)
     self.signals_received = []
     for sig in signal.__dict__.values():
         if isinstance(sig, Signal):
             signal.connect(self.handler, sig)
Exemple #14
0
    def execute(self, agenda, selectors=None):  # NOQA
        """
        Execute the run specified by an agenda. Optionally, selectors may be used to only
        selecute a subset of the specified agenda.

        Params::

            :agenda: an ``Agenda`` instance to be executed.
            :selectors: A dict mapping selector name to the coresponding values.

        **Selectors**

        Currently, the following seectors are supported:

        ids
            The value must be a sequence of workload specfication IDs to be executed. Note
            that if sections are specified inthe agenda, the workload specifacation ID will
            be a combination of the section and workload IDs.

        """
        signal.connect(self._error_signalled_callback, signal.ERROR_LOGGED)
        signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED)

        self.logger.info('Initializing')
        self.ext_loader = ExtensionLoader(packages=settings.extension_packages,
                                          paths=settings.extension_paths)

        self.logger.debug('Loading run configuration.')
        self.config = RunConfiguration(self.ext_loader)
        for filepath in settings.get_config_paths():
            self.config.load_config(filepath)
        self.config.set_agenda(agenda, selectors)
        self.config.finalize()
        config_outfile = os.path.join(settings.meta_directory,
                                      'run_config.json')
        with open(config_outfile, 'w') as wfh:
            self.config.serialize(wfh)

        self.logger.debug('Initialising device configuration.')
        if not self.config.device:
            raise ConfigError('Make sure a device is specified in the config.')
        self.device = self.ext_loader.get_device(self.config.device,
                                                 **self.config.device_config)
        self.device.validate()

        self.context = ExecutionContext(self.device, self.config)

        self.logger.debug('Loading resource discoverers.')
        self.context.initialize()
        self.context.resolver.load()
        self.context.add_artifact('run_config', config_outfile, 'meta')

        self.logger.debug('Installing instrumentation')
        for name, params in self.config.instrumentation.iteritems():
            instrument = self.ext_loader.get_instrument(
                name, self.device, **params)
            instrumentation.install(instrument)
        instrumentation.validate()

        self.logger.debug('Installing result processors')
        result_manager = ResultManager()
        for name, params in self.config.result_processors.iteritems():
            processor = self.ext_loader.get_result_processor(name, **params)
            result_manager.install(processor)
        result_manager.validate()

        self.logger.debug('Loading workload specs')
        for workload_spec in self.config.workload_specs:
            workload_spec.load(self.device, self.ext_loader)
            workload_spec.workload.init_resources(self.context)
            workload_spec.workload.validate()

        if self.config.flashing_config:
            if not self.device.flasher:
                msg = 'flashing_config specified for {} device that does not support flashing.'
                raise ConfigError(msg.format(self.device.name))
            self.logger.debug('Flashing the device')
            self.device.flasher.flash(self.device)

        self.logger.info('Running workloads')
        runner = self._get_runner(result_manager)
        runner.init_queue(self.config.workload_specs)
        runner.run()
        self.execute_postamble()
    def execute(self, agenda, selectors=None):  # NOQA
        """
        Execute the run specified by an agenda. Optionally, selectors may be used to only
        selecute a subset of the specified agenda.

        Params::

            :agenda: an ``Agenda`` instance to be executed.
            :selectors: A dict mapping selector name to the coresponding values.

        **Selectors**

        Currently, the following seectors are supported:

        ids
            The value must be a sequence of workload specfication IDs to be executed. Note
            that if sections are specified inthe agenda, the workload specifacation ID will
            be a combination of the section and workload IDs.

        """
        signal.connect(self._error_signalled_callback, signal.ERROR_LOGGED)
        signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED)

        self.logger.info('Initializing')
        self.ext_loader = ExtensionLoader(packages=settings.extension_packages,
                                          paths=settings.extension_paths)

        self.logger.debug('Loading run configuration.')
        self.config = RunConfiguration(self.ext_loader)
        for filepath in settings.get_config_paths():
            self.config.load_config(filepath)
        self.config.set_agenda(agenda, selectors)
        self.config.finalize()
        config_outfile = os.path.join(settings.meta_directory, 'run_config.json')
        with open(config_outfile, 'w') as wfh:
            self.config.serialize(wfh)

        self.logger.debug('Initialising device configuration.')
        if not self.config.device:
            raise ConfigError('Make sure a device is specified in the config.')
        self.device = self.ext_loader.get_device(self.config.device, **self.config.device_config)
        self.device.validate()

        self.context = ExecutionContext(self.device, self.config)

        self.logger.debug('Loading resource discoverers.')
        self.context.initialize()
        self.context.resolver.load()
        self.context.add_artifact('run_config', config_outfile, 'meta')

        self.logger.debug('Installing instrumentation')
        for name, params in self.config.instrumentation.iteritems():
            instrument = self.ext_loader.get_instrument(name, self.device, **params)
            instrumentation.install(instrument)
        instrumentation.validate()

        self.logger.debug('Installing result processors')
        result_manager = ResultManager()
        for name, params in self.config.result_processors.iteritems():
            processor = self.ext_loader.get_result_processor(name, **params)
            result_manager.install(processor)
        result_manager.validate()

        self.logger.debug('Loading workload specs')
        for workload_spec in self.config.workload_specs:
            workload_spec.load(self.device, self.ext_loader)
            workload_spec.workload.init_resources(self.context)
            workload_spec.workload.validate()

        if self.config.flashing_config:
            if not self.device.flasher:
                msg = 'flashing_config specified for {} device that does not support flashing.'
                raise ConfigError(msg.format(self.device.name))
            self.logger.debug('Flashing the device')
            self.device.flasher.flash(self.device)

        self.logger.info('Running workloads')
        runner = self._get_runner(result_manager)
        runner.init_queue(self.config.workload_specs)
        runner.run()
        self.execute_postamble()
 def __init__(self):
     Instrument.__init__(self, None)
     self.signals_received = []
     for sig in signal.__dict__.values():
         if isinstance(sig, Signal):
             signal.connect(self.handler, sig)
 def initialize(self, context):
     self.device = self.root_owner
     signal.connect(self._on_device_init, signal.RUN_INIT, priority=1)
 def initialize(self, context):
     self.device = self.root_owner
     signal.connect(self._on_device_init, signal.RUN_INIT, priority=1)
 def on_run_start(self, context):
     signal.connect(self.get_start_time, signal.BEFORE_WORKLOAD_EXECUTION, priority=self.priority)
     signal.connect(self.get_stop_time, signal.AFTER_WORKLOAD_EXECUTION, priority=self.priority)