1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
7 * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Holds LTTng per-session event registry.
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
22 #include <urcu/list.h>
23 #include <urcu/hlist.h>
25 #include <lttng/ust-abi.h>
26 #include <lttng/ust-tracer.h>
27 #include <lttng/ust-endian.h>
30 #define LTTNG_UST_UUID_LEN 16
34 struct lttng_ust_lib_ring_buffer_ctx
;
37 * Data structures used by tracepoint event declarations, and by the
38 * tracer. Those structures have padding for future extension.
42 * LTTng client type enumeration. Used by the consumer to map the
43 * callbacks from its own address space.
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
,
52 /* Type description */
54 /* Update the astract_types name table in lttng-types.c along with this enum */
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,
73 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
74 struct lttng_enum_entry
{
75 unsigned long long start
, end
; /* start and end are inclusive */
77 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
80 #define __type_integer(_type, _byte_order, _base, _encoding) \
82 .atype = atype_integer, \
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, \
90 .encoding = lttng_encode_##_encoding, \
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
];
106 * Only float and double are supported. long double is not supported at
109 #define _float_mant_dig(_type) \
110 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
111 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
114 #define __type_float(_type) \
116 .atype = atype_float, \
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, \
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
];
136 #define LTTNG_UST_BASIC_TYPE_PADDING 128
137 union _lttng_basic_type
{
138 struct lttng_integer_type integer
;
143 enum lttng_string_encodings encoding
;
145 struct lttng_float_type _float
;
146 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
149 struct lttng_basic_type
{
150 enum abstract_types atype
;
152 union _lttng_basic_type basic
;
156 #define LTTNG_UST_TYPE_PADDING 128
158 enum abstract_types atype
;
160 union _lttng_basic_type basic
;
162 struct lttng_basic_type elem_type
;
163 unsigned int length
; /* num. elems. */
166 struct lttng_basic_type length_type
;
167 struct lttng_basic_type elem_type
;
169 char padding
[LTTNG_UST_TYPE_PADDING
];
173 #define LTTNG_UST_ENUM_TYPE_PADDING 24
176 struct lttng_type container_type
;
177 const struct lttng_enum_entry
*entries
;
179 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
182 /* Event field description */
184 #define LTTNG_UST_EVENT_FIELD_PADDING 28
185 struct lttng_event_field
{
187 struct lttng_type type
;
188 unsigned int written
; /* written into trace */
189 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
192 #define LTTNG_UST_CTX_FIELD_PADDING 40
193 struct lttng_ctx_field
{
194 struct lttng_event_field event_field
;
195 size_t (*get_size
)(size_t offset
);
196 void (*record
)(struct lttng_ctx_field
*field
,
197 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
198 struct ltt_channel
*chan
);
200 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
202 void (*destroy
)(struct lttng_ctx_field
*field
);
205 #define LTTNG_UST_CTX_PADDING 24
207 struct lttng_ctx_field
*fields
;
208 unsigned int nr_fields
;
209 unsigned int allocated_fields
;
210 char padding
[LTTNG_UST_CTX_PADDING
];
213 #define LTTNG_UST_EVENT_DESC_PADDING 40
214 struct lttng_event_desc
{
216 void (*probe_callback
)(void);
217 const struct lttng_event_ctx
*ctx
; /* context */
218 const struct lttng_event_field
*fields
; /* event payload */
219 unsigned int nr_fields
;
220 const int **loglevel
;
221 const char *signature
; /* Argument types/names received */
222 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
225 #define LTTNG_UST_PROBE_DESC_PADDING 40
226 struct lttng_probe_desc
{
227 const char *provider
;
228 const struct lttng_event_desc
**event_desc
;
229 unsigned int nr_events
;
230 struct cds_list_head head
; /* chain registered probes */
231 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
234 /* Data structures used by the tracer. */
237 * Entry describing a per-session active wildcard, along with the event
238 * attribute and channel information configuring the events that need to
241 struct session_wildcard
{
242 struct ltt_channel
*chan
;
243 struct lttng_ctx
*ctx
; /* TODO */
244 struct lttng_ust_event event_param
;
245 struct cds_list_head events
; /* list of events enabled */
246 struct cds_list_head list
; /* per-session list of wildcards */
247 struct cds_list_head session_list
; /* node of session wildcard list */
248 struct wildcard_entry
*entry
;
249 struct lttng_ust_filter_bytecode
*filter_bytecode
;
250 unsigned int enabled
:1;
254 * Entry describing an active wildcard (per name) for all sessions.
256 struct wildcard_entry
{
257 /* node of global wildcards list */
258 struct cds_list_head list
;
259 /* head of session list to which this wildcard apply */
260 struct cds_list_head session_list
;
261 enum lttng_ust_loglevel_type loglevel_type
;
262 struct lttng_ust_filter_bytecode
*filter_bytecode
;
267 struct tp_list_entry
{
268 struct lttng_ust_tracepoint_iter tp
;
269 struct cds_list_head head
;
272 struct lttng_ust_tracepoint_list
{
273 struct tp_list_entry
*iter
;
274 struct cds_list_head head
;
277 struct tp_field_list_entry
{
278 struct lttng_ust_field_iter field
;
279 struct cds_list_head head
;
282 struct lttng_ust_field_list
{
283 struct tp_field_list_entry
*iter
;
284 struct cds_list_head head
;
287 struct ust_pending_probe
;
289 struct lttng_ust_filter_bytecode
;
292 * ltt_event structure is referred to by the tracing fast path. It must be
297 struct ltt_channel
*chan
;
299 const struct lttng_event_desc
*desc
;
300 int (*filter
)(void *filter_data
, const char *filter_stack_data
);
302 struct lttng_ctx
*ctx
;
303 enum lttng_ust_instrumentation instrumentation
;
306 struct cds_list_head list
; /* Event list */
307 struct cds_list_head wildcard_list
; /* Event list for wildcard */
308 struct ust_pending_probe
*pending_probe
;
309 struct lttng_ust_filter_bytecode
*filter_bytecode
;
310 unsigned int metadata_dumped
:1;
314 struct lttng_ust_shm_handle
;
316 struct ltt_channel_ops
{
317 struct ltt_channel
*(*channel_create
)(const char *name
,
319 size_t subbuf_size
, size_t num_subbuf
,
320 unsigned int switch_timer_interval
,
321 unsigned int read_timer_interval
,
322 int **shm_fd
, int **wait_fd
,
323 uint64_t **memory_map_size
,
324 struct ltt_channel
*chan_priv_init
);
325 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
326 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
327 struct lttng_ust_shm_handle
*handle
,
328 int **shm_fd
, int **wait_fd
,
329 uint64_t **memory_map_size
);
330 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
331 struct lttng_ust_shm_handle
*handle
);
332 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
334 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
335 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
338 * packet_avail_size returns the available size in the current
339 * packet. Note that the size returned is only a hint, since it
340 * may change due to concurrent writes.
342 size_t (*packet_avail_size
)(struct channel
*chan
,
343 struct lttng_ust_shm_handle
*handle
);
344 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
345 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
346 int (*is_finalized
)(struct channel
*chan
);
347 int (*is_disabled
)(struct channel
*chan
);
348 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
353 * The pointers located in this private data are NOT safe to be
354 * dereferenced by the consumer. The only operations the
355 * consumer process is designed to be allowed to do is to read
356 * and perform subbuffer flush.
358 struct channel
*chan
; /* Channel buffers */
360 struct lttng_ctx
*ctx
;
361 /* Event ID management */
362 struct ltt_session
*session
;
363 int objd
; /* Object associated to channel */
364 unsigned int free_event_id
; /* Next event ID to allocate */
365 unsigned int used_event_id
; /* Max allocated event IDs */
366 struct cds_list_head list
; /* Channel list */
367 struct ltt_channel_ops
*ops
;
368 int header_type
; /* 0: unset, 1: compact, 2: large */
369 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
370 unsigned int metadata_dumped
:1;
372 /* Channel ID, available for consumer too */
374 /* Copy of session UUID for consumer (availability through shm) */
375 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
379 int active
; /* Is trace session active ? */
380 int been_active
; /* Has trace session been active ? */
381 int objd
; /* Object associated to session */
382 struct ltt_channel
*metadata
; /* Metadata channel */
383 struct cds_list_head chan
; /* Channel list head */
384 struct cds_list_head events
; /* Event list head */
385 struct cds_list_head wildcards
; /* Wildcard list head */
386 struct cds_list_head list
; /* Session list */
387 unsigned int free_chan_id
; /* Next chan ID to allocate */
388 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
389 unsigned int metadata_dumped
:1;
392 struct ltt_transport
{
394 struct cds_list_head node
;
395 struct ltt_channel_ops ops
;
398 struct ltt_session
*ltt_session_create(void);
399 int ltt_session_enable(struct ltt_session
*session
);
400 int ltt_session_disable(struct ltt_session
*session
);
401 void ltt_session_destroy(struct ltt_session
*session
);
403 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
404 const char *transport_name
,
406 size_t subbuf_size
, size_t num_subbuf
,
407 unsigned int switch_timer_interval
,
408 unsigned int read_timer_interval
,
409 int **shm_fd
, int **wait_fd
,
410 uint64_t **memory_map_size
,
411 struct ltt_channel
*chan_priv_init
);
412 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
413 int overwrite
, void *buf_addr
,
414 size_t subbuf_size
, size_t num_subbuf
,
415 unsigned int switch_timer_interval
,
416 unsigned int read_timer_interval
,
417 int **shm_fd
, int **wait_fd
,
418 uint64_t **memory_map_size
);
420 int ltt_event_create(struct ltt_channel
*chan
,
421 struct lttng_ust_event
*event_param
,
422 struct ltt_event
**event
);
424 int ltt_channel_enable(struct ltt_channel
*channel
);
425 int ltt_channel_disable(struct ltt_channel
*channel
);
426 int ltt_event_enable(struct ltt_event
*event
);
427 int ltt_event_disable(struct ltt_event
*event
);
429 void ltt_transport_register(struct ltt_transport
*transport
);
430 void ltt_transport_unregister(struct ltt_transport
*transport
);
432 void synchronize_trace(void);
434 int ltt_probe_register(struct lttng_probe_desc
*desc
);
435 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
436 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
437 const struct lttng_event_desc
*ltt_event_get(const char *name
);
438 void ltt_event_put(const struct lttng_event_desc
*desc
);
439 int ltt_probes_init(void);
440 void ltt_probes_exit(void);
441 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
442 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
443 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
444 struct lttng_ctx_field
*field
);
445 void lttng_destroy_context(struct lttng_ctx
*ctx
);
446 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
447 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
448 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
449 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
450 void lttng_context_vtid_reset(void);
451 void lttng_context_vpid_reset(void);
453 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
454 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
455 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
457 struct ltt_transport
*ltt_transport_find(const char *name
);
459 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
460 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
461 struct lttng_ust_tracepoint_iter
*
462 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
463 int ltt_probes_get_field_list(struct lttng_ust_field_list
*list
);
464 void ltt_probes_prune_field_list(struct lttng_ust_field_list
*list
);
465 struct lttng_ust_field_iter
*
466 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
468 int ltt_wildcard_enable(struct session_wildcard
*wildcard
);
469 int ltt_wildcard_disable(struct session_wildcard
*wildcard
);
470 int ltt_wildcard_create(struct ltt_channel
*chan
,
471 struct lttng_ust_event
*event_param
,
472 struct session_wildcard
**sl
);
473 int ltt_loglevel_match(const struct lttng_event_desc
*desc
,
474 enum lttng_ust_loglevel_type req_type
,
476 void ltt_probes_create_wildcard_events(struct wildcard_entry
*entry
,
477 struct session_wildcard
*wildcard
);
478 int lttng_filter_event_attach_bytecode(struct ltt_event
*event
,
479 struct lttng_ust_filter_bytecode
*filter
);
480 int lttng_filter_wildcard_attach_bytecode(struct session_wildcard
*wildcard
,
481 struct lttng_ust_filter_bytecode
*filter
);
482 void lttng_filter_event_link_bytecode(struct ltt_event
*event
,
483 struct lttng_ust_filter_bytecode
*filter_bytecode
);
484 void lttng_filter_wildcard_link_bytecode(struct session_wildcard
*wildcard
);
486 #endif /* _LTTNG_UST_EVENTS_H */