From b0bb560c74db6747bd9599af0896d7ef0dbaf77c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 16 Apr 2014 18:03:27 -0400 Subject: [PATCH] Add Python bindings for CTF-IR clock's getters 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 | 62 ++++++++++++++++++++++---- bindings/python/examples/ctf_writer.py | 8 ++++ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/bindings/python/babeltrace.i.in b/bindings/python/babeltrace.i.in index d2789991..4d9b3585 100644 --- a/bindings/python/babeltrace.i.in +++ b/bindings/python/babeltrace.i.in @@ -1246,23 +1246,39 @@ class _Definition(object): ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ */ %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name); +%rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock); +%rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc); +%rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq); +%rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision); +%rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s); +%rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset); +%rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute); +%rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time); %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock); %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock); struct bt_ctf_clock *bt_ctf_clock_create(const char *name); +const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock); +const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock); int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc); +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); +uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock); int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s); +uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock); int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_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); +uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock); int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time); void bt_ctf_clock_get(struct bt_ctf_clock *clock); void bt_ctf_clock_put(struct bt_ctf_clock *clock); @@ -1425,6 +1441,8 @@ void bt_ctf_writer_put(struct bt_ctf_writer *writer); %pythoncode %{ class CTFWriter: + # Used to compare to -1ULL in error checks + _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF class Clock: def __init__(self, name): @@ -1436,11 +1454,21 @@ class CTFWriter: _bt_ctf_clock_put(self._c) """ - Get the clock's description. + Get the clock's name. + """ + @property + def name(self): + name = _bt_ctf_clock_get_name(self._c) + if name is None: + raise ValueError("Invalid clock instance.") + return name + + """ + Get the clock's description. None if unset. """ @property def description(self): - raise NotImplementedError("Getter not implemented.") + return _bt_ctf_clock_get_description(self._c) """ Set the clock's description. The description appears in the clock's TSDL @@ -1457,7 +1485,10 @@ class CTFWriter: """ @property def frequency(self): - raise NotImplementedError("Getter not implemented.") + freq = _bt_ctf_clock_get_frequency(self._c) + if freq == CTFWriter._MAX_UINT64: + raise ValueError("Invalid clock instance") + return freq """ Set the clock's frequency (Hz). @@ -1473,7 +1504,10 @@ class CTFWriter: """ @property def precision(self): - raise NotImplementedError("Getter not implemented.") + precision = _bt_ctf_clock_get_precision(self._c) + if precision == CTFWriter._MAX_UINT64: + raise ValueError("Invalid clock instance") + return precision """ Set the clock's precision (in clock ticks). @@ -1487,7 +1521,10 @@ class CTFWriter: """ @property def offset_seconds(self): - raise NotImplementedError("Getter not implemented.") + offset_s = _bt_ctf_clock_get_offset_s(self._c) + if offset_s == CTFWriter._MAX_UINT64: + raise ValueError("Invalid clock instance") + return offset_s """ Set the clock's offset in seconds from POSIX.1 Epoch. @@ -1503,7 +1540,10 @@ class CTFWriter: """ @property def offset(self): - raise NotImplementedError("Getter not implemented.") + offset = _bt_ctf_clock_get_offset(self._c) + if offset == CTFWriter._MAX_UINT64: + raise ValueError("Invalid clock instance") + return offset """ Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds. @@ -1520,7 +1560,10 @@ class CTFWriter: """ @property def absolute(self): - raise NotImplementedError("Getter not implemented.") + is_absolute = _bt_ctf_clock_get_is_absolute(self._c) + if is_absolute == -1: + raise ValueError("Invalid clock instance") + return False if is_absolute == 0 else True """ Set a clock's absolute attribute. A clock is absolute if the clock @@ -1538,7 +1581,10 @@ class CTFWriter: """ @property def time(self): - raise NotImplementedError("Getter not implemented.") + time = _bt_ctf_clock_get_time(self._c) + if time == CTFWriter._MAX_UINT64: + raise ValueError("Invalid clock instance") + return time """ Set the current time in nanoseconds since the clock's origin (offset and diff --git a/bindings/python/examples/ctf_writer.py b/bindings/python/examples/ctf_writer.py index e3d48fc1..30163b59 100644 --- a/bindings/python/examples/ctf_writer.py +++ b/bindings/python/examples/ctf_writer.py @@ -27,7 +27,15 @@ print("Writing trace at {}".format(trace_path)) writer = CTFWriter.Writer(trace_path) clock = CTFWriter.Clock("A_clock") +print("Clock name is \"{}\"".format(clock.name)) clock.description = "Simple clock" +print("Clock description is \"{}\"".format(clock.description)) +print("Clock frequency is {}".format(clock.frequency)) +print("Clock precision is {}".format(clock.precision)) +print("Clock offset_seconds is {}".format(clock.offset_seconds)) +print("Clock offset is {}".format(clock.offset)) +print("Clock is absolute: {}".format(clock.absolute)) +print("Clock time is {}".format(clock.time)) writer.add_clock(clock) writer.add_environment_field("Python_version", str(sys.version_info)) -- 2.34.1