From ce3d728cd9bfcc0f7d43e08275a92cf04e898662 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 2 May 2011 14:04:39 -0400 Subject: [PATCH] Add ust start trace feature Signed-off-by: David Goulet --- include/lttng/liblttngctl.h | 1 + liblttngctl/liblttngctl.c | 15 ++++++++ liblttsessiondcomm/liblttsessiondcomm.c | 1 + liblttsessiondcomm/liblttsessiondcomm.h | 1 + ltt-sessiond/main.c | 48 ++++++++++++++++++++++++- lttng/lttng.c | 18 ++++++++-- lttng/lttng.h | 3 +- lttng/options.c | 3 ++ 8 files changed, 84 insertions(+), 6 deletions(-) diff --git a/include/lttng/liblttngctl.h b/include/lttng/liblttngctl.h index 3025571e1..aeb822010 100644 --- a/include/lttng/liblttngctl.h +++ b/include/lttng/liblttngctl.h @@ -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 */ diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index a586b34f5..64764682b 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -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 * diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index f9cdede85..aeef8e754 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -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", diff --git a/liblttsessiondcomm/liblttsessiondcomm.h b/liblttsessiondcomm/liblttsessiondcomm.h index 41c2cd419..ce85e8292 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.h +++ b/liblttsessiondcomm/liblttsessiondcomm.h @@ -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 */ diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 56266db3c..720d23439 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -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(); diff --git a/lttng/lttng.c b/lttng/lttng.c index 9751621ff..e538df2fd 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -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; } diff --git a/lttng/lttng.h b/lttng/lttng.h index a2dd7d73f..4f16c8d1f 100644 --- a/lttng/lttng.h +++ b/lttng/lttng.h @@ -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 */ diff --git a/lttng/options.c b/lttng/options.c index 4b8eeb50b..183c54dcf 100644 --- a/lttng/options.c +++ b/lttng/options.c @@ -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"); -- 2.34.1