Пример #1
0
def find_plugin(
    name,
    find_in_std_env_var=True,
    find_in_user_dir=True,
    find_in_sys_dir=True,
    find_in_static=True,
    fail_on_load_error=False,
):
    utils._check_str(name)
    utils._check_bool(fail_on_load_error)
    status, ptr = native_bt.bt2_plugin_find(
        name,
        int(find_in_std_env_var),
        int(find_in_user_dir),
        int(find_in_sys_dir),
        int(find_in_static),
        int(fail_on_load_error),
    )

    if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
        return

    utils._handle_func_status(status, 'failed to find plugin')
    assert ptr is not None
    return _Plugin._create_from_ptr(ptr)
    def __init__(self, source_component_specs, filter_component_specs=None,
                 message_types=None, stream_intersection_mode=False,
                 begin=None, end=None):
        utils._check_bool(stream_intersection_mode)
        self._stream_intersection_mode = stream_intersection_mode
        self._begin_ns = _get_ns(begin)
        self._end_ns = _get_ns(end)
        self._message_types = message_types

        if type(source_component_specs) is ComponentSpec:
            source_component_specs = [source_component_specs]

        if type(filter_component_specs) is ComponentSpec:
            filter_component_specs = [filter_component_specs]
        elif filter_component_specs is None:
            filter_component_specs = []

        self._src_comp_specs = source_component_specs
        self._flt_comp_specs = filter_component_specs
        self._next_suffix = 1
        self._connect_ports = False

        # lists of _ComponentAndSpec
        self._src_comps_and_specs = []
        self._flt_comps_and_specs = []

        self._validate_component_specs(source_component_specs)
        self._validate_component_specs(filter_component_specs)
        self._build_graph()
    def __init__(
        self,
        source_component_specs,
        filter_component_specs=None,
        stream_intersection_mode=False,
        begin=None,
        end=None,
    ):
        utils._check_bool(stream_intersection_mode)
        self._stream_intersection_mode = stream_intersection_mode
        self._begin_ns = _get_ns(begin)
        self._end_ns = _get_ns(end)
        self._msg_list = [None]

        if type(source_component_specs) is ComponentSpec:
            source_component_specs = [source_component_specs]

        if type(filter_component_specs) is ComponentSpec:
            filter_component_specs = [filter_component_specs]
        elif filter_component_specs is None:
            filter_component_specs = []

        self._src_comp_specs = source_component_specs
        self._flt_comp_specs = filter_component_specs
        self._next_suffix = 1
        self._connect_ports = False

        # lists of _ComponentAndSpec
        self._src_comps_and_specs = []
        self._flt_comps_and_specs = []

        self._validate_component_specs(source_component_specs)
        self._validate_component_specs(filter_component_specs)
        self._build_graph()
Пример #4
0
    def _set_supports_discarded_events(self, supports, with_cs=False):
        utils._check_bool(supports)
        utils._check_bool(with_cs)

        if not supports and with_cs:
            raise ValueError(
                'cannot not support discarded events, but have default clock snapshots'
            )

        native_bt.stream_class_set_supports_discarded_events(
            self._ptr, supports, with_cs)
Пример #5
0
 def _bt_can_seek_beginning_from_native(self):
     # Here, we mimic the behavior of the C API:
     #
     # - If the iterator has a _user_can_seek_beginning method,
     #   read it and use that result.
     # - Otherwise, the presence or absence of a `_user_seek_beginning`
     #   method indicates whether the iterator can seek beginning.
     if hasattr(self, '_user_can_seek_beginning'):
         can_seek_beginning = self._user_can_seek_beginning()
         utils._check_bool(can_seek_beginning)
         return can_seek_beginning
     else:
         return hasattr(self, '_user_seek_beginning')
Пример #6
0
def find_plugins(path, recurse=True):
    utils._check_str(path)
    utils._check_bool(recurse)
    plugin_set_ptr = None

    if os.path.isfile(path):
        plugin_set_ptr = native_bt.plugin_find_all_from_file(path)
    elif os.path.isdir(path):
        plugin_set_ptr = native_bt.plugin_find_all_from_dir(path, int(recurse))

    if plugin_set_ptr is None:
        return

    return _PluginSet._create_from_ptr(plugin_set_ptr)
Пример #7
0
def find_plugins(path, recurse=True):
    utils._check_str(path)
    utils._check_bool(recurse)
    plugin_set_ptr = None

    if os.path.isfile(path):
        plugin_set_ptr = native_bt.plugin_create_all_from_file(path)
    elif os.path.isdir(path):
        plugin_set_ptr = native_bt.plugin_create_all_from_dir(path, int(recurse))

    if plugin_set_ptr is None:
        return

    return _PluginSet._create_from_ptr(plugin_set_ptr)
