/*
- * lttng-events.c
- *
- * Holds LTTng per-session event registry.
+ * SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; only
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Holds LTTng per-session event registry.
*/
#define _LGPL_SOURCE
#include <time.h>
#include <stdbool.h>
#include <unistd.h>
+#include <dlfcn.h>
#include <lttng/ust-endian.h>
-#include <urcu-bp.h>
#include <urcu/arch.h>
#include <urcu/compiler.h>
#include <urcu/hlist.h>
#include <lttng/ust-events.h>
#include <usterr-signal-safe.h>
-#include <helper.h>
+#include <ust-helper.h>
#include <lttng/ust-ctl.h>
#include <ust-comm.h>
#include <ust-fd.h>
-#include <lttng/ust-dynamic-type.h>
-#include <lttng/ust-context-provider.h>
+#include <ust-dynamic-type.h>
+#include <ust-context-provider.h>
#include "error.h"
#include "compat.h"
#include "lttng-ust-uuid.h"
#include "ust-events-internal.h"
#include "wait.h"
#include "../libringbuffer/shm.h"
+#include "../libcounter/counter.h"
#include "jhash.h"
#include <lttng/ust-abi.h>
static CDS_LIST_HEAD(sessions);
static CDS_LIST_HEAD(event_notifier_groups);
-struct cds_list_head *_lttng_get_sessions(void)
+struct cds_list_head *lttng_get_sessions(void)
{
return &sessions;
}
}
}
-void synchronize_trace(void)
-{
- synchronize_rcu();
-}
-
struct lttng_session *lttng_session_create(void)
{
struct lttng_session *session;
return session;
}
+struct lttng_counter *lttng_ust_counter_create(
+ const char *counter_transport_name,
+ size_t number_dimensions, const struct lttng_counter_dimension *dimensions)
+{
+ struct lttng_counter_transport *counter_transport = NULL;
+ struct lttng_counter *counter = NULL;
+
+ counter_transport = lttng_counter_transport_find(counter_transport_name);
+ if (!counter_transport)
+ goto notransport;
+ counter = zmalloc(sizeof(struct lttng_counter));
+ if (!counter)
+ goto nomem;
+
+ counter->ops = &counter_transport->ops;
+ counter->transport = counter_transport;
+
+ counter->counter = counter->ops->counter_create(
+ number_dimensions, dimensions, 0,
+ -1, 0, NULL, false);
+ if (!counter->counter) {
+ goto create_error;
+ }
+
+ return counter;
+
+create_error:
+ free(counter);
+nomem:
+notransport:
+ return NULL;
+}
+
+static
+void lttng_ust_counter_destroy(struct lttng_counter *counter)
+{
+ counter->ops->counter_destroy(counter->counter);
+ free(counter);
+}
+
struct lttng_event_notifier_group *lttng_event_notifier_group_create(void)
{
struct lttng_event_notifier_group *event_notifier_group;
cds_list_for_each_entry(event, &session->events_head, node) {
_lttng_event_unregister(event);
}
- synchronize_trace(); /* Wait for in-flight events to complete */
+ lttng_ust_synchronize_trace(); /* Wait for in-flight events to complete */
__tracepoint_probe_prune_release_queue();
cds_list_for_each_entry_safe(event_enabler, event_tmpenabler,
&session->enablers_head, node)
&event_notifier_group->event_notifiers_head, node)
_lttng_event_notifier_unregister(notifier);
- synchronize_trace();
+ lttng_ust_synchronize_trace();
cds_list_for_each_entry_safe(notifier_enabler, tmpnotifier_enabler,
&event_notifier_group->enablers_head, node)
&event_notifier_group->event_notifiers_head, node)
_lttng_event_notifier_destroy(notifier);
- /* Close the notification fd to the listener of event notifiers. */
+ if (event_notifier_group->error_counter)
+ lttng_ust_counter_destroy(event_notifier_group->error_counter);
+
+ /* Close the notification fd to the listener of event_notifiers. */
lttng_ust_lock_fd_tracker();
close_ret = close(event_notifier_group->notification_fd);
static
int lttng_event_notifier_create(const struct lttng_event_desc *desc,
- uint64_t token,
+ uint64_t token, uint64_t error_counter_index,
struct lttng_event_notifier_group *event_notifier_group)
{
struct lttng_event_notifier *event_notifier;
event_notifier->group = event_notifier_group;
event_notifier->user_token = token;
+ event_notifier->error_counter_index = error_counter_index;
/* Event notifier will be enabled by enabler sync. */
event_notifier->enabled = 0;
event_notifier->registered = 0;
CDS_INIT_LIST_HEAD(&event_notifier->filter_bytecode_runtime_head);
+ CDS_INIT_LIST_HEAD(&event_notifier->capture_bytecode_runtime_head);
CDS_INIT_LIST_HEAD(&event_notifier->enablers_ref_head);
event_notifier->desc = desc;
+ event_notifier->notification_send = lttng_event_notifier_notification_send;
cds_list_add(&event_notifier->node,
&event_notifier_group->event_notifiers_head);
unsigned int i;
/* Get handle on list of sessions. */
- sessionsp = _lttng_get_sessions();
+ sessionsp = lttng_get_sessions();
/*
* Iterate over all events in the probe provider descriptions and
_lttng_event_notifier_unregister);
/* Wait for grace period. */
- synchronize_trace();
+ lttng_ust_synchronize_trace();
/* Prune the unregistration queue. */
__tracepoint_probe_prune_release_queue();
return NULL;
event_notifier_enabler->base.format_type = format_type;
CDS_INIT_LIST_HEAD(&event_notifier_enabler->base.filter_bytecode_head);
+ CDS_INIT_LIST_HEAD(&event_notifier_enabler->capture_bytecode_head);
CDS_INIT_LIST_HEAD(&event_notifier_enabler->base.excluder_head);
event_notifier_enabler->user_token = event_notifier_param->event.token;
+ event_notifier_enabler->error_counter_index = event_notifier_param->error_counter_index;
+ event_notifier_enabler->num_captures = 0;
memcpy(&event_notifier_enabler->base.event_param.name,
event_notifier_param->event.name,
static
void _lttng_enabler_attach_filter_bytecode(struct lttng_enabler *enabler,
- struct lttng_ust_bytecode_node *bytecode)
+ struct lttng_ust_bytecode_node **bytecode)
{
- bytecode->enabler = enabler;
- cds_list_add_tail(&bytecode->node, &enabler->filter_bytecode_head);
+ (*bytecode)->enabler = enabler;
+ cds_list_add_tail(&(*bytecode)->node, &enabler->filter_bytecode_head);
+ /* Take ownership of bytecode */
+ *bytecode = NULL;
}
int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event_enabler,
- struct lttng_ust_bytecode_node *bytecode)
+ struct lttng_ust_bytecode_node **bytecode)
{
_lttng_enabler_attach_filter_bytecode(
lttng_event_enabler_as_enabler(event_enabler), bytecode);
static
void _lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
- struct lttng_ust_excluder_node *excluder)
+ struct lttng_ust_excluder_node **excluder)
{
- excluder->enabler = enabler;
- cds_list_add_tail(&excluder->node, &enabler->excluder_head);
+ (*excluder)->enabler = enabler;
+ cds_list_add_tail(&(*excluder)->node, &enabler->excluder_head);
+ /* Take ownership of excluder */
+ *excluder = NULL;
}
int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabler,
- struct lttng_ust_excluder_node *excluder)
+ struct lttng_ust_excluder_node **excluder)
{
_lttng_enabler_attach_exclusion(
lttng_event_enabler_as_enabler(event_enabler), excluder);
int lttng_event_notifier_enabler_attach_filter_bytecode(
struct lttng_event_notifier_enabler *event_notifier_enabler,
- struct lttng_ust_bytecode_node *bytecode)
+ struct lttng_ust_bytecode_node **bytecode)
{
_lttng_enabler_attach_filter_bytecode(
lttng_event_notifier_enabler_as_enabler(event_notifier_enabler),
return 0;
}
+int lttng_event_notifier_enabler_attach_capture_bytecode(
+ struct lttng_event_notifier_enabler *event_notifier_enabler,
+ struct lttng_ust_bytecode_node **bytecode)
+{
+ (*bytecode)->enabler = lttng_event_notifier_enabler_as_enabler(
+ event_notifier_enabler);
+ cds_list_add_tail(&(*bytecode)->node,
+ &event_notifier_enabler->capture_bytecode_head);
+ /* Take ownership of bytecode */
+ *bytecode = NULL;
+ event_notifier_enabler->num_captures++;
+
+ lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
+ return 0;
+}
+
int lttng_event_notifier_enabler_attach_exclusion(
struct lttng_event_notifier_enabler *event_notifier_enabler,
- struct lttng_ust_excluder_node *excluder)
+ struct lttng_ust_excluder_node **excluder)
{
_lttng_enabler_attach_exclusion(
lttng_event_notifier_enabler_as_enabler(event_notifier_enabler),
__tracepoint_probe_prune_release_queue();
}
+/* Support for event notifier is introduced by probe provider major version 2. */
+static
+bool lttng_ust_probe_supports_event_notifier(struct lttng_probe_desc *probe_desc)
+{
+ return probe_desc->major >= 2;
+}
+
static
void lttng_create_event_notifier_if_missing(
struct lttng_event_notifier_enabler *event_notifier_enabler)
struct cds_hlist_node *node;
desc = probe_desc->event_desc[i];
+
if (!lttng_desc_match_enabler(desc,
lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)))
continue;
if (found)
continue;
+ /* Check that the probe supports event notifiers, else report the error. */
+ if (!lttng_ust_probe_supports_event_notifier(probe_desc)) {
+ ERR("Probe \"%s\" contains event \"%s\" which matches an enabled event notifier, "
+ "but its version (%u.%u) is too old and does not implement event notifiers. "
+ "It needs to be recompiled against a newer version of LTTng-UST, otherwise "
+ "this event will not generate any notification.",
+ probe_desc->provider,
+ desc->name,
+ probe_desc->major,
+ probe_desc->minor);
+ continue;
+ }
/*
* We need to create a event_notifier for this event probe.
*/
ret = lttng_event_notifier_create(desc,
event_notifier_enabler->user_token,
+ event_notifier_enabler->error_counter_index,
event_notifier_group);
if (ret) {
DBG("Unable to create event_notifier %s, error %d\n",
&event_notifier_group->ctx,
&event_notifier->filter_bytecode_runtime_head,
<tng_event_notifier_enabler_as_enabler(event_notifier_enabler)->filter_bytecode_head);
+
+ /*
+ * Link capture bytecodes if not linked yet.
+ */
+ lttng_enabler_link_bytecode(event_notifier->desc,
+ &event_notifier_group->ctx, &event_notifier->capture_bytecode_runtime_head,
+ &event_notifier_enabler->capture_bytecode_head);
+
+ event_notifier->num_captures = event_notifier_enabler->num_captures;
}
end:
return 0;
&event_notifier->filter_bytecode_runtime_head, node) {
lttng_bytecode_filter_sync_state(runtime);
}
+
+ /* Enable captures. */
+ cds_list_for_each_entry(runtime,
+ &event_notifier->capture_bytecode_runtime_head, node) {
+ lttng_bytecode_capture_sync_state(runtime);
+ }
}
__tracepoint_probe_prune_release_queue();
}