2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <lttng-share.h>
27 #include "trace-ust.h"
30 * Find the channel name for the given ust session.
32 struct ltt_ust_channel
*trace_ust_get_channel_by_name(
33 char *name
, struct ltt_ust_session
*session
)
35 struct ltt_ust_channel
*chan
;
37 if (session
== NULL
) {
38 ERR("Undefine session");
42 cds_list_for_each_entry(chan
, &session
->channels
.head
, list
) {
43 if (strcmp(name
, chan
->name
) == 0) {
44 DBG("Found UST channel by name %s", name
);
54 * Find the event name for the given channel.
56 struct ltt_ust_event
*trace_ust_get_event_by_name(
57 char *name
, struct ltt_ust_channel
*channel
)
59 struct ltt_ust_event
*ev
;
61 if (channel
== NULL
) {
62 ERR("Undefine channel");
66 cds_list_for_each_entry(ev
, &channel
->events
.head
, list
) {
67 if (strcmp(name
, ev
->event
->name
) == 0) {
68 DBG("Found UST event by name %s for channel %s", name
,
79 * Allocate and initialize a ust session data structure.
81 * Return pointer to structure or NULL.
83 struct ltt_ust_session
*trace_ust_create_session(void)
85 struct ltt_ust_session
*lus
;
87 /* Allocate a new ltt ust session */
88 lus
= malloc(sizeof(struct ltt_ust_session
));
90 perror("create ust session malloc");
94 /* Init data structure */
97 lus
->uconsumer_fds_sent
= 0;
100 lus
->channels
.count
= 0;
101 CDS_INIT_LIST_HEAD(&lus
->channels
.head
);
110 * Allocate and initialize a ust channel data structure.
112 * Return pointer to structure or NULL.
114 struct ltt_ust_channel
*trace_ust_create_channel(char *name
, char *path
,
115 struct lttng_ust_channel
*chan
)
118 struct ltt_ust_channel
*luc
;
120 luc
= malloc(sizeof(struct ltt_ust_channel
));
122 perror("ltt_ust_channel malloc");
126 luc
->attr
= malloc(sizeof(struct lttng_ust_channel
));
127 if (luc
->attr
== NULL
) {
128 perror("lttng_ust_channel malloc");
131 memcpy(luc
->attr
, chan
, sizeof(struct lttng_ust_channel
));
136 luc
->events
.count
= 0;
137 CDS_INIT_LIST_HEAD(&luc
->events
.head
);
139 /* Copy channel name */
140 strncpy(luc
->name
, name
, LTTNG_UST_SYM_NAME_LEN
);
141 luc
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
143 /* Set trace output path */
144 ret
= asprintf(&luc
->trace_path
, "%s", path
);
146 perror("asprintf ust create channel");
157 * Allocate and initialize a ust event. Set name and event type.
159 * Return pointer to structure or NULL.
161 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
)
163 struct ltt_ust_event
*lue
;
164 struct lttng_ust_event
*event
;
166 lue
= malloc(sizeof(struct ltt_ust_event
));
167 event
= malloc(sizeof(struct lttng_ust_event
));
168 if (lue
== NULL
|| event
== NULL
) {
169 perror("ust event malloc");
174 case LTTNG_EVENT_PROBE
:
175 event
->instrumentation
= LTTNG_UST_PROBE
;
177 case LTTNG_EVENT_FUNCTION
:
178 event
->instrumentation
= LTTNG_UST_FUNCTION
;
180 case LTTNG_EVENT_FUNCTION_ENTRY
:
181 event
->instrumentation
= LTTNG_UST_FUNCTION
;
183 case LTTNG_EVENT_TRACEPOINT
:
184 event
->instrumentation
= LTTNG_UST_TRACEPOINT
;
187 ERR("Unknown ust instrumentation type (%d)", ev
->type
);
191 /* Copy event name */
192 strncpy(event
->name
, ev
->name
, LTTNG_UST_SYM_NAME_LEN
);
193 event
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
195 /* Setting up a ust event */
208 * Allocate and initialize a ust metadata.
210 * Return pointer to structure or NULL.
212 struct ltt_ust_metadata
*trace_ust_create_metadata(char *path
)
215 struct ltt_ust_metadata
*lum
;
216 struct lttng_ust_channel
*attr
;
218 lum
= malloc(sizeof(struct ltt_ust_metadata
));
219 attr
= malloc(sizeof(struct lttng_ust_channel
));
220 if (lum
== NULL
|| attr
== NULL
) {
221 perror("ust metadata malloc");
225 /* Set default attributes */
226 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
227 attr
->subbuf_size
= DEFAULT_METADATA_SUBBUF_SIZE
;
228 attr
->num_subbuf
= DEFAULT_METADATA_SUBBUF_NUM
;
229 attr
->switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
230 attr
->read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
231 attr
->output
= DEFAULT_UST_CHANNEL_OUTPUT
;
235 /* Set metadata trace path */
236 ret
= asprintf(&lum
->trace_path
, "%s/metadata", path
);
238 perror("asprintf ust metadata");
249 * Cleanup ust event structure.
251 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
253 DBG("[trace] Destroy ust event %s", event
->event
->name
);
255 /* Free attributes */
259 /* Remove from event list */
260 cds_list_del(&event
->list
);
265 * Cleanup ust channel structure.
267 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
269 struct ltt_ust_event
*event
, *etmp
;
271 DBG("[trace] Destroy ust channel %d", channel
->handle
);
273 free(channel
->trace_path
);
274 /* Free attributes structure */
278 /* For each event in the channel list */
279 cds_list_for_each_entry_safe(event
, etmp
, &channel
->events
.head
, list
) {
280 trace_ust_destroy_event(event
);
283 /* Remove from channel list */
284 cds_list_del(&channel
->list
);
289 * Cleanup ust metadata structure.
291 void trace_ust_destroy_metadata(struct ltt_ust_metadata
*metadata
)
293 DBG("[trace] Destroy ust metadata %d", metadata
->handle
);
295 /* Free attributes */
296 free(metadata
->attr
);
297 free(metadata
->trace_path
);
303 * Cleanup ust session structure
305 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
307 struct ltt_ust_channel
*channel
, *ctmp
;
309 DBG("[trace] Destroy ust session %d", session
->handle
);
312 if (session
== NULL
) {
316 if (session
->metadata
!= NULL
) {
317 trace_ust_destroy_metadata(session
->metadata
);
320 cds_list_for_each_entry_safe(channel
, ctmp
, &session
->channels
.head
, list
) {
321 trace_ust_destroy_channel(channel
);