Add ust stop trace feature
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 2 May 2011 20:10:36 +0000 (16:10 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 2 May 2011 20:10:46 +0000 (16:10 -0400)
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
include/lttng/liblttngctl.h
liblttngctl/liblttngctl.c
liblttsessiondcomm/liblttsessiondcomm.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/main.c
lttng/lttng.c
lttng/lttng.h
lttng/options.c

index 0ffa6f25896a45b003c6d382f1947e21bd92ffcd..71c5e820805e2d9db11a3a7c61c532e760f1ba06 100644 (file)
@@ -69,5 +69,6 @@ extern int lttng_list_traces(uuid_t *uuid, struct lttng_trace **traces);
 extern void lttng_set_current_session_uuid(char *uuid);
 extern int lttng_ust_create_trace(pid_t pid);
 extern int lttng_ust_start_trace(pid_t pid);
+extern int lttng_ust_stop_trace(pid_t pid);
 
 #endif /* _LIBLTTNGCTL_H */
index 7d020daad2a9d83ca3a72d6dffd089b3e86189c3..bd02a13b2c451fad17d6b0612472bba7b5652023 100644 (file)
@@ -182,6 +182,21 @@ int lttng_ust_start_trace(pid_t pid)
        return ret;
 }
 
+/*
+ *  lttng_ust_stop_trace
+ *
+ *  Request a trace stop for pid.
+ */
+int lttng_ust_stop_trace(pid_t pid)
+{
+       int ret;
+
+       lsm.pid = pid;
+       ret = ask_sessiond(UST_STOP_TRACE, NULL);
+
+       return ret;
+}
+
 /*
  *  lttng_ust_create_trace
  *
index aeef8e7544bb9c281221f703b44638046ce767f8..2c46f0027d58077f1035342ae3fa14fe55de92d6 100644 (file)
@@ -44,6 +44,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_FATAL) ] = "Fatal error of the session daemon",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_FAIL) ] = "Create trace failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_START_FAIL) ] = "Start trace failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_STOP_FAIL) ] = "Stop trace failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACEABLE) ] = "App is not traceable",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_SELECT_SESS) ] = "A session MUST be selected",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_EXIST_SESS) ] = "Session name already exist",
index bd17a2ac6375003c06ee2a20c0d4b913a938bd28..0993b76c819db939cc8f306acb2e38ad589a3bc7 100644 (file)
@@ -73,6 +73,7 @@ enum lttcomm_return_code {
        LTTCOMM_CREATE_FAIL,    /* Create trace fail */
        LTTCOMM_SESSION_FAIL,   /* Create session fail */
        LTTCOMM_START_FAIL,             /* Start tracing fail */
+       LTTCOMM_STOP_FAIL,              /* Stop tracing fail */
        LTTCOMM_LIST_FAIL,              /* Listing apps fail */
        LTTCOMM_NO_APPS,                /* No traceable application */
        LTTCOMM_NO_SESS,                /* No sessions available */
index 70ce53c8b1cd50c87e1712bc42a2c2e0ba0f9bd4..150f211fb825a44e1e614a3222744d7edf51a4bc 100644 (file)
@@ -374,6 +374,42 @@ error:
        return ret;
 }
 
+/*
+ *  ust_stop_trace
+ *
+ *  Stop a trace. This trace, identified by the pid, must be
+ *  in the current session ust_traces list.
+ */
+static int ust_stop_trace(pid_t pid)
+{
+       int sock, ret;
+       struct ltt_ust_trace *trace;
+
+       DBG("Stopping trace for pid %d", pid);
+
+       trace = find_session_ust_trace_by_pid(current_session, pid);
+       if (trace == NULL) {
+               ret = LTTCOMM_NO_TRACE;
+               goto error;
+       }
+
+       /* Connect to app using ustctl API */
+       sock = connect_app(pid);
+       if (sock < 0) {
+               ret = LTTCOMM_NO_TRACEABLE;
+               goto error;
+       }
+
+       ret = ustctl_stop_trace(sock, trace->name);
+       if (ret < 0) {
+               ret = LTTCOMM_STOP_FAIL;
+               goto error;
+       }
+
+error:
+       return ret;
+}
+
 /*
  *  copy_common_data
  *
@@ -564,6 +600,13 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
                        /* No auxiliary data so only send the llm struct. */
                        goto end;
                }
+               case UST_STOP_TRACE:
+               {
+                       ret = ust_stop_trace(lsm->pid);
+
+                       /* No auxiliary data so only send the llm struct. */
+                       goto end;
+               }
                case LTTNG_LIST_SESSIONS:
                {
                        unsigned int session_count = get_session_count();
index e286917ed1effff58afaacb91c1f8bcb780d7de4..8a0d58faeaa8ac7ec7299a7a633d9ada73e8e513 100644 (file)
@@ -126,6 +126,15 @@ static int process_client_opt(void)
                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;
+               }
+               MSG("Trace stopped successfully!");
+       }
+
        return 0;
 
 end:
index cb419681806b63119959a21eb9b4a7a1a1811a12..dd9462ce94fcabaaa542933770867aae2c4369aa 100644 (file)
@@ -37,5 +37,6 @@ 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;
 
 #endif /* _LTTNG_H */
index 1ed0aca7d38b07e7ebf903709a478324b5ee6c04..3025117e4c36b9f67bd8a168260d94304b34d226 100644 (file)
@@ -36,6 +36,7 @@ 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;
 
 enum {
        OPT_HELP = 42,
@@ -58,6 +59,7 @@ static struct poptOption long_options[] = {
        {"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},
        {"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}
@@ -93,6 +95,7 @@ static void usage(FILE *ofp)
        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, "\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.039313 seconds and 4 git commands to generate.