2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
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
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 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.
28 #include <lttng/lttng.h>
34 int main(int argc
, char **argv
)
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";
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
));
53 dom
.type
= LTTNG_DOMAIN_UST
;
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
;
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
;
73 strcpy(ev1
.name
, "tp1");
74 ev1
.type
= LTTNG_EVENT_TRACEPOINT
;
75 ev1
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
77 strcpy(ev2
.name
, "ev2");
78 ev2
.type
= LTTNG_EVENT_TRACEPOINT
;
79 ev2
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
81 strcpy(ev3
.name
, "ev3");
82 ev3
.type
= LTTNG_EVENT_TRACEPOINT
;
83 ev3
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
85 printf("\nTesting tracing UST events:\n");
86 printf("-----------\n");
89 printf("Missing session trace path\n");
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
));
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
));
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
));
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
));
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
));
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
));
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
));
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
));
149 context
.ctx
= LTTNG_EVENT_CONTEXT_VPID
;
151 printf("Adding context VPID to UST event %s in channel %s: ", ev1
.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
));
160 context
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
162 printf("Adding context VTID to UST event %s in channel %s: ", ev1
.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
));
171 context
.ctx
= LTTNG_EVENT_CONTEXT_PTHREAD_ID
;
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
));
182 context
.ctx
= LTTNG_EVENT_CONTEXT_PROCNAME
;
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
));
193 context
.ctx
= LTTNG_EVENT_CONTEXT_PROCNAME
;
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
));
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
));
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
));
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
));
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
));
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
));
239 printf("Start tracing: ");
240 if ((ret
= lttng_start_tracing(session_name
)) < 0) {
241 printf("error starting tracing: %s\n", lttng_strerror(ret
));
248 printf("Stop tracing: ");
249 if ((ret
= lttng_stop_tracing(session_name
)) < 0) {
250 printf("error stopping tracing: %s\n", lttng_strerror(ret
));
255 printf("Restart tracing: ");
256 if ((ret
= lttng_start_tracing(session_name
)) < 0) {
257 printf("error starting tracing: %s\n", lttng_strerror(ret
));
264 printf("Stop tracing: ");
265 if ((ret
= lttng_stop_tracing(session_name
)) < 0) {
266 printf("error stopping tracing: %s\n", lttng_strerror(ret
));
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
));
277 printf("Destroy tracing session: ");
278 if ((ret
= lttng_destroy_session(session_name
)) < 0) {
279 printf("error destroying session: %s\n", lttng_strerror(ret
));
286 assert(handle
!= NULL
);
294 lttng_destroy_session(session_name2
);
295 lttng_destroy_session(session_name
);
296 lttng_destroy_handle(handle
);