Fix: Build examples when rpath is stripped from in-build-tree libs
[lttng-ust.git] / src / common / events.h
index 338573a9947373bbce5ef07b7d0ff4e639155273..d53a587b2aaf6dea0428fb6ec14dd498ae40cbac 100644 (file)
 #include "common/macros.h"
 #include "common/ust-context-provider.h"
 
 #include "common/macros.h"
 #include "common/ust-context-provider.h"
 
+/*
+ * The context procname length is part of the LTTng-UST ABI.
+ * TODO: At the next breaking protocol bump, all users of this macro
+ * should instead use LTTNG_UST_ABI_PROCNAME_LEN.
+ */
+#define LTTNG_UST_CONTEXT_PROCNAME_LEN 17
+
 struct lttng_ust_abi_obj;
 struct lttng_event_notifier_group;
 
 struct lttng_ust_abi_obj;
 struct lttng_event_notifier_group;
 
@@ -40,11 +47,18 @@ union lttng_ust_abi_args {
                int event_notifier_notif_fd;
        } event_notifier_handle;
        struct {
                int event_notifier_notif_fd;
        } event_notifier_handle;
        struct {
-               void *counter_data;
+               uint32_t len;
+       } event_notifier;
+       struct {
+               uint32_t len;
        } counter;
        struct {
        } counter;
        struct {
+               uint32_t len;
                int shm_fd;
        } counter_shm;
                int shm_fd;
        } counter_shm;
+       struct {
+               uint32_t len;
+       } counter_event;
 };
 
 struct lttng_ust_abi_objd_ops {
 };
 
 struct lttng_ust_abi_objd_ops {
@@ -58,11 +72,65 @@ enum lttng_enabler_format_type {
        LTTNG_ENABLER_FORMAT_EVENT,
 };
 
        LTTNG_ENABLER_FORMAT_EVENT,
 };
 
