Commit | Line | Data |
---|---|---|
0a42beb6 MD |
1 | #ifndef _UST_LTTNG_EVENTS_H |
2 | #define _UST_LTTNG_EVENTS_H | |
8020ceb5 MD |
3 | |
4 | /* | |
0a42beb6 | 5 | * ust/lttng-events.h |
8020ceb5 MD |
6 | * |
7 | * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9 | * Holds LTTng per-session event registry. | |
10 | * | |
11 | * Dual LGPL v2.1/GPL v2 license. | |
12 | */ | |
13 | ||
9f3fdbc6 MD |
14 | #include <urcu/list.h> |
15 | #include <uuid/uuid.h> | |
16 | #include <stdint.h> | |
4318ae1b MD |
17 | #include <lttng/ust-abi.h> |
18 | #include <lttng/ust-tracer.h> | |
20f1eee7 MD |
19 | #include <endian.h> |
20 | #include <float.h> | |
8020ceb5 | 21 | |
8020ceb5 MD |
22 | struct ltt_channel; |
23 | struct ltt_session; | |
4cfec15c | 24 | struct lttng_ust_lib_ring_buffer_ctx; |
8020ceb5 | 25 | |
c1fca457 MD |
26 | /* |
27 | * LTTng client type enumeration. Used by the consumer to map the | |
28 | * callbacks from its own address space. | |
29 | */ | |
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, | |
35 | }; | |
36 | ||
8020ceb5 MD |
37 | /* Type description */ |
38 | ||
39 | /* Update the astract_types name table in lttng-types.c along with this enum */ | |
40 | enum abstract_types { | |
41 | atype_integer, | |
42 | atype_enum, | |
43 | atype_array, | |
44 | atype_sequence, | |
45 | atype_string, | |
20f1eee7 | 46 | atype_float, |
8020ceb5 MD |
47 | NR_ABSTRACT_TYPES, |
48 | }; | |
49 | ||
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, | |
55 | NR_STRING_ENCODINGS, | |
56 | }; | |
57 | ||
58 | struct lttng_enum_entry { | |
59 | unsigned long long start, end; /* start and end are inclusive */ | |
60 | const char *string; | |
61 | }; | |
62 | ||
63 | #define __type_integer(_type, _byte_order, _base, _encoding) \ | |
64 | { \ | |
65 | .atype = atype_integer, \ | |
66 | .u.basic.integer = \ | |
67 | { \ | |
68 | .size = sizeof(_type) * CHAR_BIT, \ | |
1dbfff0c MD |
69 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
70 | .signedness = lttng_is_signed_type(_type), \ | |
8020ceb5 MD |
71 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ |
72 | .base = _base, \ | |
73 | .encoding = lttng_encode_##_encoding, \ | |
74 | }, \ | |
75 | } \ | |
76 | ||
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; | |
84 | }; | |
85 | ||
d3ed854b MD |
86 | /* |
87 | * Only float and double are supported. long double is not supported at | |
88 | * the moment. | |
89 | */ | |
20f1eee7 MD |
90 | #define _float_mant_dig(_type) \ |
91 | (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \ | |
92 | : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \ | |
d3ed854b | 93 | : 0)) |
20f1eee7 MD |
94 | |
95 | #define __type_float(_type) \ | |
96 | { \ | |
97 | .atype = atype_float, \ | |
98 | .u.basic._float = \ | |
99 | { \ | |
100 | .exp_dig = sizeof(_type) * CHAR_BIT \ | |
101 | - _float_mant_dig(_type), \ | |
102 | .mant_dig = _float_mant_dig(_type), \ | |
1dbfff0c | 103 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
20f1eee7 MD |
104 | .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \ |
105 | }, \ | |
106 | } \ | |
107 | ||
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; | |
113 | }; | |
114 | ||
8020ceb5 MD |
115 | union _lttng_basic_type { |
116 | struct lttng_integer_type integer; | |
117 | struct { | |
118 | const char *name; | |
119 | } enumeration; | |
120 | struct { | |
121 | enum lttng_string_encodings encoding; | |
122 | } string; | |
20f1eee7 | 123 | struct lttng_float_type _float; |
8020ceb5 MD |
124 | }; |
125 | ||
126 | struct lttng_basic_type { | |
127 | enum abstract_types atype; | |
128 | union { | |
129 | union _lttng_basic_type basic; | |
130 | } u; | |
131 | }; | |
132 | ||
133 | struct lttng_type { | |
134 | enum abstract_types atype; | |
135 | union { | |
136 | union _lttng_basic_type basic; | |
137 | struct { | |
138 | struct lttng_basic_type elem_type; | |
139 | unsigned int length; /* num. elems. */ | |
140 | } array; | |
141 | struct { | |
142 | struct lttng_basic_type length_type; | |
143 | struct lttng_basic_type elem_type; | |
144 | } sequence; | |
145 | } u; | |
146 | }; | |
147 | ||
148 | struct lttng_enum { | |
149 | const char *name; | |
150 | struct lttng_type container_type; | |
151 | const struct lttng_enum_entry *entries; | |
152 | unsigned int len; | |
153 | }; | |
154 | ||
155 | /* Event field description */ | |
156 | ||
157 | struct lttng_event_field { | |
158 | const char *name; | |
159 | struct lttng_type type; | |
160 | }; | |
161 | ||
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, | |
4cfec15c | 166 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
8020ceb5 MD |
167 | struct ltt_channel *chan); |
168 | union { | |
8020ceb5 MD |
169 | } u; |
170 | void (*destroy)(struct lttng_ctx_field *field); | |
171 | }; | |
172 | ||
173 | struct lttng_ctx { | |
174 | struct lttng_ctx_field *fields; | |
175 | unsigned int nr_fields; | |
176 | unsigned int allocated_fields; | |
177 | }; | |
178 | ||
179 | struct lttng_event_desc { | |
180 | const char *name; | |
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; | |
8020ceb5 MD |
185 | }; |
186 | ||
187 | struct lttng_probe_desc { | |
188 | const struct lttng_event_desc *event_desc; | |
189 | unsigned int nr_events; | |
9f3fdbc6 | 190 | struct cds_list_head head; /* chain registered probes */ |
8020ceb5 MD |
191 | }; |
192 | ||
8165c8da MD |
193 | struct ust_pending_probe; |
194 | ||
8020ceb5 MD |
195 | /* |
196 | * ltt_event structure is referred to by the tracing fast path. It must be | |
197 | * kept small. | |
198 | */ | |
199 | struct ltt_event { | |
200 | unsigned int id; | |
201 | struct ltt_channel *chan; | |
976fe9ea | 202 | int enabled; |
8020ceb5 MD |
203 | const struct lttng_event_desc *desc; |
204 | void *filter; | |
205 | struct lttng_ctx *ctx; | |
9f3fdbc6 | 206 | enum lttng_ust_instrumentation instrumentation; |
8020ceb5 | 207 | union { |
8020ceb5 | 208 | } u; |
9f3fdbc6 | 209 | struct cds_list_head list; /* Event list */ |
8165c8da | 210 | struct ust_pending_probe *pending_probe; |
8020ceb5 MD |
211 | int metadata_dumped:1; |
212 | }; | |
213 | ||
8d8a24c8 | 214 | struct channel; |
38fae1d3 | 215 | struct lttng_ust_shm_handle; |
8d8a24c8 | 216 | |
8020ceb5 | 217 | struct ltt_channel_ops { |
1d498196 | 218 | struct ltt_channel *(*channel_create)(const char *name, |
8020ceb5 MD |
219 | void *buf_addr, |
220 | size_t subbuf_size, size_t num_subbuf, | |
221 | unsigned int switch_timer_interval, | |
193183fb MD |
222 | unsigned int read_timer_interval, |
223 | int *shm_fd, int *wait_fd, | |
224 | uint64_t *memory_map_size); | |
1d498196 | 225 | void (*channel_destroy)(struct ltt_channel *ltt_chan); |
4cfec15c | 226 | struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan, |
38fae1d3 | 227 | struct lttng_ust_shm_handle *handle, |
381c0f1e MD |
228 | int *shm_fd, int *wait_fd, |
229 | uint64_t *memory_map_size); | |
4cfec15c | 230 | void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf, |
38fae1d3 | 231 | struct lttng_ust_shm_handle *handle); |
4cfec15c | 232 | int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx, |
8020ceb5 | 233 | uint32_t event_id); |
4cfec15c MD |
234 | void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx); |
235 | void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src, | |
8020ceb5 MD |
236 | size_t len); |
237 | /* | |
238 | * packet_avail_size returns the available size in the current | |
239 | * packet. Note that the size returned is only a hint, since it | |
240 | * may change due to concurrent writes. | |
241 | */ | |
1d498196 | 242 | size_t (*packet_avail_size)(struct channel *chan, |
38fae1d3 | 243 | struct lttng_ust_shm_handle *handle); |
9f3fdbc6 MD |
244 | //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); |
245 | //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); | |
8020ceb5 MD |
246 | int (*is_finalized)(struct channel *chan); |
247 | int (*is_disabled)(struct channel *chan); | |
38fae1d3 | 248 | int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle); |
8020ceb5 MD |
249 | }; |
250 | ||
251 | struct ltt_channel { | |
a3f61e7f MD |
252 | /* |
253 | * The pointers located in this private data are NOT safe to be | |
254 | * dereferenced by the consumer. The only operations the | |
255 | * consumer process is designed to be allowed to do is to read | |
256 | * and perform subbuffer flush. | |
257 | */ | |
8020ceb5 | 258 | struct channel *chan; /* Channel buffers */ |
976fe9ea | 259 | int enabled; |
8020ceb5 MD |
260 | struct lttng_ctx *ctx; |
261 | /* Event ID management */ | |
262 | struct ltt_session *session; | |
0a42beb6 | 263 | int objd; /* Object associated to channel */ |
8020ceb5 | 264 | unsigned int free_event_id; /* Next event ID to allocate */ |
8165c8da | 265 | unsigned int used_event_id; /* Max allocated event IDs */ |
9f3fdbc6 | 266 | struct cds_list_head list; /* Channel list */ |
8020ceb5 MD |
267 | struct ltt_channel_ops *ops; |
268 | int header_type; /* 0: unset, 1: compact, 2: large */ | |
38fae1d3 | 269 | struct lttng_ust_shm_handle *handle; /* shared-memory handle */ |
8020ceb5 | 270 | int metadata_dumped:1; |
a3f61e7f MD |
271 | |
272 | /* Channel ID, available for consumer too */ | |
273 | unsigned int id; | |
274 | /* Copy of session UUID for consumer (availability through shm) */ | |
275 | uuid_t uuid; /* Trace session unique ID */ | |
8020ceb5 MD |
276 | }; |
277 | ||
278 | struct ltt_session { | |
279 | int active; /* Is trace session active ? */ | |
280 | int been_active; /* Has trace session been active ? */ | |
0a42beb6 | 281 | int objd; /* Object associated to session */ |
8020ceb5 | 282 | struct ltt_channel *metadata; /* Metadata channel */ |
9f3fdbc6 MD |
283 | struct cds_list_head chan; /* Channel list head */ |
284 | struct cds_list_head events; /* Event list head */ | |
285 | struct cds_list_head list; /* Session list */ | |
8020ceb5 | 286 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
9f3fdbc6 | 287 | uuid_t uuid; /* Trace session unique ID */ |
8020ceb5 MD |
288 | int metadata_dumped:1; |
289 | }; | |
290 | ||
291 | struct ltt_transport { | |
292 | char *name; | |
9f3fdbc6 | 293 | struct cds_list_head node; |
8020ceb5 MD |
294 | struct ltt_channel_ops ops; |
295 | }; | |
296 | ||
297 | struct ltt_session *ltt_session_create(void); | |
976fe9ea MD |
298 | int ltt_session_enable(struct ltt_session *session); |
299 | int ltt_session_disable(struct ltt_session *session); | |
8020ceb5 MD |
300 | void ltt_session_destroy(struct ltt_session *session); |
301 | ||
302 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, | |
303 | const char *transport_name, | |
304 | void *buf_addr, | |
305 | size_t subbuf_size, size_t num_subbuf, | |
306 | unsigned int switch_timer_interval, | |
193183fb MD |
307 | unsigned int read_timer_interval, |
308 | int *shm_fd, int *wait_fd, | |
309 | uint64_t *memory_map_size); | |
8020ceb5 MD |
310 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, |
311 | int overwrite, void *buf_addr, | |
312 | size_t subbuf_size, size_t num_subbuf, | |
313 | unsigned int switch_timer_interval, | |
193183fb MD |
314 | unsigned int read_timer_interval, |
315 | int *shm_fd, int *wait_fd, | |
316 | uint64_t *memory_map_size); | |
8020ceb5 MD |
317 | |
318 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, | |
9f3fdbc6 | 319 | struct lttng_ust_event *event_param, |
8020ceb5 MD |
320 | void *filter); |
321 | ||
976fe9ea MD |
322 | int ltt_channel_enable(struct ltt_channel *channel); |
323 | int ltt_channel_disable(struct ltt_channel *channel); | |
324 | int ltt_event_enable(struct ltt_event *event); | |
325 | int ltt_event_disable(struct ltt_event *event); | |
326 | ||
8020ceb5 MD |
327 | void ltt_transport_register(struct ltt_transport *transport); |
328 | void ltt_transport_unregister(struct ltt_transport *transport); | |
329 | ||
4b4de73e | 330 | void synchronize_trace(void); |
8020ceb5 MD |
331 | |
332 | int ltt_probe_register(struct lttng_probe_desc *desc); | |
333 | void ltt_probe_unregister(struct lttng_probe_desc *desc); | |
8165c8da | 334 | int pending_probe_fix_events(const struct lttng_event_desc *desc); |
8020ceb5 MD |
335 | const struct lttng_event_desc *ltt_event_get(const char *name); |
336 | void ltt_event_put(const struct lttng_event_desc *desc); | |
337 | int ltt_probes_init(void); | |
338 | void ltt_probes_exit(void); | |
8173ec7c MD |
339 | int lttng_find_context(struct lttng_ctx *ctx, const char *name); |
340 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p); | |
341 | void lttng_remove_context_field(struct lttng_ctx **ctx_p, | |
8020ceb5 MD |
342 | struct lttng_ctx_field *field); |
343 | void lttng_destroy_context(struct lttng_ctx *ctx); | |
3b402b40 | 344 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
c1ef86f0 | 345 | int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); |
8173ec7c | 346 | int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); |
4847e9bb | 347 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); |
a93bfc45 | 348 | void lttng_context_vtid_reset(void); |
c1ef86f0 | 349 | void lttng_context_vpid_reset(void); |
9f3fdbc6 | 350 | |
7a784989 MD |
351 | const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata; |
352 | const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard; | |
353 | const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite; | |
c1fca457 MD |
354 | |
355 | struct cds_list_head ltt_transport_list; | |
356 | struct ltt_transport *ltt_transport_find(const char *name); | |
357 | ||
0a42beb6 | 358 | #endif /* _UST_LTTNG_EVENTS_H */ |