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.
23 #include <urcu/list.h>
25 #include "ltt-sessiond.h"
29 * trace_create_kernel_session
31 * Allocate and initialize a kernel session data structure.
33 * Return pointer to structure or NULL.
35 struct ltt_kernel_session
*trace_create_kernel_session(void)
37 struct ltt_kernel_session
*lks
;
39 /* Allocate a new ltt kernel session */
40 lks
= malloc(sizeof(struct ltt_kernel_session
));
42 perror("create kernel session malloc");
46 /* Init data structure */
48 lks
->metadata_stream_fd
= 0;
49 lks
->channel_count
= 0;
50 lks
->stream_count_global
= 0;
52 CDS_INIT_LIST_HEAD(&lks
->channel_list
.head
);
61 * trace_create_kernel_channel
63 * Allocate and initialize a kernel channel data structure.
65 * Return pointer to structure or NULL.
67 struct ltt_kernel_channel
*trace_create_kernel_channel(void)
70 struct ltt_kernel_channel
*lkc
;
71 struct lttng_kernel_channel
*chan
;
73 lkc
= malloc(sizeof(struct ltt_kernel_channel
));
74 chan
= malloc(sizeof(struct lttng_kernel_channel
));
75 if (lkc
== NULL
|| chan
== NULL
) {
76 perror("kernel channel malloc");
80 /* Default value to channel */
81 chan
->overwrite
= DEFAULT_KERNEL_OVERWRITE
;
82 chan
->subbuf_size
= DEFAULT_KERNEL_SUBBUF_SIZE
;
83 chan
->num_subbuf
= DEFAULT_KERNEL_SUBBUF_NUM
;
84 chan
->switch_timer_interval
= DEFAULT_KERNEL_SWITCH_TIMER
;
85 chan
->read_timer_interval
= DEFAULT_KERNEL_READ_TIMER
;
88 lkc
->stream_count
= 0;
90 /* Init linked list */
91 CDS_INIT_LIST_HEAD(&lkc
->events_list
.head
);
92 CDS_INIT_LIST_HEAD(&lkc
->stream_list
.head
);
93 /* Set default trace output path */
94 ret
= asprintf(&lkc
->pathname
, "%s", DEFAULT_TRACE_OUTPUT
);
96 perror("asprintf kernel create channel");
107 * trace_create_kernel_event
109 * Allocate and initialize a kernel event. Set name and event type.
111 * Return pointer to structure or NULL.
113 struct ltt_kernel_event
*trace_create_kernel_event(char *name
,
114 enum lttng_kernel_instrumentation type
)
116 struct ltt_kernel_event
*lke
;
117 struct lttng_kernel_event
*attr
;
119 lke
= malloc(sizeof(struct ltt_kernel_event
));
120 attr
= malloc(sizeof(struct lttng_kernel_event
));
121 if (lke
== NULL
|| attr
== NULL
) {
122 perror("kernel event malloc");
126 /* Init event attribute */
127 attr
->instrumentation
= type
;
128 strncpy(attr
->name
, name
, LTTNG_SYM_NAME_LEN
);
129 /* Setting up a kernel event */
140 * trace_create_kernel_metadata
142 * Allocate and initialize a kernel metadata.
144 * Return pointer to structure or NULL.
146 struct ltt_kernel_metadata
*trace_create_kernel_metadata(void)
149 struct ltt_kernel_metadata
*lkm
;
150 struct lttng_kernel_channel
*attr
;
152 lkm
= malloc(sizeof(struct ltt_kernel_metadata
));
153 attr
= malloc(sizeof(struct lttng_kernel_channel
));
154 if (lkm
== NULL
|| attr
== NULL
) {
155 perror("kernel metadata malloc");
159 /* Set default attributes */
160 attr
->overwrite
= DEFAULT_KERNEL_OVERWRITE
;
161 attr
->subbuf_size
= DEFAULT_KERNEL_SUBBUF_SIZE
;
162 attr
->num_subbuf
= DEFAULT_KERNEL_SUBBUF_NUM
;
163 attr
->switch_timer_interval
= DEFAULT_KERNEL_SWITCH_TIMER
;
164 attr
->read_timer_interval
= DEFAULT_KERNEL_READ_TIMER
;
169 /* Set default metadata path */
170 ret
= asprintf(&lkm
->pathname
, "%s/metadata", DEFAULT_TRACE_OUTPUT
);
172 perror("asprintf kernel metadata");
183 * trace_create_kernel_stream
185 * Allocate and initialize a kernel stream. The stream is set to ACTIVE_FD by
188 * Return pointer to structure or NULL.
190 struct ltt_kernel_stream
*trace_create_kernel_stream(void)
192 struct ltt_kernel_stream
*lks
;
194 lks
= malloc(sizeof(struct ltt_kernel_stream
));
196 perror("kernel stream malloc");
202 lks
->pathname
= NULL
;