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 * Dual LGPL v2.1/GPL v2 license.
14 #include <urcu/list.h>
15 #include <uuid/uuid.h>
17 #include <lttng/ust-abi.h>
18 #include <lttng/ust-tracer.h>
21 #include <lttng/tracepoint-internal.h>
25 struct lttng_ust_lib_ring_buffer_ctx
;
28 * LTTng client type enumeration. Used by the consumer to map the
29 * callbacks from its own address space.
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
,
38 /* Type description */
40 /* Update the astract_types name table in lttng-types.c along with this enum */
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,
59 struct lttng_enum_entry
{
60 unsigned long long start
, end
; /* start and end are inclusive */
64 #define __type_integer(_type, _byte_order, _base, _encoding) \
66 .atype = atype_integer, \
69 .size = sizeof(_type) * CHAR_BIT, \
70 .alignment = lttng_alignof(_type) * CHAR_BIT, \
71 .signedness = lttng_is_signed_type(_type), \
72 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
74 .encoding = lttng_encode_##_encoding, \
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
;
88 * Only float and double are supported. long double is not supported at
91 #define _float_mant_dig(_type) \
92 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
93 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
96 #define __type_float(_type) \
98 .atype = atype_float, \
101 .exp_dig = sizeof(_type) * CHAR_BIT \
102 - _float_mant_dig(_type), \
103 .mant_dig = _float_mant_dig(_type), \
104 .alignment = lttng_alignof(_type) * CHAR_BIT, \
105 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
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;
116 union _lttng_basic_type
{
117 struct lttng_integer_type integer
;
122 enum lttng_string_encodings encoding
;
124 struct lttng_float_type _float
;
127 struct lttng_basic_type
{
128 enum abstract_types atype
;
130 union _lttng_basic_type basic
;
135 enum abstract_types atype
;
137 union _lttng_basic_type basic
;
139 struct lttng_basic_type elem_type
;
140 unsigned int length
; /* num. elems. */
143 struct lttng_basic_type length_type
;
144 struct lttng_basic_type elem_type
;
151 struct lttng_type container_type
;
152 const struct lttng_enum_entry
*entries
;
156 /* Event field description */
158 struct lttng_event_field
{
160 struct lttng_type type
;
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
,
167 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
168 struct ltt_channel
*chan
);
171 void (*destroy
)(struct lttng_ctx_field
*field
);
175 struct lttng_ctx_field
*fields
;
176 unsigned int nr_fields
;
177 unsigned int allocated_fields
;
180 struct lttng_event_desc
{
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
;
188 struct lttng_probe_desc
{
189 const struct lttng_event_desc
*event_desc
;
190 unsigned int nr_events
;
191 struct cds_list_head head
; /* chain registered probes */
194 struct ust_pending_probe
;
197 * ltt_event structure is referred to by the tracing fast path. It must be
202 struct ltt_channel
*chan
;
204 const struct lttng_event_desc
*desc
;
206 struct lttng_ctx
*ctx
;
207 enum lttng_ust_instrumentation instrumentation
;
210 struct cds_list_head list
; /* Event list */
211 struct ust_pending_probe
*pending_probe
;
212 int metadata_dumped
:1;
216 struct lttng_ust_shm_handle
;
218 struct ltt_channel_ops
{
219 struct ltt_channel
*(*channel_create
)(const char *name
,
221 size_t subbuf_size
, size_t num_subbuf
,
222 unsigned int switch_timer_interval
,
223 unsigned int read_timer_interval
,
224 int *shm_fd
, int *wait_fd
,
225 uint64_t *memory_map_size
,
226 struct ltt_channel
*chan_priv_init
);
227 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
228 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
229 struct lttng_ust_shm_handle
*handle
,
230 int *shm_fd
, int *wait_fd
,
231 uint64_t *memory_map_size
);
232 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
233 struct lttng_ust_shm_handle
*handle
);
234 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
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
,
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.
244 size_t (*packet_avail_size
)(struct channel
*chan
,
245 struct lttng_ust_shm_handle
*handle
);
246 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
247 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
248 int (*is_finalized
)(struct channel
*chan
);
249 int (*is_disabled
)(struct channel
*chan
);
250 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
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.
260 struct channel
*chan
; /* Channel buffers */
262 struct lttng_ctx
*ctx
;
263 /* Event ID management */
264 struct ltt_session
*session
;
265 int objd
; /* Object associated to channel */
266 unsigned int free_event_id
; /* Next event ID to allocate */
267 unsigned int used_event_id
; /* Max allocated event IDs */
268 struct cds_list_head list
; /* Channel list */
269 struct ltt_channel_ops
*ops
;
270 int header_type
; /* 0: unset, 1: compact, 2: large */
271 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
272 int metadata_dumped
:1;
274 /* Channel ID, available for consumer too */
276 /* Copy of session UUID for consumer (availability through shm) */
277 uuid_t uuid
; /* Trace session unique ID */
281 int active
; /* Is trace session active ? */
282 int been_active
; /* Has trace session been active ? */
283 int objd
; /* Object associated to session */
284 struct ltt_channel
*metadata
; /* Metadata channel */
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 */
288 unsigned int free_chan_id
; /* Next chan ID to allocate */
289 uuid_t uuid
; /* Trace session unique ID */
290 int metadata_dumped
:1;
293 struct ltt_transport
{
295 struct cds_list_head node
;
296 struct ltt_channel_ops ops
;
299 struct ltt_tracepoint_list
{
300 struct tracepoint_iter iter
;
304 struct ltt_session
*ltt_session_create(void);
305 int ltt_session_enable(struct ltt_session
*session
);
306 int ltt_session_disable(struct ltt_session
*session
);
307 void ltt_session_destroy(struct ltt_session
*session
);
309 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
310 const char *transport_name
,
312 size_t subbuf_size
, size_t num_subbuf
,
313 unsigned int switch_timer_interval
,
314 unsigned int read_timer_interval
,
315 int *shm_fd
, int *wait_fd
,
316 uint64_t *memory_map_size
,
317 struct ltt_channel
*chan_priv_init
);
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
,
322 unsigned int read_timer_interval
,
323 int *shm_fd
, int *wait_fd
,
324 uint64_t *memory_map_size
);
326 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
,
327 struct lttng_ust_event
*event_param
,
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
);
335 void ltt_transport_register(struct ltt_transport
*transport
);
336 void ltt_transport_unregister(struct ltt_transport
*transport
);
338 void synchronize_trace(void);
340 int ltt_probe_register(struct lttng_probe_desc
*desc
);
341 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
342 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
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);
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
,
350 struct lttng_ctx_field
*field
);
351 void lttng_destroy_context(struct lttng_ctx
*ctx
);
352 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
353 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
354 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
355 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
356 void lttng_context_vtid_reset(void);
357 void lttng_context_vpid_reset(void);
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
;
363 struct ltt_transport
*ltt_transport_find(const char *name
);
365 #endif /* _LTTNG_UST_EVENTS_H */