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 _discover_cooling_module(self): cooling_module = None for module in self.active_cooling_modules: if self.target.has(module): if not cooling_module: cooling_module = getattr(self.target, identifier(module)) else: msg = 'Multiple cooling modules found "{}" "{}".' raise InstrumentError( msg.format(cooling_module.name, module)) return cooling_module
def update_output(self, context): host_output_file = os.path.join(context.output_directory, 'poller.csv') self.target.pull(self.target_output_path, host_output_file) context.add_artifact('poller-output', host_output_file, kind='data') host_log_file = os.path.join(context.output_directory, 'poller.log') self.target.pull(self.target_log_path, host_log_file) context.add_artifact('poller-log', host_log_file, kind='log') with open(host_log_file) as fh: for line in fh: if 'ERROR' in line: raise InstrumentError(line.strip()) if 'WARNING' in line: self.logger.warning(line.strip())
def initialize(self, context): if self.active_cooling: self.cooling = self._discover_cooling_module() if not self.cooling: msg = 'Cooling module not found on target. Please install one of the following modules: {}' raise InstrumentError(msg.format(self.active_cooling_modules)) if self.temperature_between_jobs == 0: temp = self.target.read_int(self.temperature_file) self.logger.debug( 'Setting temperature threshold between jobs to {}'.format( temp)) self.temperature_between_jobs = temp if self.temperature_between_specs == 0: temp = self.target.read_int(self.temperature_file) msg = 'Setting temperature threshold between workload specs to {}' self.logger.debug(msg.format(temp)) self.temperature_between_specs = temp
def update_output(self, context): for device, instrument in self.instruments.items(): # Append the device key to the filename and artifact name, unless # it's None (as it will be for backends with only 1 # devce/instrument) if len(self.instruments) > 1: name = 'energy_instrument_output_{}'.format(device) else: name = 'energy_instrument_output' outfile = os.path.join(context.output_directory, '{}.csv'.format(name)) measurements = instrument.get_data(outfile) if not measurements: raise InstrumentError("Failed to collect energy data from {}" .format(self.backend.name)) self.measurement_csvs[device] = measurements context.add_artifact(name, measurements.path, 'data', classifiers={'device': device}) self.extract_metrics(context)
def _adjust_timestamps(self, context): output_file = context.get_artifact_path('poller-output') message = 'Adjusting timestamps inside "{}" to align with ftrace' self.logger.debug(message.format(output_file)) trace_txt = context.get_artifact_path('trace-cmd-txt') trace_parser = TraceCmdParser(filter_markers=False) marker_timestamp = None for event in trace_parser.parse(trace_txt): if event.name == 'print' and 'POLLER_START' in event.text: marker_timestamp = event.timestamp break if marker_timestamp is None: raise InstrumentError('Did not see poller marker in ftrace') df = pd.read_csv(output_file) df.time -= df.time[0] df.time += marker_timestamp df.to_csv(output_file, index=False)
def validate(self): if self.report and not self.report_on_target and not which( 'trace-cmd'): raise InstrumentError('trace-cmd is not in PATH; is it installed?')
def initialize(self, context): # pylint: disable=unused-argument self.need_root = self.target.os == 'android' if self.need_root and not self.target.is_rooted: raise InstrumentError('Need root to collect dmesg on Android')