ltt_event_create should return error values
[lttng-ust.git] / include / lttng / ust-events.h
1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
3
4 /*
5 * lttng/ust-events.h
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
11 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
12 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
13 *
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.
19 */
20
21 #include <urcu/list.h>
22 #include <uuid/uuid.h>
23 #include <stdint.h>
24 #include <lttng/ust-abi.h>
25 #include <lttng/ust-tracer.h>
26 #include <endian.h>
27 #include <float.h>
28
29 struct ltt_channel;
30 struct ltt_session;
31 struct lttng_ust_lib_ring_buffer_ctx;
32
33 /*
34 * LTTng client type enumeration. Used by the consumer to map the
35 * callbacks from its own address space.
36 */
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,
42 };
43
44 /* Type description */
45
46 /* Update the astract_types name table in lttng-types.c along with this enum */
47 enum abstract_types {
48 atype_integer,
49 atype_enum,
50 atype_array,
51 atype_sequence,
52 atype_string,
53 atype_float,
54 NR_ABSTRACT_TYPES,
55 };
56
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,
62 NR_STRING_ENCODINGS,
63 };
64
65 struct lttng_enum_entry {
66 unsigned long long start, end; /* start and end are inclusive */
67 const char *string;
68 };
69
70 #define __type_integer(_type, _byte_order, _base, _encoding) \
71 { \
72 .atype = atype_integer, \
73 .u.basic.integer = \
74 { \
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, \
79 .base = _base, \
80 .encoding = lttng_encode_##_encoding, \
81 }, \
82 } \
83
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;
91 };
92
93 /*
94 * Only float and double are supported. long double is not supported at
95 * the moment.
96 */
97 #define _float_mant_dig(_type) \
98 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
99 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
100 : 0))
101
102 #define __type_float(_type) \
103 { \
104 .atype = atype_float, \
105 .u.basic._float = \
106 { \
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, \
112 }, \
113 } \
114
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;
120 };
121
122 union _lttng_basic_type {
123 struct lttng_integer_type integer;
124 struct {
125 const char *name;
126 } enumeration;
127 struct {
128 enum lttng_string_encodings encoding;
129 } string;
130 struct lttng_float_type _float;
131 };
132
133 struct lttng_basic_type {
134 enum abstract_types atype;
135 union {
136 union _lttng_basic_type basic;
137 } u;
138 };
139
140 struct lttng_type {
141 enum abstract_types atype;
142 union {
143 union _lttng_basic_type basic;
144 struct {
145 struct lttng_basic_type elem_type;
146 unsigned int length; /* num. elems. */
147 } array;
148 struct {
149 struct lttng_basic_type length_type;
150 struct lttng_basic_type elem_type;
151 } sequence;
152 } u;
153 };
154
155 struct lttng_enum {
156 const char *name;
157 struct lttng_type container_type;
158 const struct lttng_enum_entry *entries;
159 unsigned int len;
160 };
161
162 /* Event field description */
163
164 struct lttng_event_field {
165 const char *name;
166 struct lttng_type type;
167 };
168
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);
175 union {
176 } u;
177 void (*destroy)(struct lttng_ctx_field *field);
178 };
179
180 struct lttng_ctx {
181 struct lttng_ctx_field *fields;
182 unsigned int nr_fields;
183 unsigned int allocated_fields;
184 };
185
186 struct lttng_event_desc {
187 const char *name;
188 void *probe_callback;
189 const struct lttng_event_ctx *ctx; /* context */
190 const struct lttng_event_field *fields; /* event payload */
191 unsigned int nr_fields;
192 };
193
194 struct lttng_probe_desc {
195 const struct lttng_event_desc *event_desc;
196 unsigned int nr_events;
197 struct cds_list_head head; /* chain registered probes */
198 struct tracepoint_loglevel *loglevels;
199 };
200
201 struct ust_pending_probe;
202
203 /*
204 * ltt_event structure is referred to by the tracing fast path. It must be
205 * kept small.
206 */
207 struct ltt_event {
208 unsigned int id;
209 struct ltt_channel *chan;
210 int enabled;
211 const struct lttng_event_desc *desc;
212 void *filter;
213 struct lttng_ctx *ctx;
214 enum lttng_ust_instrumentation instrumentation;
215 union {
216 } u;
217 struct cds_list_head list; /* Event list */
218 struct ust_pending_probe *pending_probe;
219 int metadata_dumped:1;
220 };
221
222 struct channel;
223 struct lttng_ust_shm_handle;
224
225 struct ltt_channel_ops {
226 struct ltt_channel *(*channel_create)(const char *name,
227 void *buf_addr,
228 size_t subbuf_size, size_t num_subbuf,
229 unsigned int switch_timer_interval,
230 unsigned int read_timer_interval,
231 int *shm_fd, int *wait_fd,
232 uint64_t *memory_map_size,
233 struct ltt_channel *chan_priv_init);
234 void (*channel_destroy)(struct ltt_channel *ltt_chan);
235 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
236 struct lttng_ust_shm_handle *handle,
237 int *shm_fd, int *wait_fd,
238 uint64_t *memory_map_size);
239 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
240 struct lttng_ust_shm_handle *handle);
241 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
242 uint32_t event_id);
243 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
244 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
245 size_t len);
246 /*
247 * packet_avail_size returns the available size in the current
248 * packet. Note that the size returned is only a hint, since it
249 * may change due to concurrent writes.
250 */
251 size_t (*packet_avail_size)(struct channel *chan,
252 struct lttng_ust_shm_handle *handle);
253 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
254 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
255 int (*is_finalized)(struct channel *chan);
256 int (*is_disabled)(struct channel *chan);
257 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
258 };
259
260 struct ltt_channel {
261 /*
262 * The pointers located in this private data are NOT safe to be
263 * dereferenced by the consumer. The only operations the
264 * consumer process is designed to be allowed to do is to read
265 * and perform subbuffer flush.
266 */
267 struct channel *chan; /* Channel buffers */
268 int enabled;
269 struct lttng_ctx *ctx;
270 /* Event ID management */
271 struct ltt_session *session;
272 int objd; /* Object associated to channel */
273 unsigned int free_event_id; /* Next event ID to allocate */
274 unsigned int used_event_id; /* Max allocated event IDs */
275 struct cds_list_head list; /* Channel list */
276 struct ltt_channel_ops *ops;
277 int header_type; /* 0: unset, 1: compact, 2: large */
278 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
279 int metadata_dumped:1;
280
281 /* Channel ID, available for consumer too */
282 unsigned int id;
283 /* Copy of session UUID for consumer (availability through shm) */
284 uuid_t uuid; /* Trace session unique ID */
285 };
286
287 struct ltt_session {
288 int active; /* Is trace session active ? */
289 int been_active; /* Has trace session been active ? */
290 int objd; /* Object associated to session */
291 struct ltt_channel *metadata; /* Metadata channel */
292 struct cds_list_head chan; /* Channel list head */
293 struct cds_list_head events; /* Event list head */
294 struct cds_list_head list; /* Session list */
295 unsigned int free_chan_id; /* Next chan ID to allocate */
296 uuid_t uuid; /* Trace session unique ID */
297 int metadata_dumped:1;
298 };
299
300 struct ltt_transport {
301 char *name;
302 struct cds_list_head node;
303 struct ltt_channel_ops ops;
304 };
305
306 struct tracepoint_loglevel_enum_entry {
307 const char *identifier;
308 long value;
309 };
310
311 /* mapping between tracepoint and loglevel */
312 struct tracepoint_loglevel {
313 const char *name;
314 const struct tracepoint_loglevel_enum_entry *loglevel;
315 };
316
317 struct ltt_session *ltt_session_create(void);
318 int ltt_session_enable(struct ltt_session *session);
319 int ltt_session_disable(struct ltt_session *session);
320 void ltt_session_destroy(struct ltt_session *session);
321
322 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
323 const char *transport_name,
324 void *buf_addr,
325 size_t subbuf_size, size_t num_subbuf,
326 unsigned int switch_timer_interval,
327 unsigned int read_timer_interval,
328 int *shm_fd, int *wait_fd,
329 uint64_t *memory_map_size,
330 struct ltt_channel *chan_priv_init);
331 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
332 int overwrite, void *buf_addr,
333 size_t subbuf_size, size_t num_subbuf,
334 unsigned int switch_timer_interval,
335 unsigned int read_timer_interval,
336 int *shm_fd, int *wait_fd,
337 uint64_t *memory_map_size);
338
339 int ltt_event_create(struct ltt_channel *chan,
340 struct lttng_ust_event *event_param,
341 void *filter,
342 struct ltt_event **event);
343
344 int ltt_channel_enable(struct ltt_channel *channel);
345 int ltt_channel_disable(struct ltt_channel *channel);
346 int ltt_event_enable(struct ltt_event *event);
347 int ltt_event_disable(struct ltt_event *event);
348
349 void ltt_transport_register(struct ltt_transport *transport);
350 void ltt_transport_unregister(struct ltt_transport *transport);
351
352 void synchronize_trace(void);
353
354 int ltt_probe_register(struct lttng_probe_desc *desc);
355 void ltt_probe_unregister(struct lttng_probe_desc *desc);
356 int pending_probe_fix_events(const struct lttng_event_desc *desc);
357 const struct lttng_event_desc *ltt_event_get(const char *name);
358 void ltt_event_put(const struct lttng_event_desc *desc);
359 int ltt_probes_init(void);
360 void ltt_probes_exit(void);
361 int lttng_find_context(struct lttng_ctx *ctx, const char *name);
362 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
363 void lttng_remove_context_field(struct lttng_ctx **ctx_p,
364 struct lttng_ctx_field *field);
365 void lttng_destroy_context(struct lttng_ctx *ctx);
366 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
367 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
368 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
369 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
370 void lttng_context_vtid_reset(void);
371 void lttng_context_vpid_reset(void);
372
373 const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
374 const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
375 const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
376
377 struct ltt_transport *ltt_transport_find(const char *name);
378
379 #endif /* _LTTNG_UST_EVENTS_H */
This page took 0.047284 seconds and 5 git commands to generate.