| 1 | #ifndef _UST_LTTNG_EVENTS_H |
| 2 | #define _UST_LTTNG_EVENTS_H |
| 3 | |
| 4 | /* |
| 5 | * ust/lttng-events.h |
| 6 | * |
| 7 | * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * Holds LTTng per-session event registry. |
| 10 | * |
| 11 | * Dual LGPL v2.1/GPL v2 license. |
| 12 | */ |
| 13 | |
| 14 | #include <urcu/list.h> |
| 15 | #include <uuid/uuid.h> |
| 16 | #include <stdint.h> |
| 17 | #include <ust/lttng-ust-abi.h> |
| 18 | |
| 19 | #undef is_signed_type |
| 20 | #define is_signed_type(type) (((type)(-1)) < 0) |
| 21 | |
| 22 | struct ltt_channel; |
| 23 | struct ltt_session; |
| 24 | struct lib_ring_buffer_ctx; |
| 25 | |
| 26 | /* Type description */ |
| 27 | |
| 28 | /* Update the astract_types name table in lttng-types.c along with this enum */ |
| 29 | enum abstract_types { |
| 30 | atype_integer, |
| 31 | atype_enum, |
| 32 | atype_array, |
| 33 | atype_sequence, |
| 34 | atype_string, |
| 35 | NR_ABSTRACT_TYPES, |
| 36 | }; |
| 37 | |
| 38 | /* Update the string_encodings name table in lttng-types.c along with this enum */ |
| 39 | enum lttng_string_encodings { |
| 40 | lttng_encode_none = 0, |
| 41 | lttng_encode_UTF8 = 1, |
| 42 | lttng_encode_ASCII = 2, |
| 43 | NR_STRING_ENCODINGS, |
| 44 | }; |
| 45 | |
| 46 | struct lttng_enum_entry { |
| 47 | unsigned long long start, end; /* start and end are inclusive */ |
| 48 | const char *string; |
| 49 | }; |
| 50 | |
| 51 | #define __type_integer(_type, _byte_order, _base, _encoding) \ |
| 52 | { \ |
| 53 | .atype = atype_integer, \ |
| 54 | .u.basic.integer = \ |
| 55 | { \ |
| 56 | .size = sizeof(_type) * CHAR_BIT, \ |
| 57 | .alignment = ltt_alignof(_type) * CHAR_BIT, \ |
| 58 | .signedness = is_signed_type(_type), \ |
| 59 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ |
| 60 | .base = _base, \ |
| 61 | .encoding = lttng_encode_##_encoding, \ |
| 62 | }, \ |
| 63 | } \ |
| 64 | |
| 65 | struct lttng_integer_type { |
| 66 | unsigned int size; /* in bits */ |
| 67 | unsigned short alignment; /* in bits */ |
| 68 | unsigned int signedness:1; |
| 69 | unsigned int reverse_byte_order:1; |
| 70 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
| 71 | enum lttng_string_encodings encoding; |
| 72 | }; |
| 73 | |
| 74 | union _lttng_basic_type { |
| 75 | struct lttng_integer_type integer; |
| 76 | struct { |
| 77 | const char *name; |
| 78 | } enumeration; |
| 79 | struct { |
| 80 | enum lttng_string_encodings encoding; |
| 81 | } string; |
| 82 | }; |
| 83 | |
| 84 | struct lttng_basic_type { |
| 85 | enum abstract_types atype; |
| 86 | union { |
| 87 | union _lttng_basic_type basic; |
| 88 | } u; |
| 89 | }; |
| 90 | |
| 91 | struct lttng_type { |
| 92 | enum abstract_types atype; |
| 93 | union { |
| 94 | union _lttng_basic_type basic; |
| 95 | struct { |
| 96 | struct lttng_basic_type elem_type; |
| 97 | unsigned int length; /* num. elems. */ |
| 98 | } array; |
| 99 | struct { |
| 100 | struct lttng_basic_type length_type; |
| 101 | struct lttng_basic_type elem_type; |
| 102 | } sequence; |
| 103 | } u; |
| 104 | }; |
| 105 | |
| 106 | struct lttng_enum { |
| 107 | const char *name; |
| 108 | struct lttng_type container_type; |
| 109 | const struct lttng_enum_entry *entries; |
| 110 | unsigned int len; |
| 111 | }; |
| 112 | |
| 113 | /* Event field description */ |
| 114 | |
| 115 | struct lttng_event_field { |
| 116 | const char *name; |
| 117 | struct lttng_type type; |
| 118 | }; |
| 119 | |
| 120 | struct lttng_ctx_field { |
| 121 | struct lttng_event_field event_field; |
| 122 | size_t (*get_size)(size_t offset); |
| 123 | void (*record)(struct lttng_ctx_field *field, |
| 124 | struct lib_ring_buffer_ctx *ctx, |
| 125 | struct ltt_channel *chan); |
| 126 | union { |
| 127 | } u; |
| 128 | void (*destroy)(struct lttng_ctx_field *field); |
| 129 | }; |
| 130 | |
| 131 | struct lttng_ctx { |
| 132 | struct lttng_ctx_field *fields; |
| 133 | unsigned int nr_fields; |
| 134 | unsigned int allocated_fields; |
| 135 | }; |
| 136 | |
| 137 | struct lttng_event_desc { |
| 138 | const char *name; |
| 139 | void *probe_callback; |
| 140 | const struct lttng_event_ctx *ctx; /* context */ |
| 141 | const struct lttng_event_field *fields; /* event payload */ |
| 142 | unsigned int nr_fields; |
| 143 | }; |
| 144 | |
| 145 | struct lttng_probe_desc { |
| 146 | const struct lttng_event_desc *event_desc; |
| 147 | unsigned int nr_events; |
| 148 | struct cds_list_head head; /* chain registered probes */ |
| 149 | }; |
| 150 | |
| 151 | /* |
| 152 | * ltt_event structure is referred to by the tracing fast path. It must be |
| 153 | * kept small. |
| 154 | */ |
| 155 | struct ltt_event { |
| 156 | unsigned int id; |
| 157 | struct ltt_channel *chan; |
| 158 | int enabled; |
| 159 | const struct lttng_event_desc *desc; |
| 160 | void *filter; |
| 161 | struct lttng_ctx *ctx; |
| 162 | enum lttng_ust_instrumentation instrumentation; |
| 163 | union { |
| 164 | } u; |
| 165 | struct cds_list_head list; /* Event list */ |
| 166 | int metadata_dumped:1; |
| 167 | }; |
| 168 | |
| 169 | struct ltt_channel_ops { |
| 170 | struct channel *(*channel_create)(const char *name, |
| 171 | struct ltt_channel *ltt_chan, |
| 172 | void *buf_addr, |
| 173 | size_t subbuf_size, size_t num_subbuf, |
| 174 | unsigned int switch_timer_interval, |
| 175 | unsigned int read_timer_interval, |
| 176 | int *shmid); |
| 177 | void (*channel_destroy)(struct channel *chan); |
| 178 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); |
| 179 | void (*buffer_read_close)(struct lib_ring_buffer *buf); |
| 180 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx, |
| 181 | uint32_t event_id); |
| 182 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
| 183 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, |
| 184 | size_t len); |
| 185 | /* |
| 186 | * packet_avail_size returns the available size in the current |
| 187 | * packet. Note that the size returned is only a hint, since it |
| 188 | * may change due to concurrent writes. |
| 189 | */ |
| 190 | size_t (*packet_avail_size)(struct channel *chan); |
| 191 | //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); |
| 192 | //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); |
| 193 | int (*is_finalized)(struct channel *chan); |
| 194 | int (*is_disabled)(struct channel *chan); |
| 195 | }; |
| 196 | |
| 197 | struct ltt_channel { |
| 198 | unsigned int id; |
| 199 | struct channel *chan; /* Channel buffers */ |
| 200 | int enabled; |
| 201 | struct lttng_ctx *ctx; |
| 202 | /* Event ID management */ |
| 203 | struct ltt_session *session; |
| 204 | int objd; /* Object associated to channel */ |
| 205 | unsigned int free_event_id; /* Next event ID to allocate */ |
| 206 | struct cds_list_head list; /* Channel list */ |
| 207 | struct ltt_channel_ops *ops; |
| 208 | int header_type; /* 0: unset, 1: compact, 2: large */ |
| 209 | int shmid; /* shared memory ID */ |
| 210 | int metadata_dumped:1; |
| 211 | }; |
| 212 | |
| 213 | struct ltt_session { |
| 214 | int active; /* Is trace session active ? */ |
| 215 | int been_active; /* Has trace session been active ? */ |
| 216 | int objd; /* Object associated to session */ |
| 217 | struct ltt_channel *metadata; /* Metadata channel */ |
| 218 | struct cds_list_head chan; /* Channel list head */ |
| 219 | struct cds_list_head events; /* Event list head */ |
| 220 | struct cds_list_head list; /* Session list */ |
| 221 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
| 222 | uuid_t uuid; /* Trace session unique ID */ |
| 223 | int metadata_dumped:1; |
| 224 | }; |
| 225 | |
| 226 | struct ltt_transport { |
| 227 | char *name; |
| 228 | struct cds_list_head node; |
| 229 | struct ltt_channel_ops ops; |
| 230 | }; |
| 231 | |
| 232 | struct ltt_session *ltt_session_create(void); |
| 233 | int ltt_session_enable(struct ltt_session *session); |
| 234 | int ltt_session_disable(struct ltt_session *session); |
| 235 | void ltt_session_destroy(struct ltt_session *session); |
| 236 | |
| 237 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, |
| 238 | const char *transport_name, |
| 239 | void *buf_addr, |
| 240 | size_t subbuf_size, size_t num_subbuf, |
| 241 | unsigned int switch_timer_interval, |
| 242 | unsigned int read_timer_interval); |
| 243 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, |
| 244 | int overwrite, void *buf_addr, |
| 245 | size_t subbuf_size, size_t num_subbuf, |
| 246 | unsigned int switch_timer_interval, |
| 247 | unsigned int read_timer_interval); |
| 248 | |
| 249 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, |
| 250 | struct lttng_ust_event *event_param, |
| 251 | void *filter); |
| 252 | |
| 253 | int ltt_channel_enable(struct ltt_channel *channel); |
| 254 | int ltt_channel_disable(struct ltt_channel *channel); |
| 255 | int ltt_event_enable(struct ltt_event *event); |
| 256 | int ltt_event_disable(struct ltt_event *event); |
| 257 | |
| 258 | void ltt_transport_register(struct ltt_transport *transport); |
| 259 | void ltt_transport_unregister(struct ltt_transport *transport); |
| 260 | |
| 261 | void synchronize_trace(void); |
| 262 | //int ltt_debugfs_abi_init(void); |
| 263 | //void ltt_debugfs_abi_exit(void); |
| 264 | |
| 265 | int ltt_probe_register(struct lttng_probe_desc *desc); |
| 266 | void ltt_probe_unregister(struct lttng_probe_desc *desc); |
| 267 | const struct lttng_event_desc *ltt_event_get(const char *name); |
| 268 | void ltt_event_put(const struct lttng_event_desc *desc); |
| 269 | int ltt_probes_init(void); |
| 270 | void ltt_probes_exit(void); |
| 271 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); |
| 272 | void lttng_remove_context_field(struct lttng_ctx **ctx, |
| 273 | struct lttng_ctx_field *field); |
| 274 | void lttng_destroy_context(struct lttng_ctx *ctx); |
| 275 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
| 276 | |
| 277 | //extern const struct file_operations lttng_tracepoint_list_fops; |
| 278 | |
| 279 | #endif /* _UST_LTTNG_EVENTS_H */ |