unregister event when FD is closed
[deliverable/lttng-modules.git] / 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
12 #include <linux/list.h>
13 #include <linux/uuid.h>
14 #include "ltt-debugfs-abi.h"
15
16 struct ltt_channel;
17 struct ltt_session;
18 struct lib_ring_buffer_ctx;
19
20 /* Type description */
21
22 /* Update the astract_types name table in lttng-types.c along with this enum */
23 enum abstract_types {
24 atype_integer,
25 atype_enum,
26 atype_array,
27 atype_sequence,
28 atype_string,
29 NR_ABSTRACT_TYPES,
30 };
31
32 /* Update the string_encodings name table in lttng-types.c along with this enum */
33 enum lttng_string_encodings {
34 lttng_encode_UTF8 = 0,
35 lttng_encode_ASCII = 1,
36 NR_STRING_ENCODINGS,
37 };
38
39 struct lttng_enum_entry {
40 unsigned long long start, end; /* start and end are inclusive */
41 const char *string;
42 };
43
44 #define __type_integer(_type, _byte_order) \
45 { \
46 .atype = atype_integer, \
47 .u.basic.integer = \
48 { \
49 .size = sizeof(_type), \
50 .alignment = ltt_alignof(_type) * CHAR_BIT, \
51 .signedness = is_signed_type(_type), \
52 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
53 }, \
54 } \
55
56 struct lttng_integer_type {
57 unsigned int size; /* in bits */
58 unsigned short alignment; /* in bits */
59 unsigned int signedness:1;
60 unsigned int reverse_byte_order:1;
61 };
62
63 union _lttng_basic_type {
64 struct lttng_integer_type integer;
65 struct {
66 const char *name;
67 } enumeration;
68 struct {
69 enum lttng_string_encodings encoding;
70 } string;
71 };
72
73 struct lttng_basic_type {
74 enum abstract_types atype;
75 union {
76 union _lttng_basic_type basic;
77 } u;
78 };
79
80 struct lttng_type {
81 enum abstract_types atype;
82 union {
83 union _lttng_basic_type basic;
84 struct {
85 struct lttng_basic_type elem_type;
86 unsigned int length; /* num. elems. */
87 } array;
88 struct {
89 struct lttng_basic_type length_type;
90 struct lttng_basic_type elem_type;
91 } sequence;
92 } u;
93 };
94
95 struct lttng_enum {
96 const char *name;
97 struct lttng_type container_type;
98 const struct lttng_enum_entry *entries;
99 unsigned int len;
100 };
101
102 /* Event field description */
103
104 struct lttng_event_field {
105 const char *name;
106 const struct lttng_type type;
107 };
108
109 struct lttng_event_desc {
110 const struct lttng_event_field *fields;
111 const char *name;
112 void *probe_callback;
113 unsigned int nr_fields;
114 };
115
116 struct lttng_probe_desc {
117 const struct lttng_event_desc *event_desc;
118 unsigned int nr_events;
119 struct list_head head; /* chain registered probes */
120 };
121
122 /*
123 * ltt_event structure is referred to by the tracing fast path. It must be
124 * kept small.
125 */
126 struct ltt_event {
127 unsigned int id;
128 struct ltt_channel *chan;
129 const struct lttng_event_desc *desc;
130 void *filter;
131 enum instrum_type itype;
132 struct list_head list; /* Event list */
133 int metadata_dumped:1;
134 };
135
136 struct ltt_channel_ops {
137 struct channel *(*channel_create)(const char *name,
138 struct ltt_session *session,
139 void *buf_addr,
140 size_t subbuf_size, size_t num_subbuf,
141 unsigned int switch_timer_interval,
142 unsigned int read_timer_interval);
143 void (*channel_destroy)(struct channel *chan);
144 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
145 void (*buffer_read_close)(struct lib_ring_buffer *buf);
146 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx);
147 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
148 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
149 size_t len);
150 /*
151 * packet_avail_size returns the available size in the current
152 * packet. Note that the size returned is only a hint, since it
153 * may change due to concurrent writes.
154 */
155 size_t (*packet_avail_size)(struct channel *chan);
156 wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan);
157 };
158
159 struct ltt_channel {
160 unsigned int id;
161 struct channel *chan; /* Channel buffers */
162 /* Event ID management */
163 struct ltt_session *session;
164 struct file *file; /* File associated to channel */
165 unsigned int free_event_id; /* Next event ID to allocate */
166 struct list_head list; /* Channel list */
167 wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */
168 struct ltt_channel_ops *ops;
169 int metadata_dumped:1;
170 int header_type:2; /* 0: unset, 1: compact, 2: large */
171 };
172
173 struct ltt_session {
174 int active; /* Is trace session active ? */
175 struct file *file; /* File associated to session */
176 struct ltt_channel *metadata; /* Metadata channel */
177 struct list_head chan; /* Channel list head */
178 struct list_head events; /* Event list head */
179 struct list_head list; /* Session list */
180 unsigned int free_chan_id; /* Next chan ID to allocate */
181 uuid_le uuid; /* Trace session unique ID */
182 int metadata_dumped:1;
183 };
184
185 struct ltt_transport {
186 char *name;
187 struct module *owner;
188 struct list_head node;
189 struct ltt_channel_ops ops;
190 };
191
192 struct ltt_session *ltt_session_create(void);
193 int ltt_session_start(struct ltt_session *session);
194 int ltt_session_stop(struct ltt_session *session);
195 void ltt_session_destroy(struct ltt_session *session);
196
197 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
198 const char *transport_name,
199 void *buf_addr,
200 size_t subbuf_size, size_t num_subbuf,
201 unsigned int switch_timer_interval,
202 unsigned int read_timer_interval);
203 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
204 int overwrite, void *buf_addr,
205 size_t subbuf_size, size_t num_subbuf,
206 unsigned int switch_timer_interval,
207 unsigned int read_timer_interval);
208 void _ltt_channel_destroy(struct ltt_channel *chan);
209
210 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
211 char *name,
212 enum instrum_type itype,
213 const struct lttng_event_desc *event_desc,
214 void *filter);
215 int ltt_event_unregister(struct ltt_event *event);
216
217 void ltt_transport_register(struct ltt_transport *transport);
218 void ltt_transport_unregister(struct ltt_transport *transport);
219
220 int ltt_debugfs_abi_init(void);
221 void ltt_debugfs_abi_exit(void);
222
223 int ltt_probe_register(struct lttng_probe_desc *desc);
224 void ltt_probe_unregister(struct lttng_probe_desc *desc);
225 const struct lttng_event_desc *ltt_event_get(const char *name);
226 void ltt_event_put(const struct lttng_event_desc *desc);
227 int ltt_probes_init(void);
228 void ltt_probes_exit(void);
229
230 #endif /* _LTT_EVENTS_H */
This page took 0.045451 seconds and 6 git commands to generate.