Send filter expression string to session daemon
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 Jan 2014 17:24:24 +0000 (12:24 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 6 Mar 2014 19:21:20 +0000 (14:21 -0500)
Send the filter expression string along with the filter's bytecode to
the session daemon. The session daemon now stores the filter expression.
This makes it possible to list the filter's expression when listing
events.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/cmd.h
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/event.h
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/trace-ust.h
src/common/sessiond-comm/sessiond-comm.h
src/lib/lttng-ctl/lttng-ctl.c
tests/unit/test_ust_data.c

index 812c850faa73b9b4efb34b5030c6f46dd22c00d2..4b8d82efe255d398d9e5eba605be42d96cec5421 100644 (file)
@@ -1309,6 +1309,7 @@ error:
  */
 int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                char *channel_name, struct lttng_event *event,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion,
                int wpipe)
@@ -1424,7 +1425,8 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                }
 
                /* At this point, the session and channel exist on the tracer */
-               ret = event_ust_enable_tracepoint(usess, uchan, event, filter, exclusion);
+               ret = event_ust_enable_tracepoint(usess, uchan, event,
+                               filter_expression, filter, exclusion);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1460,7 +1462,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                tmp_dom.type = LTTNG_DOMAIN_UST;
 
                ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
-                               &uevent, NULL, NULL, wpipe);
+                       &uevent, NULL, NULL, NULL, wpipe);
                if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
                        goto error;
                }
@@ -1499,6 +1501,7 @@ error:
  */
 int cmd_enable_event_all(struct ltt_session *session,
                struct lttng_domain *domain, char *channel_name, int event_type,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter, int wpipe)
 {
        int ret;
@@ -1632,7 +1635,8 @@ int cmd_enable_event_all(struct ltt_session *session,
                switch (event_type) {
                case LTTNG_EVENT_ALL:
                case LTTNG_EVENT_TRACEPOINT:
-                       ret = event_ust_enable_all_tracepoints(usess, uchan, filter);
+                       ret = event_ust_enable_all_tracepoints(usess, uchan,
+                               filter_expression, filter);
                        if (ret != LTTNG_OK) {
                                goto error;
                        }
@@ -1678,7 +1682,7 @@ int cmd_enable_event_all(struct ltt_session *session,
                tmp_dom.type = LTTNG_DOMAIN_UST;
 
                ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
-                               &uevent, NULL, NULL, wpipe);
+                       &uevent, NULL, NULL, NULL, wpipe);
                if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
                        goto error;
                }
index b5264f713d2b3136eb99389f54e807c68d1ea2f7..5de3590abf646becf6b3a8d52865175106596e7a 100644 (file)
@@ -53,11 +53,13 @@ int cmd_set_filter(struct ltt_session *session, int domain,
                struct lttng_filter_bytecode *bytecode);
 int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                char *channel_name, struct lttng_event *event,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion,
                int wpipe);
 int cmd_enable_event_all(struct ltt_session *session,
                struct lttng_domain *domain, char *channel_name, int event_type,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter, int wpipe);
 
 /* Trace session action commands */
index 1efa5a1badf2ee8c6eed919aaa19b522c99e606e..da6a2913fc217352734fe821306ff8ae4879775a 100644 (file)
@@ -314,7 +314,9 @@ end:
  * Enable all UST tracepoints for a channel from a UST session.
  */
 int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, struct lttng_filter_bytecode *filter)
+               struct ltt_ust_channel *uchan,
+               char *filter_expression,
+               struct lttng_filter_bytecode *filter)
 {
        int ret, i, size;
        struct lttng_ht_iter iter;
@@ -365,7 +367,8 @@ int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess,
                }
 
                /* Create ust event */
-               uevent = trace_ust_create_event(&events[i], filter, NULL);
+               uevent = trace_ust_create_event(&events[i], filter_expression,
+                       filter, NULL);
                if (uevent == NULL) {
                        ret = LTTNG_ERR_FATAL;
                        goto error_destroy;
@@ -409,6 +412,7 @@ error:
  */
 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct lttng_event *event,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion)
 {
@@ -424,7 +428,8 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
        uevent = trace_ust_find_event(uchan->events, event->name, filter,
                        event->loglevel, exclusion);
        if (uevent == NULL) {
-               uevent = trace_ust_create_event(event, filter, exclusion);
+               uevent = trace_ust_create_event(event, filter_expression,
+                       filter, exclusion);
                if (uevent == NULL) {
                        ret = LTTNG_ERR_UST_ENABLE_FAIL;
                        goto error;
index e73814fd4ed8ba6dcaeca332fd87f1eed3506e3c..4080c4f93a56c06975bc5df27502f77ea2ccc80e 100644 (file)
@@ -37,12 +37,15 @@ int event_kernel_enable_all(struct ltt_kernel_channel *kchan,
 
 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct lttng_event *event,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion);
 int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, char *event_name);
 int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, struct lttng_filter_bytecode *filter);
+               struct ltt_ust_channel *uchan,
+               char *filter_expression,
+               struct lttng_filter_bytecode *filter);
 int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan);
 
