From 7e4347a3c70483b14015485ead05cee7e57ce95a Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 16 Mar 2015 19:24:57 -0400 Subject: [PATCH] ir: add bt_ctf_trace_get_clock_by_name() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/trace.c | 30 ++++++++++++++++++++++++++++++ include/babeltrace/ctf-ir/trace.h | 11 +++++++++++ 2 files changed, 41 insertions(+) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 78c2f28e..3f9bdb86 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -497,6 +497,36 @@ end: return stream_class; } +struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name( + struct bt_ctf_trace *trace, const char *name) +{ + size_t i; + struct bt_ctf_clock *clock = NULL; + + if (!trace || !name) { + goto end; + } + + for (i = 0; i < trace->clocks->len; ++i) { + struct bt_ctf_clock *cur_clk = + g_ptr_array_index(trace->clocks, i); + const char *cur_clk_name = bt_ctf_clock_get_name(cur_clk); + + if (!cur_clk_name) { + goto end; + } + + if (!strcmp(cur_clk_name, name)) { + clock = cur_clk; + bt_ctf_clock_get(clock); + goto end; + } + } + +end: + return clock; +} + BT_HIDDEN const char *get_byte_order_string(int byte_order) { diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index 03c281bc..bcef8973 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -253,6 +253,17 @@ extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace); extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class( struct bt_ctf_trace *trace, int index); +/* + * bt_ctf_trace_get_clock_by_name: get a trace's clock by name + * + * @param trace Trace instance. + * @param name Name of the clock in the given trace. + * + * Return a clock instance on success, NULL on error. + */ +extern struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name( + struct bt_ctf_trace *trace, const char *name); + /* * bt_ctf_trace_get_metadata_string: get metadata string. * -- 2.34.1