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 <uuid/uuid.h>
24 #include <lttng/ust-abi.h>
25 #include <lttng/ust-tracer.h>
31 struct lttng_ust_lib_ring_buffer_ctx
;
34 * LTTng client type enumeration. Used by the consumer to map the
35 * callbacks from its own address space.
37 enum lttng_client_types
{
38 LTTNG_CLIENT_METADATA
= 0,
39 LTTNG_CLIENT_DISCARD
= 1,
40 LTTNG_CLIENT_OVERWRITE
= 2,
41 LTTNG_NR_CLIENT_TYPES
,
44 /* Type description */
46 /* Update the astract_types name table in lttng-types.c along with this enum */
57 /* Update the string_encodings name table in lttng-types.c along with this enum */
58 enum lttng_string_encodings
{
59 lttng_encode_none
= 0,
60 lttng_encode_UTF8
= 1,
61 lttng_encode_ASCII
= 2,
65 struct lttng_enum_entry
{
66 unsigned long long start
, end
; /* start and end are inclusive */
70 #define __type_integer(_type, _byte_order, _base, _encoding) \
72 .atype = atype_integer, \
75 .size = sizeof(_type) * CHAR_BIT, \
76 .alignment = lttng_alignof(_type) * CHAR_BIT, \
77 .signedness = lttng_is_signed_type(_type), \
78 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
80 .encoding = lttng_encode_##_encoding, \
84 struct lttng_integer_type {
85 unsigned int size
; /* in bits */
86 unsigned short alignment
; /* in bits */
87 unsigned int signedness
:1;
88 unsigned int reverse_byte_order
:1;
89 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
90 enum lttng_string_encodings encoding
;
94 * Only float and double are supported. long double is not supported at
97 #define _float_mant_dig(_type) \
98 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
99 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
102 #define __type_float(_type) \
104 .atype = atype_float, \
107 .exp_dig = sizeof(_type) * CHAR_BIT \
108 - _float_mant_dig(_type), \
109 .mant_dig = _float_mant_dig(_type), \
110 .alignment = lttng_alignof(_type) * CHAR_BIT, \
111 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
115 struct lttng_float_type {
116 unsigned int exp_dig
; /* exponent digits, in bits */
117 unsigned int mant_dig
; /* mantissa digits, in bits */
118 unsigned short alignment
; /* in bits */
119 unsigned int reverse_byte_order
:1;
122 union _lttng_basic_type
{
123 struct lttng_integer_type integer
;
128 enum lttng_string_encodings encoding
;
130 struct lttng_float_type _float
;
133 struct lttng_basic_type
{
134 enum abstract_types atype
;
136 union _lttng_basic_type basic
;
141 enum abstract_types atype
;
143 union _lttng_basic_type basic
;
145 struct lttng_basic_type elem_type
;
146 unsigned int length
; /* num. elems. */
149 struct lttng_basic_type length_type
;
150 struct lttng_basic_type elem_type
;
157 struct lttng_type container_type
;
158 const struct lttng_enum_entry
*entries
;
162 /* Event field description */
164 struct lttng_event_field
{
166 struct lttng_type type
;
169 struct lttng_ctx_field
{
170 struct lttng_event_field event_field
;
171 size_t (*get_size
)(size_t offset
);
172 void (*record
)(struct lttng_ctx_field
*field
,
173 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
174 struct ltt_channel
*chan
);
177 void (*destroy
)(struct lttng_ctx_field
*field
);
181 struct lttng_ctx_field
*fields
;
182 unsigned int nr_fields
;
183 unsigned int allocated_fields
;
186 struct tracepoint_loglevel_entry
{
187 const char *identifier
;
191 struct lttng_event_desc
{
193 void *probe_callback
;
194 const struct lttng_event_ctx
*ctx
; /* context */
195 const struct lttng_event_field
*fields
; /* event payload */
196 unsigned int nr_fields
;
197 const struct tracepoint_loglevel_entry
**loglevel
;
200 struct lttng_probe_desc
{
201 const char *provider
;
202 const struct lttng_event_desc
**event_desc
;
203 unsigned int nr_events
;
204 const struct tracepoint_loglevel_entry
**loglevels
;
205 unsigned int nr_loglevels
;
206 struct cds_list_head head
; /* chain registered probes */
209 struct tp_loglevel_iter
{
210 struct lttng_probe_desc
*desc
;
211 const struct tracepoint_loglevel_entry
*loglevel
;
214 struct ust_pending_probe
;
217 * ltt_event structure is referred to by the tracing fast path. It must be
222 struct ltt_channel
*chan
;
224 const struct lttng_event_desc
*desc
;
226 struct lttng_ctx
*ctx
;
227 enum lttng_ust_instrumentation instrumentation
;
230 struct cds_list_head list
; /* Event list */
231 struct ust_pending_probe
*pending_probe
;
232 int metadata_dumped
:1;
236 struct lttng_ust_shm_handle
;
238 struct ltt_channel_ops
{
239 struct ltt_channel
*(*channel_create
)(const char *name
,
241 size_t subbuf_size
, size_t num_subbuf
,
242 unsigned int switch_timer_interval
,
243 unsigned int read_timer_interval
,
244 int *shm_fd
, int *wait_fd
,
245 uint64_t *memory_map_size
,
246 struct ltt_channel
*chan_priv_init
);
247 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
248 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
249 struct lttng_ust_shm_handle
*handle
,
250 int *shm_fd
, int *wait_fd
,
251 uint64_t *memory_map_size
);
252 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
253 struct lttng_ust_shm_handle
*handle
);
254 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
256 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
257 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
260 * packet_avail_size returns the available size in the current
261 * packet. Note that the size returned is only a hint, since it
262 * may change due to concurrent writes.
264 size_t (*packet_avail_size
)(struct channel
*chan
,
265 struct lttng_ust_shm_handle
*handle
);
266 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
267 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
268 int (*is_finalized
)(struct channel
*chan
);
269 int (*is_disabled
)(struct channel
*chan
);
270 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
275 * The pointers located in this private data are NOT safe to be
276 * dereferenced by the consumer. The only operations the
277 * consumer process is designed to be allowed to do is to read
278 * and perform subbuffer flush.
280 struct channel
*chan
; /* Channel buffers */
282 struct lttng_ctx
*ctx
;
283 /* Event ID management */
284 struct ltt_session
*session
;
285 int objd
; /* Object associated to channel */
286 unsigned int free_event_id
; /* Next event ID to allocate */
287 unsigned int used_event_id
; /* Max allocated event IDs */
288 struct cds_list_head list
; /* Channel list */
289 struct ltt_channel_ops
*ops
;
290 int header_type
; /* 0: unset, 1: compact, 2: large */
291 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
292 int metadata_dumped
:1;
294 /* Channel ID, available for consumer too */
296 /* Copy of session UUID for consumer (availability through shm) */
297 uuid_t uuid
; /* Trace session unique ID */
301 int active
; /* Is trace session active ? */
302 int been_active
; /* Has trace session been active ? */
303 int objd
; /* Object associated to session */
304 struct ltt_channel
*metadata
; /* Metadata channel */
305 struct cds_list_head chan
; /* Channel list head */
306 struct cds_list_head events
; /* Event list head */
307 struct cds_list_head list
; /* Session list */
308 unsigned int free_chan_id
; /* Next chan ID to allocate */
309 uuid_t uuid
; /* Trace session unique ID */
310 int metadata_dumped
:1;
313 struct ltt_transport
{
315 struct cds_list_head node
;
316 struct ltt_channel_ops ops
;
319 struct ltt_session
*ltt_session_create(void);
320 int ltt_session_enable(struct ltt_session
*session
);
321 int ltt_session_disable(struct ltt_session
*session
);
322 void ltt_session_destroy(struct ltt_session
*session
);
324 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
325 const char *transport_name
,
327 size_t subbuf_size
, size_t num_subbuf
,
328 unsigned int switch_timer_interval
,
329 unsigned int read_timer_interval
,
330 int *shm_fd
, int *wait_fd
,
331 uint64_t *memory_map_size
,
332 struct ltt_channel
*chan_priv_init
);
333 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
334 int overwrite
, void *buf_addr
,
335 size_t subbuf_size
, size_t num_subbuf
,
336 unsigned int switch_timer_interval
,
337 unsigned int read_timer_interval
,
338 int *shm_fd
, int *wait_fd
,
339 uint64_t *memory_map_size
);
341 int ltt_event_create(struct ltt_channel
*chan
,
342 struct lttng_ust_event
*event_param
,
344 struct ltt_event
**event
);
346 int ltt_channel_enable(struct ltt_channel
*channel
);
347 int ltt_channel_disable(struct ltt_channel
*channel
);
348 int ltt_event_enable(struct ltt_event
*event
);
349 int ltt_event_disable(struct ltt_event
*event
);
351 void ltt_transport_register(struct ltt_transport
*transport
);
352 void ltt_transport_unregister(struct ltt_transport
*transport
);
354 void synchronize_trace(void);
356 int ltt_probe_register(struct lttng_probe_desc
*desc
);
357 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
358 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
359 const struct lttng_event_desc
*ltt_event_get(const char *name
);
360 void ltt_event_put(const struct lttng_event_desc
*desc
);
361 int ltt_probes_init(void);
362 void ltt_probes_exit(void);
363 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
364 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
365 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
366 struct lttng_ctx_field
*field
);
367 void lttng_destroy_context(struct lttng_ctx
*ctx
);
368 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
369 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
370 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
371 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
372 void lttng_context_vtid_reset(void);
373 void lttng_context_vpid_reset(void);
375 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
376 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
377 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
379 struct ltt_transport
*ltt_transport_find(const char *name
);
381 #endif /* _LTTNG_UST_EVENTS_H */