+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 4096
+struct lttng_key_token {
+       enum lttng_key_token_type type;
+       union {
+               char string[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
+       } arg;
+};
+
+enum lttng_key_type {
+       LTTNG_KEY_TYPE_TOKENS = 0,
+       LTTNG_KEY_TYPE_INTEGER = 1,
+};
+
+#define LTTNG_NR_KEY_TOKEN 8
+struct lttng_counter_key_dimension {
+       enum lttng_key_type key_type;
+
+       union {
+               struct {
+                       size_t nr_key_tokens;
+                       struct lttng_key_token key_tokens[LTTNG_NR_KEY_TOKEN];
+               } tokens;
+       } u;
+};
+
+#define LTTNG_COUNTER_DIMENSION_MAX 4
+struct lttng_counter_key {
+       size_t nr_dimensions;
+       struct lttng_counter_key_dimension key_dimensions[LTTNG_COUNTER_DIMENSION_MAX];
+};
+
+struct lttng_counter_dimension {
+       uint64_t size;
+       uint64_t underflow_index;
+       uint64_t overflow_index;
+       enum lttng_key_type key_type;
+       uint8_t has_underflow;
+       uint8_t has_overflow;
+};
+
+enum lttng_event_enabler_type {
+       LTTNG_EVENT_ENABLER_TYPE_RECORDER,
+       LTTNG_EVENT_ENABLER_TYPE_NOTIFIER,
+       LTTNG_EVENT_ENABLER_TYPE_COUNTER,
+};
+
 /*
  * Enabler field, within whatever object is enabling an event. Target of
  * backward reference.
  */
 /*
  * Enabler field, within whatever object is enabling an event. Target of
  * backward reference.
  */
-struct lttng_enabler {
+struct lttng_event_enabler_common {
+       enum lttng_event_enabler_type enabler_type;
+
        enum lttng_enabler_format_type format_type;
 
        /* head list of struct lttng_ust_filter_bytecode_node */
        enum lttng_enabler_format_type format_type;
 
        /* head list of struct lttng_ust_filter_bytecode_node */
@@ -72,26 +140,38 @@ struct lttng_enabler {
 
        struct lttng_ust_abi_event event_param;
        unsigned int enabled:1;
 
        struct lttng_ust_abi_event event_param;
        unsigned int enabled:1;
+
+       struct cds_list_head node;      /* list of enablers */
+       uint64_t user_token;            /* User-provided token */
+};
+
+struct lttng_event_enabler_session_common {
+       struct lttng_event_enabler_common parent;
+       struct lttng_ust_channel_common *chan;
 };
 
 };
 
-struct lttng_event_enabler {
-       struct lttng_enabler base;
-       struct cds_list_head node;      /* per-session list of enablers */
+struct lttng_event_recorder_enabler {
+       struct lttng_event_enabler_session_common parent;
        struct lttng_ust_channel_buffer *chan;
        struct lttng_ust_channel_buffer *chan;
-       /*
-        * Unused, but kept around to make it explicit that the tracer can do
-        * it.
-        */
-       struct lttng_ust_ctx *ctx;
+};
+
+enum lttng_event_counter_action {
+       LTTNG_EVENT_COUNTER_ACTION_INCREMENT = 0,
+};
+
+struct lttng_event_counter_enabler {
+       struct lttng_event_enabler_session_common parent;
+       struct lttng_ust_channel_counter *chan;
+       struct lttng_counter_key key;
+
+       enum lttng_event_counter_action action;
 };
 
 struct lttng_event_notifier_enabler {
 };
 
 struct lttng_event_notifier_enabler {
-       struct lttng_enabler base;
+       struct lttng_event_enabler_common parent;
        uint64_t error_counter_index;
        uint64_t error_counter_index;
-       struct cds_list_head node;      /* per-app list of event_notifier enablers */
        struct cds_list_head capture_bytecode_head;
        struct lttng_event_notifier_group *group; /* weak ref */
        struct cds_list_head capture_bytecode_head;
        struct lttng_event_notifier_group *group; /* weak ref */
-       uint64_t user_token;            /* User-provided token */
        uint64_t num_captures;
 };
 
        uint64_t num_captures;
 };
 
@@ -103,7 +183,7 @@ enum lttng_ust_bytecode_type {
 struct lttng_ust_bytecode_node {
        enum lttng_ust_bytecode_type type;
        struct cds_list_head node;
 struct lttng_ust_bytecode_node {
        enum lttng_ust_bytecode_type type;
        struct cds_list_head node;
-       struct lttng_enabler *enabler;
+       struct lttng_event_enabler_common *enabler;
        struct  {
                uint32_t len;
                uint32_t reloc_offset;
        struct  {
                uint32_t len;
                uint32_t reloc_offset;
@@ -134,7 +214,7 @@ struct lttng_ust_bytecode_filter_ctx {
 
 struct lttng_ust_excluder_node {
        struct cds_list_head node;
 
 struct lttng_ust_excluder_node {
        struct cds_list_head node;
-       struct lttng_enabler *enabler;
+       struct lttng_event_enabler_common *enabler;
        /*
         * struct lttng_ust_event_exclusion had variable sized array,
         * must be last field.
        /*
         * struct lttng_ust_event_exclusion had variable sized array,
         * must be last field.
@@ -175,44 +255,7 @@ struct lttng_ust_field_list {
  */
 struct lttng_enabler_ref {
        struct cds_list_head node;              /* enabler ref list */
  */
 struct lttng_enabler_ref {
        struct cds_list_head node;              /* enabler ref list */
-       struct lttng_enabler *ref;              /* backward ref */
-};
-
-#define LTTNG_COUNTER_DIMENSION_MAX    8
-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_counter_ops {
-       struct lib_counter *(*counter_create)(size_t nr_dimensions,
-                       const struct lttng_counter_dimension *dimensions,
-                       int64_t global_sum_step,
-                       int global_counter_fd,
-                       int nr_counter_cpu_fds,
-                       const int *counter_cpu_fds,
-                       bool is_daemon);
-       void (*counter_destroy)(struct lib_counter *counter);
-       int (*counter_add)(struct lib_counter *counter,
-                       const size_t *dimension_indexes, int64_t v);
-       int (*counter_read)(struct lib_counter *counter,
-                       const size_t *dimension_indexes, int cpu,
-                       int64_t *value, bool *overflow, bool *underflow);
-       int (*counter_aggregate)(struct lib_counter *counter,
-                       const size_t *dimension_indexes, int64_t *value,
-                       bool *overflow, bool *underflow);
-       int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
-};
-
-struct lttng_counter {
-       int objd;
-       struct lttng_event_notifier_group *event_notifier_group;    /* owner */
-       struct lttng_counter_transport *transport;
-       struct lib_counter *counter;
-       struct lttng_counter_ops *ops;
+       struct lttng_event_enabler_common *ref;         /* backward ref */
 };
 
 #define LTTNG_UST_EVENT_HT_BITS                12
 };
 
 #define LTTNG_UST_EVENT_HT_BITS                12
@@ -222,12 +265,6 @@ struct lttng_ust_event_ht {
        struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
 };
 
        struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
 };
 
-#define LTTNG_UST_EVENT_NOTIFIER_HT_BITS               12
-#define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE               (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
-struct lttng_ust_event_notifier_ht {
-       struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE];
-};
-
 #define LTTNG_UST_ENUM_HT_BITS         12
 #define LTTNG_UST_ENUM_HT_SIZE         (1U << LTTNG_UST_ENUM_HT_BITS)
 
 #define LTTNG_UST_ENUM_HT_BITS         12
 #define LTTNG_UST_ENUM_HT_SIZE         (1U << LTTNG_UST_ENUM_HT_BITS)
 
@@ -240,12 +277,17 @@ struct lttng_event_notifier_group {
        void *owner;
        int notification_fd;
        struct cds_list_head node;              /* Event notifier group handle list */
        void *owner;
        int notification_fd;
        struct cds_list_head node;              /* Event notifier group handle list */
-       struct cds_list_head enablers_head;
+
+       /* List of non-synchronized enablers */
+       struct cds_list_head unsync_enablers_head;
+       /* List of synchronized enablers */
+       struct cds_list_head sync_enablers_head;
+
        struct cds_list_head event_notifiers_head; /* list of event_notifiers */
        struct cds_list_head event_notifiers_head; /* list of event_notifiers */
-       struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */
+       struct lttng_ust_event_ht event_notifiers_ht; /* hashtable of event notifiers */
        struct lttng_ust_ctx *ctx;              /* contexts for filters. */
 
        struct lttng_ust_ctx *ctx;              /* contexts for filters. */
 
-       struct lttng_counter *error_counter;
+       struct lttng_ust_channel_counter *error_counter;
        size_t error_counter_len;
 };
 
        size_t error_counter_len;
 };
 
@@ -259,7 +301,7 @@ struct lttng_transport {
 struct lttng_counter_transport {
        const char *name;
        struct cds_list_head node;
 struct lttng_counter_transport {
        const char *name;
        struct cds_list_head node;
-       struct lttng_counter_ops ops;
+       struct lttng_ust_channel_counter_ops ops;
        const struct lib_counter_config *client_config;
 };
 
        const struct lib_counter_config *client_config;
 };
 
@@ -275,16 +317,31 @@ struct lttng_ust_event_common_private {
        int has_enablers_without_filter_bytecode;
        /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
        struct cds_list_head filter_bytecode_runtime_head;
        int has_enablers_without_filter_bytecode;
        /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
        struct cds_list_head filter_bytecode_runtime_head;
+
+       struct cds_hlist_node name_hlist_node;  /* node in events-by-name hash table */
+       struct cds_list_head node;              /* node in event list */
 };
 
 };
 
-struct lttng_ust_event_recorder_private {
+struct lttng_ust_event_session_common_private {
        struct lttng_ust_event_common_private parent;
 
        struct lttng_ust_event_common_private parent;
 
+       struct lttng_ust_channel_common *chan;
+
+       uint64_t id;                            /* Event id */
+};
+
+struct lttng_ust_event_recorder_private {
+       struct lttng_ust_event_session_common_private parent;
+
        struct lttng_ust_event_recorder *pub;   /* Public event interface */
        struct lttng_ust_event_recorder *pub;   /* Public event interface */
-       struct cds_list_head node;              /* Event recorder list */
-       struct cds_hlist_node hlist;            /* Hash table of event recorders */
-       struct lttng_ust_ctx *ctx;
-       unsigned int id;
+};
+
+struct lttng_ust_event_counter_private {
+       struct lttng_ust_event_session_common_private parent;
+
+       struct lttng_ust_event_counter *pub;    /* Public event interface */
+       enum lttng_event_counter_action action;
+       char key[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
 };
 
 struct lttng_ust_event_notifier_private {
 };
 
 struct lttng_ust_event_notifier_private {
@@ -294,8 +351,6 @@ struct lttng_ust_event_notifier_private {
        struct lttng_event_notifier_group *group; /* weak ref */
        size_t num_captures;                    /* Needed to allocate the msgpack array. */
        uint64_t error_counter_index;
        struct lttng_event_notifier_group *group; /* weak ref */
        size_t num_captures;                    /* Needed to allocate the msgpack array. */
        uint64_t error_counter_index;
-       struct cds_list_head node;              /* Event notifier list */
-       struct cds_hlist_node hlist;            /* Hash table of event notifiers */
        struct cds_list_head capture_bytecode_runtime_head;
 };
 
        struct cds_list_head capture_bytecode_runtime_head;
 };
 
@@ -321,21 +376,24 @@ struct lttng_ust_session_private {
        int been_active;                        /* Been active ? */
        int objd;                               /* Object associated */
        struct cds_list_head chan_head;         /* Channel list head */
        int been_active;                        /* Been active ? */
        int objd;                               /* Object associated */
        struct cds_list_head chan_head;         /* Channel list head */
+       struct cds_list_head counters_head;     /* Counter list head */
        struct cds_list_head events_head;       /* list of events */
        struct cds_list_head node;              /* Session list */
 
        struct cds_list_head events_head;       /* list of events */
        struct cds_list_head node;              /* Session list */
 
-       /* List of enablers */
-       struct cds_list_head enablers_head;
-       struct lttng_ust_event_ht events_ht;    /* ht of events */
-       void *owner;                            /* object owner */
-       int tstate:1;                           /* Transient enable state */
+       /* List of non-synchronized enablers */
+       struct cds_list_head unsync_enablers_head;
+       /* List of synchronized enablers */
+       struct cds_list_head sync_enablers_head;
 
 
-       int statedump_pending:1;
+       struct cds_list_head enums_head;
 
 
+       struct lttng_ust_event_ht events_name_ht; /* ht of events, indexed by name */
        struct lttng_ust_enum_ht enums_ht;      /* ht of enumerations */
        struct lttng_ust_enum_ht enums_ht;      /* ht of enumerations */
-       struct cds_list_head enums_head;
-       struct lttng_ust_ctx *ctx;              /* contexts for filters. */
 
 
+       void *owner;                            /* object owner */
+       unsigned int tstate:1;                  /* Transient enable state */
+       unsigned int statedump_pending:1;
+       struct lttng_ust_ctx *ctx;              /* contexts for filters. */
        unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
        bool uuid_set;                          /* Is uuid set ? */
 };
        unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
        bool uuid_set;                          /* Is uuid set ? */
 };
@@ -378,7 +436,8 @@ struct lttng_ust_channel_common_private {
        struct lttng_ust_channel_common *pub;   /* Public channel interface */
 
        int objd;                               /* Object associated with channel. */
        struct lttng_ust_channel_common *pub;   /* Public channel interface */
 
        int objd;                               /* Object associated with channel. */
-       int tstate:1;                           /* Transient enable state */
+       unsigned int tstate:1;                  /* Transient enable state */
+       bool coalesce_hits;
 };
 
 struct lttng_ust_channel_buffer_private {
 };
 
 struct lttng_ust_channel_buffer_private {
@@ -394,6 +453,46 @@ struct lttng_ust_channel_buffer_private {
        unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
 };
 
        unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
 };
 
+struct lttng_ust_channel_counter_ops_private {
+       struct lttng_ust_channel_counter_ops *pub;      /* Public channel counter ops interface */
+
+       struct lttng_ust_channel_counter *(*counter_create)(size_t nr_dimensions,
+                       const struct lttng_counter_dimension *dimensions,
+                       int64_t global_sum_step,
+                       int global_counter_fd,
+                       int nr_counter_cpu_fds,
+                       const int *counter_cpu_fds,
+                       bool is_daemon);
+       void (*counter_destroy)(struct lttng_ust_channel_counter *counter);
+       int (*counter_add)(struct lttng_ust_channel_counter *counter,
+                       const size_t *dimension_indexes, int64_t v);
+       int (*counter_read)(struct lttng_ust_channel_counter *counter,
+                       const size_t *dimension_indexes, int cpu,
+                       int64_t *value, bool *overflow, bool *underflow);
+       int (*counter_aggregate)(struct lttng_ust_channel_counter *counter,
+                       const size_t *dimension_indexes, int64_t *value,
+                       bool *overflow, bool *underflow);
+       int (*counter_clear)(struct lttng_ust_channel_counter *counter,
+                       const size_t *dimension_indexes);
+};
+
+struct lttng_ust_channel_counter_private {
+       struct lttng_ust_channel_common_private parent;
+
+       struct lttng_ust_channel_counter *pub;          /* Public channel counter interface */
+       struct lib_counter *counter;
+       struct lttng_ust_channel_counter_ops *ops;
+
+       /* Event notifier group owner. */
+       struct lttng_event_notifier_group *event_notifier_group;
+
+       /* Session owner. */
+       struct lttng_session *session;
+       struct cds_list_head node;                      /* Counter list (in session) */
+       size_t free_index;                              /* Next index to allocate */
+       enum lttng_key_type dimension_key_types[LTTNG_COUNTER_DIMENSION_MAX];
+};
+
 /*
  * IMPORTANT: this structure is part of the ABI between the consumer
  * daemon and the UST library within traced applications. Changing it
 /*
  * IMPORTANT: this structure is part of the ABI between the consumer
  * daemon and the UST library within traced applications. Changing it
@@ -559,20 +658,55 @@ const struct lttng_ust_type_struct *lttng_ust_get_type_struct(const struct lttng
        })
 
 static inline
        })
 
 static inline
-struct lttng_enabler *lttng_event_enabler_as_enabler(
-               struct lttng_event_enabler *event_enabler)
+struct lttng_event_enabler_common *lttng_event_notifier_enabler_as_enabler(
+               struct lttng_event_notifier_enabler *event_notifier_enabler)
 {
 {
-       return &event_enabler->base;
+       return &event_notifier_enabler->parent;
 }
 
 static inline
 }
 
 static inline
-struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
-               struct lttng_event_notifier_enabler *event_notifier_enabler)
+struct lttng_ust_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common *event_enabler)
 {
 {
-       return &event_notifier_enabler->base;
+       switch (event_enabler->enabler_type) {
+       case LTTNG_EVENT_ENABLER_TYPE_RECORDER:         /* Fall-through */
+       case LTTNG_EVENT_ENABLER_TYPE_COUNTER:
+       {
+               struct lttng_event_enabler_session_common *event_enabler_session =
+                       caa_container_of(event_enabler, struct lttng_event_enabler_session_common, parent);
+               return &event_enabler_session->chan->session->priv->events_name_ht;
+       }
+       case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
+       {
+               struct lttng_event_notifier_enabler *event_notifier_enabler =
+                       caa_container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
+               return &event_notifier_enabler->group->event_notifiers_ht;
+       }
+       default:
+               return NULL;
+       }
 }
 
 }
 
-
+static inline
+struct cds_list_head *lttng_get_event_list_head_from_enabler(struct lttng_event_enabler_common *event_enabler)
+{
+       switch (event_enabler->enabler_type) {
+       case LTTNG_EVENT_ENABLER_TYPE_RECORDER:         /* Fall-through */
+       case LTTNG_EVENT_ENABLER_TYPE_COUNTER:
+       {
+               struct lttng_event_enabler_session_common *event_enabler_session =
+                       caa_container_of(event_enabler, struct lttng_event_enabler_session_common, parent);
+               return &event_enabler_session->chan->session->priv->events_head;
+       }
+       case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
+       {
+               struct lttng_event_notifier_enabler *event_notifier_enabler =
+                       caa_container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
+               return &event_notifier_enabler->group->event_notifiers_head;
+       }
+       default:
+               return NULL;
+       }
+}
 
 /* This is ABI between liblttng-ust and liblttng-ust-dl */
 void lttng_ust_dl_update(void *ip);
 
 /* This is ABI between liblttng-ust and liblttng-ust-dl */
 void lttng_ust_dl_update(void *ip);
This page took 0.034353 seconds and 4 git commands to generate.