ad14afbb358a42f50dd911b44c9a04ce4b94e5f4
[lttng-tools.git] / tests / ust / ust_global_event_basic.c
1 /*
2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #define _GNU_SOURCE
20 #include <assert.h>
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <time.h>
27
28 #include <lttng/lttng.h>
29
30 #include "../utils.h"
31
32 int lttng_opt_quiet;
33
34 int main(int argc, char **argv)
35 {
36 struct lttng_handle *handle = NULL;
37 struct lttng_domain dom;
38 struct lttng_channel channel, channel2;
39 struct lttng_event ev1, ev2, ev3;
40 struct lttng_event_context context;
41 char *session_name = "ust_global_event_basic";
42 char *session_name2 = "ust_global_event_basic2";
43 int ret = 0;
44
45 memset(&dom, 0, sizeof(dom));
46 memset(&channel, 0, sizeof(channel));
47 memset(&channel2, 0, sizeof(channel2));
48 memset(&ev1, 0, sizeof(ev1));
49 memset(&ev2, 0, sizeof(ev2));
50 memset(&ev3, 0, sizeof(ev3));
51 memset(&context, 0, sizeof(context));
52
53 dom.type = LTTNG_DOMAIN_UST;
54
55 /* Setup channel 1 */
56 strcpy(channel.name, "mychan");
57 channel.attr.overwrite = 0;
58 channel.attr.subbuf_size = 4096;
59 channel.attr.num_subbuf = 4;
60 channel.attr.switch_timer_interval = 0;
61 channel.attr.read_timer_interval = 200;
62 channel.attr.output = LTTNG_EVENT_MMAP;
63
64 /* Setup channel 2 */
65 strcpy(channel2.name, "mychan2");
66 channel2.attr.overwrite = 0;
67 channel2.attr.subbuf_size = 8192;
68 channel2.attr.num_subbuf = 8;
69 channel2.attr.switch_timer_interval = 0;
70 channel2.attr.read_timer_interval = 500;
71 channel2.attr.output = LTTNG_EVENT_MMAP;
72
73 strcpy(ev1.name, "tp1");
74 ev1.type = LTTNG_EVENT_TRACEPOINT;
75 ev1.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
76
77 strcpy(ev2.name, "ev2");
78 ev2.type = LTTNG_EVENT_TRACEPOINT;
79 ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
80
81 strcpy(ev3.name, "ev3");
82 ev3.type = LTTNG_EVENT_TRACEPOINT;
83 ev3.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
84
85 printf("\nTesting tracing UST events:\n");
86 printf("-----------\n");
87
88 if (argc < 2) {
89 printf("Missing session trace path\n");
90 return 1;
91 }
92
93 printf("Creating tracing session (%s): ", argv[1]);
94 if ((ret = lttng_create_session(session_name, argv[1])) < 0) {
95 printf("error creating the session : %s\n", lttng_strerror(ret));
96 goto create_fail;
97 }
98 PRINT_OK();
99
100 printf("Creating tracing session 2 (%s): ", argv[1]);
101 if ((ret = lttng_create_session(session_name2, argv[1])) < 0) {
102 printf("error creating the session : %s\n", lttng_strerror(ret));
103 goto create_fail;
104 }
105 PRINT_OK();
106
107 printf("Creating session handle: ");
108 if ((handle = lttng_create_handle(session_name, &dom)) == NULL) {
109 printf("error creating handle: %s\n", lttng_strerror(ret));
110 goto handle_fail;
111 }
112 PRINT_OK();
113
114 printf("Enabling %s UST channel: ", channel.name);
115 if ((ret = lttng_enable_channel(handle, &channel)) < 0) {
116 printf("error enable channel: %s\n", lttng_strerror(ret));
117 goto enable_fail;
118 }
119 PRINT_OK();
120
121 printf("Enabling %s UST channel2: ", channel2.name);
122 if ((ret = lttng_enable_channel(handle, &channel2)) < 0) {
123 printf("error enable channel: %s\n", lttng_strerror(ret));
124 goto enable_fail;
125 }
126 PRINT_OK();
127
128 printf("Enabling %s UST event in channel %s: ", ev1.name, channel.name);
129 if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) {
130 printf("error enabling event: %s\n", lttng_strerror(ret));
131 goto enable_fail;
132 }
133 PRINT_OK();
134
135 printf("Enabling %s UST event in channel %s: ", ev2.name, channel.name);
136 if ((ret = lttng_enable_event(handle, &ev2, channel.name)) < 0) {
137 printf("error enabling event: %s\n", lttng_strerror(ret));
138 goto enable_fail;
139 }
140 PRINT_OK();
141
142 printf("Enabling %s UST event in channel %s: ", ev3.name, channel2.name);
143 if ((ret = lttng_enable_event(handle, &ev3, channel2.name)) < 0) {
144 printf("error enabling event: %s\n", lttng_strerror(ret));
145 goto enable_fail;
146 }
147 PRINT_OK();
148
149 context.ctx = LTTNG_EVENT_CONTEXT_VPID;
150
151 printf("Adding context VPID to UST event %s in channel %s: ", ev1.name,
152 channel.name);
153 if ((ret = lttng_add_context(handle, &context, ev1.name,
154 channel.name)) < 0) {
155 printf("error adding context VPID: %s\n", lttng_strerror(ret));
156 goto context_fail;
157 }
158 PRINT_OK();
159
160 context.ctx = LTTNG_EVENT_CONTEXT_VTID;
161
162 printf("Adding context VTID to UST event %s in channel %s: ", ev1.name,
163 channel.name);
164 if ((ret = lttng_add_context(handle, &context, ev1.name,
165 channel.name)) < 0) {
166 printf("error adding context VTID: %s\n", lttng_strerror(ret));
167 goto context_fail;
168 }
169 PRINT_OK();
170
171 context.ctx = LTTNG_EVENT_CONTEXT_PTHREAD_ID;
172
173 printf("Adding context PTHREAD_ID to UST event %s in channel %s: ",
174 ev1.name, channel.name);
175 if ((ret = lttng_add_context(handle, &context, ev1.name,
176 channel.name)) < 0) {
177 printf("error adding context PTHREAD_ID: %s\n", lttng_strerror(ret));
178 goto context_fail;
179 }
180 PRINT_OK();
181
182 context.ctx = LTTNG_EVENT_CONTEXT_PROCNAME;
183
184 printf("Adding context PROCNAME to UST event %s in channel %s: ",
185 ev1.name, channel.name);
186 if ((ret = lttng_add_context(handle, &context, ev1.name,
187 channel.name)) < 0) {
188 printf("error adding context PROCNAME: %s\n", lttng_strerror(ret));
189 goto context_fail;
190 }
191 PRINT_OK();
192
193 context.ctx = LTTNG_EVENT_CONTEXT_PROCNAME;
194
195 printf("Adding context PROCNAME to UST event %s in channel %s: ",
196 ev3.name, channel2.name);
197 if ((ret = lttng_add_context(handle, &context, ev3.name,
198 channel2.name)) < 0) {
199 printf("error adding context PROCNAME: %s\n", lttng_strerror(ret));
200 goto context_fail;
201 }
202 PRINT_OK();
203
204 printf("Disabling %s UST event: ", ev1.name);
205 if ((ret = lttng_disable_event(handle, ev1.name, channel.name)) < 0) {
206 printf("error enabling event: %s\n", lttng_strerror(ret));
207 goto enable_fail;
208 }
209 PRINT_OK();
210
211 printf("Disabling %s UST event: ", ev3.name);
212 if ((ret = lttng_disable_event(handle, ev3.name, channel2.name)) < 0) {
213 printf("error enabling event: %s\n", lttng_strerror(ret));
214 goto enable_fail;
215 }
216 PRINT_OK();
217
218 printf("Renabling %s UST event: ", ev1.name);
219 if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) {
220 printf("error enabling event: %s\n", lttng_strerror(ret));
221 goto enable_fail;
222 }
223 PRINT_OK();
224
225 printf("Renabling %s UST event: ", ev3.name);
226 if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) {
227 printf("error enabling event: %s\n", lttng_strerror(ret));
228 goto enable_fail;
229 }
230 PRINT_OK();
231
232 printf("Disabling channel %s: ", channel2.name);
233 if ((ret = lttng_disable_channel(handle, channel2.name)) < 0) {
234 printf("error disabling channel: %s\n", lttng_strerror(ret));
235 goto enable_fail;
236 }
237 PRINT_OK();
238
239 printf("Start tracing: ");
240 if ((ret = lttng_start_tracing(session_name)) < 0) {
241 printf("error starting tracing: %s\n", lttng_strerror(ret));
242 goto start_fail;
243 }
244 PRINT_OK();
245
246 sleep(2);
247
248 printf("Stop tracing: ");
249 if ((ret = lttng_stop_tracing(session_name)) < 0) {
250 printf("error stopping tracing: %s\n", lttng_strerror(ret));
251 goto stop_fail;
252 }
253 PRINT_OK();
254
255 printf("Restart tracing: ");
256 if ((ret = lttng_start_tracing(session_name)) < 0) {
257 printf("error starting tracing: %s\n", lttng_strerror(ret));
258 goto start_fail;
259 }
260 PRINT_OK();
261
262 sleep(2);
263
264 printf("Stop tracing: ");
265 if ((ret = lttng_stop_tracing(session_name)) < 0) {
266 printf("error stopping tracing: %s\n", lttng_strerror(ret));
267 goto stop_fail;
268 }
269 PRINT_OK();
270
271 printf("Destroy tracing session 2: ");
272 if ((ret = lttng_destroy_session(session_name2)) < 0) {
273 printf("error destroying session 2: %s\n", lttng_strerror(ret));
274 }
275 PRINT_OK();
276
277 printf("Destroy tracing session: ");
278 if ((ret = lttng_destroy_session(session_name)) < 0) {
279 printf("error destroying session: %s\n", lttng_strerror(ret));
280 }
281 PRINT_OK();
282
283 return 0;
284
285 handle_fail:
286 assert(handle != NULL);
287 create_fail:
288 assert(ret != 0);
289
290 stop_fail:
291 start_fail:
292 context_fail:
293 enable_fail:
294 lttng_destroy_session(session_name2);
295 lttng_destroy_session(session_name);
296 lttng_destroy_handle(handle);
297
298 return 1;
299 }
This page took 0.038884 seconds and 3 git commands to generate.