Add -p, --pid option to lttng command line
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 2 May 2011 20:42:35 +0000 (16:42 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 2 May 2011 20:45:59 +0000 (16:45 -0400)
This makes create, start and stop trace available for both kernel and
userspace tracing. For userspace tracing, use the -p, --pid option to
enable those action for an application identified by a pid.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng/lttng.c
lttng/lttng.h
lttng/options.c

index 8a0d58faeaa8ac7ec7299a7a633d9ada73e8e513..f6cad42434e2f718a1a8077a4823866998a7acfd 100644 (file)
@@ -108,31 +108,37 @@ static int process_client_opt(void)
                lttng_set_current_session_uuid(opt_session_uuid);
        }
 
-       if (opt_create_trace) {
-               DBG("Create trace for pid %d", opt_create_trace);
-               ret = lttng_ust_create_trace(opt_create_trace);
-               if (ret < 0) {
-                       goto end;
-               }
-               MSG("Trace created successfully!\nUse --start PID to start tracing.");
+       if (opt_trace_kernel) {
+               ERR("Not implemented yet");
+               goto end;
        }
 
-       if (opt_start_trace) {
-               DBG("Start trace for pid %d", opt_start_trace);
-               ret = lttng_ust_start_trace(opt_start_trace);
-               if (ret < 0) {
-                       goto end;
+       if (opt_trace_pid != 0) {
+               if (opt_create_trace) {
+                       DBG("Create a userspace trace for pid %d", opt_trace_pid);
+                       ret = lttng_ust_create_trace(opt_trace_pid);
+                       if (ret < 0) {
+                               goto end;
+                       }
+                       MSG("Trace created successfully!\nUse --start to start tracing.");
                }
-               MSG("Trace started successfully!");
-       }
 
-       if (opt_stop_trace) {
-               DBG("Stop trace for pid %d", opt_stop_trace);
-               ret = lttng_ust_stop_trace(opt_stop_trace);
-               if (ret < 0) {
-                       goto end;
+               if (opt_start_trace) {
+                       DBG("Start trace for pid %d", opt_trace_pid);
+                       ret = lttng_ust_start_trace(opt_trace_pid);
+                       if (ret < 0) {
+                               goto end;
+                       }
+                       MSG("Trace started successfully!");
+               } else if (opt_stop_trace) {
+                       DBG("Stop trace for pid %d", opt_trace_pid);
+                       ret = lttng_ust_stop_trace(opt_trace_pid);
+                       if (ret < 0) {
+                               goto end;
+                       }
+                       MSG("Trace stopped successfully!");
                }
-               MSG("Trace stopped successfully!");
+
        }
 
        return 0;
@@ -320,10 +326,20 @@ end:
  */
 static int validate_options(void)
 {
-       if ((opt_session_uuid == NULL) &&
-                       (opt_create_trace || opt_start_trace || opt_list_traces)) {
+       /* Conflicting command */
+       if (opt_start_trace && opt_stop_trace) {
+               ERR("Can't use --start and --stop together.");
+               goto error;
+       /* Must have a session UUID for trace action. */
+       } else if ((opt_session_uuid == NULL) &&
+                       (opt_create_trace || opt_start_trace || opt_stop_trace || opt_list_traces)) {
                ERR("You need to specify a session UUID.\nPlease use --session UUID to do so.");
                goto error;
+       /* If no PID specified and trace_kernel is off */
+       } else if ((opt_trace_pid == 0 && opt_trace_kernel == 0) &&
+                       (opt_create_trace || opt_start_trace || opt_stop_trace)) {
+               ERR("Please specify a PID using -p, --pid PID.");
+               goto error;
        }
 
        return 0;
index dd9462ce94fcabaaa542933770867aae2c4369aa..1cc7981f5ea670ca660fbfd3efc5f8c42a970148 100644 (file)
@@ -35,8 +35,9 @@ extern int opt_list_apps;
 extern int opt_no_sessiond;
 extern int opt_list_session;
 extern int opt_list_traces;
-extern pid_t opt_create_trace;
-extern pid_t opt_start_trace;
-extern pid_t opt_stop_trace;
+extern int opt_create_trace;
+extern int opt_start_trace;
+extern int opt_stop_trace;
+extern pid_t opt_trace_pid;
 
 #endif /* _LTTNG_H */
index 3025117e4c36b9f67bd8a168260d94304b34d226..b4630c3d79d3b01c0d90ff420682e2079f6f6a54 100644 (file)
@@ -34,9 +34,10 @@ int opt_list_apps = 0;
 int opt_no_sessiond = 0;
 int opt_list_session = 0;
 int opt_list_traces = 0;
-pid_t opt_create_trace = 0;
-pid_t opt_start_trace = 0;
-pid_t opt_stop_trace = 0;
+int opt_create_trace = 0;
+int opt_start_trace = 0;
+int opt_stop_trace = 0;
+pid_t opt_trace_pid = 0;
 
 enum {
        OPT_HELP = 42,
@@ -45,7 +46,7 @@ enum {
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"create-session",  'c',        POPT_ARG_STRING,        &opt_create_session, 0, 0, 0},
-       {"create-trace",        'C',    POPT_ARG_INT,           &opt_create_trace, 0, 0, 0},
+       {"create-trace",        'C',    POPT_ARG_VAL,           &opt_create_trace, 1, 0, 0},
        {"destroy-session", 'd',        POPT_ARG_STRING,        &opt_destroy_session, 0, 0, 0},
        {"group",                       0,              POPT_ARG_STRING,        &opt_tracing_group, 0, 0},
        {"help",                        'h',    POPT_ARG_NONE,          0, OPT_HELP, 0, 0},
@@ -55,11 +56,12 @@ static struct poptOption long_options[] = {
        {"list-traces",         't',    POPT_ARG_VAL,           &opt_list_traces, 1, 0, 0},
        {"no-kernel",           0,              POPT_ARG_VAL,           &opt_trace_kernel, 0, 0, 0},
        {"no-sessiond",         0,              POPT_ARG_VAL,           &opt_no_sessiond, 1, 0, 0},
+       {"pid",                         'p',    POPT_ARG_INT,           &opt_trace_pid, 0, 0, 0},
        {"quiet",                       'q',    POPT_ARG_VAL,           &opt_quiet, 1, 0, 0},
        {"session",                     's',    POPT_ARG_STRING,        &opt_session_uuid, 0, 0, 0},
        {"sessiond-path",       0,              POPT_ARG_STRING,        &opt_sessiond_path, 0, 0, 0},
-       {"start",                       0,              POPT_ARG_INT,           &opt_start_trace, 0, 0, 0},
-       {"stop",                        0,              POPT_ARG_INT,           &opt_stop_trace, 0, 0, 0},
+       {"start",                       0,              POPT_ARG_VAL,           &opt_start_trace, 1, 0, 0},
+       {"stop",                        0,              POPT_ARG_VAL,           &opt_stop_trace, 1, 0, 0},
        {"verbose",                     'v',    POPT_ARG_VAL,           &opt_verbose, 1, 0, 0},
        //{"session",                   0,              POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
@@ -91,11 +93,12 @@ static void usage(FILE *ofp)
        fprintf(ofp, "Tracing options:\n");
        //fprintf(ofp, "      --kernel               Enable kernel tracing\n");
        //fprintf(ofp, "      --no-kernel            Disable kernel tracing\n");
+       fprintf(ofp, "  -p, --pid PID                Set tracing action for PID\n");
        fprintf(ofp, "  -L, --list-apps              List traceable UST applications\n");
        fprintf(ofp, "  -t, --list-traces            List session's traces. Use -s to specify the session\n");
-       fprintf(ofp, "  -C, --create-trace PID       Create trace for PID\n");
-       fprintf(ofp, "      --start PID              Start trace for PID\n");
-       fprintf(ofp, "      --stop PID               Stop trace for PID\n");
+       fprintf(ofp, "  -C, --create-trace           Create a trace\n");
+       fprintf(ofp, "      --start                  Start tracing\n");
+       fprintf(ofp, "      --stop                   Stop tracing\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Please see the lttng(1) man page for full documentation.\n");
        fprintf(ofp, "See http://lttng.org/ust for updates, bug reports and news.\n");
This page took 0.029416 seconds and 5 git commands to generate.