From: Philippe Proulx Date: Sat, 29 Aug 2015 22:31:03 +0000 (-0400) Subject: Add lttng_event_get_filter_string() to liblttng-ctl X-Git-Tag: v2.8.0-rc1~142 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d31d3e8cf774b98a8ed46b8c7f6273364360f246;p=lttng-tools.git Add lttng_event_get_filter_string() to liblttng-ctl Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/event.h b/include/lttng/event.h index 06a63ccba..a85f0f3b5 100644 --- a/include/lttng/event.h +++ b/include/lttng/event.h @@ -295,6 +295,18 @@ struct lttng_event_field { extern int lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events); +/* + * Get the filter string of a specific LTTng event. + * + * If the call is successful, then the filter string's address is put + * in *filter_string. If the event has no filter string, *filter_string + * is set to NULL. The caller does NOT own *filter_string. + * + * Returns 0 on success, or a negative LTTng error code on error. + */ +extern int lttng_event_get_filter_string(struct lttng_event *event, + const char **filter_string); + /* * List the available tracepoints of a specific lttng domain. * diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 12bdf17cd..800859b8e 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -326,7 +326,7 @@ static int list_lttng_ust_global_events(char *channel_name, node = lttng_ht_iter_get_node_str(&iter); if (node == NULL) { ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; - goto error; + goto end; } uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node); @@ -335,7 +335,7 @@ static int list_lttng_ust_global_events(char *channel_name, if (nb_event == 0) { ret = nb_event; *total_size = 0; - goto error; + goto end; } DBG3("Listing UST global %d events", nb_event); @@ -350,6 +350,12 @@ static int list_lttng_ust_global_events(char *channel_name, increment_extended_len(uevent->filter_expression, &extended_len); } + if (nb_event == 0) { + /* All events are internal, skip. */ + ret = 0; + *total_size = 0; + goto end; + } *total_size = nb_event * sizeof(struct lttng_event) + extended_len; tmp = zmalloc(*total_size); @@ -407,8 +413,7 @@ static int list_lttng_ust_global_events(char *channel_name, ret = nb_event; *events = tmp; - -error: +end: rcu_read_unlock(); return ret; } diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 9cb2eb4a6..146783fd3 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -1782,6 +1782,38 @@ error: return ret; } +int lttng_event_get_filter_string(struct lttng_event *event, + const char **filter_string) +{ + int ret = 0; + struct lttcomm_event_extended_header *ext_header; + + if (!event || !filter_string) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + + if (!ext_header) { + /* + * This can happen since the lttng_event structure is + * used for other tasks where this pointer is never set. + */ + *filter_string = NULL; + goto end; + } + + if (ext_header->filter_len) { + *filter_string = ((const char *) (ext_header)) + + sizeof(*ext_header); + } else { + *filter_string = NULL; + } + +end: + return ret; +} /* * Sets the tracing_group variable with name.