implement ring buffer clients
[lttng-ust.git] / libust / ltt-events.h
1 #ifndef _LTT_EVENTS_H
2 #define _LTT_EVENTS_H
3
4 /*
5 * ltt-events.h
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
11 * Dual LGPL v2.1/GPL v2 license.
12 */
13
14 #include <urcu/list.h>
15 #include <uuid/uuid.h>
16 #include <stdint.h>
17 #include <ust/lttng-ust-abi.h>
18
19 #undef is_signed_type
20 #define is_signed_type(type) (((type)(-1)) < 0)
21
22 struct ltt_channel;
23 struct ltt_session;
24 struct lib_ring_buffer_ctx;
25
26 /* Type description */
27
28 /* Update the astract_types name table in lttng-types.c along with this enum */
29 enum abstract_types {
30 atype_integer,
31 atype_enum,
32 atype_array,
33 atype_sequence,
34 atype_string,
35 NR_ABSTRACT_TYPES,
36 };
37
38 /* Update the string_encodings name table in lttng-types.c along with this enum */
39 enum lttng_string_encodings {
40 lttng_encode_none = 0,
41 lttng_encode_UTF8 = 1,
42 lttng_encode_ASCII = 2,
43 NR_STRING_ENCODINGS,
44 };
45
46 struct lttng_enum_entry {
47 unsigned long long start, end; /* start and end are inclusive */
48 const char *string;
49 };
50
51 #define __type_integer(_type, _byte_order, _base, _encoding) \
52 { \
53 .atype = atype_integer, \
54 .u.basic.integer = \
55 { \
56 .size = sizeof(_type) * CHAR_BIT, \
57 .alignment = ltt_alignof(_type) * CHAR_BIT, \
58 .signedness = is_signed_type(_type), \
59 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
60 .base = _base, \
61 .encoding = lttng_encode_##_encoding, \
62 }, \
63 } \
64
65 struct lttng_integer_type {
66 unsigned int size; /* in bits */
67 unsigned short alignment; /* in bits */
68 unsigned int signedness:1;
69 unsigned int reverse_byte_order:1;
70 unsigned int base; /* 2, 8, 10, 16, for pretty print */
71 enum lttng_string_encodings encoding;
72 };
73
74 union _lttng_basic_type {
75 struct lttng_integer_type integer;
76 struct {
77 const char *name;
78 } enumeration;
79 struct {
80 enum lttng_string_encodings encoding;
81 } string;
82 };
83
84 struct lttng_basic_type {
85 enum abstract_types atype;
86 union {
87 union _lttng_basic_type basic;
88 } u;
89 };
90
91 struct lttng_type {
92 enum abstract_types atype;
93 union {
94 union _lttng_basic_type basic;
95 struct {
96 struct lttng_basic_type elem_type;
97 unsigned int length; /* num. elems. */
98 } array;
99 struct {
100 struct lttng_basic_type length_type;
101 struct lttng_basic_type elem_type;
102 } sequence;
103 } u;
104 };
105
106 struct lttng_enum {
107 const char *name;
108 struct lttng_type container_type;
109 const struct lttng_enum_entry *entries;
110 unsigned int len;
111 };
112
113 /* Event field description */
114
115 struct lttng_event_field {
116 const char *name;
117 struct lttng_type type;
118 };
119
120 struct lttng_ctx_field {
121 struct lttng_event_field event_field;
122 size_t (*get_size)(size_t offset);
123 void (*record)(struct lttng_ctx_field *field,
124 struct lib_ring_buffer_ctx *ctx,
125 struct ltt_channel *chan);
126 union {
127 } u;
128 void (*destroy)(struct lttng_ctx_field *field);
129 };
130
131 struct lttng_ctx {
132 struct lttng_ctx_field *fields;
133 unsigned int nr_fields;
134 unsigned int allocated_fields;
135 };
136
137 struct lttng_event_desc {
138 const char *name;
139 void *probe_callback;
140 const struct lttng_event_ctx *ctx; /* context */
141 const struct lttng_event_field *fields; /* event payload */
142 unsigned int nr_fields;
143 };
144
145 struct lttng_probe_desc {
146 const struct lttng_event_desc *event_desc;
147 unsigned int nr_events;
148 struct cds_list_head head; /* chain registered probes */
149 };
150
151 /*
152 * ltt_event structure is referred to by the tracing fast path. It must be
153 * kept small.
154 */
155 struct ltt_event {
156 unsigned int id;
157 struct ltt_channel *chan;
158 int enabled;
159 const struct lttng_event_desc *desc;
160 void *filter;
161 struct lttng_ctx *ctx;
162 enum lttng_ust_instrumentation instrumentation;
163 union {
164 } u;
165 struct cds_list_head list; /* Event list */
166 int metadata_dumped:1;
167 };
168
169 struct ltt_channel_ops {
170 struct channel *(*channel_create)(const char *name,
171 struct ltt_channel *ltt_chan,
172 void *buf_addr,
173 size_t subbuf_size, size_t num_subbuf,
174 unsigned int switch_timer_interval,
175 unsigned int read_timer_interval,
176 int *shmid);
177 void (*channel_destroy)(struct channel *chan);
178 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
179 void (*buffer_read_close)(struct lib_ring_buffer *buf);
180 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
181 uint32_t event_id);
182 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
183 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
184 size_t len);
185 /*
186 * packet_avail_size returns the available size in the current
187 * packet. Note that the size returned is only a hint, since it
188 * may change due to concurrent writes.
189 */
190 size_t (*packet_avail_size)(struct channel *chan);
191 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
192 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
193 int (*is_finalized)(struct channel *chan);
194 int (*is_disabled)(struct channel *chan);
195 };
196
197 struct ltt_channel {
198 unsigned int id;
199 struct channel *chan; /* Channel buffers */
200 int enabled;
201 struct lttng_ctx *ctx;
202 /* Event ID management */
203 struct ltt_session *session;
204 struct file *file; /* File associated to channel */
205 unsigned int free_event_id; /* Next event ID to allocate */
206 struct cds_list_head list; /* Channel list */
207 struct ltt_channel_ops *ops;
208 int header_type; /* 0: unset, 1: compact, 2: large */
209 int metadata_dumped:1;
210 };
211
212 struct ltt_session {
213 int active; /* Is trace session active ? */
214 int been_active; /* Has trace session been active ? */
215 struct file *file; /* File associated to session */
216 struct ltt_channel *metadata; /* Metadata channel */
217 struct cds_list_head chan; /* Channel list head */
218 struct cds_list_head events; /* Event list head */
219 struct cds_list_head list; /* Session list */
220 unsigned int free_chan_id; /* Next chan ID to allocate */
221 uuid_t uuid; /* Trace session unique ID */
222 int metadata_dumped:1;
223 };
224
225 struct ltt_transport {
226 char *name;
227 struct cds_list_head node;
228 struct ltt_channel_ops ops;
229 };
230
231 struct ltt_session *ltt_session_create(void);
232 int ltt_session_enable(struct ltt_session *session);
233 int ltt_session_disable(struct ltt_session *session);
234 void ltt_session_destroy(struct ltt_session *session);
235
236 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
237 const char *transport_name,
238 void *buf_addr,
239 size_t subbuf_size, size_t num_subbuf,
240 unsigned int switch_timer_interval,
241 unsigned int read_timer_interval);
242 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
243 int overwrite, void *buf_addr,
244 size_t subbuf_size, size_t num_subbuf,
245 unsigned int switch_timer_interval,
246 unsigned int read_timer_interval);
247
248 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
249 struct lttng_ust_event *event_param,
250 void *filter);
251
252 int ltt_channel_enable(struct ltt_channel *channel);
253 int ltt_channel_disable(struct ltt_channel *channel);
254 int ltt_event_enable(struct ltt_event *event);
255 int ltt_event_disable(struct ltt_event *event);
256
257 void ltt_transport_register(struct ltt_transport *transport);
258 void ltt_transport_unregister(struct ltt_transport *transport);
259
260 void synchronize_trace(void);
261 //int ltt_debugfs_abi_init(void);
262 //void ltt_debugfs_abi_exit(void);
263
264 int ltt_probe_register(struct lttng_probe_desc *desc);
265 void ltt_probe_unregister(struct lttng_probe_desc *desc);
266 const struct lttng_event_desc *ltt_event_get(const char *name);
267 void ltt_event_put(const struct lttng_event_desc *desc);
268 int ltt_probes_init(void);
269 void ltt_probes_exit(void);
270 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
271 void lttng_remove_context_field(struct lttng_ctx **ctx,
272 struct lttng_ctx_field *field);
273 void lttng_destroy_context(struct lttng_ctx *ctx);
274 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
275
276 //extern const struct file_operations lttng_tracepoint_list_fops;
277
278 #endif /* _LTT_EVENTS_H */
This page took 0.045913 seconds and 4 git commands to generate.