def __init__(self, element_field_class, length): utils._check_type(element_field_class, _FieldClass) utils._check_uint64(length) ptr = native_bt.field_class_array_create(element_field_class._ptr, length) self._check_create_status(ptr) super().__init__(ptr)
def __init__(self, size, alignment=None, byte_order=None, is_signed=None, base=None, encoding=None, mapped_clock_class=None): utils._check_uint64(size) if size == 0: raise ValueError('size is 0 bits') ptr = native_bt.field_class_integer_create(size) self._check_create_status(ptr) super().__init__(ptr) if alignment is not None: self.alignment = alignment if byte_order is not None: self.byte_order = byte_order if is_signed is not None: self.is_signed = is_signed if base is not None: self.base = base if encoding is not None: self.encoding = encoding if mapped_clock_class is not None: self.mapped_clock_class = mapped_clock_class
def __init__(self, name, frequency, description=None, precision=None, offset=None, is_absolute=None, uuid=None): utils._check_str(name) utils._check_uint64(frequency) ptr = native_bt.clock_class_create(name, frequency) if ptr is None: raise bt2.CreationError('cannot create clock class object') super().__init__(ptr) if description is not None: self.description = description if frequency is not None: self.frequency = frequency if precision is not None: self.precision = precision if offset is not None: self.offset = offset if is_absolute is not None: self.is_absolute = is_absolute if uuid is not None: self.uuid = uuid
def cycles_to_ns_from_origin(self, cycles): utils._check_uint64(cycles) status, ns = native_bt.clock_class_cycles_to_ns_from_origin( self._ptr, cycles) error_msg = "cannot convert clock value to nanoseconds from origin for given clock class" utils._handle_func_status(status, error_msg) return ns
def at_index(self, index): utils._check_uint64(index) field_ptr = native_bt.ctf_field_structure_get_field_by_index( self._ptr, index) utils._handle_ptr(field_ptr, "cannot get structure field object's field") return _create_from_ptr(field_ptr)
def _create_packet_end_message(self, packet, default_clock_snapshot=None): utils._check_type(packet, bt2_packet._Packet) if packet.stream.cls.packets_have_end_default_clock_snapshot: if default_clock_snapshot is None: raise ValueError( "packet end messages in this stream must have a default clock snapshot" ) utils._check_uint64(default_clock_snapshot) ptr = native_bt.message_packet_end_create_with_default_clock_snapshot( self._bt_ptr, packet._ptr, default_clock_snapshot) else: if default_clock_snapshot is not None: raise ValueError( "packet end messages in this stream must not have a default clock snapshot" ) ptr = native_bt.message_packet_end_create(self._bt_ptr, packet._ptr) if ptr is None: raise bt2._MemoryError('cannot create packet end message object') return bt2_message._PacketEndMessage(ptr)
def create_stream(self, stream_class, id=None, name=None): utils._check_type(stream_class, bt2_stream_class._StreamClass) if stream_class.assigns_automatic_stream_id: if id is not None: raise ValueError( "id provided, but stream class assigns automatic stream ids" ) stream_ptr = native_bt.stream_create(stream_class._ptr, self._ptr) else: if id is None: raise ValueError( "id not provided, but stream class does not assign automatic stream ids" ) utils._check_uint64(id) stream_ptr = native_bt.stream_create_with_id( stream_class._ptr, self._ptr, id ) if stream_ptr is None: raise bt2._MemoryError('cannot create stream object') stream = bt2_stream._Stream._create_from_ptr(stream_ptr) if name is not None: stream._name = name return stream
def __setitem__(self, key, value): utils._check_type(key, bt2.ClockClass) utils._check_uint64(value) ret = native_bt.clock_class_priority_map_add_clock_class(self._ptr, key._ptr, value) utils._handle_ret(ret, "cannot set clock class's priority in clock class priority map object")
def _set_count(self, count): utils._check_uint64(count) if count == 0: raise ValueError('discarded {} count is 0'.format(self._item_name)) self._set_count(self._ptr, count)
def __getitem__(self, key): utils._check_uint64(key) sc_ptr = self._borrow_stream_class_ptr_by_id(self._ptr, key) if sc_ptr is None: raise KeyError(key) return self._stream_class_pycls._create_from_ptr_and_get_ref(sc_ptr)
def _value_to_int(self, value): if not isinstance(value, numbers.Integral): raise TypeError('expecting an integral number object') value = int(value) utils._check_uint64(value) return value
def _set_maximum_input_notification_iterator_count(self, count): utils._check_uint64(count) status = native_bt.component_sink_set_maximum_input_count( self._ptr, count) self._handle_status( status, "unexpected error: cannot set sink component object's maximum input notification iterator count" )
def __init__(self, clock_class_ptr, cycles): utils._check_uint64(cycles) ptr = native_bt.ctf_clock_value_create(clock_class_ptr, cycles) if ptr is None: raise bt2.CreationError('cannot create clock value object') super().__init__(ptr)
def mantissa_size(self, mantissa_size): utils._check_uint64(mantissa_size) ret = native_bt.field_class_floating_point_set_mantissa_digits( self._ptr, mantissa_size) utils._handle_ret( ret, "cannot set floating point number field class object's mantissa size" )
def exponent_size(self, exponent_size): utils._check_uint64(exponent_size) ret = native_bt.field_class_floating_point_set_exponent_digits( self._ptr, exponent_size) utils._handle_ret( ret, "cannot set floating point number field class object's exponent size" )
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError plugin_ptr = native_bt.plugin_set_get_plugin(self._ptr, index) assert(plugin_ptr) return _Plugin._create_from_ptr(plugin_ptr)
def create_event_class( self, id=None, name=None, user_attributes=None, log_level=None, emf_uri=None, specific_context_field_class=None, payload_field_class=None, ): # Validate parameters before we create the object. bt2_event_class._EventClass._validate_create_params( name, user_attributes, log_level, emf_uri, specific_context_field_class, payload_field_class, ) if self.assigns_automatic_event_class_id: if id is not None: raise ValueError( 'id provided, but stream class assigns automatic event class ids' ) ec_ptr = native_bt.event_class_create(self._ptr) else: if id is None: raise ValueError( 'id not provided, but stream class does not assign automatic event class ids' ) utils._check_uint64(id) ec_ptr = native_bt.event_class_create_with_id(self._ptr, id) event_class = bt2_event_class._EventClass._create_from_ptr(ec_ptr) if name is not None: event_class._name = name if user_attributes is not None: event_class._user_attributes = user_attributes if log_level is not None: event_class._log_level = log_level if emf_uri is not None: event_class._emf_uri = emf_uri if specific_context_field_class is not None: event_class._specific_context_field_class = specific_context_field_class if payload_field_class is not None: event_class._payload_field_class = payload_field_class return event_class
def mappings_by_value(self, value): if self.is_signed: utils._check_int64(value) iter_ptr = native_bt.ctf_field_type_enumeration_find_mappings_by_signed_value(self._ptr, value) else: utils._check_uint64(value) iter_ptr = native_bt.ctf_field_type_enumeration_find_mappings_by_unsigned_value(self._ptr, value) return self._get_mapping_iter(iter_ptr)
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError plugin_ptr = native_bt.plugin_set_borrow_plugin_by_index_const(self._ptr, index) assert plugin_ptr is not None return _Plugin._create_from_ptr_and_get_ref(plugin_ptr)
def __getitem__(self, id): utils._check_uint64(id) stream_ptr = self._borrow_stream_ptr_by_id(self._ptr, id) if stream_ptr is None: raise KeyError(id) return self._stream_pycls._create_from_ptr_and_get_ref(stream_ptr)
def __setitem__(self, key, value): utils._check_type(key, bt2.ClockClass) utils._check_uint64(value) ret = native_bt.clock_class_priority_map_add_clock_class( self._ptr, key._ptr, value) utils._handle_ret( ret, "cannot set clock class's priority in clock class priority map object" )
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError plugin_ptr = native_bt.plugin_set_get_plugin(self._ptr, index) assert (plugin_ptr) return _Plugin._create_from_ptr(plugin_ptr)
def at_index(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError field_ptr = native_bt.field_structure_get_field_by_index(self._ptr, index) assert(field_ptr) return _create_from_ptr(field_ptr)
def option_at_index(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError opt_ptr = self._borrow_option_ptr_by_index(self._ptr, index) assert opt_ptr is not None return self._create_option_from_ptr(opt_ptr)
def member_at_index(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError member_ptr = self._borrow_member_ptr_by_index(self._ptr, index) assert member_ptr is not None return self._structure_member_field_class_pycls(self, member_ptr)
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError cc_ptr = native_bt.plugin_get_component_class(self._ptr, index) utils._handle_ptr(cc_ptr, "cannot get plugin object's component class object") return bt2.component._create_generic_component_class_from_ptr(cc_ptr)
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError notif_iter_ptr = self._get_func(self._comp._ptr, index) utils._handle_ptr(notif_iter_ptr, "cannot get component object's input notification iterator") return bt2.notification_iterator._GenericNotificationIterator._create_from_ptr(notif_iter_ptr)
def __getitem__(self, id): utils._check_uint64(id) stream_ptr = native_bt.trace_borrow_stream_by_id_const(self._ptr, id) if stream_ptr is None: raise KeyError(id) return bt2_stream._Stream._create_from_ptr_and_get_ref(stream_ptr)
def mappings_by_value(self, value): if self.is_signed: utils._check_int64(value) iter_ptr = native_bt.field_class_enumeration_find_mappings_by_signed_value(self._ptr, value) else: utils._check_uint64(value) iter_ptr = native_bt.field_class_enumeration_find_mappings_by_unsigned_value(self._ptr, value) return self._get_mapping_iter(iter_ptr)
def create_static_array_field_class(self, elem_fc, length): utils._check_type(elem_fc, bt2_field_class._FieldClass) utils._check_uint64(length) ptr = native_bt.field_class_array_static_create( self._ptr, elem_fc._ptr, length) self._check_create_status(ptr, 'static array') return bt2_field_class._StaticArrayFieldClass._create_from_ptr_and_get_ref( ptr)
def member_at_index(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError field_ptr = self._borrow_member_field_ptr_by_index(self._ptr, index) assert field_ptr is not None return self._create_field_from_ptr(field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref)
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError stream_ptr = native_bt.trace_get_stream_by_index(self._trace._ptr, index) assert(stream_ptr) return bt2.stream._create_from_ptr(stream_ptr)
def __getitem__(self, key): utils._check_uint64(key) sc_ptr = native_bt.trace_class_borrow_stream_class_by_id_const( self._ptr, key) if sc_ptr is None: raise KeyError(key) return bt2_stream_class._StreamClass._create_from_ptr_and_get_ref( sc_ptr)
def member_at_index(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError member_ptr = native_bt.field_class_structure_borrow_member_by_index_const( self._ptr, index) assert member_ptr is not None return self._create_member_from_ptr(member_ptr)
def _value_to_int(self, value): if not isinstance(value, numbers.Real): raise TypeError('expecting a real number object') value = int(value) if self.field_type.is_signed: utils._check_int64(value) else: utils._check_uint64(value) return value
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError if self.is_signed: get_fn = native_bt.field_class_enumeration_get_mapping_signed else: get_fn = native_bt.field_class_enumeration_get_mapping_unsigned ret, name, lower, upper = get_fn(self._ptr, index) assert(ret == 0) return _EnumerationFieldClassMapping(name, lower, upper)
def __getitem__(self, index): utils._check_uint64(index) if index >= len(self): raise IndexError if self.is_signed: get_fn = native_bt.ctf_field_type_enumeration_get_mapping_signed else: get_fn = native_bt.ctf_field_type_enumeration_get_mapping_unsigned ret, name, lower, upper = get_fn(self._ptr, index) utils._handle_ret(ret, "cannot get enumeration field type object's mapping") return _EnumerationFieldTypeMapping(name, lower, upper)
def add_mapping(self, name, lower, upper=None): utils._check_str(name) if upper is None: upper = lower if self.is_signed: add_fn = native_bt.field_class_enumeration_add_mapping_signed utils._check_int64(lower) utils._check_int64(upper) else: add_fn = native_bt.field_class_enumeration_add_mapping_unsigned utils._check_uint64(lower) utils._check_uint64(upper) ret = add_fn(self._ptr, name, lower, upper) utils._handle_ret(ret, "cannot add mapping to enumeration field class object")
def __init__(self, element_field_type, length): utils._check_type(element_field_type, _FieldType) utils._check_uint64(length) ptr = native_bt.ctf_field_type_array_create(element_field_type._ptr, length) self._check_create_status(ptr) super().__init__(ptr)
def at_index(self, index): utils._check_uint64(index) field_ptr = native_bt.ctf_field_structure_get_field_by_index(self._ptr, index) utils._handle_ptr(field_ptr, "cannot get structure field object's field") return _create_from_ptr(field_ptr)
def exponent_size(self, exponent_size): utils._check_uint64(exponent_size) ret = native_bt.field_class_floating_point_set_exponent_digits(self._ptr, exponent_size) utils._handle_ret(ret, "cannot set floating point number field class object's exponent size")
def mantissa_size(self, mantissa_size): utils._check_uint64(mantissa_size) ret = native_bt.field_class_floating_point_set_mantissa_digits(self._ptr, mantissa_size) utils._handle_ret(ret, "cannot set floating point number field class object's mantissa size")
def precision(self, precision): utils._check_uint64(precision) ret = native_bt.ctf_clock_class_set_precision(self._ptr, precision) utils._handle_ret(ret, "cannot set clock class object's precision")
def frequency(self, frequency): utils._check_uint64(frequency) ret = native_bt.ctf_clock_class_set_frequency(self._ptr, frequency) utils._handle_ret(ret, "cannot set clock class object's frequency")
def at_index(self, index): utils._check_uint64(index) return self._at(index)
def append_discarded_events(self, count): utils._check_uint64(count) native_bt.stream_append_discarded_events(self._ptr, count)
def _set_maximum_input_notification_iterator_count(self, count): utils._check_uint64(count) status = native_bt.component_sink_set_maximum_input_count(self._ptr, count) self._handle_status(status, "unexpected error: cannot set sink component object's maximum input notification iterator count")