Fix: don't define variables in headers
[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-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22 #include <urcu/list.h>
23 #include <urcu/hlist.h>
24 #include <uuid/uuid.h>
25 #include <stdint.h>
26 #include <lttng/ust-abi.h>
27 #include <lttng/ust-tracer.h>
28 #include <endian.h>
29 #include <float.h>
30
31 struct ltt_channel;
32 struct ltt_session;
33 struct lttng_ust_lib_ring_buffer_ctx;
34
35 /*
36 * Data structures used by tracepoint event declarations, and by the
37 * tracer. Those structures have padding for future extension.
38 */
39
40 /*
41 * LTTng client type enumeration. Used by the consumer to map the
42 * callbacks from its own address space.
43 */
44 enum lttng_client_types {
45 LTTNG_CLIENT_METADATA = 0,
46 LTTNG_CLIENT_DISCARD = 1,
47 LTTNG_CLIENT_OVERWRITE = 2,
48 LTTNG_NR_CLIENT_TYPES,
49 };
50
51 /* Type description */
52
53 /* Update the astract_types name table in lttng-types.c along with this enum */
54 enum abstract_types {
55 atype_integer,
56 atype_enum,
57 atype_array,
58 atype_sequence,
59 atype_string,
60 atype_float,
61 NR_ABSTRACT_TYPES,
62 };
63
64 /* Update the string_encodings name table in lttng-types.c along with this enum */
65 enum lttng_string_encodings {
66 lttng_encode_none = 0,
67 lttng_encode_UTF8 = 1,
68 lttng_encode_ASCII = 2,
69 NR_STRING_ENCODINGS,
70 };
71
72 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
73 struct lttng_enum_entry {
74 unsigned long long start, end; /* start and end are inclusive */
75 const char *string;
76 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
77 };
78
79 #define __type_integer(_type, _byte_order, _base, _encoding) \
80 { \
81 .atype = atype_integer, \
82 .u.basic.integer = \
83 { \
84 .size = sizeof(_type) * CHAR_BIT, \
85 .alignment = lttng_alignof(_type) * CHAR_BIT, \
86 .signedness = lttng_is_signed_type(_type), \
87 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
88 .base = _base, \
89 .encoding = lttng_encode_##_encoding, \
90 }, \
91 } \
92
93 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
94 struct lttng_integer_type {
95 unsigned int size; /* in bits */
96 unsigned short alignment; /* in bits */
97 unsigned int signedness:1;
98 unsigned int reverse_byte_order:1;
99 unsigned int base; /* 2, 8, 10, 16, for pretty print */
100 enum lttng_string_encodings encoding;
101 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
102 };
103
104 /*
105 * Only float and double are supported. long double is not supported at
106 * the moment.
107 */
108 #define _float_mant_dig(_type) \
109 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
110 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
111 : 0))
112
113 #define __type_float(_type) \
114 { \
115 .atype = atype_float, \
116 .u.basic._float = \
117 { \
118 .exp_dig = sizeof(_type) * CHAR_BIT \
119 - _float_mant_dig(_type), \
120 .mant_dig = _float_mant_dig(_type), \
121 .alignment = lttng_alignof(_type) * CHAR_BIT, \
122 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
123 }, \
124 } \
125
126 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
127 struct lttng_float_type {
128 unsigned int exp_dig; /* exponent digits, in bits */
129 unsigned int mant_dig; /* mantissa digits, in bits */
130 unsigned short alignment; /* in bits */
131 unsigned int reverse_byte_order:1;
132 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
133 };
134
135 #define LTTNG_UST_BASIC_TYPE_PADDING 128
136 union _lttng_basic_type {
137 struct lttng_integer_type integer;
138 struct {
139 const char *name;
140 } enumeration;
141 struct {
142 enum lttng_string_encodings encoding;
143 } string;
144 struct lttng_float_type _float;
145 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
146 };
147
148 struct lttng_basic_type {
149 enum abstract_types atype;
150 union {
151 union _lttng_basic_type basic;
152 } u;
153 };
154
155 #define LTTNG_UST_TYPE_PADDING 128
156 struct lttng_type {
157 enum abstract_types atype;
158 union {
159 union _lttng_basic_type basic;
160 struct {
161 struct lttng_basic_type elem_type;
162 unsigned int length; /* num. elems. */
163 } array;
164 struct {
165 struct lttng_basic_type length_type;
166 struct lttng_basic_type elem_type;
167 } sequence;
168 char padding[LTTNG_UST_TYPE_PADDING];
169 } u;
170 };
171
172 #define LTTNG_UST_ENUM_TYPE_PADDING 24
173 struct lttng_enum {
174 const char *name;
175 struct lttng_type container_type;
176 const struct lttng_enum_entry *entries;
177 unsigned int len;
178 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
179 };
180
181 /* Event field description */
182
183 #define LTTNG_UST_EVENT_FIELD_PADDING 32
184 struct lttng_event_field {
185 const char *name;
186 struct lttng_type type;
187 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
188 };
189
190 #define LTTNG_UST_CTX_FIELD_PADDING 40
191 struct lttng_ctx_field {
192 struct lttng_event_field event_field;
193 size_t (*get_size)(size_t offset);
194 void (*record)(struct lttng_ctx_field *field,
195 struct lttng_ust_lib_ring_buffer_ctx *ctx,
196 struct ltt_channel *chan);
197 union {
198 char padding[LTTNG_UST_CTX_FIELD_PADDING];
199 } u;
200 void (*destroy)(struct lttng_ctx_field *field);
201 };
202
203 #define LTTNG_UST_CTX_PADDING 24
204 struct lttng_ctx {
205 struct lttng_ctx_field *fields;
206 unsigned int nr_fields;
207 unsigned int allocated_fields;
208 char padding[LTTNG_UST_CTX_PADDING];
209 };
210
211 #define LTTNG_UST_EVENT_DESC_PADDING 40
212 struct lttng_event_desc {
213 const char *name;
214 void *probe_callback;
215 const struct lttng_event_ctx *ctx; /* context */
216 const struct lttng_event_field *fields; /* event payload */
217 unsigned int nr_fields;
218 const int **loglevel;
219 const char *signature; /* Argument types/names received */
220 char padding[LTTNG_UST_EVENT_DESC_PADDING];
221 };
222
223 #define LTTNG_UST_PROBE_DESC_PADDING 40
224 struct lttng_probe_desc {
225 const char *provider;
226 const struct lttng_event_desc **event_desc;
227 unsigned int nr_events;
228 struct cds_list_head head; /* chain registered probes */
229 char padding[LTTNG_UST_PROBE_DESC_PADDING];
230 };
231
232 /* Data structures used by the tracer. */
233
234 /*
235 * Entry describing a per-session active wildcard, along with the event
236 * attribute and channel information configuring the events that need to
237 * be enabled.
238 */
239 struct session_wildcard {
240 struct ltt_channel *chan;
241 struct lttng_ctx *ctx; /* TODO */
242 struct lttng_ust_event event_param;
243 struct cds_list_head events; /* list of events enabled */
244 struct cds_list_head list; /* per-session list of wildcards */
245 struct cds_list_head session_list; /* node of session wildcard list */
246 struct wildcard_entry *entry;
247 unsigned int enabled:1;
248 };
249
250 /*
251 * Entry describing an active wildcard (per name) for all sessions.
252 */
253 struct wildcard_entry {
254 /* node of global wildcards list */
255 struct cds_list_head list;
256 /* head of session list to which this wildcard apply */
257 struct cds_list_head session_list;
258 enum lttng_ust_loglevel_type loglevel_type;
259 int loglevel;
260 char name[0];
261 };
262
263 struct tp_list_entry {
264 struct lttng_ust_tracepoint_iter tp;
265 struct cds_list_head head;
266 };
267
268 struct lttng_ust_tracepoint_list {
269 struct tp_list_entry *iter;
270 struct cds_list_head head;
271 };
272
273 struct ust_pending_probe;
274
275 /*
276 * ltt_event structure is referred to by the tracing fast path. It must be
277 * kept small.
278 */
279 struct ltt_event {
280 unsigned int id;
281 struct ltt_channel *chan;
282 int enabled;
283 const struct lttng_event_desc *desc;
284 void *filter;
285 struct lttng_ctx *ctx;
286 enum lttng_ust_instrumentation instrumentation;
287 union {
288 } u;
289 struct cds_list_head list; /* Event list */
290 struct cds_list_head wildcard_list; /* Event list for wildcard */
291 struct ust_pending_probe *pending_probe;
292 unsigned int metadata_dumped:1;
293 };
294
295 struct channel;
296 struct lttng_ust_shm_handle;
297
298 struct ltt_channel_ops {
299 struct ltt_channel *(*channel_create)(const char *name,
300 void *buf_addr,
301 size_t subbuf_size, size_t num_subbuf,
302 unsigned int switch_timer_interval,
303 unsigned int read_timer_interval,
304 int **shm_fd, int **wait_fd,
305 uint64_t **memory_map_size,
306 struct ltt_channel *chan_priv_init);
307 void (*channel_destroy)(struct ltt_channel *ltt_chan);
308 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
309 struct lttng_ust_shm_handle *handle,
310 int **shm_fd, int **wait_fd,
311 uint64_t **memory_map_size);
312 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
313 struct lttng_ust_shm_handle *handle);
314 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
315 uint32_t event_id);
316 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
317 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
318 size_t len);
319 /*
320 * packet_avail_size returns the available size in the current
321 * packet. Note that the size returned is only a hint, since it
322 * may change due to concurrent writes.
323 */
324 size_t (*packet_avail_size)(struct channel *chan,
325 struct lttng_ust_shm_handle *handle);
326 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
327 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
328 int (*is_finalized)(struct channel *chan);
329 int (*is_disabled)(struct channel *chan);
330 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
331 };
332
333 struct ltt_channel {
334 /*
335 * The pointers located in this private data are NOT safe to be
336 * dereferenced by the consumer. The only operations the
337 * consumer process is designed to be allowed to do is to read
338 * and perform subbuffer flush.
339 */
340 struct channel *chan; /* Channel buffers */
341 int enabled;
342 struct lttng_ctx *ctx;
343 /* Event ID management */
344 struct ltt_session *session;
345 int objd; /* Object associated to channel */
346 unsigned int free_event_id; /* Next event ID to allocate */
347 unsigned int used_event_id; /* Max allocated event IDs */
348 struct cds_list_head list; /* Channel list */
349 struct ltt_channel_ops *ops;
350 int header_type; /* 0: unset, 1: compact, 2: large */
351 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
352 unsigned int metadata_dumped:1;
353
354 /* Channel ID, available for consumer too */
355 unsigned int id;
356 /* Copy of session UUID for consumer (availability through shm) */
357 uuid_t uuid; /* Trace session unique ID */
358 };
359
360 struct ltt_session {
361 int active; /* Is trace session active ? */
362 int been_active; /* Has trace session been active ? */
363 int objd; /* Object associated to session */
364 struct ltt_channel *metadata; /* Metadata channel */
365 struct cds_list_head chan; /* Channel list head */
366 struct cds_list_head events; /* Event list head */
367 struct cds_list_head wildcards; /* Wildcard list head */
368 struct cds_list_head list; /* Session list */
369 unsigned int free_chan_id; /* Next chan ID to allocate */
370 uuid_t uuid; /* Trace session unique ID */
371 unsigned int metadata_dumped:1;
372 };
373
374 struct ltt_transport {
375 char *name;
376 struct cds_list_head node;
377 struct ltt_channel_ops ops;
378 };
379
380 struct ltt_session *ltt_session_create(void);
381 int ltt_session_enable(struct ltt_session *session);
382 int ltt_session_disable(struct ltt_session *session);
383 void ltt_session_destroy(struct ltt_session *session);
384
385 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
386 const char *transport_name,
387 void *buf_addr,
388 size_t subbuf_size, size_t num_subbuf,
389 unsigned int switch_timer_interval,
390 unsigned int read_timer_interval,
391 int **shm_fd, int **wait_fd,
392 uint64_t **memory_map_size,
393 struct ltt_channel *chan_priv_init);
394 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
395 int overwrite, void *buf_addr,
396 size_t subbuf_size, size_t num_subbuf,
397 unsigned int switch_timer_interval,
398 unsigned int read_timer_interval,
399 int **shm_fd, int **wait_fd,
400 uint64_t **memory_map_size);
401
402 int ltt_event_create(struct ltt_channel *chan,
403 struct lttng_ust_event *event_param,
404 void *filter,
405 struct ltt_event **event);
406
407 int ltt_channel_enable(struct ltt_channel *channel);
408 int ltt_channel_disable(struct ltt_channel *channel);
409 int ltt_event_enable(struct ltt_event *event);
410 int ltt_event_disable(struct ltt_event *event);
411
412 void ltt_transport_register(struct ltt_transport *transport);
413 void ltt_transport_unregister(struct ltt_transport *transport);
414
415 void synchronize_trace(void);
416
417 int ltt_probe_register(struct lttng_probe_desc *desc);
418 void ltt_probe_unregister(struct lttng_probe_desc *desc);
419 int pending_probe_fix_events(const struct lttng_event_desc *desc);
420 const struct lttng_event_desc *ltt_event_get(const char *name);
421 void ltt_event_put(const struct lttng_event_desc *desc);
422 int ltt_probes_init(void);
423 void ltt_probes_exit(void);
424 int lttng_find_context(struct lttng_ctx *ctx, const char *name);
425 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
426 void lttng_remove_context_field(struct lttng_ctx **ctx_p,
427 struct lttng_ctx_field *field);
428 void lttng_destroy_context(struct lttng_ctx *ctx);
429 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
430 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
431 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
432 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
433 void lttng_context_vtid_reset(void);
434 void lttng_context_vpid_reset(void);
435
436 extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
437 extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
438 extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
439
440 struct ltt_transport *ltt_transport_find(const char *name);
441
442 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
443 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
444 struct lttng_ust_tracepoint_iter *
445 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
446
447 int ltt_wildcard_enable(struct session_wildcard *wildcard);
448 int ltt_wildcard_disable(struct session_wildcard *wildcard);
449 int ltt_wildcard_create(struct ltt_channel *chan,
450 struct lttng_ust_event *event_param,
451 struct session_wildcard **sl);
452 int ltt_loglevel_match(const struct lttng_event_desc *desc,
453 enum lttng_ust_loglevel_type req_type,
454 int req_loglevel);
455 void ltt_probes_create_wildcard_events(struct wildcard_entry *entry,
456 struct session_wildcard *wildcard);
457
458 #endif /* _LTTNG_UST_EVENTS_H */
This page took 0.057521 seconds and 4 git commands to generate.