def _handle_ret(ret, msg=None): if int(ret) < 0: if msg is None: error = bt2.Error() else: error = bt2.Error(msg) raise error
def _handle_ptr(ptr, msg=None): if ptr is None: if msg is None: error = bt2.Error() else: error = bt2.Error(msg) raise error
def _create_muxer(self): plugin = bt2.find_plugin('utils') if plugin is None: raise bt2.Error('cannot find "utils" plugin (needed for the muxer)') if 'muxer' not in plugin.filter_component_classes: raise bt2.Error('cannot find "muxer" filter component class in "utils" plugin') comp_cls = plugin.filter_component_classes['muxer'] return self._graph.add_component(comp_cls, 'muxer')
def id(self): id = native_bt.ctf_event_class_get_id(self._ptr) if utils._is_m1ull(id): raise bt2.Error("cannot get event class object's ID") return id
def frequency(self): frequency = native_bt.ctf_clock_get_frequency(self._ptr) if utils._is_m1ull(frequency): raise bt2.Error("cannot get CTF writer clock object's frequency") return frequency
def _handle_status(status, gen_error_msg): if status == native_bt.CONNECTION_STATUS_GRAPH_IS_CANCELED: raise bt2.GraphCanceled elif status == native_bt.CONNECTION_STATUS_IS_ENDED: raise bt2.ConnectionEnded elif status < 0: raise bt2.Error(gen_error_msg)
def uuid(self): uuid_bytes = native_bt.ctf_clock_get_uuid(self._ptr) if uuid_bytes is None: raise bt2.Error("cannot get CTF writer clock object's UUID") return uuidp.UUID(bytes=uuid_bytes)
def _handle_status(self, status, gen_error_msg): if status == native_bt.NOTIFICATION_ITERATOR_STATUS_END: raise bt2.Stop elif status == native_bt.NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED: raise bt2.UnsupportedFeature elif status < 0: raise bt2.Error(gen_error_msg)
def precision(self): precision = native_bt.ctf_clock_get_precision(self._ptr) if utils._is_m1ull(precision): raise bt2.Error("cannot get CTF writer clock object's precision") return precision
def create_plugins_from_dir(path, recurse=True): utils._check_str(path) plugin_ptrs = native_bt.py3_plugin_create_all_from_dir(path, recurse) if plugin_ptrs is None: raise bt2.Error('cannot get plugin objects from directory') return _plugin_ptrs_to_plugins(plugin_ptrs)
def create_plugins_from_file(path): utils._check_str(path) plugin_ptrs = native_bt.py3_plugin_create_all_from_file(path) if plugin_ptrs is None: raise bt2.Error('cannot get plugin objects from file') return _plugin_ptrs_to_plugins(plugin_ptrs)
def _create_from_ptr(ptr): msg_type = native_bt.message_get_type(ptr) cls = None if msg_type not in _MESSAGE_TYPE_TO_CLS: raise bt2.Error('unknown message type: {}'.format(msg_type)) return _MESSAGE_TYPE_TO_CLS[msg_type]._create_from_ptr(ptr)
def _create_from_ptr(ptr): notif_type = native_bt.notification_get_type(ptr) cls = None if notif_type not in _NOTIF_TYPE_TO_CLS: raise bt2.Error('unknown notification type: {}'.format(notif_type)) return _NOTIF_TYPE_TO_CLS[notif_type]._create_from_ptr(ptr)
def _handle_status(self, status, gen_error_msg): if status == native_bt.COMPONENT_STATUS_END: raise bt2.Stop elif status == native_bt.COMPONENT_STATUS_AGAIN: raise bt2.TryAgain elif status == native_bt.COMPONENT_STATUS_UNSUPPORTED: raise bt2.UnsupportedFeature elif status < 0: raise bt2.Error(gen_error_msg)
def _create_trimmer(self, begin, end, name): plugin = bt2.find_plugin('utils') if plugin is None: raise bt2.Error('cannot find "utils" plugin (needed for the trimmer)') if 'trimmer' not in plugin.filter_component_classes: raise bt2.Error('cannot find "trimmer" filter component class in "utils" plugin') params = {} if begin is not None: params['begin'] = begin if end is not None: params['end'] = end comp_cls = plugin.filter_component_classes['trimmer'] return self._graph.add_component(comp_cls, name, params)
def _handle_status(self, status, gen_error_msg): if status == native_bt.NOTIFICATION_ITERATOR_STATUS_CANCELED: raise bt2.NotificationIteratorCanceled elif status == native_bt.NOTIFICATION_ITERATOR_STATUS_AGAIN: raise bt2.TryAgain elif status == native_bt.NOTIFICATION_ITERATOR_STATUS_END: raise bt2.Stop elif status == native_bt.NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED: raise bt2.UnsupportedFeature elif status < 0: raise bt2.Error(gen_error_msg)
def _handle_status(self, status, gen_error_msg): if status == native_bt.GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: raise bt2.PortConnectionRefused elif status == native_bt.GRAPH_STATUS_CANCELED: raise bt2.GraphCanceled elif status == native_bt.GRAPH_STATUS_END: raise bt2.Stop elif status == native_bt.GRAPH_STATUS_AGAIN: raise bt2.TryAgain elif status < 0: raise bt2.Error(gen_error_msg)
def _handle_status(self, status, gen_error_msg): if status == native_bt.MESSAGE_ITERATOR_STATUS_CANCELED: raise bt2.MessageIteratorCanceled elif status == native_bt.MESSAGE_ITERATOR_STATUS_AGAIN: raise bt2.TryAgain elif status == native_bt.MESSAGE_ITERATOR_STATUS_END: raise bt2.Stop elif status == native_bt.MESSAGE_ITERATOR_STATUS_UNSUPPORTED: raise bt2.UnsupportedFeature elif status < 0: raise bt2.Error(gen_error_msg)
def _create_from_ptr(ptr): port_type = native_bt.port_get_type(ptr) if port_type == native_bt.PORT_TYPE_INPUT: cls = _InputPort elif port_type == native_bt.PORT_TYPE_OUTPUT: cls = _OutputPort else: raise bt2.Error('unknown port type: {}'.format(port_type)) return cls._create_from_ptr(ptr)
def _handle_status(self, status, gen_error_msg): if status == native_bt.QUERY_EXECUTOR_STATUS_AGAIN: raise bt2.TryAgain elif status == native_bt.QUERY_EXECUTOR_STATUS_CANCELED: raise bt2.QueryExecutorCanceled elif status == native_bt.QUERY_EXECUTOR_STATUS_INVALID_OBJECT: raise bt2.InvalidQueryObject elif status == native_bt.QUERY_EXECUTOR_STATUS_INVALID_PARAMS: raise bt2.InvalidQueryParams elif status < 0: raise bt2.Error(gen_error_msg)
def _create_comp(self, comp_spec, comp_cls_type): plugin = bt2.find_plugin(comp_spec.plugin_name) if plugin is None: raise bt2.Error('no such plugin: {}'.format(comp_spec.plugin_name)) if comp_cls_type == _CompClsType.SOURCE: comp_classes = plugin.source_component_classes else: comp_classes = plugin.filter_component_classes if comp_spec.component_class_name not in comp_classes: cc_type = 'source' if comp_cls_type == _CompClsType.SOURCE else 'filter' raise bt2.Error('no such {} component class in "{}" plugin: {}'.format(cc_type, comp_spec.plugin_name, comp_spec.component_class_name)) comp_cls = comp_classes[comp_spec.component_class_name] name = self._get_unique_comp_name(comp_spec) comp = self._graph.add_component(comp_cls, name, comp_spec.params) return comp
def _create_stream_intersection_trimmer(self, port): # find the original parameters specified by the user to create # this port's component to get the `path` parameter for src_comp_and_spec in self._src_comps_and_specs: if port.component == src_comp_and_spec.comp: params = src_comp_and_spec.spec.params break try: path = params['path'] except: raise bt2.Error('all source components must be created with a "path" parameter in stream intersection mode') params = {'path': str(path)} # query the port's component for the `trace-info` object which # contains the stream intersection range for each exposed # trace query_exec = bt2.QueryExecutor() trace_info_res = query_exec.query(port.component.component_class, 'trace-info', params) begin = None end = None # find the trace info for this port's trace by name's prefix try: for trace_info in trace_info_res: if port.name.startswith(str(trace_info['path'])): range_ns = trace_info['intersection-range-ns'] begin = range_ns['begin'] end = range_ns['end'] break except: pass if begin is None or end is None: raise bt2.Error('cannot find stream intersection range for port "{}"'.format(port.name)) name = 'trimmer-{}-{}'.format(port.component.name, port.name) return self._create_trimmer(begin, end, name)
def _handle_component_status(status, gen_error_msg): if status == native_bt.COMPONENT_STATUS_END: raise bt2.Stop elif status == native_bt.COMPONENT_STATUS_AGAIN: raise bt2.TryAgain elif status == native_bt.COMPONENT_STATUS_UNSUPPORTED: raise bt2.UnsupportedFeature elif status == native_bt.COMPONENT_STATUS_REFUSE_PORT_CONNECTION: raise bt2.PortConnectionRefused elif status == native_bt.COMPONENT_STATUS_GRAPH_IS_CANCELED: raise bt2.GraphCanceled elif status < 0: raise bt2.Error(gen_error_msg)
def __call__(self, value=None): field_ptr = native_bt.ctf_field_create(self._ptr) if field_ptr is None: raise bt2.CreationError('cannot create {} field object'.format(self._NAME.lower())) field = bt2.fields._create_from_ptr(field_ptr) if value is not None: if not isinstance(field, (bt2.fields._IntegerField, bt2.fields._FloatingPointNumberField, bt2.fields._StringField)): raise bt2.Error('cannot assign an initial value to a {} field object'.format(field._NAME)) field.value = value return field
def _handle_status(self, status, gen_error_msg): if status == native_bt.GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: raise bt2.PortConnectionRefused elif status == native_bt.GRAPH_STATUS_CANCELED: raise bt2.GraphCanceled elif status == native_bt.GRAPH_STATUS_END: raise bt2.Stop elif status == native_bt.GRAPH_STATUS_AGAIN: raise bt2.TryAgain elif status == native_bt.GRAPH_STATUS_NO_SINK: raise bt2.NoSinkComponent elif status == native_bt.GRAPH_STATUS_CANNOT_CONSUME: raise bt2.CannotConsumeGraph elif status < 0: raise bt2.Error(gen_error_msg)
def __next__(self): if self._at == len(self._trace): raise StopIteration sc_ptr = native_bt.ctf_trace_get_stream_class(self._trace._ptr, self._at) utils._handle_ptr( sc_ptr, "cannot get trace class object's stream class object") id = native_bt.ctf_stream_class_get_id(sc_ptr) native_bt.put(sc_ptr) if utils._is_m1ull(id): raise bt2.Error("cannot get stream class object's ID") self._at += 1 return id
def _query(comp_cls_ptr, obj, params): utils._check_str(obj) if params is None: params_ptr = native_bt.value_null else: params = bt2.create_value(params) params_ptr = params._ptr results_ptr = native_bt.component_class_query(comp_cls_ptr, obj, params_ptr) if results_ptr is None: raise bt2.Error('cannot query info with object "{}"'.format(obj)) if results_ptr == native_bt.value_null: return return bt2.values._create_from_ptr(results_ptr)
def _get(self): if self._cur_notif is None: raise bt2.Error('nothing here!') return self._cur_notif
def _disconnect(ptr): status = native_bt.port_disconnect(ptr) if status < 0: raise bt2.Error('cannot disconnect port')
def remove_from_component(self): status = native_bt.private_port_remove_from_component(self._ptr) if status < 0: raise bt2.Error("cannot remove port from component")