Commit | Line | Data |
---|---|---|
54012638 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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. | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | #include <urcu/list.h> | |
24 | ||
25 | #include "ltt-sessiond.h" | |
26 | #include "trace.h" | |
27 | ||
28 | /* | |
29 | * trace_create_kernel_session | |
30 | * | |
31 | * Allocate and initialize a kernel session data structure. | |
32 | * | |
33 | * Return pointer to structure or NULL. | |
34 | */ | |
35 | struct ltt_kernel_session *trace_create_kernel_session(void) | |
36 | { | |
37 | struct ltt_kernel_session *lks; | |
38 | ||
39 | /* Allocate a new ltt kernel session */ | |
40 | lks = malloc(sizeof(struct ltt_kernel_session)); | |
41 | if (lks == NULL) { | |
42 | perror("create kernel session malloc"); | |
43 | goto error; | |
44 | } | |
45 | ||
46 | /* Init data structure */ | |
47 | lks->fd = 0; | |
48 | lks->metadata_stream_fd = 0; | |
49 | lks->channel_count = 0; | |
50 | lks->stream_count_global = 0; | |
51 | lks->metadata = NULL; | |
52 | CDS_INIT_LIST_HEAD(&lks->channel_list.head); | |
53 | ||
54 | return lks; | |
55 | ||
56 | error: | |
57 | return NULL; | |
58 | } | |
59 | ||
60 | /* | |
61 | * trace_create_kernel_channel | |
62 | * | |
63 | * Allocate and initialize a kernel channel data structure. | |
64 | * | |
65 | * Return pointer to structure or NULL. | |
66 | */ | |
67 | struct ltt_kernel_channel *trace_create_kernel_channel(void) | |
68 | { | |
69 | int ret; | |
70 | struct ltt_kernel_channel *lkc; | |
71 | struct lttng_kernel_channel *chan; | |
72 | ||
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"); | |
77 | goto error; | |
78 | } | |
79 | ||
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; | |
86 | ||
87 | lkc->fd = 0; | |
88 | lkc->stream_count = 0; | |
89 | lkc->channel = chan; | |
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); | |
95 | if (ret < 0) { | |
96 | perror("asprintf kernel create channel"); | |
97 | goto error; | |
98 | } | |
99 | ||
100 | return lkc; | |
101 | ||
102 | error: | |
103 | return NULL; | |
104 | } | |
105 | ||
106 | /* | |
107 | * trace_create_kernel_event | |
108 | * | |
109 | * Allocate and initialize a kernel event. Set name and event type. | |
110 | * | |
111 | * Return pointer to structure or NULL. | |
112 | */ | |
113 | struct ltt_kernel_event *trace_create_kernel_event(char *name, | |
114 | enum lttng_kernel_instrumentation type) | |
115 | { | |
116 | struct ltt_kernel_event *lke; | |
117 | struct lttng_kernel_event *attr; | |
118 | ||
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"); | |
123 | goto error; | |
124 | } | |
125 | ||
126 | /* Init event attribute */ | |
127 | attr->instrumentation = type; | |
128 | strncpy(attr->name, name, LTTNG_SYM_NAME_LEN); | |
129 | /* Setting up a kernel event */ | |
130 | lke->fd = 0; | |
131 | lke->event = attr; | |
132 | ||
133 | return lke; | |
134 | ||
135 | error: | |
136 | return NULL; | |
137 | } | |
138 | ||
139 | /* | |
140 | * trace_create_kernel_metadata | |
141 | * | |
142 | * Allocate and initialize a kernel metadata. | |
143 | * | |
144 | * Return pointer to structure or NULL. | |
145 | */ | |
146 | struct ltt_kernel_metadata *trace_create_kernel_metadata(void) | |
147 | { | |
148 | int ret; | |
149 | struct ltt_kernel_metadata *lkm; | |
150 | struct lttng_kernel_channel *attr; | |
151 | ||
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"); | |
156 | goto error; | |
157 | } | |
158 | ||
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; | |
165 | ||
166 | /* Init metadata */ | |
167 | lkm->fd = 0; | |
168 | lkm->conf = attr; | |
169 | /* Set default metadata path */ | |
170 | ret = asprintf(&lkm->pathname, "%s/metadata", DEFAULT_TRACE_OUTPUT); | |
171 | if (ret < 0) { | |
172 | perror("asprintf kernel metadata"); | |
173 | goto error; | |
174 | } | |
175 | ||
176 | return lkm; | |
177 | ||
178 | error: | |
179 | return NULL; | |
180 | } | |
181 | ||
182 | /* | |
183 | * trace_create_kernel_stream | |
184 | * | |
185 | * Allocate and initialize a kernel stream. The stream is set to ACTIVE_FD by | |
186 | * default. | |
187 | * | |
188 | * Return pointer to structure or NULL. | |
189 | */ | |
190 | struct ltt_kernel_stream *trace_create_kernel_stream(void) | |
191 | { | |
192 | struct ltt_kernel_stream *lks; | |
193 | ||
194 | lks = malloc(sizeof(struct ltt_kernel_stream)); | |
195 | if (lks == NULL) { | |
196 | perror("kernel stream malloc"); | |
197 | goto error; | |
198 | } | |
199 | ||
200 | /* Init stream */ | |
201 | lks->fd = 0; | |
202 | lks->pathname = NULL; | |
203 | lks->state = 0; | |
204 | ||
205 | return lks; | |
206 | ||
207 | error: | |
208 | return NULL; | |
209 | } |