Fix: lttng-live: 100ms active poll delay
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 24 Feb 2014 17:54:03 +0000 (12:54 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 25 Feb 2014 12:49:51 +0000 (07:49 -0500)
Do a 100ms delay before retry intead of 1s delays (slightly too long in
terms of user experience) and instead of actively hogging the CPU (too
fast).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/lttng-live/lttng-live-comm.c

index 8e701b2100ebadf1c2136bc7323a1814c29b737b..568a4a1e806d64db8ad6191d4f0fcce25670ea21 100644 (file)
@@ -33,6 +33,7 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <poll.h>
 
 #include <babeltrace/ctf/ctf-index.h>
 
@@ -54,6 +55,8 @@
 #include "lttng-live.h"
 #include "lttng-viewer-abi.h"
 
+#define ACTIVE_POLL_DELAY      100     /* ms */
+
 /*
  * Memory allocation zeroed
  */
@@ -893,6 +896,9 @@ int get_new_metadata(struct lttng_live_ctx *ctx,
                if (ret > 0) {
                        len_read += ret;
                }
+               if (!len_read) {
+                       (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
+               }
        } while (ret > 0 || !len_read);
 
        if (fclose(metadata_stream->metadata_fp_write))
@@ -989,7 +995,7 @@ retry:
                break;
        case LTTNG_VIEWER_INDEX_RETRY:
                printf_verbose("get_next_index: retry\n");
-               sleep(1);
+               (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
                goto retry;
        case LTTNG_VIEWER_INDEX_HUP:
                printf_verbose("get_next_index: stream hung up\n");
@@ -1488,6 +1494,8 @@ void lttng_live_read(struct lttng_live_ctx *ctx)
                        ret = ask_new_streams(ctx);
                        if (ret < 0)
                                goto end_free;
+                       if (!ctx->session->stream_count)
+                               (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
                }
 
                g_hash_table_foreach(ctx->session->ctf_traces, add_traces,
This page took 0.027591 seconds and 4 git commands to generate.