Python bindings: add "datetime" property to the Event class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 6 Oct 2014 19:04:26 +0000 (15:04 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 6 Oct 2014 19:04:26 +0000 (15:04 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/babeltrace.i.in

index 4ead2980563f4534800f33f3f1d4a78810c2d316..e0f3253c8408a19de96f534c72946a57b0d496f2 100644 (file)
@@ -653,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.
@@ -683,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.
This page took 0.025607 seconds and 4 git commands to generate.