Add disable all UST event(s) command
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 24 Nov 2011 20:11:52 +0000 (15:11 -0500)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 24 Nov 2011 20:11:52 +0000 (15:11 -0500)
Note that you can only disable all events for a specific channel (like
the kernel). So, using the UST global domain (-u -a), only the event(s)
in the specified channel will be disabled for all registered
applications.

Bottom line, it disables all events in a channel.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng-sessiond/main.c
lttng-sessiond/ust-app.c
lttng-sessiond/ust-app.h
lttng/commands/disable_events.c

index 8850fc0f9288463307f14c5bcd79f20c28ab09ff..b2d421e56b15b8bd9e6534a35819d9755853d8f2 100644 (file)
@@ -2315,26 +2315,57 @@ static int cmd_disable_event_all(struct ltt_session *session, int domain,
                char *channel_name)
 {
        int ret;
-       struct ltt_kernel_channel *kchan;
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
-               kchan = trace_kernel_get_channel_by_name(channel_name,
-                               session->kernel_session);
+       {
+               struct ltt_kernel_session *ksess;
+               struct ltt_kernel_channel *kchan;
+
+               ksess = session->kernel_session;
+
+               kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
                if (kchan == NULL) {
                        ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
                        goto error;
                }
 
-               ret = event_kernel_disable_all(session->kernel_session, kchan);
+               ret = event_kernel_disable_all(ksess, kchan);
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
 
                kernel_wait_quiescent(kernel_tracer_fd);
                break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_session *usess;
+               struct ltt_ust_channel *uchan;
+
+               usess = session->ust_session;
+
+               uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
+                               channel_name);
+               if (uchan == NULL) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+
+               ret = ust_app_disable_event_all(usess, uchan);
+               if (ret < 0) {
+                       ret = LTTCOMM_UST_DISABLE_FAIL;
+                       goto error;
+               }
+
+               DBG2("Disable all UST event in channel %s completed", channel_name);
+
+               break;
+       }
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
        default:
-               /* TODO: Userspace tracing */
                ret = LTTCOMM_NOT_IMPLEMENTED;
                goto error;
        }
index e5bd47c7d2770721148af4505223823aa14d5d78..e0f907fbd0ff2d42b65f3a01fd4d33d9a33d03ee 100644 (file)
@@ -244,6 +244,29 @@ error:
        return NULL;
 }
 
+/*
+ * Disable the specified event on to UST tracer for the UST session.
+ */
+static int disable_ust_event(struct ust_app *app,
+               struct ust_app_session *ua_sess, struct ust_app_event *ua_event)
+{
+       int ret;
+
+       ret = ustctl_disable(app->key.sock, ua_event->obj);
+       if (ret < 0) {
+               ERR("UST app event %s disable failed for app (pid: %d) "
+                               "and session handle %d with ret %d",
+                               ua_event->attr.name, app->key.pid, ua_sess->handle, ret);
+               goto error;
+       }
+
+       DBG2("UST app event %s disabled successfully for app (pid: %d)",
+                       ua_event->attr.name, app->key.pid);
+
+error:
+       return ret;
+}
+
 /*
  * Disable the specified channel on to UST tracer for the UST session.
  */
@@ -704,6 +727,26 @@ error:
        return NULL;
 }
 
+/*
+ * Disable on the tracer side a ust app event for the session and channel.
+ */
+static int disable_ust_app_event(struct ust_app_session *ua_sess,
+               struct ust_app_channel *ua_chan, struct ust_app_event *ua_event,
+               struct ust_app *app)
+{
+       int ret;
+
+       ret = disable_ust_event(app, ua_sess, ua_event);
+       if (ret < 0) {
+               goto error;
+       }
+
+       ua_event->enabled = 0;
+
+error:
+       return ret;
+}
+
 /*
  * Lookup ust app channel for session and disable it on the tracer side.
  */
@@ -1227,6 +1270,60 @@ error:
        return ret;
 }
 
+/*
+ * For a specific UST session and UST channel, create the event for all
+ * registered apps.
+ */
+int ust_app_disable_event_all(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan)
+{
+       int ret = 0;
+       struct cds_lfht_iter iter, uiter;
+       struct cds_lfht_node *ua_chan_node;
+       struct ust_app *app;
+       struct ust_app_session *ua_sess;
+       struct ust_app_channel *ua_chan;
+       struct ust_app_event *ua_event;
+
+       DBG("UST app disabling all event for all apps in channel "
+                       "%s for session uid %d", uchan->name, usess->uid);
+
+       rcu_read_lock();
+
+       /* For all registered applications */
+       cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
+               ua_sess = lookup_session_by_app(usess, app);
+               if (ua_sess == NULL) {
+                       /* Next app */
+                       continue;
+               }
+
+               /* Lookup channel in the ust app session */
+               ua_chan_node = hashtable_lookup(ua_sess->channels,
+                               (void *)uchan->name, strlen(uchan->name),
+                               &uiter);
+               if (ua_chan_node == NULL) {
+                       DBG2("Channel %s not found in session uid %d for app pid %d."
+                                       "Skipping", uchan->name, app->key.pid, usess->uid);
+                       continue;
+               }
+               ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+
+               /* Disable each events of channel */
+               cds_lfht_for_each_entry(ua_chan->events, &uiter, ua_event, node) {
+                       ret = disable_ust_app_event(ua_sess, ua_chan, ua_event, app);
+                       if (ret < 0) {
+                               /* XXX: Report error someday... */
+                               continue;
+                       }
+               }
+       }
+
+       rcu_read_unlock();
+
+       return ret;
+}
+
 /*
  * For a specific UST session, create the channel for all registered apps.
  */
