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