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