2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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.
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.
18 #ifndef _LTT_TRACE_UST_H
19 #define _LTT_TRACE_UST_H
23 #include <urcu/list.h>
25 #include <lttng/lttng.h>
26 #include <common/hashtable/hashtable.h>
27 #include <common/defaults.h>
32 struct ltt_ust_ht_key
{
34 const struct lttng_filter_bytecode
*filter
;
35 enum lttng_ust_loglevel_type loglevel
;
39 struct ltt_ust_stream_list
{
41 struct cds_list_head head
;
44 /* Context hash table nodes */
45 struct ltt_ust_context
{
46 struct lttng_ust_context ctx
;
47 struct lttng_ht_node_ulong node
;
51 struct ltt_ust_event
{
53 struct lttng_ust_event attr
;
54 struct lttng_ht_node_str node
;
55 struct lttng_ust_filter_bytecode
*filter
;
59 struct ltt_ust_stream
{
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
;
70 struct ltt_ust_channel
{
72 char name
[LTTNG_UST_SYM_NAME_LEN
];
73 char pathname
[PATH_MAX
];
74 struct lttng_ust_channel attr
;
76 struct lttng_ht
*events
;
77 struct lttng_ht_node_str node
;
81 struct ltt_ust_metadata
{
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
;
89 /* UST domain global (LTTNG_DOMAIN_UST) */
90 struct ltt_ust_domain_global
{
91 struct lttng_ht
*channels
;
94 /* UST domain pid (LTTNG_DOMAIN_UST_PID) */
95 struct ltt_ust_domain_pid
{
97 struct lttng_ht
*channels
;
98 struct lttng_ht_node_ulong node
;
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
;
109 struct ltt_ust_session
{
110 int id
; /* Unique identifier of session */
112 char pathname
[PATH_MAX
];
113 struct ltt_ust_domain_global domain_global
;
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.
119 struct lttng_ht
*domain_pid
;
120 struct lttng_ht
*domain_exec
;
121 /* UID/GID of the user owning the session */
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.
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
;
136 #ifdef HAVE_LIBLTTNG_UST_CTL
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
,
143 * Lookup functions. NULL is returned if not found.
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
,
151 * Create functions malloc() the data structure.
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
,
157 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
,
158 struct lttng_filter_bytecode
*filter
);
159 struct ltt_ust_metadata
*trace_ust_create_metadata(char *path
);
160 struct ltt_ust_context
*trace_ust_create_context(
161 struct lttng_event_context
*ctx
);
164 * Destroy functions free() the data structure and remove from linked list if
167 void trace_ust_destroy_session(struct ltt_ust_session
*session
);
168 void trace_ust_destroy_metadata(struct ltt_ust_metadata
*metadata
);
169 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
);
170 void trace_ust_destroy_event(struct ltt_ust_event
*event
);
172 #else /* HAVE_LIBLTTNG_UST_CTL */
174 static inline int trace_ust_ht_match_event(struct cds_lfht_node
*node
,
179 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
185 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
192 struct ltt_ust_session
*trace_ust_create_session(char *path
, pid_t pid
,
193 struct lttng_domain
*domain
)
198 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
204 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
,
205 struct lttng_filter_bytecode
*filter
)
210 struct ltt_ust_metadata
*trace_ust_create_metadata(char *path
)
216 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
221 void trace_ust_destroy_metadata(struct ltt_ust_metadata
*metadata
)
226 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
231 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
235 struct ltt_ust_context
*trace_ust_create_context(
236 struct lttng_event_context
*ctx
)
240 static inline struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
241 char *name
, struct lttng_filter_bytecode
*filter
, int loglevel
)
246 #endif /* HAVE_LIBLTTNG_UST_CTL */
248 #endif /* _LTT_TRACE_UST_H */