Commit | Line | Data |
---|---|---|
51489cad MD |
1 | #ifndef _LTTNG_UST_EVENTS_H |
2 | #define _LTTNG_UST_EVENTS_H | |
8020ceb5 MD |
3 | |
4 | /* | |
51489cad | 5 | * lttng/ust-events.h |
8020ceb5 MD |
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 | ||
9f3fdbc6 MD |
14 | #include <urcu/list.h> |
15 | #include <uuid/uuid.h> | |
16 | #include <stdint.h> | |
4318ae1b MD |
17 | #include <lttng/ust-abi.h> |
18 | #include <lttng/ust-tracer.h> | |
20f1eee7 MD |
19 | #include <endian.h> |
20 | #include <float.h> | |
51489cad | 21 | #include <lttng/tracepoint-internal.h> |
8020ceb5 | 22 | |
8020ceb5 MD |
23 | struct ltt_channel; |
24 | struct ltt_session; | |
4cfec15c | 25 | struct lttng_ust_lib_ring_buffer_ctx; |
8020ceb5 | 26 | |
c1fca457 MD |
27 | /* |
28 | * LTTng client type enumeration. Used by the consumer to map the | |
29 | * callbacks from its own address space. | |
30 | */ | |
31 | enum lttng_client_types { | |
32 | LTTNG_CLIENT_METADATA = 0, | |
33 | LTTNG_CLIENT_DISCARD = 1, | |
34 | LTTNG_CLIENT_OVERWRITE = 2, | |
35 | LTTNG_NR_CLIENT_TYPES, | |
36 | }; | |
37 | ||
8020ceb5 MD |
38 | /* Type description */ |
39 | ||
40 | /* Update the astract_types name table in lttng-types.c along with this enum */ | |
41 | enum abstract_types { | |
42 | atype_integer, | |
43 | atype_enum, | |
44 | atype_array, | |
45 | atype_sequence, | |
46 | atype_string, | |
20f1eee7 | 47 | atype_float, |
8020ceb5 MD |
48 | NR_ABSTRACT_TYPES, |
49 | }; | |
50 | ||
51 | /* Update the string_encodings name table in lttng-types.c along with this enum */ | |
52 | enum lttng_string_encodings { | |
53 | lttng_encode_none = 0, | |
54 | lttng_encode_UTF8 = 1, | |
55 | lttng_encode_ASCII = 2, | |
56 | NR_STRING_ENCODINGS, | |
57 | }; | |
58 | ||
59 | struct lttng_enum_entry { | |
60 | unsigned long long start, end; /* start and end are inclusive */ | |
61 | const char *string; | |
62 | }; | |
63 | ||
64 | #define __type_integer(_type, _byte_order, _base, _encoding) \ | |
65 | { \ | |
66 | .atype = atype_integer, \ | |
67 | .u.basic.integer = \ | |
68 | { \ | |
69 | .size = sizeof(_type) * CHAR_BIT, \ | |
1dbfff0c MD |
70 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
71 | .signedness = lttng_is_signed_type(_type), \ | |
8020ceb5 MD |
72 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ |
73 | .base = _base, \ | |
74 | .encoding = lttng_encode_##_encoding, \ | |
75 | }, \ | |
76 | } \ | |
77 | ||
78 | struct lttng_integer_type { | |
79 | unsigned int size; /* in bits */ | |
80 | unsigned short alignment; /* in bits */ | |
81 | unsigned int signedness:1; | |
82 | unsigned int reverse_byte_order:1; | |
83 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ | |
84 | enum lttng_string_encodings encoding; | |
85 | }; | |
86 | ||
d3ed854b MD |
87 | /* |
88 | * Only float and double are supported. long double is not supported at | |
89 | * the moment. | |
90 | */ | |
20f1eee7 MD |
91 | #define _float_mant_dig(_type) \ |
92 | (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \ | |
93 | : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \ | |
d3ed854b | 94 | : 0)) |
20f1eee7 MD |
95 | |
96 | #define __type_float(_type) \ | |
97 | { \ | |
98 | .atype = atype_float, \ | |
99 | .u.basic._float = \ | |
100 | { \ | |
101 | .exp_dig = sizeof(_type) * CHAR_BIT \ | |
102 | - _float_mant_dig(_type), \ | |
103 | .mant_dig = _float_mant_dig(_type), \ | |
1dbfff0c | 104 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
20f1eee7 MD |
105 | .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \ |
106 | }, \ | |
107 | } \ | |
108 | ||
109 | struct lttng_float_type { | |
110 | unsigned int exp_dig; /* exponent digits, in bits */ | |
111 | unsigned int mant_dig; /* mantissa digits, in bits */ | |
112 | unsigned short alignment; /* in bits */ | |
113 | unsigned int reverse_byte_order:1; | |
114 | }; | |
115 | ||
8020ceb5 MD |
116 | union _lttng_basic_type { |
117 | struct lttng_integer_type integer; | |
118 | struct { | |
119 | const char *name; | |
120 | } enumeration; | |
121 | struct { | |
122 | enum lttng_string_encodings encoding; | |
123 | } string; | |
20f1eee7 | 124 | struct lttng_float_type _float; |
8020ceb5 MD |
125 | }; |
126 | ||
127 | struct lttng_basic_type { | |
128 | enum abstract_types atype; | |
129 | union { | |
130 | union _lttng_basic_type basic; | |
131 | } u; | |
132 | }; | |
133 | ||
134 | struct lttng_type { | |
135 | enum abstract_types atype; | |
136 | union { | |
137 | union _lttng_basic_type basic; | |
138 | struct { | |
139 | struct lttng_basic_type elem_type; | |
140 | unsigned int length; /* num. elems. */ | |
141 | } array; | |
142 | struct { | |
143 | struct lttng_basic_type length_type; | |
144 | struct lttng_basic_type elem_type; | |
145 | } sequence; | |
146 | } u; | |
147 | }; | |
148 | ||
149 | struct lttng_enum { | |
150 | const char *name; | |
151 | struct lttng_type container_type; | |
152 | const struct lttng_enum_entry *entries; | |
153 | unsigned int len; | |
154 | }; | |
155 | ||
156 | /* Event field description */ | |
157 | ||
158 | struct lttng_event_field { | |
159 | const char *name; | |
160 | struct lttng_type type; | |
161 | }; | |
162 | ||
163 | struct lttng_ctx_field { | |
164 | struct lttng_event_field event_field; | |
165 | size_t (*get_size)(size_t offset); | |
166 | void (*record)(struct lttng_ctx_field *field, | |
4cfec15c | 167 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
8020ceb5 MD |
168 | struct ltt_channel *chan); |
169 | union { | |
8020ceb5 MD |
170 | } u; |
171 | void (*destroy)(struct lttng_ctx_field *field); | |
172 | }; | |
173 | ||
174 | struct lttng_ctx { | |
175 | struct lttng_ctx_field *fields; | |
176 | unsigned int nr_fields; | |
177 | unsigned int allocated_fields; | |
178 | }; | |
179 | ||
180 | struct lttng_event_desc { | |
181 | const char *name; | |
182 | void *probe_callback; | |
183 | const struct lttng_event_ctx *ctx; /* context */ | |
184 | const struct lttng_event_field *fields; /* event payload */ | |
185 | unsigned int nr_fields; | |
8020ceb5 MD |
186 | }; |
187 | ||
188 | struct lttng_probe_desc { | |
189 | const struct lttng_event_desc *event_desc; | |
190 | unsigned int nr_events; | |
9f3fdbc6 | 191 | struct cds_list_head head; /* chain registered probes */ |
8020ceb5 MD |
192 | }; |
193 | ||
8165c8da MD |
194 | struct ust_pending_probe; |
195 | ||
8020ceb5 MD |
196 | /* |
197 | * ltt_event structure is referred to by the tracing fast path. It must be | |
198 | * kept small. | |
199 | */ | |
200 | struct ltt_event { | |
201 | unsigned int id; | |
202 | struct ltt_channel *chan; | |
976fe9ea | 203 | int enabled; |
8020ceb5 MD |
204 | const struct lttng_event_desc *desc; |
205 | void *filter; | |
206 | struct lttng_ctx *ctx; | |
9f3fdbc6 | 207 | enum lttng_ust_instrumentation instrumentation; |
8020ceb5 | 208 | union { |
8020ceb5 | 209 | } u; |
9f3fdbc6 | 210 | struct cds_list_head list; /* Event list */ |
8165c8da | 211 | struct ust_pending_probe *pending_probe; |
8020ceb5 MD |
212 | int metadata_dumped:1; |
213 | }; | |
214 | ||
8d8a24c8 | 215 | struct channel; |
38fae1d3 | 216 | struct lttng_ust_shm_handle; |
8d8a24c8 | 217 | |
8020ceb5 | 218 | struct ltt_channel_ops { |
1d498196 | 219 | struct ltt_channel *(*channel_create)(const char *name, |
8020ceb5 MD |
220 | void *buf_addr, |
221 | size_t subbuf_size, size_t num_subbuf, | |
222 | unsigned int switch_timer_interval, | |
193183fb MD |
223 | unsigned int read_timer_interval, |
224 | int *shm_fd, int *wait_fd, | |
d028eddb MD |
225 | uint64_t *memory_map_size, |
226 | struct ltt_channel *chan_priv_init); | |
1d498196 | 227 | void (*channel_destroy)(struct ltt_channel *ltt_chan); |
4cfec15c | 228 | struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan, |
38fae1d3 | 229 | struct lttng_ust_shm_handle *handle, |
381c0f1e MD |
230 | int *shm_fd, int *wait_fd, |
231 | uint64_t *memory_map_size); | |
4cfec15c | 232 | void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf, |
38fae1d3 | 233 | struct lttng_ust_shm_handle *handle); |
4cfec15c | 234 | int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx, |
8020ceb5 | 235 | uint32_t event_id); |
4cfec15c MD |
236 | void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx); |
237 | void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src, | |
8020ceb5 MD |
238 | size_t len); |
239 | /* | |
240 | * packet_avail_size returns the available size in the current | |
241 | * packet. Note that the size returned is only a hint, since it | |
242 | * may change due to concurrent writes. | |
243 | */ | |
1d498196 | 244 | size_t (*packet_avail_size)(struct channel *chan, |
38fae1d3 | 245 | struct lttng_ust_shm_handle *handle); |
9f3fdbc6 MD |
246 | //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); |
247 | //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); | |
8020ceb5 MD |
248 | int (*is_finalized)(struct channel *chan); |
249 | int (*is_disabled)(struct channel *chan); | |
38fae1d3 | 250 | int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle); |
8020ceb5 MD |
251 | }; |
252 | ||
253 | struct ltt_channel { | |
a3f61e7f MD |
254 | /* |
255 | * The pointers located in this private data are NOT safe to be | |
256 | * dereferenced by the consumer. The only operations the | |
257 | * consumer process is designed to be allowed to do is to read | |
258 | * and perform subbuffer flush. | |
259 | */ | |
8020ceb5 | 260 | struct channel *chan; /* Channel buffers */ |
976fe9ea | 261 | int enabled; |
8020ceb5 MD |
262 | struct lttng_ctx *ctx; |
263 | /* Event ID management */ | |
264 | struct ltt_session *session; | |
0a42beb6 | 265 | int objd; /* Object associated to channel */ |
8020ceb5 | 266 | unsigned int free_event_id; /* Next event ID to allocate */ |
8165c8da | 267 | unsigned int used_event_id; /* Max allocated event IDs */ |
9f3fdbc6 | 268 | struct cds_list_head list; /* Channel list */ |
8020ceb5 MD |
269 | struct ltt_channel_ops *ops; |
270 | int header_type; /* 0: unset, 1: compact, 2: large */ | |
38fae1d3 | 271 | struct lttng_ust_shm_handle *handle; /* shared-memory handle */ |
8020ceb5 | 272 | int metadata_dumped:1; |
a3f61e7f MD |
273 | |
274 | /* Channel ID, available for consumer too */ | |
275 | unsigned int id; | |
276 | /* Copy of session UUID for consumer (availability through shm) */ | |
277 | uuid_t uuid; /* Trace session unique ID */ | |
8020ceb5 MD |
278 | }; |
279 | ||
280 | struct ltt_session { | |
281 | int active; /* Is trace session active ? */ | |
282 | int been_active; /* Has trace session been active ? */ | |
0a42beb6 | 283 | int objd; /* Object associated to session */ |
8020ceb5 | 284 | struct ltt_channel *metadata; /* Metadata channel */ |
9f3fdbc6 MD |
285 | struct cds_list_head chan; /* Channel list head */ |
286 | struct cds_list_head events; /* Event list head */ | |
287 | struct cds_list_head list; /* Session list */ | |
8020ceb5 | 288 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
9f3fdbc6 | 289 | uuid_t uuid; /* Trace session unique ID */ |
8020ceb5 MD |
290 | int metadata_dumped:1; |
291 | }; | |
292 | ||
293 | struct ltt_transport { | |
294 | char *name; | |
9f3fdbc6 | 295 | struct cds_list_head node; |
8020ceb5 MD |
296 | struct ltt_channel_ops ops; |
297 | }; | |
298 | ||
51489cad MD |
299 | struct ltt_tracepoint_list { |
300 | struct tracepoint_iter iter; | |
301 | int got_first; | |
302 | }; | |
303 | ||
8020ceb5 | 304 | struct ltt_session *ltt_session_create(void); |
976fe9ea MD |
305 | int ltt_session_enable(struct ltt_session *session); |
306 | int ltt_session_disable(struct ltt_session *session); | |
8020ceb5 MD |
307 | void ltt_session_destroy(struct ltt_session *session); |
308 | ||
309 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, | |
310 | const char *transport_name, | |
311 | void *buf_addr, | |
312 | size_t subbuf_size, size_t num_subbuf, | |
313 | unsigned int switch_timer_interval, | |
193183fb MD |
314 | unsigned int read_timer_interval, |
315 | int *shm_fd, int *wait_fd, | |
d028eddb MD |
316 | uint64_t *memory_map_size, |
317 | struct ltt_channel *chan_priv_init); | |
8020ceb5 MD |
318 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, |
319 | int overwrite, void *buf_addr, | |
320 | size_t subbuf_size, size_t num_subbuf, | |
321 | unsigned int switch_timer_interval, | |
193183fb MD |
322 | unsigned int read_timer_interval, |
323 | int *shm_fd, int *wait_fd, | |
324 | uint64_t *memory_map_size); | |
8020ceb5 MD |
325 | |
326 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, | |
9f3fdbc6 | 327 | struct lttng_ust_event *event_param, |
8020ceb5 MD |
328 | void *filter); |
329 | ||
976fe9ea MD |
330 | int ltt_channel_enable(struct ltt_channel *channel); |
331 | int ltt_channel_disable(struct ltt_channel *channel); | |
332 | int ltt_event_enable(struct ltt_event *event); | |
333 | int ltt_event_disable(struct ltt_event *event); | |
334 | ||
8020ceb5 MD |
335 | void ltt_transport_register(struct ltt_transport *transport); |
336 | void ltt_transport_unregister(struct ltt_transport *transport); | |
337 | ||
4b4de73e | 338 | void synchronize_trace(void); |
8020ceb5 MD |
339 | |
340 | int ltt_probe_register(struct lttng_probe_desc *desc); | |
341 | void ltt_probe_unregister(struct lttng_probe_desc *desc); | |
8165c8da | 342 | int pending_probe_fix_events(const struct lttng_event_desc *desc); |
8020ceb5 MD |
343 | const struct lttng_event_desc *ltt_event_get(const char *name); |
344 | void ltt_event_put(const struct lttng_event_desc *desc); | |
345 | int ltt_probes_init(void); | |
346 | void ltt_probes_exit(void); | |
8173ec7c MD |
347 | int lttng_find_context(struct lttng_ctx *ctx, const char *name); |
348 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p); | |
349 | void lttng_remove_context_field(struct lttng_ctx **ctx_p, | |
8020ceb5 MD |
350 | struct lttng_ctx_field *field); |
351 | void lttng_destroy_context(struct lttng_ctx *ctx); | |
3b402b40 | 352 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
c1ef86f0 | 353 | int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); |
8173ec7c | 354 | int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); |
4847e9bb | 355 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); |
a93bfc45 | 356 | void lttng_context_vtid_reset(void); |
c1ef86f0 | 357 | void lttng_context_vpid_reset(void); |
9f3fdbc6 | 358 | |
7a784989 MD |
359 | const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata; |
360 | const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard; | |
361 | const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite; | |
c1fca457 MD |
362 | |
363 | struct cds_list_head ltt_transport_list; | |
364 | struct ltt_transport *ltt_transport_find(const char *name); | |
365 | ||
51489cad | 366 | #endif /* _LTTNG_UST_EVENTS_H */ |