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