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