1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Holds LTTng per-session event registry.
11 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
12 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
21 #include <urcu/list.h>
22 #include <urcu/hlist.h>
23 #include <uuid/uuid.h>
25 #include <lttng/ust-abi.h>
26 #include <lttng/ust-tracer.h>
32 struct lttng_ust_lib_ring_buffer_ctx
;
35 * Data structures used by tracepoint event declarations, and by the
36 * tracer. Those structures have padding for future extension.
40 * LTTng client type enumeration. Used by the consumer to map the
41 * callbacks from its own address space.
43 enum lttng_client_types
{
44 LTTNG_CLIENT_METADATA
= 0,
45 LTTNG_CLIENT_DISCARD
= 1,
46 LTTNG_CLIENT_OVERWRITE
= 2,
47 LTTNG_NR_CLIENT_TYPES
,
50 /* Type description */
52 /* Update the astract_types name table in lttng-types.c along with this enum */
63 /* Update the string_encodings name table in lttng-types.c along with this enum */
64 enum lttng_string_encodings
{
65 lttng_encode_none
= 0,
66 lttng_encode_UTF8
= 1,
67 lttng_encode_ASCII
= 2,
71 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
72 struct lttng_enum_entry
{
73 unsigned long long start
, end
; /* start and end are inclusive */
75 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
78 #define __type_integer(_type, _byte_order, _base, _encoding) \
80 .atype = atype_integer, \
83 .size = sizeof(_type) * CHAR_BIT, \
84 .alignment = lttng_alignof(_type) * CHAR_BIT, \
85 .signedness = lttng_is_signed_type(_type), \
86 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
88 .encoding = lttng_encode_##_encoding, \
92 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
93 struct lttng_integer_type
{
94 unsigned int size
; /* in bits */
95 unsigned short alignment
; /* in bits */
96 unsigned int signedness
:1;
97 unsigned int reverse_byte_order
:1;
98 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
99 enum lttng_string_encodings encoding
;
100 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
104 * Only float and double are supported. long double is not supported at
107 #define _float_mant_dig(_type) \
108 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
109 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
112 #define __type_float(_type) \
114 .atype = atype_float, \
117 .exp_dig = sizeof(_type) * CHAR_BIT \
118 - _float_mant_dig(_type), \
119 .mant_dig = _float_mant_dig(_type), \
120 .alignment = lttng_alignof(_type) * CHAR_BIT, \
121 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
125 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
126 struct lttng_float_type
{
127 unsigned int exp_dig
; /* exponent digits, in bits */
128 unsigned int mant_dig
; /* mantissa digits, in bits */
129 unsigned short alignment
; /* in bits */
130 unsigned int reverse_byte_order
:1;
131 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
134 #define LTTNG_UST_BASIC_TYPE_PADDING 128
135 union _lttng_basic_type
{
136 struct lttng_integer_type integer
;
141 enum lttng_string_encodings encoding
;
143 struct lttng_float_type _float
;
144 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
147 struct lttng_basic_type
{
148 enum abstract_types atype
;
150 union _lttng_basic_type basic
;
154 #define LTTNG_UST_TYPE_PADDING 128
156 enum abstract_types atype
;
158 union _lttng_basic_type basic
;
160 struct lttng_basic_type elem_type
;
161 unsigned int length
; /* num. elems. */
164 struct lttng_basic_type length_type
;
165 struct lttng_basic_type elem_type
;
167 char padding
[LTTNG_UST_TYPE_PADDING
];
171 #define LTTNG_UST_ENUM_TYPE_PADDING 24
174 struct lttng_type container_type
;
175 const struct lttng_enum_entry
*entries
;
177 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
180 /* Event field description */
182 #define LTTNG_UST_EVENT_FIELD_PADDING 32
183 struct lttng_event_field
{
185 struct lttng_type type
;
186 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
189 #define LTTNG_UST_CTX_FIELD_PADDING 40
190 struct lttng_ctx_field
{
191 struct lttng_event_field event_field
;
192 size_t (*get_size
)(size_t offset
);
193 void (*record
)(struct lttng_ctx_field
*field
,
194 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
195 struct ltt_channel
*chan
);
197 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
199 void (*destroy
)(struct lttng_ctx_field
*field
);
202 #define LTTNG_UST_CTX_PADDING 24
204 struct lttng_ctx_field
*fields
;
205 unsigned int nr_fields
;
206 unsigned int allocated_fields
;
207 char padding
[LTTNG_UST_CTX_PADDING
];
210 #define LTTNG_UST_EVENT_DESC_PADDING 40
211 struct lttng_event_desc
{
213 void *probe_callback
;
214 const struct lttng_event_ctx
*ctx
; /* context */
215 const struct lttng_event_field
*fields
; /* event payload */
216 unsigned int nr_fields
;
217 const int **loglevel
;
218 const char *signature
; /* Argument types/names received */
219 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
222 #define LTTNG_UST_PROBE_DESC_PADDING 40
223 struct lttng_probe_desc
{
224 const char *provider
;
225 const struct lttng_event_desc
**event_desc
;
226 unsigned int nr_events
;
227 struct cds_list_head head
; /* chain registered probes */
228 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
231 /* Data structures used by the tracer. */
234 * Entry describing a per-session active wildcard, along with the event
235 * attribute and channel information configuring the events that need to
238 struct session_wildcard
{
239 struct ltt_channel
*chan
;
240 struct lttng_ctx
*ctx
; /* TODO */
241 struct lttng_ust_event event_param
;
242 struct cds_list_head events
; /* list of events enabled */
243 struct cds_list_head list
; /* per-session list of wildcards */
244 struct cds_list_head session_list
; /* node of session wildcard list */
245 struct wildcard_entry
*entry
;
246 unsigned int enabled
:1;
250 * Entry describing an active wildcard (per name) for all sessions.
252 struct wildcard_entry
{
253 /* node of global wildcards list */
254 struct cds_list_head list
;
255 /* head of session list to which this wildcard apply */
256 struct cds_list_head session_list
;
257 enum lttng_ust_loglevel_type loglevel_type
;
262 struct tp_list_entry
{
263 struct lttng_ust_tracepoint_iter tp
;
264 struct cds_list_head head
;
267 struct lttng_ust_tracepoint_list
{
268 struct tp_list_entry
*iter
;
269 struct cds_list_head head
;
272 struct ust_pending_probe
;
275 * ltt_event structure is referred to by the tracing fast path. It must be
280 struct ltt_channel
*chan
;
282 const struct lttng_event_desc
*desc
;
284 struct lttng_ctx
*ctx
;
285 enum lttng_ust_instrumentation instrumentation
;
288 struct cds_list_head list
; /* Event list */
289 struct cds_list_head wildcard_list
; /* Event list for wildcard */
290 struct ust_pending_probe
*pending_probe
;
291 unsigned int metadata_dumped
:1;
295 struct lttng_ust_shm_handle
;
297 struct ltt_channel_ops
{
298 struct ltt_channel
*(*channel_create
)(const char *name
,
300 size_t subbuf_size
, size_t num_subbuf
,
301 unsigned int switch_timer_interval
,
302 unsigned int read_timer_interval
,
303 int **shm_fd
, int **wait_fd
,
304 uint64_t **memory_map_size
,
305 struct ltt_channel
*chan_priv_init
);
306 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
307 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
308 struct lttng_ust_shm_handle
*handle
,
309 int **shm_fd
, int **wait_fd
,
310 uint64_t **memory_map_size
);
311 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
312 struct lttng_ust_shm_handle
*handle
);
313 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
315 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
316 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
319 * packet_avail_size returns the available size in the current
320 * packet. Note that the size returned is only a hint, since it
321 * may change due to concurrent writes.
323 size_t (*packet_avail_size
)(struct channel
*chan
,
324 struct lttng_ust_shm_handle
*handle
);
325 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
326 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
327 int (*is_finalized
)(struct channel
*chan
);
328 int (*is_disabled
)(struct channel
*chan
);
329 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
334 * The pointers located in this private data are NOT safe to be
335 * dereferenced by the consumer. The only operations the
336 * consumer process is designed to be allowed to do is to read
337 * and perform subbuffer flush.
339 struct channel
*chan
; /* Channel buffers */
341 struct lttng_ctx
*ctx
;
342 /* Event ID management */
343 struct ltt_session
*session
;
344 int objd
; /* Object associated to channel */
345 unsigned int free_event_id
; /* Next event ID to allocate */
346 unsigned int used_event_id
; /* Max allocated event IDs */
347 struct cds_list_head list
; /* Channel list */
348 struct ltt_channel_ops
*ops
;
349 int header_type
; /* 0: unset, 1: compact, 2: large */
350 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
351 unsigned int metadata_dumped
:1;
353 /* Channel ID, available for consumer too */
355 /* Copy of session UUID for consumer (availability through shm) */
356 uuid_t uuid
; /* Trace session unique ID */
360 int active
; /* Is trace session active ? */
361 int been_active
; /* Has trace session been active ? */
362 int objd
; /* Object associated to session */
363 struct ltt_channel
*metadata
; /* Metadata channel */
364 struct cds_list_head chan
; /* Channel list head */
365 struct cds_list_head events
; /* Event list head */
366 struct cds_list_head wildcards
; /* Wildcard list head */
367 struct cds_list_head list
; /* Session list */
368 unsigned int free_chan_id
; /* Next chan ID to allocate */
369 uuid_t uuid
; /* Trace session unique ID */
370 unsigned int metadata_dumped
:1;
373 struct ltt_transport
{
375 struct cds_list_head node
;
376 struct ltt_channel_ops ops
;
379 struct ltt_session
*ltt_session_create(void);
380 int ltt_session_enable(struct ltt_session
*session
);
381 int ltt_session_disable(struct ltt_session
*session
);
382 void ltt_session_destroy(struct ltt_session
*session
);
384 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
385 const char *transport_name
,
387 size_t subbuf_size
, size_t num_subbuf
,
388 unsigned int switch_timer_interval
,
389 unsigned int read_timer_interval
,
390 int **shm_fd
, int **wait_fd
,
391 uint64_t **memory_map_size
,
392 struct ltt_channel
*chan_priv_init
);
393 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
394 int overwrite
, void *buf_addr
,
395 size_t subbuf_size
, size_t num_subbuf
,
396 unsigned int switch_timer_interval
,
397 unsigned int read_timer_interval
,
398 int **shm_fd
, int **wait_fd
,
399 uint64_t **memory_map_size
);
401 int ltt_event_create(struct ltt_channel
*chan
,
402 struct lttng_ust_event
*event_param
,
404 struct ltt_event
**event
);
406 int ltt_channel_enable(struct ltt_channel
*channel
);
407 int ltt_channel_disable(struct ltt_channel
*channel
);
408 int ltt_event_enable(struct ltt_event
*event
);
409 int ltt_event_disable(struct ltt_event
*event
);
411 void ltt_transport_register(struct ltt_transport
*transport
);
412 void ltt_transport_unregister(struct ltt_transport
*transport
);
414 void synchronize_trace(void);
416 int ltt_probe_register(struct lttng_probe_desc
*desc
);
417 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
418 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
419 const struct lttng_event_desc
*ltt_event_get(const char *name
);
420 void ltt_event_put(const struct lttng_event_desc
*desc
);
421 int ltt_probes_init(void);
422 void ltt_probes_exit(void);
423 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
424 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
425 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
426 struct lttng_ctx_field
*field
);
427 void lttng_destroy_context(struct lttng_ctx
*ctx
);
428 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
429 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
430 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
431 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
432 void lttng_context_vtid_reset(void);
433 void lttng_context_vpid_reset(void);
435 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
436 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
437 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
439 struct ltt_transport
*ltt_transport_find(const char *name
);
441 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
442 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
443 struct lttng_ust_tracepoint_iter
*
444 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
446 int ltt_wildcard_enable(struct session_wildcard
*wildcard
);
447 int ltt_wildcard_disable(struct session_wildcard
*wildcard
);
448 int ltt_wildcard_create(struct ltt_channel
*chan
,
449 struct lttng_ust_event
*event_param
,
450 struct session_wildcard
**sl
);
451 int ltt_loglevel_match(const struct lttng_event_desc
*desc
,
452 enum lttng_ust_loglevel_type req_type
,
454 void ltt_probes_create_wildcard_events(struct wildcard_entry
*entry
,
455 struct session_wildcard
*wildcard
);
457 #endif /* _LTTNG_UST_EVENTS_H */