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