From df0da1392bb6c77fff7fc65be518dce7de457ed7 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 27 Apr 2011 13:25:48 -0400 Subject: [PATCH] Add ust create trace feature Can now create a trace with name set to 'auto' using the PID of the application. Also, this patch adds a missing param to the long_options, add some information for help and sort the option's array. Signed-off-by: David Goulet --- include/lttng/liblttngctl.h | 1 + liblttngctl/liblttngctl.c | 15 ++++++++++++ liblttsessiondcomm/liblttsessiondcomm.c | 1 + ltt-sessiond/ltt-sessiond.c | 14 +++++++++++ lttng/lttng.c | 9 +++++++ lttng/lttng.h | 1 + lttng/options.c | 32 +++++++++++++++---------- 7 files changed, 60 insertions(+), 13 deletions(-) diff --git a/include/lttng/liblttngctl.h b/include/lttng/liblttngctl.h index a3bdff807..3025571e1 100644 --- a/include/lttng/liblttngctl.h +++ b/include/lttng/liblttngctl.h @@ -52,5 +52,6 @@ extern const char *lttng_get_readable_code(int code); 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); #endif /* _LIBLTTNGCTL_H */ diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index 7c5af7fe7..a586b34f5 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_create_trace + * + * Request a trace creation for pid. + */ +int lttng_ust_create_trace(pid_t pid) +{ + int ret; + + lsm.pid = pid; + ret = ask_sessiond(UST_CREATE_TRACE, NULL); + + return ret; +} + /* * lttng_ust_list_apps * diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index 8413f6b08..bc74cc9e8 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -41,6 +41,7 @@ static const char *lttcomm_readable_code[] = { [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_APPS) ] = "No traceable apps found", [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESS) ] = "No session found", [ LTTCOMM_ERR_INDEX(LTTCOMM_FATAL) ] = "Fatal error of the session daemon", + [ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_FAIL) ] = "Create trace failed", }; /* diff --git a/ltt-sessiond/ltt-sessiond.c b/ltt-sessiond/ltt-sessiond.c index eee4cc84f..6df78d8e3 100644 --- a/ltt-sessiond/ltt-sessiond.c +++ b/ltt-sessiond/ltt-sessiond.c @@ -587,6 +587,20 @@ 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_CREATE_TRACE: + { + int sock; + sock = connect_app(lsm->pid); + + ret = ustctl_create_trace(sock, "auto"); + if (ret < 0) { + ret = LTTCOMM_CREATE_FAIL; + } else { + ret = LTTCOMM_OK; + } + + goto end; + } case UST_LIST_APPS: { /* Stop right now if no apps */ diff --git a/lttng/lttng.c b/lttng/lttng.c index 40cf52bc6..3878fb836 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -97,6 +97,15 @@ 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"); + } + return 0; end: diff --git a/lttng/lttng.h b/lttng/lttng.h index 804ccf694..a2dd7d73f 100644 --- a/lttng/lttng.h +++ b/lttng/lttng.h @@ -34,6 +34,7 @@ extern char *opt_destroy_session; 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 diff --git a/lttng/options.c b/lttng/options.c index 59d59046d..61a3802e5 100644 --- a/lttng/options.c +++ b/lttng/options.c @@ -33,6 +33,7 @@ int opt_verbose = 0; int opt_list_apps = 0; int opt_no_sessiond = 0; int opt_list_session = 0; +pid_t opt_create_trace = 0; enum { OPT_HELP = 42, @@ -40,21 +41,22 @@ enum { static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ - {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, + {"create-session", 'c', POPT_ARG_STRING, &opt_create_session, 0, 0, 0}, + {"create-trace", 'C', POPT_ARG_INT, &opt_create_trace, 0, 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}, {"kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 1, 0, 0}, + {"list-apps", 'L', POPT_ARG_VAL, &opt_list_apps, 1, 0, 0}, + {"list-sessions", 'l', POPT_ARG_VAL, &opt_list_session, 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}, + {"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}, + {"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0, 0}, //{"session", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 0, 0}, - {"session", 's', POPT_ARG_STRING, &opt_session_uuid, 0, 0}, - {"create-session", 'c', POPT_ARG_STRING, &opt_create_session, 0, 0}, - {"quiet", 'q', POPT_ARG_VAL, &opt_quiet, 1, 0}, - {"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0}, - {"list-apps", 'L', POPT_ARG_VAL, &opt_list_apps, 1, 0}, - {"no-sessiond", 0, POPT_ARG_VAL, &opt_no_sessiond, 1, 0}, - {"sessiond-path", 0, POPT_ARG_STRING, &opt_sessiond_path, 0, 0}, - {"list-sessions", 'l', POPT_ARG_VAL, &opt_list_session, 1, 0}, - {"destroy-session", 'd', POPT_ARG_STRING, &opt_destroy_session, 0, 0}, - {0, 0, 0, 0, 0, 0} + {0, 0, 0, 0, 0, 0, 0} }; @@ -71,19 +73,23 @@ static void usage(FILE *ofp) fprintf(ofp, " -q, --quiet Quiet mode\n"); fprintf(ofp, " --help Show help\n"); fprintf(ofp, " --group NAME Unix tracing group name. (default: tracing)\n"); - fprintf(ofp, " --no-sessiond Don't spawn a session daemon.\n"); + fprintf(ofp, " --no-sessiond Don't spawn a session daemon\n"); fprintf(ofp, " --sessiond-path Session daemon full path\n"); fprintf(ofp, "\n"); fprintf(ofp, "Session options:\n"); fprintf(ofp, " -c, --create-session NAME Create a new session\n"); fprintf(ofp, " -l, --list-sessions List all available sessions\n"); - fprintf(ofp, " -s, --session UUID Specify tracing session using UUID.\n"); + fprintf(ofp, " -s, --session UUID Specify tracing session using UUID\n"); fprintf(ofp, " -d, --destroy-session=NAME Destroy the session specified by NAME\n"); fprintf(ofp, "\n"); fprintf(ofp, "Tracing options:\n"); //fprintf(ofp, " --kernel Enable kernel tracing\n"); //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, "\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