From: David Goulet Date: Tue, 15 Apr 2014 19:05:42 +0000 (-0400) Subject: Fix: add JUL filter to UST event on logger_name X-Git-Tag: v2.5.0-rc1~60 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9b21e6d59ee650f44a0db24cf7f75e08fbd0fe9c;p=lttng-tools.git Fix: add JUL filter to UST event on logger_name This is to avoid having the JUL event copied in each sessions. See ticket description for more details. To achieve this, JUL filtering has been added to fix that bug. Fixes #773 Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index ea25a5e47..bb9329f30 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1445,7 +1445,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, NULL, wpipe); + &uevent, filter_expression, filter, NULL, wpipe); if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) { goto error; } diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 100e587d9..756fd6b59 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -708,7 +708,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, int exclusion_count, char **exclusion_list) { struct lttcomm_session_msg lsm; - char *varlen_data; + char *varlen_data, *jul_filter = NULL; int ret = 0; struct filter_parser_ctx *ctx = NULL; FILE *fmem = NULL; @@ -750,7 +750,13 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, lsm.u.enable.exclusion_count = exclusion_count; lsm.u.enable.bytecode_len = 0; - if (exclusion_count == 0 && filter_expression == NULL) { + /* + * For the JUL domain, a filter is enforced except for the enable all + * event. This is done to avoid having the event in all sessions thus + * filtering by logger name. + */ + if (exclusion_count == 0 && filter_expression == NULL && + (handle->domain.type != LTTNG_DOMAIN_JUL || ev->name[0] == '*')) { ret = lttng_ctl_ask_sessiond(&lsm, NULL); return ret; } @@ -761,7 +767,23 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, */ /* Parse filter expression */ - if (filter_expression != NULL) { + if (filter_expression != NULL || + (handle->domain.type == LTTNG_DOMAIN_JUL && ev->name[0] != '*')) { + if (handle->domain.type == LTTNG_DOMAIN_JUL) { + int err; + + if (filter_expression) { + err = asprintf(&jul_filter, "%s && logger_name == \"%s\"", + filter_expression, ev->name); + } else { + err = asprintf(&jul_filter, "logger_name == \"%s\"", ev->name); + } + if (err < 0) { + PERROR("asprintf"); + return -LTTNG_ERR_NOMEM; + } + filter_expression = jul_filter; + } /* * casting const to non-const, as the underlying function will @@ -771,6 +793,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, strlen(filter_expression), "r"); if (!fmem) { fprintf(stderr, "Error opening memory as stream\n"); + free(jul_filter); return -LTTNG_ERR_FILTER_NOMEM; } ctx = filter_parser_ctx_alloc(fmem); @@ -881,6 +904,7 @@ varlen_alloc_error: perror("fclose"); } } + free(jul_filter); return ret; parse_error: @@ -891,6 +915,7 @@ filter_alloc_error: if (fclose(fmem) != 0) { perror("fclose"); } + free(jul_filter); return ret; } diff --git a/tests/regression/ust/java-jul/JTestLTTng.java b/tests/regression/ust/java-jul/JTestLTTng.java index b39f7e345..24f4e7e1f 100644 --- a/tests/regression/ust/java-jul/JTestLTTng.java +++ b/tests/regression/ust/java-jul/JTestLTTng.java @@ -28,21 +28,35 @@ public class JTestLTTng public static void main(String args[]) throws Exception { Logger lttng = Logger.getLogger("JTestLTTng"); + Logger lttng2 = Logger.getLogger("JTestLTTng2"); int nrIter = Integer.parseInt(args[0]); int waitTime = Integer.parseInt(args[1]); + int fire_finest_tp = 0; + int fire_second_tp = 0; + + if (args.length > 2) { + fire_finest_tp = Integer.parseInt(args[2]); + } + if (args.length > 3) { + fire_second_tp = Integer.parseInt(args[3]); + } lttngAgent = LTTngAgent.getLTTngAgent(); lttng.setLevel(Level.FINEST); for (int iter = 0; iter < nrIter; iter++) { lttng.info("JUL tp fired!"); - if (args.length == 3) { + if (fire_finest_tp == 1) { /* Third arg, trigger finest TP. */ lttng.finest("JUL FINEST tp fired"); } Thread.sleep(waitTime); } + if (fire_second_tp == 1) { + lttng2.info("JUL second logger fired"); + } + lttngAgent.dispose(); } } diff --git a/tests/regression/ust/java-jul/test_java_jul b/tests/regression/ust/java-jul/test_java_jul index bd6a0e9b3..50452023b 100755 --- a/tests/regression/ust/java-jul/test_java_jul +++ b/tests/regression/ust/java-jul/test_java_jul @@ -26,19 +26,21 @@ TESTAPP_BIN="$TESTAPP_NAME.java" TESTAPP_PATH="$CURDIR/$TESTAPP_NAME" SESSION_NAME="jul" EVENT_NAME="JTestLTTng" +EVENT_NAME2="JTestLTTng2" JAVA_CP="$CURDIR:/usr/local/lib/lttng/java/liblttng-ust-jul.jar:/usr/lib/lttng/java/liblttng-ust-jul.jar" TRACE_PATH=$(mktemp -d) -NUM_TESTS=53 +NUM_TESTS=66 source $TESTDIR/utils/utils.sh function run_app { local finest_tp=$1 + local fire_second_tp=$2 - java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp >/dev/null 2>&1 & + java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1 & } function wait_apps @@ -199,6 +201,40 @@ function test_jul_loglevel_multiple () fi } +function test_jul_multi_session() +{ + diag "Test JUL with multiple session" + + create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 + enable_jul_lttng_event $SESSION_NAME-1 $EVENT_NAME + start_lttng_tracing $SESSION_NAME-1 + + create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 + enable_jul_lttng_event $SESSION_NAME-2 $EVENT_NAME2 + start_lttng_tracing $SESSION_NAME-2 + + # Run 5 times with a 1 second delay and fire second TP. + run_app 0 1 + wait_apps + + stop_lttng_tracing $SESSION_NAME-1 + stop_lttng_tracing $SESSION_NAME-2 + destroy_lttng_session $SESSION_NAME-1 + destroy_lttng_session $SESSION_NAME-2 + + # Validate test. Expecting all events of first TP + trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1 + if [ $? -ne 0 ]; then + return $? + fi + + # Validate test. Expecting one event of the second TP. + trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 + if [ $? -ne 0 ]; then + return $? + fi +} + plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" @@ -218,6 +254,7 @@ skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS || test_jul_loglevel_multiple test_jul_before_start test_jul_after_start + test_jul_multi_session ) for fct_test in ${tests[@]};