Add lttng_event_get_filter_string() to liblttng-ctl
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 29 Aug 2015 22:31:03 +0000 (18:31 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 3 Mar 2016 21:42:26 +0000 (16:42 -0500)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/event.h
src/bin/lttng-sessiond/cmd.c
src/lib/lttng-ctl/lttng-ctl.c

index 06a63ccba9dbb2626df9be08feb39707f0436d8b..a85f0f3b569ff002471a2f49af679ae35082177b 100644 (file)
@@ -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.
  *
index 12bdf17cd9e63f3e4e8c19703766026f468e2918..800859b8e55437919af0eba63d3278652eba1bed 100644 (file)
@@ -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;
 }
index 9cb2eb4a695648bfb3f4002248ffdeae3a6d6d64..146783fd3e5e09289ebb0d14d0606fd50a1c0aeb 100644 (file)
@@ -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.
This page took 0.039862 seconds and 4 git commands to generate.