Fix: lttng-live flush when output to file
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Apr 2016 22:42:06 +0000 (18:42 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 20 Apr 2016 17:04:48 +0000 (13:04 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
doc/babeltrace.1
formats/lttng-live/lttng-live-comm.c
formats/lttng-live/lttng-live-plugin.c
formats/lttng-live/lttng-live.h

index 929c5634e51d7fc83b040983477fc4fb93ce059d..1ee2281fd9a79d1c0c22ee9b200b94f88339889f 100644 (file)
@@ -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 <lttng-dev@lists.lttng.org> to help improve this
index 492125a7b058bdfcd03d940c3d5d34d536d25885..fdecf31c92eaa70238611a0b138fdcf6baf7b764 100644 (file)
@@ -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);
index bf71b2bfb3beee37bf009d3c186ed310bef0e59c..771801ce9c655d59bac690fd6b0e34863dd54105 100644 (file)
@@ -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;
        }
index 4ab641d59609dceb6d53d2a9cfa4f12f9835d467..56492be0c81a3f5c340e614d4067deb93ee355b9 100644 (file)
 #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];
This page took 0.026505 seconds and 4 git commands to generate.