From 7a5f95fa9307a7d0ef30173c5935155222449f0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 16 Feb 2016 22:26:26 -0500 Subject: [PATCH] Python bindings: accomodate API changes introduced for negative time MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- bindings/python/nativebt.i | 14 +++++++------- bindings/python/reader.py | 23 +++++++++++++++-------- bindings/python/writer.py | 12 ++++++------ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/bindings/python/nativebt.i b/bindings/python/nativebt.i index e1d83785..c5b00c9e 100644 --- a/bindings/python/nativebt.i +++ b/bindings/python/nativebt.i @@ -213,9 +213,9 @@ void bt_trace_handle_destroy(struct bt_trace_handle *bt); int64_t *timestamp); const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id); int bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id, - enum bt_clock_type type, int64_t *timestamp); + enum bt_clock_type type, int64_t *OUTPUT); int bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id, - enum bt_clock_type type, int64_t *timestamp); + enum bt_clock_type type, int64_t *OUTPUT); %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id( const struct bt_ctf_event *event); @@ -243,7 +243,7 @@ struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter); bt_ctf_event *event, enum bt_ctf_scope scope); %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event); %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp( - const struct bt_ctf_event *ctf_event, int64_t *timestamp); + const struct bt_ctf_event *ctf_event, int64_t *OUTPUT); %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles( const struct bt_ctf_event *ctf_event); @@ -289,7 +289,7 @@ struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter); const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event, enum bt_ctf_scope scope); const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event); -int bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event, int64_t *timestamp); +int bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event, int64_t *OUTPUT); uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event); const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event, const struct bt_definition *scope, @@ -356,13 +356,13 @@ uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock); int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq); uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock); int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision); -int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *offset_s); +int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *OUTPUT); int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, int64_t offset_s); -int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *offset); +int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *OUTPUT); int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, int64_t offset); int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock); int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute); -int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time); +int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *OUTPUT); int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time); void bt_ctf_clock_get(struct bt_ctf_clock *clock); void bt_ctf_clock_put(struct bt_ctf_clock *clock); diff --git a/bindings/python/reader.py b/bindings/python/reader.py index 35440336..52a51670 100644 --- a/bindings/python/reader.py +++ b/bindings/python/reader.py @@ -289,9 +289,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): @@ -300,9 +302,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): @@ -419,10 +423,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): diff --git a/bindings/python/writer.py b/bindings/python/writer.py index 3d4797eb..b419a271 100644 --- a/bindings/python/writer.py +++ b/bindings/python/writer.py @@ -168,9 +168,9 @@ class Clock: :exc:`ValueError` is raised on error. """ - offset_s = nbt._bt_ctf_clock_get_offset_s(self._c) + ret, offset_s = nbt._bt_ctf_clock_get_offset_s(self._c) - if offset_s == _MAX_UINT64: + if ret < 0: raise ValueError("Invalid clock instance") return offset_s @@ -193,9 +193,9 @@ class Clock: :exc:`ValueError` is raised on error. """ - offset = nbt._bt_ctf_clock_get_offset(self._c) + ret, offset = nbt._bt_ctf_clock_get_offset(self._c) - if offset == _MAX_UINT64: + if ret < 0: raise ValueError("Invalid clock instance") return offset @@ -280,9 +280,9 @@ class Clock: :exc:`ValueError` is raised on error. """ - time = nbt._bt_ctf_clock_get_time(self._c) + ret, time = nbt._bt_ctf_clock_get_time(self._c) - if time == _MAX_UINT64: + if ret < 0: raise ValueError("Invalid clock instance") return time -- 2.34.1