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