index 605e91dc382f8893cc9f480c590e70afbdd1e998..4d81896bfd121cbe8163bafcc62fe65f3c134c08 100644 (file)
@@ -3039,6 +3039,7 @@ skip_domain:
        {
                struct lttng_event_exclusion *exclusion = NULL;
                struct lttng_filter_bytecode *bytecode = NULL;
+               char *filter_expression = NULL;
 
                /* Handle exclusion events and receive it from the client. */
                if (cmd_ctx->lsm->u.enable.exclusion_count > 0) {
@@ -3064,6 +3065,38 @@ skip_domain:
                        }
                }
 
+               /* Get filter expression from client. */
+               if (cmd_ctx->lsm->u.enable.expression_len > 0) {
+                       size_t expression_len =
+                               cmd_ctx->lsm->u.enable.expression_len;
+
+                       if (expression_len > LTTNG_FILTER_MAX_LEN) {
+                               ret = LTTNG_ERR_FILTER_INVAL;
+                               free(exclusion);
+                               goto error;
+                       }
+
+                       filter_expression = zmalloc(expression_len);
+                       if (!filter_expression) {
+                               free(exclusion);
+                               ret = LTTNG_ERR_FILTER_NOMEM;
+                               goto error;
+                       }
+
+                       /* Receive var. len. data */
+                       DBG("Receiving var len filter's expression from client ...");
+                       ret = lttcomm_recv_unix_sock(sock, filter_expression,
+                               expression_len);
+                       if (ret <= 0) {
+                               DBG("Nothing recv() from client car len data... continuing");
+                               *sock_error = 1;
+                               free(filter_expression);
+                               free(exclusion);
+                               ret = LTTNG_ERR_FILTER_INVAL;
+                               goto error;
+                       }
+               }
+
                /* Handle filter and get bytecode from client. */
                if (cmd_ctx->lsm->u.enable.bytecode_len > 0) {
                        size_t bytecode_len = cmd_ctx->lsm->u.enable.bytecode_len;
@@ -3103,7 +3136,8 @@ skip_domain:
 
                ret = cmd_enable_event(cmd_ctx->session, &cmd_ctx->lsm->domain,
                                cmd_ctx->lsm->u.enable.channel_name,
-                               &cmd_ctx->lsm->u.enable.event, bytecode, exclusion,
+                               &cmd_ctx->lsm->u.enable.event,
+                               filter_expression, bytecode, exclusion,
                                kernel_poll_pipe[1]);
                break;
        }
@@ -3113,7 +3147,8 @@ skip_domain:
 
                ret = cmd_enable_event_all(cmd_ctx->session, &cmd_ctx->lsm->domain,
                                cmd_ctx->lsm->u.enable.channel_name,
-                               cmd_ctx->lsm->u.enable.event.type, NULL, kernel_poll_pipe[1]);
+                               cmd_ctx->lsm->u.enable.event.type, NULL, NULL,
+                               kernel_poll_pipe[1]);
                break;
        }
        case LTTNG_LIST_TRACEPOINTS:
index 996916558f8b3a0d5fd1c3d5945fe11783368d53..8d3c7dcf8e8e59f3962c991225b67174a5414d22 100644 (file)
@@ -340,6 +340,7 @@ error:
  * Return pointer to structure or NULL.
  */
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion)
 {
@@ -394,6 +395,7 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
        }
 
        /* Same layout. */
+       lue->filter_expression = filter_expression;
        lue->filter = (struct lttng_ust_filter_bytecode *) filter;
        lue->exclusion = (struct lttng_event_exclusion *) exclusion;
 
@@ -511,6 +513,7 @@ void trace_ust_destroy_event(struct ltt_ust_event *event)
        assert(event);
 
        DBG2("Trace destroy UST event %s", event->attr.name);
+       free(event->filter_expression);
        free(event->filter);
        free(event->exclusion);
        free(event);
index 6c6c6c454a53abba8dd480c40160848c8b84d4ac..6a41f0f9fbcdf6994c9807d153e37051b513bcdc 100644 (file)
@@ -49,6 +49,7 @@ struct ltt_ust_event {
        unsigned int enabled;
        struct lttng_ust_event attr;
        struct lttng_ht_node_str node;
+       char *filter_expression;
        struct lttng_ust_filter_bytecode *filter;
        struct lttng_event_exclusion *exclusion;
 };
