SoW-2020-0003: Trace Hit Counters
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
1 /*
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef _LTT_TRACE_UST_H
10 #define _LTT_TRACE_UST_H
11
12 #include <limits.h>
13 #include <urcu/list.h>
14
15 #include <common/defaults.h>
16 #include <common/hashtable/hashtable.h>
17 #include <common/tracker.h>
18 #include <lttng/lttng.h>
19
20 #include "consumer.h"
21 #include "lttng-ust-ctl.h"
22
23 struct agent;
24
25 struct ltt_ust_ht_key {
26 uint64_t tracer_token;
27 const char *name;
28 const struct lttng_bytecode *filter;
29 enum lttng_ust_loglevel_type loglevel_type;
30 int loglevel_value;
31 const struct lttng_event_exclusion *exclusion;
32 struct lttng_map_key *key;
33 };
34
35 /* Context hash table nodes */
36 struct ltt_ust_context {
37 struct lttng_ust_context_attr ctx;
38 struct lttng_ht_node_ulong node;
39 struct cds_list_head list;
40 };
41
42 /* UST event */
43 struct ltt_ust_event {
44 unsigned int enabled;
45 struct lttng_ust_event attr;
46 struct lttng_ht_node_str node;
47 char *filter_expression;
48 struct lttng_bytecode *filter;
49 struct lttng_event_exclusion *exclusion;
50
51 /* refcounted */
52 struct lttng_map_key *key;
53 /*
54 * An internal event is an event which was created by the session daemon
55 * through which, for example, events emitted in Agent domains are
56 * "funelled". This is used to hide internal events from external
57 * clients as they should never be modified by the external world.
58 */
59 bool internal;
60 };
61
62 /* UST channel */
63 struct ltt_ust_channel {
64 uint64_t id; /* unique id per session. */
65 unsigned int enabled;
66 /*
67 * A UST channel can be part of a userspace sub-domain such as JUL,
68 * Log4j, Python.
69 */
70 enum lttng_domain_type domain;
71 char name[LTTNG_UST_SYM_NAME_LEN];
72 struct lttng_ust_channel_attr attr;
73 struct lttng_ht *ctx;
74 struct cds_list_head ctx_list;
75 struct lttng_ht *events;
76 struct lttng_ht_node_str node;
77 uint64_t tracefile_size;
78 uint64_t tracefile_count;
79 uint64_t per_pid_closed_app_discarded;
80 uint64_t per_pid_closed_app_lost;
81 uint64_t monitor_timer_interval;
82 };
83
84 struct ltt_ust_map_dead_pid_kv_values {
85 pthread_mutex_t lock;
86 struct lttng_ht *dead_app_kv_values_32bits;
87 struct lttng_ht *dead_app_kv_values_64bits;
88 };
89
90 /* UST map */
91 struct ltt_ust_map {
92 uint64_t id; /* unique id per session. */
93 char name[LTTNG_UST_SYM_NAME_LEN];
94 unsigned int enabled;
95 size_t bucket_count;
96 bool coalesce_hits;
97 enum lttng_map_bitness bitness;
98 uint64_t nr_cpu;
99 struct lttng_ht_node_str node;
100 struct lttng_map *map;
101 struct lttng_ht *events;
102 struct ltt_ust_map_dead_pid_kv_values dead_app_kv_values;
103 };
104
105 /* UST domain global (LTTNG_DOMAIN_UST) */
106 struct ltt_ust_domain_global {
107 struct lttng_ht *channels;
108 struct lttng_ht *maps;
109 struct cds_list_head registry_buffer_uid_list;
110 };
111
112 struct ust_id_tracker_node {
113 struct lttng_ht_node_ulong node;
114 };
115
116 struct ust_id_tracker {
117 struct lttng_ht *ht;
118 };
119
120 /* UST session */
121 struct ltt_ust_session {
122 uint64_t id; /* Unique identifier of session */
123 struct ltt_ust_domain_global domain_global;
124 /* Hash table of agent indexed by agent domain. */
125 struct lttng_ht *agents;
126 /* UID/GID of the user owning the session */
127 uid_t uid;
128 gid_t gid;
129 /* Is the session active meaning has is been started or stopped. */
130 unsigned int active:1;
131 struct consumer_output *consumer;
132 /* Sequence number for filters so the tracer knows the ordering. */
133 uint64_t filter_seq_num;
134 /* This indicates which type of buffer this session is set for. */
135 enum lttng_buffer_type buffer_type;
136 /* If set to 1, the buffer_type can not be changed anymore. */
137 int buffer_type_changed;
138 /* For per UID buffer, every buffer reg object is kept of this session */
139 struct cds_list_head buffer_reg_uid_list;
140 /* Next channel ID available for a newly registered channel. */
141 uint64_t next_channel_id;
142 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
143 uint64_t used_channel_id;
144 /* Tell or not if the session has to output the traces. */
145 unsigned int output_traces;
146 unsigned int snapshot_mode;
147 unsigned int has_non_default_channel;
148 unsigned int live_timer_interval; /* usec */
149
150 /* Metadata channel attributes. */
151 struct lttng_ust_channel_attr metadata_attr;
152
153 /*
154 * Path where to keep the shared memory files.
155 */
156 char root_shm_path[PATH_MAX];
157 char shm_path[PATH_MAX];
158
159 /* Current trace chunk of the ltt_session. */
160 struct lttng_trace_chunk *current_trace_chunk;
161
162 /* Trackers used for actual lookup on app registration. */
163 struct ust_id_tracker vpid_tracker;
164 struct ust_id_tracker vuid_tracker;
165 struct ust_id_tracker vgid_tracker;
166
167 /* Tracker list of keys requested by users. */
168 struct process_attr_tracker *tracker_vpid;
169 struct process_attr_tracker *tracker_vuid;
170 struct process_attr_tracker *tracker_vgid;
171 };
172
173 /*
174 * Validate that the id has reached the maximum allowed or not.
175 *
176 * Return 0 if NOT else 1.
177 */
178 static inline int trace_ust_is_max_id(uint64_t id)
179 {
180 return (id == UINT64_MAX) ? 1 : 0;
181 }
182
183 /*
184 * Return next available channel id and increment the used counter. The
185 * trace_ust_is_max_id function MUST be called before in order to validate if
186 * the maximum number of IDs have been reached. If not, it is safe to call this
187 * function.
188 *
189 * Return a unique channel ID. If max is reached, the used_channel_id counter
190 * is returned.
191 */
192 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
193 {
194 if (trace_ust_is_max_id(s->used_channel_id)) {
195 return s->used_channel_id;
196 }
197
198 s->used_channel_id++;
199 return s->next_channel_id++;
200 }
201
202 #ifdef HAVE_LIBLTTNG_UST_CTL
203
204 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
205 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
206 const void *_key);
207
208 /*
209 * Lookup functions. NULL is returned if not found.
210 */
211 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
212 uint64_t tracer_token, char *name, struct lttng_bytecode *filter,
213 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
214 struct lttng_event_exclusion *exclusion,
215 struct lttng_map_key *key);
216 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
217 const char *name);
218 struct ltt_ust_map *trace_ust_find_map_by_name(struct lttng_ht *ht,
219 const char *name);
220 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
221 enum lttng_domain_type domain_type);
222
223 /*
224 * Create functions malloc() the data structure.
225 */
226 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
227 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
228 enum lttng_domain_type domain);
229 struct ltt_ust_map *trace_ust_create_map(const struct lttng_map *map);
230 enum lttng_error_code trace_ust_create_event(uint64_t tracer_token,
231 const char *ev_name,
232 struct lttng_map_key *key,
233 enum lttng_event_type ev_type,
234 enum lttng_loglevel_type ev_loglevel_type,
235 enum lttng_loglevel ev_loglevel,
236 char *filter_expression,
237 struct lttng_bytecode *filter,
238 struct lttng_event_exclusion *exclusion,
239 bool internal_event,
240 struct ltt_ust_event **ust_event);
241 struct ltt_ust_context *trace_ust_create_context(
242 const struct lttng_event_context *ctx);
243 int trace_ust_match_context(const struct ltt_ust_context *uctx,
244 const struct lttng_event_context *ctx);
245 void trace_ust_delete_channel(struct lttng_ht *ht,
246 struct ltt_ust_channel *channel);
247 void trace_ust_delete_map(struct lttng_ht *ht,
248 struct ltt_ust_map *map);
249
250 /*
251 * Destroy functions free() the data structure and remove from linked list if
252 * it's applies.
253 */
254 void trace_ust_destroy_session(struct ltt_ust_session *session);
255 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
256 void trace_ust_destroy_map(struct ltt_ust_map *map);
257 void trace_ust_destroy_event(struct ltt_ust_event *event);
258 void trace_ust_destroy_context(struct ltt_ust_context *ctx);
259 void trace_ust_free_session(struct ltt_ust_session *session);
260
261 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
262 struct ltt_ust_session *session,
263 int id);
264 enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy(
265 struct ltt_ust_session *session,
266 enum lttng_process_attr process_attr,
267 enum lttng_tracking_policy policy);
268 enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value(
269 struct ltt_ust_session *session,
270 enum lttng_process_attr process_attr,
271 const struct process_attr_value *value);
272 enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value(
273 struct ltt_ust_session *session,
274 enum lttng_process_attr process_attr,
275 const struct process_attr_value *value);
276 const struct process_attr_tracker *trace_ust_get_process_attr_tracker(
277 struct ltt_ust_session *session,
278 enum lttng_process_attr process_attr);
279
280 #else /* HAVE_LIBLTTNG_UST_CTL */
281
282 static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
283 const void *_key)
284 {
285 return 0;
286 }
287 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
288 const void *_key)
289 {
290 return 0;
291 }
292 static inline
293 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
294 const char *name)
295 {
296 return NULL;
297 }
298 static inline
299 struct ltt_ust_map *trace_ust_find_map_by_name(struct lttng_ht *ht,
300 const char *name)
301 {
302 return NULL;
303 }
304 static inline
305 struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
306 {
307 return NULL;
308 }
309 static inline
310 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
311 enum lttng_domain_type domain)
312 {
313 return NULL;
314 }
315 static inline
316 struct ltt_ust_map *trace_ust_create_map(const struct lttng_map *map)
317 {
318 return NULL;
319 }
320 static inline
321 enum lttng_error_code trace_ust_create_event(uint64_t tracer_token,
322 const char *ev_name,
323 struct lttng_map_key *key,
324 enum lttng_event_type ev_type,
325 enum lttng_loglevel_type ev_loglevel_type,
326 enum lttng_loglevel ev_loglevel,
327 char *filter_expression,
328 struct lttng_bytecode *filter,
329 struct lttng_event_exclusion *exclusion,
330 bool internal_event,
331 struct ltt_ust_event **ust_event)
332 {
333 return LTTNG_ERR_NO_UST;
334 }
335 static inline
336 void trace_ust_destroy_session(struct ltt_ust_session *session)
337 {
338 }
339
340 static inline
341 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
342 {
343 }
344
345 static inline
346 void trace_ust_destroy_map(struct ltt_ust_map *map)
347 {
348 }
349
350 static inline
351 void trace_ust_destroy_event(struct ltt_ust_event *event)
352 {
353 }
354
355 static inline
356 void trace_ust_free_session(struct ltt_ust_session *session)
357 {
358 }
359
360 static inline
361 struct ltt_ust_context *trace_ust_create_context(
362 const struct lttng_event_context *ctx)
363 {
364 return NULL;
365 }
366 static inline
367 int trace_ust_match_context(const struct ltt_ust_context *uctx,
368 const struct lttng_event_context *ctx)
369 {
370 return 0;
371 }
372 static inline
373 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
374 uint64_t tracer_token, char *name, struct lttng_bytecode *filter,
375 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
376 struct lttng_event_exclusion *exclusion,
377 struct lttng_map_key *key)
378 {
379 return NULL;
380 }
381 static inline
382 void trace_ust_delete_channel(struct lttng_ht *ht,
383 struct ltt_ust_channel *channel)
384 {
385 return;
386 }
387 static inline
388 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
389 enum lttng_domain_type domain_type)
390 {
391 return NULL;
392 }
393 static inline int trace_ust_id_tracker_lookup(
394 enum lttng_process_attr process_attr,
395 struct ltt_ust_session *session,
396 int id)
397 {
398 return 0;
399 }
400 static inline enum lttng_error_code
401 trace_ust_process_attr_tracker_set_tracking_policy(
402 struct ltt_ust_session *session,
403 enum lttng_process_attr process_attr,
404 enum lttng_tracking_policy policy)
405 {
406 return LTTNG_OK;
407 }
408 static inline enum lttng_error_code
409 trace_ust_process_attr_tracker_inclusion_set_add_value(
410 struct ltt_ust_session *session,
411 enum lttng_process_attr process_attr,
412 const struct process_attr_value *value)
413 {
414 return LTTNG_OK;
415 }
416 static inline enum lttng_error_code
417 trace_ust_process_attr_tracker_inclusion_set_remove_value(
418 struct ltt_ust_session *session,
419 enum lttng_process_attr process_attr,
420 const struct process_attr_value *value)
421 {
422 return LTTNG_OK;
423 }
424 static inline const struct process_attr_tracker *
425 trace_ust_get_process_attr_tracker(struct ltt_ust_session *session,
426 enum lttng_process_attr process_attr)
427 {
428 return NULL;
429 }
430
431 #endif /* HAVE_LIBLTTNG_UST_CTL */
432
433 #endif /* _LTT_TRACE_UST_H */
This page took 0.039572 seconds and 5 git commands to generate.