#include "lttng-tracer.h"
#include "lttng-tracer-core.h"
#include "lttng-ust-statedump.h"
+#include "ust-events-internal.h"
#include "wait.h"
#include "../libringbuffer/shm.h"
#include "jhash.h"
static void _lttng_enum_destroy(struct lttng_enum *_enum);
static
-void lttng_session_lazy_sync_enablers(struct lttng_session *session);
+void lttng_session_lazy_sync_event_enablers(struct lttng_session *session);
static
-void lttng_session_sync_enablers(struct lttng_session *session);
+void lttng_session_sync_event_enablers(struct lttng_session *session);
static
void lttng_enabler_destroy(struct lttng_enabler *enabler);
struct lttng_channel *chan, *tmpchan;
struct lttng_event *event, *tmpevent;
struct lttng_enum *_enum, *tmp_enum;
- struct lttng_enabler *enabler, *tmpenabler;
+ struct lttng_event_enabler *event_enabler, *event_tmpenabler;
CMM_ACCESS_ONCE(session->active) = 0;
cds_list_for_each_entry(event, &session->events_head, node) {
}
synchronize_trace(); /* Wait for in-flight events to complete */
__tracepoint_probe_prune_release_queue();
- cds_list_for_each_entry_safe(enabler, tmpenabler,
+ cds_list_for_each_entry_safe(event_enabler, event_tmpenabler,
&session->enablers_head, node)
- lttng_enabler_destroy(enabler);
+ lttng_event_enabler_destroy(event_enabler);
cds_list_for_each_entry_safe(event, tmpevent,
&session->events_head, node)
_lttng_event_destroy(event);
free(session);
}
+static
+void lttng_enabler_destroy(struct lttng_enabler *enabler)
+{
+ struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node;
+ struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node;
+
+ if (!enabler) {
+ return;
+ }
+
+ /* Destroy filter bytecode */
+ cds_list_for_each_entry_safe(filter_node, tmp_filter_node,
+ &enabler->filter_bytecode_head, node) {
+ free(filter_node);
+ }
+
+ /* Destroy excluders */
+ cds_list_for_each_entry_safe(excluder_node, tmp_excluder_node,
+ &enabler->excluder_head, node) {
+ free(excluder_node);
+ }
+}
+
static
int lttng_enum_create(const struct lttng_enum_desc *desc,
struct lttng_session *session)
session->tstate = 1;
/* We need to sync enablers with session before activation. */
- lttng_session_sync_enablers(session);
+ lttng_session_sync_event_enablers(session);
/*
* Snapshot the number of events per channel to know the type of header
/* Set transient enabler state to "disabled" */
session->tstate = 0;
- lttng_session_sync_enablers(session);
+ lttng_session_sync_event_enablers(session);
end:
return ret;
}
}
/* Set transient enabler state to "enabled" */
channel->tstate = 1;
- lttng_session_sync_enablers(channel->session);
+ lttng_session_sync_event_enablers(channel->session);
/* Set atomically the state to "enabled" */
CMM_ACCESS_ONCE(channel->enabled) = 1;
end:
CMM_ACCESS_ONCE(channel->enabled) = 0;
/* Set transient enabler state to "enabled" */
channel->tstate = 0;
- lttng_session_sync_enablers(channel->session);
+ lttng_session_sync_event_enablers(channel->session);
end:
return ret;
}
}
static
-int lttng_event_match_enabler(struct lttng_event *event,
- struct lttng_enabler *enabler)
+int lttng_event_enabler_match_event(struct lttng_event_enabler *event_enabler,
+ struct lttng_event *event)
{
- if (lttng_desc_match_enabler(event->desc, enabler)
- && event->chan == enabler->chan)
+ if (lttng_desc_match_enabler(event->desc,
+ lttng_event_enabler_as_enabler(event_enabler))
+ && event->chan == event_enabler->chan)
return 1;
else
return 0;
}
static
-struct lttng_enabler_ref * lttng_event_enabler_ref(struct lttng_event *event,
+struct lttng_enabler_ref *lttng_enabler_ref(
+ struct cds_list_head *enabler_ref_list,
struct lttng_enabler *enabler)
{
struct lttng_enabler_ref *enabler_ref;
- cds_list_for_each_entry(enabler_ref,
- &event->enablers_ref_head, node) {
+ cds_list_for_each_entry(enabler_ref, enabler_ref_list, node) {
if (enabler_ref->ref == enabler)
return enabler_ref;
}
* tracepoint probes.
*/
static
-void lttng_create_event_if_missing(struct lttng_enabler *enabler)
+void lttng_create_event_if_missing(struct lttng_event_enabler *event_enabler)
{
- struct lttng_session *session = enabler->chan->session;
+ struct lttng_session *session = event_enabler->chan->session;
struct lttng_probe_desc *probe_desc;
const struct lttng_event_desc *desc;
struct lttng_event *event;
uint32_t hash;
desc = probe_desc->event_desc[i];
- if (!lttng_desc_match_enabler(desc, enabler))
+ if (!lttng_desc_match_enabler(desc,
+ lttng_event_enabler_as_enabler(event_enabler)))
continue;
event_name = desc->name;
name_len = strlen(event_name);
head = &session->events_ht.table[hash & (LTTNG_UST_EVENT_HT_SIZE - 1)];
cds_hlist_for_each_entry(event, node, head, hlist) {
if (event->desc == desc
- && event->chan == enabler->chan) {
+ && event->chan == event_enabler->chan) {
found = true;
break;
}
* event probe.
*/
ret = lttng_event_create(probe_desc->event_desc[i],
- enabler->chan);
+ event_enabler->chan);
if (ret) {
DBG("Unable to create event %s, error %d\n",
probe_desc->event_desc[i]->name, ret);
* and add backward reference from the event to the enabler.
*/
static
-int lttng_enabler_ref_events(struct lttng_enabler *enabler)
+int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler)
{
- struct lttng_session *session = enabler->chan->session;
+ struct lttng_session *session = event_enabler->chan->session;
struct lttng_event *event;
- if (!enabler->enabled)
+ if (!lttng_event_enabler_as_enabler(event_enabler)->enabled)
goto end;
/* First ensure that probe events are created for this enabler. */
- lttng_create_event_if_missing(enabler);
+ lttng_create_event_if_missing(event_enabler);
/* For each event matching enabler in session event list. */
cds_list_for_each_entry(event, &session->events_head, node) {
struct lttng_enabler_ref *enabler_ref;
- if (!lttng_event_match_enabler(event, enabler))
+ if (!lttng_event_enabler_match_event(event_enabler, event))
continue;
- enabler_ref = lttng_event_enabler_ref(event, enabler);
+ enabler_ref = lttng_enabler_ref(&event->enablers_ref_head,
+ lttng_event_enabler_as_enabler(event_enabler));
if (!enabler_ref) {
/*
* If no backward ref, create it.
enabler_ref = zmalloc(sizeof(*enabler_ref));
if (!enabler_ref)
return -ENOMEM;
- enabler_ref->ref = enabler;
+ enabler_ref->ref = lttng_event_enabler_as_enabler(
+ event_enabler);
cds_list_add(&enabler_ref->node,
&event->enablers_ref_head);
}
/*
* Link filter bytecodes if not linked yet.
*/
- lttng_enabler_event_link_bytecode(event, enabler);
+ lttng_event_enabler_link_bytecode(event, event_enabler);
/* TODO: merge event context. */
}
struct lttng_session *session;
cds_list_for_each_entry(session, &sessions, node) {
- lttng_session_lazy_sync_enablers(session);
+ lttng_session_lazy_sync_event_enablers(session);
}
return 0;
}
/*
* Enabler management.
*/
-struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_format_type format_type,
+struct lttng_event_enabler *lttng_event_enabler_create(
+ enum lttng_enabler_format_type format_type,
struct lttng_ust_event *event_param,
struct lttng_channel *chan)
{
- struct lttng_enabler *enabler;
+ struct lttng_event_enabler *event_enabler;
- enabler = zmalloc(sizeof(*enabler));
- if (!enabler)
+ event_enabler = zmalloc(sizeof(*event_enabler));
+ if (!event_enabler)
return NULL;
- enabler->format_type = format_type;
- CDS_INIT_LIST_HEAD(&enabler->filter_bytecode_head);
- CDS_INIT_LIST_HEAD(&enabler->excluder_head);
- memcpy(&enabler->event_param, event_param,
- sizeof(enabler->event_param));
- enabler->chan = chan;
+ event_enabler->base.format_type = format_type;
+ CDS_INIT_LIST_HEAD(&event_enabler->base.filter_bytecode_head);
+ CDS_INIT_LIST_HEAD(&event_enabler->base.excluder_head);
+ memcpy(&event_enabler->base.event_param, event_param,
+ sizeof(event_enabler->base.event_param));
+ event_enabler->chan = chan;
/* ctx left NULL */
- enabler->enabled = 0;
- cds_list_add(&enabler->node, &enabler->chan->session->enablers_head);
- lttng_session_lazy_sync_enablers(enabler->chan->session);
- return enabler;
+ event_enabler->base.enabled = 0;
+ cds_list_add(&event_enabler->node, &event_enabler->chan->session->enablers_head);
+ lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
+
+ return event_enabler;
}
-int lttng_enabler_enable(struct lttng_enabler *enabler)
+int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler)
{
- enabler->enabled = 1;
- lttng_session_lazy_sync_enablers(enabler->chan->session);
+ lttng_event_enabler_as_enabler(event_enabler)->enabled = 1;
+ lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
+
return 0;
}
-int lttng_enabler_disable(struct lttng_enabler *enabler)
+int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler)
{
- enabler->enabled = 0;
- lttng_session_lazy_sync_enablers(enabler->chan->session);
+ lttng_event_enabler_as_enabler(event_enabler)->enabled = 0;
+ lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
+
return 0;
}
-int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
+static
+void _lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
struct lttng_ust_filter_bytecode_node *bytecode)
{
bytecode->enabler = enabler;
cds_list_add_tail(&bytecode->node, &enabler->filter_bytecode_head);
- lttng_session_lazy_sync_enablers(enabler->chan->session);
+}
+
+int lttng_event_enabler_attach_bytecode(struct lttng_event_enabler *event_enabler,
+ struct lttng_ust_filter_bytecode_node *bytecode)
+{
+ _lttng_enabler_attach_bytecode(
+ lttng_event_enabler_as_enabler(event_enabler), bytecode);
+
+ lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
return 0;
}
-int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
+static
+void _lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
struct lttng_ust_excluder_node *excluder)
{
excluder->enabler = enabler;
cds_list_add_tail(&excluder->node, &enabler->excluder_head);
- lttng_session_lazy_sync_enablers(enabler->chan->session);
+}
+
+int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabler,
+ struct lttng_ust_excluder_node *excluder)
+{
+ _lttng_enabler_attach_exclusion(
+ lttng_event_enabler_as_enabler(event_enabler), excluder);
+
+ lttng_session_lazy_sync_event_enablers(event_enabler->chan->session);
return 0;
}
}
}
-int lttng_enabler_attach_context(struct lttng_enabler *enabler,
+int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
struct lttng_ust_context *context_param)
{
-#if 0 // disabled for now.
- struct lttng_session *session = enabler->chan->session;
- int ret;
-
- ret = lttng_attach_context(context_param, &enabler->ctx,
- session);
- if (ret)
- return ret;
- lttng_session_lazy_sync_enablers(enabler->chan->session);
-#endif
return -ENOSYS;
}
-static
-void lttng_enabler_destroy(struct lttng_enabler *enabler)
+void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler)
{
- struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node;
- struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node;
-
- /* Destroy filter bytecode */
- cds_list_for_each_entry_safe(filter_node, tmp_filter_node,
- &enabler->filter_bytecode_head, node) {
- free(filter_node);
- }
-
- /* Destroy excluders */
- cds_list_for_each_entry_safe(excluder_node, tmp_excluder_node,
- &enabler->excluder_head, node) {
- free(excluder_node);
+ if (!event_enabler) {
+ return;
}
+ cds_list_del(&event_enabler->node);
- /* Destroy contexts */
- lttng_destroy_context(enabler->ctx);
+ lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler));
- cds_list_del(&enabler->node);
- free(enabler);
+ lttng_destroy_context(event_enabler->ctx);
+ free(event_enabler);
}
/*
- * lttng_session_sync_enablers should be called just before starting a
+ * lttng_session_sync_event_enablers should be called just before starting a
* session.
*/
static
-void lttng_session_sync_enablers(struct lttng_session *session)
+void lttng_session_sync_event_enablers(struct lttng_session *session)
{
- struct lttng_enabler *enabler;
+ struct lttng_event_enabler *event_enabler;
struct lttng_event *event;
- cds_list_for_each_entry(enabler, &session->enablers_head, node)
- lttng_enabler_ref_events(enabler);
+ cds_list_for_each_entry(event_enabler, &session->enablers_head, node)
+ lttng_event_enabler_ref_events(event_enabler);
/*
* For each event, if at least one of its enablers is enabled,
* and its channel and session transient states are enabled, we
* "lazy" sync means we only sync if required.
*/
static
-void lttng_session_lazy_sync_enablers(struct lttng_session *session)
+void lttng_session_lazy_sync_event_enablers(struct lttng_session *session)
{
/* We can skip if session is not active */
if (!session->active)
return;
- lttng_session_sync_enablers(session);
+ lttng_session_sync_event_enablers(session);
}
/*
#include "../libringbuffer/shm.h"
#include "lttng-tracer.h"
#include "string-utils.h"
+#include "ust-events-internal.h"
#define OBJ_NAME_LEN 16
static const struct lttng_ust_objd_ops lttng_ops;
static const struct lttng_ust_objd_ops lttng_session_ops;
static const struct lttng_ust_objd_ops lttng_channel_ops;
-static const struct lttng_ust_objd_ops lttng_enabler_ops;
+static const struct lttng_ust_objd_ops lttng_event_enabler_ops;
static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops;
static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops;
}
static
-int lttng_abi_create_enabler(int channel_objd,
+int lttng_abi_create_event_enabler(int channel_objd,
struct lttng_ust_event *event_param,
void *owner,
enum lttng_enabler_format_type format_type)
{
struct lttng_channel *channel = objd_private(channel_objd);
- struct lttng_enabler *enabler;
+ struct lttng_event_enabler *enabler;
int event_objd, ret;
event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
- event_objd = objd_alloc(NULL, <tng_enabler_ops, owner, "enabler");
+ event_objd = objd_alloc(NULL, <tng_event_enabler_ops, owner,
+ "event enabler");
if (event_objd < 0) {
ret = event_objd;
goto objd_error;
* We tolerate no failure path after event creation. It will stay
* invariant for the rest of the session.
*/
- enabler = lttng_enabler_create(format_type, event_param, channel);
+ enabler = lttng_event_enabler_create(format_type, event_param, channel);
if (!enabler) {
ret = -ENOMEM;
goto event_error;
* If the event name is a star globbing pattern,
* we create the special star globbing enabler.
*/
- return lttng_abi_create_enabler(objd, event_param,
+ return lttng_abi_create_event_enabler(objd, event_param,
owner, LTTNG_ENABLER_FORMAT_STAR_GLOB);
} else {
- return lttng_abi_create_enabler(objd, event_param,
+ return lttng_abi_create_event_enabler(objd, event_param,
owner, LTTNG_ENABLER_FORMAT_EVENT);
}
}
* Attach exclusions to an enabler.
*/
static
-long lttng_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
+long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
union ust_args *uargs, void *owner)
{
- struct lttng_enabler *enabler = objd_private(objd);
+ struct lttng_event_enabler *enabler = objd_private(objd);
switch (cmd) {
case LTTNG_UST_CONTEXT:
- return lttng_enabler_attach_context(enabler,
+ return lttng_event_enabler_attach_context(enabler,
(struct lttng_ust_context *) arg);
case LTTNG_UST_ENABLE:
- return lttng_enabler_enable(enabler);
+ return lttng_event_enabler_enable(enabler);
case LTTNG_UST_DISABLE:
- return lttng_enabler_disable(enabler);
+ return lttng_event_enabler_disable(enabler);
case LTTNG_UST_FILTER:
{
int ret;
- ret = lttng_enabler_attach_bytecode(enabler,
+ ret = lttng_event_enabler_attach_bytecode(enabler,
(struct lttng_ust_filter_bytecode_node *) arg);
if (ret)
return ret;
}
case LTTNG_UST_EXCLUSION:
{
- return lttng_enabler_attach_exclusion(enabler,
+ return lttng_event_enabler_attach_exclusion(enabler,
(struct lttng_ust_excluder_node *) arg);
}
default:
}
static
-int lttng_enabler_release(int objd)
+int lttng_event_enabler_release(int objd)
{
- struct lttng_enabler *enabler = objd_private(objd);
+ struct lttng_event_enabler *event_enabler = objd_private(objd);
+
+ if (event_enabler)
+ return lttng_ust_objd_unref(event_enabler->chan->objd, 0);
- if (enabler)
- return lttng_ust_objd_unref(enabler->chan->objd, 0);
return 0;
}
-static const struct lttng_ust_objd_ops lttng_enabler_ops = {
- .release = lttng_enabler_release,
- .cmd = lttng_enabler_cmd,
+static const struct lttng_ust_objd_ops lttng_event_enabler_ops = {
+ .release = lttng_event_enabler_release,
+ .cmd = lttng_event_enabler_cmd,
};
void lttng_ust_abi_exit(void)
--- /dev/null
+#ifndef _LTTNG_UST_EVENTS_INTERNAL_H
+#define _LTTNG_UST_EVENTS_INTERNAL_H
+
+/*
+ * ust-events-internal.h
+ *
+ * Copyright 2019 (c) - Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+
+#include <urcu/list.h>
+#include <urcu/hlist.h>
+
+#include <helper.h>
+#include <lttng/ust-events.h>
+
+struct lttng_event_enabler {
+ struct lttng_enabler base;
+ struct cds_list_head node; /* per-session list of enablers */
+ struct lttng_channel *chan;
+ /*
+ * Unused, but kept around to make it explicit that the tracer can do
+ * it.
+ */
+ struct lttng_ctx *ctx;
+};
+
+static inline
+struct lttng_enabler *lttng_event_enabler_as_enabler(
+ struct lttng_event_enabler *event_enabler)
+{
+ return &event_enabler->base;
+}
+
+
+/*
+ * Allocate and initialize a `struct lttng_event_enabler` object.
+ *
+ * On success, returns a `struct lttng_event_enabler`,
+ * On memory error, returns NULL.
+ */
+LTTNG_HIDDEN
+struct lttng_event_enabler *lttng_event_enabler_create(
+ enum lttng_enabler_format_type format_type,
+ struct lttng_ust_event *event_param,
+ struct lttng_channel *chan);
+
+/*
+ * Destroy a `struct lttng_event_enabler` object.
+ */
+LTTNG_HIDDEN
+void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
+
+/*
+ * Enable a `struct lttng_event_enabler` object and all events related to this
+ * enabler.
+ */
+LTTNG_HIDDEN
+int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
+
+/*
+ * Disable a `struct lttng_event_enabler` object and all events related to this
+ * enabler.
+ */
+LTTNG_HIDDEN
+int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
+
+/*
+ * Attach filter bytecode program to `struct lttng_event_enabler` and all
+ * events related to this enabler.
+ */
+LTTNG_HIDDEN
+int lttng_event_enabler_attach_bytecode(struct lttng_event_enabler *enabler,
+ struct lttng_ust_filter_bytecode_node *bytecode);
+
+/*
+ * Attach an application context to an event enabler.
+ *
+ * Not implemented.
+ */
+LTTNG_HIDDEN
+int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
+ struct lttng_ust_context *ctx);
+
+/*
+ * Attach exclusion list to `struct lttng_event_enabler` and all
+ * events related to this enabler.
+ */
+LTTNG_HIDDEN
+int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
+ struct lttng_ust_excluder_node *excluder);
+
+/*
+ * Synchronize bytecodes for the enabler and the event.
+ *
+ * This function goes over all bytecode programs of the event enabler to ensure
+ * each is linked to the provided event.
+ */
+LTTNG_HIDDEN
+void lttng_event_enabler_link_bytecode(struct lttng_event *event,
+ struct lttng_event_enabler *enabler);
+
+#endif /* _LTTNG_UST_EVENTS_INTERNAL_H */