Wait for data availability when stopping a session
authorDavid Goulet <dgoulet@efficios.com>
Wed, 17 Oct 2012 17:40:49 +0000 (13:40 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 19 Oct 2012 18:55:19 +0000 (14:55 -0400)
The lttng_stop_tracing now waits by default for data availability. A
status output is added in the library on stdout.

A no wait version is added to the API and the option no-wait is added to
the lttng command line for the stop command.

Also good to note that if a second stop_tracing call is done on an
already stopped session, the call will wait for data availability before
returning if the stop command on the session daemon returned an already
stopped error code.

Signed-off-by: David Goulet <dgoulet@efficios.com>
include/lttng/lttng.h
src/bin/lttng/commands/stop.c
src/common/defaults.h
src/lib/lttng-ctl/lttng-ctl.c

index 4171cde41c998d123fac3b407a337ec622b42cfe..0a12d9be75e4b97be6728bad11727105f4e68b8c 100644 (file)
@@ -472,9 +472,20 @@ extern int lttng_start_tracing(const char *session_name);
 
 /*
  * Stop tracing for *all* registered traces (kernel and user-space).
+ *
+ * This call will wait for data availability for each domain of the session so
+ * this can take an abritrary amount of time. However, when returning you have
+ * the guarantee that the data is ready to be read and analyse. Use the
+ * _no_wait call below to avoid this behavior.
  */
 extern int lttng_stop_tracing(const char *session_name);
 
+/*
+ * Behave exactly like lttng_stop_tracing but does not wait for data
+ * availability.
+ */
+extern int lttng_stop_tracing_no_wait(const char *session_name);
+
 /*
  * Add context to event(s) for a specific channel (or for all).
  *
index 7c89e37e577af5af2f52ca2600795f0c9f1bd7d7..60a1dac8fe8ca4db4fd58c19d7d4a904012acd70 100644 (file)
@@ -29,6 +29,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 
 static char *opt_session_name;
+static int opt_no_wait;
 
 enum {
        OPT_HELP = 1,
@@ -39,6 +40,7 @@ static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
        {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
+       {"no-wait",   'n', POPT_ARG_VAL, &opt_no_wait, 1, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -55,6 +57,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "Options:\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
        fprintf(ofp, "      --list-options       Simple listing of options\n");
+       fprintf(ofp, "  -n, --no-wait            Don't wait for data availability\n");
        fprintf(ofp, "\n");
 }
 
@@ -76,7 +79,11 @@ static int stop_tracing(void)
                session_name = opt_session_name;
        }
 
-       ret = lttng_stop_tracing(session_name);
+       if (opt_no_wait) {
+               ret = lttng_stop_tracing_no_wait(session_name);
+       } else {
+               ret = lttng_stop_tracing(session_name);
+       }
        if (ret < 0) {
                switch (-ret) {
                case LTTNG_ERR_TRACE_ALREADY_STOPPED:
index ad1b708a3a5825be66bc33e864276b3a4d9f7db2..8bb1190e7e8887b12014b49ec0c6087f11d72909 100644 (file)
 #define DEFAULT_HEALTH_CHECK_DELTA_S        20
 #define DEFAULT_HEALTH_CHECK_DELTA_NS       0
 
+/*
+ * Wait period before retrying the lttng_data_available command in the lttng
+ * stop command of liblttng-ctl.
+ */
+#define DEFAULT_DATA_AVAILABILITY_WAIT_TIME 200000  /* usec */
+
 #endif /* _DEFAULTS_H */
index c6238e11c81e17b746553725d2d062d67a22d2d3..67c5972191016d8eafbf74d1e34faea0e8221e7f 100644 (file)
@@ -69,8 +69,6 @@ static int connected;
  * Those two variables are used by error.h to silent or control the verbosity of
  * error message. They are global to the library so application linking with it
  * are able to compile correctly and also control verbosity of the library.
- *
- * Note that it is *not* possible to silent ERR() and PERROR() macros.
  */
 int lttng_opt_quiet;
 int lttng_opt_verbose;
@@ -682,11 +680,11 @@ int lttng_start_tracing(const char *session_name)
 }
 
 /*
- *  Stop tracing for all traces of the session.
- *  Returns size of returned session payload data or a negative error code.
+ * Stop tracing for all traces of the session.
  */
-int lttng_stop_tracing(const char *session_name)
+static int _lttng_stop_tracing(const char *session_name, int wait)
 {
+       int ret, data_ret;
        struct lttcomm_session_msg lsm;
 
        if (session_name == NULL) {
@@ -697,7 +695,57 @@ int lttng_stop_tracing(const char *session_name)
 
        copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
 
-       return ask_sessiond(&lsm, NULL);
+       ret = ask_sessiond(&lsm, NULL);
+       if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
+               goto error;
+       }
+
+       if (!wait) {
+               goto end;
+       }
+
+       _MSG("Waiting for data availability");
+
+       /* Check for data availability */
+       do {
+               data_ret = lttng_data_available(session_name);
+               if (data_ret < 0) {
+                       /* Return the data available call error. */
+                       ret = data_ret;
+                       goto error;
+               }
+
+               /*
+                * Data sleep time before retrying (in usec). Don't sleep if the call
+                * returned value indicates availability.
+                */
+               if (!data_ret) {
+                       usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME);
+                       _MSG(".");
+               }
+       } while (data_ret != 1);
+
+       MSG("");
+
+end:
+error:
+       return ret;
+}
+
+/*
+ * Stop tracing and wait for data availability.
+ */
+int lttng_stop_tracing(const char *session_name)
+{
+       return _lttng_stop_tracing(session_name, 1);
+}
+
+/*
+ * Stop tracing but _don't_ wait for data availability.
+ */
+int lttng_stop_tracing_no_wait(const char *session_name)
+{
+       return _lttng_stop_tracing(session_name, 0);
 }
 
 /*
This page took 0.030407 seconds and 5 git commands to generate.