2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <urcu/list.h>
26 #include "ltt-sessiond.h"
30 * trace_create_kernel_session
32 * Allocate and initialize a kernel session data structure.
34 * Return pointer to structure or NULL.
36 struct ltt_kernel_session
*trace_create_kernel_session(void)
38 struct ltt_kernel_session
*lks
;
40 /* Allocate a new ltt kernel session */
41 lks
= malloc(sizeof(struct ltt_kernel_session
));
43 perror("create kernel session malloc");
47 /* Init data structure */
49 lks
->metadata_stream_fd
= 0;
50 lks
->channel_count
= 0;
51 lks
->stream_count_global
= 0;
53 CDS_INIT_LIST_HEAD(&lks
->channel_list
.head
);
62 * trace_create_kernel_channel
64 * Allocate and initialize a kernel channel data structure.
66 * Return pointer to structure or NULL.
68 struct ltt_kernel_channel
*trace_create_kernel_channel(void)
71 struct ltt_kernel_channel
*lkc
;
72 struct lttng_kernel_channel
*chan
;
74 lkc
= malloc(sizeof(struct ltt_kernel_channel
));
75 chan
= malloc(sizeof(struct lttng_kernel_channel
));
76 if (lkc
== NULL
|| chan
== NULL
) {
77 perror("kernel channel malloc");
81 /* Default value to channel */
82 chan
->overwrite
= DEFAULT_KERNEL_OVERWRITE
;
83 chan
->subbuf_size
= DEFAULT_KERNEL_SUBBUF_SIZE
;
84 chan
->num_subbuf
= DEFAULT_KERNEL_SUBBUF_NUM
;
85 chan
->switch_timer_interval
= DEFAULT_KERNEL_SWITCH_TIMER
;
86 chan
->read_timer_interval
= DEFAULT_KERNEL_READ_TIMER
;
89 lkc
->stream_count
= 0;
91 /* Init linked list */
92 CDS_INIT_LIST_HEAD(&lkc
->events_list
.head
);
93 CDS_INIT_LIST_HEAD(&lkc
->stream_list
.head
);
94 /* Set default trace output path */
95 ret
= asprintf(&lkc
->pathname
, "%s", DEFAULT_TRACE_OUTPUT
);
97 perror("asprintf kernel create channel");
108 * trace_create_kernel_event
110 * Allocate and initialize a kernel event. Set name and event type.
112 * Return pointer to structure or NULL.
114 struct ltt_kernel_event
*trace_create_kernel_event(char *name
,
115 enum lttng_kernel_instrumentation type
)
117 struct ltt_kernel_event
*lke
;
118 struct lttng_kernel_event
*attr
;
120 lke
= malloc(sizeof(struct ltt_kernel_event
));
121 attr
= malloc(sizeof(struct lttng_kernel_event
));
122 if (lke
== NULL
|| attr
== NULL
) {
123 perror("kernel event malloc");
127 /* Init event attribute */
128 attr
->instrumentation
= type
;
129 strncpy(attr
->name
, name
, LTTNG_SYM_NAME_LEN
);
130 /* Setting up a kernel event */
141 * trace_create_kernel_metadata
143 * Allocate and initialize a kernel metadata.
145 * Return pointer to structure or NULL.
147 struct ltt_kernel_metadata
*trace_create_kernel_metadata(void)
150 struct ltt_kernel_metadata
*lkm
;
151 struct lttng_kernel_channel
*attr
;
153 lkm
= malloc(sizeof(struct ltt_kernel_metadata
));
154 attr
= malloc(sizeof(struct lttng_kernel_channel
));
155 if (lkm
== NULL
|| attr
== NULL
) {
156 perror("kernel metadata malloc");
160 /* Set default attributes */
161 attr
->overwrite
= DEFAULT_KERNEL_OVERWRITE
;
162 attr
->subbuf_size
= DEFAULT_KERNEL_SUBBUF_SIZE
;
163 attr
->num_subbuf
= DEFAULT_KERNEL_SUBBUF_NUM
;
164 attr
->switch_timer_interval
= DEFAULT_KERNEL_SWITCH_TIMER
;
165 attr
->read_timer_interval
= DEFAULT_KERNEL_READ_TIMER
;
170 /* Set default metadata path */
171 ret
= asprintf(&lkm
->pathname
, "%s/metadata", DEFAULT_TRACE_OUTPUT
);
173 perror("asprintf kernel metadata");
184 * trace_create_kernel_stream
186 * Allocate and initialize a kernel stream. The stream is set to ACTIVE_FD by
189 * Return pointer to structure or NULL.
191 struct ltt_kernel_stream
*trace_create_kernel_stream(void)
193 struct ltt_kernel_stream
*lks
;
195 lks
= malloc(sizeof(struct ltt_kernel_stream
));
197 perror("kernel stream malloc");
203 lks
->pathname
= NULL
;
212 void trace_destroy_kernel_stream(struct ltt_kernel_stream
*stream
)
214 /* Close kernel fd */
216 free(stream
->pathname
);
218 /* Remove from stream list */
219 cds_list_del(&stream
->list
);
223 void trace_destroy_kernel_event(struct ltt_kernel_event
*event
)
225 /* Close kernel fd */
227 /* Free attributes */
230 /* Remove from event list */
231 cds_list_del(&event
->list
);
235 void trace_destroy_kernel_channel(struct ltt_kernel_channel
*channel
)
237 struct ltt_kernel_stream
*stream
;
238 struct ltt_kernel_event
*event
;
240 /* Close kernel fd */
242 free(channel
->pathname
);
243 /* Free attributes structure */
244 free(channel
->channel
);
246 /* For each stream in the channel list */
247 cds_list_for_each_entry(stream
, &channel
->stream_list
.head
, list
) {
248 trace_destroy_kernel_stream(stream
);
251 /* For each event in the channel list */
252 cds_list_for_each_entry(event
, &channel
->events_list
.head
, list
) {
253 trace_destroy_kernel_event(event
);
256 /* Remove from channel list */
257 cds_list_del(&channel
->list
);
261 void trace_destroy_kernel_metadata(struct ltt_kernel_metadata
*metadata
)
263 /* Close kernel fd */
265 /* Free attributes */
266 free(metadata
->conf
);
271 void trace_destroy_kernel_session(struct ltt_kernel_session
*session
)
273 struct ltt_kernel_channel
*channel
;
275 /* Close kernel fds */
277 close(session
->metadata_stream_fd
);
279 trace_destroy_kernel_metadata(session
->metadata
);
281 cds_list_for_each_entry(channel
, &session
->channel_list
.head
, list
) {
282 trace_destroy_kernel_channel(channel
);