Fix: reference counting of consumer output
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
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.
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 *
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.
16 */
17
18#ifndef _LTT_TRACE_UST_H
19#define _LTT_TRACE_UST_H
20
21#include <config.h>
22#include <limits.h>
23#include <urcu/list.h>
24
25#include <lttng/lttng.h>
26#include <common/hashtable/hashtable.h>
27#include <common/defaults.h>
28
29#include "consumer.h"
30#include "agent.h"
31#include "ust-ctl.h"
32
33struct ltt_ust_ht_key {
34 const char *name;
35 const struct lttng_filter_bytecode *filter;
36 enum lttng_ust_loglevel_type loglevel;
37 const struct lttng_event_exclusion *exclusion;
38};
39
40/* Context hash table nodes */
41struct ltt_ust_context {
42 struct lttng_ust_context ctx;
43 struct lttng_ht_node_ulong node;
44 struct cds_list_head list;
45};
46
47/* UST event */
48struct ltt_ust_event {
49 unsigned int enabled;
50 struct lttng_ust_event attr;
51 struct lttng_ht_node_str node;
52 char *filter_expression;
53 struct lttng_filter_bytecode *filter;
54 struct lttng_event_exclusion *exclusion;
55 bool internal;
56};
57
58/* UST channel */
59struct ltt_ust_channel {
60 uint64_t id; /* unique id per session. */
61 unsigned int enabled;
62 /*
63 * A UST channel can be part of a userspace sub-domain such as JUL,
64 * Log4j, Python.
65 */
66 enum lttng_domain_type domain;
67 char name[LTTNG_UST_SYM_NAME_LEN];
68 struct lttng_ust_channel_attr attr;
69 struct lttng_ht *ctx;
70 struct cds_list_head ctx_list;
71 struct lttng_ht *events;
72 struct lttng_ht_node_str node;
73 uint64_t tracefile_size;
74 uint64_t tracefile_count;
75};
76
77/* UST domain global (LTTNG_DOMAIN_UST) */
78struct ltt_ust_domain_global {
79 struct lttng_ht *channels;
80 struct cds_list_head registry_buffer_uid_list;
81};
82
83struct ust_pid_tracker_node {
84 struct lttng_ht_node_ulong node;
85};
86
87struct ust_pid_tracker {
88 struct lttng_ht *ht;
89};
90
91/* UST session */
92struct ltt_ust_session {
93 uint64_t id; /* Unique identifier of session */
94 struct ltt_ust_domain_global domain_global;
95 /* Hash table of agent indexed by agent domain. */
96 struct lttng_ht *agents;
97 /* UID/GID of the user owning the session */
98 uid_t uid;
99 gid_t gid;
100 /* Is the session active meaning has is been started or stopped. */
101 unsigned int active:1;
102 struct consumer_output *consumer;
103 /* Sequence number for filters so the tracer knows the ordering. */
104 uint64_t filter_seq_num;
105 /* This indicates which type of buffer this session is set for. */
106 enum lttng_buffer_type buffer_type;
107 /* If set to 1, the buffer_type can not be changed anymore. */
108 int buffer_type_changed;
109 /* For per UID buffer, every buffer reg object is kept of this session */
110 struct cds_list_head buffer_reg_uid_list;
111 /* Next channel ID available for a newly registered channel. */
112 uint64_t next_channel_id;
113 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
114 uint64_t used_channel_id;
115 /* Tell or not if the session has to output the traces. */
116 unsigned int output_traces;
117 unsigned int snapshot_mode;
118 unsigned int has_non_default_channel;
119 unsigned int live_timer_interval; /* usec */
120
121 /* Metadata channel attributes. */
122 struct lttng_ust_channel_attr metadata_attr;
123
124 /*
125 * Path where to keep the shared memory files.
126 */
127 char root_shm_path[PATH_MAX];
128 char shm_path[PATH_MAX];
129
130 struct ust_pid_tracker pid_tracker;
131};
132
133/*
134 * Validate that the id has reached the maximum allowed or not.
135 *
136 * Return 0 if NOT else 1.
137 */
138static inline int trace_ust_is_max_id(uint64_t id)
139{
140 return (id == UINT64_MAX) ? 1 : 0;
141}
142
143/*
144 * Return next available channel id and increment the used counter. The
145 * trace_ust_is_max_id function MUST be called before in order to validate if
146 * the maximum number of IDs have been reached. If not, it is safe to call this
147 * function.
148 *
149 * Return a unique channel ID. If max is reached, the used_channel_id counter
150 * is returned.
151 */
152static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
153{
154 if (trace_ust_is_max_id(s->used_channel_id)) {
155 return s->used_channel_id;
156 }
157
158 s->used_channel_id++;
159 return s->next_channel_id++;
160}
161
162#ifdef HAVE_LIBLTTNG_UST_CTL
163
164int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
165int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
166 const void *_key);
167
168/*
169 * Lookup functions. NULL is returned if not found.
170 */
171struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
172 char *name, struct lttng_filter_bytecode *filter, int loglevel,
173 struct lttng_event_exclusion *exclusion);
174struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
175 char *name);
176struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
177 enum lttng_domain_type domain_type);
178
179/*
180 * Create functions malloc() the data structure.
181 */
182struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
183struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
184 enum lttng_domain_type domain);
185struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
186 char *filter_expression,
187 struct lttng_filter_bytecode *filter,
188 struct lttng_event_exclusion *exclusion,
189 bool internal_event);
190struct ltt_ust_context *trace_ust_create_context(
191 struct lttng_event_context *ctx);
192int trace_ust_match_context(struct ltt_ust_context *uctx,
193 struct lttng_event_context *ctx);
194void trace_ust_delete_channel(struct lttng_ht *ht,
195 struct ltt_ust_channel *channel);
196
197/*
198 * Destroy functions free() the data structure and remove from linked list if
199 * it's applies.
200 */
201void trace_ust_destroy_session(struct ltt_ust_session *session);
202void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
203void trace_ust_destroy_event(struct ltt_ust_event *event);
204
205int trace_ust_track_pid(struct ltt_ust_session *session, int pid);
206int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid);
207
208int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid);
209
210ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
211 int32_t **_pids);
212
213#else /* HAVE_LIBLTTNG_UST_CTL */
214
215static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
216 const void *_key)
217{
218 return 0;
219}
220static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
221 const void *_key)
222{
223 return 0;
224}
225static inline
226struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
227 char *name)
228{
229 return NULL;
230}
231
232static inline
233struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
234{
235 return NULL;
236}
237static inline
238struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
239 enum lttng_domain_type domain)
240{
241 return NULL;
242}
243static inline
244struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
245 const char *filter_expression,
246 struct lttng_filter_bytecode *filter,
247 struct lttng_event_exclusion *exclusion,
248 bool internal_event)
249{
250 return NULL;
251}
252static inline
253void trace_ust_destroy_session(struct ltt_ust_session *session)
254{
255}
256
257static inline
258void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
259{
260}
261
262static inline
263void trace_ust_destroy_event(struct ltt_ust_event *event)
264{
265}
266static inline
267struct ltt_ust_context *trace_ust_create_context(
268 struct lttng_event_context *ctx)
269{
270 return NULL;
271}
272static inline
273int trace_ust_match_context(struct ltt_ust_context *uctx,
274 struct lttng_event_context *ctx)
275{
276 return 0;
277}
278static inline struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
279 char *name, struct lttng_filter_bytecode *filter, int loglevel,
280 struct lttng_event_exclusion *exclusion)
281{
282 return NULL;
283}
284static inline
285void trace_ust_delete_channel(struct lttng_ht *ht,
286 struct ltt_ust_channel *channel)
287{
288 return;
289}
290static inline
291struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
292 enum lttng_domain_type domain_type)
293{
294 return NULL;
295}
296static inline
297int trace_ust_track_pid(struct ltt_ust_session *session, int pid)
298{
299 return 0;
300}
301static inline
302int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid)
303{
304 return 0;
305}
306static inline
307int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid)
308{
309 return 0;
310}
311static inline
312ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
313 int32_t **_pids)
314{
315 return -1;
316}
317#endif /* HAVE_LIBLTTNG_UST_CTL */
318
319#endif /* _LTT_TRACE_UST_H */
This page took 0.025337 seconds and 4 git commands to generate.