channels[i].attr.read_timer_interval =
uchan->attr.read_timer_interval;
channels[i].enabled = uchan->enabled;
+ channels[i].attr.tracefile_size = uchan->tracefile_size;
+ channels[i].attr.tracefile_count = uchan->tracefile_count;
switch (uchan->attr.output) {
case LTTNG_UST_MMAP:
default:
strncpy(tmp_events[i].name, event->name, sizeof(tmp_events[i].name));
tmp_events[i].name[sizeof(tmp_events[i].name) - 1] = '\0';
tmp_events[i].enabled = event->enabled;
+ tmp_events[i].loglevel = event->loglevel;
+ tmp_events[i].loglevel_type = event->loglevel_type;
i++;
}
rcu_read_unlock();
if (uevent->filter) {
tmp[i].filter = 1;
}
+ if (uevent->exclusion) {
+ tmp[i].exclusion = 1;
+ }
i++;
}
* URI was the same in the consumer so we do not append the subdir
* again so to not duplicate output dir.
*/
+ ret = LTTNG_OK;
goto error;
}
/* Quiescent wait after starting trace */
kernel_wait_quiescent(kernel_tracer_fd);
- ksess->started = 1;
+ ksess->active = 1;
ret = LTTNG_OK;
* Don't try to enable a channel if the session has been started at
* some point in time before. The tracer does not allow it.
*/
- if (session->started) {
+ if (session->has_been_started) {
ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
goto error;
}
attr->attr.switch_timer_interval = 0;
}
+ /*
+ * The ringbuffer (both in user space and kernel) behave badly in overwrite
+ * mode and with less than 2 subbuf so block it right away and send back an
+ * invalid attribute error.
+ */
+ if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
switch (domain->type) {
case LTTNG_DOMAIN_KERNEL:
{
kchan = trace_kernel_get_channel_by_name(attr->name,
session->kernel_session);
if (kchan == NULL) {
- /*
- * Don't try to create a channel if the session
- * has been started at some point in time
- * before. The tracer does not allow it.
- */
- if (session->started) {
- ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
- goto error;
- }
ret = channel_kernel_create(session->kernel_session, attr, wpipe);
if (attr->name[0] != '\0') {
session->kernel_session->has_non_default_channel = 1;
uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
if (uchan == NULL) {
- /*
- * Don't try to create a channel if the session
- * has been started at some point in time
- * before. The tracer does not allow it.
- */
- if (session->started) {
- ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
- goto error;
- }
ret = channel_ust_create(usess, attr, domain->buf_type);
if (attr->name[0] != '\0') {
usess->has_non_default_channel = 1;
*/
int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
char *channel_name, struct lttng_event *event,
- struct lttng_filter_bytecode *filter, int wpipe)
+ char *filter_expression,
+ struct lttng_filter_bytecode *filter,
+ struct lttng_event_exclusion *exclusion,
+ int wpipe)
{
int ret, channel_created = 0;
struct lttng_channel *attr;
}
/* At this point, the session and channel exist on the tracer */
- ret = event_ust_enable_tracepoint(usess, uchan, event, filter);
+ ret = event_ust_enable_tracepoint(usess, uchan, event,
+ filter_expression, filter, exclusion);
if (ret != LTTNG_OK) {
goto error;
}
assert(usess);
/* Create the default JUL tracepoint. */
+ memset(&uevent, 0, sizeof(uevent));
uevent.type = LTTNG_EVENT_TRACEPOINT;
uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
- strncpy(uevent.name, DEFAULT_JUL_EVENT_NAME, sizeof(uevent.name));
+ if (is_root) {
+ strncpy(uevent.name, DEFAULT_SYS_JUL_EVENT_NAME,
+ sizeof(uevent.name));
+ } else {
+ strncpy(uevent.name, DEFAULT_USER_JUL_EVENT_NAME,
+ sizeof(uevent.name));
+ }
uevent.name[sizeof(uevent.name) - 1] = '\0';
/*
tmp_dom.type = LTTNG_DOMAIN_UST;
ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
- &uevent, NULL, wpipe);
+ &uevent, filter_expression, filter, NULL, wpipe);
if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
goto error;
}
/* The wild card * means that everything should be enabled. */
if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
- ret = event_jul_enable_all(usess);
+ ret = event_jul_enable_all(usess, event, filter);
} else {
- ret = event_jul_enable(usess, event);
+ ret = event_jul_enable(usess, event, filter);
}
if (ret != LTTNG_OK) {
goto error;
*/
int cmd_enable_event_all(struct ltt_session *session,
struct lttng_domain *domain, char *channel_name, int event_type,
+ char *filter_expression,
struct lttng_filter_bytecode *filter, int wpipe)
{
int ret;
switch (event_type) {
case LTTNG_EVENT_ALL:
case LTTNG_EVENT_TRACEPOINT:
- ret = event_ust_enable_all_tracepoints(usess, uchan, filter);
+ ret = event_ust_enable_all_tracepoints(usess, uchan,
+ filter_expression, filter);
if (ret != LTTNG_OK) {
goto error;
}
}
case LTTNG_DOMAIN_JUL:
{
- struct lttng_event uevent;
+ struct lttng_event uevent, event;
struct lttng_domain tmp_dom;
struct ltt_ust_session *usess = session->ust_session;
/* Create the default JUL tracepoint. */
uevent.type = LTTNG_EVENT_TRACEPOINT;
uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
- strncpy(uevent.name, DEFAULT_JUL_EVENT_NAME, sizeof(uevent.name));
+ if (is_root) {
+ strncpy(uevent.name, DEFAULT_SYS_JUL_EVENT_NAME,
+ sizeof(uevent.name));
+ } else {
+ strncpy(uevent.name, DEFAULT_USER_JUL_EVENT_NAME,
+ sizeof(uevent.name));
+ }
uevent.name[sizeof(uevent.name) - 1] = '\0';
/*
tmp_dom.type = LTTNG_DOMAIN_UST;
ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
- &uevent, NULL, wpipe);
+ &uevent, NULL, NULL, NULL, wpipe);
if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
goto error;
}
- ret = event_jul_enable_all(usess);
+ event.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
+ event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
+ strncpy(event.name, "*", sizeof(event.name));
+ event.name[sizeof(event.name) - 1] = '\0';
+
+ ret = event_jul_enable_all(usess, &event, filter);
if (ret != LTTNG_OK) {
goto error;
}
int cmd_start_trace(struct ltt_session *session)
{
int ret;
+ unsigned long nb_chan = 0;
struct ltt_kernel_session *ksession;
struct ltt_ust_session *usess;
ksession = session->kernel_session;
usess = session->ust_session;
- if (session->enabled) {
- /* Already started. */
+ /* Is the session already started? */
+ if (session->active) {
ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
goto error;
}
- session->enabled = 1;
+ /*
+ * Starting a session without channel is useless since after that it's not
+ * possible to enable channel thus inform the client.
+ */
+ if (usess && usess->domain_global.channels) {
+ nb_chan += lttng_ht_get_count(usess->domain_global.channels);
+ }
+ if (ksession) {
+ nb_chan += ksession->channel_count;
+ }
+ if (!nb_chan) {
+ ret = LTTNG_ERR_NO_CHANNEL;
+ goto error;
+ }
/* Kernel tracing */
if (ksession != NULL) {
/* Flag session that trace should start automatically */
if (usess) {
- usess->start_trace = 1;
+ /*
+ * Even though the start trace might fail, flag this session active so
+ * other application coming in are started by default.
+ */
+ usess->active = 1;
ret = ust_app_start_trace_all(usess);
if (ret < 0) {
}
}
- session->started = 1;
+ /* Flag this after a successful start. */
+ session->has_been_started = 1;
+ session->active = 1;
ret = LTTNG_OK;
ksession = session->kernel_session;
usess = session->ust_session;
- if (!session->enabled) {
+ /* Session is not active. Skip everythong and inform the client. */
+ if (!session->active) {
ret = LTTNG_ERR_TRACE_ALREADY_STOPPED;
goto error;
}
- session->enabled = 0;
-
/* Kernel tracer */
- if (ksession && ksession->started) {
+ if (ksession && ksession->active) {
DBG("Stop kernel tracing");
/* Flush metadata if exist */
kernel_wait_quiescent(kernel_tracer_fd);
- ksession->started = 0;
+ ksession->active = 0;
}
- if (usess && usess->start_trace) {
- usess->start_trace = 0;
+ if (usess && usess->active) {
+ /*
+ * Even though the stop trace might fail, flag this session inactive so
+ * other application coming in are not started by default.
+ */
+ usess->active = 0;
ret = ust_app_stop_trace_all(usess);
if (ret < 0) {
}
}
+ /* Flag inactive after a successful stop. */
+ session->active = 0;
ret = LTTNG_OK;
error:
assert(uris);
assert(nb_uri > 0);
- /* Can't enable consumer after session started. */
- if (session->enabled) {
+ /* Can't set consumer URI if the session is active. */
+ if (session->active) {
ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
goto error;
}
}
}
+ /*
+ * Make sure to set the session in output mode after we set URI since a
+ * session can be created without URL (thus flagged in no output mode).
+ */
+ session->output_traces = 1;
+ if (ksess) {
+ ksess->output_traces = 1;
+ } else if (usess) {
+ usess->output_traces = 1;
+ }
+
/* All good! */
ret = LTTNG_OK;
{
struct lttng_kernel_calibrate kcalibrate;
- kcalibrate.type = calibrate->type;
+ switch (calibrate->type) {
+ case LTTNG_CALIBRATE_FUNCTION:
+ default:
+ /* Default and only possible calibrate option. */
+ kcalibrate.type = LTTNG_KERNEL_CALIBRATE_KRETPROBE;
+ break;
+ }
+
ret = kernel_calibrate(kernel_tracer_fd, &kcalibrate);
if (ret < 0) {
ret = LTTNG_ERR_KERN_ENABLE_FAIL;
{
struct lttng_ust_calibrate ucalibrate;
- ucalibrate.type = calibrate->type;
+ switch (calibrate->type) {
+ case LTTNG_CALIBRATE_FUNCTION:
+ default:
+ /* Default and only possible calibrate option. */
+ ucalibrate.type = LTTNG_UST_CALIBRATE_TRACEPOINT;
+ break;
+ }
+
ret = ust_app_calibrate_glb(&ucalibrate);
if (ret < 0) {
ret = LTTNG_ERR_UST_CALIBRATE_FAIL;
strncpy(sessions[i].name, session->name, NAME_MAX);
sessions[i].name[NAME_MAX - 1] = '\0';
- sessions[i].enabled = session->enabled;
+ sessions[i].enabled = session->active;
sessions[i].snapshot_mode = session->snapshot_mode;
+ sessions[i].live_timer_interval = session->live_timer;
i++;
}
}
assert(session);
/* Session MUST be stopped to ask for data availability. */
- if (session->enabled) {
+ if (session->active) {
ret = LTTNG_ERR_SESSION_STARTED;
goto error;
+ } else {
+ /*
+ * If stopped, just make sure we've started before else the above call
+ * will always send that there is data pending.
+ *
+ * The consumer assumes that when the data pending command is received,
+ * the trace has been started before or else no output data is written
+ * by the streams which is a condition for data pending. So, this is
+ * *VERY* important that we don't ask the consumer before a start
+ * trace.
+ */
+ if (!session->has_been_started) {
+ ret = 0;
+ goto error;
+ }
}
if (ksess && ksess->consumer) {
/*
* Record a kernel snapshot.
*
- * Return 0 on success or a LTTNG_ERR code.
+ * Return LTTNG_OK on success or a LTTNG_ERR code.
*/
static int record_kernel_snapshot(struct ltt_kernel_session *ksess,
struct snapshot_output *output, struct ltt_session *session,
- int wait, int nb_streams)
+ int wait, uint64_t max_stream_size)
{
int ret;
goto error_snapshot;
}
- ret = kernel_snapshot_record(ksess, output, wait, nb_streams);
+ ret = kernel_snapshot_record(ksess, output, wait, max_stream_size);
if (ret != LTTNG_OK) {
goto error_snapshot;
}
*/
static int record_ust_snapshot(struct ltt_ust_session *usess,
struct snapshot_output *output, struct ltt_session *session,
- int wait, int nb_streams)
+ int wait, uint64_t max_stream_size)
{
int ret;
goto error_snapshot;
}
- ret = ust_app_snapshot_record(usess, output, wait, nb_streams);
+ ret = ust_app_snapshot_record(usess, output, wait, max_stream_size);
if (ret < 0) {
- if (ret == -EINVAL) {
+ switch (-ret) {
+ case EINVAL:
ret = LTTNG_ERR_INVALID;
- goto error_snapshot;
+ break;
+ case ENODATA:
+ ret = LTTNG_ERR_SNAPSHOT_NODATA;
+ break;
+ default:
+ ret = LTTNG_ERR_SNAPSHOT_FAIL;
+ break;
}
-
- ret = LTTNG_ERR_SNAPSHOT_FAIL;
goto error_snapshot;
}
return ret;
}
+/*
+ * Return the biggest subbuffer size of all channels in the given session.
+ */
+static uint64_t get_session_max_subbuf_size(struct ltt_session *session)
+{
+ uint64_t max_size = 0;
+
+ assert(session);
+
+ if (session->kernel_session) {
+ struct ltt_kernel_channel *chan;
+ struct ltt_kernel_session *ksess = session->kernel_session;
+
+ /*
+ * For each channel, add to the max size the size of each subbuffer
+ * multiplied by their sized.
+ */
+ cds_list_for_each_entry(chan, &ksess->channel_list.head, list) {
+ if (chan->channel->attr.subbuf_size > max_size) {
+ max_size = chan->channel->attr.subbuf_size;
+ }
+ }
+ }
+
+ if (session->ust_session) {
+ struct lttng_ht_iter iter;
+ struct ltt_ust_channel *uchan;
+ struct ltt_ust_session *usess = session->ust_session;
+
+ cds_lfht_for_each_entry(usess->domain_global.channels->ht, &iter.iter,
+ uchan, node.node) {
+ if (uchan->attr.subbuf_size > max_size) {
+ max_size = uchan->attr.subbuf_size;
+ }
+ }
+ }
+
+ return max_size;
+}
+
/*
* Returns the total number of streams for a session or a negative value
* on error.
*/
-static unsigned int get_total_nb_stream(struct ltt_session *session)
+static unsigned int get_session_nb_streams(struct ltt_session *session)
{
unsigned int total_streams = 0;
unsigned int use_tmp_output = 0;
struct snapshot_output tmp_output;
unsigned int nb_streams, snapshot_success = 0;
+ uint64_t session_max_size = 0, max_stream_size = 0;
assert(session);
}
/* The session needs to be started at least once. */
- if (!session->started) {
+ if (!session->has_been_started) {
ret = LTTNG_ERR_START_SESSION_ONCE;
goto error;
}
}
/*
- * Get the total number of stream of that session which is used by the
- * maximum size of the snapshot feature.
+ * Get the session maximum size for a snapshot meaning it will compute the
+ * size of all streams from all domain.
*/
- nb_streams = get_total_nb_stream(session);
+ max_stream_size = get_session_max_subbuf_size(session);
+
+ nb_streams = get_session_nb_streams(session);
+ if (nb_streams) {
+ /*
+ * The maximum size of the snapshot is the number of streams multiplied
+ * by the biggest subbuf size of all channels in a session which is the
+ * maximum stream size available for each stream. The session max size
+ * is now checked against the snapshot max size value given by the user
+ * and if lower, an error is returned.
+ */
+ session_max_size = max_stream_size * nb_streams;
+ }
+
+ DBG3("Snapshot max size is %" PRIu64 " for max stream size of %" PRIu64,
+ session_max_size, max_stream_size);
+
+ /*
+ * If we use a temporary output, check right away if the max size fits else
+ * for each output the max size will be checked.
+ */
+ if (use_tmp_output &&
+ (tmp_output.max_size != 0 &&
+ tmp_output.max_size < session_max_size)) {
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto error;
+ }
if (session->kernel_session) {
struct ltt_kernel_session *ksess = session->kernel_session;
if (use_tmp_output) {
ret = record_kernel_snapshot(ksess, &tmp_output, session,
- wait, nb_streams);
+ wait, max_stream_size);
if (ret != LTTNG_OK) {
goto error;
}
tmp_output.max_size = output->max_size;
}
+ if (tmp_output.max_size != 0 &&
+ tmp_output.max_size < session_max_size) {
+ rcu_read_unlock();
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto error;
+ }
+
/* Use temporary name. */
if (*output->name != '\0') {
strncpy(tmp_output.name, output->name,
tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
ret = record_kernel_snapshot(ksess, &tmp_output,
- session, wait, nb_streams);
+ session, wait, max_stream_size);
if (ret != LTTNG_OK) {
rcu_read_unlock();
goto error;
if (use_tmp_output) {
ret = record_ust_snapshot(usess, &tmp_output, session,
- wait, nb_streams);
+ wait, max_stream_size);
if (ret != LTTNG_OK) {
goto error;
}
tmp_output.max_size = output->max_size;
}
+ if (tmp_output.max_size != 0 &&
+ tmp_output.max_size < session_max_size) {
+ rcu_read_unlock();
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto error;
+ }
+
/* Use temporary name. */
if (*output->name != '\0') {
strncpy(tmp_output.name, output->name,
tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
ret = record_ust_snapshot(usess, &tmp_output, session,
- wait, nb_streams);
+ wait, max_stream_size);
if (ret != LTTNG_OK) {
rcu_read_unlock();
goto error;