trackers: update lttng-sessiond
[deliverable/lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#ifndef _LTT_TRACE_UST_H
20#define _LTT_TRACE_UST_H
21
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 "ust-ctl.h"
31
32struct agent;
33
34struct ltt_ust_ht_key {
35 const char *name;
36 const struct lttng_filter_bytecode *filter;
37 enum lttng_ust_loglevel_type loglevel_type;
38 int loglevel_value;
39 const struct lttng_event_exclusion *exclusion;
40};
41
42/* Context hash table nodes */
43struct ltt_ust_context {
44 struct lttng_ust_context_attr ctx;
45 struct lttng_ht_node_ulong node;
46 struct cds_list_head list;
47};
48
49/* UST event */
50struct ltt_ust_event {
51 unsigned int enabled;
52 struct lttng_ust_event attr;
53 struct lttng_ht_node_str node;
54 char *filter_expression;
55 struct lttng_filter_bytecode *filter;
56 struct lttng_event_exclusion *exclusion;
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 */
63 bool internal;
64};
65
66/* UST channel */
67struct ltt_ust_channel {
68 uint64_t id; /* unique id per session. */
69 unsigned int enabled;
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;
75 char name[LTTNG_UST_SYM_NAME_LEN];
76 struct lttng_ust_channel_attr attr;
77 struct lttng_ht *ctx;
78 struct cds_list_head ctx_list;
79 struct lttng_ht *events;
80 struct lttng_ht_node_str node;
81 uint64_t tracefile_size;
82 uint64_t tracefile_count;
83 uint64_t per_pid_closed_app_discarded;
84 uint64_t per_pid_closed_app_lost;
85 uint64_t monitor_timer_interval;
86};
87
88/* UST domain global (LTTNG_DOMAIN_UST) */
89struct ltt_ust_domain_global {
90 struct lttng_ht *channels;
91 struct cds_list_head registry_buffer_uid_list;
92};
93
94struct ust_id_tracker_node {
95 struct lttng_ht_node_ulong node;
96};
97
98struct ust_id_tracker {
99 struct lttng_ht *ht;
100};
101
102/* UST session */
103struct ltt_ust_session {
104 uint64_t id; /* Unique identifier of session */
105 struct ltt_ust_domain_global domain_global;
106 /* Hash table of agent indexed by agent domain. */
107 struct lttng_ht *agents;
108 /* UID/GID of the user owning the session */
109 uid_t uid;
110 gid_t gid;
111 /* Is the session active meaning has is been started or stopped. */
112 unsigned int active:1;
113 struct consumer_output *consumer;
114 /* Sequence number for filters so the tracer knows the ordering. */
115 uint64_t filter_seq_num;
116 /* This indicates which type of buffer this session is set for. */
117 enum lttng_buffer_type buffer_type;
118 /* If set to 1, the buffer_type can not be changed anymore. */
119 int buffer_type_changed;
120 /* For per UID buffer, every buffer reg object is kept of this session */
121 struct cds_list_head buffer_reg_uid_list;
122 /* Next channel ID available for a newly registered channel. */
123 uint64_t next_channel_id;
124 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
125 uint64_t used_channel_id;
126 /* Tell or not if the session has to output the traces. */
127 unsigned int output_traces;
128 unsigned int snapshot_mode;
129 unsigned int has_non_default_channel;
130 unsigned int live_timer_interval; /* usec */
131
132 /* Metadata channel attributes. */
133 struct lttng_ust_channel_attr metadata_attr;
134
135 /*
136 * Path where to keep the shared memory files.
137 */
138 char root_shm_path[PATH_MAX];
139 char shm_path[PATH_MAX];
140
141 /* Trackers used for actual lookup on app registration. */
142 struct ust_id_tracker vpid_tracker;
143 struct ust_id_tracker vuid_tracker;
144 struct ust_id_tracker vgid_tracker;
145
146 /* Tracker list of keys requested by users. */
147 struct lttng_tracker_list *tracker_list_vpid;
148 struct lttng_tracker_list *tracker_list_vuid;
149 struct lttng_tracker_list *tracker_list_vgid;
150};
151
152/*
153 * Validate that the id has reached the maximum allowed or not.
154 *
155 * Return 0 if NOT else 1.
156 */
157static inline int trace_ust_is_max_id(uint64_t id)
158{
159 return (id == UINT64_MAX) ? 1 : 0;
160}
161
162/*
163 * Return next available channel id and increment the used counter. The
164 * trace_ust_is_max_id function MUST be called before in order to validate if
165 * the maximum number of IDs have been reached. If not, it is safe to call this
166 * function.
167 *
168 * Return a unique channel ID. If max is reached, the used_channel_id counter
169 * is returned.
170 */
171static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
172{
173 if (trace_ust_is_max_id(s->used_channel_id)) {
174 return s->used_channel_id;
175 }
176
177 s->used_channel_id++;
178 return s->next_channel_id++;
179}
180
181#ifdef HAVE_LIBLTTNG_UST_CTL
182
183int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
184int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
185 const void *_key);
186
187/*
188 * Lookup functions. NULL is returned if not found.
189 */
190struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
191 char *name, struct lttng_filter_bytecode *filter,
192 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
193 struct lttng_event_exclusion *exclusion);
194struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
195 char *name);
196struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
197 enum lttng_domain_type domain_type);
198
199/*
200 * Create functions malloc() the data structure.
201 */
202struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
203struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
204 enum lttng_domain_type domain);
205struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
206 char *filter_expression,
207 struct lttng_filter_bytecode *filter,
208 struct lttng_event_exclusion *exclusion,
209 bool internal_event);
210struct ltt_ust_context *trace_ust_create_context(
211 struct lttng_event_context *ctx);
212int trace_ust_match_context(struct ltt_ust_context *uctx,
213 struct lttng_event_context *ctx);
214void trace_ust_delete_channel(struct lttng_ht *ht,
215 struct ltt_ust_channel *channel);
216
217/*
218 * Destroy functions free() the data structure and remove from linked list if
219 * it's applies.
220 */
221void trace_ust_destroy_session(struct ltt_ust_session *session);
222void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
223void trace_ust_destroy_event(struct ltt_ust_event *event);
224void trace_ust_destroy_context(struct ltt_ust_context *ctx);
225
226int trace_ust_track_id(enum lttng_tracker_type tracker_type,
227 struct ltt_ust_session *session,
228 struct lttng_tracker_id *id);
229int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
230 struct ltt_ust_session *session,
231 struct lttng_tracker_id *id);
232
233int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type,
234 struct ltt_ust_session *session, int id);
235
236ssize_t trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
237 struct ltt_ust_session *session,
238 struct lttng_tracker_id **_ids);
239
240#else /* HAVE_LIBLTTNG_UST_CTL */
241
242static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
243 const void *_key)
244{
245 return 0;
246}
247static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
248 const void *_key)
249{
250 return 0;
251}
252static inline
253struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
254 char *name)
255{
256 return NULL;
257}
258
259static inline
260struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
261{
262 return NULL;
263}
264static inline
265struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
266 enum lttng_domain_type domain)
267{
268 return NULL;
269}
270static inline
271struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
272 const char *filter_expression,
273 struct lttng_filter_bytecode *filter,
274 struct lttng_event_exclusion *exclusion,
275 bool internal_event)
276{
277 return NULL;
278}
279static inline
280void trace_ust_destroy_session(struct ltt_ust_session *session)
281{
282}
283
284static inline
285void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
286{
287}
288
289static inline
290void trace_ust_destroy_event(struct ltt_ust_event *event)
291{
292}
293static inline
294struct ltt_ust_context *trace_ust_create_context(
295 struct lttng_event_context *ctx)
296{
297 return NULL;
298}
299static inline
300int trace_ust_match_context(struct ltt_ust_context *uctx,
301 struct lttng_event_context *ctx)
302{
303 return 0;
304}
305static inline
306struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
307 char *name, struct lttng_filter_bytecode *filter,
308 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
309 struct lttng_event_exclusion *exclusion)
310{
311 return NULL;
312}
313static inline
314void trace_ust_delete_channel(struct lttng_ht *ht,
315 struct ltt_ust_channel *channel)
316{
317 return;
318}
319static inline
320struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
321 enum lttng_domain_type domain_type)
322{
323 return NULL;
324}
325static inline
326int trace_ust_track_id(enum lttng_tracker_type tracker_type,
327 struct ltt_ust_session *session, int id)
328{
329 return 0;
330}
331static inline
332int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
333 struct ltt_ust_session *session, int id)
334{
335 return 0;
336}
337static inline
338int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type,
339 struct ltt_ust_session *session, int pid)
340{
341 return 0;
342}
343static inline
344ssize_t trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
345 struct ltt_ust_session *session,
346 struct lttng_tracker_id **_ids)
347{
348 return -1;
349}
350#endif /* HAVE_LIBLTTNG_UST_CTL */
351
352#endif /* _LTT_TRACE_UST_H */
This page took 0.030234 seconds and 5 git commands to generate.