From: Julien Desfossez Date: Tue, 18 Feb 2014 20:34:48 +0000 (-0500) Subject: Command to create a live local session X-Git-Tag: v0.3~28 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=26d63ddf68515dd749de4b22465b28ef6bce2ed2;p=lttngtop.git Command to create a live local session Signed-off-by: Julien Desfossez --- diff --git a/doc/lttngtop.1 b/doc/lttngtop.1 index 54f7c14..243571f 100644 --- a/doc/lttngtop.1 +++ b/doc/lttngtop.1 @@ -30,6 +30,11 @@ Input trace path LTTngTop requires that the pid, procname, tid and ppid context information are enabled during tracing. + +The command --create-local-session does all the required setup for a local +trace (that must be stopped and destroyed manually by the user). +And the command --create-live-session does all the required setup for a live +trace on localhost (it must also be stopped and destroyed manually by the user). .PP .PP diff --git a/src/lttng-session.c b/src/lttng-session.c index 29676f3..75699b0 100644 --- a/src/lttng-session.c +++ b/src/lttng-session.c @@ -32,6 +32,13 @@ int check_or_start_sessiond() ret = -1; goto end; } + ret = system("sudo -l lttng >/dev/null"); + if (ret < 0) { + fprintf(stderr, "[error] You are not root and not " + "allowed by sudo to use lttng\n"); + ret = -1; + goto end; + } sudo = 1; } @@ -236,7 +243,30 @@ end: } static -int enable_event(char *name, int sudo) +int live_local_session(char *name, int sudo) +{ + int ret; + char cmd[1024]; + + ret = sprintf(cmd, "%s lttng create %s --live 1000000 -U net://localhost >/dev/null", + (sudo) ? "sudo" : " ", name); + if (ret < 0) { + fprintf(stderr, "Allocating cmd\n"); + goto end; + } + ret = (system(cmd)); + if (ret != 0) { + fprintf(stderr, "Error: creating the session\n"); + ret = -1; + goto end; + } + +end: + return ret; +} + +static +int enable_events(char *name, int sudo) { int ret; char cmd[1024]; @@ -284,7 +314,7 @@ end: } static -int start(char *name, int sudo) +int start(char *name, int sudo, int local) { int ret; char cmd[1024]; @@ -303,13 +333,19 @@ int start(char *name, int sudo) goto end; } - ret = sprintf(cmd, "%s lttng list|grep %s|cut -d'(' -f2|cut -d ')' -f1", - (sudo) ? "sudo" : " ", name); + if (local) { + ret = sprintf(cmd, "%s lttng list|grep %s|cut -d'(' -f2|cut -d ')' -f1", + (sudo) ? "sudo" : " ", name); + } else { + ret = sprintf(cmd, "lttngtop -r net://localhost|grep %s|cut -d' ' -f1", + name); + } if (ret < 0) { fprintf(stderr, "allocating cmd\n"); goto end; } - fprintf(stderr, "Local session started in "); + fprintf(stderr, "%s session started : ", + (local) ? "Local" : "Live"); ret = (system(cmd)); if (ret != 0) { fprintf(stderr, "error: listing the sessions\n"); @@ -322,11 +358,23 @@ end: } static -int destroy(char *name, int sudo) +int destroy(char *name) { int ret; + int sudo = 0; char cmd[1024]; + if (getuid() != 0) { + ret = system("sudo -l lttng >/dev/null"); + if (ret < 0) { + fprintf(stderr, "[error] You are not root and not " + "allowed by sudo to use lttng\n"); + ret = -1; + goto end; + } + sudo = 1; + } + ret = sprintf(cmd, "%s lttng destroy %s >/dev/null", (sudo) ? "sudo" : " ", name); if (ret < 0) { @@ -369,7 +417,7 @@ int create_local_session() goto end_free; } - ret = enable_event(name, sudo); + ret = enable_events(name, sudo); if (ret < 0) { goto end_free; } @@ -379,7 +427,7 @@ int create_local_session() goto end_free; } - ret = start(name, sudo); + ret = start(name, sudo, 1); if (ret < 0) { goto end_free; } @@ -390,9 +438,54 @@ end: return ret; } -int destroy_local_session(char *name, int sudo) +int destroy_session(char *name) +{ + return destroy(name); +} + +int create_live_local_session() { - return destroy(name, sudo); + int ret; + char *name; + int sudo = 0; + + ret = check_requirements(&sudo); + + name = random_session_name(); + if (!name) { + ret = -1; + goto end; + } + + ret = check_session_name(name, sudo); + if (ret < 0) { + goto end_free; + } + + ret = live_local_session(name, sudo); + if (ret < 0) { + goto end_free; + } + + ret = enable_events(name, sudo); + if (ret < 0) { + goto end_free; + } + + ret = add_contexts(name, sudo); + if (ret < 0) { + goto end_free; + } + + ret = start(name, sudo, 0); + if (ret < 0) { + goto end_free; + } + +end_free: + free(name); +end: + return ret; } /* diff --git a/src/lttngtop.c b/src/lttngtop.c index 9cf3a55..ea9c389 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -109,6 +109,7 @@ enum { OPT_VERBOSE, OPT_GUI_TEST, OPT_CREATE_LOCAL_SESSION, + OPT_CREATE_LIVE_SESSION, }; static struct poptOption long_options[] = { @@ -127,6 +128,7 @@ static struct poptOption long_options[] = { { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL }, { "gui-test", 'g', POPT_ARG_NONE, NULL, OPT_GUI_TEST, NULL, NULL }, { "create-local-session", 0, POPT_ARG_NONE, NULL, OPT_CREATE_LOCAL_SESSION, NULL, NULL }, + { "create-live-session", 0, POPT_ARG_NONE, NULL, OPT_CREATE_LIVE_SESSION, NULL, NULL }, { NULL, 0, 0, NULL, 0, NULL, NULL }, }; @@ -695,6 +697,8 @@ void usage(FILE *fp) fprintf(fp, " -b, --begin Network live streaming : read the trace for the beginning of the recording\n"); fprintf(fp, " -o, --output In textdump, output the log in \n"); fprintf(fp, " -g, --gui-test Test if the ncurses support is compiled in (return 0 if it is)\n"); + fprintf(fp, " --create-local-session Setup a LTTng local session with all the right parameters\n"); + fprintf(fp, " --create-live-session Setup a LTTng live session on localhost with all the right parameters\n"); } /* @@ -805,6 +809,9 @@ static int parse_options(int argc, char **argv) case OPT_CREATE_LOCAL_SESSION: ret = create_local_session(); exit(ret); + case OPT_CREATE_LIVE_SESSION: + ret = create_live_local_session(); + exit(ret); case OPT_TEXTDUMP: opt_textdump = 1; break;