Remove all LGPL-licensed headers
[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
MD
21#include <urcu/list.h>
22#include <uuid/uuid.h>
23#include <stdint.h>
4318ae1b
MD
24#include <lttng/ust-abi.h>
25#include <lttng/ust-tracer.h>
20f1eee7
MD
26#include <endian.h>
27#include <float.h>
51489cad 28#include <lttng/tracepoint-internal.h>
8020ceb5 29
8020ceb5
MD
30struct ltt_channel;
31struct ltt_session;
4cfec15c 32struct lttng_ust_lib_ring_buffer_ctx;
8020ceb5 33
c1fca457
MD
34/*
35 * LTTng client type enumeration. Used by the consumer to map the
36 * callbacks from its own address space.
37 */
38enum lttng_client_types {
39 LTTNG_CLIENT_METADATA = 0,
40 LTTNG_CLIENT_DISCARD = 1,
41 LTTNG_CLIENT_OVERWRITE = 2,
42 LTTNG_NR_CLIENT_TYPES,
43};
44
8020ceb5
MD
45/* Type description */
46
47/* Update the astract_types name table in lttng-types.c along with this enum */
48enum abstract_types {
49 atype_integer,
50 atype_enum,
51 atype_array,
52 atype_sequence,
53 atype_string,
20f1eee7 54 atype_float,
8020ceb5
MD
55 NR_ABSTRACT_TYPES,
56};
57
58/* Update the string_encodings name table in lttng-types.c along with this enum */
59enum lttng_string_encodings {
60 lttng_encode_none = 0,
61 lttng_encode_UTF8 = 1,
62 lttng_encode_ASCII = 2,
63 NR_STRING_ENCODINGS,
64};
65
66struct lttng_enum_entry {
67 unsigned long long start, end; /* start and end are inclusive */
68 const char *string;
69};
70
71#define __type_integer(_type, _byte_order, _base, _encoding) \
72 { \
73 .atype = atype_integer, \
74 .u.basic.integer = \
75 { \
76 .size = sizeof(_type) * CHAR_BIT, \
1dbfff0c
MD
77 .alignment = lttng_alignof(_type) * CHAR_BIT, \
78 .signedness = lttng_is_signed_type(_type), \
8020ceb5
MD
79 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
80 .base = _base, \
81 .encoding = lttng_encode_##_encoding, \
82 }, \
83 } \
84
85struct lttng_integer_type {
86 unsigned int size; /* in bits */
87 unsigned short alignment; /* in bits */
88 unsigned int signedness:1;
89 unsigned int reverse_byte_order:1;
90 unsigned int base; /* 2, 8, 10, 16, for pretty print */
91 enum lttng_string_encodings encoding;
92};
93
d3ed854b
MD
94/*
95 * Only float and double are supported. long double is not supported at
96 * the moment.
97 */
20f1eee7
MD
98#define _float_mant_dig(_type) \
99 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
100 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
d3ed854b 101 : 0))
20f1eee7
MD
102
103#define __type_float(_type) \
104 { \
105 .atype = atype_float, \
106 .u.basic._float = \
107 { \
108 .exp_dig = sizeof(_type) * CHAR_BIT \
109 - _float_mant_dig(_type), \
110 .mant_dig = _float_mant_dig(_type), \
1dbfff0c 111 .alignment = lttng_alignof(_type) * CHAR_BIT, \
20f1eee7
MD
112 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
113 }, \
114 } \
115
116struct lttng_float_type {
117 unsigned int exp_dig; /* exponent digits, in bits */
118 unsigned int mant_dig; /* mantissa digits, in bits */
119 unsigned short alignment; /* in bits */
120 unsigned int reverse_byte_order:1;
121};
122
8020ceb5
MD
123union _lttng_basic_type {
124 struct lttng_integer_type integer;
125 struct {
126 const char *name;
127 } enumeration;
128 struct {
129 enum lttng_string_encodings encoding;
130 } string;
20f1eee7 131 struct lttng_float_type _float;
8020ceb5
MD
132};
133
134struct lttng_basic_type {
135 enum abstract_types atype;
136 union {
137 union _lttng_basic_type basic;
138 } u;
139};
140
141struct lttng_type {
142 enum abstract_types atype;
143 union {
144 union _lttng_basic_type basic;
145 struct {
146 struct lttng_basic_type elem_type;
147 unsigned int length; /* num. elems. */
148 } array;
149 struct {
150 struct lttng_basic_type length_type;
151 struct lttng_basic_type elem_type;
152 } sequence;
153 } u;
154};
155
156struct lttng_enum {
157 const char *name;
158 struct lttng_type container_type;
159 const struct lttng_enum_entry *entries;
a60d70e6 160 nsigned int len;
8020ceb5
MD
161};
162
163/* Event field description */
164
165struct lttng_event_field {
166 const char *name;
167 struct lttng_type type;
168};
169
170struct lttng_ctx_field {
171 struct lttng_event_field event_field;
172 size_t (*get_size)(size_t offset);
173 void (*record)(struct lttng_ctx_field *field,
4cfec15c 174 struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5
MD
175 struct ltt_channel *chan);
176 union {
8020ceb5
MD
177 } u;
178 void (*destroy)(struct lttng_ctx_field *field);
179};
180
181struct lttng_ctx {
182 struct lttng_ctx_field *fields;
183 unsigned int nr_fields;
184 unsigned int allocated_fields;
185};
186
187struct lttng_event_desc {
188 const char *name;
189 void *probe_callback;
190 const struct lttng_event_ctx *ctx; /* context */
191 const struct lttng_event_field *fields; /* event payload */
192 unsigned int nr_fields;
8020ceb5
MD
193};
194
195struct lttng_probe_desc {
196 const struct lttng_event_desc *event_desc;
197 unsigned int nr_events;
9f3fdbc6 198 struct cds_list_head head; /* chain registered probes */
8020ceb5
MD
199};
200
8165c8da
MD
201struct ust_pending_probe;
202
8020ceb5
MD
203/*
204 * ltt_event structure is referred to by the tracing fast path. It must be
205 * kept small.
206 */
207struct ltt_event {
208 unsigned int id;
209 struct ltt_channel *chan;
976fe9ea 210 int enabled;
8020ceb5
MD
211 const struct lttng_event_desc *desc;
212 void *filter;
213 struct lttng_ctx *ctx;
9f3fdbc6 214 enum lttng_ust_instrumentation instrumentation;
8020ceb5 215 union {
8020ceb5 216 } u;
9f3fdbc6 217 struct cds_list_head list; /* Event list */
8165c8da 218 struct ust_pending_probe *pending_probe;
8020ceb5
MD
219 int metadata_dumped:1;
220};
221
8d8a24c8 222struct channel;
38fae1d3 223struct lttng_ust_shm_handle;
8d8a24c8 224
8020ceb5 225struct ltt_channel_ops {
1d498196 226 struct ltt_channel *(*channel_create)(const char *name,
8020ceb5
MD
227 void *buf_addr,
228 size_t subbuf_size, size_t num_subbuf,
229 unsigned int switch_timer_interval,
193183fb
MD
230 unsigned int read_timer_interval,
231 int *shm_fd, int *wait_fd,
d028eddb
MD
232 uint64_t *memory_map_size,
233 struct ltt_channel *chan_priv_init);
1d498196 234 void (*channel_destroy)(struct ltt_channel *ltt_chan);
4cfec15c 235 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
38fae1d3 236 struct lttng_ust_shm_handle *handle,
381c0f1e
MD
237 int *shm_fd, int *wait_fd,
238 uint64_t *memory_map_size);
4cfec15c 239 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
38fae1d3 240 struct lttng_ust_shm_handle *handle);
4cfec15c 241 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5 242 uint32_t event_id);
4cfec15c
MD
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,
8020ceb5
MD
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 */
1d498196 251 size_t (*packet_avail_size)(struct channel *chan,
38fae1d3 252 struct lttng_ust_shm_handle *handle);
9f3fdbc6
MD
253 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
254 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
8020ceb5
MD
255 int (*is_finalized)(struct channel *chan);
256 int (*is_disabled)(struct channel *chan);
38fae1d3 257 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
8020ceb5
MD
258};
259
260struct ltt_channel {
a3f61e7f
MD
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 */
8020ceb5 267 struct channel *chan; /* Channel buffers */
976fe9ea 268 int enabled;
8020ceb5
MD
269 struct lttng_ctx *ctx;
270 /* Event ID management */
271 struct ltt_session *session;
0a42beb6 272 int objd; /* Object associated to channel */
8020ceb5 273 unsigned int free_event_id; /* Next event ID to allocate */
8165c8da 274 unsigned int used_event_id; /* Max allocated event IDs */
9f3fdbc6 275 struct cds_list_head list; /* Channel list */
8020ceb5
MD
276 struct ltt_channel_ops *ops;
277 int header_type; /* 0: unset, 1: compact, 2: large */
38fae1d3 278 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
8020ceb5 279 int metadata_dumped:1;
a3f61e7f
MD
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 */
8020ceb5
MD
285};
286
287struct ltt_session {
288 int active; /* Is trace session active ? */
289 int been_active; /* Has trace session been active ? */
0a42beb6 290 int objd; /* Object associated to session */
8020ceb5 291 struct ltt_channel *metadata; /* Metadata channel */
9f3fdbc6
MD
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 */
8020ceb5 295 unsigned int free_chan_id; /* Next chan ID to allocate */
9f3fdbc6 296 uuid_t uuid; /* Trace session unique ID */
8020ceb5
MD
297 int metadata_dumped:1;
298};
299
300struct ltt_transport {
301 char *name;
9f3fdbc6 302 struct cds_list_head node;
8020ceb5
MD
303 struct ltt_channel_ops ops;
304};
305
51489cad
MD
306struct ltt_tracepoint_list {
307 struct tracepoint_iter iter;
308 int got_first;
309};
310
8020ceb5 311struct ltt_session *ltt_session_create(void);
976fe9ea
MD
312int ltt_session_enable(struct ltt_session *session);
313int ltt_session_disable(struct ltt_session *session);
8020ceb5
MD
314void ltt_session_destroy(struct ltt_session *session);
315
316struct ltt_channel *ltt_channel_create(struct ltt_session *session,
317 const char *transport_name,
318 void *buf_addr,
319 size_t subbuf_size, size_t num_subbuf,
320 unsigned int switch_timer_interval,
193183fb
MD
321 unsigned int read_timer_interval,
322 int *shm_fd, int *wait_fd,
d028eddb
MD
323 uint64_t *memory_map_size,
324 struct ltt_channel *chan_priv_init);
8020ceb5
MD
325struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
326 int overwrite, void *buf_addr,
327 size_t subbuf_size, size_t num_subbuf,
328 unsigned int switch_timer_interval,
193183fb
MD
329 unsigned int read_timer_interval,
330 int *shm_fd, int *wait_fd,
331 uint64_t *memory_map_size);
8020ceb5
MD
332
333struct ltt_event *ltt_event_create(struct ltt_channel *chan,
9f3fdbc6 334 struct lttng_ust_event *event_param,
8020ceb5
MD
335 void *filter);
336
976fe9ea
MD
337int ltt_channel_enable(struct ltt_channel *channel);
338int ltt_channel_disable(struct ltt_channel *channel);
339int ltt_event_enable(struct ltt_event *event);
340int ltt_event_disable(struct ltt_event *event);
341
8020ceb5
MD
342void ltt_transport_register(struct ltt_transport *transport);
343void ltt_transport_unregister(struct ltt_transport *transport);
344
4b4de73e 345void synchronize_trace(void);
8020ceb5
MD
346
347int ltt_probe_register(struct lttng_probe_desc *desc);
348void ltt_probe_unregister(struct lttng_probe_desc *desc);
8165c8da 349int pending_probe_fix_events(const struct lttng_event_desc *desc);
8020ceb5
MD
350const struct lttng_event_desc *ltt_event_get(const char *name);
351void ltt_event_put(const struct lttng_event_desc *desc);
352int ltt_probes_init(void);
353void ltt_probes_exit(void);
8173ec7c
MD
354int lttng_find_context(struct lttng_ctx *ctx, const char *name);
355struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
356void lttng_remove_context_field(struct lttng_ctx **ctx_p,
8020ceb5
MD
357 struct lttng_ctx_field *field);
358void lttng_destroy_context(struct lttng_ctx *ctx);
3b402b40 359int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
c1ef86f0 360int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
8173ec7c 361int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
4847e9bb 362int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
a93bfc45 363void lttng_context_vtid_reset(void);
c1ef86f0 364void lttng_context_vpid_reset(void);
9f3fdbc6 365
7a784989
MD
366const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
367const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
368const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
c1fca457 369
c1fca457
MD
370struct ltt_transport *ltt_transport_find(const char *name);
371
51489cad 372#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.042355 seconds and 4 git commands to generate.