Пример #8
0
 def create_option_with_bool_selector_field_class(
         self,
         content_fc,
         selector_fc,
         selector_is_reversed=False,
         user_attributes=None):
     utils._check_type(content_fc, bt2_field_class._FieldClass)
     utils._check_bool(selector_is_reversed)
     utils._check_type(selector_fc, bt2_field_class._BoolFieldClass)
     ptr = native_bt.field_class_option_with_selector_field_bool_create(
         self._ptr, content_fc._ptr, selector_fc._ptr)
     self._check_field_class_create_status(ptr, 'option')
     fc = bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr)
     self._set_field_class_user_attrs(fc, user_attributes)
     fc._selector_is_reversed = selector_is_reversed
     return fc
Пример #9
0
    def _bt_can_seek_ns_from_origin_from_native(self, ns_from_origin):
        # Return whether the iterator can seek ns from origin using the
        # user-implemented seek_ns_from_origin method.  We mimic the behavior
        # of the C API:
        #
        # - If the iterator has a _user_can_seek_ns_from_origin method,
        #   call it and use its return value.
        # - Otherwise, if there is a `_user_seek_ns_from_origin` method,
        #   we presume it's possible.

        if hasattr(self, '_user_can_seek_ns_from_origin'):
            can_seek_ns_from_origin = self._user_can_seek_ns_from_origin(
                ns_from_origin)
            utils._check_bool(can_seek_ns_from_origin)
            return can_seek_ns_from_origin
        else:
            return hasattr(self, '_user_seek_ns_from_origin')
Пример #10
0
def find_plugins_in_path(path, recurse=True, fail_on_load_error=False):
    utils._check_str(path)
    utils._check_bool(recurse)
    utils._check_bool(fail_on_load_error)
    plugin_set_ptr = None

    if os.path.isfile(path):
        status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_file(
            path, fail_on_load_error)
    elif os.path.isdir(path):
        status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_dir(
            path, int(recurse), int(fail_on_load_error))
    else:
        raise ValueError("invalid path: '{}'".format(path))

    if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
        return

    utils._handle_func_status(status, 'failed to find plugins')
    assert plugin_set_ptr is not None
    return _PluginSet._create_from_ptr(plugin_set_ptr)
Пример #11
0
    def _set_supports_packets(self,
                              supports,
                              with_begin_cs=False,
                              with_end_cs=False):
        utils._check_bool(supports)
        utils._check_bool(with_begin_cs)
        utils._check_bool(with_end_cs)

        if not supports and (with_begin_cs or with_end_cs):
            raise ValueError(
                'cannot not support packets, but have default clock snapshots')

        if not supports and self.packet_context_field_class is not None:
            raise ValueError(
                'stream class already has a packet context field class')

        native_bt.stream_class_set_supports_packets(self._ptr, supports,
                                                    with_begin_cs, with_end_cs)
Пример #12
0
    def _validate_create_params(
        cls,
        name,
        user_attributes,
        packet_context_field_class,
        event_common_context_field_class,
        default_clock_class,
        assigns_automatic_event_class_id,
        assigns_automatic_stream_id,
        supports_packets,
        packets_have_beginning_default_clock_snapshot,
        packets_have_end_default_clock_snapshot,
        supports_discarded_events,
        discarded_events_have_default_clock_snapshots,
        supports_discarded_packets,
        discarded_packets_have_default_clock_snapshots,
    ):
        # Name
        if name is not None:
            utils._check_str(name)

        # User attributes
        if user_attributes is not None:
            value = bt2_value.create_value(user_attributes)
            utils._check_type(value, bt2_value.MapValue)

        # Packet context field class
        if packet_context_field_class is not None:
            if not supports_packets:
                raise ValueError(
                    'cannot have a packet context field class without supporting packets'
                )

            utils._check_type(packet_context_field_class,
                              bt2_field_class._StructureFieldClass)

        # Event common context field class
        if event_common_context_field_class is not None:
            utils._check_type(event_common_context_field_class,
                              bt2_field_class._StructureFieldClass)

        # Default clock class
        if default_clock_class is not None:
            utils._check_type(default_clock_class, bt2_clock_class._ClockClass)

        # Assigns automatic event class id
        utils._check_bool(assigns_automatic_event_class_id)

        # Assigns automatic stream id
        utils._check_bool(assigns_automatic_stream_id)

        # Packets
        utils._check_bool(supports_packets)
        utils._check_bool(packets_have_beginning_default_clock_snapshot)
        utils._check_bool(packets_have_end_default_clock_snapshot)

        if not supports_packets:
            if packets_have_beginning_default_clock_snapshot:
                raise ValueError(
                    'cannot not support packets, but have packet beginning default clock snapshot'
                )
            if packets_have_end_default_clock_snapshot:
                raise ValueError(
                    'cannot not support packets, but have packet end default clock snapshots'
                )

        # Discarded events
        utils._check_bool(supports_discarded_events)
        utils._check_bool(discarded_events_have_default_clock_snapshots)

        if (not supports_discarded_events
                and discarded_events_have_default_clock_snapshots):
            raise ValueError(
                'cannot not support discarded events, but have default clock snapshots for discarded event messages'
            )

        # Discarded packets
        utils._check_bool(supports_discarded_packets)
        utils._check_bool(discarded_packets_have_default_clock_snapshots)

        if supports_discarded_packets and not supports_packets:
            raise ValueError(
                'cannot support discarded packets, but not support packets')

        if (not supports_discarded_packets
                and discarded_packets_have_default_clock_snapshots):
            raise ValueError(
                'cannot not support discarded packets, but have default clock snapshots for discarded packet messages'
            )
