Add enable kernel event using the enable ioctl
authorDavid Goulet <david.goulet@polymtl.ca>
Wed, 29 Jun 2011 17:27:09 +0000 (13:27 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Wed, 29 Jun 2011 17:29:30 +0000 (13:29 -0400)
Two helper functions are added which are get an event by name and a
channel by name.

The disable and enable event command was modified to use these two
functions.

Overall, it's now possible to enable/disable at will kernel events.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/kernel-ctl.c
ltt-sessiond/kernel-ctl.h
ltt-sessiond/main.c
ltt-sessiond/trace.c
ltt-sessiond/trace.h

index 2f1864d6495ca8092a4a2744ec5a5c301bac9686..16b85bdb5bcb5b6793450b0f2794023541fa2466 100644 (file)
@@ -124,7 +124,7 @@ error:
  *  Create a kernel event, enable it to the kernel tracer and add it to the
  *  channel event list of the kernel session.
  */
-int kernel_create_event(struct ltt_kernel_channel *channel, struct lttng_event *ev)
+int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel)
 {
        int ret;
        struct ltt_kernel_event *event;
@@ -161,29 +161,47 @@ error:
 }
 
 /*
- *  kernel_disable_event
+ *  kernel_enable_event
  *
- *  Disable a kernel event for a specific channel.
+ *  Enable a kernel event.
  */
-int kernel_disable_event(char *event_name, struct ltt_kernel_channel *channel)
+int kernel_enable_event(struct ltt_kernel_event *event)
 {
        int ret;
-       struct ltt_kernel_event *iter;
 
-       cds_list_for_each_entry(iter, &channel->events_list.head, list) {
-               if (strcmp(iter->event->name, event_name) == 0) {
-                       ret = kernctl_disable(iter->fd);
-                       if (ret < 0) {
-                               perror("disable event ioctl");
-                               goto error;
-                       }
+       ret = kernctl_enable(event->fd);
+       if (ret < 0) {
+               perror("enable event ioctl");
+               goto error;
+       }
 
-                       iter->enabled = 0;
-                       DBG("Kernel event %s disabled (fd: %d)", iter->event->name, iter->fd);
-                       break;
-               }
+       event->enabled = 1;
+       DBG("Kernel event %s enabled (fd: %d)", event->event->name, event->fd);
+
+       return 0;
+
+error:
+       return -1;
+}
+
+/*
+ *  kernel_disable_event
+ *
+ *  Disable a kernel event.
+ */
+int kernel_disable_event(struct ltt_kernel_event *event)
+{
+       int ret;
+
+       ret = kernctl_disable(event->fd);
+       if (ret < 0) {
+               perror("disable event ioctl");
+               goto error;
        }
 
+       event->enabled = 0;
+       DBG("Kernel event %s disabled (fd: %d)", event->event->name, event->fd);
+
        return 0;
 
 error:
index adc930d1c0671ff116f979e4233d002818708e15..d36cd6d103fcea0b49dcea64e2ceb7985405a85a 100644 (file)
@@ -32,8 +32,9 @@
 
 int kernel_create_session(struct ltt_session *session, int tracer_fd);
 int kernel_create_channel(struct ltt_kernel_session *session, struct lttng_channel *chan);
-int kernel_create_event(struct ltt_kernel_channel *channel, struct lttng_event *ev);
-int kernel_disable_event(char *event_name, struct ltt_kernel_channel *channel);
+int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel);
+int kernel_disable_event(struct ltt_kernel_event *event);
+int kernel_enable_event(struct ltt_kernel_event *event);
 int kernel_open_metadata(struct ltt_kernel_session *session);
 int kernel_open_metadata_stream(struct ltt_kernel_session *session);
 int kernel_open_channel_stream(struct ltt_kernel_channel *channel);
index 4da3caba0471f7977452d7412229c17cccdd2295..5a8119f917b40b6d4b4aaa92759a8f124de9f62c 100644 (file)
@@ -875,8 +875,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        }
        case LTTNG_KERNEL_DISABLE_EVENT:
        {
-               int found = 0;
                struct ltt_kernel_channel *chan;
+               struct ltt_kernel_event *ev;
 
                /* Setup lttng message with no payload */
                ret = setup_lttng_msg(cmd_ctx, 0);
@@ -884,34 +884,32 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                        goto setup_error;
                }
 
-               /* Get channel by name and create event for that channel */
-               cds_list_for_each_entry(chan, &cmd_ctx->session->kernel_session->channel_list.head, list) {
-                       if (strcmp(cmd_ctx->lsm->u.disable.channel_name, chan->channel->name) == 0) {
-                               DBG("Disabling kernel event %s for channel %s.",
-                                               cmd_ctx->lsm->u.disable.name, cmd_ctx->lsm->u.disable.channel_name);
+               chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.disable.channel_name,
+                               cmd_ctx->session->kernel_session);
+               if (chan == NULL) {
+                       ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+                       goto error;
+               }
 
-                               ret = kernel_disable_event(cmd_ctx->lsm->u.disable.name, chan);
-                               if (ret < 0) {
-                                       ret = LTTCOMM_KERN_DISABLE_FAIL;
-                                       goto error;
-                               }
-                               found = 1;
-                               break;
+               ev = get_kernel_event_by_name(cmd_ctx->lsm->u.disable.name, chan);
+               if (ev != NULL) {
+                       DBG("Disabling kernel event %s for channel %s.",
+                                       cmd_ctx->lsm->u.disable.name, cmd_ctx->lsm->u.disable.channel_name);
+                       ret = kernel_disable_event(ev);
+                       if (ret < 0) {
+                               ret = LTTCOMM_KERN_ENABLE_FAIL;
+                               goto error;
                        }
                }
 
-               if (!found) {
-                       ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
-               } else {
-                       kernel_wait_quiescent(kernel_tracer_fd);
-                       ret = LTTCOMM_OK;
-               }
+               kernel_wait_quiescent(kernel_tracer_fd);
+               ret = LTTCOMM_OK;
                break;
        }
        case LTTNG_KERNEL_ENABLE_EVENT:
        {
-               int found = 0;
                struct ltt_kernel_channel *chan;
+               struct ltt_kernel_event *ev;
 
                /* Setup lttng message with no payload */
                ret = setup_lttng_msg(cmd_ctx, 0);
@@ -919,28 +917,31 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                        goto setup_error;
                }
 
