Add support for model.emf.uri event info
[lttng-ust.git] / include / lttng / ust-events.h
1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
3
4 /*
5 * lttng/ust-events.h
6 *
7 * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22 #include <urcu/list.h>
23 #include <urcu/hlist.h>
24 #include <stdint.h>
25 #include <lttng/ust-abi.h>
26 #include <lttng/ust-tracer.h>
27 #include <lttng/ust-endian.h>
28 #include <float.h>
29
30 #define LTTNG_UST_UUID_LEN 16
31
32 struct ltt_channel;
33 struct ltt_session;
34 struct lttng_ust_lib_ring_buffer_ctx;
35
36 /*
37 * Data structures used by tracepoint event declarations, and by the
38 * tracer. Those structures have padding for future extension.
39 */
40
41 /*
42 * LTTng client type enumeration. Used by the consumer to map the
43 * callbacks from its own address space.
44 */
45 enum lttng_client_types {
46 LTTNG_CLIENT_METADATA = 0,
47 LTTNG_CLIENT_DISCARD = 1,
48 LTTNG_CLIENT_OVERWRITE = 2,
49 LTTNG_NR_CLIENT_TYPES,
50 };
51
52 /* Type description */
53
54 /* Update the astract_types name table in lttng-types.c along with this enum */
55 enum abstract_types {
56 atype_integer,
57 atype_enum,
58 atype_array,
59 atype_sequence,
60 atype_string,
61 atype_float,
62 NR_ABSTRACT_TYPES,
63 };
64
65 /* Update the string_encodings name table in lttng-types.c along with this enum */
66 enum lttng_string_encodings {
67 lttng_encode_none = 0,
68 lttng_encode_UTF8 = 1,
69 lttng_encode_ASCII = 2,
70 NR_STRING_ENCODINGS,
71 };
72
73 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
74 struct lttng_enum_entry {
75 unsigned long long start, end; /* start and end are inclusive */
76 const char *string;
77 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
78 };
79
80 #define __type_integer(_type, _byte_order, _base, _encoding) \
81 { \
82 .atype = atype_integer, \
83 .u.basic.integer = \
84 { \
85 .size = sizeof(_type) * CHAR_BIT, \
86 .alignment = lttng_alignof(_type) * CHAR_BIT, \
87 .signedness = lttng_is_signed_type(_type), \
88 .reverse_byte_order = _byte_order != BYTE_ORDER, \
89 .base = _base, \
90 .encoding = lttng_encode_##_encoding, \
91 }, \
92 } \
93
94 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
95 struct lttng_integer_type {
96 unsigned int size; /* in bits */
97 unsigned short alignment; /* in bits */
98 unsigned int signedness:1;
99 unsigned int reverse_byte_order:1;
100 unsigned int base; /* 2, 8, 10, 16, for pretty print */
101 enum lttng_string_encodings encoding;
102 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
103 };
104
105 /*
106 * Only float and double are supported. long double is not supported at
107 * the moment.
108 */
109 #define _float_mant_dig(_type) \
110 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
111 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
112 : 0))
113
114 #define __type_float(_type) \
115 { \
116 .atype = atype_float, \
117 .u.basic._float = \
118 { \
119 .exp_dig = sizeof(_type) * CHAR_BIT \
120 - _float_mant_dig(_type), \
121 .mant_dig = _float_mant_dig(_type), \
122 .alignment = lttng_alignof(_type) * CHAR_BIT, \
123 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
124 }, \
125 } \
126
127 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
128 struct lttng_float_type {
129 unsigned int exp_dig; /* exponent digits, in bits */
130 unsigned int mant_dig; /* mantissa digits, in bits */
131 unsigned short alignment; /* in bits */
132 unsigned int reverse_byte_order:1;
133 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
134 };
135
136 #define LTTNG_UST_BASIC_TYPE_PADDING 128
137 union _lttng_basic_type {
138 struct lttng_integer_type integer;
139 struct {
140 const char *name;
141 } enumeration;
142 struct {
143 enum lttng_string_encodings encoding;
144 } string;
145 struct lttng_float_type _float;
146 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
147 };
148
149 struct lttng_basic_type {
150 enum abstract_types atype;
151 union {
152 union _lttng_basic_type basic;
153 } u;
154 };
155
156 #define LTTNG_UST_TYPE_PADDING 128
157 struct lttng_type {
158 enum abstract_types atype;
159 union {
160 union _lttng_basic_type basic;
161 struct {
162 struct lttng_basic_type elem_type;
163 unsigned int length; /* num. elems. */
164 } array;
165 struct {
166 struct lttng_basic_type length_type;
167 struct lttng_basic_type elem_type;
168 } sequence;
169 char padding[LTTNG_UST_TYPE_PADDING];
170 } u;
171 };
172
173 #define LTTNG_UST_ENUM_TYPE_PADDING 24
174 struct lttng_enum {
175 const char *name;
176 struct lttng_type container_type;
177 const struct lttng_enum_entry *entries;
178 unsigned int len;
179 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
180 };
181
182 /*
183 * Event field description
184 *
185 * IMPORTANT: this structure is part of the ABI between the probe and
186 * UST. Fields need to be only added at the end, never reordered, never
187 * removed.
188 */
189
190 #define LTTNG_UST_EVENT_FIELD_PADDING 28
191 struct lttng_event_field {
192 const char *name;
193 struct lttng_type type;
194 unsigned int nowrite; /* do not write into trace */
195 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
196 };
197
198 #define LTTNG_UST_CTX_FIELD_PADDING 40
199 struct lttng_ctx_field {
200 struct lttng_event_field event_field;
201 size_t (*get_size)(size_t offset);
202 void (*record)(struct lttng_ctx_field *field,
203 struct lttng_ust_lib_ring_buffer_ctx *ctx,
204 struct ltt_channel *chan);
205 union {
206 char padding[LTTNG_UST_CTX_FIELD_PADDING];
207 } u;
208 void (*destroy)(struct lttng_ctx_field *field);
209 };
210
211 #define LTTNG_UST_CTX_PADDING 24
212 struct lttng_ctx {
213 struct lttng_ctx_field *fields;
214 unsigned int nr_fields;
215 unsigned int allocated_fields;
216 char padding[LTTNG_UST_CTX_PADDING];
217 };
218
219 #define LTTNG_UST_EVENT_DESC_PADDING 40
220 struct lttng_event_desc {
221 const char *name;
222 void (*probe_callback)(void);
223 const struct lttng_event_ctx *ctx; /* context */
224 const struct lttng_event_field *fields; /* event payload */
225 unsigned int nr_fields;
226 const int **loglevel;
227 const char *signature; /* Argument types/names received */
228 union {
229 struct {
230 const char **model_emf_uri;
231 } ext;
232 char padding[LTTNG_UST_EVENT_DESC_PADDING];
233 } u;
234 };
235
236 #define LTTNG_UST_PROBE_DESC_PADDING 40
237 struct lttng_probe_desc {
238 const char *provider;
239 const struct lttng_event_desc **event_desc;
240 unsigned int nr_events;
241 struct cds_list_head head; /* chain registered probes */
242 char padding[LTTNG_UST_PROBE_DESC_PADDING];
243 };
244
245 /* Data structures used by the tracer. */
246
247 /*
248 * Entry describing a per-session active wildcard, along with the event
249 * attribute and channel information configuring the events that need to
250 * be enabled.
251 */
252 struct session_wildcard {
253 struct ltt_channel *chan;
254 struct lttng_ctx *ctx; /* TODO */
255 struct lttng_ust_event event_param;
256 struct cds_list_head events; /* list of events enabled */
257 struct cds_list_head list; /* per-session list of wildcards */
258 struct cds_list_head session_list; /* node of session wildcard list */
259 struct wildcard_entry *entry;
260 struct lttng_ust_filter_bytecode *filter_bytecode;
261 unsigned int enabled:1;
262 };
263
264 /*
265 * Entry describing an active wildcard (per name) for all sessions.
266 */
267 struct wildcard_entry {
268 /* node of global wildcards list */
269 struct cds_list_head list;
270 /* head of session list to which this wildcard apply */
271 struct cds_list_head session_list;
272 enum lttng_ust_loglevel_type loglevel_type;
273 struct lttng_ust_filter_bytecode *filter_bytecode;
274 int loglevel;
275 char name[0];
276 };
277
278 struct tp_list_entry {
279 struct lttng_ust_tracepoint_iter tp;
280 struct cds_list_head head;
281 };
282
283 struct lttng_ust_tracepoint_list {
284 struct tp_list_entry *iter;
285 struct cds_list_head head;
286 };
287
288 struct tp_field_list_entry {
289 struct lttng_ust_field_iter field;
290 struct cds_list_head head;
291 };
292
293 struct lttng_ust_field_list {
294 struct tp_field_list_entry *iter;
295 struct cds_list_head head;
296 };
297
298 struct ust_pending_probe;
299 struct ltt_event;
300 struct lttng_ust_filter_bytecode;
301
302 /*
303 * ltt_event structure is referred to by the tracing fast path. It must be
304 * kept small.
305 *
306 * IMPORTANT: this structure is part of the ABI between the probe and
307 * UST. Fields need to be only added at the end, never reordered, never
308 * removed.
309 */
310 struct ltt_event {
311 /* LTTng-UST 2.0 starts here */
312 unsigned int id;
313 struct ltt_channel *chan;
314 int enabled;
315 const struct lttng_event_desc *desc;
316 int (*filter)(void *filter_data, const char *filter_stack_data);
317 struct lttng_ctx *ctx;
318 enum lttng_ust_instrumentation instrumentation;
319 union {
320 } u;
321 struct cds_list_head list; /* Event list */
322 struct cds_list_head wildcard_list; /* Event list for wildcard */
323 struct ust_pending_probe *pending_probe;
324 unsigned int metadata_dumped:1;
325 /* LTTng-UST 2.1 starts here */
326 struct lttng_ust_filter_bytecode *filter_bytecode;
327 void *filter_data;
328 };
329
330 struct channel;
331 struct lttng_ust_shm_handle;
332
333 /*
334 * IMPORTANT: this structure is part of the ABI between the probe and
335 * UST. Fields need to be only added at the end, never reordered, never
336 * removed.
337 */
338 struct ltt_channel_ops {
339 struct ltt_channel *(*channel_create)(const char *name,
340 void *buf_addr,
341 size_t subbuf_size, size_t num_subbuf,
342 unsigned int switch_timer_interval,
343 unsigned int read_timer_interval,
344 int **shm_fd, int **wait_fd,
345 uint64_t **memory_map_size,
346 struct ltt_channel *chan_priv_init);
347 void (*channel_destroy)(struct ltt_channel *ltt_chan);
348 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
349 struct lttng_ust_shm_handle *handle,
350 int **shm_fd, int **wait_fd,
351 uint64_t **memory_map_size);
352 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
353 struct lttng_ust_shm_handle *handle);
354 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
355 uint32_t event_id);
356 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
357 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
358 size_t len);
359 /*
360 * packet_avail_size returns the available size in the current
361 * packet. Note that the size returned is only a hint, since it
362 * may change due to concurrent writes.
363 */
364 size_t (*packet_avail_size)(struct channel *chan,
365 struct lttng_ust_shm_handle *handle);
366 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
367 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
368 int (*is_finalized)(struct channel *chan);
369 int (*is_disabled)(struct channel *chan);
370 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
371 };
372
373 /*
374 * IMPORTANT: this structure is part of the ABI between the probe and
375 * UST. Fields need to be only added at the end, never reordered, never
376 * removed.
377 */
378 struct ltt_channel {
379 /*
380 * The pointers located in this private data are NOT safe to be
381 * dereferenced by the consumer. The only operations the
382 * consumer process is designed to be allowed to do is to read
383 * and perform subbuffer flush.
384 */
385 struct channel *chan; /* Channel buffers */
386 int enabled;
387 struct lttng_ctx *ctx;
388 /* Event ID management */
389 struct ltt_session *session;
390 int objd; /* Object associated to channel */
391 unsigned int free_event_id; /* Next event ID to allocate */
392 unsigned int used_event_id; /* Max allocated event IDs */
393 struct cds_list_head list; /* Channel list */
394 struct ltt_channel_ops *ops;
395 int header_type; /* 0: unset, 1: compact, 2: large */
396 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
397 unsigned int metadata_dumped:1;
398
399 /* Channel ID, available for consumer too */
400 unsigned int id;
401 /* Copy of session UUID for consumer (availability through shm) */
402 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
403 };
404
405 /*
406 * IMPORTANT: this structure is part of the ABI between the probe and
407 * UST. Fields need to be only added at the end, never reordered, never
408 * removed.
409 */
410 struct ltt_session {
411 int active; /* Is trace session active ? */
412 int been_active; /* Has trace session been active ? */
413 int objd; /* Object associated to session */
414 struct ltt_channel *metadata; /* Metadata channel */
415 struct cds_list_head chan; /* Channel list head */
416 struct cds_list_head events; /* Event list head */
417 struct cds_list_head wildcards; /* Wildcard list head */
418 struct cds_list_head list; /* Session list */
419 unsigned int free_chan_id; /* Next chan ID to allocate */
420 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
421 unsigned int metadata_dumped:1;
422 };
423
424 struct ltt_transport {
425 char *name;
426 struct cds_list_head node;
427 struct ltt_channel_ops ops;
428 };
429
430 struct ltt_session *ltt_session_create(void);
431 int ltt_session_enable(struct ltt_session *session);
432 int ltt_session_disable(struct ltt_session *session);
433 void ltt_session_destroy(struct ltt_session *session);
434
435 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
436 const char *transport_name,
437 void *buf_addr,
438 size_t subbuf_size, size_t num_subbuf,
439 unsigned int switch_timer_interval,
440 unsigned int read_timer_interval,
441 int **shm_fd, int **wait_fd,
442 uint64_t **memory_map_size,
443 struct ltt_channel *chan_priv_init);
444 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
445 int overwrite, void *buf_addr,
446 size_t subbuf_size, size_t num_subbuf,
447 unsigned int switch_timer_interval,
448 unsigned int read_timer_interval,
449 int **shm_fd, int **wait_fd,
450 uint64_t **memory_map_size);
451
452 int ltt_event_create(struct ltt_channel *chan,
453 struct lttng_ust_event *event_param,
454 struct ltt_event **event);
455
456 int ltt_channel_enable(struct ltt_channel *channel);
457 int ltt_channel_disable(struct ltt_channel *channel);
458 int ltt_event_enable(struct ltt_event *event);
459 int ltt_event_disable(struct ltt_event *event);
460
461 void ltt_transport_register(struct ltt_transport *transport);
462 void ltt_transport_unregister(struct ltt_transport *transport);
463
464 void synchronize_trace(void);
465
466 int ltt_probe_register(struct lttng_probe_desc *desc);
467 void ltt_probe_unregister(struct lttng_probe_desc *desc);
468 int pending_probe_fix_events(const struct lttng_event_desc *desc);
469 const struct lttng_event_desc *ltt_event_get(const char *name);
470 void ltt_event_put(const struct lttng_event_desc *desc);
471 int ltt_probes_init(void);
472 void ltt_probes_exit(void);
473 int lttng_find_context(struct lttng_ctx *ctx, const char *name);
474 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
475 void lttng_remove_context_field(struct lttng_ctx **ctx_p,
476 struct lttng_ctx_field *field);
477 void lttng_destroy_context(struct lttng_ctx *ctx);
478 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
479 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
480 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
481 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
482 void lttng_context_vtid_reset(void);
483 void lttng_context_vpid_reset(void);
484
485 extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
486 extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
487 extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
488
489 struct ltt_transport *ltt_transport_find(const char *name);
490
491 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
492 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
493 struct lttng_ust_tracepoint_iter *
494 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
495 int ltt_probes_get_field_list(struct lttng_ust_field_list *list);
496 void ltt_probes_prune_field_list(struct lttng_ust_field_list *list);
497 struct lttng_ust_field_iter *
498 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
499
500 int ltt_wildcard_enable(struct session_wildcard *wildcard);
501 int ltt_wildcard_disable(struct session_wildcard *wildcard);
502 int ltt_wildcard_create(struct ltt_channel *chan,
503 struct lttng_ust_event *event_param,
504 struct session_wildcard **sl);
505 int ltt_loglevel_match(const struct lttng_event_desc *desc,
506 enum lttng_ust_loglevel_type req_type,
507 int req_loglevel);
508 void ltt_probes_create_wildcard_events(struct wildcard_entry *entry,
509 struct session_wildcard *wildcard);
510 int lttng_filter_event_attach_bytecode(struct ltt_event *event,
511 struct lttng_ust_filter_bytecode *filter);
512 int lttng_filter_wildcard_attach_bytecode(struct session_wildcard *wildcard,
513 struct lttng_ust_filter_bytecode *filter);
514 void lttng_filter_event_link_bytecode(struct ltt_event *event,
515 struct lttng_ust_filter_bytecode *filter_bytecode);
516 void lttng_filter_wildcard_link_bytecode(struct session_wildcard *wildcard);
517
518 #endif /* _LTTNG_UST_EVENTS_H */
This page took 0.039239 seconds and 5 git commands to generate.