Command to create a live local session
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 18 Feb 2014 20:34:48 +0000 (15:34 -0500)
committerJulien Desfossez <jdesfossez@efficios.com>
Tue, 18 Feb 2014 20:34:48 +0000 (15:34 -0500)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
doc/lttngtop.1
src/lttng-session.c
src/lttngtop.c

index 54f7c14518ea1c98dcd8fda80827d309e94edc2a..243571f6da37e2c48ef8d85c101170ef31e970c7 100644 (file)
@@ -30,6 +30,11 @@ Input trace path
 
 LTTngTop requires that the pid, procname, tid and ppid context information
 are enabled during tracing.
 
 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
 .PP
 
 .PP
index 29676f31dca8fbaf98bf79add6496f7f9f291327..75699b0852f2baa80b3a0a528af6ca5e58811be0 100644 (file)
@@ -32,6 +32,13 @@ int check_or_start_sessiond()
                        ret = -1;
                        goto end;
                }
                        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;
        }
 
                sudo = 1;
        }
 
@@ -236,7 +243,30 @@ end:
 }
 
 static
 }
 
 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];
 {
        int ret;
        char cmd[1024];
@@ -284,7 +314,7 @@ end:
 }
 
 static
 }
 
 static
-int start(char *name, int sudo)
+int start(char *name, int sudo, int local)
 {
        int ret;
        char cmd[1024];
 {
        int ret;
        char cmd[1024];
@@ -303,13 +333,19 @@ int start(char *name, int sudo)
                goto end;
        }
 
                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;
        }
        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");
        ret = (system(cmd));
        if (ret != 0) {
                fprintf(stderr, "error: listing the sessions\n");
@@ -322,11 +358,23 @@ end:
 }
 
 static
 }
 
 static
-int destroy(char *name, int sudo)
+int destroy(char *name)
 {
        int ret;
 {
        int ret;
+       int sudo = 0;
        char cmd[1024];
 
        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) {
        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;
        }
 
                goto end_free;
        }
 
-       ret = enable_event(name, sudo);
+       ret = enable_events(name, sudo);
        if (ret < 0) {
                goto end_free;
        }
        if (ret < 0) {
                goto end_free;
        }
@@ -379,7 +427,7 @@ int create_local_session()
                goto end_free;
        }
 
                goto end_free;
        }
 
-       ret = start(name, sudo);
+       ret = start(name, sudo, 1);
        if (ret < 0) {
                goto end_free;
        }
        if (ret < 0) {
                goto end_free;
        }
@@ -390,9 +438,54 @@ end:
        return ret;
 }
 
        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;
 }
 
 /*
 }
 
 /*
index 9cf3a55d9c80bc4565dc6c5abd4aa5f4fded88f9..ea9c389059f1836117b36e72c654f303d590e916 100644 (file)
@@ -109,6 +109,7 @@ enum {
        OPT_VERBOSE,
        OPT_GUI_TEST,
        OPT_CREATE_LOCAL_SESSION,
        OPT_VERBOSE,
        OPT_GUI_TEST,
        OPT_CREATE_LOCAL_SESSION,
+       OPT_CREATE_LIVE_SESSION,
 };
 
 static struct poptOption long_options[] = {
 };
 
 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 },
        { "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 },
 };
 
        { 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 <filename>  In textdump, output the log in <filename>\n");
        fprintf(fp, "  -g, --gui-test           Test if the ncurses support is compiled in (return 0 if it is)\n");
        fprintf(fp, "  -b, --begin              Network live streaming : read the trace for the beginning of the recording\n");
        fprintf(fp, "  -o, --output <filename>  In textdump, output the log in <filename>\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_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;
                        case OPT_TEXTDUMP:
                                opt_textdump = 1;
                                break;
This page took 0.026205 seconds and 4 git commands to generate.