From: Mathieu Desnoyers Date: Tue, 19 Apr 2016 22:42:06 +0000 (-0400) Subject: Fix: lttng-live flush when output to file X-Git-Tag: v1.4.0-rc1~100 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=857eaa682bde4acfb5b9437ac9ace2d429d7107a Fix: lttng-live flush when output to file When the standard output is redirected to a file, we need to flush the output between each packet, otherwise the stream buffering may keep us from seeing events for a while in a low-throughput trace. While we are there, document that lttng-live does now support the --output option in babeltrace 1.x. Fixes #1010 Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/doc/babeltrace.1 b/doc/babeltrace.1 index 929c5634..1ee2281f 100644 --- a/doc/babeltrace.1 +++ b/doc/babeltrace.1 @@ -97,7 +97,8 @@ babeltrace-log(1), lttng(1), lttng-ust(3), lttng-sessiond(8) .SH "BUGS" .PP -No known bugs at this point. +The lttng-live plugin does not honor the the "--output" command line +option. If you encounter any issues or usability problem, please report it on our mailing list to help improve this diff --git a/formats/lttng-live/lttng-live-comm.c b/formats/lttng-live/lttng-live-comm.c index 492125a7..fdecf31c 100644 --- a/formats/lttng-live/lttng-live-comm.c +++ b/formats/lttng-live/lttng-live-comm.c @@ -246,7 +246,7 @@ void print_session_list(GPtrArray *session_list, const char *path) for (i = 0; i < session_list->len; i++) { relay_session = g_ptr_array_index(session_list, i); - fprintf(stdout, "%s/host/%s/%s (timer = %u, " + fprintf(LTTNG_LIVE_OUTPUT_FP, "%s/host/%s/%s (timer = %u, " "%u stream(s), %u client(s) connected)\n", path, relay_session->hostname, relay_session->name, relay_session->timer, @@ -649,6 +649,18 @@ retry: ret = -1; goto end; } + + /* + * Flush the output between attempts to grab a packet, thus + * ensuring we flush at least at the periodical timer period. + * This ensures the output remains reactive for interactive users and + * that the output is flushed when redirected to a file by the shell. + */ + if (fflush(LTTNG_LIVE_OUTPUT_FP) < 0) { + perror("fflush"); + goto error; + } + cmd.cmd = htobe32(LTTNG_VIEWER_GET_PACKET); cmd.data_size = htobe64(sizeof(rq)); cmd.cmd_version = htobe32(0); diff --git a/formats/lttng-live/lttng-live-plugin.c b/formats/lttng-live/lttng-live-plugin.c index bf71b2bf..771801ce 100644 --- a/formats/lttng-live/lttng-live-plugin.c +++ b/formats/lttng-live/lttng-live-plugin.c @@ -292,6 +292,12 @@ struct bt_trace_descriptor *lttng_live_open_trace(const char *path, int flags, pos->parent.rw_table = NULL; pos->parent.event_cb = NULL; pos->parent.trace = &pos->trace_descriptor; + /* + * Since we do *everything* in this function, we are skipping + * the output plugin handling that is part of Babeltrace 1.x. + * Therefore, don't expect the --output cmd line option to work. + * This limits the output of lttng-live to stderr and stdout. + */ if (lttng_live_open_trace_read(path) < 0) { goto error; } diff --git a/formats/lttng-live/lttng-live.h b/formats/lttng-live/lttng-live.h index 4ab641d5..56492be0 100644 --- a/formats/lttng-live/lttng-live.h +++ b/formats/lttng-live/lttng-live.h @@ -32,6 +32,13 @@ #define LTTNG_LIVE_MAJOR 2 #define LTTNG_LIVE_MINOR 4 +/* + * The lttng-live output file pointer is currently hardcoded to stdout, + * and is expected to be hardcoded to this by fflush() performed between + * each packet. + */ +#define LTTNG_LIVE_OUTPUT_FP stdout + struct lttng_live_ctx { char traced_hostname[MAXNAMLEN]; char session_name[MAXNAMLEN];