Python bindings: cleanup whitespace
[babeltrace.git] / bindings / python / babeltrace.i.in
index 99a86ec3268e38d17379dd481c92876e4d854d18..724ed45d7e5d76351cdf905ca75e2690b57c9253 100644 (file)
@@ -226,6 +226,17 @@ class TraceCollection:
                """
                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()
@@ -642,6 +653,7 @@ _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_
        CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
 
 import collections
+from datetime import datetime
 class Event(collections.Mapping):
        """
        This class represents an event from the trace.
@@ -672,6 +684,15 @@ class Event(collections.Mapping):
                """
                return _bt_ctf_get_timestamp(self._e)
 
+       @property
+       def datetime(self):
+               """
+               Return a datetime object based on the event's
+               timestamp. Note that the datetime class' precision
+               is limited to microseconds.
+               """
+               return datetime.fromtimestamp(self.timestamp / 1E9)
+
        def field_with_scope(self, field_name, scope):
                """
                Get field_name's value in scope.
@@ -799,7 +820,7 @@ class Event(collections.Mapping):
        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
@@ -1513,6 +1534,7 @@ void bt_ctf_event_put(struct bt_ctf_event *event);
 %rename("_bt_ctf_stream_class_get_event_class_by_name") bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
 %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_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
 %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);
@@ -1531,6 +1553,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_str
 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
 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);
+int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
 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);
@@ -2744,6 +2767,16 @@ class CTFWriter:
                def __del__(self):
                        _bt_ctf_stream_put(self._s)
 
+               """
+               Get a stream's discarded event count.
+               """
+               @property
+               def discarded_events(self):
+                       ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
+                       if ret < 0:
+                               raise ValueError("Could not get the stream's discarded events count")
+                       return count
+
                """
                Increase the current packet's discarded event count.
                """
This page took 0.025135 seconds and 4 git commands to generate.