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;
}
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;
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;
}
*/
/* 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
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);
perror("fclose");
}
}
+ free(jul_filter);
return ret;
parse_error:
if (fclose(fmem) != 0) {
perror("fclose");
}
+ free(jul_filter);
return ret;
}
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();
}
}
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
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"
test_jul_loglevel_multiple
test_jul_before_start
test_jul_after_start
+ test_jul_multi_session
)
for fct_test in ${tests[@]};