-               /* Get channel by name and create event for that channel */
-               cds_list_for_each_entry(chan, &cmd_ctx->session->kernel_session->channel_list.head, list) {
-                       if (strcmp(cmd_ctx->lsm->u.enable.channel_name, chan->channel->name) == 0) {
-                               DBG("Creating kernel event %s for channel %s.",
-                                               cmd_ctx->lsm->u.enable.event.name, cmd_ctx->lsm->u.enable.channel_name);
-
-                               ret = kernel_create_event(chan, &cmd_ctx->lsm->u.enable.event);
-                               if (ret < 0) {
-                                       ret = LTTCOMM_KERN_ENABLE_FAIL;
-                                       goto error;
-                               }
-                               found = 1;
-                               break;
-                       }
+               chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.enable.channel_name,
+                               cmd_ctx->session->kernel_session);
+               if (chan == NULL) {
+                       ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+                       goto error;
                }
 
-               if (!found) {
-                       ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+               ev = get_kernel_event_by_name(cmd_ctx->lsm->u.enable.event.name, chan);
+               if (ev == NULL) {
+                       DBG("Creating kernel event %s for channel %s.",
+                                       cmd_ctx->lsm->u.enable.event.name, cmd_ctx->lsm->u.enable.channel_name);
+                       ret = kernel_create_event(&cmd_ctx->lsm->u.enable.event, chan);
                } else {
-                       kernel_wait_quiescent(kernel_tracer_fd);
-                       ret = LTTCOMM_OK;
+                       DBG("Enabling kernel event %s for channel %s.",
+                                       cmd_ctx->lsm->u.enable.event.name, cmd_ctx->lsm->u.enable.channel_name);
+                       ret = kernel_enable_event(ev);
+               }
+
+               if (ret < 0) {
+                       ret = LTTCOMM_KERN_ENABLE_FAIL;
+                       goto error;
                }
+
+               kernel_wait_quiescent(kernel_tracer_fd);
+               ret = LTTCOMM_OK;
                break;
        }
        case LTTNG_KERNEL_ENABLE_ALL_EVENT:
@@ -983,7 +984,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                        /* Default event type for enable all */
                        ev.type = LTTNG_EVENT_TRACEPOINTS;
                        /* Enable each single tracepoint event */
-                       ret = kernel_create_event(chan, &ev);
+                       ret = kernel_create_event(&ev, chan);
                        if (ret < 0) {
                                ret = LTTCOMM_KERN_ENABLE_FAIL;
                                goto error;
index e0051cd1cabe0e7d50bd783c4b4a48d67429e925..eb7d0e152497569634e5fbf094d2a8d7170e9cbe 100644 (file)
 #include "ltt-sessiond.h"
 #include "trace.h"
 
+/*
+ *  get_kernel_channel_by_name
+ *
+ *  Find the channel name for the given kernel session.
+ */
+struct ltt_kernel_channel *get_kernel_channel_by_name(
+               char *name, struct ltt_kernel_session *session)
+{
+       struct ltt_kernel_channel *chan;
+
+       if (session == NULL) {
+               ERR("Undefine session");
+               goto error;
+       }
+
+       cds_list_for_each_entry(chan, &session->channel_list.head, list) {
+               if (strcmp(name, chan->channel->name) == 0) {
+                       DBG("Found channel by name %s", name);
+                       return chan;
+               }
+       }
+
+error:
+       return NULL;
+}
+
+/*
+ *  get_kernel_event_by_name
+ *
+ *  Find the event name for the given channel.
+ */
+struct ltt_kernel_event *get_kernel_event_by_name(
+               char *name, struct ltt_kernel_channel *channel)
+{
+       struct ltt_kernel_event *ev;
+
+       if (channel == NULL) {
+               ERR("Undefine channel");
+               goto error;
+       }
+
+       cds_list_for_each_entry(ev, &channel->events_list.head, list) {
+               if (strcmp(name, ev->event->name) == 0) {
+                       DBG("Found event by name %s for channel %s", name,
+                                       channel->channel->name);
+                       return ev;
+               }
+       }
+
+error:
+       return NULL;
+}
+
 /*
  *  trace_create_kernel_session
  *
index 8da147230e22a928ec89b7b33f37c9a84d02cc8c..427b05b8814be010bd72b2ce0caf15c753fa8f51 100644 (file)
@@ -101,6 +101,14 @@ struct ltt_ust_marker {
        char *channel;
 };
 
+/*
+ * Get functions.
+ */
+struct ltt_kernel_event *get_kernel_event_by_name(
+               char *name, struct ltt_kernel_channel *channel);
+struct ltt_kernel_channel *get_kernel_channel_by_name(
+               char *name, struct ltt_kernel_session *session);
+
 /*
  * Create functions malloc() the data structure.
  */
This page took 0.042473 seconds and 4 git commands to generate.