}
/*
- * Create a newly allocated agent event data structure. If name is valid, it's
- * copied into the created event.
+ * Create a newly allocated agent event data structure.
+ * Ownership of filter_expression is taken.
*
* Return a new object else NULL on error.
*/
struct agent_event *agent_create_event(const char *name,
- struct lttng_filter_bytecode *filter)
+ int loglevel, enum lttng_loglevel_type loglevel_type,
+ struct lttng_filter_bytecode *filter, char *filter_expression)
{
- struct agent_event *event;
+ struct agent_event *event = NULL;
DBG3("Agent create new event with name %s", name);
- event = zmalloc(sizeof(*event));
- if (!event) {
+ if (!name) {
+ ERR("Failed to create agent event; no name provided.");
goto error;
}
- if (name) {
- strncpy(event->name, name, sizeof(event->name));
- event->name[sizeof(event->name) - 1] = '\0';
- lttng_ht_node_init_str(&event->node, event->name);
+ event = zmalloc(sizeof(*event));
+ if (!event) {
+ goto error;
}
- if (filter) {
- event->filter = filter;
- }
+ strncpy(event->name, name, sizeof(event->name));
+ event->name[sizeof(event->name) - 1] = '\0';
+ lttng_ht_node_init_str(&event->node, event->name);
+ event->loglevel = loglevel;
+ event->loglevel_type = loglevel_type;
+ event->filter = filter;
+ event->filter_expression = filter_expression;
error:
return event;
}
free(event->filter);
free(event->filter_expression);
+ free(event->exclusion);
free(event);
}
/* Hash table node of the agent domain object. */
struct lttng_ht_node_str node;
- /* Bytecode filter associated with the event . NULL if none. */
- char *filter_expression;
+ /* Filter associated with the event. NULL if none. */
struct lttng_filter_bytecode *filter;
+ char *filter_expression;
+ struct lttng_event_exclusion *exclusion;
};
/*
void agent_add(struct agent *agt, struct lttng_ht *ht);
/* Agent event API. */
-struct agent_event *agent_create_event(const char *name,
- struct lttng_filter_bytecode *filter);
+struct agent_event *agent_create_event(const char *name, int loglevel,
+ enum lttng_loglevel_type loglevel_type,
+ struct lttng_filter_bytecode *filter,
+ char *filter_expression);
void agent_add_event(struct agent_event *event, struct agent *agt);
struct agent_event *agent_find_event(const char *name, int loglevel,
}
/* Create UST channel */
- uchan = trace_ust_create_channel(attr);
+ uchan = trace_ust_create_channel(attr, LTTNG_DOMAIN_UST);
if (uchan == NULL) {
ret = LTTNG_ERR_FATAL;
goto error;
}
+
+ /*
+ * HACK: Set the channel's subdomain (JUL, Log4j, Python, etc.)
+ * based on the default name.
+ */
+ if (!strcmp(uchan->name, DEFAULT_JUL_CHANNEL_NAME)) {
+ uchan->domain = LTTNG_DOMAIN_JUL;
+ } else if (!strcmp(uchan->name, DEFAULT_LOG4J_CHANNEL_NAME)) {
+ uchan->domain = LTTNG_DOMAIN_LOG4J;
+ } else if (!strcmp(uchan->name, DEFAULT_PYTHON_CHANNEL_NAME)) {
+ uchan->domain = LTTNG_DOMAIN_PYTHON;
+ }
+
uchan->enabled = 1;
if (trace_ust_is_max_id(usess->used_channel_id)) {
ret = LTTNG_ERR_UST_CHAN_FAIL;
memset(&uevent, 0, sizeof(uevent));
uevent.type = LTTNG_EVENT_TRACEPOINT;
uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
- default_event_name = event_get_default_agent_ust_name(domain->type);
+ default_event_name = event_get_default_agent_ust_name(
+ domain->type);
if (!default_event_name) {
ret = LTTNG_ERR_FATAL;
goto error;
}
{
- struct lttng_filter_bytecode *filter_copy = NULL;
char *filter_expression_copy = NULL;
+ struct lttng_filter_bytecode *filter_copy = NULL;
if (filter) {
- filter_copy = zmalloc(
- sizeof(struct lttng_filter_bytecode)
- + filter->len);
+ const size_t filter_size = sizeof(
+ struct lttng_filter_bytecode)
+ + filter->len;
+
+ filter_copy = zmalloc(filter_size);
if (!filter_copy) {
ret = LTTNG_ERR_NOMEM;
- goto error;
}
+ memcpy(filter_copy, filter, filter_size);
- memcpy(filter_copy, filter,
- sizeof(struct lttng_filter_bytecode)
- + filter->len);
- }
-
- if (filter_expression) {
filter_expression_copy =
strdup(filter_expression);
if (!filter_expression) {
ret = LTTNG_ERR_NOMEM;
- goto error_free_copy;
+ }
+
+ if (!filter_expression_copy || !filter_copy) {
+ free(filter_expression_copy);
+ free(filter_copy);
+ goto error;
}
}
(char *) default_chan_name,
&uevent, filter_expression_copy,
filter_copy, NULL, wpipe);
- filter_copy = NULL;
- filter_expression_copy = NULL;
-error_free_copy:
- free(filter_copy);
- free(filter_expression_copy);
}
if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
ret = event_agent_enable_all(usess, agt, event, filter,
filter_expression);
- filter = NULL;
} else {
ret = event_agent_enable(usess, agt, event, filter,
filter_expression);
- filter = NULL;
}
+ filter = NULL;
+ filter_expression = NULL;
if (ret != LTTNG_OK) {
goto error;
}
*/
int event_agent_enable_all(struct ltt_ust_session *usess,
struct agent *agt, struct lttng_event *event,
- struct lttng_filter_bytecode *filter,
- char *filter_expression)
+ struct lttng_filter_bytecode *filter ,char *filter_expression)
{
int ret;
struct agent_event *aevent;
assert(agt);
DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d "
- "and loglevel %d", event->name, usess->id, event->loglevel_type,
- event->loglevel);
+ ", loglevel %d and filter \"%s\"", event->name,
+ usess->id, event->loglevel_type, event->loglevel,
+ filter_expression ? filter_expression : "NULL");
aevent = agent_find_event(event->name, event->loglevel, agt);
if (!aevent) {
- aevent = agent_create_event(event->name, filter);
+ aevent = agent_create_event(event->name, event->loglevel,
+ event->loglevel_type, filter,
+ filter_expression);
if (!aevent) {
ret = LTTNG_ERR_NOMEM;
goto error;
}
- aevent->loglevel = event->loglevel;
- aevent->loglevel_type = event->loglevel_type;
created = 1;
}
#include "session.h"
#include "syscall.h"
#include "trace-ust.h"
+#include "agent.h"
static
int save_kernel_channel_attributes(struct config_writer *writer,
return ret;
}
+static
+void init_ust_event_from_agent_event(struct ltt_ust_event *ust_event,
+ struct agent_event *agent_event)
+{
+ ust_event->enabled = agent_event->enabled;
+ ust_event->attr.instrumentation = LTTNG_UST_TRACEPOINT;
+ strncpy(ust_event->attr.name, agent_event->name, LTTNG_SYMBOL_NAME_LEN);
+ ust_event->attr.loglevel_type = agent_event->loglevel_type;
+ ust_event->attr.loglevel = agent_event->loglevel;
+ ust_event->filter_expression = agent_event->filter_expression;
+ ust_event->exclusion = agent_event->exclusion;
+}
+
+static
+int save_agent_events(struct config_writer *writer,
+ struct ltt_ust_channel *chan,
+ struct agent *agent)
+{
+ int ret;
+ struct lttng_ht_iter iter;
+ struct lttng_ht_node_str *node;
+
+ ret = config_writer_open_element(writer, config_element_events);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(agent->events->ht, &iter.iter, node, node) {
+ int ret;
+ struct agent_event *agent_event;
+ struct ltt_ust_event fake_event;
+
+ memset(&fake_event, 0, sizeof(fake_event));
+ agent_event = caa_container_of(node, struct agent_event, node);
+
+ /*
+ * Initialize a fake ust event to reuse the same serialization
+ * function since UST and agent events contain the same info
+ * (and one could wonder why they don't reuse the same
+ * structures...).
+ */
+ init_ust_event_from_agent_event(&fake_event, agent_event);
+ ret = save_ust_event(writer, &fake_event);
+ if (ret) {
+ rcu_read_unlock();
+ goto end;
+ }
+ }
+ rcu_read_unlock();
+
+ /* /events */
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+end:
+ return ret;
+}
+
static
int save_kernel_context(struct config_writer *writer,
struct lttng_kernel_context *ctx)
goto end;
}
- ret = save_ust_events(writer, ust_chan->events);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
+ if (ust_chan->domain == LTTNG_DOMAIN_UST) {
+ ret = save_ust_events(writer, ust_chan->events);
+ if (ret) {
+ goto end;
+ }
+ } else {
+ struct agent *agent = NULL;
+
+ agent = trace_ust_find_agent(session, ust_chan->domain);
+ if (!agent) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ ERR("Could not find agent associated to UST subdomain");
+ goto end;
+ }
+
+ /*
+ * Channels associated with a UST sub-domain (such as JUL, Log4j
+ * or Python) don't have any non-internal events. We retrieve
+ * the "agent" events associated with this channel and serialize
+ * them.
+ */
+ ret = save_agent_events(writer, ust_chan, agent);
+ if (ret) {
+ goto end;
+ }
}
ret = save_ust_context(writer, &ust_chan->ctx_list);
}
static
-int save_ust_session(struct config_writer *writer,
- struct ltt_session *session, int save_agent)
+const char *get_config_domain_str(enum lttng_domain_type domain)
+{
+ const char *str_dom;
+
+ switch (domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ str_dom = config_domain_type_kernel;
+ break;
+ case LTTNG_DOMAIN_UST:
+ str_dom = config_domain_type_ust;
+ break;
+ case LTTNG_DOMAIN_JUL:
+ str_dom = config_domain_type_jul;
+ break;
+ case LTTNG_DOMAIN_LOG4J:
+ str_dom = config_domain_type_log4j;
+ break;
+ case LTTNG_DOMAIN_PYTHON:
+ str_dom = config_domain_type_python;
+ break;
+ default:
+ assert(0);
+ }
+
+ return str_dom;
+}
+
+static
+int save_ust_domain(struct config_writer *writer,
+ struct ltt_session *session, enum lttng_domain_type domain)
{
int ret;
struct ltt_ust_channel *ust_chan;
const char *buffer_type_string;
struct lttng_ht_node_str *node;
struct lttng_ht_iter iter;
+ const char *config_domain_name;
assert(writer);
assert(session);
- ret = config_writer_write_element_string(writer, config_element_type,
- save_agent ? config_domain_type_jul : config_domain_type_ust);
+ ret = config_writer_open_element(writer,
+ config_element_domain);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ config_domain_name = get_config_domain_str(domain);
+ if (!config_domain_name) {
+ ret = LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ ret = config_writer_write_element_string(writer,
+ config_element_type, config_domain_name);
if (ret) {
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
rcu_read_lock();
cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
&iter.iter, node, node) {
- int agent_channel;
-
ust_chan = caa_container_of(node, struct ltt_ust_channel, node);
- agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name) ||
- !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name) ||
- !strcmp(DEFAULT_PYTHON_CHANNEL_NAME, ust_chan->name);
- if (!(save_agent ^ agent_channel)) {
+ if (domain == ust_chan->domain) {
ret = save_ust_channel(writer, ust_chan, session->ust_session);
if (ret) {
rcu_read_unlock();
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
+
+ /* /domain */
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
end:
return ret;
}
}
if (session->ust_session) {
- unsigned long agent_count;
-
- ret = config_writer_open_element(writer,
- config_element_domain);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
-
- ret = save_ust_session(writer, session, 0);
+ ret = save_ust_domain(writer, session, LTTNG_DOMAIN_UST);
if (ret) {
goto end;
}
ret = config_writer_open_element(writer,
- config_element_trackers);
+ config_element_trackers);
if (ret) {
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
/* /trackers */
ret = config_writer_close_element(writer);
if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
- /* /domain */
- ret = config_writer_close_element(writer);
+
+ ret = save_ust_domain(writer, session, LTTNG_DOMAIN_JUL);
if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
- rcu_read_lock();
- agent_count =
- lttng_ht_get_count(session->ust_session->agents);
- rcu_read_unlock();
-
- if (agent_count > 0) {
- ret = config_writer_open_element(writer,
- config_element_domain);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
-
- ret = save_ust_session(writer, session, 1);
- if (ret) {
- goto end;
- }
+ ret = save_ust_domain(writer, session, LTTNG_DOMAIN_LOG4J);
+ if (ret) {
+ goto end;
+ }
- /* /domain */
- ret = config_writer_close_element(writer);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
+ ret = save_ust_domain(writer, session, LTTNG_DOMAIN_PYTHON);
+ if (ret) {
+ goto end;
}
}
*
* Return pointer to structure or NULL.
*/
-struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan)
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
+ enum lttng_domain_type domain)
{
struct ltt_ust_channel *luc;
goto error;
}
+ luc->domain = domain;
+
/* Copy UST channel attributes */
luc->attr.overwrite = chan->attr.overwrite;
luc->attr.subbuf_size = chan->attr.subbuf_size;
/* Same layout. */
lue->filter_expression = filter_expression;
- lue->filter = (struct lttng_ust_filter_bytecode *) filter;
- lue->exclusion = (struct lttng_event_exclusion *) exclusion;
+ lue->filter = filter;
+ lue->exclusion = exclusion;
/* Init node */
lttng_ht_node_init_str(&lue->node, lue->attr.name);
struct lttng_ust_event attr;
struct lttng_ht_node_str node;
char *filter_expression;
- struct lttng_ust_filter_bytecode *filter;
+ struct lttng_filter_bytecode *filter;
struct lttng_event_exclusion *exclusion;
bool internal;
};
struct ltt_ust_channel {
uint64_t id; /* unique id per session. */
unsigned int enabled;
+ /*
+ * A UST channel can be part of a userspace sub-domain such as JUL,
+ * Log4j, Python.
+ */
+ enum lttng_domain_type domain;
char name[LTTNG_UST_SYM_NAME_LEN];
struct lttng_ust_channel_attr attr;
struct lttng_ht *ctx;
* Create functions malloc() the data structure.
*/
struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
-struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr);
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
+ enum lttng_domain_type domain);
struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
char *filter_expression,
struct lttng_filter_bytecode *filter,
return NULL;
}
static inline
-struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr)
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
+ enum lttng_domain_type domain)
{
return NULL;
}
*
* Return allocated filter or NULL on error.
*/
-static struct lttng_ust_filter_bytecode *alloc_copy_ust_app_filter(
- struct lttng_ust_filter_bytecode *orig_f)
+static struct lttng_filter_bytecode *copy_filter_bytecode(
+ struct lttng_filter_bytecode *orig_f)
{
- struct lttng_ust_filter_bytecode *filter = NULL;
+ struct lttng_filter_bytecode *filter = NULL;
/* Copy filter bytecode */
filter = zmalloc(sizeof(*filter) + orig_f->len);
if (!filter) {
- PERROR("zmalloc alloc ust app filter");
+ PERROR("zmalloc alloc filter bytecode");
goto error;
}
return filter;
}
+/*
+ * Create a liblttng-ust filter bytecode from given bytecode.
+ *
+ * Return allocated filter or NULL on error.
+ */
+static struct lttng_ust_filter_bytecode *create_ust_bytecode_from_bytecode(
+ struct lttng_filter_bytecode *orig_f)
+{
+ struct lttng_ust_filter_bytecode *filter = NULL;
+
+ /* Copy filter bytecode */
+ filter = zmalloc(sizeof(*filter) + orig_f->len);
+ if (!filter) {
+ PERROR("zmalloc alloc ust filter bytecode");
+ goto error;
+ }
+
+ assert(sizeof(struct lttng_filter_bytecode) ==
+ sizeof(struct lttng_ust_filter_bytecode));
+ memcpy(filter, orig_f, sizeof(*filter) + orig_f->len);
+error:
+ return filter;
+}
+
/*
* Find an ust_app using the sock and return it. RCU read side lock must be
* held before calling this helper function.
* Return an ust_app_event object or NULL on error.
*/
static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht,
- char *name, struct lttng_ust_filter_bytecode *filter, int loglevel,
+ char *name, struct lttng_filter_bytecode *filter, int loglevel,
const struct lttng_event_exclusion *exclusion)
{
struct lttng_ht_iter iter;
key.filter = filter;
key.loglevel = loglevel;
/* lttng_event_exclusion and lttng_ust_event_exclusion structures are similar */
- key.exclusion = (struct lttng_ust_event_exclusion *)exclusion;
+ key.exclusion = exclusion;
/* Lookup using the event name as hash and a custom match fct. */
cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed),
struct ust_app *app)
{
int ret;
+ struct lttng_ust_filter_bytecode *ust_bytecode = NULL;
health_code_update();
goto error;
}
- ret = ustctl_set_filter(app->sock, ua_event->filter,
+ ust_bytecode = create_ust_bytecode_from_bytecode(ua_event->filter);
+ if (!ust_bytecode) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ ret = ustctl_set_filter(app->sock, ust_bytecode,
ua_event->obj);
if (ret < 0) {
if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
error:
health_code_update();
+ free(ust_bytecode);
return ret;
}
+static
+struct lttng_ust_event_exclusion *create_ust_exclusion_from_exclusion(
+ struct lttng_event_exclusion *exclusion)
+{
+ struct lttng_ust_event_exclusion *ust_exclusion = NULL;
+ size_t exclusion_alloc_size = sizeof(struct lttng_ust_event_exclusion) +
+ LTTNG_UST_SYM_NAME_LEN * exclusion->count;
+
+ ust_exclusion = zmalloc(exclusion_alloc_size);
+ if (!ust_exclusion) {
+ PERROR("malloc");
+ goto end;
+ }
+
+ assert(sizeof(struct lttng_event_exclusion) ==
+ sizeof(struct lttng_ust_event_exclusion));
+ memcpy(ust_exclusion, exclusion, exclusion_alloc_size);
+end:
+ return ust_exclusion;
+}
+
/*
* Set event exclusions on the tracer.
*/
struct ust_app *app)
{
int ret;
+ struct lttng_ust_event_exclusion *ust_exclusion = NULL;
health_code_update();
goto error;
}
- ret = ustctl_set_exclusion(app->sock, ua_event->exclusion,
- ua_event->obj);
+ ust_exclusion = create_ust_exclusion_from_exclusion(
+ ua_event->exclusion);
+ if (!ust_exclusion) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ ret = ustctl_set_exclusion(app->sock, ust_exclusion, ua_event->obj);
if (ret < 0) {
if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
ERR("UST app event %s exclusions failed for app (pid: %d) "
error:
health_code_update();
+ free(ust_exclusion);
return ret;
}
/* Copy filter bytecode */
if (uevent->filter) {
- ua_event->filter = alloc_copy_ust_app_filter(uevent->filter);
+ ua_event->filter = copy_filter_bytecode(uevent->filter);
/* Filter might be NULL here in case of ENONEM. */
}
/* Copy exclusion data */
if (uevent->exclusion) {
- exclusion_alloc_size = sizeof(struct lttng_ust_event_exclusion) +
+ exclusion_alloc_size = sizeof(struct lttng_event_exclusion) +
LTTNG_UST_SYM_NAME_LEN * uevent->exclusion->count;
ua_event->exclusion = zmalloc(exclusion_alloc_size);
if (ua_event->exclusion == NULL) {
struct ust_app_ht_key {
const char *name;
- const struct lttng_ust_filter_bytecode *filter;
+ const struct lttng_filter_bytecode *filter;
enum lttng_ust_loglevel_type loglevel;
- const struct lttng_ust_event_exclusion *exclusion;
+ const struct lttng_event_exclusion *exclusion;
};
/*
struct lttng_ust_event attr;
char name[LTTNG_UST_SYM_NAME_LEN];
struct lttng_ht_node_str node;
- struct lttng_ust_filter_bytecode *filter;
- struct lttng_ust_event_exclusion *exclusion;
+ struct lttng_filter_bytecode *filter;
+ struct lttng_event_exclusion *exclusion;
};
struct ust_app_stream {
strncpy(attr.name, "channel0", 8);
- uchan = trace_ust_create_channel(&attr);
+ uchan = trace_ust_create_channel(&attr, LTTNG_DOMAIN_UST);
ok(uchan != NULL, "Create UST channel");
ok(uchan->enabled == 0 &&