lttngtop without arguments starts a local live trace
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 18 Feb 2014 21:42:10 +0000 (16:42 -0500)
committerJulien Desfossez <jdesfossez@efficios.com>
Tue, 18 Feb 2014 21:42:10 +0000 (16:42 -0500)
Get rid of the code trying to attach to a live mmap session, since the
support for this mode of operation is not going to enter anytime soon in
lttng-tools and babeltrace.

Instead, we try to create a live session on localhost with all the
required parameters and try to attach to it.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
src/lttng-session.c
src/lttng-session.h
src/lttngtop.c

index 75699b0852f2baa80b3a0a528af6ca5e58811be0..8b0f6414539eb5b20f52d4c0b0af18f004736e06 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <inttypes.h>
+#include <string.h>
 
 #define event_list "lttng_statedump_start,lttng_statedump_end," \
        "lttng_statedump_process_state,lttng_statedump_file_descriptor," \
 
 #define event_list "lttng_statedump_start,lttng_statedump_end," \
        "lttng_statedump_process_state,lttng_statedump_file_descriptor," \
@@ -314,7 +315,7 @@ end:
 }
 
 static
 }
 
 static
-int start(char *name, int sudo, int local)
+int start(char *name, int sudo, int local, int print)
 {
        int ret;
        char cmd[1024];
 {
        int ret;
        char cmd[1024];
@@ -333,11 +334,14 @@ int start(char *name, int sudo, int local)
                goto end;
        }
 
                goto end;
        }
 
+       if (!print)
+               goto end;
+
        if (local) {
                ret = sprintf(cmd, "%s lttng list|grep %s|cut -d'(' -f2|cut -d ')' -f1",
                                (sudo) ? "sudo" : " ", name);
        } else {
        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",
+               ret = sprintf(cmd, "babeltrace -i lttng-live net://localhost|grep %s|cut -d' ' -f1",
                                name);
        }
        if (ret < 0) {
                                name);
        }
        if (ret < 0) {
@@ -357,6 +361,40 @@ end:
        return ret;
 }
 
        return ret;
 }
 
+static
+char *live_path(char *name)
+{
+       FILE *fp;
+       int ret;
+       char path[1035];
+       char cmd[1024];
+       char *out = NULL;
+
+       ret = sprintf(cmd, "lttngtop -r net://localhost|grep %s|cut -d' ' -f1",
+                       name);
+       if (ret < 0) {
+               fprintf(stderr, "allocating cmd\n");
+               goto end;
+       }
+
+       fp = popen(cmd, "r");
+       if (fp == NULL) {
+               printf("Failed to run command\n" );
+               goto end;
+       }
+
+       /* Read the output a line at a time - output it. */
+       out = fgets(path, sizeof(path)-1, fp);
+       if (out)
+               out = strdup(path);
+
+       /* close */
+       pclose(fp);
+
+end:
+       return out;
+}
+
 static
 int destroy(char *name)
 {
 static
 int destroy(char *name)
 {
@@ -427,7 +465,7 @@ int create_local_session()
                goto end_free;
        }
 
                goto end_free;
        }
 
-       ret = start(name, sudo, 1);
+       ret = start(name, sudo, 1, 1);
        if (ret < 0) {
                goto end_free;
        }
        if (ret < 0) {
                goto end_free;
        }
@@ -438,12 +476,12 @@ end:
        return ret;
 }
 
        return ret;
 }
 
-int destroy_session(char *name)
+int destroy_live_local_session(char *name)
 {
        return destroy(name);
 }
 
 {
        return destroy(name);
 }
 
-int create_live_local_session()
+int create_live_local_session(char **session_path, char **session_name, int print)
 {
        int ret;
        char *name;
 {
        int ret;
        char *name;
@@ -477,18 +515,20 @@ int create_live_local_session()
                goto end_free;
        }
 
                goto end_free;
        }
 
-       ret = start(name, sudo, 0);
+       ret = start(name, sudo, 0, print);
        if (ret < 0) {
                goto end_free;
        }
 
        if (ret < 0) {
                goto end_free;
        }
 
+       if (session_path)
+               *session_path = live_path(name);
+       if (session_name) {
+               *session_name = name;
+               goto end;
+       }
+
 end_free:
        free(name);
 end:
        return ret;
 }
 end_free:
        free(name);
 end:
        return ret;
 }
