Change the UST event hash table match function
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
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 "ust-ctl.h"
31
32 struct ltt_ust_ht_key {
33 const char *name;
34 const struct lttng_filter_bytecode *filter;
35 enum lttng_ust_loglevel_type loglevel;
36 };
37
38 /* UST Stream list */
39 struct ltt_ust_stream_list {
40 unsigned int count;
41 struct cds_list_head head;
42 };
43
44 /* Context hash table nodes */
45 struct ltt_ust_context {
46 struct lttng_ust_context ctx;
47 struct lttng_ht_node_ulong node;
48 };
49
50 /* UST event */
51 struct ltt_ust_event {
52 unsigned int enabled;
53 struct lttng_ust_event attr;
54 struct lttng_ht_node_str node;
55 struct lttng_ust_filter_bytecode *filter;
56 };
57
58 /* UST stream */
59 struct ltt_ust_stream {
60 int handle;
61 char pathname[PATH_MAX];
62 /* Format is %s_%d respectively channel name and CPU number. */
63 char name[DEFAULT_STREAM_NAME_LEN];
64 struct lttng_ust_object_data *obj;
65 /* Using a list of streams to keep order. */
66 struct cds_list_head list;
67 };
68
69 /* UST channel */
70 struct ltt_ust_channel {
71 unsigned int enabled;
72 char name[LTTNG_UST_SYM_NAME_LEN];
73 char pathname[PATH_MAX];
74 struct lttng_ust_channel attr;
75 struct lttng_ht *ctx;
76 struct lttng_ht *events;
77 struct lttng_ht_node_str node;
78 };
79
80 /* UST Metadata */
81 struct ltt_ust_metadata {
82 int handle;
83 struct lttng_ust_object_data *obj;
84 char pathname[PATH_MAX]; /* Trace file path name */
85 struct lttng_ust_channel attr;
86 struct lttng_ust_object_data *stream_obj;
87 };
88
89 /* UST domain global (LTTNG_DOMAIN_UST) */
90 struct ltt_ust_domain_global {
91 struct lttng_ht *channels;
92 };
93
94 /* UST domain pid (LTTNG_DOMAIN_UST_PID) */
95 struct ltt_ust_domain_pid {
96 pid_t pid;
97 struct lttng_ht *channels;
98 struct lttng_ht_node_ulong node;
99 };
100
101 /* UST domain exec name (LTTNG_DOMAIN_UST_EXEC_NAME) */
102 struct ltt_ust_domain_exec {
103 char exec_name[LTTNG_UST_SYM_NAME_LEN];
104 struct lttng_ht *channels;
105 struct lttng_ht_node_str node;
106 };
107
108 /* UST session */
109 struct ltt_ust_session {
110 int id; /* Unique identifier of session */
111 int start_trace;
112 char pathname[PATH_MAX];
113 struct ltt_ust_domain_global domain_global;
114 /*
115 * Those two hash tables contains data for a specific UST domain and each
116 * contains a HT of channels. See ltt_ust_domain_exec and
117 * ltt_ust_domain_pid data structures.
118 */
119 struct lttng_ht *domain_pid;
120 struct lttng_ht *domain_exec;
121 /* UID/GID of the user owning the session */
122 uid_t uid;
123 gid_t gid;
124 /*
125 * Two consumer_output object are needed where one is for the current
126 * output object and the second one is the temporary object used to store
127 * URI being set by the lttng_set_consumer_uri call. Once
128 * lttng_enable_consumer is called, the two pointers are swapped.
129 */
130 struct consumer_output *consumer;
131 struct consumer_output *tmp_consumer;
132 /* Sequence number for filters so the tracer knows the ordering. */
133 uint64_t filter_seq_num;
134 };
135
136 #ifdef HAVE_LIBLTTNG_UST_CTL
137
138 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
139 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
140 const void *_key);
141
142 /*
143 * Lookup functions. NULL is returned if not found.
144 */
145 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
146 char *name, struct lttng_filter_bytecode *filter, int loglevel);
147 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
148 char *name);
149
150 /*
151 * Create functions malloc() the data structure.
152 */
153 struct ltt_ust_session *trace_ust_create_session(char *path,
154 unsigned int session_id, struct lttng_domain *domain);
155 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
156 char *path);
157 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev);
158 struct ltt_ust_metadata *trace_ust_create_metadata(char *path);
159 struct ltt_ust_context *trace_ust_create_context(
160 struct lttng_event_context *ctx);
161
162 /*
163 * Destroy functions free() the data structure and remove from linked list if
164 * it's applies.
165 */
166 void trace_ust_destroy_session(struct ltt_ust_session *session);
167 void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata);
168 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
169 void trace_ust_destroy_event(struct ltt_ust_event *event);
170
171 #else /* HAVE_LIBLTTNG_UST_CTL */
172
173 static inline
174 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
175 char *name)
176 {
177 return NULL;
178 }
179
180 static inline
181 struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid,
182 struct lttng_domain *domain)
183 {
184 return NULL;
185 }
186 static inline
187 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
188 char *path)
189 {
190 return NULL;
191 }
192 static inline
193 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev)
194 {
195 return NULL;
196 }
197 static inline
198 struct ltt_ust_metadata *trace_ust_create_metadata(char *path)
199 {
200 return NULL;
201 }
202
203 static inline
204 void trace_ust_destroy_session(struct ltt_ust_session *session)
205 {
206 }
207
208 static inline
209 void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata)
210 {
211 }
212
213 static inline
214 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
215 {
216 }
217
218 static inline
219 void trace_ust_destroy_event(struct ltt_ust_event *event)
220 {
221 }
222 static inline
223 struct ltt_ust_context *trace_ust_create_context(
224 struct lttng_event_context *ctx)
225 {
226 return NULL;
227 }
228
229 #endif /* HAVE_LIBLTTNG_UST_CTL */
230
231 #endif /* _LTT_TRACE_UST_H */
This page took 0.049158 seconds and 4 git commands to generate.