X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=c9fb293be1ed74411d20238ec7f94663a613041e;hp=edaebf59c8654515ac7872d0888e4a84dd6ab0ad;hb=18eace3ba4aeaa6b869c8ad9ec1273381b4cbdee;hpb=2f70b271351fe2b7befc4e327503f7c13a57dcd5 diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index edaebf59c..c9fb293be 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -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,14 +695,64 @@ 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_pending(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 != 0); + + 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); } /* - * Add context to event and/or channel. - * If event_name is NULL, the context is applied to all events of the channel. - * If channel_name is NULL, a lookup of the event's channel is done. - * If both are NULL, the context is applied to all events of all channels. + * 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); +} + +/* + * Add context to a channel. + * + * If the given channel is NULL, add the contexts to all channels. + * The event_name param is ignored. * * Returns the size of the returned payload data or a negative error code. */ @@ -726,9 +774,6 @@ int lttng_add_context(struct lttng_handle *handle, /* Copy channel name */ copy_string(lsm.u.context.channel_name, channel_name, sizeof(lsm.u.context.channel_name)); - /* Copy event name */ - copy_string(lsm.u.context.event_name, event_name, - sizeof(lsm.u.context.event_name)); copy_lttng_domain(&lsm.domain, &handle->domain); @@ -782,13 +827,13 @@ int lttng_enable_event(struct lttng_handle *handle, } /* - * set filter for an event + * Set filter for an event + * * Return negative error value on error. * Return size of returned session payload data if OK. */ - int lttng_set_event_filter(struct lttng_handle *handle, - const char *event_name, const char *channel_name, + struct lttng_event *event, const char *channel_name, const char *filter_expression) { struct lttcomm_session_msg lsm; @@ -882,8 +927,10 @@ int lttng_set_event_filter(struct lttng_handle *handle, copy_string(lsm.u.filter.channel_name, channel_name, sizeof(lsm.u.filter.channel_name)); /* Copy event name */ - copy_string(lsm.u.filter.event_name, event_name, - sizeof(lsm.u.filter.event_name)); + if (event) { + memcpy(&lsm.u.enable.event, event, sizeof(lsm.u.enable.event)); + } + lsm.u.filter.bytecode_len = sizeof(ctx->bytecode->b) + bytecode_get_len(&ctx->bytecode->b); @@ -1296,7 +1343,7 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; - attr->subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE; + attr->subbuf_size = default_get_kernel_channel_subbuf_size(); attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM; attr->output = DEFAULT_KERNEL_CHANNEL_OUTPUT; break; @@ -1310,7 +1357,7 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; - attr->subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE; + attr->subbuf_size = default_get_ust_channel_subbuf_size(); attr->num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM; attr->output = DEFAULT_UST_CHANNEL_OUTPUT; break; @@ -1558,16 +1605,7 @@ int _lttng_create_session_ext(const char *name, const char *url, memset(&lsm, 0, sizeof(lsm)); lsm.cmd_type = LTTNG_CREATE_SESSION; - if (!strncmp(name, DEFAULT_SESSION_NAME, strlen(DEFAULT_SESSION_NAME))) { - ret = snprintf(lsm.session.name, sizeof(lsm.session.name), "%s-%s", - name, datetime); - if (ret < 0) { - PERROR("snprintf session name datetime"); - return -LTTNG_ERR_FATAL; - } - } else { - copy_string(lsm.session.name, name, sizeof(lsm.session.name)); - } + copy_string(lsm.session.name, name, sizeof(lsm.session.name)); /* There should never be a data URL */ size = parse_str_urls_to_uri(url, NULL, &uris); @@ -1577,7 +1615,7 @@ int _lttng_create_session_ext(const char *name, const char *url, lsm.u.uri.size = size; - if (uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) { + if (size > 0 && uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) { ret = snprintf(uris[0].subdir, sizeof(uris[0].subdir), "%s-%s", name, datetime); if (ret < 0) { @@ -1590,6 +1628,38 @@ int _lttng_create_session_ext(const char *name, const char *url, NULL); } +/* + * For a given session name, this call checks if the data is ready to be read + * or is still being extracted by the consumer(s) hence not ready to be used by + * any readers. + */ +int lttng_data_pending(const char *session_name) +{ + int ret; + struct lttcomm_session_msg lsm; + + if (session_name == NULL) { + return -LTTNG_ERR_INVALID; + } + + lsm.cmd_type = LTTNG_DATA_PENDING; + + copy_string(lsm.session.name, session_name, sizeof(lsm.session.name)); + + ret = ask_sessiond(&lsm, NULL); + + /* + * The ask_sessiond function negate the return code if it's not LTTNG_OK so + * getting -1 means that the reply ret_code was 1 thus meaning that the + * data is available. Yes it is hackish but for now this is the only way. + */ + if (ret == -1) { + ret = 1; + } + + return ret; +} + /* * lib constructor */ @@ -1600,3 +1670,11 @@ static void __attribute__((constructor)) init() /* Set socket for health check */ (void) set_health_socket_path(); } + +/* + * lib destructor + */ +static void __attribute__((destructor)) lttng_ctl_exit() +{ + free(tracing_group); +}