From 49a04569fb23a20644248e83c03622fec69f8aed Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 6 Oct 2014 15:04:26 -0400 Subject: [PATCH] Python bindings: add "datetime" property to the Event class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- bindings/python/babeltrace.i.in | 10 ++++++++++ 1 file changed, 10 insertions(+) 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. -- 2.34.1