From 85e2085e04672b7ca72960e5c17b8441275d91a0 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 24 Feb 2014 12:54:03 -0500 Subject: [PATCH] Fix: lttng-live: 100ms active poll delay 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 --- formats/lttng-live/lttng-live-comm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/formats/lttng-live/lttng-live-comm.c b/formats/lttng-live/lttng-live-comm.c index 8e701b21..568a4a1e 100644 --- a/formats/lttng-live/lttng-live-comm.c +++ b/formats/lttng-live/lttng-live-comm.c @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -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, -- 2.34.1