+ def _get_str(self):
+ """
+ Return the value associated with the field.
+ If the field does not exist or is not of the type requested,
+ the value returned is undefined. To check if an error occurred,
+ use the field_error() function after accessing a field.
+ """
+ return _bt_ctf_get_string(self._d)
+
+ def _get_float(self):
+ """
+ Return the value associated with the field.
+ If the field does not exist or is not of the type requested,
+ the value returned is undefined. To check if an error occurred,
+ use the field_error() function after accessing a field.
+ """
+ return _bt_ctf_get_float(self._d)
+
+ def _get_variant(self):
+ """
+ Return the variant's selected field.
+ If the field does not exist or is not of the type requested,
+ the value returned is undefined. To check if an error occurred,
+ use the field_error() function after accessing a field.
+ """
+ return _bt_ctf_get_variant(self._d)
+
+ def _get_struct_field_count(self):
+ """
+ Return the number of fields contained in the structure.
+ If the field does not exist or is not of the type requested,
+ the value returned is undefined.
+ """
+ return _bt_ctf_get_struct_field_count(self._d)
+
+ def _get_struct_field_at(self, i):
+ """
+ Return the structure's field at position i.
+ If the field does not exist or is not of the type requested,
+ the value returned is undefined. To check if an error occurred,
+ use the field_error() function after accessing a field.
+ """
+ return _bt_ctf_get_struct_field_index(self._d, i)
+
+ @property
+ def value(self):
+ """
+ Return the value associated with the field according to its type.
+ Return None on error.
+ """
+ id = self.type
+ value = None
+
+ if id == CTFTypeId.STRING:
+ value = self._get_str()
+ elif id == CTFTypeId.ARRAY:
+ element_decl = self.declaration.element_declaration
+ if ((element_decl.type == CTFTypeId.INTEGER
+ and element_decl.length == 8)
+ and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
+ value = _bt_python_get_array_string(self._d)
+ else:
+ value = []
+ for i in range(self.declaration.length):
+ element = self._get_array_element_at(i)
+ value.append(element.value)
+ elif id == CTFTypeId.INTEGER:
+ if self.declaration.signedness == 0:
+ value = self._get_uint64()
+ else:
+ value = self._get_int64()
+ elif id == CTFTypeId.ENUM:
+ value = self._get_enum_str()
+ elif id == CTFTypeId.SEQUENCE:
+ element_decl = self.declaration.element_declaration
+ if ((element_decl.type == CTFTypeId.INTEGER
+ and element_decl.length == 8)
+ and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
+ value = _bt_python_get_sequence_string(self._d)
+ else:
+ seq_len = self._get_sequence_len()
+ value = []
+ for i in range(seq_len):
+ evDef = self._get_sequence_element_at(i)
+ value.append(evDef.value)
+ elif id == CTFTypeId.FLOAT:
+ value = self._get_float()
+ elif id == CTFTypeId.VARIANT:
+ variant = _Definition.__new__(_Definition)
+ variant._d = self._get_variant();
+ value = variant.value
+ elif id == CTFTypeId.STRUCT:
+ value = {}
+ for i in range(self._get_struct_field_count()):
+ member = _Definition(self._get_struct_field_at(i), self.scope)
+ value[member.name] = member.value
+
+ if field_error():
+ raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
+ return value
+
+ @property
+ def scope(self):
+ """Return the scope of a field or None on error."""
+ return self._s
+
+%}
+
+
+// =================================================================
+// CTF Writer
+// =================================================================
+
+/* =================================================================
+ CLOCK.H
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+*/
+%rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
+%rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
+%rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
+%rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
+%rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
+%rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
+%rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
+%rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
+%rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
+
+struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
+int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
+int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
+int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
+int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
+int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
+int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
+int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
+void bt_ctf_clock_get(struct bt_ctf_clock *clock);
+void bt_ctf_clock_put(struct bt_ctf_clock *clock);
+
+/* =================================================================
+ EVENT-TYPES.H
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+*/
+%rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
+%rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
+%rename("_bt_ctf_field_type_integer_set_base") bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
+%rename("_bt_ctf_field_type_integer_set_encoding") bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
+%rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
+%rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *string, int64_t range_start, int64_t range_end);
+%rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
+%rename("_bt_ctf_field_type_floating_point_set_exponent_digits") bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
+%rename("_bt_ctf_field_type_floating_point_set_mantissa_digits") bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
+%rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
+%rename("_bt_ctf_field_type_structure_add_field") bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
+%rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
+%rename("_bt_ctf_field_type_variant_add_field") bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
+%rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
+%rename("_bt_ctf_field_type_sequence_create") bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
+%rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
+%rename("_bt_ctf_field_type_string_set_encoding") bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
+%rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
+%rename("_bt_ctf_field_type_set_byte_order") bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
+%rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
+%rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
+
+struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
+int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
+int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
+int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
+struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
+int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *string, int64_t range_start, int64_t range_end);
+struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
+int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
+int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
+struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
+int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
+struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
+int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
+struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
+struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
+struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
+int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
+int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
+int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
+void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
+void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
+
+/* =================================================================
+ EVENT-FIELDS.H
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+*/
+%rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
+%rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
+%rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
+%rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
+%rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
+%rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
+%rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
+%rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
+%rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
+%rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
+%rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
+%rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
+%rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
+
+struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
+struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
+struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
+int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
+struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
+struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
+struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
+int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
+int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
+int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
+int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
+void bt_ctf_field_get(struct bt_ctf_field *field);
+void bt_ctf_field_put(struct bt_ctf_field *field);
+
+/* =================================================================
+ EVENT.H
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+*/
+%rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
+%rename("_bt_ctf_event_class_add_field") bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
+%rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
+%rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
+%rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
+%rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
+
+struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
+int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
+void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
+void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
+struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
+int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
+struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
+void bt_ctf_event_get(struct bt_ctf_event *event);
+void bt_ctf_event_put(struct bt_ctf_event *event);
+
+/* =================================================================
+ STREAM.H
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+*/
+%rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
+%rename("_bt_ctf_stream_class_set_clock") bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
+%rename("_bt_ctf_stream_class_add_event_class") bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
+%rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
+%rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
+%rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
+%rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
+
+struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
+int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
+int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
+void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
+void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
+void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
+int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
+int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
+void bt_ctf_stream_get(struct bt_ctf_stream *stream);
+void bt_ctf_stream_put(struct bt_ctf_stream *stream);
+
+/* =================================================================
+ WRITER.H
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
+*/
+%rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
+%rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
+%rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
+%newobject bt_ctf_writer_get_metadata_string;
+%rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
+%rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
+%rename("_bt_ctf_writer_set_byte_order") bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
+%rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
+%rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
+
+struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
+struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
+int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
+int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
+char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
+void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
+int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
+void bt_ctf_writer_get(struct bt_ctf_writer *writer);
+void bt_ctf_writer_put(struct bt_ctf_writer *writer);
+
+%pythoncode %{
+
+class CTFWriter:
+
+ class Clock:
+ def __init__(self, name):
+ self._c = _bt_ctf_clock_create(name)
+ if self._c is None:
+ raise ValueError("Invalid clock name.")
+
+ def __del__(self):
+ _bt_ctf_clock_put(self._c)
+
+ """
+ Get the clock's description.
+ """
+ @property
+ def description(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the clock's description. The description appears in the clock's TSDL
+ meta-data.
+ """
+ @description.setter
+ def description(self, desc):
+ ret = _bt_ctf_clock_set_description(self._c, str(desc))
+ if ret < 0:
+ raise ValueError("Invalid clock description.")
+
+ """
+ Get the clock's frequency (Hz).
+ """
+ @property
+ def frequency(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the clock's frequency (Hz).
+ """
+ @frequency.setter
+ def frequency(self, freq):
+ ret = _bt_ctf_clock_set_frequency(self._c, freq)
+ if ret < 0:
+ raise ValueError("Invalid frequency value.")
+
+ """
+ Get the clock's precision (in clock ticks).
+ """
+ @property
+ def precision(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the clock's precision (in clock ticks).
+ """
+ @precision.setter
+ def precision(self, precision):
+ ret = _bt_ctf_clock_set_precision(self._c, precision)
+
+ """
+ Get the clock's offset in seconds from POSIX.1 Epoch.
+ """
+ @property
+ def offset_seconds(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the clock's offset in seconds from POSIX.1 Epoch.
+ """
+ @offset_seconds.setter
+ def offset_seconds(self, offset_s):
+ ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
+ if ret < 0:
+ raise ValueError("Invalid offset value.")
+
+ """
+ Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
+ """
+ @property
+ def offset(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
+ """
+ @offset.setter
+ def offset(self, offset):
+ ret = _bt_ctf_clock_set_offset(self._c, offset)
+ if ret < 0:
+ raise ValueError("Invalid offset value.")
+
+ """
+ Get a clock's absolute attribute. A clock is absolute if the clock
+ is a global reference across the trace's other clocks.
+ """
+ @property
+ def absolute(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set a clock's absolute attribute. A clock is absolute if the clock
+ is a global reference across the trace's other clocks.
+ """
+ @absolute.setter
+ def absolute(self, is_absolute):
+ ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
+ if ret < 0:
+ raise ValueError("Could not set the clock's absolute attribute.")
+
+ """
+ Get the current time in nanoseconds since the clock's origin (offset and
+ offset_s attributes).
+ """
+ @property
+ def time(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the current time in nanoseconds since the clock's origin (offset and
+ offset_s attributes). The clock's value will be sampled as events are
+ appended to a stream.
+ """
+ @time.setter
+ def time(self, time):
+ ret = _bt_ctf_clock_set_time(self._c, time)
+ if ret < 0:
+ raise ValueError("Invalid time value.")
+
+ class FieldDeclaration:
+ """
+ FieldDeclaration should not be instantiated directly. Please instantiate
+ one of the concrete FieldDeclaration classes.
+ """
+ class IntegerBase:
+ # These values are based on the bt_ctf_integer_base enum
+ # declared in event-types.h.
+ INTEGER_BASE_UNKNOWN = -1
+ INTEGER_BASE_BINARY = 2
+ INTEGER_BASE_OCTAL = 8
+ INTEGER_BASE_DECIMAL = 10
+ INTEGER_BASE_HEXADECIMAL = 16
+
+ def __init__(self):
+ if self._ft is None:
+ raise ValueError("FieldDeclaration creation failed.")
+
+ def __del__(self):
+ _bt_ctf_field_type_put(self._ft)
+
+ """
+ Get the field type's alignment.
+ """
+ @property
+ def alignment(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the field type's alignment. Defaults to 1 (bit-aligned). However,
+ some types, such as structures and string, may impose other alignment
+ constraints.
+ """
+ @alignment.setter
+ def alignment(self, alignment):
+ ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
+ if ret < 0:
+ raise ValueError("Invalid alignment value.")
+
+ """
+ Get the field type's byte order. One of the ByteOrder's constant.
+ """
+ @property
+ def byte_order(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the field type's byte order. Use constants defined in the ByteOrder
+ class.
+ """
+ @byte_order.setter
+ def byte_order(self, byte_order):
+ ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
+ if ret < 0:
+ raise ValueError("Could not set byte order value.")
+
+ class IntegerFieldDeclaration(FieldDeclaration):
+ """
+ Create a new integer field type of the given size.
+ """
+ def __init__(self, size):
+ self._ft = _bt_ctf_field_type_integer_create(size)
+ super().__init__()
+
+ """
+ Get an integer's signedness attribute.
+ """
+ @property
+ def signed(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set an integer's signedness attribute.
+ """
+ @signed.setter
+ def signed(self, signed):
+ ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
+ if ret < 0:
+ raise ValueError("Could not set signed attribute.")
+
+ """
+ Get the integer's base used to pretty-print the resulting trace.
+ """
+ @property
+ def base(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the integer's base used to pretty-print the resulting trace.
+ The base must be a constant of the IntegerBase class.
+ """
+ @base.setter
+ def base(self, base):
+ ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
+ if ret < 0:
+ raise ValueError("Could not set base value.")
+
+ """
+ Get the integer's encoding (one of the constants of the
+ CTFStringEncoding class).
+ """
+ @property
+ def encoding(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ An integer encoding may be set to signal that the integer must be printed
+ as a text character. Must be a constant from the CTFStringEncoding class.
+ """
+ @encoding.setter
+ def encoding(self, encoding):
+ ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
+ if ret < 0:
+ raise ValueError("Could not set integer encoding.")
+
+ class EnumerationFieldDeclaration(FieldDeclaration):
+ """
+ Create a new enumeration field type with the given underlying type.
+ """
+ def __init__(self, integer_type):
+ if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
+ raise TypeError("Invalid integer container.")
+
+ self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
+ super().__init__()
+
+ """
+ Add a mapping to the enumeration. The range's values are inclusive.
+ """
+ def add_mapping(self, name, range_start, range_end):
+ ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
+ if ret < 0:
+ raise ValueError("Could not add mapping to enumeration type.")
+
+ class FloatFieldDeclaration(FieldDeclaration):
+ FLT_EXP_DIG = 8
+ DBL_EXP_DIG = 11
+ FLT_MANT_DIG = 24
+ DBL_MANT_DIG = 53
+
+ """
+ Create a new floating point field type.
+ """
+ def __init__(self):
+ self._ft = _bt_ctf_field_type_floating_point_create()
+ super().__init__()
+
+ """
+ Get the number of exponent digits to use to store the floating point field.
+ """
+ @property
+ def exponent_digits(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the number of exponent digits to use to store the floating point field.
+ The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
+ are defined as constants of this class.
+ """
+ @exponent_digits.setter
+ def exponent_digits(self, exponent_digits):
+ ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
+ if ret < 0:
+ raise ValueError("Could not set exponent digit count.")
+
+ """
+ Get the number of mantissa digits to use to store the floating point field.
+ """
+ @property
+ def mantissa_digits(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the number of mantissa digits to use to store the floating point field.
+ The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
+ are defined as constants of this class.
+ """
+ @mantissa_digits.setter
+ def mantissa_digits(self, mantissa_digits):
+ ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
+ if ret < 0:
+ raise ValueError("Could not set mantissa digit count.")
+
+ class StructureFieldDeclaration(FieldDeclaration):
+ """
+ Create a new structure field type.
+ """
+ def __init__(self):
+ self._ft = _bt_ctf_field_type_structure_create()
+ super().__init__()
+
+ """
+ Add a field of type "field_type" to the structure.
+ """
+ def add_field(self, field_type, field_name):
+ ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
+ if ret < 0:
+ raise ValueError("Could not add field to structure.")
+
+ class VariantFieldDeclaration(FieldDeclaration):
+ """
+ Create a new variant field type.
+ """
+ def __init__(self, enum_tag, tag_name):
+ if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
+ raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
+
+ self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
+ super().__init__()
+
+ """
+ Add a field of type "field_type" to the variant.
+ """
+ def add_field(self, field_type, field_name):
+ ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
+ if ret < 0:
+ raise ValueError("Could not add field to variant.")
+
+ class ArrayFieldDeclaration(FieldDeclaration):
+ """
+ Create a new array field type.
+ """
+ def __init__(self, element_type, length):
+ self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
+ super().__init__()
+
+ class SequenceFieldDeclaration(FieldDeclaration):
+ """
+ Create a new sequence field type.
+ """
+ def __init__(self, element_type, length_field_name):
+ self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
+ super().__init__()
+
+ class StringFieldDeclaration(FieldDeclaration):
+ """
+ Create a new string field type.
+ """
+ def __init__(self):
+ self._ft = _bt_ctf_field_type_string_create()
+ super().__init__()
+
+ """
+ Get a string type's encoding (a constant from the CTFStringEncoding class).
+ """
+ @property
+ def encoding(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
+ """
+ @encoding.setter
+ def encoding(self, encoding):
+ ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
+ if ret < 0:
+ raise ValueError("Could not set string encoding.")
+
+ """
+ Create an instance of a field.
+ """
+ @staticmethod
+ def create_field(self, field_type):
+ if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
+ raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
+
+ if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
+ return CTFWriter.IntegerField(field_type)
+ elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
+ return CTFWriter.EnumerationField(field_type)
+ elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
+ return CTFWriter.FloatFieldingPoint(field_type)
+ elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
+ return CTFWriter.StructureField(field_type)
+ elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
+ return CTFWriter.VariantField(field_type)
+ elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
+ return CTFWriter.ArrayField(field_type)
+ elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
+ return CTFWriter.SequenceField(field_type)
+ elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
+ return CTFWriter.StringField(field_type)
+
+ class Field:
+ """
+ Base class, do not instantiate.
+ """
+ def __init__(self, field_type):
+ if not isinstance(field_type, CTFWriter.FieldDeclaration):
+ raise TypeError("Invalid field_type argument.")
+
+ self._f = _bt_ctf_field_create(field_type._ft)
+ if self._f is None:
+ raise ValueError("Field creation failed.")
+
+ def __del__(self):
+ _bt_ctf_field_put(self._f)
+
+ @staticmethod
+ def _create_field_from_native_instance(native_field_instance):
+ type_dict = {
+ CTFTypeId.INTEGER : CTFWriter.IntegerField,
+ CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
+ CTFTypeId.ENUM : CTFWriter.EnumerationField,
+ CTFTypeId.STRING : CTFWriter.StringField,
+ CTFTypeId.STRUCT : CTFWriter.StructureField,
+ CTFTypeId.VARIANT : CTFWriter.VariantField,
+ CTFTypeId.ARRAY : CTFWriter.ArrayField,
+ CTFTypeId.SEQUENCE : CTFWriter.SequenceField
+ }
+
+ field_type = _bt_python_get_field_type(native_field_instance)
+ if field_type == CTFTypeId.UNKNOWN:
+ raise TypeError("Invalid field instance")
+
+ field = CTFWriter.Field.__new__(CTFWriter.Field)
+ field._f = native_field_instance
+ field.__class__ = type_dict[field_type]
+ return field
+
+ class IntegerField(Field):
+ """
+ Get an integer field's value.
+ """
+ @property
+ def value(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set an integer field's value.
+ """
+ @value.setter
+ def value(self, value):
+ signedness = _bt_python_field_integer_get_signedness(self._f)
+ if signedness < 0:
+ raise TypeError("Invalid integer instance.")
+
+ if signedness == 0:
+ ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
+ else:
+ ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
+
+ if ret < 0:
+ raise ValueError("Could not set integer field value.")
+
+ class EnumerationField(Field):
+ """
+ Return the enumeration's underlying container field (an integer field).
+ """
+ @property
+ def container(self):
+ container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
+ container._f = _bt_ctf_field_enumeration_get_container(self._f)
+ if container._f is None:
+ raise TypeError("Invalid enumeration field type.")
+ return container
+
+ class FloatFieldingPoint(Field):
+ """
+ Get a floating point field's value.
+ """
+ @property
+ def value(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set a floating point field's value.
+ """
+ @value.setter
+ def value(self, value):
+ ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
+ if ret < 0:
+ raise ValueError("Could not set floating point field value.")
+
+ class StructureField(Field):
+ """
+ Get the structure's field corresponding to the provided field name.
+ """
+ def field(self, field_name):
+ native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
+ if native_instance is None:
+ raise ValueError("Invalid field_name provided.")
+ return CTFWriter.Field._create_field_from_native_instance(native_instance)
+
+ class VariantField(Field):
+ """
+ Return the variant's selected field. The "tag" field is the selector enum field.
+ """
+ def field(self, tag):
+ native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
+ if native_instance is None:
+ raise ValueError("Invalid tag provided.")
+ return CTFWriter.Field._create_field_from_native_instance(native_instance)
+
+ class ArrayField(Field):
+ """
+ Return the array's field at position "index".
+ """
+ def field(self, index):
+ native_instance = _bt_ctf_field_array_get_field(self._f, index)
+ if native_instance is None:
+ raise IndexError("Invalid index provided.")
+ return CTFWriter.Field._create_field_from_native_instance(native_instance)
+
+ class SequenceField(Field):
+ """
+ Get the sequence's length field (IntegerField).
+ """
+ @property
+ def length(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the sequence's length field (IntegerField).
+ """
+ @length.setter
+ def length(self, length_field):
+ if not isinstance(length_field, CTFWriter.IntegerField):
+ raise TypeError("Invalid length field.")
+ ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
+ if ret < 0:
+ raise ValueError("Could not set sequence length.")
+
+ """
+ Return the sequence's field at position "index".
+ """
+ def field(self, index):
+ native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
+ if native_instance is None:
+ raise ValueError("Could not get sequence element at index.")
+ return CTFWriter.Field._create_field_from_native_instance(native_instance)
+
+ class StringField(Field):
+ """
+ Get a string field's value.
+ """
+ @property
+ def value(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set a string field's value.
+ """
+ @value.setter
+ def value(self, value):
+ ret = _bt_ctf_field_string_set_value(self._f, str(value))
+ if ret < 0:
+ raise ValueError("Could not set string field value.")
+
+ class EventClass:
+ """
+ Create a new event class of the given name.
+ """
+ def __init__(self, name):
+ self._ec = _bt_ctf_event_class_create(name)
+ if self._ec is None:
+ raise ValueError("Event class creation failed.")
+
+ def __del__(self):
+ _bt_ctf_event_class_put(self._ec)
+
+ """
+ Add a field of type "field_type" to the event class.
+ """
+ def add_field(self, field_type, field_name):
+ ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
+ if ret < 0:
+ raise ValueError("Could not add field to event class.")
+
+ class Event:
+ """
+ Create a new event of the given event class.
+ """
+ def __init__(self, event_class):
+ if not isinstance(event_class, CTFWriter.EventClass):
+ raise TypeError("Invalid event_class argument.")
+
+ self._e = _bt_ctf_event_create(event_class._ec)
+ if self._e is None:
+ raise ValueError("Event creation failed.")
+
+ def __del__(self):
+ _bt_ctf_event_put(self._e)
+
+ """
+ Set a manually created field as an event's payload.
+ """
+ def set_payload(self, field_name, value_field):
+ if not isinstance(value, CTFWriter.Field):
+ raise TypeError("Invalid value type.")
+ ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
+ if ret < 0:
+ raise ValueError("Could not set event field payload.")
+
+ """
+ Get a field from event.
+ """
+ def payload(self, field_name):
+ native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
+ if native_instance is None:
+ raise ValueError("Could not get event payload.")
+ return CTFWriter.Field._create_field_from_native_instance(native_instance)
+
+ class StreamClass:
+ """
+ Create a new stream class of the given name.
+ """
+ def __init__(self, name):
+ self._sc = _bt_ctf_stream_class_create(name)
+ if self._sc is None:
+ raise ValueError("Stream class creation failed.")
+
+ def __del__(self):
+ _bt_ctf_stream_class_put(self._sc)
+
+ """
+ Get a stream class' clock.
+ """
+ @property
+ def clock(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Assign a clock to a stream class.
+ """
+ @clock.setter
+ def clock(self, clock):
+ if not isinstance(clock, CTFWriter.Clock):
+ raise TypeError("Invalid clock type.")
+
+ ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
+ if ret < 0:
+ raise ValueError("Could not set stream class clock.")
+
+ """
+ Add an event class to a stream class. New events can be added even after a
+ stream has been instantiated and events have been appended. However, a stream
+ will not accept events of a class that has not been registered beforehand.
+ """
+ def add_event_class(self, event_class):
+ if not isinstance(event_class, CTFWriter.EventClass):
+ raise TypeError("Invalid event_class type.")
+
+ ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
+ if ret < 0:
+ raise ValueError("Could not add event class.")
+
+ class Stream:
+ """
+ Create a stream of the given class.
+ """
+ def __init__(self, stream_class):
+ if not isinstance(stream_class, CTFWriter.StreamClass):
+ raise TypeError("Invalid stream_class type.")
+
+ self._s = _bt_ctf_stream_create(stream_class._sc)
+ if self._s is None:
+ raise ValueError("Stream creation failed.")
+
+ def __del__(self):
+ _bt_ctf_stream_put(self._s)
+
+ """
+ Increase the current packet's discarded event count.
+ """
+ def append_discarded_events(self, event_count):
+ _bt_ctf_stream_append_discarded_events(self._s, event_count)
+
+ """
+ Append "event" to the stream's current packet. The stream's associated clock
+ will be sampled during this call. The event shall not be modified after
+ being appended to a stream.
+ """
+ def append_event(self, event):
+ ret = _bt_ctf_stream_append_event(self._s, event._e)
+ if ret < 0:
+ raise ValueError("Could not append event to stream.")
+
+ """
+ The stream's current packet's events will be flushed to disk. Events
+ subsequently appended to the stream will be added to a new packet.
+ """
+ def flush(self):
+ ret = _bt_ctf_stream_flush(self._s)
+ if ret < 0:
+ raise ValueError("Could not flush stream.")
+
+ class Writer:
+ """
+ Create a new writer that will produce a trace in the given path.
+ """
+ def __init__(self, path):
+ self._w = _bt_ctf_writer_create(path)
+ if self._w is None:
+ raise ValueError("Writer creation failed.")
+
+ def __del__(self):
+ _bt_ctf_writer_put(self._w)
+
+ """
+ Create a new stream instance and register it to the writer.
+ """
+ def create_stream(self, stream_class):
+ if not isinstance(stream_class, CTFWriter.StreamClass):
+ raise TypeError("Invalid stream_class type.")
+
+ stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
+ stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
+ return stream
+
+ """
+ Add an environment field to the trace.
+ """
+ def add_environment_field(self, name, value):
+ ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
+ if ret < 0:
+ raise ValueError("Could not add environment field to trace.")
+
+ """
+ Add a clock to the trace. Clocks assigned to stream classes must be
+ registered to the writer.
+ """
+ def add_clock(self, clock):
+ ret = _bt_ctf_writer_add_clock(self._w, clock._c)
+ if ret < 0:
+ raise ValueError("Could not add clock to Writer.")
+
+ """
+ Get the trace's TSDL meta-data.
+ """
+ @property
+ def metadata(self):
+ return _bt_ctf_writer_get_metadata_string(self._w)
+
+ """
+ Flush the trace's metadata to the metadata file.
+ """
+ def flush_metadata(self):
+ _bt_ctf_writer_flush_metadata(self._w)
+
+ """
+ Get the trace's byte order. Must be a constant from the ByteOrder
+ class.
+ """
+ @property
+ def byte_order(self):
+ raise NotImplementedError("Getter not implemented.")
+
+ """
+ Set the trace's byte order. Must be a constant from the ByteOrder
+ class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
+ """
+ @byte_order.setter
+ def byte_order(self, byte_order):
+ ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
+ if ret < 0:
+ raise ValueError("Could not set trace's byte order.")