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 * LTTng client type enumeration. Used by the consumer to map the
36 * callbacks from its own address space.
38 enum lttng_client_types
{
39 LTTNG_CLIENT_METADATA
= 0,
40 LTTNG_CLIENT_DISCARD
= 1,
41 LTTNG_CLIENT_OVERWRITE
= 2,
42 LTTNG_NR_CLIENT_TYPES
,
45 /* Type description */
47 /* Update the astract_types name table in lttng-types.c along with this enum */
58 /* Update the string_encodings name table in lttng-types.c along with this enum */
59 enum lttng_string_encodings
{
60 lttng_encode_none
= 0,
61 lttng_encode_UTF8
= 1,
62 lttng_encode_ASCII
= 2,
66 struct lttng_enum_entry
{
67 unsigned long long start
, end
; /* start and end are inclusive */
71 #define __type_integer(_type, _byte_order, _base, _encoding) \
73 .atype = atype_integer, \
76 .size = sizeof(_type) * CHAR_BIT, \
77 .alignment = lttng_alignof(_type) * CHAR_BIT, \
78 .signedness = lttng_is_signed_type(_type), \
79 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
81 .encoding = lttng_encode_##_encoding, \
85 struct lttng_integer_type {
86 unsigned int size
; /* in bits */
87 unsigned short alignment
; /* in bits */
88 unsigned int signedness
:1;
89 unsigned int reverse_byte_order
:1;
90 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
91 enum lttng_string_encodings encoding
;
95 * Only float and double are supported. long double is not supported at
98 #define _float_mant_dig(_type) \
99 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
100 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
103 #define __type_float(_type) \
105 .atype = atype_float, \
108 .exp_dig = sizeof(_type) * CHAR_BIT \
109 - _float_mant_dig(_type), \
110 .mant_dig = _float_mant_dig(_type), \
111 .alignment = lttng_alignof(_type) * CHAR_BIT, \
112 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
116 struct lttng_float_type {
117 unsigned int exp_dig
; /* exponent digits, in bits */
118 unsigned int mant_dig
; /* mantissa digits, in bits */
119 unsigned short alignment
; /* in bits */
120 unsigned int reverse_byte_order
:1;
123 union _lttng_basic_type
{
124 struct lttng_integer_type integer
;
129 enum lttng_string_encodings encoding
;
131 struct lttng_float_type _float
;
134 struct lttng_basic_type
{
135 enum abstract_types atype
;
137 union _lttng_basic_type basic
;
142 enum abstract_types atype
;
144 union _lttng_basic_type basic
;
146 struct lttng_basic_type elem_type
;
147 unsigned int length
; /* num. elems. */
150 struct lttng_basic_type length_type
;
151 struct lttng_basic_type elem_type
;
158 struct lttng_type container_type
;
159 const struct lttng_enum_entry
*entries
;
163 /* Event field description */
165 struct lttng_event_field
{
167 struct lttng_type type
;
170 struct lttng_ctx_field
{
171 struct lttng_event_field event_field
;
172 size_t (*get_size
)(size_t offset
);
173 void (*record
)(struct lttng_ctx_field
*field
,
174 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
175 struct ltt_channel
*chan
);
178 void (*destroy
)(struct lttng_ctx_field
*field
);
182 struct lttng_ctx_field
*fields
;
183 unsigned int nr_fields
;
184 unsigned int allocated_fields
;
187 struct tracepoint_loglevel_entry
{
188 const char *identifier
;
193 * Entry describing an active loglevel, along with the event attribute
194 * and channel information configuring the events that need to be
197 struct loglevel_entry
{
198 struct cds_hlist_node hlist
;
199 struct ltt_channel
*chan
;
200 struct lttng_ctx
*ctx
; /* TODO */
201 struct lttng_ust_event event_param
;
202 struct cds_list_head events
; /* list of events enabled */
203 struct cds_list_head list
; /* per-session list of loglevels */
204 unsigned int enabled
:1;
208 struct lttng_event_desc
{
210 void *probe_callback
;
211 const struct lttng_event_ctx
*ctx
; /* context */
212 const struct lttng_event_field
*fields
; /* event payload */
213 unsigned int nr_fields
;
214 const struct tracepoint_loglevel_entry
**loglevel
;
217 struct lttng_probe_desc
{
218 const char *provider
;
219 const struct lttng_event_desc
**event_desc
;
220 unsigned int nr_events
;
221 const struct tracepoint_loglevel_entry
**loglevels
;
222 unsigned int nr_loglevels
;
223 struct cds_list_head head
; /* chain registered probes */
226 struct tp_list_entry
{
227 struct lttng_ust_tracepoint_iter tp
;
228 struct cds_list_head head
;
231 struct lttng_ust_tracepoint_list
{
232 struct tp_list_entry
*iter
;
233 struct cds_list_head head
;
236 struct ust_pending_probe
;
239 * ltt_event structure is referred to by the tracing fast path. It must be
241 * Note about loglevel_list: this list is only used to enable/disable
242 * events on a per-loglevel basis. The events created internally by the
243 * loglevel are only freed when the session is destroyed.
247 struct ltt_channel
*chan
;
249 const struct lttng_event_desc
*desc
;
251 struct lttng_ctx
*ctx
;
252 enum lttng_ust_instrumentation instrumentation
;
255 struct cds_list_head list
; /* Event list */
256 struct cds_list_head loglevel_list
; /* Event list for loglevel */
257 struct ust_pending_probe
*pending_probe
;
258 unsigned int metadata_dumped
:1;
262 struct lttng_ust_shm_handle
;
264 struct ltt_channel_ops
{
265 struct ltt_channel
*(*channel_create
)(const char *name
,
267 size_t subbuf_size
, size_t num_subbuf
,
268 unsigned int switch_timer_interval
,
269 unsigned int read_timer_interval
,
270 int *shm_fd
, int *wait_fd
,
271 uint64_t *memory_map_size
,
272 struct ltt_channel
*chan_priv_init
);
273 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
274 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
275 struct lttng_ust_shm_handle
*handle
,
276 int *shm_fd
, int *wait_fd
,
277 uint64_t *memory_map_size
);
278 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
279 struct lttng_ust_shm_handle
*handle
);
280 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
282 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
283 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
286 * packet_avail_size returns the available size in the current
287 * packet. Note that the size returned is only a hint, since it
288 * may change due to concurrent writes.
290 size_t (*packet_avail_size
)(struct channel
*chan
,
291 struct lttng_ust_shm_handle
*handle
);
292 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
293 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
294 int (*is_finalized
)(struct channel
*chan
);
295 int (*is_disabled
)(struct channel
*chan
);
296 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
301 * The pointers located in this private data are NOT safe to be
302 * dereferenced by the consumer. The only operations the
303 * consumer process is designed to be allowed to do is to read
304 * and perform subbuffer flush.
306 struct channel
*chan
; /* Channel buffers */
308 struct lttng_ctx
*ctx
;
309 /* Event ID management */
310 struct ltt_session
*session
;
311 int objd
; /* Object associated to channel */
312 unsigned int free_event_id
; /* Next event ID to allocate */
313 unsigned int used_event_id
; /* Max allocated event IDs */
314 struct cds_list_head list
; /* Channel list */
315 struct ltt_channel_ops
*ops
;
316 int header_type
; /* 0: unset, 1: compact, 2: large */
317 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
318 unsigned int metadata_dumped
:1;
320 /* Channel ID, available for consumer too */
322 /* Copy of session UUID for consumer (availability through shm) */
323 uuid_t uuid
; /* Trace session unique ID */
327 int active
; /* Is trace session active ? */
328 int been_active
; /* Has trace session been active ? */
329 int objd
; /* Object associated to session */
330 struct ltt_channel
*metadata
; /* Metadata channel */
331 struct cds_list_head chan
; /* Channel list head */
332 struct cds_list_head events
; /* Event list head */
333 struct cds_list_head loglevels
; /* Loglevel list head */
334 struct cds_list_head list
; /* Session list */
335 unsigned int free_chan_id
; /* Next chan ID to allocate */
336 uuid_t uuid
; /* Trace session unique ID */
337 unsigned int metadata_dumped
:1;
340 struct ltt_transport
{
342 struct cds_list_head node
;
343 struct ltt_channel_ops ops
;
346 struct ltt_session
*ltt_session_create(void);
347 int ltt_session_enable(struct ltt_session
*session
);
348 int ltt_session_disable(struct ltt_session
*session
);
349 void ltt_session_destroy(struct ltt_session
*session
);
351 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
352 const char *transport_name
,
354 size_t subbuf_size
, size_t num_subbuf
,
355 unsigned int switch_timer_interval
,
356 unsigned int read_timer_interval
,
357 int *shm_fd
, int *wait_fd
,
358 uint64_t *memory_map_size
,
359 struct ltt_channel
*chan_priv_init
);
360 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
361 int overwrite
, void *buf_addr
,
362 size_t subbuf_size
, size_t num_subbuf
,
363 unsigned int switch_timer_interval
,
364 unsigned int read_timer_interval
,
365 int *shm_fd
, int *wait_fd
,
366 uint64_t *memory_map_size
);
368 int ltt_event_create(struct ltt_channel
*chan
,
369 struct lttng_ust_event
*event_param
,
371 struct ltt_event
**event
);
373 int ltt_channel_enable(struct ltt_channel
*channel
);
374 int ltt_channel_disable(struct ltt_channel
*channel
);
375 int ltt_event_enable(struct ltt_event
*event
);
376 int ltt_event_disable(struct ltt_event
*event
);
378 void ltt_transport_register(struct ltt_transport
*transport
);
379 void ltt_transport_unregister(struct ltt_transport
*transport
);
381 void synchronize_trace(void);
383 int ltt_probe_register(struct lttng_probe_desc
*desc
);
384 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
385 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
386 const struct lttng_event_desc
*ltt_event_get(const char *name
);
387 void ltt_event_put(const struct lttng_event_desc
*desc
);
388 int ltt_probes_init(void);
389 void ltt_probes_exit(void);
390 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
391 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
392 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
393 struct lttng_ctx_field
*field
);
394 void lttng_destroy_context(struct lttng_ctx
*ctx
);
395 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
396 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
397 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
398 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
399 void lttng_context_vtid_reset(void);
400 void lttng_context_vpid_reset(void);
402 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
403 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
404 const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
406 struct ltt_transport
*ltt_transport_find(const char *name
);
408 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
409 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
410 struct lttng_ust_tracepoint_iter
*
411 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
413 struct loglevel_entry
*get_loglevel(const char *name
);
414 struct loglevel_entry
*add_loglevel(const char *name
,
415 struct ltt_channel
*chan
,
416 struct lttng_ust_event
*event_param
);
417 void _remove_loglevel(struct loglevel_entry
*e
);
418 int ltt_loglevel_enable(struct loglevel_entry
*loglevel
);
419 int ltt_loglevel_disable(struct loglevel_entry
*loglevel
);
420 int ltt_loglevel_create(struct ltt_channel
*chan
,
421 struct lttng_ust_event
*event_param
,
422 struct loglevel_entry
**_entry
);
424 #endif /* _LTTNG_UST_EVENTS_H */