From: Jérémie Galarneau Date: Thu, 30 Jan 2020 17:40:08 +0000 (-0500) Subject: lttng-view: make babeltrace2 the default viewer X-Git-Tag: v2.12.0-rc1~29 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=3cd887b35fa74815822b87c5495473288002345a lttng-view: make babeltrace2 the default viewer Use the `babeltrace2` binary to view traces by default rather than the legacy `babeltrace`. As the install base of Babeltrace 2.x is rather small at this point, silently fallback to Babeltrace 1.x when it is not found on the system. The man page is updated to reflect this change in behaviour. Signed-off-by: Jérémie Galarneau Change-Id: Ie7cd7424f8af1e25238fcc4bb1aa3ee8226da023 --- diff --git a/configure.ac b/configure.ac index 97bb30f2a..ab659691f 100644 --- a/configure.ac +++ b/configure.ac @@ -245,13 +245,12 @@ AC_ARG_WITH([babeltrace-bin], [BABELTRACE_BIN='']) AC_SUBST([BABELTRACE_BIN]) -# lttv-gui -AC_ARG_WITH([lttv-gui-bin], - AS_HELP_STRING([--with-lttv-gui-bin], - [Location of the lttv GUI viewer executable (including the filename)]), - [LTTV_GUI_BIN="$withval"], - [LTTV_GUI_BIN='']) -AC_SUBST([LTTV_GUI_BIN]) +AC_ARG_WITH([babeltrace2-bin], + AS_HELP_STRING([--with-babeltrace2-bin], + [Location of the babeltrace2 viewer executable (including the filename)]), + [BABELTRACE2_BIN="$withval"], + [BABELTRACE2_BIN='']) +AC_SUBST([BABELTRACE2_BIN]) AC_ARG_WITH([consumerd32-bin], AS_HELP_STRING([--with-consumerd32-bin], @@ -319,6 +318,7 @@ AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD64_BIN], "$CONSUMERD64_BIN", [Location of th AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD32_LIBDIR], "$CONSUMERD32_LIBDIR", [Search for consumerd 32-bit libraries in this location.]) AC_DEFINE_UNQUOTED([CONFIG_CONSUMERD64_LIBDIR], "$CONSUMERD64_LIBDIR", [Search for consumerd 64-bit libraries in this location.]) AC_DEFINE_UNQUOTED([CONFIG_BABELTRACE_BIN], "$BABELTRACE_BIN", [Location of the babeltrace viewer executable.]) +AC_DEFINE_UNQUOTED([CONFIG_BABELTRACE2_BIN], "$BABELTRACE2_BIN", [Location of the babeltrace2 viewer executable.]) AC_DEFINE_UNQUOTED([CONFIG_SESSIOND_BIN], "$SESSIOND_BIN", [Location of the sessiond executable.]) AC_DEFINE_UNQUOTED([CONFIG_LTTNG_SYSTEM_RUNDIR], ["$LTTNG_SYSTEM_RUNDIR"], [LTTng system runtime directory]) diff --git a/doc/man/lttng-view.1.txt b/doc/man/lttng-view.1.txt index 50dc129d3..e358c5b63 100644 --- a/doc/man/lttng-view.1.txt +++ b/doc/man/lttng-view.1.txt @@ -25,7 +25,9 @@ about the current tracing session). Otherwise, it is launched for the existing tracing session named 'SESSION'. `lttng list` outputs all the existing tracing sessions (see man:lttng-list(1)). -By default, the man:babeltrace(1) trace viewer is launched. +By default, the man:babeltrace2(1) trace viewer is launched. If it is +not found on the system, the man:babeltrace(1) trace viewer is +used. Another trace viewer command can be specified using the option:--viewer option. diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index a13cb3525..3e2ce40ef 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -30,6 +30,7 @@ static char *opt_session_name; static char *opt_viewer; static char *opt_trace_path; static const char *babeltrace_bin = CONFIG_BABELTRACE_BIN; +static const char *babeltrace2_bin = CONFIG_BABELTRACE2_BIN; #ifdef LTTNG_EMBED_HELP static const char help_msg[] = @@ -55,6 +56,7 @@ static struct poptOption long_options[] = { * This is needed for each viewer since we are using execvp(). */ static const char *babeltrace_opts[] = { "babeltrace" }; +static const char *babeltrace2_opts[] = { "babeltrace2" }; /* * Type is also use as the index in the viewers array. So please, make sure @@ -62,7 +64,8 @@ static const char *babeltrace_opts[] = { "babeltrace" }; */ enum viewer_type { VIEWER_BABELTRACE = 0, - VIEWER_USER_DEFINED = 1, + VIEWER_BABELTRACE2 = 1, + VIEWER_USER_DEFINED = 2, }; /* @@ -74,6 +77,7 @@ static const struct viewers { enum viewer_type type; } viewers[] = { { "babeltrace", VIEWER_BABELTRACE }, + { "babeltrace2", VIEWER_BABELTRACE2 }, { NULL, VIEWER_USER_DEFINED }, }; @@ -84,7 +88,7 @@ static const struct viewers *parse_options(void) { if (opt_viewer == NULL) { /* Default is babeltrace */ - return &(viewers[VIEWER_BABELTRACE]); + return &(viewers[VIEWER_BABELTRACE2]); } /* @@ -217,7 +221,17 @@ static int spawn_viewer(const char *trace_path) goto error; } +retry_viewer: switch (viewer->type) { + case VIEWER_BABELTRACE2: + if (stat(babeltrace2_bin, &status) == 0) { + viewer_bin = babeltrace2_bin; + } else { + viewer_bin = viewer->exec_name; + } + argv = alloc_argv_from_local_opts(babeltrace2_opts, + ARRAY_SIZE(babeltrace2_opts), trace_path); + break; case VIEWER_BABELTRACE: if (stat(babeltrace_bin, &status) == 0) { viewer_bin = babeltrace_bin; @@ -249,10 +263,20 @@ static int spawn_viewer(const char *trace_path) ret = execvp(viewer_bin, argv); if (ret) { - if (errno == ENOENT) { - ERR("%s not found on the system", viewer_bin); + if (errno == ENOENT && viewer->exec_name) { + if (viewer->type == VIEWER_BABELTRACE2) { + /* Fallback to legacy babeltrace. */ + DBG("babeltrace2 not installed on the system, falling back to babeltrace 1.x"); + viewer = &viewers[VIEWER_BABELTRACE]; + free(argv); + argv = NULL; + goto retry_viewer; + } else { + ERR("Viewer \"%s\" not found on the system", + viewer_bin); + } } else { - PERROR("exec: %s", viewer_bin); + PERROR("Failed to launch \"%s\" viewer", viewer_bin); } ret = CMD_FATAL; goto error;