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