From 520ff6876d5fdf7e5421733a8f2a7d0c20e43c8c Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 2 May 2011 16:10:36 -0400 Subject: [PATCH] Add ust stop 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 | 43 +++++++++++++++++++++++++ lttng/lttng.c | 9 ++++++ lttng/lttng.h | 1 + lttng/options.c | 3 ++ 8 files changed, 74 insertions(+) diff --git a/include/lttng/liblttngctl.h b/include/lttng/liblttngctl.h index 0ffa6f258..71c5e8208 100644 --- a/include/lttng/liblttngctl.h +++ b/include/lttng/liblttngctl.h @@ -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 */ diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index 7d020daad..bd02a13b2 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -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 * diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index aeef8e754..2c46f0027 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -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", diff --git a/liblttsessiondcomm/liblttsessiondcomm.h b/liblttsessiondcomm/liblttsessiondcomm.h index bd17a2ac6..0993b76c8 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.h +++ b/liblttsessiondcomm/liblttsessiondcomm.h @@ -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 */ diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 70ce53c8b..150f211fb 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -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(); diff --git a/lttng/lttng.c b/lttng/lttng.c index e286917ed..8a0d58fae 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -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: diff --git a/lttng/lttng.h b/lttng/lttng.h index cb4196818..dd9462ce9 100644 --- a/lttng/lttng.h +++ b/lttng/lttng.h @@ -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 */ diff --git a/lttng/options.c b/lttng/options.c index 1ed0aca7d..3025117e4 100644 --- a/lttng/options.c +++ b/lttng/options.c @@ -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"); -- 2.34.1