Commit | Line | Data |
---|---|---|
97ee3a89 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
bdf64013 | 3 | * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com> |
97ee3a89 | 4 | * |
d14d33bf AM |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License, version 2 only, | |
7 | * as published by the Free Software Foundation. | |
97ee3a89 DG |
8 | * |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
d14d33bf AM |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
97ee3a89 DG |
17 | */ |
18 | ||
19 | #ifndef _LTT_TRACE_UST_H | |
20 | #define _LTT_TRACE_UST_H | |
21 | ||
22 | #include <limits.h> | |
23 | #include <urcu/list.h> | |
bec39940 | 24 | |
97ee3a89 | 25 | #include <lttng/lttng.h> |
10a8a223 | 26 | #include <common/hashtable/hashtable.h> |
ce2a9e76 | 27 | #include <common/defaults.h> |
3bd1e081 | 28 | |
00e2e675 | 29 | #include "consumer.h" |
48842b30 | 30 | #include "ust-ctl.h" |
97ee3a89 | 31 | |
7c1d2758 JG |
32 | struct agent; |
33 | ||
18eace3b DG |
34 | struct ltt_ust_ht_key { |
35 | const char *name; | |
36 | const struct lttng_filter_bytecode *filter; | |
2106efa0 | 37 | enum lttng_ust_loglevel_type loglevel_type; |
b953b8cd | 38 | int loglevel_value; |
7724731b | 39 | const struct lttng_event_exclusion *exclusion; |
18eace3b DG |
40 | }; |
41 | ||
f6a9efaa DG |
42 | /* Context hash table nodes */ |
43 | struct ltt_ust_context { | |
bdf64013 | 44 | struct lttng_ust_context_attr ctx; |
bec39940 | 45 | struct lttng_ht_node_ulong node; |
31746f93 | 46 | struct cds_list_head list; |
97ee3a89 DG |
47 | }; |
48 | ||
49 | /* UST event */ | |
50 | struct ltt_ust_event { | |
37357452 | 51 | unsigned int enabled; |
f6a9efaa | 52 | struct lttng_ust_event attr; |
bec39940 | 53 | struct lttng_ht_node_str node; |
6b453b5e | 54 | char *filter_expression; |
51755dc8 | 55 | struct lttng_filter_bytecode *filter; |
40024f8a | 56 | struct lttng_event_exclusion *exclusion; |
5b37cc51 JG |
57 | /* |
58 | * An internal event is an event which was created by the session daemon | |
59 | * through which, for example, events emitted in Agent domains are | |
60 | * "funelled". This is used to hide internal events from external | |
61 | * clients as they should never be modified by the external world. | |
62 | */ | |
88f06f15 | 63 | bool internal; |
2bdd86d4 MD |
64 | }; |
65 | ||
97ee3a89 DG |
66 | /* UST channel */ |
67 | struct ltt_ust_channel { | |
7972aab2 | 68 | uint64_t id; /* unique id per session. */ |
37357452 | 69 | unsigned int enabled; |
51755dc8 JG |
70 | /* |
71 | * A UST channel can be part of a userspace sub-domain such as JUL, | |
72 | * Log4j, Python. | |
73 | */ | |
74 | enum lttng_domain_type domain; | |
44d3bd01 | 75 | char name[LTTNG_UST_SYM_NAME_LEN]; |
ffe60014 | 76 | struct lttng_ust_channel_attr attr; |
bec39940 | 77 | struct lttng_ht *ctx; |
31746f93 | 78 | struct cds_list_head ctx_list; |
bec39940 DG |
79 | struct lttng_ht *events; |
80 | struct lttng_ht_node_str node; | |
1624d5b7 JD |
81 | uint64_t tracefile_size; |
82 | uint64_t tracefile_count; | |
fb83fe64 JD |
83 | uint64_t per_pid_closed_app_discarded; |
84 | uint64_t per_pid_closed_app_lost; | |
e9404c27 | 85 | uint64_t monitor_timer_interval; |
97ee3a89 DG |
86 | }; |
87 | ||
f6a9efaa DG |
88 | /* UST domain global (LTTNG_DOMAIN_UST) */ |
89 | struct ltt_ust_domain_global { | |
bec39940 | 90 | struct lttng_ht *channels; |
7972aab2 | 91 | struct cds_list_head registry_buffer_uid_list; |
f6a9efaa DG |
92 | }; |
93 | ||
a9ad0c8f MD |
94 | struct ust_pid_tracker_node { |
95 | struct lttng_ht_node_ulong node; | |
96 | }; | |
97 | ||
98 | struct ust_pid_tracker { | |
99 | struct lttng_ht *ht; | |
100 | }; | |
101 | ||
97ee3a89 DG |
102 | /* UST session */ |
103 | struct ltt_ust_session { | |
d9bf3ca4 | 104 | uint64_t id; /* Unique identifier of session */ |
f6a9efaa | 105 | struct ltt_ust_domain_global domain_global; |
fefd409b DG |
106 | /* Hash table of agent indexed by agent domain. */ |
107 | struct lttng_ht *agents; | |
6df2e2c9 MD |
108 | /* UID/GID of the user owning the session */ |
109 | uid_t uid; | |
110 | gid_t gid; | |
14fb1ebe DG |
111 | /* Is the session active meaning has is been started or stopped. */ |
112 | unsigned int active:1; | |
00e2e675 | 113 | struct consumer_output *consumer; |
f3f0db50 DG |
114 | /* Sequence number for filters so the tracer knows the ordering. */ |
115 | uint64_t filter_seq_num; | |
7972aab2 DG |
116 | /* This indicates which type of buffer this session is set for. */ |
117 | enum lttng_buffer_type buffer_type; | |
118 | /* If set to 1, the buffer_type can not be changed anymore. */ | |
119 | int buffer_type_changed; | |
120 | /* For per UID buffer, every buffer reg object is kept of this session */ | |
121 | struct cds_list_head buffer_reg_uid_list; | |
122 | /* Next channel ID available for a newly registered channel. */ | |
123 | uint64_t next_channel_id; | |
124 | /* Once this value reaches UINT32_MAX, no more id can be allocated. */ | |
125 | uint64_t used_channel_id; | |
2bba9e53 DG |
126 | /* Tell or not if the session has to output the traces. */ |
127 | unsigned int output_traces; | |
27babd3a | 128 | unsigned int snapshot_mode; |
85076754 | 129 | unsigned int has_non_default_channel; |
ecc48a90 | 130 | unsigned int live_timer_interval; /* usec */ |
84ad93e8 DG |
131 | |
132 | /* Metadata channel attributes. */ | |
133 | struct lttng_ust_channel_attr metadata_attr; | |
d7ba1388 MD |
134 | |
135 | /* | |
136 | * Path where to keep the shared memory files. | |
137 | */ | |
3d071855 | 138 | char root_shm_path[PATH_MAX]; |
d7ba1388 | 139 | char shm_path[PATH_MAX]; |
a9ad0c8f MD |
140 | |
141 | struct ust_pid_tracker pid_tracker; | |
82b69413 JG |
142 | |
143 | /* Current trace chunk of the ltt_session. */ | |
144 | struct lttng_trace_chunk *current_trace_chunk; | |
97ee3a89 DG |
145 | }; |
146 | ||
7972aab2 DG |
147 | /* |
148 | * Validate that the id has reached the maximum allowed or not. | |
149 | * | |
150 | * Return 0 if NOT else 1. | |
151 | */ | |
152 | static inline int trace_ust_is_max_id(uint64_t id) | |
153 | { | |
154 | return (id == UINT64_MAX) ? 1 : 0; | |
155 | } | |
156 | ||
157 | /* | |
158 | * Return next available channel id and increment the used counter. The | |
159 | * trace_ust_is_max_id function MUST be called before in order to validate if | |
160 | * the maximum number of IDs have been reached. If not, it is safe to call this | |
161 | * function. | |
162 | * | |
163 | * Return a unique channel ID. If max is reached, the used_channel_id counter | |
164 | * is returned. | |
165 | */ | |
166 | static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s) | |
167 | { | |
168 | if (trace_ust_is_max_id(s->used_channel_id)) { | |
169 | return s->used_channel_id; | |
170 | } | |
171 | ||
172 | s->used_channel_id++; | |
173 | return s->next_channel_id++; | |
174 | } | |
175 | ||
74d0b642 | 176 | #ifdef HAVE_LIBLTTNG_UST_CTL |
3bd1e081 | 177 | |
18eace3b DG |
178 | int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key); |
179 | int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, | |
180 | const void *_key); | |
181 | ||
97ee3a89 DG |
182 | /* |
183 | * Lookup functions. NULL is returned if not found. | |
184 | */ | |
18eace3b | 185 | struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
2106efa0 | 186 | char *name, struct lttng_filter_bytecode *filter, |
b953b8cd PP |
187 | enum lttng_ust_loglevel_type loglevel_type, int loglevel_value, |
188 | struct lttng_event_exclusion *exclusion); | |
bec39940 | 189 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
f6a9efaa | 190 | char *name); |
fefd409b DG |
191 | struct agent *trace_ust_find_agent(struct ltt_ust_session *session, |
192 | enum lttng_domain_type domain_type); | |
97ee3a89 DG |
193 | |
194 | /* | |
195 | * Create functions malloc() the data structure. | |
196 | */ | |
d9bf3ca4 | 197 | struct ltt_ust_session *trace_ust_create_session(uint64_t session_id); |
51755dc8 JG |
198 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
199 | enum lttng_domain_type domain); | |
39687410 | 200 | enum lttng_error_code trace_ust_create_event(struct lttng_event *ev, |
6b453b5e | 201 | char *filter_expression, |
561c6897 | 202 | struct lttng_filter_bytecode *filter, |
88f06f15 | 203 | struct lttng_event_exclusion *exclusion, |
39687410 | 204 | bool internal_event, struct ltt_ust_event **ust_event); |
55cc08a6 DG |
205 | struct ltt_ust_context *trace_ust_create_context( |
206 | struct lttng_event_context *ctx); | |
aa3514e9 MD |
207 | int trace_ust_match_context(struct ltt_ust_context *uctx, |
208 | struct lttng_event_context *ctx); | |
d5979e4a DG |
209 | void trace_ust_delete_channel(struct lttng_ht *ht, |
210 | struct ltt_ust_channel *channel); | |
97ee3a89 DG |
211 | |
212 | /* | |
213 | * Destroy functions free() the data structure and remove from linked list if | |
214 | * it's applies. | |
215 | */ | |
216 | void trace_ust_destroy_session(struct ltt_ust_session *session); | |
97ee3a89 DG |
217 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel); |
218 | void trace_ust_destroy_event(struct ltt_ust_event *event); | |
bdf64013 | 219 | void trace_ust_destroy_context(struct ltt_ust_context *ctx); |
97ee3a89 | 220 | |
a9ad0c8f MD |
221 | int trace_ust_track_pid(struct ltt_ust_session *session, int pid); |
222 | int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid); | |
223 | ||
b4650bd0 MD |
224 | int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid); |
225 | ||
a5dfbb9d MD |
226 | ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session, |
227 | int32_t **_pids); | |
228 | ||
74d0b642 | 229 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
3bd1e081 | 230 | |
37a86c61 DG |
231 | static inline int trace_ust_ht_match_event(struct cds_lfht_node *node, |
232 | const void *_key) | |
233 | { | |
234 | return 0; | |
235 | } | |
236 | static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, | |
237 | const void *_key) | |
238 | { | |
239 | return 0; | |
240 | } | |
3bd1e081 | 241 | static inline |
bec39940 | 242 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
f6a9efaa | 243 | char *name) |
3bd1e081 MD |
244 | { |
245 | return NULL; | |
246 | } | |
f6a9efaa | 247 | |
3bd1e081 | 248 | static inline |
dec56f6c | 249 | struct ltt_ust_session *trace_ust_create_session(unsigned int session_id) |
3bd1e081 MD |
250 | { |
251 | return NULL; | |
252 | } | |
253 | static inline | |
51755dc8 JG |
254 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
255 | enum lttng_domain_type domain) | |
3bd1e081 MD |
256 | { |
257 | return NULL; | |
258 | } | |
259 | static inline | |
39687410 | 260 | enum lttng_error_code trace_ust_create_event(struct lttng_event *ev, |
6b453b5e | 261 | const char *filter_expression, |
561c6897 | 262 | struct lttng_filter_bytecode *filter, |
88f06f15 | 263 | struct lttng_event_exclusion *exclusion, |
39687410 | 264 | bool internal_event, struct ltt_ust_event **ust_event) |
3bd1e081 | 265 | { |
39687410 | 266 | return LTTNG_ERR_NO_UST; |
3bd1e081 | 267 | } |
3bd1e081 MD |
268 | static inline |
269 | void trace_ust_destroy_session(struct ltt_ust_session *session) | |
270 | { | |
271 | } | |
48842b30 | 272 | |
3bd1e081 MD |
273 | static inline |
274 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel) | |
275 | { | |
276 | } | |
48842b30 | 277 | |
3bd1e081 MD |
278 | static inline |
279 | void trace_ust_destroy_event(struct ltt_ust_event *event) | |
280 | { | |
281 | } | |
34378f76 DG |
282 | static inline |
283 | struct ltt_ust_context *trace_ust_create_context( | |
284 | struct lttng_event_context *ctx) | |
285 | { | |
286 | return NULL; | |
287 | } | |
aa3514e9 MD |
288 | static inline |
289 | int trace_ust_match_context(struct ltt_ust_context *uctx, | |
290 | struct lttng_event_context *ctx) | |
291 | { | |
292 | return 0; | |
293 | } | |
b953b8cd PP |
294 | static inline |
295 | struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, | |
2106efa0 | 296 | char *name, struct lttng_filter_bytecode *filter, |
b953b8cd PP |
297 | enum lttng_ust_loglevel_type loglevel_type, int loglevel_value, |
298 | struct lttng_event_exclusion *exclusion) | |
37a86c61 DG |
299 | { |
300 | return NULL; | |
301 | } | |
d5979e4a DG |
302 | static inline |
303 | void trace_ust_delete_channel(struct lttng_ht *ht, | |
304 | struct ltt_ust_channel *channel) | |
305 | { | |
306 | return; | |
307 | } | |
fefd409b DG |
308 | static inline |
309 | struct agent *trace_ust_find_agent(struct ltt_ust_session *session, | |
310 | enum lttng_domain_type domain_type) | |
311 | { | |
312 | return NULL; | |
313 | } | |
a9ad0c8f MD |
314 | static inline |
315 | int trace_ust_track_pid(struct ltt_ust_session *session, int pid) | |
316 | { | |
317 | return 0; | |
318 | } | |
319 | static inline | |
320 | int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid) | |
321 | { | |
322 | return 0; | |
323 | } | |
b4650bd0 MD |
324 | static inline |
325 | int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid) | |
326 | { | |
327 | return 0; | |
328 | } | |
3646a051 | 329 | static inline |
a5dfbb9d MD |
330 | ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session, |
331 | int32_t **_pids) | |
332 | { | |
333 | return -1; | |
334 | } | |
74d0b642 | 335 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
3bd1e081 | 336 | |
97ee3a89 | 337 | #endif /* _LTT_TRACE_UST_H */ |