-
-/*
-int create_live_local_session();
-int destroy_live_local_session();
-*/
index 1d85330a2276215ca8ccf81018ea72c2c6589698..e61f8a4dfd0ed42d247137676b19f66e00ecd266 100644 (file)
@@ -20,7 +20,7 @@
 
 int create_local_session();
 int destroy_local_session();
 
 int create_local_session();
 int destroy_local_session();
-int create_live_local_session();
-int destroy_live_local_session();
+int create_live_local_session(char **session_path, char **session_name, int print);
+int destroy_live_local_session(char *name);
 
 #endif /* LTTNG_SESSION_H */
 
 #endif /* LTTNG_SESSION_H */
index ea9c389059f1836117b36e72c654f303d590e916..a2b552c6242bd4816c6c5d2eca8ec896c2897945 100644 (file)
@@ -810,7 +810,7 @@ static int parse_options(int argc, char **argv)
                                ret = create_local_session();
                                exit(ret);
                        case OPT_CREATE_LIVE_SESSION:
                                ret = create_local_session();
                                exit(ret);
                        case OPT_CREATE_LIVE_SESSION:
-                               ret = create_live_local_session();
+                               ret = create_live_local_session(NULL, NULL, 1);
                                exit(ret);
                        case OPT_TEXTDUMP:
                                opt_textdump = 1;
                                exit(ret);
                        case OPT_TEXTDUMP:
                                opt_textdump = 1;
@@ -1246,6 +1246,7 @@ int main(int argc, char **argv, char **envp)
 {
        int ret;
        struct bt_context *bt_ctx = NULL;
 {
        int ret;
        struct bt_context *bt_ctx = NULL;
+       char *live_session_name = NULL;
 
        init_lttngtop();
        ret = parse_options(argc, argv);
 
        init_lttngtop();
        ret = parse_options(argc, argv);
@@ -1264,28 +1265,13 @@ int main(int argc, char **argv, char **envp)
 
        if (!opt_input_path && !remote_live && !opt_exec_name) {
                /* mmap live */
 
        if (!opt_input_path && !remote_live && !opt_exec_name) {
                /* mmap live */
-#ifdef LTTNGTOP_MMAP_LIVE
-               if (opt_textdump) {
-                       signal(SIGTERM, handle_textdump_sigterm);
-                       signal(SIGINT, handle_textdump_sigterm);
-               }
-               mmap_live_loop(bt_ctx);
-               pthread_join(timer_thread, NULL);
-               quit = 1;
-               pthread_join(display_thread, NULL);
-
-               lttng_stop_tracing("test");
-               lttng_destroy_session("test");
-
-               goto end;
-#else
-               fprintf(stderr, "[ERROR] Mmap live support not compiled, specify a "
-                               "trace directory or -r <relayd hostname/IP>\n");
-               usage(stdout);
-               ret = -1;
-               goto end;
-#endif /* LTTNGTOP_MMAP_LIVE */
-       } else if (!opt_input_path && remote_live) {
+               ret = create_live_local_session(&opt_relay_hostname,
+                               &live_session_name, 0);
+               if (ret < 0)
+                       goto end;
+               remote_live = 1;
+       }
+       if (!opt_input_path && remote_live) {
                /* network live */
                bt_ctx = bt_context_create();
                ret = bt_context_add_traces_recursive(bt_ctx, opt_relay_hostname,
                /* network live */
                bt_ctx = bt_context_create();
                ret = bt_context_add_traces_recursive(bt_ctx, opt_relay_hostname,
@@ -1295,8 +1281,6 @@ int main(int argc, char **argv, char **envp)
                        goto end;
                }
        } else {
                        goto end;
                }
        } else {
-               //init_lttngtop();
-
                bt_ctx = bt_context_create();
                ret = bt_context_add_traces_recursive(bt_ctx, opt_input_path, "ctf", NULL);
                if (ret < 0) {
                bt_ctx = bt_context_create();
                ret = bt_context_add_traces_recursive(bt_ctx, opt_input_path, "ctf", NULL);
                if (ret < 0) {
@@ -1338,5 +1322,12 @@ end:
        if (bt_ctx)
                bt_context_put(bt_ctx);
 
        if (bt_ctx)
                bt_context_put(bt_ctx);
 
+       if (live_session_name) {
+               ret = destroy_live_local_session(live_session_name);
+               if (ret < 0) {
+                       fprintf(stderr, "Error destroying %s\n", live_session_name);
+               }
+       }
+
        return ret;
 }
        return ret;
 }
This page took 0.027601 seconds and 4 git commands to generate.