Fix: disable event for JUL domain
authorDavid Goulet <dgoulet@efficios.com>
Fri, 5 Sep 2014 19:10:06 +0000 (15:10 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 5 Sep 2014 19:11:28 +0000 (15:11 -0400)
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 <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/event.h
src/bin/lttng-sessiond/jul.h
tests/regression/ust/java-jul/test_java_jul
tests/utils/utils.sh

index 8a17dd62a0ce39fc3e980fb9fd64bb78fe125207..8f8278eecd0d4515eda282495918c0c279e813f2 100644 (file)
@@ -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;
                }
index 1efa5a1badf2ee8c6eed919aaa19b522c99e606e..a82ed9183da3c200b522efac133e2b648601fab8 100644 (file)
@@ -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();
 
index e73814fd4ed8ba6dcaeca332fd87f1eed3506e3c..1df2367bfc341e32f033ed4960e640251674decf 100644 (file)
@@ -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);
index 55c9e18c758cdd3beb59bb9b9210dc626987593d..4a030895190506244844e88503a456c7f16dcdca 100644 (file)
@@ -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;
 };
 
 /*
index a91904af4b28f1323a9f5a04aad4e2d97d2c4151..0859e963fe4aee7f544ea37941ea306fb348282b 100755 (executable)
@@ -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
index 88304eb80083629b9e26a729ff046ae8855abda4..c2bebf4a267e856dde080643608322c39c8923d5 100644 (file)
@@ -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
+}
This page took 0.032456 seconds and 4 git commands to generate.