Remove useless else clause
[lttng-ust.git] / include / lttng / ust-events.h
... / ...
CommitLineData
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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30#include <urcu/list.h>
31#include <urcu/hlist.h>
32#include <stdint.h>
33#include <lttng/ust-abi.h>
34#include <lttng/ust-tracer.h>
35#include <lttng/ust-endian.h>
36#include <float.h>
37
38#define LTTNG_UST_UUID_LEN 16
39
40struct lttng_channel;
41struct lttng_session;
42struct lttng_ust_lib_ring_buffer_ctx;
43
44/*
45 * Data structures used by tracepoint event declarations, and by the
46 * tracer. Those structures have padding for future extension.
47 */
48
49/*
50 * LTTng client type enumeration. Used by the consumer to map the
51 * callbacks from its own address space.
52 */
53enum lttng_client_types {
54 LTTNG_CLIENT_METADATA = 0,
55 LTTNG_CLIENT_DISCARD = 1,
56 LTTNG_CLIENT_OVERWRITE = 2,
57 LTTNG_CLIENT_DISCARD_RT = 3,
58 LTTNG_CLIENT_OVERWRITE_RT = 4,
59 LTTNG_NR_CLIENT_TYPES,
60};
61
62/* Type description */
63
64/* Update the astract_types name table in lttng-types.c along with this enum */
65enum lttng_abstract_types {
66 atype_integer,
67 atype_enum,
68 atype_array,
69 atype_sequence,
70 atype_string,
71 atype_float,
72 NR_ABSTRACT_TYPES,
73};
74
75/* Update the string_encodings name table in lttng-types.c along with this enum */
76enum lttng_string_encodings {
77 lttng_encode_none = 0,
78 lttng_encode_UTF8 = 1,
79 lttng_encode_ASCII = 2,
80 NR_STRING_ENCODINGS,
81};
82
83#define LTTNG_UST_ENUM_ENTRY_PADDING 16
84struct lttng_enum_entry {
85 unsigned long long start, end; /* start and end are inclusive */
86 const char *string;
87 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
88};
89
90#define __type_integer(_type, _byte_order, _base, _encoding) \
91 { \
92 .atype = atype_integer, \
93 .u.basic.integer = \
94 { \
95 .size = sizeof(_type) * CHAR_BIT, \
96 .alignment = lttng_alignof(_type) * CHAR_BIT, \
97 .signedness = lttng_is_signed_type(_type), \
98 .reverse_byte_order = _byte_order != BYTE_ORDER, \
99 .base = _base, \
100 .encoding = lttng_encode_##_encoding, \
101 }, \
102 } \
103
104#define LTTNG_UST_INTEGER_TYPE_PADDING 24
105struct lttng_integer_type {
106 unsigned int size; /* in bits */
107 unsigned short alignment; /* in bits */
108 unsigned int signedness:1;
109 unsigned int reverse_byte_order:1;
110 unsigned int base; /* 2, 8, 10, 16, for pretty print */
111 enum lttng_string_encodings encoding;
112 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
113};
114
115/*
116 * Only float and double are supported. long double is not supported at
117 * the moment.
118 */
119#define _float_mant_dig(_type) \
120 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
121 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
122 : 0))
123
124#define __type_float(_type) \
125 { \
126 .atype = atype_float, \
127 .u.basic._float = \
128 { \
129 .exp_dig = sizeof(_type) * CHAR_BIT \
130 - _float_mant_dig(_type), \
131 .mant_dig = _float_mant_dig(_type), \
132 .alignment = lttng_alignof(_type) * CHAR_BIT, \
133 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
134 }, \
135 } \
136
137#define LTTNG_UST_FLOAT_TYPE_PADDING 24
138struct lttng_float_type {
139 unsigned int exp_dig; /* exponent digits, in bits */
140 unsigned int mant_dig; /* mantissa digits, in bits */
141 unsigned short alignment; /* in bits */
142 unsigned int reverse_byte_order:1;
143 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
144};
145
146#define LTTNG_UST_BASIC_TYPE_PADDING 128
147union _lttng_basic_type {
148 struct lttng_integer_type integer;
149 struct {
150 const char *name;
151 } enumeration;
152 struct {
153 enum lttng_string_encodings encoding;
154 } string;
155 struct lttng_float_type _float;
156 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
157};
158
159struct lttng_basic_type {
160 enum lttng_abstract_types atype;
161 union {
162 union _lttng_basic_type basic;
163 } u;
164};
165
166#define LTTNG_UST_TYPE_PADDING 128
167struct lttng_type {
168 enum lttng_abstract_types atype;
169 union {
170 union _lttng_basic_type basic;
171 struct {
172 struct lttng_basic_type elem_type;
173 unsigned int length; /* num. elems. */
174 } array;
175 struct {
176 struct lttng_basic_type length_type;
177 struct lttng_basic_type elem_type;
178 } sequence;
179 char padding[LTTNG_UST_TYPE_PADDING];
180 } u;
181};
182
183#define LTTNG_UST_ENUM_TYPE_PADDING 24
184struct lttng_enum {
185 const char *name;
186 struct lttng_type container_type;
187 const struct lttng_enum_entry *entries;
188 unsigned int len;
189 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
190};
191
192/*
193 * Event field description
194 *
195 * IMPORTANT: this structure is part of the ABI between the probe and
196 * UST. Fields need to be only added at the end, never reordered, never
197 * removed.
198 */
199
200#define LTTNG_UST_EVENT_FIELD_PADDING 28
201struct lttng_event_field {
202 const char *name;
203 struct lttng_type type;
204 unsigned int nowrite; /* do not write into trace */
205 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
206};
207
208#define LTTNG_UST_CTX_FIELD_PADDING 40
209struct lttng_ctx_field {
210 struct lttng_event_field event_field;
211 size_t (*get_size)(size_t offset);
212 void (*record)(struct lttng_ctx_field *field,
213 struct lttng_ust_lib_ring_buffer_ctx *ctx,
214 struct lttng_channel *chan);
215 union {
216 char padding[LTTNG_UST_CTX_FIELD_PADDING];
217 } u;
218 void (*destroy)(struct lttng_ctx_field *field);
219};
220
221#define LTTNG_UST_CTX_PADDING 24
222struct lttng_ctx {
223 struct lttng_ctx_field *fields;
224 unsigned int nr_fields;
225 unsigned int allocated_fields;
226 char padding[LTTNG_UST_CTX_PADDING];
227};
228
229#define LTTNG_UST_EVENT_DESC_PADDING 40
230struct lttng_event_desc {
231 const char *name;
232 void (*probe_callback)(void);
233 const struct lttng_event_ctx *ctx; /* context */
234 const struct lttng_event_field *fields; /* event payload */
235 unsigned int nr_fields;
236 const int **loglevel;
237 const char *signature; /* Argument types/names received */
238 union {
239 struct {
240 const char **model_emf_uri;
241 } ext;
242 char padding[LTTNG_UST_EVENT_DESC_PADDING];
243 } u;
244};
245
246#define LTTNG_UST_PROBE_DESC_PADDING 20
247struct lttng_probe_desc {
248 const char *provider;
249 const struct lttng_event_desc **event_desc;
250 unsigned int nr_events;
251 struct cds_list_head head; /* chain registered probes */
252 struct cds_list_head lazy_init_head;
253 int lazy; /* lazy registration */
254 char padding[LTTNG_UST_PROBE_DESC_PADDING];
255};
256
257/* Data structures used by the tracer. */
258
259enum lttng_enabler_type {
260 LTTNG_ENABLER_WILDCARD,
261 LTTNG_ENABLER_EVENT,
262};
263
264/*
265 * Enabler field, within whatever object is enabling an event. Target of
266 * backward reference.
267 */
268struct lttng_enabler {
269 enum lttng_enabler_type type;
270
271 /* head list of struct lttng_ust_filter_bytecode_node */
272 struct cds_list_head filter_bytecode_head;
273 struct cds_list_head node; /* per-session list of enablers */
274
275 struct lttng_ust_event event_param;
276 struct lttng_channel *chan;
277 struct lttng_ctx *ctx;
278 unsigned int enabled:1;
279};
280
281struct tp_list_entry {
282 struct lttng_ust_tracepoint_iter tp;
283 struct cds_list_head head;
284};
285
286struct lttng_ust_tracepoint_list {
287 struct tp_list_entry *iter;
288 struct cds_list_head head;
289};
290
291struct tp_field_list_entry {
292 struct lttng_ust_field_iter field;
293 struct cds_list_head head;
294};
295
296struct lttng_ust_field_list {
297 struct tp_field_list_entry *iter;
298 struct cds_list_head head;
299};
300
301struct ust_pending_probe;
302struct lttng_event;
303
304struct lttng_ust_filter_bytecode_node {
305 struct cds_list_head node;
306 struct lttng_enabler *enabler;
307 /*
308 * struct lttng_ust_filter_bytecode has var. sized array, must
309 * be last field.
310 */
311 struct lttng_ust_filter_bytecode bc;
312};
313
314/*
315 * Filter return value masks.
316 */
317enum lttng_filter_ret {
318 LTTNG_FILTER_DISCARD = 0,
319 LTTNG_FILTER_RECORD_FLAG = (1ULL << 0),
320 /* Other bits are kept for future use. */
321};
322
323struct lttng_bytecode_runtime {
324 /* Associated bytecode */
325 struct lttng_ust_filter_bytecode_node *bc;
326 uint64_t (*filter)(void *filter_data, const char *filter_stack_data);
327 int link_failed;
328 struct cds_list_head node; /* list of bytecode runtime in event */
329};
330
331/*
332 * Objects in a linked-list of enablers, owned by an event.
333 */
334struct lttng_enabler_ref {
335 struct cds_list_head node; /* enabler ref list */
336 struct lttng_enabler *ref; /* backward ref */
337};
338
339/*
340 * lttng_event structure is referred to by the tracing fast path. It
341 * must be kept small.
342 *
343 * IMPORTANT: this structure is part of the ABI between the probe and
344 * UST. Fields need to be only added at the end, never reordered, never
345 * removed.
346 */
347struct lttng_event {
348 /* LTTng-UST 2.0 starts here */
349 unsigned int id;
350 struct lttng_channel *chan;
351 int enabled;
352 const struct lttng_event_desc *desc;
353 void *_deprecated1;
354 struct lttng_ctx *ctx;
355 enum lttng_ust_instrumentation instrumentation;
356 union {
357 } u;
358 struct cds_list_head node; /* Event list in session */
359 struct cds_list_head _deprecated2;
360 void *_deprecated3;
361 unsigned int _deprecated4:1;
362
363 /* LTTng-UST 2.1 starts here */
364 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
365 struct cds_list_head bytecode_runtime_head;
366 int has_enablers_without_bytecode;
367 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
368 struct cds_list_head enablers_ref_head;
369 struct cds_hlist_node hlist; /* session ht of events */
370 int registered; /* has reg'd tracepoint probe */
371};
372
373struct channel;
374struct lttng_ust_shm_handle;
375
376/*
377 * IMPORTANT: this structure is part of the ABI between the probe and
378 * UST. Fields need to be only added at the end, never reordered, never
379 * removed.
380 */
381struct lttng_channel_ops {
382 struct lttng_channel *(*channel_create)(const char *name,
383 void *buf_addr,
384 size_t subbuf_size, size_t num_subbuf,
385 unsigned int switch_timer_interval,
386 unsigned int read_timer_interval,
387 unsigned char *uuid);
388 void (*channel_destroy)(struct lttng_channel *chan);
389 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
390 uint32_t event_id);
391 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
392 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
393 const void *src, size_t len);
394 /*
395 * packet_avail_size returns the available size in the current
396 * packet. Note that the size returned is only a hint, since it
397 * may change due to concurrent writes.
398 */
399 size_t (*packet_avail_size)(struct channel *chan,
400 struct lttng_ust_shm_handle *handle);
401 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
402 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
403 int (*is_finalized)(struct channel *chan);
404 int (*is_disabled)(struct channel *chan);
405 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
406};
407
408/*
409 * IMPORTANT: this structure is part of the ABI between the probe and
410 * UST. Fields need to be only added at the end, never reordered, never
411 * removed.
412 */
413struct lttng_channel {
414 /*
415 * The pointers located in this private data are NOT safe to be
416 * dereferenced by the consumer. The only operations the
417 * consumer process is designed to be allowed to do is to read
418 * and perform subbuffer flush.
419 */
420 struct channel *chan; /* Channel buffers */
421 int enabled;
422 struct lttng_ctx *ctx;
423 /* Event ID management */
424 struct lttng_session *session;
425 int objd; /* Object associated to channel */
426 unsigned int _deprecated1;
427 unsigned int _deprecated2;
428 struct cds_list_head node; /* Channel list in session */
429 const struct lttng_channel_ops *ops;
430 int header_type; /* 0: unset, 1: compact, 2: large */
431 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
432 unsigned int _deprecated3:1;
433
434 /* Channel ID */
435 unsigned int id;
436 enum lttng_ust_chan_type type;
437 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
438 int tstate:1; /* Transient enable state */
439};
440
441#define LTTNG_UST_EVENT_HT_BITS 12
442#define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
443
444struct lttng_ust_event_ht {
445 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
446};
447
448/*
449 * IMPORTANT: this structure is part of the ABI between the probe and
450 * UST. Fields need to be only added at the end, never reordered, never
451 * removed.
452 */
453struct lttng_session {
454 int active; /* Is trace session active ? */
455 int been_active; /* Been active ? */
456 int objd; /* Object associated */
457 void *_deprecated1;
458 struct cds_list_head chan_head; /* Channel list head */
459 struct cds_list_head events_head; /* list of events */
460 struct cds_list_head _deprecated2;
461 struct cds_list_head node; /* Session list */
462 int _deprecated3;
463 unsigned int _deprecated4:1;
464
465 /* New UST 2.1 */
466 /* List of enablers */
467 struct cds_list_head enablers_head;
468 struct lttng_ust_event_ht events_ht; /* ht of events */
469 void *owner; /* object owner */
470 int tstate:1; /* Transient enable state */
471};
472
473struct lttng_transport {
474 char *name;
475 struct cds_list_head node;
476 struct lttng_channel_ops ops;
477 const struct lttng_ust_lib_ring_buffer_config *client_config;
478};
479
480struct lttng_session *lttng_session_create(void);
481int lttng_session_enable(struct lttng_session *session);
482int lttng_session_disable(struct lttng_session *session);
483void lttng_session_destroy(struct lttng_session *session);
484
485struct lttng_channel *lttng_channel_create(struct lttng_session *session,
486 const char *transport_name,
487 void *buf_addr,
488 size_t subbuf_size, size_t num_subbuf,
489 unsigned int switch_timer_interval,
490 unsigned int read_timer_interval,
491 int **shm_fd, int **wait_fd,
492 uint64_t **memory_map_size,
493 struct lttng_channel *chan_priv_init);
494
495int lttng_channel_enable(struct lttng_channel *channel);
496int lttng_channel_disable(struct lttng_channel *channel);
497
498struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_type type,
499 struct lttng_ust_event *event_param,
500 struct lttng_channel *chan);
501int lttng_enabler_enable(struct lttng_enabler *enabler);
502int lttng_enabler_disable(struct lttng_enabler *enabler);
503int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
504 struct lttng_ust_filter_bytecode_node *bytecode);
505int lttng_enabler_attach_context(struct lttng_enabler *enabler,
506 struct lttng_ust_context *ctx);
507
508int lttng_attach_context(struct lttng_ust_context *context_param,
509 struct lttng_ctx **ctx, struct lttng_session *session);
510
511void lttng_transport_register(struct lttng_transport *transport);
512void lttng_transport_unregister(struct lttng_transport *transport);
513
514void synchronize_trace(void);
515
516int lttng_probe_register(struct lttng_probe_desc *desc);
517void lttng_probe_unregister(struct lttng_probe_desc *desc);
518int lttng_fix_pending_event_desc(const struct lttng_event_desc *desc);
519int lttng_probes_init(void);
520void lttng_probes_exit(void);
521int lttng_find_context(struct lttng_ctx *ctx, const char *name);
522struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
523void lttng_remove_context_field(struct lttng_ctx **ctx_p,
524 struct lttng_ctx_field *field);
525void lttng_destroy_context(struct lttng_ctx *ctx);
526int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
527int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
528int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
529int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
530void lttng_context_vtid_reset(void);
531void lttng_context_vpid_reset(void);
532
533extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
534extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
535extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
536
537struct lttng_transport *lttng_transport_find(const char *name);
538
539int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
540void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
541struct lttng_ust_tracepoint_iter *
542 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
543int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
544void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
545struct lttng_ust_field_iter *
546 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
547
548void lttng_filter_event_link_bytecode(struct lttng_event *event);
549void lttng_enabler_event_link_bytecode(struct lttng_event *event,
550 struct lttng_enabler *enabler);
551void lttng_free_event_filter_runtime(struct lttng_event *event);
552void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime);
553
554struct cds_list_head *lttng_get_probe_list_head(void);
555int lttng_session_active(void);
556
557#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.023473 seconds and 4 git commands to generate.