From 56fa021be759b10596877bd1766e7a6cff234bfb Mon Sep 17 00:00:00 2001 From: David Goulet Date: Fri, 5 Sep 2014 15:10:06 -0400 Subject: [PATCH] Fix: disable event for JUL domain This fix could not be backported from master since it has changed too much but the ref. is 0dcfcf94b356c12e3936fa27f350896d96724e4e on the master branch. This fixes the disable event command that was not working with the JUL domain and adds a test for it. Signed-off-by: David Goulet --- src/bin/lttng-sessiond/cmd.c | 6 +- src/bin/lttng-sessiond/event.c | 77 +++++++++++++++------ src/bin/lttng-sessiond/event.h | 5 +- src/bin/lttng-sessiond/jul.h | 5 ++ tests/regression/ust/java-jul/test_java_jul | 28 +++++++- tests/utils/utils.sh | 29 ++++++++ 6 files changed, 122 insertions(+), 28 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 8a17dd62a..8f8278eec 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1460,9 +1460,9 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, /* The wild card * means that everything should be enabled. */ if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) { - ret = event_jul_enable_all(usess, event); + ret = event_jul_enable_all(usess, event, filter); } else { - ret = event_jul_enable(usess, event); + ret = event_jul_enable(usess, event, filter); } if (ret != LTTNG_OK) { goto error; @@ -1681,7 +1681,7 @@ int cmd_enable_event_all(struct ltt_session *session, strncpy(event.name, "*", sizeof(event.name)); event.name[sizeof(event.name) - 1] = '\0'; - ret = event_jul_enable_all(usess, &event); + ret = event_jul_enable_all(usess, &event, filter); if (ret != LTTNG_OK) { goto error; } diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 1efa5a1ba..a82ed9183 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -27,6 +27,7 @@ #include "channel.h" #include "event.h" #include "kernel.h" +#include "lttng-sessiond.h" #include "ust-ctl.h" #include "ust-app.h" #include "trace-kernel.h" @@ -616,7 +617,7 @@ error: * Return LTTNG_OK on success or else a LTTNG_ERR* code. */ int event_jul_enable_all(struct ltt_ust_session *usess, - struct lttng_event *event) + struct lttng_event *event, struct lttng_filter_bytecode *filter) { int ret; struct jul_event *jevent; @@ -627,7 +628,7 @@ int event_jul_enable_all(struct ltt_ust_session *usess, DBG("Event JUL enabling ALL events for session %" PRIu64, usess->id); /* Enable event on JUL application through TCP socket. */ - ret = event_jul_enable(usess, event); + ret = event_jul_enable(usess, event, filter); if (ret != LTTNG_OK) { goto error; } @@ -651,7 +652,8 @@ error: * * Return LTTNG_OK on success or else a LTTNG_ERR* code. */ -int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event) +int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event, + struct lttng_filter_bytecode *filter) { int ret, created = 0; struct jul_event *jevent; @@ -672,6 +674,7 @@ int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event) } jevent->loglevel = event->loglevel; jevent->loglevel_type = event->loglevel_type; + jevent->filter = filter; created = 1; } @@ -708,7 +711,10 @@ error: int event_jul_disable(struct ltt_ust_session *usess, char *event_name) { int ret; + char *ust_event_name; struct jul_event *jevent; + struct ltt_ust_event *uevent = NULL; + struct ltt_ust_channel *uchan = NULL; assert(usess); assert(event_name); @@ -726,6 +732,40 @@ int event_jul_disable(struct ltt_ust_session *usess, char *event_name) goto end; } + /* + * Disable it on the UST side. First get the channel reference then find + * the event and finally disable it. + */ + uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, + DEFAULT_JUL_CHANNEL_NAME); + if (!uchan) { + ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; + goto error; + } + + if (is_root) { + ust_event_name = DEFAULT_SYS_JUL_EVENT_NAME; + } else { + ust_event_name = DEFAULT_USER_JUL_EVENT_NAME; + } + + /* + * The loglevel is hardcoded with 0 here since the agent ust event is set + * with the loglevel type to ALL thus the loglevel stays 0. The event's + * filter is the one handling the loglevel for agent. + */ + uevent = trace_ust_find_event(uchan->events, ust_event_name, + jevent->filter, 0, NULL); + /* If the agent event exists, it must be available on the UST side. */ + assert(uevent); + + ret = ust_app_disable_event_glb(usess, uchan, uevent); + if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { + ret = LTTNG_ERR_UST_DISABLE_FAIL; + goto error; + } + uevent->enabled = 0; + ret = jul_disable_event(jevent); if (ret != LTTNG_OK) { goto error; @@ -737,6 +777,7 @@ end: error: return ret; } + /* * Disable all JUL event for a given UST session. * @@ -744,7 +785,7 @@ error: */ int event_jul_disable_all(struct ltt_ust_session *usess) { - int ret, do_disable = 0; + int ret; struct jul_event *jevent; struct lttng_ht_iter iter; @@ -752,31 +793,23 @@ int event_jul_disable_all(struct ltt_ust_session *usess) /* Enable event on JUL application through TCP socket. */ ret = event_jul_disable(usess, "*"); - if (ret != LTTNG_OK) { - if (ret == LTTNG_ERR_UST_EVENT_NOT_FOUND) { - /* - * This means that no enable all was done before but still a user - * could want to disable everything even though the * wild card - * event does not exists. - */ - do_disable = 1; - } else { - goto error; - } + if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) { + goto error; } /* Flag every event that they are now enabled. */ rcu_read_lock(); cds_lfht_for_each_entry(usess->domain_jul.events->ht, &iter.iter, jevent, node.node) { - if (jevent->enabled && do_disable) { - ret = event_jul_disable(usess, jevent->name); - if (ret != LTTNG_OK) { - rcu_read_unlock(); - goto error; - } + if (!jevent->enabled) { + continue; + } + + ret = event_jul_disable(usess, jevent->name); + if (ret != LTTNG_OK) { + rcu_read_unlock(); + goto error; } - jevent->enabled = 0; } rcu_read_unlock(); diff --git a/src/bin/lttng-sessiond/event.h b/src/bin/lttng-sessiond/event.h index e73814fd4..1df2367bf 100644 --- a/src/bin/lttng-sessiond/event.h +++ b/src/bin/lttng-sessiond/event.h @@ -46,9 +46,10 @@ int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess, int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, struct ltt_ust_channel *uchan); -int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event); +int event_jul_enable(struct ltt_ust_session *usess, struct lttng_event *event, + struct lttng_filter_bytecode *filter); int event_jul_enable_all(struct ltt_ust_session *usess, - struct lttng_event *event); + struct lttng_event *event, struct lttng_filter_bytecode *filter); int event_jul_disable(struct ltt_ust_session *usess, char *event_name); int event_jul_disable_all(struct ltt_ust_session *usess); diff --git a/src/bin/lttng-sessiond/jul.h b/src/bin/lttng-sessiond/jul.h index 55c9e18c7..4a0308951 100644 --- a/src/bin/lttng-sessiond/jul.h +++ b/src/bin/lttng-sessiond/jul.h @@ -84,6 +84,11 @@ struct jul_event { * Hash table nodes of the JUL domain. Indexed by name string. */ struct lttng_ht_node_str node; + + /* + * Filter that we keep to use it to disable an event. + */ + struct lttng_filter_bytecode *filter; }; /* diff --git a/tests/regression/ust/java-jul/test_java_jul b/tests/regression/ust/java-jul/test_java_jul index a91904af4..0859e963f 100755 --- a/tests/regression/ust/java-jul/test_java_jul +++ b/tests/regression/ust/java-jul/test_java_jul @@ -323,6 +323,31 @@ function test_jul_destroy_session() fi } +function test_jul_disable() +{ + diag "Test JUL disable event" + + create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME + # Enable all event with a filter. + enable_jul_lttng_event $SESSION_NAME $EVENT_NAME + enable_jul_lttng_event $SESSION_NAME $EVENT_NAME2 + disable_jul_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + + # Fire second TP but not the finest one. + run_app 0 1 + wait_apps + + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + + # Validate test. Expecting one event of the second TP only. + trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME + if [ $? -ne 0 ]; then + return $? + fi +} + plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" @@ -338,6 +363,7 @@ skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS || start_lttng_sessiond tests=( + test_jul_disable test_jul_multi_session_loglevel test_jul_destroy_session test_jul_loglevel @@ -355,7 +381,7 @@ skip $withapp "JUL support is needed. Skipping all tests." $NUM_TESTS || if [ $? -ne 0 ]; then break; fi - rm -rf $TRACE_PATH + #rm -rf $TRACE_PATH done stop_lttng_sessiond diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 88304eb80..c2bebf4a2 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -348,6 +348,15 @@ function disable_ust_lttng_event () ok $? "Disable event $event_name for session $sess_name" } +function disable_jul_lttng_event () +{ + local sess_name="$1" + local event_name="$2" + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 + ok $? "Disable JUL event $event_name for session $sess_name" +} + function start_lttng_tracing () { sess_name=$1 @@ -444,3 +453,23 @@ function validate_trace IFS=$OLDIFS return $ret } + +function trace_match_only() +{ + local event_name=$1 + local nr_iter=$2 + local trace_path=$3 + + which $BABELTRACE_BIN >/dev/null + skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" + + local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) + local total=$($BABELTRACE_BIN $trace_path | wc -l) + + if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then + pass "Trace match with $total event $event_name" + else + fail "Trace match" + diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" + fi +} -- 2.34.1