index 0446363c37c78b0bcf296d5aa782bd3749e3063d..dafca85b0203b86046826a301ab79fe4152b4284 100644 (file)
@@ -126,6 +126,8 @@ int ust_app_disable_channel_all(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan);
 int ust_app_enable_channel_all(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan);
+int ust_app_disable_event_all(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan);
 void ust_app_global_update(struct ltt_ust_session *usess, int sock);
 
 void ust_app_clean_list(void);
index 13ebd6c3acff763b235bfc4748fab0404716c81c..1891cd2e34729cc45b94ec3c2f4da12f8f9391dc 100644 (file)
@@ -30,7 +30,7 @@
 #include "../utils.h"
 
 static char *opt_event_list;
-static char *opt_kernel;
+static int opt_kernel;
 static char *opt_channel_name;
 static char *opt_session_name;
 static int opt_pid_all;
@@ -69,7 +69,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "  -h, --help               Show this help\n");
        fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -c, --channel            Apply on this channel\n");
-       fprintf(ofp, "  -a, --all-events         Enable all tracepoints\n");
+       fprintf(ofp, "  -a, --all-events         Disable all tracepoints\n");
        fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
        fprintf(ofp, "  -u, --userspace [CMD]    Apply for the user-space tracer\n");
        fprintf(ofp, "      --all                If -u, apply on all traceable apps\n");
@@ -100,6 +100,20 @@ static int disable_events(char *session_name)
 
        if (opt_kernel) {
                dom.type = LTTNG_DOMAIN_KERNEL;
+       } else if (opt_pid != 0) {
+               dom.type = LTTNG_DOMAIN_UST_PID;
+               dom.attr.pid = opt_pid;
+               DBG("PID %d set to lttng handle", opt_pid);
+       } else if (opt_userspace && opt_cmd_name == NULL) {
+               dom.type = LTTNG_DOMAIN_UST;
+               DBG("UST global domain selected");
+       } else if (opt_userspace && opt_cmd_name != NULL) {
+               dom.type = LTTNG_DOMAIN_UST_EXEC_NAME;
+               strncpy(dom.attr.exec_name, opt_cmd_name, NAME_MAX);
+       } else {
+               ERR("Please specify a tracer (--kernel or --userspace)");
+               ret = CMD_NOT_IMPLEMENTED;
+               goto error;
        }
 
        handle = lttng_create_handle(session_name, &dom);
@@ -109,12 +123,14 @@ static int disable_events(char *session_name)
        }
 
        if (opt_disable_all) {
-               if (opt_kernel) {
-                       ret = lttng_disable_event(handle, NULL, channel_name);
+               ret = lttng_disable_event(handle, NULL, channel_name);
+               if (ret < 0) {
                        goto error;
                }
 
-               /* TODO: User-space tracer */
+               MSG("All %s events are disabled in channel %s",
+                               opt_kernel ? "kernel" : "UST", channel_name);
+               goto end;
        }
 
        /* Strip event list */
@@ -122,35 +138,37 @@ static int disable_events(char *session_name)
        while (event_name != NULL) {
                /* Kernel tracer action */
                if (opt_kernel) {
-                       DBG("Disabling kernel event %s for channel %s",
+                       DBG("Disabling kernel event %s in channel %s",
                                        event_name, channel_name);
-
-                       ret = lttng_disable_event(handle, event_name, channel_name);
-                       if (ret < 0) {
-                               MSG("Unable to disable event %s for channel %s",
-                                               event_name, channel_name);
-                       } else {
-                               MSG("Kernel event %s disabled for channel %s",
-                                               event_name, channel_name);
-                       }
                } else if (opt_userspace) {             /* User-space tracer action */
-                       /*
-                        * TODO: Waiting on lttng UST 2.0
-                        */
-                       if (opt_pid_all) {
-                       } else if (opt_pid != 0) {
+                       if (!opt_pid_all) {
+                               MSG("Only supporting tracing all UST processes (-u --all) for now.");
+                               ret = CMD_NOT_IMPLEMENTED;
+                               goto error;
                        }
-                       ret = CMD_NOT_IMPLEMENTED;
-                       goto error;
+                       DBG("Disabling UST event %s in channel %s",
+                                       event_name, channel_name);
                } else {
                        ERR("Please specify a tracer (--kernel or --userspace)");
                        goto error;
                }
 
+               ret = lttng_disable_event(handle, event_name, channel_name);
+               if (ret < 0) {
+                       MSG("Unable to disable %s event %s in channel %s",
+                                       opt_kernel ? "kernel" : "UST", event_name,
+                                       channel_name);
+               } else {
+                       MSG("%s event %s disabled in channel %s",
+                                       opt_kernel ? "kernel" : "UST", event_name,
+                                       channel_name);
+               }
+
                /* Next event */
                event_name = strtok(NULL, ",");
        }
 
+end:
 error:
        if (opt_channel_name == NULL) {
                free(channel_name);
This page took 0.033733 seconds and 4 git commands to generate.