Include lttng/tracepoint-types.h from tracepoint.h
[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>
8020ceb5 28
8020ceb5
MD
29struct ltt_channel;
30struct ltt_session;
4cfec15c 31struct lttng_ust_lib_ring_buffer_ctx;
8020ceb5 32
c1fca457
MD
33/*
34 * LTTng client type enumeration. Used by the consumer to map the
35 * callbacks from its own address space.
36 */
37enum 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
8020ceb5
MD
44/* Type description */
45
46/* Update the astract_types name table in lttng-types.c along with this enum */
47enum abstract_types {
48 atype_integer,
49 atype_enum,
50 atype_array,
51 atype_sequence,
52 atype_string,
20f1eee7 53 atype_float,
8020ceb5
MD
54 NR_ABSTRACT_TYPES,
55};
56
57/* Update the string_encodings name table in lttng-types.c along with this enum */
58enum lttng_string_encodings {
59 lttng_encode_none = 0,
60 lttng_encode_UTF8 = 1,
61 lttng_encode_ASCII = 2,
62 NR_STRING_ENCODINGS,
63};
64
65struct 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, \
1dbfff0c
MD
76 .alignment = lttng_alignof(_type) * CHAR_BIT, \
77 .signedness = lttng_is_signed_type(_type), \
8020ceb5
MD
78 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
79 .base = _base, \
80 .encoding = lttng_encode_##_encoding, \
81 }, \
82 } \
83
84struct 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
d3ed854b
MD
93/*
94 * Only float and double are supported. long double is not supported at
95 * the moment.
96 */
20f1eee7
MD
97#define _float_mant_dig(_type) \
98 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
99 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
d3ed854b 100 : 0))
20f1eee7
MD
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), \
1dbfff0c 110 .alignment = lttng_alignof(_type) * CHAR_BIT, \
20f1eee7
MD
111 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
112 }, \
113 } \
114
115struct 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
8020ceb5
MD
122union _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;
20f1eee7 130 struct lttng_float_type _float;
8020ceb5
MD
131};
132
133struct lttng_basic_type {
134 enum abstract_types atype;
135 union {
136 union _lttng_basic_type basic;
137 } u;
138};
139
140struct 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
155struct lttng_enum {
156 const char *name;
157 struct lttng_type container_type;
158 const struct lttng_enum_entry *entries;
23c8854a 159 unsigned int len;
8020ceb5
MD
160};
161
162/* Event field description */
163
164struct lttng_event_field {
165 const char *name;
166 struct lttng_type type;
167};
168
169struct 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,
4cfec15c 173 struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5
MD
174 struct ltt_channel *chan);
175 union {
8020ceb5
MD
176 } u;
177 void (*destroy)(struct lttng_ctx_field *field);
178};
179
180struct lttng_ctx {
181 struct lttng_ctx_field *fields;
182 unsigned int nr_fields;
183 unsigned int allocated_fields;
184};
185
df854e41
MD
186struct tracepoint_loglevel_entry {
187 const char *identifier;
188 long value;
189};
190
8020ceb5
MD
191struct lttng_event_desc {
192 const char *name;
193 void *probe_callback;
194 const struct lttng_event_ctx *ctx; /* context */
195 const struct lttng_event_field *fields; /* event payload */
196 unsigned int nr_fields;
df854e41 197 const struct tracepoint_loglevel_entry **loglevel;
8020ceb5
MD
198};
199
200struct lttng_probe_desc {
df854e41
MD
201 const char *provider;
202 const struct lttng_event_desc **event_desc;
8020ceb5 203 unsigned int nr_events;
df854e41
MD
204 const struct tracepoint_loglevel_entry **loglevels;
205 unsigned int nr_loglevels;
9f3fdbc6 206 struct cds_list_head head; /* chain registered probes */
df854e41
MD
207};
208
c8fcf224
MD
209struct tp_list_entry {
210 struct lttng_ust_tracepoint_iter tp;
211 struct cds_list_head head;
212};
213
214struct lttng_ust_tracepoint_list {
215 struct tp_list_entry *iter;
216 struct cds_list_head head;
8020ceb5
MD
217};
218
8165c8da
MD
219struct ust_pending_probe;
220
8020ceb5
MD
221/*
222 * ltt_event structure is referred to by the tracing fast path. It must be
223 * kept small.
224 */
225struct ltt_event {
226 unsigned int id;
227 struct ltt_channel *chan;
976fe9ea 228 int enabled;
8020ceb5
MD
229 const struct lttng_event_desc *desc;
230 void *filter;
231 struct lttng_ctx *ctx;
9f3fdbc6 232 enum lttng_ust_instrumentation instrumentation;
8020ceb5 233 union {
8020ceb5 234 } u;
9f3fdbc6 235 struct cds_list_head list; /* Event list */
8165c8da 236 struct ust_pending_probe *pending_probe;
7c2caf2b 237 unsigned int metadata_dumped:1;
8020ceb5
MD
238};
239
8d8a24c8 240struct channel;
38fae1d3 241struct lttng_ust_shm_handle;
8d8a24c8 242
8020ceb5 243struct ltt_channel_ops {
1d498196 244 struct ltt_channel *(*channel_create)(const char *name,
8020ceb5
MD
245 void *buf_addr,
246 size_t subbuf_size, size_t num_subbuf,
247 unsigned int switch_timer_interval,
193183fb
MD
248 unsigned int read_timer_interval,
249 int *shm_fd, int *wait_fd,
d028eddb
MD
250 uint64_t *memory_map_size,
251 struct ltt_channel *chan_priv_init);
1d498196 252 void (*channel_destroy)(struct ltt_channel *ltt_chan);
4cfec15c 253 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
38fae1d3 254 struct lttng_ust_shm_handle *handle,
381c0f1e
MD
255 int *shm_fd, int *wait_fd,
256 uint64_t *memory_map_size);
4cfec15c 257 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
38fae1d3 258 struct lttng_ust_shm_handle *handle);
4cfec15c 259 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5 260 uint32_t event_id);
4cfec15c
MD
261 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
262 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
8020ceb5
MD
263 size_t len);
264 /*
265 * packet_avail_size returns the available size in the current
266 * packet. Note that the size returned is only a hint, since it
267 * may change due to concurrent writes.
268 */
1d498196 269 size_t (*packet_avail_size)(struct channel *chan,
38fae1d3 270 struct lttng_ust_shm_handle *handle);
9f3fdbc6
MD
271 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
272 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
8020ceb5
MD
273 int (*is_finalized)(struct channel *chan);
274 int (*is_disabled)(struct channel *chan);
38fae1d3 275 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
8020ceb5
MD
276};
277
278struct ltt_channel {
a3f61e7f
MD
279 /*
280 * The pointers located in this private data are NOT safe to be
281 * dereferenced by the consumer. The only operations the
282 * consumer process is designed to be allowed to do is to read
283 * and perform subbuffer flush.
284 */
8020ceb5 285 struct channel *chan; /* Channel buffers */
976fe9ea 286 int enabled;
8020ceb5
MD
287 struct lttng_ctx *ctx;
288 /* Event ID management */
289 struct ltt_session *session;
0a42beb6 290 int objd; /* Object associated to channel */
8020ceb5 291 unsigned int free_event_id; /* Next event ID to allocate */
8165c8da 292 unsigned int used_event_id; /* Max allocated event IDs */
9f3fdbc6 293 struct cds_list_head list; /* Channel list */
8020ceb5
MD
294 struct ltt_channel_ops *ops;
295 int header_type; /* 0: unset, 1: compact, 2: large */
38fae1d3 296 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
7c2caf2b 297 unsigned int metadata_dumped:1;
a3f61e7f
MD
298
299 /* Channel ID, available for consumer too */
300 unsigned int id;
301 /* Copy of session UUID for consumer (availability through shm) */
302 uuid_t uuid; /* Trace session unique ID */
8020ceb5
MD
303};
304
305struct ltt_session {
306 int active; /* Is trace session active ? */
307 int been_active; /* Has trace session been active ? */
0a42beb6 308 int objd; /* Object associated to session */
8020ceb5 309 struct ltt_channel *metadata; /* Metadata channel */
9f3fdbc6
MD
310 struct cds_list_head chan; /* Channel list head */
311 struct cds_list_head events; /* Event list head */
312 struct cds_list_head list; /* Session list */
8020ceb5 313 unsigned int free_chan_id; /* Next chan ID to allocate */
9f3fdbc6 314 uuid_t uuid; /* Trace session unique ID */
7c2caf2b 315 unsigned int metadata_dumped:1;
8020ceb5
MD
316};
317
318struct ltt_transport {
319 char *name;
9f3fdbc6 320 struct cds_list_head node;
8020ceb5
MD
321 struct ltt_channel_ops ops;
322};
323
324struct ltt_session *ltt_session_create(void);
976fe9ea
MD
325int ltt_session_enable(struct ltt_session *session);
326int ltt_session_disable(struct ltt_session *session);
8020ceb5
MD
327void ltt_session_destroy(struct ltt_session *session);
328
329struct ltt_channel *ltt_channel_create(struct ltt_session *session,
330 const char *transport_name,
331 void *buf_addr,
332 size_t subbuf_size, size_t num_subbuf,
333 unsigned int switch_timer_interval,
193183fb
MD
334 unsigned int read_timer_interval,
335 int *shm_fd, int *wait_fd,
d028eddb
MD
336 uint64_t *memory_map_size,
337 struct ltt_channel *chan_priv_init);
8020ceb5
MD
338struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
339 int overwrite, void *buf_addr,
340 size_t subbuf_size, size_t num_subbuf,
341 unsigned int switch_timer_interval,
193183fb
MD
342 unsigned int read_timer_interval,
343 int *shm_fd, int *wait_fd,
344 uint64_t *memory_map_size);
8020ceb5 345
576599a0
MD
346int ltt_event_create(struct ltt_channel *chan,
347 struct lttng_ust_event *event_param,
348 void *filter,
349 struct ltt_event **event);
8020ceb5 350
976fe9ea
MD
351int ltt_channel_enable(struct ltt_channel *channel);
352int ltt_channel_disable(struct ltt_channel *channel);
353int ltt_event_enable(struct ltt_event *event);
354int ltt_event_disable(struct ltt_event *event);
355
8020ceb5
MD
356void ltt_transport_register(struct ltt_transport *transport);
357void ltt_transport_unregister(struct ltt_transport *transport);
358
4b4de73e 359void synchronize_trace(void);
8020ceb5
MD
360
361int ltt_probe_register(struct lttng_probe_desc *desc);
362void ltt_probe_unregister(struct lttng_probe_desc *desc);
8165c8da 363int pending_probe_fix_events(const struct lttng_event_desc *desc);
8020ceb5
MD
364const struct lttng_event_desc *ltt_event_get(const char *name);
365void ltt_event_put(const struct lttng_event_desc *desc);
366int ltt_probes_init(void);
367void ltt_probes_exit(void);
8173ec7c
MD
368int lttng_find_context(struct lttng_ctx *ctx, const char *name);
369struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
370void lttng_remove_context_field(struct lttng_ctx **ctx_p,
8020ceb5
MD
371 struct lttng_ctx_field *field);
372void lttng_destroy_context(struct lttng_ctx *ctx);
3b402b40 373int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
c1ef86f0 374int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
8173ec7c 375int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
4847e9bb 376int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
a93bfc45 377void lttng_context_vtid_reset(void);
c1ef86f0 378void lttng_context_vpid_reset(void);
9f3fdbc6 379
7a784989
MD
380const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
381const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
382const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
c1fca457 383
c1fca457
MD
384struct ltt_transport *ltt_transport_find(const char *name);
385
c8fcf224
MD
386int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
387void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
388struct lttng_ust_tracepoint_iter *
389 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
390
51489cad 391#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.043078 seconds and 4 git commands to generate.