@@ -162,6 +163,7 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr);
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
+               char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion);
 struct ltt_ust_context *trace_ust_create_context(
@@ -208,6 +210,7 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr)
 }
 static inline
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
+               const char *filter_expression,
                struct lttng_filter_bytecode *filter,
                struct lttng_event_exclusion *exclusion)
 {
index 96106a77dee0e1a35905313d8c0d0e592b16e3bd..7ce252d591f28b609216bb1ec2d1a367051694d4 100644 (file)
@@ -232,6 +232,8 @@ struct lttcomm_session_msg {
                struct {
                        char channel_name[LTTNG_SYMBOL_NAME_LEN];
                        struct lttng_event event;
+                       /* Length of following filter expression. */
+                       uint32_t expression_len;
                        /* Length of following bytecode for filter. */
                        uint32_t bytecode_len;
                        /* exclusion data */
@@ -240,6 +242,7 @@ struct lttcomm_session_msg {
                         * After this structure, the following variable-length
                         * items are transmitted:
                         * - char exclusion_names[LTTNG_SYMBOL_NAME_LEN][exclusion_count]
+                        * - unsigned char filter_expression[expression_len]
                         * - unsigned char filter_bytecode[bytecode_len]
                         */
                } LTTNG_PACKED enable;
index 94f075b460f2b9ed541e0610691cb18bfb1a67d0..8e2593db125acb4f30c0a7e7b076395b685682f3 100644 (file)
@@ -834,40 +834,43 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
 
                lsm.u.enable.bytecode_len = sizeof(ctx->bytecode->b)
                                + bytecode_get_len(&ctx->bytecode->b);
-       }
-
-       /* Allocate variable length data */
-       if (lsm.u.enable.exclusion_count != 0) {
-               varlen_data = zmalloc(lsm.u.enable.bytecode_len
-                               + LTTNG_SYMBOL_NAME_LEN * exclusion_count);
-               if (!varlen_data) {
-                       ret = -LTTNG_ERR_EXCLUSION_NOMEM;
-                       goto varlen_alloc_error;
-               }
-               /* Put exclusion names first in the data */
-               while (exclusion_count--) {
-                       strncpy(varlen_data + LTTNG_SYMBOL_NAME_LEN * exclusion_count,
-                                       *(exclusion_list + exclusion_count),
-                                       LTTNG_SYMBOL_NAME_LEN);
-               }
-               /* Add filter bytecode next */
-               if (lsm.u.enable.bytecode_len != 0) {
-                       memcpy(varlen_data + LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count,
-                                       &ctx->bytecode->b,
-                                       lsm.u.enable.bytecode_len);
-               }
-       } else {
-               /* no exclusions - use the already allocated filter bytecode */
-               varlen_data = (char *)(&ctx->bytecode->b);
+               lsm.u.enable.expression_len = strlen(filter_expression) + 1;
+       }
+
+       varlen_data = zmalloc(lsm.u.enable.bytecode_len
+                             + lsm.u.enable.expression_len
+                             + LTTNG_SYMBOL_NAME_LEN * exclusion_count);
+       if (!varlen_data) {
+               ret = -LTTNG_ERR_EXCLUSION_NOMEM;
+               goto varlen_alloc_error;
+       }
+       /* Put exclusion names first in the data */
+       while (exclusion_count--) {
+               strncpy(varlen_data + LTTNG_SYMBOL_NAME_LEN * exclusion_count,
+                       *(exclusion_list + exclusion_count),
+                       LTTNG_SYMBOL_NAME_LEN);
+       }
+       /* Add filter expression next */
+       if (lsm.u.enable.expression_len != 0) {
+               memcpy(varlen_data
+                       + LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count,
+                       filter_expression,
+                       lsm.u.enable.expression_len);
+       }
+       /* Add filter bytecode next */
+       if (lsm.u.enable.bytecode_len != 0) {
+               memcpy(varlen_data
+                       + LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count
+                       + lsm.u.enable.expression_len,
+                       &ctx->bytecode->b,
+                       lsm.u.enable.bytecode_len);
        }
 
        ret = lttng_ctl_ask_sessiond_varlen(&lsm, varlen_data,
                        (LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count) +
-                       lsm.u.enable.bytecode_len, NULL);
-
-       if (lsm.u.enable.exclusion_count != 0) {
-               free(varlen_data);
-       }
+                       lsm.u.enable.bytecode_len + lsm.u.enable.expression_len,
+                       NULL);
+       free(varlen_data);
 
 varlen_alloc_error:
        if (filter_expression) {
index d07e9347d2d81cc31cb6bddefda780aa4f9f4a25..bc3154c288662f149e0409361392239d10fd85f1 100644 (file)
@@ -124,7 +124,7 @@ static void test_create_ust_event(void)
        ev.type = LTTNG_EVENT_TRACEPOINT;
        ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
 
-       event = trace_ust_create_event(&ev, NULL, NULL);
+       event = trace_ust_create_event(&ev, NULL, NULL, NULL);
 
        ok(event != NULL, "Create UST event");
 
@@ -159,7 +159,7 @@ static void test_create_ust_event_exclusion(void)
        exclusion->count = 1;
        strncpy((char *)(exclusion->names), get_random_string(), LTTNG_SYMBOL_NAME_LEN);
 
-       event = trace_ust_create_event(&ev, NULL, exclusion);
+       event = trace_ust_create_event(&ev, NULL, NULL, exclusion);
 
        ok(event != NULL, "Create UST event with exclusion");
 
This page took 0.051113 seconds and 4 git commands to generate.