struct bt_definition *field);
struct bt_declaration *_bt_python_get_array_element_declaration(
struct bt_declaration *field);
+struct bt_declaration *_bt_python_get_sequence_element_declaration(
+ struct bt_declaration *field);
const char *_bt_python_get_array_string(struct bt_definition *field);
+const char *_bt_python_get_sequence_string(struct bt_definition *field);
int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
+struct bt_iter_pos *_bt_python_create_iter_pos(void);
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+ struct bt_context *ctx,
+ struct bt_iter_pos *inter_begin_pos,
+ struct bt_iter_pos *inter_end_pos);
+int _bt_python_has_intersection(struct bt_context *ctx);
/* =================================================================
CONTEXT.H, CONTEXT-INTERNAL.H
The TraceCollection is the object that contains all currently opened traces.
"""
- def __init__(self):
+ def __init__(self, intersect_mode=False):
self._tc = _bt_context_create()
+ self.intersect_mode = intersect_mode
def __del__(self):
_bt_context_put(self._tc)
"""
Generator function to iterate over the events of open in the current
TraceCollection.
+
+ Due to limitations of the native Babeltrace API, only one event
+ may be "alive" at a time (i.e. a user should never store a copy
+ of the events returned by this function for ulterior use). Users
+ shall make sure to copy the information they need from an event
+ before accessing the next one.
+
+ Furthermore, event objects become invalid when the generator goes
+ out of scope as the underlying iterator will be reclaimed. Using an
+ event after the the generator has gone out of scope may result in a
+ crash or data corruption.
"""
- begin_pos_ptr = _bt_iter_pos()
- end_pos_ptr = _bt_iter_pos()
- begin_pos_ptr.type = SEEK_BEGIN
- end_pos_ptr.type = SEEK_LAST
+ begin_pos_ptr = _bt_python_create_iter_pos()
+ end_pos_ptr = _bt_python_create_iter_pos()
+ if not self.intersection_mode:
+ begin_pos_ptr.type = SEEK_BEGIN
+ end_pos_ptr.type = SEEK_LAST
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
+ _bt_iter_free_pos(begin_pos_ptr)
+ _bt_iter_free_pos(end_pos_ptr)
+
def events_timestamps(self, timestamp_begin, timestamp_end):
"""
Generator function to iterate over the events of open in the current
TraceCollection from timestamp_begin to timestamp_end.
"""
- begin_pos_ptr = _bt_iter_pos()
- end_pos_ptr = _bt_iter_pos()
+ begin_pos_ptr = _bt_python_create_iter_pos()
+ end_pos_ptr = _bt_python_create_iter_pos()
begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
begin_pos_ptr.u.seek_time = timestamp_begin
end_pos_ptr.u.seek_time = timestamp_end
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
+ _bt_iter_free_pos(begin_pos_ptr)
+ _bt_iter_free_pos(end_pos_ptr)
+
@property
def timestamp_begin(self):
pos_ptr = _bt_iter_pos()
ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
_bt_ctf_iter_destroy(ctf_it_ptr)
if ev_ptr is None:
- return None;
+ return None
+ ev = Event.__new__(Event)
+ ev._e = ev_ptr
+ return ev.timestamp
def _events(self, begin_pos_ptr, end_pos_ptr):
- ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
+ if self.intersect_mode:
+ has_intersection = _bt_python_has_intersection(self._tc)
+ if not has_intersection:
+ # There are no events to provide.
+ return
+
+ ctf_it_ptr = _bt_python_ctf_iter_create_intersect(
+ self._tc, begin_pos_ptr, end_pos_ptr
+ )
+ else:
+ ctf_it_ptr = _bt_ctf_iter_create(
+ self._tc, begin_pos_ptr, end_pos_ptr
+ )
+
if ctf_it_ptr is None:
raise NotImplementedError(
"Creation of multiple iterators is unsupported.")
def _field_list_with_scope(self, scope):
fields = []
scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
-
+
# Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
# provide the "count" return value
count = 0
def __init__(self):
raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
+ @property
+ def element_declaration(self):
+ """
+ Return element declaration.
+ """
+ field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
+ return _create_field_declaration(field_decl_ptr, "", self.scope)
+
class FloatFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
elif id == CTFTypeId.ENUM:
value = self._get_enum_str()
elif id == CTFTypeId.SEQUENCE:
- seq_len = self._get_sequence_len()
- value = []
- for i in range(seq_len):
- evDef = self._get_sequence_element_at(i)
- value.append(evDef.value)
+ 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:
"""
@length.setter
def length(self, length_field):
- if not isinstance(length, CTFWriter.IntegerField):
+ if not isinstance(length_field, CTFWriter.IntegerField):
raise TypeError("Invalid length field.")
- ret = _bt_ctf_field_sequence_set_length(self._f, length._f)
+ ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
if ret < 0:
raise ValueError("Could not set sequence length.")
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._f)
+ 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.")
Increase the current packet's discarded event count.
"""
def append_discarded_events(self, event_count):
- ret = _bt_ctf_stream_append_discarded_events(self._s, event_count)
- if ret < 0:
- raise ValueError("Could not append discarded events.")
+ _bt_ctf_stream_append_discarded_events(self._s, event_count)
"""
Append "event" to the stream's current packet. The stream's associated clock