#include "trace-kernel.h"
#include "trace-ust.h"
+static void add_unique_ust_event(struct lttng_ht *ht,
+ struct ltt_ust_event *event)
+{
+ struct cds_lfht_node *node_ptr;
+ struct ltt_ust_ht_key key;
+
+ assert(ht);
+ assert(ht->ht);
+ assert(event);
+
+ key.name = event->attr.name;
+ key.filter = (struct lttng_filter_bytecode *) event->filter;
+ key.loglevel = event->attr.loglevel;
+
+ node_ptr = cds_lfht_add_unique(ht->ht,
+ ht->hash_fct(event->node.key, lttng_ht_seed),
+ trace_ust_ht_match_event, &key, &event->node.node);
+ assert(node_ptr == &event->node.node);
+}
+
/*
* Setup a lttng_event used to enable *all* syscall tracing.
*/
* Check if event exist and if so, continue since it was enable
* previously.
*/
- uevent = trace_ust_find_event_by_name(uchan->events,
- events[i].name);
+ uevent = trace_ust_find_event(uchan->events, events[i].name, NULL,
+ events[i].loglevel);
if (uevent != NULL) {
ret = ust_app_enable_event_pid(usess, uchan, uevent,
events[i].pid);
uevent->enabled = 1;
/* Add ltt ust event to channel */
rcu_read_lock();
- lttng_ht_add_unique_str(uchan->events, &uevent->node);
+ add_unique_ust_event(uchan->events, uevent);
rcu_read_unlock();
}
int ret = LTTNG_OK, to_create = 0;
struct ltt_ust_event *uevent;
- uevent = trace_ust_find_event_by_name(uchan->events, event->name);
+ DBG3("Enable ust: %s l:%d f:%p", event->name, event->loglevel, NULL);
+
+ rcu_read_lock();
+
+ uevent = trace_ust_find_event(uchan->events, event->name, NULL,
+ event->loglevel);
if (uevent == NULL) {
uevent = trace_ust_create_event(event);
if (uevent == NULL) {
}
if (to_create) {
- rcu_read_lock();
/* Add ltt ust event to channel */
- lttng_ht_add_unique_str(uchan->events, &uevent->node);
- rcu_read_unlock();
+ add_unique_ust_event(uchan->events, uevent);
}
DBG("Event UST %s %s in channel %s", uevent->attr.name,
ret = LTTNG_OK;
end:
+ rcu_read_unlock();
return ret;
error:
/* In this code path, the uevent was not added to the hash table */
trace_ust_destroy_event(uevent);
}
+ rcu_read_unlock();
return ret;
}
{
int ret;
struct ltt_ust_event *uevent;
+ struct lttng_ht_node_str *node;
+ struct lttng_ht_iter iter;
+ void *orig_match_fct;
+ struct lttng_ht *ht;
- uevent = trace_ust_find_event_by_name(uchan->events, event_name);
- if (uevent == NULL) {
+ ht = uchan->events;
+
+ /* Save match function so we can use the event by name match. */
+ orig_match_fct = (void *) ht->match_fct;
+ ht->match_fct = trace_ust_ht_match_event_by_name;
+
+ rcu_read_lock();
+ lttng_ht_lookup(ht, (void *) event_name, &iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+ if (node == NULL) {
+ DBG2("Trace UST event NOT found by name %s", event_name);
ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
goto error;
}
- if (uevent->enabled == 0) {
- /* It's already enabled so everything is OK */
- ret = LTTNG_OK;
- goto end;
- }
-
- switch (domain) {
- case LTTNG_DOMAIN_UST:
- ret = ust_app_disable_event_glb(usess, uchan, uevent);
- if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
- ret = LTTNG_ERR_UST_DISABLE_FAIL;
- goto error;
+ do {
+ uevent = caa_container_of(node, struct ltt_ust_event, node);
+ if (uevent->enabled == 0) {
+ /* It's already disabled so everything is OK */
+ ret = LTTNG_OK;
+ continue;
}
- break;
+
+ switch (domain) {
+ case LTTNG_DOMAIN_UST:
+ ret = ust_app_disable_event_glb(usess, uchan, uevent);
+ if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
+ ret = LTTNG_ERR_UST_DISABLE_FAIL;
+ goto error;
+ }
+ break;
#if 0
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+ case LTTNG_DOMAIN_UST_EXEC_NAME:
+ case LTTNG_DOMAIN_UST_PID:
+ case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
#endif
- default:
- ret = LTTNG_ERR_UND;
- goto error;
- }
+ default:
+ ret = LTTNG_ERR_UND;
+ goto error;
+ }
+
+ uevent->enabled = 0;
+
+ /* Get next duplicate event by name. */
+ cds_lfht_next_duplicate(ht->ht, trace_ust_ht_match_event_by_name,
+ event_name, &iter.iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+ } while (node);
- uevent->enabled = 0;
ret = LTTNG_OK;
-end:
DBG2("Event UST %s disabled in channel %s", uevent->attr.name,
uchan->name);
-
error:
+ ht->match_fct = orig_match_fct;
+ rcu_read_unlock();
return ret;
}
}
for (i = 0; i < size; i++) {
- uevent = trace_ust_find_event_by_name(uchan->events,
+ ret = event_ust_disable_tracepoint(usess, domain, uchan,
events[i].name);
- if (uevent != NULL && uevent->enabled == 1) {
- ret = ust_app_disable_event_pid(usess, uchan, uevent,
- events[i].pid);
- if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) {
- ret = LTTNG_ERR_UST_DISABLE_FAIL;
- goto error;
- }
- uevent->enabled = 0;
+ if (ret != LTTNG_OK) {
+ /* Continue to disable the rest... */
continue;
}
}
/* If UST channel specified and event name, get UST event ref */
if (uchan && have_event) {
- uevent = trace_ust_find_event_by_name(uchan->events, event->name);
+ uevent = trace_ust_find_event(uchan->events, event->name, bytecode,
+ event->loglevel);
if (uevent == NULL) {
ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
goto error;
} else if (!uchan && have_event) { /* Add filter to event */
/* Add context to event without having the channel name */
cds_lfht_for_each_entry(chan_ht->ht, &iter.iter, uchan, node.node) {
- uevent = trace_ust_find_event_by_name(uchan->events, event->name);
+ uevent = trace_ust_find_event(uchan->events, event->name, bytecode,
+ event->loglevel);
if (uevent != NULL) {
ret = add_ufilter_to_event(usess, domain, uchan, uevent, bytecode);
/*
#include "trace-ust.h"
+int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
+ const void *_key)
+{
+ struct ltt_ust_event *event;
+ const char *name;
+
+ assert(node);
+ assert(_key);
+
+ event = caa_container_of(node, struct ltt_ust_event, node.node);
+ name = _key;
+
+ /* Event name */
+ if (strncmp(event->attr.name, name, sizeof(event->attr.name)) != 0) {
+ goto no_match;
+ }
+
+ /* Match. */
+ return 1;
+
+no_match:
+ return 0;
+}
+
+int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key)
+{
+ struct ltt_ust_event *event;
+ const struct ltt_ust_ht_key *key;
+
+ assert(node);
+ assert(_key);
+
+ event = caa_container_of(node, struct ltt_ust_event, node.node);
+ key = _key;
+
+ /* Match the 3 elements of the key: name, filter and loglevel. */
+
+ /* Event name */
+ if (strncmp(event->attr.name, key->name, sizeof(event->attr.name)) != 0) {
+ DBG3("[Match] name failed: %s and %s",
+ event->attr.name, key->name);
+ goto no_match;
+ }
+
+ /* Event loglevel. */
+ if (event->attr.loglevel != key->loglevel) {
+ if (event->attr.loglevel_type == 0 && key->loglevel == 0 &&
+ event->attr.loglevel == -1) {
+ /*
+ * This is because on event creation, the loglevel is set to -1 if
+ * the event loglevel type is ALL so 0 and -1 are accepted for this
+ * loglevel type.
+ */
+ } else {
+ DBG3("[Match] loglevel failed: %d and %d",
+ event->attr.loglevel, key->loglevel);
+ goto no_match;
+ }
+ }
+
+ /* Only one of the filters is NULL, fail. */
+ if ((key->filter && !event->filter) || (!key->filter && event->filter)) {
+ DBG3("[Match] filters failed: k:%p and e:%p",
+ key->filter, event->filter);
+ goto no_match;
+ }
+
+ /* Both filters are NULL, success. */
+ if (!key->filter && !event->filter) {
+ goto match;
+ }
+
+ /* Both filters exists, check length followed by the bytecode. */
+ if (event->filter->len == key->filter->len &&
+ memcmp(event->filter->data, key->filter->data,
+ event->filter->len) == 0) {
+ goto match;
+ }
+
+ DBG3("[Match] filters failed: k:%p and e:%p",
+ key->filter, event->filter);
+
+no_match:
+ return 0;
+
+match:
+ DBG3("[MATCH] %s", key->name);
+ return 1;
+}
+
/*
* Find the channel in the hashtable.
*/
/*
* Find the event in the hashtable.
*/
-struct ltt_ust_event *trace_ust_find_event_by_name(struct lttng_ht *ht,
- char *name)
+struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
+ char *name, struct lttng_filter_bytecode *filter, int loglevel)
{
struct lttng_ht_node_str *node;
struct lttng_ht_iter iter;
+ struct ltt_ust_ht_key key;
+ void *orig_match_fct;
- rcu_read_lock();
- lttng_ht_lookup(ht, (void *) name, &iter);
+ assert(name);
+ assert(ht);
+
+ key.name = name;
+ key.filter = filter;
+ key.loglevel = loglevel;
+
+ /* Save match function so we can use the ust app event match. */
+ orig_match_fct = (void *) ht->match_fct;
+ ht->match_fct = trace_ust_ht_match_event;
+
+ cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed),
+ trace_ust_ht_match_event, &key, &iter.iter);
node = lttng_ht_iter_get_node_str(&iter);
if (node == NULL) {
- rcu_read_unlock();
goto error;
}
- rcu_read_unlock();
- DBG2("Trace UST event found by name %s", name);
+ DBG2("Trace UST event %s found", key.name);
return caa_container_of(node, struct ltt_ust_event, node);
error:
- DBG2("Trace UST event NOT found by name %s", name);
+ DBG2("Trace UST event %s NOT found", key.name);
+ /* Put back original match function. */
+ ht->match_fct = orig_match_fct;
return NULL;
}
#include "consumer.h"
#include "ust-ctl.h"
+struct ltt_ust_ht_key {
+ const char *name;
+ const struct lttng_filter_bytecode *filter;
+ enum lttng_ust_loglevel_type loglevel;
+};
+
/* UST Stream list */
struct ltt_ust_stream_list {
unsigned int count;
#ifdef HAVE_LIBLTTNG_UST_CTL
+int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
+int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
+ const void *_key);
+
/*
* Lookup functions. NULL is returned if not found.
*/
-struct ltt_ust_event *trace_ust_find_event_by_name(struct lttng_ht *ht,
- char *name);
+struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
+ char *name, struct lttng_filter_bytecode *filter, int loglevel);
struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
char *name);
#else /* HAVE_LIBLTTNG_UST_CTL */
-static inline
-struct ltt_ust_event *trace_ust_find_event_by_name(struct lttng_ht *ht,
- char *name)
-{
- return NULL;
-}
-
static inline
struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
char *name)
#include "ust-consumer.h"
#include "ust-ctl.h"
+static int ht_match_ust_app_event(struct cds_lfht_node *node, const void *_key)
+{
+ struct ust_app_event *event;
+ const struct ust_app_ht_key *key;
+
+ assert(node);
+ assert(_key);
+
+ event = caa_container_of(node, struct ust_app_event, node.node);
+ key = _key;
+
+ /* Match the 3 elements of the key: name, filter and loglevel. */
+
+ /* Event name */
+ if (strncmp(event->attr.name, key->name, sizeof(event->attr.name)) != 0) {
+ goto no_match;
+ }
+
+ /* Event loglevel. */
+ if (event->attr.loglevel != key->loglevel) {
+ goto no_match;
+ }
+
+ /* One of the filters is NULL, fail. */
+ if ((key->filter && !event->filter) || (!key->filter && event->filter)) {
+ goto no_match;
+ }
+
+ /* Both filters are NULL, success. */
+ if (!key->filter && !event->filter) {
+ goto match;
+ }
+
+ /* Both filters exists, check length followed by the bytecode. */
+ if (event->filter->len == key->filter->len &&
+ memcmp(event->filter->data, key->filter->data,
+ event->filter->len) == 0) {
+ goto match;
+ }
+
+match:
+ return 1;
+
+no_match:
+ return 0;
+
+}
+
+static void add_unique_ust_app_event(struct lttng_ht *ht,
+ struct ust_app_event *event)
+{
+ struct cds_lfht_node *node_ptr;
+ struct ust_app_ht_key key;
+
+ assert(ht);
+ assert(ht->ht);
+ assert(event);
+
+ key.name = event->attr.name;
+ key.filter = event->filter;
+ key.loglevel = event->attr.loglevel;
+
+ node_ptr = cds_lfht_add_unique(ht->ht,
+ ht->hash_fct(event->node.key, lttng_ht_seed),
+ ht_match_ust_app_event, &key, &event->node.node);
+ assert(node_ptr == &event->node.node);
+}
+
/*
* Delete ust context safely. RCU read lock must be held before calling
* this function.
return NULL;
}
+static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht,
+ char *name, struct lttng_ust_filter_bytecode *filter, int loglevel)
+{
+ struct lttng_ht_iter iter;
+ struct lttng_ht_node_str *node;
+ struct ust_app_event *event = NULL;
+ struct ust_app_ht_key key;
+ void *orig_match_fct;
+
+ assert(name);
+ assert(ht);
+
+ /* Setup key for event lookup. */
+ key.name = name;
+ key.filter = filter;
+ key.loglevel = loglevel;
+
+ /* Save match function so we can use the ust app event match. */
+ orig_match_fct = (void *) ht->match_fct;
+ ht->match_fct = ht_match_ust_app_event;
+
+ lttng_ht_lookup(ht, (void *) &key, &iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+ if (node == NULL) {
+ goto end;
+ }
+
+ event = caa_container_of(node, struct ust_app_event, node);
+
+end:
+ /* Put back original match function. */
+ ht->match_fct = orig_match_fct;
+ return event;
+}
+
/*
* Create the channel context on the tracer.
*/
struct ltt_ust_channel *uchan)
{
struct lttng_ht_iter iter;
- struct lttng_ht_node_str *ua_event_node;
struct ltt_ust_event *uevent;
struct ltt_ust_context *uctx;
struct ust_app_event *ua_event;
/* Copy all events from ltt ust channel to ust app channel */
cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) {
- struct lttng_ht_iter uiter;
-
- lttng_ht_lookup(ua_chan->events, (void *) uevent->attr.name, &uiter);
- ua_event_node = lttng_ht_iter_get_node_str(&uiter);
- if (ua_event_node == NULL) {
+ ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
+ uevent->filter, uevent->attr.loglevel);
+ if (ua_event == NULL) {
DBG2("UST event %s not found on shadow copy channel",
uevent->attr.name);
ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr);
continue;
}
shadow_copy_event(ua_event, uevent);
- lttng_ht_add_unique_str(ua_chan->events, &ua_event->node);
+ add_unique_ust_app_event(ua_chan->events, ua_event);
}
}
struct ust_app *app)
{
int ret = 0;
- struct lttng_ht_iter iter;
- struct lttng_ht_node_str *ua_event_node;
struct ust_app_event *ua_event;
/* Get event node */
- lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &iter);
- ua_event_node = lttng_ht_iter_get_node_str(&iter);
- if (ua_event_node != NULL) {
+ ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
+ uevent->filter, uevent->attr.loglevel);
+ if (ua_event != NULL) {
ret = -EEXIST;
goto end;
}
goto error;
}
- lttng_ht_add_unique_str(ua_chan->events, &ua_event->node);
+ add_unique_ust_app_event(ua_chan->events, ua_event);
DBG2("UST app create event %s for PID %d completed", ua_event->name,
app->pid);
{
int ret = 0;
struct lttng_ht_iter iter, uiter;
- struct lttng_ht_node_str *ua_chan_node, *ua_event_node;
+ struct lttng_ht_node_str *ua_chan_node;
struct ust_app *app;
struct ust_app_session *ua_sess;
struct ust_app_channel *ua_chan;
ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
- lttng_ht_lookup(ua_chan->events, (void*)uevent->attr.name, &uiter);
- ua_event_node = lttng_ht_iter_get_node_str(&uiter);
- if (ua_event_node == NULL) {
+ /* Get event node */
+ ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
+ uevent->filter, uevent->attr.loglevel);
+ if (ua_event == NULL) {
DBG3("UST app enable event %s not found for app PID %d."
"Skipping app", uevent->attr.name, app->pid);
continue;
}
- ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
ret = enable_ust_app_event(ua_sess, ua_event, app);
if (ret < 0) {
struct lttng_filter_bytecode *bytecode)
{
int ret = 0;
- struct lttng_ht_node_str *ua_chan_node, *ua_event_node;
+ struct lttng_ht_node_str *ua_chan_node;
struct lttng_ht_iter iter, uiter;
struct ust_app_session *ua_sess;
struct ust_app_event *ua_event;
ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel,
node);
- lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &uiter);
- ua_event_node = lttng_ht_iter_get_node_str(&uiter);
- if (ua_event_node == NULL) {
+ ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
+ (struct lttng_ust_filter_bytecode *) bytecode,
+ uevent->attr.loglevel);
+ if (ua_event == NULL) {
continue;
}
- ua_event = caa_container_of(ua_event_node, struct ust_app_event,
- node);
ret = set_ust_app_event_filter(ua_sess, ua_event, bytecode, app);
if (ret < 0) {
{
int ret = 0;
struct lttng_ht_iter iter;
- struct lttng_ht_node_str *ua_chan_node, *ua_event_node;
+ struct lttng_ht_node_str *ua_chan_node;
struct ust_app *app;
struct ust_app_session *ua_sess;
struct ust_app_channel *ua_chan;
ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
- lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &iter);
- ua_event_node = lttng_ht_iter_get_node_str(&iter);
- if (ua_event_node == NULL) {
+ ua_event = find_ust_app_event(ua_chan->events, uevent->attr.name,
+ uevent->filter, uevent->attr.loglevel);
+ if (ua_event == NULL) {
ret = create_ust_app_event(ua_sess, ua_chan, uevent, app);
if (ret < 0) {
goto error;
}
} else {
- ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
-
ret = enable_ust_app_event(ua_sess, ua_event, app);
if (ret < 0) {
goto error;
extern int ust_consumerd64_fd, ust_consumerd32_fd;
+struct ust_app_ht_key {
+ const char *name;
+ const struct lttng_ust_filter_bytecode *filter;
+ enum lttng_ust_loglevel_type loglevel;
+};
+
/*
* Application registration data structure.
*/