X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Freader.py;h=bb3d92811b71f3c4e631deeb37df09536f275ded;hb=ae512132fbf1641663510ab09d69bbe052bd495c;hp=285111e82f6f02d354a8c4f860b010450edaff4e;hpb=be5a4e673f4603dd4867e945ee6054de41be78c2;p=babeltrace.git diff --git a/bindings/python/reader.py b/bindings/python/reader.py index 285111e8..bb3d9281 100644 --- a/bindings/python/reader.py +++ b/bindings/python/reader.py @@ -45,12 +45,13 @@ class TraceCollection: 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) @@ -132,6 +133,14 @@ class TraceCollection: 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): """ @@ -145,14 +154,19 @@ class TraceCollection: 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 @@ -165,8 +179,8 @@ class TraceCollection: 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 @@ -174,6 +188,9 @@ class TraceCollection: 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): """ @@ -207,8 +224,24 @@ class TraceCollection: ev_ptr = nbt._bt_ctf_iter_read_event(ctf_it_ptr) nbt._bt_ctf_iter_destroy(ctf_it_ptr) + ev = Event.__new__(Event) + ev._e = ev_ptr + + 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.") @@ -278,9 +311,11 @@ class TraceHandle: 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): @@ -289,9 +324,11 @@ class TraceHandle: 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): @@ -408,10 +445,13 @@ class Event(collections.Mapping): @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): @@ -810,13 +850,16 @@ class IntegerFieldDeclaration(FieldDeclaration): return common.ByteOrder.BYTE_ORDER_UNKNOWN @property - def length(self): + def size(self): """ Integer size in bits, or a negative value on error. """ - return nbt._bt_ctf_get_int_len(self._fd) + @property + def length(self): + return self.size + @property def encoding(self): """