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 <ust/lttng-ust-abi.h>
18 #include <ust/lttng-tracer.h>
24 struct lttng_ust_lib_ring_buffer_ctx
;
26 /* Type description */
28 /* Update the astract_types name table in lttng-types.c along with this enum */
39 /* Update the string_encodings name table in lttng-types.c along with this enum */
40 enum lttng_string_encodings
{
41 lttng_encode_none
= 0,
42 lttng_encode_UTF8
= 1,
43 lttng_encode_ASCII
= 2,
47 struct lttng_enum_entry
{
48 unsigned long long start
, end
; /* start and end are inclusive */
52 #define __type_integer(_type, _byte_order, _base, _encoding) \
54 .atype = atype_integer, \
57 .size = sizeof(_type) * CHAR_BIT, \
58 .alignment = lttng_alignof(_type) * CHAR_BIT, \
59 .signedness = lttng_is_signed_type(_type), \
60 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
62 .encoding = lttng_encode_##_encoding, \
66 struct lttng_integer_type {
67 unsigned int size
; /* in bits */
68 unsigned short alignment
; /* in bits */
69 unsigned int signedness
:1;
70 unsigned int reverse_byte_order
:1;
71 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
72 enum lttng_string_encodings encoding
;
76 * Only float and double are supported. long double is not supported at
79 #define _float_mant_dig(_type) \
80 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
81 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
84 #define __type_float(_type) \
86 .atype = atype_float, \
89 .exp_dig = sizeof(_type) * CHAR_BIT \
90 - _float_mant_dig(_type), \
91 .mant_dig = _float_mant_dig(_type), \
92 .alignment = lttng_alignof(_type) * CHAR_BIT, \
93 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
97 struct lttng_float_type {
98 unsigned int exp_dig
; /* exponent digits, in bits */
99 unsigned int mant_dig
; /* mantissa digits, in bits */
100 unsigned short alignment
; /* in bits */
101 unsigned int reverse_byte_order
:1;
104 union _lttng_basic_type
{
105 struct lttng_integer_type integer
;
110 enum lttng_string_encodings encoding
;
112 struct lttng_float_type _float
;
115 struct lttng_basic_type
{
116 enum abstract_types atype
;
118 union _lttng_basic_type basic
;
123 enum abstract_types atype
;
125 union _lttng_basic_type basic
;
127 struct lttng_basic_type elem_type
;
128 unsigned int length
; /* num. elems. */
131 struct lttng_basic_type length_type
;
132 struct lttng_basic_type elem_type
;
139 struct lttng_type container_type
;
140 const struct lttng_enum_entry
*entries
;
144 /* Event field description */
146 struct lttng_event_field
{
148 struct lttng_type type
;
151 struct lttng_ctx_field
{
152 struct lttng_event_field event_field
;
153 size_t (*get_size
)(size_t offset
);
154 void (*record
)(struct lttng_ctx_field
*field
,
155 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
156 struct ltt_channel
*chan
);
159 void (*destroy
)(struct lttng_ctx_field
*field
);
163 struct lttng_ctx_field
*fields
;
164 unsigned int nr_fields
;
165 unsigned int allocated_fields
;
168 struct lttng_event_desc
{
170 void *probe_callback
;
171 const struct lttng_event_ctx
*ctx
; /* context */
172 const struct lttng_event_field
*fields
; /* event payload */
173 unsigned int nr_fields
;
176 struct lttng_probe_desc
{
177 const struct lttng_event_desc
*event_desc
;
178 unsigned int nr_events
;
179 struct cds_list_head head
; /* chain registered probes */
182 struct ust_pending_probe
;
185 * ltt_event structure is referred to by the tracing fast path. It must be
190 struct ltt_channel
*chan
;
192 const struct lttng_event_desc
*desc
;
194 struct lttng_ctx
*ctx
;
195 enum lttng_ust_instrumentation instrumentation
;
198 struct cds_list_head list
; /* Event list */
199 struct ust_pending_probe
*pending_probe
;
200 int metadata_dumped
:1;
204 struct lttng_ust_shm_handle
;
206 struct ltt_channel_ops
{
207 struct ltt_channel
*(*channel_create
)(const char *name
,
208 struct ltt_channel
*ltt_chan
,
210 size_t subbuf_size
, size_t num_subbuf
,
211 unsigned int switch_timer_interval
,
212 unsigned int read_timer_interval
,
213 int *shm_fd
, int *wait_fd
,
214 uint64_t *memory_map_size
);
215 void (*channel_destroy
)(struct ltt_channel
*ltt_chan
);
216 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
217 struct lttng_ust_shm_handle
*handle
,
218 int *shm_fd
, int *wait_fd
,
219 uint64_t *memory_map_size
);
220 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
221 struct lttng_ust_shm_handle
*handle
);
222 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
224 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
225 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
228 * packet_avail_size returns the available size in the current
229 * packet. Note that the size returned is only a hint, since it
230 * may change due to concurrent writes.
232 size_t (*packet_avail_size
)(struct channel
*chan
,
233 struct lttng_ust_shm_handle
*handle
);
234 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
235 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
236 int (*is_finalized
)(struct channel
*chan
);
237 int (*is_disabled
)(struct channel
*chan
);
238 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
243 struct channel
*chan
; /* Channel buffers */
245 struct lttng_ctx
*ctx
;
246 /* Event ID management */
247 struct ltt_session
*session
;
248 int objd
; /* Object associated to channel */
249 unsigned int free_event_id
; /* Next event ID to allocate */
250 unsigned int used_event_id
; /* Max allocated event IDs */
251 struct cds_list_head list
; /* Channel list */
252 struct ltt_channel_ops
*ops
;
253 int header_type
; /* 0: unset, 1: compact, 2: large */
254 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
255 int metadata_dumped
:1;
259 int active
; /* Is trace session active ? */
260 int been_active
; /* Has trace session been active ? */
261 int objd
; /* Object associated to session */
262 struct ltt_channel
*metadata
; /* Metadata channel */
263 struct cds_list_head chan
; /* Channel list head */
264 struct cds_list_head events
; /* Event list head */
265 struct cds_list_head list
; /* Session list */
266 unsigned int free_chan_id
; /* Next chan ID to allocate */
267 uuid_t uuid
; /* Trace session unique ID */
268 int metadata_dumped
:1;
271 struct ltt_transport
{
273 struct cds_list_head node
;
274 struct ltt_channel_ops ops
;
277 struct ltt_session
*ltt_session_create(void);
278 int ltt_session_enable(struct ltt_session
*session
);
279 int ltt_session_disable(struct ltt_session
*session
);
280 void ltt_session_destroy(struct ltt_session
*session
);
282 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
283 const char *transport_name
,
285 size_t subbuf_size
, size_t num_subbuf
,
286 unsigned int switch_timer_interval
,
287 unsigned int read_timer_interval
,
288 int *shm_fd
, int *wait_fd
,
289 uint64_t *memory_map_size
);
290 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
291 int overwrite
, void *buf_addr
,
292 size_t subbuf_size
, size_t num_subbuf
,
293 unsigned int switch_timer_interval
,
294 unsigned int read_timer_interval
,
295 int *shm_fd
, int *wait_fd
,
296 uint64_t *memory_map_size
);
298 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
,
299 struct lttng_ust_event
*event_param
,
302 int ltt_channel_enable(struct ltt_channel
*channel
);
303 int ltt_channel_disable(struct ltt_channel
*channel
);
304 int ltt_event_enable(struct ltt_event
*event
);
305 int ltt_event_disable(struct ltt_event
*event
);
307 void ltt_transport_register(struct ltt_transport
*transport
);
308 void ltt_transport_unregister(struct ltt_transport
*transport
);
310 void synchronize_trace(void);
312 int ltt_probe_register(struct lttng_probe_desc
*desc
);
313 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
314 int pending_probe_fix_events(const struct lttng_event_desc
*desc
);
315 const struct lttng_event_desc
*ltt_event_get(const char *name
);
316 void ltt_event_put(const struct lttng_event_desc
*desc
);
317 int ltt_probes_init(void);
318 void ltt_probes_exit(void);
319 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
320 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
321 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
322 struct lttng_ctx_field
*field
);
323 void lttng_destroy_context(struct lttng_ctx
*ctx
);
324 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
325 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
326 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
327 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
328 void lttng_context_vtid_reset(void);
329 void lttng_context_vpid_reset(void);
331 #endif /* _UST_LTTNG_EVENTS_H */