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> | |
17 | #include <ust/lttng-ust-abi.h> | |
20f1eee7 MD |
18 | #include <endian.h> |
19 | #include <float.h> | |
8020ceb5 MD |
20 | |
21 | #undef is_signed_type | |
22 | #define is_signed_type(type) (((type)(-1)) < 0) | |
23 | ||
24 | struct ltt_channel; | |
25 | struct ltt_session; | |
26 | struct lib_ring_buffer_ctx; | |
8020ceb5 MD |
27 | |
28 | /* Type description */ | |
29 | ||
30 | /* Update the astract_types name table in lttng-types.c along with this enum */ | |
31 | enum abstract_types { | |
32 | atype_integer, | |
33 | atype_enum, | |
34 | atype_array, | |
35 | atype_sequence, | |
36 | atype_string, | |
20f1eee7 | 37 | atype_float, |
8020ceb5 MD |
38 | NR_ABSTRACT_TYPES, |
39 | }; | |
40 | ||
41 | /* Update the string_encodings name table in lttng-types.c along with this enum */ | |
42 | enum lttng_string_encodings { | |
43 | lttng_encode_none = 0, | |
44 | lttng_encode_UTF8 = 1, | |
45 | lttng_encode_ASCII = 2, | |
46 | NR_STRING_ENCODINGS, | |
47 | }; | |
48 | ||
49 | struct lttng_enum_entry { | |
50 | unsigned long long start, end; /* start and end are inclusive */ | |
51 | const char *string; | |
52 | }; | |
53 | ||
54 | #define __type_integer(_type, _byte_order, _base, _encoding) \ | |
55 | { \ | |
56 | .atype = atype_integer, \ | |
57 | .u.basic.integer = \ | |
58 | { \ | |
59 | .size = sizeof(_type) * CHAR_BIT, \ | |
60 | .alignment = ltt_alignof(_type) * CHAR_BIT, \ | |
61 | .signedness = is_signed_type(_type), \ | |
62 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ | |
63 | .base = _base, \ | |
64 | .encoding = lttng_encode_##_encoding, \ | |
65 | }, \ | |
66 | } \ | |
67 | ||
68 | struct lttng_integer_type { | |
69 | unsigned int size; /* in bits */ | |
70 | unsigned short alignment; /* in bits */ | |
71 | unsigned int signedness:1; | |
72 | unsigned int reverse_byte_order:1; | |
73 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ | |
74 | enum lttng_string_encodings encoding; | |
75 | }; | |
76 | ||
20f1eee7 MD |
77 | #define _float_mant_dig(_type) \ |
78 | (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \ | |
79 | : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \ | |
80 | : (sizeof(_type) == sizeof(long double) ? LDBL_MANT_DIG \ | |
81 | : 0))) | |
82 | ||
83 | #define __type_float(_type) \ | |
84 | { \ | |
85 | .atype = atype_float, \ | |
86 | .u.basic._float = \ | |
87 | { \ | |
88 | .exp_dig = sizeof(_type) * CHAR_BIT \ | |
89 | - _float_mant_dig(_type), \ | |
90 | .mant_dig = _float_mant_dig(_type), \ | |
91 | .alignment = ltt_alignof(_type) * CHAR_BIT, \ | |
92 | .signedness = is_signed_type(_type), \ | |
93 | .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \ | |
94 | }, \ | |
95 | } \ | |
96 | ||
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; | |
102 | }; | |
103 | ||
8020ceb5 MD |
104 | union _lttng_basic_type { |
105 | struct lttng_integer_type integer; | |
106 | struct { | |
107 | const char *name; | |
108 | } enumeration; | |
109 | struct { | |
110 | enum lttng_string_encodings encoding; | |
111 | } string; | |
20f1eee7 | 112 | struct lttng_float_type _float; |
8020ceb5 MD |
113 | }; |
114 | ||
115 | struct lttng_basic_type { | |
116 | enum abstract_types atype; | |
117 | union { | |
118 | union _lttng_basic_type basic; | |
119 | } u; | |
120 | }; | |
121 | ||
122 | struct lttng_type { | |
123 | enum abstract_types atype; | |
124 | union { | |
125 | union _lttng_basic_type basic; | |
126 | struct { | |
127 | struct lttng_basic_type elem_type; | |
128 | unsigned int length; /* num. elems. */ | |
129 | } array; | |
130 | struct { | |
131 | struct lttng_basic_type length_type; | |
132 | struct lttng_basic_type elem_type; | |
133 | } sequence; | |
134 | } u; | |
135 | }; | |
136 | ||
137 | struct lttng_enum { | |
138 | const char *name; | |
139 | struct lttng_type container_type; | |
140 | const struct lttng_enum_entry *entries; | |
141 | unsigned int len; | |
142 | }; | |
143 | ||
144 | /* Event field description */ | |
145 | ||
146 | struct lttng_event_field { | |
147 | const char *name; | |
148 | struct lttng_type type; | |
149 | }; | |
150 | ||
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 lib_ring_buffer_ctx *ctx, | |
156 | struct ltt_channel *chan); | |
157 | union { | |
8020ceb5 MD |
158 | } u; |
159 | void (*destroy)(struct lttng_ctx_field *field); | |
160 | }; | |
161 | ||
162 | struct lttng_ctx { | |
163 | struct lttng_ctx_field *fields; | |
164 | unsigned int nr_fields; | |
165 | unsigned int allocated_fields; | |
166 | }; | |
167 | ||
168 | struct lttng_event_desc { | |
169 | const char *name; | |
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; | |
8020ceb5 MD |
174 | }; |
175 | ||
176 | struct lttng_probe_desc { | |
177 | const struct lttng_event_desc *event_desc; | |
178 | unsigned int nr_events; | |
9f3fdbc6 | 179 | struct cds_list_head head; /* chain registered probes */ |
8020ceb5 MD |
180 | }; |
181 | ||
182 | /* | |
183 | * ltt_event structure is referred to by the tracing fast path. It must be | |
184 | * kept small. | |
185 | */ | |
186 | struct ltt_event { | |
187 | unsigned int id; | |
188 | struct ltt_channel *chan; | |
976fe9ea | 189 | int enabled; |
8020ceb5 MD |
190 | const struct lttng_event_desc *desc; |
191 | void *filter; | |
192 | struct lttng_ctx *ctx; | |
9f3fdbc6 | 193 | enum lttng_ust_instrumentation instrumentation; |
8020ceb5 | 194 | union { |
8020ceb5 | 195 | } u; |
9f3fdbc6 | 196 | struct cds_list_head list; /* Event list */ |
8020ceb5 MD |
197 | int metadata_dumped:1; |
198 | }; | |
199 | ||
8d8a24c8 MD |
200 | struct channel; |
201 | ||
8020ceb5 | 202 | struct ltt_channel_ops { |
8d8a24c8 | 203 | struct shm_handle *(*channel_create)(const char *name, |
8020ceb5 MD |
204 | struct ltt_channel *ltt_chan, |
205 | void *buf_addr, | |
206 | size_t subbuf_size, size_t num_subbuf, | |
207 | unsigned int switch_timer_interval, | |
8d8a24c8 MD |
208 | unsigned int read_timer_interval); |
209 | void (*channel_destroy)(struct shm_handle *handle); | |
8020ceb5 MD |
210 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); |
211 | void (*buffer_read_close)(struct lib_ring_buffer *buf); | |
212 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx, | |
213 | uint32_t event_id); | |
214 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); | |
215 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, | |
216 | size_t len); | |
217 | /* | |
218 | * packet_avail_size returns the available size in the current | |
219 | * packet. Note that the size returned is only a hint, since it | |
220 | * may change due to concurrent writes. | |
221 | */ | |
222 | size_t (*packet_avail_size)(struct channel *chan); | |
9f3fdbc6 MD |
223 | //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); |
224 | //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); | |
8020ceb5 MD |
225 | int (*is_finalized)(struct channel *chan); |
226 | int (*is_disabled)(struct channel *chan); | |
227 | }; | |
228 | ||
229 | struct ltt_channel { | |
230 | unsigned int id; | |
231 | struct channel *chan; /* Channel buffers */ | |
976fe9ea | 232 | int enabled; |
8020ceb5 MD |
233 | struct lttng_ctx *ctx; |
234 | /* Event ID management */ | |
235 | struct ltt_session *session; | |
0a42beb6 | 236 | int objd; /* Object associated to channel */ |
8020ceb5 | 237 | unsigned int free_event_id; /* Next event ID to allocate */ |
9f3fdbc6 | 238 | struct cds_list_head list; /* Channel list */ |
8020ceb5 MD |
239 | struct ltt_channel_ops *ops; |
240 | int header_type; /* 0: unset, 1: compact, 2: large */ | |
8d8a24c8 | 241 | struct shm_handle *handle; /* shared-memory handle */ |
8020ceb5 MD |
242 | int metadata_dumped:1; |
243 | }; | |
244 | ||
245 | struct ltt_session { | |
246 | int active; /* Is trace session active ? */ | |
247 | int been_active; /* Has trace session been active ? */ | |
0a42beb6 | 248 | int objd; /* Object associated to session */ |
8020ceb5 | 249 | struct ltt_channel *metadata; /* Metadata channel */ |
9f3fdbc6 MD |
250 | struct cds_list_head chan; /* Channel list head */ |
251 | struct cds_list_head events; /* Event list head */ | |
252 | struct cds_list_head list; /* Session list */ | |
8020ceb5 | 253 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
9f3fdbc6 | 254 | uuid_t uuid; /* Trace session unique ID */ |
8020ceb5 MD |
255 | int metadata_dumped:1; |
256 | }; | |
257 | ||
258 | struct ltt_transport { | |
259 | char *name; | |
9f3fdbc6 | 260 | struct cds_list_head node; |
8020ceb5 MD |
261 | struct ltt_channel_ops ops; |
262 | }; | |
263 | ||
264 | struct ltt_session *ltt_session_create(void); | |
976fe9ea MD |
265 | int ltt_session_enable(struct ltt_session *session); |
266 | int ltt_session_disable(struct ltt_session *session); | |
8020ceb5 MD |
267 | void ltt_session_destroy(struct ltt_session *session); |
268 | ||
269 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, | |
270 | const char *transport_name, | |
271 | void *buf_addr, | |
272 | size_t subbuf_size, size_t num_subbuf, | |
273 | unsigned int switch_timer_interval, | |
0a42beb6 | 274 | unsigned int read_timer_interval); |
8020ceb5 MD |
275 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, |
276 | int overwrite, void *buf_addr, | |
277 | size_t subbuf_size, size_t num_subbuf, | |
278 | unsigned int switch_timer_interval, | |
279 | unsigned int read_timer_interval); | |
280 | ||
281 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, | |
9f3fdbc6 | 282 | struct lttng_ust_event *event_param, |
8020ceb5 MD |
283 | void *filter); |
284 | ||
976fe9ea MD |
285 | int ltt_channel_enable(struct ltt_channel *channel); |
286 | int ltt_channel_disable(struct ltt_channel *channel); | |
287 | int ltt_event_enable(struct ltt_event *event); | |
288 | int ltt_event_disable(struct ltt_event *event); | |
289 | ||
8020ceb5 MD |
290 | void ltt_transport_register(struct ltt_transport *transport); |
291 | void ltt_transport_unregister(struct ltt_transport *transport); | |
292 | ||
4b4de73e | 293 | void synchronize_trace(void); |
9f3fdbc6 MD |
294 | //int ltt_debugfs_abi_init(void); |
295 | //void ltt_debugfs_abi_exit(void); | |
8020ceb5 MD |
296 | |
297 | int ltt_probe_register(struct lttng_probe_desc *desc); | |
298 | void ltt_probe_unregister(struct lttng_probe_desc *desc); | |
299 | const struct lttng_event_desc *ltt_event_get(const char *name); | |
300 | void ltt_event_put(const struct lttng_event_desc *desc); | |
301 | int ltt_probes_init(void); | |
302 | void ltt_probes_exit(void); | |
303 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); | |
304 | void lttng_remove_context_field(struct lttng_ctx **ctx, | |
305 | struct lttng_ctx_field *field); | |
306 | void lttng_destroy_context(struct lttng_ctx *ctx); | |
9f3fdbc6 MD |
307 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
308 | ||
309 | //extern const struct file_operations lttng_tracepoint_list_fops; | |
8020ceb5 | 310 | |
0a42beb6 | 311 | #endif /* _UST_LTTNG_EVENTS_H */ |