1 #ifndef _UST_LTTNG_EVENTS_H
2 #define _UST_LTTNG_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>
24 struct lttng_ust_lib_ring_buffer_ctx
;
27 * LTTng client type enumeration. Used by the consumer to map the
28 * callbacks from its own address space.
30 enum lttng_client_types
{
31 LTTNG_CLIENT_METADATA
= 0,
32 LTTNG_CLIENT_DISCARD
= 1,
33 LTTNG_CLIENT_OVERWRITE
= 2,
34 LTTNG_NR_CLIENT_TYPES
,
37 /* Type description */
39 /* Update the astract_types name table in lttng-types.c along with this enum */
50 /* Update the string_encodings name table in lttng-types.c along with this enum */
51 enum lttng_string_encodings
{
52 lttng_encode_none
= 0,
53 lttng_encode_UTF8
= 1,
54 lttng_encode_ASCII
= 2,
58 struct lttng_enum_entry
{
59 unsigned long long start
, end
; /* start and end are inclusive */
63 #define __type_integer(_type, _byte_order, _base, _encoding) \
65 .atype = atype_integer, \
68 .size = sizeof(_type) * CHAR_BIT, \
69 .alignment = lttng_alignof(_type) * CHAR_BIT, \
70 .signedness = lttng_is_signed_type(_type), \
71 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
73 .encoding = lttng_encode_##_encoding, \
77 struct lttng_integer_type {
78 unsigned int size
; /* in bits */
79 unsigned short alignment
; /* in bits */
80 unsigned int signedness
:1;
81 unsigned int reverse_byte_order
:1;
82 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
83 enum lttng_string_encodings encoding
;
87 * Only float and double are supported. long double is not supported at
90 #define _float_mant_dig(_type) \
91 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
92 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
95 #define __type_float(_type) \
97 .atype = atype_float, \
100 .exp_dig = sizeof(_type) * CHAR_BIT \
101 - _float_mant_dig(_type), \
102 .mant_dig = _float_mant_dig(_type), \
103 .alignment = lttng_alignof(_type) * CHAR_BIT, \
104 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
108 struct lttng_float_type {
109 unsigned int exp_dig
; /* exponent digits, in bits */
110 unsigned int mant_dig
; /* mantissa digits, in bits */
111 unsigned short alignment
; /* in bits */
112 unsigned int reverse_byte_order
:1;
115 union _lttng_basic_type
{
116 struct lttng_integer_type integer
;
121 enum lttng_string_encodings encoding
;
123 struct lttng_float_type _float
;
126 struct lttng_basic_type
{
127 enum abstract_types atype
;
129 union _lttng_basic_type basic
;
134 enum abstract_types atype
;
136 union _lttng_basic_type basic
;
138 struct lttng_basic_type elem_type
;
139 unsigned int length
; /* num. elems. */
142 struct lttng_basic_type length_type
;
143 struct lttng_basic_type elem_type
;
150 struct lttng_type container_type
;
151 const struct lttng_enum_entry
*entries
;
155 /* Event field description */
157 struct lttng_event_field
{
159 struct lttng_type type
;
162 struct lttng_ctx_field
{
163 struct lttng_event_field event_field
;
164 size_t (*get_size
)(size_t offset
);
165 void (*record
)(struct lttng_ctx_field
*field
,
166 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
167 struct ltt_channel
*chan
);
170 void (*destroy
)(struct lttng_ctx_field
*field
);
174 struct lttng_ctx_field
*fields
;
175 unsigned int nr_fields
;
176 unsigned int allocated_fields
;
179 struct lttng_event_desc
{
181 void *probe_callback
;
182 const struct lttng_event_ctx
*ctx
; /* context */
183 const struct lttng_event_field
*fields
; /* event payload */
184 unsigned int nr_fields
;
187 struct lttng_probe_desc
{
188 const struct lttng_event_desc
*event_desc
;
189 unsigned int nr_events
;
190 struct cds_list_head head
; /* chain registered probes */
193 struct ust_pending_probe
;
196 * ltt_event structure is referred to by the tracing fast path. It must be
201 struct ltt_channel
*chan
;
203 const struct lttng_event_desc
*desc
;
205 struct lttng_ctx
*ctx
;
206 enum lttng_ust_instrumentation instrumentation
;
209 struct cds_list_head list
; /* Event list */
210 struct ust_pending_probe
*pending_probe
;
211 int metadata_dumped
:1;
215 struct lttng_ust_shm_handle
;
217 struct ltt_channel_ops
{
218 struct ltt_channel
*(*channel_create
)(const char *name
,
219 struct ltt_channel
*ltt_chan
,
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 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
227 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
228 struct lttng_ust_shm_handle
*handle
,
229 int *shm_fd
, int *wait_fd
,
230 uint64_t *memory_map_size
);
231 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
232 struct lttng_ust_shm_handle
*handle
);
233 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
235 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
236 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
239 * packet_avail_size returns the available size in the current
240 * packet. Note that the size returned is only a hint, since it
241 * may change due to concurrent writes.
243 size_t (*packet_avail_size
)(struct channel
*chan
,
244 struct lttng_ust_shm_handle
*handle
);
245 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
246 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
247 int (*is_finalized
)(struct channel
*chan
);
248 int (*is_disabled
)(struct channel
*chan
);
249 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
254 struct channel
*chan
; /* Channel buffers */
256 struct lttng_ctx
*ctx
;
257 /* Event ID management */
258 struct ltt_session
*session
;
259 int objd
; /* Object associated to channel */
260 unsigned int free_event_id
; /* Next event ID to allocate */
261 unsigned int used_event_id
; /* Max allocated event IDs */
262 struct cds_list_head list
; /* Channel list */
263 struct ltt_channel_ops
*ops
;
264 int header_type
; /* 0: unset, 1: compact, 2: large */
265 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
266 int metadata_dumped
:1;
270 int active
; /* Is trace session active ? */
271 int been_active
; /* Has trace session been active ? */
272 int objd
; /* Object associated to session */
273 struct ltt_channel
*metadata
; /* Metadata channel */
274 struct cds_list_head chan
; /* Channel list head */
275 struct cds_list_head events
; /* Event list head */
276 struct cds_list_head list
; /* Session list */
277 unsigned int free_chan_id
; /* Next chan ID to allocate */
278 uuid_t uuid
; /* Trace session unique ID */
279 int metadata_dumped
:1;
282 struct ltt_transport
{
284 struct cds_list_head node
;
285 struct ltt_channel_ops ops
;
288 struct ltt_session
*ltt_session_create(void);
289 int ltt_session_enable(struct ltt_session
*session
);
290 int ltt_session_disable(struct ltt_session
*session
);
291 void ltt_session_destroy(struct ltt_session
*session
);
293 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
294 const char *transport_name
,
296 size_t subbuf_size
, size_t num_subbuf
,
297 unsigned int switch_timer_interval
,
298 unsigned int read_timer_interval
,
299 int *shm_fd
, int *wait_fd
,
300 uint64_t *memory_map_size
);
301 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
302 int overwrite
, void *buf_addr
,
303 size_t subbuf_size
, size_t num_subbuf
,
304 unsigned int switch_timer_interval
,
305 unsigned int read_timer_interval
,
306 int *shm_fd
, int *wait_fd
,
307 uint64_t *memory_map_size
);
309 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
,
310 struct lttng_ust_event
*event_param
,
313 int ltt_channel_enable(struct ltt_channel
*channel
);
314 int ltt_channel_disable(struct ltt_channel
*channel
);
315 int ltt_event_enable(struct ltt_event
*event
);
316 int ltt_event_disable(struct ltt_event
*event
);
318 void ltt_transport_register(struct ltt_transport
*transport
);
319 void ltt_transport_unregister(struct ltt_transport
*transport
);
321 void synchronize_trace(void);
323 int ltt_probe_register(struct lttng_probe_desc
*desc
);
324 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
325 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
326 const struct lttng_event_desc
*ltt_event_get(const char *name
);
327 void ltt_event_put(const struct lttng_event_desc
*desc
);
328 int ltt_probes_init(void);
329 void ltt_probes_exit(void);
330 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
331 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
332 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
333 struct lttng_ctx_field
*field
);
334 void lttng_destroy_context(struct lttng_ctx
*ctx
);
335 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
336 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
337 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
338 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
339 void lttng_context_vtid_reset(void);
340 void lttng_context_vpid_reset(void);
342 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
343 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
344 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
346 struct cds_list_head ltt_transport_list
;
347 struct ltt_transport
*ltt_transport_find(const char *name
);
349 #endif /* _UST_LTTNG_EVENTS_H */