Commit | Line | Data |
---|---|---|
0a42beb6 MD |
1 | #ifndef _UST_LTTNG_EVENTS_H |
2 | #define _UST_LTTNG_EVENTS_H | |
8020ceb5 MD |
3 | |
4 | /* | |
0a42beb6 | 5 | * ust/lttng-events.h |
8020ceb5 MD |
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 | ||
9f3fdbc6 MD |
14 | #include <urcu/list.h> |
15 | #include <uuid/uuid.h> | |
16 | #include <stdint.h> | |
17 | #include <ust/lttng-ust-abi.h> | |
8020ceb5 MD |
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; | |
8020ceb5 MD |
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 { | |
8020ceb5 MD |
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; | |
8020ceb5 MD |
143 | }; |
144 | ||
145 | struct lttng_probe_desc { | |
146 | const struct lttng_event_desc *event_desc; | |
147 | unsigned int nr_events; | |
9f3fdbc6 | 148 | struct cds_list_head head; /* chain registered probes */ |
8020ceb5 MD |
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; | |
976fe9ea | 158 | int enabled; |
8020ceb5 MD |
159 | const struct lttng_event_desc *desc; |
160 | void *filter; | |
161 | struct lttng_ctx *ctx; | |
9f3fdbc6 | 162 | enum lttng_ust_instrumentation instrumentation; |
8020ceb5 | 163 | union { |
8020ceb5 | 164 | } u; |
9f3fdbc6 | 165 | struct cds_list_head list; /* Event list */ |
8020ceb5 MD |
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, | |
9f3fdbc6 MD |
175 | unsigned int read_timer_interval, |
176 | int *shmid); | |
8020ceb5 MD |
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); | |
9f3fdbc6 MD |
191 | //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan); |
192 | //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); | |
8020ceb5 MD |
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 */ | |
976fe9ea | 200 | int enabled; |
8020ceb5 MD |
201 | struct lttng_ctx *ctx; |
202 | /* Event ID management */ | |
203 | struct ltt_session *session; | |
0a42beb6 | 204 | int objd; /* Object associated to channel */ |
8020ceb5 | 205 | unsigned int free_event_id; /* Next event ID to allocate */ |
9f3fdbc6 | 206 | struct cds_list_head list; /* Channel list */ |
8020ceb5 MD |
207 | struct ltt_channel_ops *ops; |
208 | int header_type; /* 0: unset, 1: compact, 2: large */ | |
0a42beb6 | 209 | int shmid; /* shared memory ID */ |
8020ceb5 MD |
210 | int metadata_dumped:1; |
211 | }; | |
212 | ||
213 | struct ltt_session { | |
214 | int active; /* Is trace session active ? */ | |
215 | int been_active; /* Has trace session been active ? */ | |
0a42beb6 | 216 | int objd; /* Object associated to session */ |
8020ceb5 | 217 | struct ltt_channel *metadata; /* Metadata channel */ |
9f3fdbc6 MD |
218 | struct cds_list_head chan; /* Channel list head */ |
219 | struct cds_list_head events; /* Event list head */ | |
220 | struct cds_list_head list; /* Session list */ | |
8020ceb5 | 221 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
9f3fdbc6 | 222 | uuid_t uuid; /* Trace session unique ID */ |
8020ceb5 MD |
223 | int metadata_dumped:1; |
224 | }; | |
225 | ||
226 | struct ltt_transport { | |
227 | char *name; | |
9f3fdbc6 | 228 | struct cds_list_head node; |
8020ceb5 MD |
229 | struct ltt_channel_ops ops; |
230 | }; | |
231 | ||
232 | struct ltt_session *ltt_session_create(void); | |
976fe9ea MD |
233 | int ltt_session_enable(struct ltt_session *session); |
234 | int ltt_session_disable(struct ltt_session *session); | |
8020ceb5 MD |
235 | void ltt_session_destroy(struct ltt_session *session); |
236 | ||
237 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, | |
238 | const char *transport_name, | |
239 | void *buf_addr, | |
240 | size_t subbuf_size, size_t num_subbuf, | |
241 | unsigned int switch_timer_interval, | |
0a42beb6 | 242 | unsigned int read_timer_interval); |
8020ceb5 MD |
243 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, |
244 | int overwrite, void *buf_addr, | |
245 | size_t subbuf_size, size_t num_subbuf, | |
246 | unsigned int switch_timer_interval, | |
247 | unsigned int read_timer_interval); | |
248 | ||
249 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, | |
9f3fdbc6 | 250 | struct lttng_ust_event *event_param, |
8020ceb5 MD |
251 | void *filter); |
252 | ||
976fe9ea MD |
253 | int ltt_channel_enable(struct ltt_channel *channel); |
254 | int ltt_channel_disable(struct ltt_channel *channel); | |
255 | int ltt_event_enable(struct ltt_event *event); | |
256 | int ltt_event_disable(struct ltt_event *event); | |
257 | ||
8020ceb5 MD |
258 | void ltt_transport_register(struct ltt_transport *transport); |
259 | void ltt_transport_unregister(struct ltt_transport *transport); | |
260 | ||
4b4de73e | 261 | void synchronize_trace(void); |
9f3fdbc6 MD |
262 | //int ltt_debugfs_abi_init(void); |
263 | //void ltt_debugfs_abi_exit(void); | |
8020ceb5 MD |
264 | |
265 | int ltt_probe_register(struct lttng_probe_desc *desc); | |
266 | void ltt_probe_unregister(struct lttng_probe_desc *desc); | |
267 | const struct lttng_event_desc *ltt_event_get(const char *name); | |
268 | void ltt_event_put(const struct lttng_event_desc *desc); | |
269 | int ltt_probes_init(void); | |
270 | void ltt_probes_exit(void); | |
271 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); | |
272 | void lttng_remove_context_field(struct lttng_ctx **ctx, | |
273 | struct lttng_ctx_field *field); | |
274 | void lttng_destroy_context(struct lttng_ctx *ctx); | |
9f3fdbc6 MD |
275 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
276 | ||
277 | //extern const struct file_operations lttng_tracepoint_list_fops; | |
8020ceb5 | 278 | |
0a42beb6 | 279 | #endif /* _UST_LTTNG_EVENTS_H */ |