def initialize(self, context): if not self.target.is_rooted: raise InstrumentError( 'trace-cmd instrument cannot be used on an unrooted device.') collector_params = dict( events=self.events, functions=self.functions, buffer_size=self.buffer_size, buffer_size_step=1000, automark=False, autoreport=True, autoview=False, no_install=self.no_install, strict=False, report_on_target=False, ) if self.report and self.report_on_target: collector_params['autoreport'] = True collector_params['report_on_target'] = True else: collector_params['autoreport'] = False collector_params['report_on_target'] = False self.collector = FtraceCollector(self.target, **collector_params) # Register ourselves as absolute last event before and # first after so we can mark the trace at the right time signal.connect(self.mark_start, signal.BEFORE_WORKLOAD_EXECUTION, priority=11) signal.connect(self.mark_stop, signal.AFTER_WORKLOAD_EXECUTION, priority=11)
def initialize(self, context): if not self.target.is_rooted: raise InstrumentError('trace-cmd instrument cannot be used on an unrooted device.') collector_params = dict( events=self.events, functions=self.functions, buffer_size=self.buffer_size, buffer_size_step=1000, automark=False, autoreport=True, autoview=False, no_install=self.no_install, strict=False, report_on_target=False, ) if self.report and self.report_on_target: collector_params['autoreport'] = True collector_params['report_on_target'] = True else: collector_params['autoreport'] = False collector_params['report_on_target'] = False self.collector = FtraceCollector(self.target, **collector_params) # Register ourselves as absolute last event before and # first after so we can mark the trace at the right time signal.connect(self.mark_start, signal.BEFORE_WORKLOAD_EXECUTION, priority=11) signal.connect(self.mark_stop, signal.AFTER_WORKLOAD_EXECUTION, priority=11)
def initialize(self, context): if not self.target.is_rooted and self.as_root: raise ConfigError('The target is not rooted, cannot run poller as root.') host_poller = context.get_resource(Executable(self, self.target.abi, "poller")) target_poller = self.target.install(host_poller) expanded_paths = [] for path in self.files: if "*" in path: for p in self.target.list_directory(path): expanded_paths.append(p) else: expanded_paths.append(path) self.files = expanded_paths if not self.labels: self.labels = self._generate_labels() self.target_output_path = self.target.path.join(self.target.working_directory, 'poller.csv') self.target_log_path = self.target.path.join(self.target.working_directory, 'poller.log') marker_option = '' if self.align_with_ftrace: marker_option = '-m' signal.connect(self._adjust_timestamps, signal.AFTER_JOB_OUTPUT_PROCESSED) self.command = '{} -t {} {} -l {} {} > {} 2>{}'.format(target_poller, self.sample_interval * 1000, marker_option, ','.join(self.labels), ' '.join(self.files), self.target_output_path, self.target_log_path)
def initialize(self, context): if not self.target.is_rooted and self.as_root: raise ConfigError( 'The target is not rooted, cannot run poller as root.') host_poller = context.get_resource( Executable(self, self.target.abi, "poller")) target_poller = self.target.install(host_poller) expanded_paths = [] for path in self.files: if "*" in path: for p in self.target.list_directory(path): expanded_paths.append(p) else: expanded_paths.append(path) self.files = expanded_paths if not self.labels: self.labels = self._generate_labels() self.target_output_path = self.target.path.join( self.target.working_directory, 'poller.csv') self.target_log_path = self.target.path.join( self.target.working_directory, 'poller.log') marker_option = '' if self.align_with_ftrace: marker_option = '-m' signal.connect(self._adjust_timestamps, signal.AFTER_JOB_OUTPUT_PROCESSED) self.command = '{} -t {} {} -l {} {} > {} 2>{}'.format( target_poller, self.sample_interval * 1000, marker_option, ','.join(self.labels), ' '.join(self.files), self.target_output_path, self.target_log_path)
def initialize_run(self): self.logger.info('Initializing run') signal.connect(self._error_signalled_callback, signal.ERROR_LOGGED) signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED) self.context.start_run() self.pm.initialize(self.context) with log.indentcontext(): self.context.initialize_jobs() self.context.write_state()
def __init__(self, target, logcat_poll_period=None, disable_selinux=True, stay_on_mode=None): self.target = target self.logcat_poll_period = logcat_poll_period self.disable_selinux = disable_selinux self.stay_on_mode = stay_on_mode self.orig_stay_on_mode = self.target.get_stay_on_mode() if stay_on_mode is not None else None self.logcat_poller = None self.logger = logging.getLogger('logcat') self._logcat_marker_msg = None self._logcat_marker_tag = None signal.connect(self._before_workload, signal.BEFORE_WORKLOAD_EXECUTION) if self.logcat_poll_period: signal.connect(self._after_workload, signal.AFTER_WORKLOAD_EXECUTION)
def install(instrument, context): """ 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. """ # pylint: disable=redefined-outer-name logger.debug('Installing instrument %s.', instrument) if is_installed(instrument): msg = 'Instrument {} is already installed.' raise ValueError(msg.format(instrument.name)) for attr_name in dir(instrument): if attr_name not in SIGNAL_MAP: continue attr = getattr(instrument, attr_name) if not callable(attr): msg = 'Attribute {} not callable in {}.' raise ValueError(msg.format(attr_name, instrument)) if sys.version_info[0] == 3: argspec = inspect.getfullargspec(attr) else: argspec = inspect.getargspec(attr) # pylint: disable=deprecated-method 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)) priority = get_priority(attr) hostside = ' [hostside]' if is_hostside(attr) else '' logger.debug('\tConnecting %s to %s with priority %s(%d)%s', attr.__name__, SIGNAL_MAP[attr_name], priority.name, priority.value, hostside) mc = ManagedCallback(instrument, attr) _callbacks.append(mc) signal.connect(mc, SIGNAL_MAP[attr_name], priority=priority.value) instrument.logger.context = context installed.append(instrument) context.add_augmentation(instrument)
def __init__(self, target, logcat_poll_period=None, disable_selinux=True): self.target = target self.logcat_poll_period = logcat_poll_period self.disable_selinux = disable_selinux self.logcat_poller = None self.logger = logging.getLogger('logcat') self._logcat_marker_msg = None self._logcat_marker_tag = None signal.connect(self._before_workload, signal.BEFORE_WORKLOAD_EXECUTION) if self.logcat_poll_period: signal.connect(self._after_workload, signal.AFTER_WORKLOAD_EXECUTION) if self.target.is_rooted and self.disable_selinux: self.do_disable_selinux()
def test_job_retry_status(self): job_spec = get_jobspec() context = get_context() job = Job_force_retry(2, job_spec, 1, context) job.workload = Mock() context.cm._joblist = [job] context.run_state.add_job(job) verifier = lambda _: assert_equal(job.status, Status.PENDING) signal.connect(verifier, signal.JOB_RESTARTED) runner = Runner(context, MockProcessorManager()) runner.run() signal.disconnect(verifier, signal.JOB_RESTARTED)
def execute(self, config_manager, output): """ Execute the run specified by an agenda. Optionally, selectors may be used to only execute a subset of the specified agenda. Params:: :state: a ``ConfigManager`` containing processed configuration :output: an initialized ``RunOutput`` that will be used to store the results. """ signal.connect(self._error_signalled_callback, signal.ERROR_LOGGED) signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED) self.logger.info('Initializing run') self.logger.debug('Finalizing run configuration.') config = config_manager.finalize() output.write_config(config) self.target_manager = TargetManager(config.run_config.device, config.run_config.device_config, output.basepath) self.logger.info('Initializing execution context') context = ExecutionContext(config_manager, self.target_manager, output) try: self.do_execute(context) except KeyboardInterrupt as e: context.run_output.status = Status.ABORTED log.log_error(e, self.logger) context.write_output() raise except Exception as e: context.run_output.status = Status.FAILED log.log_error(e, self.logger) context.write_output() raise finally: context.finalize() self.execute_postamble(context, output) signal.send(signal.RUN_COMPLETED, self, context)
def execute(self, config_manager, output): """ Execute the run specified by an agenda. Optionally, selectors may be used to only selecute a subset of the specified agenda. Params:: :state: a ``ConfigManager`` containing processed configuration :output: an initialized ``RunOutput`` that will be used to store the results. """ signal.connect(self._error_signalled_callback, signal.ERROR_LOGGED) signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED) self.logger.info('Initializing run') self.logger.debug('Finalizing run configuration.') config = config_manager.finalize() output.write_config(config) self.target_manager = TargetManager(config.run_config.device, config.run_config.device_config, output.basepath) self.logger.info('Initializing execution context') context = ExecutionContext(config_manager, self.target_manager, output) try: self.do_execute(context) except KeyboardInterrupt as e: context.run_output.status = 'ABORTED' log.log_error(e, self.logger) context.write_output() raise except Exception as e: context.run_output.status = 'FAILED' log.log_error(e, self.logger) context.write_output() raise finally: context.finalize() self.execute_postamble(context, output) signal.send(signal.RUN_COMPLETED, self, context)
def test_wrap_propagate(self): d = {'before': False, 'after': False, 'success': False} def before(): d['before'] = True def after(): d['after'] = True def success(): d['success'] = True signal.connect(before, signal.BEFORE_WORKLOAD_SETUP) signal.connect(after, signal.AFTER_WORKLOAD_SETUP) signal.connect(success, signal.SUCCESSFUL_WORKLOAD_SETUP) caught = False try: with signal.wrap('WORKLOAD_SETUP'): raise RuntimeError() except RuntimeError: caught = True assert_true(d['before']) assert_true(d['after']) assert_true(caught) assert_false(d['success'])
def test_ConnectNotify(self): one = Callable(1) two = Callable(2) three = Callable(3) signal.connect(two, 'test', priority=200) signal.connect(one, 'test', priority=100) signal.connect(three, 'test', priority=300) result = [i[1] for i in signal.send('test')] assert_equal(result, [3, 2, 1])
def test_ConnectNotify(self): one = Callable(1) two = Callable(2) three = Callable(3) signal.connect( two, 'test', priority=200 ) signal.connect( one, 'test', priority=100 ) signal.connect( three, 'test', priority=300 ) result = [i[1] for i in signal.send('test')] assert_equal(result, [3, 2, 1])
def test_wrap_propagate(self): d = {'before': False, 'after': False, 'success': False} def before(): d['before'] = True def after(): d['after'] = True def success(): d['success'] = True signal.connect(before, signal.BEFORE_WORKLOAD_SETUP) signal.connect(after, signal.AFTER_WORKLOAD_SETUP) signal.connect(success, signal.SUCCESSFUL_WORKLOAD_SETUP) caught = False try: with signal.wrap('WORKLOAD_SETUP'): raise RuntimeError() except RuntimeError: caught=True assert_true(d['before']) assert_true(d['after']) assert_true(caught) assert_false(d['success'])
def initialize(self, context): if self.delete_output: self.logger.debug('Registering RUN_FINALIZED handler.') signal.connect(self.delete_output_directory, signal.RUN_FINALIZED, priority=-100)
def setUp(self): signal.connect(self._call_me_once, 'first') signal.connect(self._call_me_once, 'second')
def initialise_signals(self): signal.connect(self._verify_serialized_state, signal.RUN_INITIALIZED) signal.connect(self._verify_serialized_state, signal.JOB_STARTED) signal.connect(self._verify_serialized_state, signal.JOB_RESTARTED) signal.connect(self._verify_serialized_state, signal.JOB_COMPLETED) signal.connect(self._verify_serialized_state, signal.JOB_FAILED) signal.connect(self._verify_serialized_state, signal.JOB_ABORTED) signal.connect(self._verify_serialized_state, signal.RUN_FINALIZED)
def initialise_signals(self): signal.connect(self._verify_restarted_job_status, signal.JOB_RESTARTED)