Fix: add JUL filter to UST event on logger_name
authorDavid Goulet <dgoulet@efficios.com>
Tue, 15 Apr 2014 19:05:42 +0000 (15:05 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 5 May 2014 14:27:41 +0000 (10:27 -0400)
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 <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/lib/lttng-ctl/lttng-ctl.c
tests/regression/ust/java-jul/JTestLTTng.java
tests/regression/ust/java-jul/test_java_jul

index ea25a5e470a690182a2e0daed6f4777d511e4f47..bb9329f308ac90d56dd28c0e66254a3378b0022b 100644 (file)
@@ -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;
                }
index 100e587d9e206905b1327bfd790f5b8f1888a8ac..756fd6b590ef80bd89c7f8fabbdf67f765d4e135 100644 (file)
@@ -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;
 }
 
index b39f7e3455ff555ba12a661488c3770760e8d8f3..24f4e7e1faf7b200cf7f885ad9fcb84c32de0d5a 100644 (file)
@@ -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();
        }
 }
index bd6a0e9b3dd701ac1677f7065e4350e28ef6cfde..50452023b55e49538a0df3f60cdae1198d48e3d8 100755 (executable)
@@ -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[@]};
This page took 0.031256 seconds and 4 git commands to generate.