Parametrize enable-channel help
[lttng-tools.git] / lttng / commands / enable_channels.c
index 1bdf60667964ff9d75614dd1e60100b5e8b9537b..ba5b7b45a5219370a9fd86aa9e9dc4d966145702 100644 (file)
@@ -50,6 +50,8 @@ enum {
        OPT_USERSPACE,
 };
 
+static struct lttng_handle *handle;
+
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",           'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
@@ -82,12 +84,22 @@ static void usage(FILE *ofp)
        fprintf(ofp, "  -p, --pid PID            If -u, apply on a specific PID\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Channel options:\n");
-       fprintf(ofp, "      --discard            Discard event when buffers are full (default)\n");
-       fprintf(ofp, "      --overwrite          Flight recorder mode\n");
-       fprintf(ofp, "      --subbuf-size        Subbuffer size in bytes (default: 4096)\n");
-       fprintf(ofp, "      --num-subbuf         Number of subbufers (default: 2)\n");
-       fprintf(ofp, "      --switch-timer       Switch timer interval in usec (default: 0)\n");
-       fprintf(ofp, "      --read-timer         Read timer interval in usec (default: 200)\n");
+       fprintf(ofp, "      --discard            Discard event when buffers are full%s\n",
+               DEFAULT_CHANNEL_OVERWRITE ? "" : " (default)");
+       fprintf(ofp, "      --overwrite          Flight recorder mode%s\n",
+               DEFAULT_CHANNEL_OVERWRITE ? " (default)" : "");
+       fprintf(ofp, "      --subbuf-size        Subbuffer size in bytes\n");
+       fprintf(ofp, "                               (default: %u, kernel default: %u)\n",
+               DEFAULT_CHANNEL_SUBBUF_SIZE,
+               DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE);
+       fprintf(ofp, "      --num-subbuf         Number of subbufers\n");
+       fprintf(ofp, "                               (default: %u, kernel default: %u)\n",
+               DEFAULT_CHANNEL_SUBBUF_NUM,
+               DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM);
+       fprintf(ofp, "      --switch-timer       Switch timer interval in usec (default: %u)\n",
+               DEFAULT_CHANNEL_SWITCH_TIMER);
+       fprintf(ofp, "      --read-timer         Read timer interval in usec (default: %u)\n",
+               DEFAULT_CHANNEL_READ_TIMER);
        fprintf(ofp, "\n");
 }
 
@@ -96,21 +108,22 @@ static void usage(FILE *ofp)
  *
  *  Adding channel using the lttng API.
  */
-static int enable_channel(void)
+static int enable_channel(char *session_name)
 {
        int ret = CMD_SUCCESS;
        char *channel_name;
        struct lttng_domain dom;
 
-       if (set_session_name(opt_session_name) < 0) {
-               ret = CMD_ERROR;
-               goto error;
-       }
-
        if (opt_kernel) {
                dom.type = LTTNG_DOMAIN_KERNEL;
        }
 
+       handle = lttng_create_handle(session_name, &dom);
+       if (handle == NULL) {
+               ret = -1;
+               goto error;
+       }
+
        /* Strip event list */
        channel_name = strtok(opt_channels, ",");
        while (channel_name != NULL) {
@@ -122,7 +135,7 @@ static int enable_channel(void)
                        strncpy(chan.name, channel_name, NAME_MAX);
                        chan.name[NAME_MAX - 1] = '\0';
 
-                       ret = lttng_enable_channel(&dom, &chan);
+                       ret = lttng_enable_channel(handle, &chan);
                        if (ret < 0) {
                                goto error;
                        } else {
@@ -147,6 +160,8 @@ static int enable_channel(void)
        }
 
 error:
+       lttng_destroy_handle(handle);
+
        return ret;
 }
 
@@ -157,12 +172,25 @@ error:
  */
 static void init_channel_config(void)
 {
-       chan.attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
-       chan.attr.subbuf_size = DEFAULT_CHANNEL_SUBBUF_SIZE;
-       chan.attr.num_subbuf = DEFAULT_CHANNEL_SUBBUF_NUM;
-       chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
-       chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
-       chan.attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
+       if (opt_kernel) {
+               /* kernel default */
+               chan.attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
+               chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+               chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+
+               chan.attr.subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
+               chan.attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
+               chan.attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
+       } else {
+               /* default behavior, used by UST. */
+               chan.attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
+               chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+               chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+
+               chan.attr.subbuf_size = DEFAULT_CHANNEL_SUBBUF_SIZE;
+               chan.attr.num_subbuf = DEFAULT_CHANNEL_SUBBUF_NUM;
+               chan.attr.output = DEFAULT_CHANNEL_OUTPUT;
+       }
 }
 
 /*
@@ -172,6 +200,7 @@ int cmd_enable_channels(int argc, const char **argv)
 {
        int opt, ret;
        static poptContext pc;
+       char *session_name = NULL;
 
        init_channel_config();
 
@@ -227,7 +256,17 @@ int cmd_enable_channels(int argc, const char **argv)
                goto end;
        }
 
-       ret = enable_channel();
+       if (!opt_session_name) {
+               session_name = get_session_name();
+               if (session_name == NULL) {
+                       ret = -1;
+                       goto end;
+               }
+       } else {
+               session_name = opt_session_name;
+       }
+
+       ret = enable_channel(session_name);
 
 end:
        return ret;
This page took 0.024479 seconds and 4 git commands to generate.