Fix: include loglevel type in UST event's primary key
[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
3bd1e081 21#include <config.h>
97ee3a89
DG
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
32struct agent;
33
18eace3b
DG
34struct 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 */
43struct ltt_ust_context {
44 struct lttng_ust_context ctx;
bec39940 45 struct lttng_ht_node_ulong node;
31746f93 46 struct cds_list_head list;
97ee3a89
DG
47};
48
49/* UST event */
50struct 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 */
67struct 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;
97ee3a89
DG
83};
84
f6a9efaa
DG
85/* UST domain global (LTTNG_DOMAIN_UST) */
86struct ltt_ust_domain_global {
bec39940 87 struct lttng_ht *channels;
7972aab2 88 struct cds_list_head registry_buffer_uid_list;
f6a9efaa
DG
89};
90
a9ad0c8f
MD
91struct ust_pid_tracker_node {
92 struct lttng_ht_node_ulong node;
93};
94
95struct ust_pid_tracker {
96 struct lttng_ht *ht;
97};
98
97ee3a89
DG
99/* UST session */
100struct ltt_ust_session {
d9bf3ca4 101 uint64_t id; /* Unique identifier of session */
f6a9efaa 102 struct ltt_ust_domain_global domain_global;
fefd409b
DG
103 /* Hash table of agent indexed by agent domain. */
104 struct lttng_ht *agents;
6df2e2c9
MD
105 /* UID/GID of the user owning the session */
106 uid_t uid;
107 gid_t gid;
14fb1ebe
DG
108 /* Is the session active meaning has is been started or stopped. */
109 unsigned int active:1;
00e2e675 110 struct consumer_output *consumer;
f3f0db50
DG
111 /* Sequence number for filters so the tracer knows the ordering. */
112 uint64_t filter_seq_num;
7972aab2
DG
113 /* This indicates which type of buffer this session is set for. */
114 enum lttng_buffer_type buffer_type;
115 /* If set to 1, the buffer_type can not be changed anymore. */
116 int buffer_type_changed;
117 /* For per UID buffer, every buffer reg object is kept of this session */
118 struct cds_list_head buffer_reg_uid_list;
119 /* Next channel ID available for a newly registered channel. */
120 uint64_t next_channel_id;
121 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
122 uint64_t used_channel_id;
2bba9e53
DG
123 /* Tell or not if the session has to output the traces. */
124 unsigned int output_traces;
27babd3a 125 unsigned int snapshot_mode;
85076754 126 unsigned int has_non_default_channel;
ecc48a90 127 unsigned int live_timer_interval; /* usec */
84ad93e8
DG
128
129 /* Metadata channel attributes. */
130 struct lttng_ust_channel_attr metadata_attr;
d7ba1388
MD
131
132 /*
133 * Path where to keep the shared memory files.
134 */
3d071855 135 char root_shm_path[PATH_MAX];
d7ba1388 136 char shm_path[PATH_MAX];
a9ad0c8f
MD
137
138 struct ust_pid_tracker pid_tracker;
97ee3a89
DG
139};
140
7972aab2
DG
141/*
142 * Validate that the id has reached the maximum allowed or not.
143 *
144 * Return 0 if NOT else 1.
145 */
146static inline int trace_ust_is_max_id(uint64_t id)
147{
148 return (id == UINT64_MAX) ? 1 : 0;
149}
150
151/*
152 * Return next available channel id and increment the used counter. The
153 * trace_ust_is_max_id function MUST be called before in order to validate if
154 * the maximum number of IDs have been reached. If not, it is safe to call this
155 * function.
156 *
157 * Return a unique channel ID. If max is reached, the used_channel_id counter
158 * is returned.
159 */
160static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
161{
162 if (trace_ust_is_max_id(s->used_channel_id)) {
163 return s->used_channel_id;
164 }
165
166 s->used_channel_id++;
167 return s->next_channel_id++;
168}
169
74d0b642 170#ifdef HAVE_LIBLTTNG_UST_CTL
3bd1e081 171
18eace3b
DG
172int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
173int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
174 const void *_key);
175
97ee3a89
DG
176/*
177 * Lookup functions. NULL is returned if not found.
178 */
18eace3b 179struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
2106efa0 180 char *name, struct lttng_filter_bytecode *filter,
b953b8cd
PP
181 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
182 struct lttng_event_exclusion *exclusion);
bec39940 183struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
f6a9efaa 184 char *name);
fefd409b
DG
185struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
186 enum lttng_domain_type domain_type);
97ee3a89
DG
187
188/*
189 * Create functions malloc() the data structure.
190 */
d9bf3ca4 191struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
51755dc8
JG
192struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
193 enum lttng_domain_type domain);
025faf73 194struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
6b453b5e 195 char *filter_expression,
561c6897 196 struct lttng_filter_bytecode *filter,
88f06f15
JG
197 struct lttng_event_exclusion *exclusion,
198 bool internal_event);
55cc08a6
DG
199struct ltt_ust_context *trace_ust_create_context(
200 struct lttng_event_context *ctx);
aa3514e9
MD
201int trace_ust_match_context(struct ltt_ust_context *uctx,
202 struct lttng_event_context *ctx);
d5979e4a
DG
203void trace_ust_delete_channel(struct lttng_ht *ht,
204 struct ltt_ust_channel *channel);
97ee3a89
DG
205
206/*
207 * Destroy functions free() the data structure and remove from linked list if
208 * it's applies.
209 */
210void trace_ust_destroy_session(struct ltt_ust_session *session);
97ee3a89
DG
211void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
212void trace_ust_destroy_event(struct ltt_ust_event *event);
213
a9ad0c8f
MD
214int trace_ust_track_pid(struct ltt_ust_session *session, int pid);
215int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid);
216
b4650bd0
MD
217int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid);
218
a5dfbb9d
MD
219ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
220 int32_t **_pids);
221
74d0b642 222#else /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 223
37a86c61
DG
224static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
225 const void *_key)
226{
227 return 0;
228}
229static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
230 const void *_key)
231{
232 return 0;
233}
3bd1e081 234static inline
bec39940 235struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
f6a9efaa 236 char *name)
3bd1e081
MD
237{
238 return NULL;
239}
f6a9efaa 240
3bd1e081 241static inline
dec56f6c 242struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
3bd1e081
MD
243{
244 return NULL;
245}
246static inline
51755dc8
JG
247struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
248 enum lttng_domain_type domain)
3bd1e081
MD
249{
250 return NULL;
251}
252static inline
025faf73 253struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
6b453b5e 254 const char *filter_expression,
561c6897 255 struct lttng_filter_bytecode *filter,
88f06f15
JG
256 struct lttng_event_exclusion *exclusion,
257 bool internal_event)
3bd1e081
MD
258{
259 return NULL;
260}
3bd1e081
MD
261static inline
262void trace_ust_destroy_session(struct ltt_ust_session *session)
263{
264}
48842b30 265
3bd1e081
MD
266static inline
267void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
268{
269}
48842b30 270
3bd1e081
MD
271static inline
272void trace_ust_destroy_event(struct ltt_ust_event *event)
273{
274}
34378f76
DG
275static inline
276struct ltt_ust_context *trace_ust_create_context(
277 struct lttng_event_context *ctx)
278{
279 return NULL;
280}
aa3514e9
MD
281static inline
282int trace_ust_match_context(struct ltt_ust_context *uctx,
283 struct lttng_event_context *ctx)
284{
285 return 0;
286}
b953b8cd
PP
287static inline
288struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
2106efa0 289 char *name, struct lttng_filter_bytecode *filter,
b953b8cd
PP
290 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
291 struct lttng_event_exclusion *exclusion)
37a86c61
DG
292{
293 return NULL;
294}
d5979e4a
DG
295static inline
296void trace_ust_delete_channel(struct lttng_ht *ht,
297 struct ltt_ust_channel *channel)
298{
299 return;
300}
fefd409b
DG
301static inline
302struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
303 enum lttng_domain_type domain_type)
304{
305 return NULL;
306}
a9ad0c8f
MD
307static inline
308int trace_ust_track_pid(struct ltt_ust_session *session, int pid)
309{
310 return 0;
311}
312static inline
313int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid)
314{
315 return 0;
316}
b4650bd0
MD
317static inline
318int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid)
319{
320 return 0;
321}
3646a051 322static inline
a5dfbb9d
MD
323ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
324 int32_t **_pids)
325{
326 return -1;
327}
74d0b642 328#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 329
97ee3a89 330#endif /* _LTT_TRACE_UST_H */
This page took 0.068897 seconds and 5 git commands to generate.