From: Julien Desfossez Date: Tue, 18 Feb 2014 21:42:10 +0000 (-0500) Subject: lttngtop without arguments starts a local live trace X-Git-Tag: v0.3~26 X-Git-Url: http://git.lttng.org/?a=commitdiff_plain;h=6a1b139cec6513cb5d423d27a1a61c4424886bf1;hp=18e85696d986196569d5c67ce5352708948f88df;p=lttngtop.git lttngtop without arguments starts a local live trace 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 --- diff --git a/src/lttng-session.c b/src/lttng-session.c index 75699b0..8b0f641 100644 --- a/src/lttng-session.c +++ b/src/lttng-session.c @@ -5,6 +5,7 @@ #include #include #include +#include #define event_list "lttng_statedump_start,lttng_statedump_end," \ "lttng_statedump_process_state,lttng_statedump_file_descriptor," \ @@ -314,7 +315,7 @@ end: } static -int start(char *name, int sudo, int local) +int start(char *name, int sudo, int local, int print) { int ret; char cmd[1024]; @@ -333,11 +334,14 @@ int start(char *name, int sudo, int local) 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 { - 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) { @@ -357,6 +361,40 @@ end: 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) { @@ -427,7 +465,7 @@ int create_local_session() goto end_free; } - ret = start(name, sudo, 1); + ret = start(name, sudo, 1, 1); if (ret < 0) { goto end_free; } @@ -438,12 +476,12 @@ end: return ret; } -int destroy_session(char *name) +int destroy_live_local_session(char *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; @@ -477,18 +515,20 @@ int create_live_local_session() goto end_free; } - ret = start(name, sudo, 0); + ret = start(name, sudo, 0, print); 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; } - -/* -int create_live_local_session(); -int destroy_live_local_session(); -*/ diff --git a/src/lttng-session.h b/src/lttng-session.h index 1d85330..e61f8a4 100644 --- a/src/lttng-session.h +++ b/src/lttng-session.h @@ -20,7 +20,7 @@ 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 */ diff --git a/src/lttngtop.c b/src/lttngtop.c index ea9c389..a2b552c 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -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_live_local_session(); + ret = create_live_local_session(NULL, NULL, 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; + char *live_session_name = NULL; 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 */ -#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 \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, @@ -1295,8 +1281,6 @@ int main(int argc, char **argv, char **envp) 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) { @@ -1338,5 +1322,12 @@ end: 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; }