Add ust start trace feature
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 2 May 2011 18:04:39 +0000 (14:04 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 2 May 2011 18:04:48 +0000 (14:04 -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 3025571e1705ced922c621b7c115977f320b5e18..aeb822010230d0b3a2d612ce10230c911c2d185c 100644 (file)
@@ -53,5 +53,6 @@ extern int lttng_ust_list_apps(pid_t **pids);
 extern int lttng_list_sessions(struct lttng_session **sessions);
 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);
 
 #endif /* _LIBLTTNGCTL_H */
index a586b34f53a61d2ba6dd630204325d1f71a31835..64764682ba18f6fe124900c4283cf74d8f58aaee 100644 (file)
@@ -167,6 +167,21 @@ const char *lttng_get_readable_code(int code)
        return lttcomm_get_readable_code(code);
 }
 
+/*
+ *  lttng_ust_start_trace
+ *
+ *  Request a trace start for pid.
+ */
+int lttng_ust_start_trace(pid_t pid)
+{
+       int ret;
+
+       lsm.pid = pid;
+       ret = ask_sessiond(UST_START_TRACE, NULL);
+
+       return ret;
+}
+
 /*
  *  lttng_ust_create_trace
  *
index f9cdede856fc1a6037b2f1d9cfb554fd611ea602..aeef8e7544bb9c281221f703b44638046ce767f8 100644 (file)
@@ -40,6 +40,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_LIST_FAIL) ] = "Unable to list traceable apps",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_APPS) ] = "No traceable apps found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESS) ] = "No session found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACE) ] = "No trace found",
        [ 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",
index 41c2cd419db807acc9a8d608997d6595210b8dc4..ce85e8292130e34dcb0c0a0fcc1dac016acc93e8 100644 (file)
@@ -75,6 +75,7 @@ enum lttcomm_return_code {
        LTTCOMM_LIST_FAIL,              /* Listing apps fail */
        LTTCOMM_NO_APPS,                /* No traceable application */
        LTTCOMM_NO_SESS,                /* No sessions available */
+       LTTCOMM_NO_TRACE,               /* No trace exist */
        LTTCOMM_FATAL,                  /* Session daemon had a fatal error */
        LTTCOMM_NO_TRACEABLE,   /* Error for non traceable app */
        LTTCOMM_SELECT_SESS,    /* Must select a session */
index 56266db3ce429bb6074bf34af85391ce6e7b865e..720d23439c99b855546617f503ad2fc609373b46 100644 (file)
@@ -322,6 +322,42 @@ error:
        return ret;
 }
 
+/*
+ *  ust_start_trace
+ *
+ *  Start a trace. This trace, identified by the pid, must be
+ *  in the current session ust_traces list.
+ */
+static int ust_start_trace(pid_t pid)
+{
+       int sock, ret;
+       struct ltt_ust_trace *trace;
+
+       DBG("Starting 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_start_trace(sock, "auto");
+       if (ret < 0) {
+               ret = LTTCOMM_START_FAIL;
+               goto error;
+       }
+
+error:
+       return ret;
+}
+
 /*
  *  copy_common_data
  *
@@ -453,7 +489,10 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
                {
                        ret = ust_create_trace(lsm->pid);
                        if (ret < 0) {
-                               ret = LTTCOMM_CREATE_FAIL;
+                               /* If -1 is returned from ust_create_trace, malloc
+                                * failed so it's pretty much a fatal error.
+                                */
+                               ret = LTTCOMM_FATAL;
                                goto end;
                        }
 
@@ -481,6 +520,13 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
 
                        break;
                }
+               case UST_START_TRACE:
+               {
+                       ret = ust_start_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 9751621ff84f2c4fceb2267c5dd1b1ec6f83e1ae..e538df2fd403f0eefaf2be2c58b3c8a04973067d 100644 (file)
@@ -96,6 +96,7 @@ static int process_client_opt(void)
        }
 
        if (opt_session_uuid != NULL) {
+               DBG("Set session uuid to %s", opt_session_uuid);
                lttng_set_current_session_uuid(opt_session_uuid);
        }
 
@@ -108,6 +109,15 @@ static int process_client_opt(void)
                MSG("Trace created successfully!\nUse --start PID to start tracing.");
        }
 
+       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;
+               }
+               MSG("Trace started successfully!");
+       }
+
        return 0;
 
 end:
@@ -255,8 +265,8 @@ not_running:
 static int validate_options(void)
 {
        if ((opt_session_uuid == NULL) &&
-                       (opt_create_trace)) {
-               ERR("Can't create trace without a session ID.\nPlease specify using --session UUID");
+                       (opt_create_trace || opt_start_trace)) {
+               ERR("Can't act on trace without a session ID.\nPlease specify using --session UUID");
                goto error;
        }
 
@@ -400,15 +410,17 @@ end:
  */
 static void sighandler(int sig)
 {
-       DBG("%d received", sig);
        switch (sig) {
                case SIGTERM:
+                       DBG("SIGTERM catched");
                        clean_exit(EXIT_FAILURE);
                        break;
                case SIGCHLD:
                        /* Notify is done */
+                       DBG("SIGCHLD catched");
                        break;
                default:
+                       DBG("Unknown signal %d catched", sig);
                        break;
        }
 
index a2dd7d73f639c8820939cff17fc8ebe5755e9ce4..4f16c8d1f2715f216c8d33940dd2623f0bd75252 100644 (file)
@@ -35,7 +35,6 @@ extern int opt_list_apps;
 extern int opt_no_sessiond;
 extern int opt_list_session;
 extern pid_t opt_create_trace;
-
-#define SESSIOND_PATH_NUM 6
+extern pid_t opt_start_trace;
 
 #endif /* _LTTNG_H */
index 4b8eeb50bed749cda2f07fd91fce04c998a206e9..183c54dcf0757e2b74f658c0fb7c61804d21b4dd 100644 (file)
@@ -34,6 +34,7 @@ int opt_list_apps = 0;
 int opt_no_sessiond = 0;
 int opt_list_session = 0;
 pid_t opt_create_trace = 0;
+pid_t opt_start_trace = 0;
 
 enum {
        OPT_HELP = 42,
@@ -54,6 +55,7 @@ static struct poptOption long_options[] = {
        {"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},
        {"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}
@@ -87,6 +89,7 @@ static void usage(FILE *ofp)
        //fprintf(ofp, "      --no-kernel            Disable kernel tracing\n");
        fprintf(ofp, "  -L, --list-apps              List traceable UST applications\n");
        fprintf(ofp, "  -C, --create-trace PID       Create trace for PID\n");
+       fprintf(ofp, "      --start PID              Start 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.044145 seconds and 4 git commands to generate.