From e8be5f4f7541ab84521ab4e1722708d2234218c6 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 27 Apr 2011 11:18:25 -0400 Subject: [PATCH] Add --session feature This allows any user to select a session and any tracing command will affect that particular session. Signed-off-by: David Goulet --- include/lttng/liblttngctl.h | 1 + liblttngctl/liblttngctl.c | 11 ++++++++++- lttng/lttng.c | 4 ++++ lttng/lttng.h | 2 +- lttng/options.c | 13 +++++++++---- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/lttng/liblttngctl.h b/include/lttng/liblttngctl.h index b729f2b5b..df9731342 100644 --- a/include/lttng/liblttngctl.h +++ b/include/lttng/liblttngctl.h @@ -50,5 +50,6 @@ extern int lttng_check_session_daemon(void); 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); #endif /* _LIBLTTNGCTL_H */ diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index 9afd6fda3..a15a26dff 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -197,7 +197,6 @@ int lttng_ust_list_apps(pid_t **pids) int lttng_create_session(char *name, uuid_t *session_id) { int ret; - char *uuid; strncpy(lsm.session_name, name, sizeof(lsm.session_name)); lsm.session_name[sizeof(lsm.session_name) - 1] = '\0'; @@ -281,6 +280,16 @@ int lttng_connect_sessiond(void) return 0; } +/* + * lttng_set_current_session_uuid + * + * Set the session uuid for current lsm. + */ +void lttng_set_current_session_uuid(char *uuid) +{ + uuid_parse(uuid, lsm.session_id); +} + /* * lttng_set_tracing_group * diff --git a/lttng/lttng.c b/lttng/lttng.c index 169e70eb0..9ef92a7d4 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -93,6 +93,10 @@ static int process_client_opt(void) } } + if (opt_session_uuid != NULL) { + lttng_set_current_session_uuid(opt_session_uuid); + } + return 0; end: diff --git a/lttng/lttng.h b/lttng/lttng.h index f9e75538c..804ccf694 100644 --- a/lttng/lttng.h +++ b/lttng/lttng.h @@ -27,7 +27,7 @@ extern int opt_trace_kernel; extern int opt_verbose; extern int opt_quiet; extern char *opt_tracing_group; -extern char *opt_session_name; +extern char *opt_session_uuid; extern char *opt_create_session; extern char *opt_sessiond_path; extern char *opt_destroy_session; diff --git a/lttng/options.c b/lttng/options.c index befeab54a..11b82fba7 100644 --- a/lttng/options.c +++ b/lttng/options.c @@ -23,7 +23,7 @@ /* Option variables */ char *opt_tracing_group; -char *opt_session_name; +char *opt_session_uuid; char *opt_create_session; char *opt_sessiond_path; char *opt_destroy_session; @@ -44,7 +44,8 @@ static struct poptOption long_options[] = { {"group", 0, POPT_ARG_STRING, &opt_tracing_group, 0, 0}, {"kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 1, 0, 0}, {"no-kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 0, 0, 0}, - {"session", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 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}, @@ -76,8 +77,7 @@ static void usage(FILE *ofp) fprintf(ofp, "Session options:\n"); fprintf(ofp, " -c, --create-session NAME Create a new session\n"); fprintf(ofp, " --list-session List all available sessions\n"); - fprintf(ofp, " --session [NAME] Specify tracing session. If no NAME is given\n"); - fprintf(ofp, " or option is ommited, a session will be created\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"); @@ -97,6 +97,11 @@ int parse_args(int argc, const char **argv) static poptContext pc; int opt; + /* If no options, fail */ + if (argc < 2) { + return -1; + } + pc = poptGetContext("lttng", argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); -- 2.34.1