From 6b453b5e07e90591c955ae14c60c13b7c1ed28a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 21 Jan 2014 12:24:24 -0500 Subject: [PATCH] Send filter expression string to session daemon MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: David Goulet --- src/bin/lttng-sessiond/cmd.c | 12 +++-- src/bin/lttng-sessiond/cmd.h | 2 + src/bin/lttng-sessiond/event.c | 11 +++-- src/bin/lttng-sessiond/event.h | 5 +- src/bin/lttng-sessiond/main.c | 39 ++++++++++++++- src/bin/lttng-sessiond/trace-ust.c | 3 ++ src/bin/lttng-sessiond/trace-ust.h | 3 ++ src/common/sessiond-comm/sessiond-comm.h | 3 ++ src/lib/lttng-ctl/lttng-ctl.c | 63 +++++++++++++----------- tests/unit/test_ust_data.c | 4 +- 10 files changed, 103 insertions(+), 42 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 812c850fa..4b8d82efe 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h index b5264f713..5de3590ab 100644 --- a/src/bin/lttng-sessiond/cmd.h +++ b/src/bin/lttng-sessiond/cmd.h @@ -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 */ diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 1efa5a1ba..da6a2913f 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -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; diff --git a/src/bin/lttng-sessiond/event.h b/src/bin/lttng-sessiond/event.h index e73814fd4..4080c4f93 100644 --- a/src/bin/lttng-sessiond/event.h +++ b/src/bin/lttng-sessiond/event.h @@ -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); diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 605e91dc3..4d81896bf 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -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: diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 996916558..8d3c7dcf8 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -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); diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index 6c6c6c454..6a41f0f9f 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -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) { diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 96106a77d..7ce252d59 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -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; diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 94f075b46..8e2593db1 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -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) { diff --git a/tests/unit/test_ust_data.c b/tests/unit/test_ust_data.c index d07e9347d..bc3154c28 100644 --- a/tests/unit/test_ust_data.c +++ b/tests/unit/test_ust_data.c @@ -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"); -- 2.34.1