From: Jérémie Galarneau Date: Mon, 6 Oct 2014 19:04:26 +0000 (-0400) Subject: Python bindings: add "datetime" property to the Event class X-Git-Tag: v2.0.0-pre1~1493 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=49a04569fb23a20644248e83c03622fec69f8aed Python bindings: add "datetime" property to the Event class Signed-off-by: Jérémie Galarneau --- diff --git a/bindings/python/babeltrace.i.in b/bindings/python/babeltrace.i.in index 4ead2980..e0f3253c 100644 --- a/bindings/python/babeltrace.i.in +++ b/bindings/python/babeltrace.i.in @@ -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.