SoW-2020-0002: Trace Hit Counters
[deliverable/lttng-ust.git] / include / lttng / ust-events.h
index 16c5abb1f569fcd76ab6ffc12d2c54bdea884d43..d87abbf539b2cf0ebfc1f64fa0ff7307c4435ead 100644 (file)
@@ -1,32 +1,14 @@
-#ifndef _LTTNG_UST_EVENTS_H
-#define _LTTNG_UST_EVENTS_H
-
 /*
- * lttng/ust-events.h
+ * SPDX-License-Identifier: MIT
  *
- * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * Holds LTTng per-session event registry.
- *
- * 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.
  */
 
+#ifndef _LTTNG_UST_EVENTS_H
+#define _LTTNG_UST_EVENTS_H
+
 #include <urcu/list.h>
 #include <urcu/hlist.h>
 #include <stddef.h>
@@ -56,7 +38,7 @@ extern "C" {
  * library, but the opposite is rejected: a newer tracepoint provider is
  * rejected by an older lttng-ust library.
  */
-#define LTTNG_UST_PROVIDER_MAJOR       2
+#define LTTNG_UST_PROVIDER_MAJOR       3
 #define LTTNG_UST_PROVIDER_MINOR       0
 
 struct lttng_channel;
@@ -354,7 +336,7 @@ struct lttng_ctx {
 #define LTTNG_UST_EVENT_DESC_PADDING   40
 struct lttng_event_desc {
        const char *name;
-       void (*probe_callback)(void);
+       void (*probe_callback)(void);           /* store-event and count-event probe */
        const struct lttng_event_ctx *ctx;      /* context */
        const struct lttng_event_field *fields; /* event payload */
        unsigned int nr_fields;
@@ -389,22 +371,6 @@ enum lttng_enabler_format_type {
        LTTNG_ENABLER_FORMAT_EVENT,
 };
 
-/*
- * Enabler field, within whatever object is enabling an event. Target of
- * backward reference.
- */
-struct lttng_enabler {
-       enum lttng_enabler_format_type format_type;
-
-       /* head list of struct lttng_ust_filter_bytecode_node */
-       struct cds_list_head filter_bytecode_head;
-       /* head list of struct lttng_ust_excluder_node */
-       struct cds_list_head excluder_head;
-
-       struct lttng_ust_event event_param;
-       unsigned int enabled:1;
-};
-
 struct tp_list_entry {
        struct lttng_ust_tracepoint_iter tp;
        struct cds_list_head head;
@@ -478,6 +444,37 @@ struct lttng_enabler_ref {
        struct lttng_enabler *ref;              /* backward ref */
 };
 
+enum lttng_event_container_type {
+       LTTNG_EVENT_CONTAINER_CHANNEL,
+       LTTNG_EVENT_CONTAINER_COUNTER,
+};
+
+enum lttng_key_token_type {
+       LTTNG_KEY_TOKEN_STRING = 0,
+       LTTNG_KEY_TOKEN_EVENT_NAME = 1,
+       LTTNG_KEY_TOKEN_PROVIDER_NAME = 2,
+};
+
+#define LTTNG_KEY_TOKEN_STRING_LEN_MAX LTTNG_UST_KEY_TOKEN_STRING_LEN_MAX
+struct lttng_key_token {
+       enum lttng_key_token_type type;
+       union {
+               char string[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
+       } arg;
+};
+
+#define LTTNG_NR_KEY_TOKEN LTTNG_UST_NR_KEY_TOKEN
+struct lttng_counter_key_dimension {
+       size_t nr_key_tokens;
+       struct lttng_key_token key_tokens[LTTNG_UST_NR_KEY_TOKEN];
+};
+
+#define LTTNG_COUNTER_DIMENSION_MAX LTTNG_UST_COUNTER_DIMENSION_MAX
+struct lttng_counter_key {
+       size_t nr_dimensions;
+       struct lttng_counter_key_dimension key_dimensions[LTTNG_COUNTER_DIMENSION_MAX];
+};
+
 /*
  * lttng_event structure is referred to by the tracing fast path. It
  * must be kept small.
@@ -488,7 +485,7 @@ struct lttng_enabler_ref {
  */
 struct lttng_event {
        unsigned int id;
-       struct lttng_channel *chan;
+       struct lttng_channel *chan;     /* for backward compatibility */
        int enabled;
        const struct lttng_event_desc *desc;
        struct lttng_ctx *ctx;
@@ -500,8 +497,19 @@ struct lttng_event {
        int has_enablers_without_bytecode;
        /* Backward references: list of lttng_enabler_ref (ref to enablers) */
        struct cds_list_head enablers_ref_head;
-       struct cds_hlist_node hlist;    /* session ht of events */
-       int registered;                 /* has reg'd tracepoint probe */
+       struct cds_hlist_node name_hlist;       /* session ht of events, per event name */
+       int registered;                         /* has reg'd tracepoint probe */
+
+       /* LTTng-UST 2.14 starts here */
+       uint64_t counter_index;                 /* counter index */
+       struct lttng_event_container *container;
+       struct cds_hlist_node key_hlist;        /* session ht of events, per key */
+       char key[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
+       /*
+        * For non-coalesce-hit event containers, each events is
+        * associated with a single event enabler token.
+        */
+       uint64_t user_token;
 };
 
 struct lttng_event_notifier {
@@ -568,6 +576,20 @@ struct lttng_channel_ops {
                        const char *src, size_t len);
 };
 
+/*
+ * This structure is ABI with the tracepoint probes, and must preserve
+ * backward compatibility. Fields can only be added at the end, and
+ * never removed nor reordered.
+ */
+struct lttng_event_container {
+       enum lttng_event_container_type type;
+       int objd;
+       struct lttng_session *session;          /* Session containing the container */
+       int enabled;
+       unsigned int tstate:1;                  /* Transient enable state */
+       bool coalesce_hits;
+};
+
 /*
  * IMPORTANT: this structure is part of the ABI between the probe and
  * UST. Fields need to be only added at the end, never reordered, never
@@ -581,10 +603,10 @@ struct lttng_channel {
         * and perform subbuffer flush.
         */
        struct channel *chan;           /* Channel buffers */
-       int enabled;
+       int enabled;                    /* For backward compatibility */
        struct lttng_ctx *ctx;
        /* Event ID management */
-       struct lttng_session *session;
+       struct lttng_session *session;  /* For backward compatibility */
        int objd;                       /* Object associated to channel */
        struct cds_list_head node;      /* Channel list in session */
        const struct lttng_channel_ops *ops;
@@ -595,22 +617,14 @@ struct lttng_channel {
        unsigned int id;
        enum lttng_ust_chan_type type;
        unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
-       int tstate:1;                   /* Transient enable state */
-};
-
-#define LTTNG_COUNTER_DIMENSION_MAX    8
+       int _deprecated:1;
 
-struct lttng_counter_dimension {
-       uint64_t size;
-       uint64_t underflow_index;
-       uint64_t overflow_index;
-       uint8_t has_underflow;
-       uint8_t has_overflow;
+       struct lttng_event_container parent;
 };
 
 struct lttng_counter_ops {
        struct lib_counter *(*counter_create)(size_t nr_dimensions,
-                       const struct lttng_counter_dimension *dimensions,
+                       const size_t *dimensions,
                        int64_t global_sum_step,
                        int global_counter_fd,
                        int nr_counter_cpu_fds,
@@ -672,7 +686,8 @@ struct lttng_session {
        /* New UST 2.1 */
        /* List of enablers */
        struct cds_list_head enablers_head;
-       struct lttng_ust_event_ht events_ht;    /* ht of events */
+       /* hash table of events, indexed by name */
+       struct lttng_ust_event_ht events_name_ht;
        void *owner;                            /* object owner */
        int tstate:1;                           /* Transient enable state */
 
@@ -683,14 +698,24 @@ struct lttng_session {
        struct lttng_ust_enum_ht enums_ht;      /* ht of enumerations */
        struct cds_list_head enums_head;
        struct lttng_ctx *ctx;                  /* contexts for filters. */
+
+       /* New UST 2.14 */
+       struct cds_list_head counters;          /* Counters list */
+       /* hash table of events, indexed by key */
+       struct lttng_ust_event_ht events_key_ht;
 };
 
 struct lttng_counter {
-       int objd;
-       struct lttng_event_notifier_group *event_notifier_group;    /* owner */
+       struct lttng_event_container parent;
+       union {
+               struct lttng_event_notifier_group *event_notifier_group;
+               struct lttng_session *session;
+       } owner;
        struct lttng_counter_transport *transport;
        struct lib_counter *counter;
        struct lttng_counter_ops *ops;
+       struct cds_list_head node;              /* Counter list (in session) */
+       size_t free_index;                      /* Next index to allocate */
 };
 
 struct lttng_event_notifier_group {
@@ -727,18 +752,8 @@ int lttng_session_disable(struct lttng_session *session);
 int lttng_session_statedump(struct lttng_session *session);
 void lttng_session_destroy(struct lttng_session *session);
 
-struct lttng_channel *lttng_channel_create(struct lttng_session *session,
-                                      const char *transport_name,
-                                      void *buf_addr,
-                                      size_t subbuf_size, size_t num_subbuf,
-                                      unsigned int switch_timer_interval,
-                                      unsigned int read_timer_interval,
-                                      int **shm_fd, int **wait_fd,
-                                      uint64_t **memory_map_size,
-                                      struct lttng_channel *chan_priv_init);
-
-int lttng_channel_enable(struct lttng_channel *channel);
-int lttng_channel_disable(struct lttng_channel *channel);
+int lttng_event_container_enable(struct lttng_event_container *container);
+int lttng_event_container_disable(struct lttng_event_container *container);
 
 int lttng_attach_context(struct lttng_ust_context *context_param,
                union ust_args *uargs,
@@ -746,9 +761,8 @@ int lttng_attach_context(struct lttng_ust_context *context_param,
 void lttng_transport_register(struct lttng_transport *transport);
 void lttng_transport_unregister(struct lttng_transport *transport);
 
-struct lttng_counter *lttng_ust_counter_create(
-               const char *counter_transport_name,
-               size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
+void lttng_counter_transport_register(struct lttng_counter_transport *transport);
+void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
 
 int lttng_probe_register(struct lttng_probe_desc *desc);
 void lttng_probe_unregister(struct lttng_probe_desc *desc);
@@ -775,7 +789,6 @@ int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx);
-int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx);
@@ -792,7 +805,6 @@ void lttng_context_ipc_ns_reset(void);
 void lttng_context_mnt_ns_reset(void);
 void lttng_context_net_ns_reset(void);
 void lttng_context_pid_ns_reset(void);
-void lttng_context_time_ns_reset(void);
 void lttng_context_user_ns_reset(void);
 void lttng_context_uts_ns_reset(void);
 void lttng_context_vuid_reset(void);
@@ -859,6 +871,34 @@ struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
 void lttng_ust_dl_update(void *ip);
 void lttng_ust_fixup_fd_tracker_tls(void);
 
+static inline
+struct lttng_event_container *lttng_channel_get_event_container(struct lttng_channel *channel)
+{
+       return &channel->parent;
+}
+
+static inline
+struct lttng_event_container *lttng_counter_get_event_container(struct lttng_counter *counter)
+{
+       return &counter->parent;
+}
+
+static inline
+struct lttng_channel *lttng_event_container_get_channel(struct lttng_event_container *container)
+{
+       if (container->type != LTTNG_EVENT_CONTAINER_CHANNEL)
+               return NULL;
+       return caa_container_of(container, struct lttng_channel, parent);
+}
+
+static inline
+struct lttng_counter *lttng_event_container_get_counter(struct lttng_event_container *container)
+{
+       if (container->type != LTTNG_EVENT_CONTAINER_COUNTER)
+               return NULL;
+       return caa_container_of(container, struct lttng_counter, parent);
+}
+
 #ifdef __cplusplus
 }
 #endif
This page took 0.028373 seconds and 5 git commands to generate.