trace from a trace collection.
"""
- def __init__(self):
+ def __init__(self, intersect_mode=False):
"""
Creates an empty trace collection.
"""
self._tc = nbt._bt_context_create()
+ self._intersect_mode = intersect_mode
def __del__(self):
nbt._bt_context_put(self._tc)
except AttributeError:
raise TypeError("in remove_trace, argument 2 must be a TraceHandle instance")
+ @property
+ def intersect_mode(self):
+ return self._intersect_mode
+
+ @property
+ def has_intersection(self):
+ return nbt._bt_python_has_intersection(self._tc)
+
@property
def events(self):
"""
they need *from* an event before accessing the next one.
"""
- begin_pos_ptr = nbt._bt_iter_pos()
- end_pos_ptr = nbt._bt_iter_pos()
- begin_pos_ptr.type = nbt.SEEK_BEGIN
- end_pos_ptr.type = nbt.SEEK_LAST
+ begin_pos_ptr = nbt._bt_python_create_iter_pos()
+ end_pos_ptr = nbt._bt_python_create_iter_pos()
+
+ if not self.intersect_mode:
+ begin_pos_ptr.type = nbt.SEEK_BEGIN
+ end_pos_ptr.type = nbt.SEEK_LAST
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
+ nbt._bt_iter_free_pos(begin_pos_ptr)
+ nbt._bt_iter_free_pos(end_pos_ptr)
+
def events_timestamps(self, timestamp_begin, timestamp_end):
"""
Generates the ordered :class:`Event` objects of all the opened
See :attr:`events` for notes and limitations.
"""
- begin_pos_ptr = nbt._bt_iter_pos()
- end_pos_ptr = nbt._bt_iter_pos()
+ begin_pos_ptr = nbt._bt_python_create_iter_pos()
+ end_pos_ptr = nbt._bt_python_create_iter_pos()
begin_pos_ptr.type = end_pos_ptr.type = nbt.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
+ nbt._bt_iter_free_pos(begin_pos_ptr)
+ nbt._bt_iter_free_pos(end_pos_ptr)
+
@property
def timestamp_begin(self):
"""
return ev.timestamp
def _events(self, begin_pos_ptr, end_pos_ptr):
- ctf_it_ptr = nbt._bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
+ if self.intersect_mode:
+ if not self.has_intersection:
+ # There are no events to provide.
+ return
+
+ ctf_it_ptr = nbt._bt_python_ctf_iter_create_intersect(
+ self._tc, begin_pos_ptr, end_pos_ptr
+ )
+ else:
+ ctf_it_ptr = nbt._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.")
underlying trace.
"""
- return nbt._bt_trace_handle_get_timestamp_begin(self._trace_collection._tc,
- self._id,
- _ClockType.CLOCK_REAL)
+ ret, value = nbt._bt_trace_handle_get_timestamp_begin(
+ self._trace_collection._tc, self._id, _ClockType.CLOCK_REAL)
+ if ret != 0:
+ raise ValueError("Invalid TraceHandle")
+ return value
@property
def timestamp_end(self):
underlying trace.
"""
- return nbt._bt_trace_handle_get_timestamp_end(self._trace_collection._tc,
- self._id,
- _ClockType.CLOCK_REAL)
+ ret, value = nbt._bt_trace_handle_get_timestamp_end(
+ self._trace_collection._tc, self._id, _ClockType.CLOCK_REAL)
+ if ret != 0:
+ raise ValueError("Invalid TraceHandle")
+ return value
@property
def events(self):
@property
def timestamp(self):
"""
- Event timestamp (nanoseconds since Epoch) or -1 on error.
+ Event timestamp (nanoseconds since Epoch).
"""
- return nbt._bt_ctf_get_timestamp(self._e)
+ ret, value = nbt._bt_ctf_get_timestamp(self._e)
+ if ret < 0:
+ raise RuntimeError("Failed to get event timestamp")
+ return value
@property
def datetime(self):