Пример #13
0
 def _assigns_automatic_stream_class_id(self, auto_id):
     utils._check_bool(auto_id)
     return native_bt.trace_class_set_assigns_automatic_stream_class_id(
         self._ptr, auto_id)
Пример #14
0
 def is_absolute(self, is_absolute):
     utils._check_bool(is_absolute)
     ret = native_bt.ctf_clock_class_set_is_absolute(self._ptr, int(is_absolute))
     utils._handle_ret(ret, "cannot set clock class object's absoluteness")
Пример #15
0
 def is_absolute(self, is_absolute):
     utils._check_bool(is_absolute)
     ret = native_bt.ctf_clock_set_is_absolute(self._ptr, int(is_absolute))
     utils._handle_ret(ret,
                       "cannot set CTF writer clock object's absoluteness")
Пример #16
0
 def _origin_is_unix_epoch(self, origin_is_unix_epoch):
     utils._check_bool(origin_is_unix_epoch)
     native_bt.clock_class_set_origin_is_unix_epoch(
         self._ptr, int(origin_is_unix_epoch)
     )
Пример #17
0
 def is_signed(self, is_signed):
     utils._check_bool(is_signed)
     ret = native_bt.field_class_integer_set_is_signed(self._ptr, int(is_signed))
     utils._handle_ret(ret, "cannot set integer field class object's signedness")
Пример #18
0
 def _has_field(self, value):
     utils._check_bool(value)
     native_bt.field_option_set_has_field(self._ptr, value)
Пример #19
0
 def is_signed(self, is_signed):
     utils._check_bool(is_signed)
     ret = native_bt.ctf_field_type_integer_set_signed(self._ptr, int(is_signed))
     utils._handle_ret(ret, "cannot set integer field type object's signedness")
Пример #20
0
 def can_seek_forward(self, value):
     utils._check_bool(value)
     native_bt.self_message_iterator_configuration_set_can_seek_forward(
         self._ptr, value)
    def __init__(
        self,
        source_component_specs,
        filter_component_specs=None,
        stream_intersection_mode=False,
        begin=None,
        end=None,
        plugin_set=None,
    ):
        utils._check_bool(stream_intersection_mode)
        self._stream_intersection_mode = stream_intersection_mode
        self._begin_ns = _get_ns(begin)
        self._end_ns = _get_ns(end)
        self._msg_list = [None]

        # If a single item is provided, convert to a list.
        if type(source_component_specs) in (
                ComponentSpec,
                AutoSourceComponentSpec,
                str,
        ):
            source_component_specs = [source_component_specs]

        # Convert any string to an AutoSourceComponentSpec.
        def str_to_auto(item):
            if type(item) is str:
                item = AutoSourceComponentSpec(item)

            return item

        source_component_specs = [
            str_to_auto(s) for s in source_component_specs
        ]

        if type(filter_component_specs) is ComponentSpec:
            filter_component_specs = [filter_component_specs]
        elif filter_component_specs is None:
            filter_component_specs = []

        self._validate_source_component_specs(source_component_specs)
        self._validate_filter_component_specs(filter_component_specs)

        # Pass any `ComponentSpec` instance as-is.
        self._src_comp_specs = [
            spec for spec in source_component_specs
            if type(spec) is ComponentSpec
        ]

        # Convert any `AutoSourceComponentSpec` in concrete `ComponentSpec` instances.
        auto_src_comp_specs = [
            spec for spec in source_component_specs
            if type(spec) is AutoSourceComponentSpec
        ]
        self._src_comp_specs += _auto_discover_source_component_specs(
            auto_src_comp_specs, plugin_set)

        self._flt_comp_specs = filter_component_specs
        self._next_suffix = 1
        self._connect_ports = False

        # lists of _ComponentAndSpec
        self._src_comps_and_specs = []
        self._flt_comps_and_specs = []

        self._build_graph()
Пример #22
0
 def is_absolute(self, is_absolute):
     utils._check_bool(is_absolute)
     ret = native_bt.clock_class_set_is_absolute(self._ptr, int(is_absolute))
     utils._handle_ret(ret, "cannot set clock class object's absoluteness")
Пример #23
0
 def _selector_is_reversed(self, selector_is_reversed):
     utils._check_bool(selector_is_reversed)
     native_bt.field_class_option_with_selector_field_bool_set_selector_is_reversed(
         self._ptr, selector_is_reversed
     )
Пример #24
0
 def is_signed(self, is_signed):
     utils._check_bool(is_signed)
     ret = native_bt.field_class_integer_set_is_signed(
         self._ptr, int(is_signed))
     utils._handle_ret(
         ret, "cannot set integer field class object's signedness")
Пример #25
0
 def _is_single_precision(self, is_single_precision):
     utils._check_bool(is_single_precision)
     native_bt.field_class_real_set_is_single_precision(
         self._ptr, is_single_precision)