Fix: make lttng expand path for trace output opt
[lttng-tools.git] / tests / ust / ust_global_event_basic.c
CommitLineData
69c0b621
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 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
97e19046 32int lttng_opt_quiet;
d2641a83 33
69c0b621
DG
34int main(int argc, char **argv)
35{
441c16a7
MD
36 struct lttng_handle *handle = NULL;
37 struct lttng_domain dom;
69c0b621
DG
38 struct lttng_channel channel;
39 struct lttng_event ev1, ev2, ev3;
d3e8f6bb 40 char *session_name = "ust_global_event_basic";
441c16a7 41 int ret = 0;
69c0b621 42
441c16a7
MD
43 memset(&dom, 0, sizeof(dom));
44 memset(&channel, 0, sizeof(channel));
45 memset(&ev1, 0, sizeof(ev1));
46 memset(&ev2, 0, sizeof(ev2));
47 memset(&ev3, 0, sizeof(ev3));
69c0b621 48
441c16a7 49 dom.type = LTTNG_DOMAIN_UST;
69c0b621
DG
50 strcpy(channel.name, "mychan");
51 channel.attr.overwrite = 0;
52 channel.attr.subbuf_size = 4096;
53 channel.attr.num_subbuf = 4;
54 channel.attr.switch_timer_interval = 0;
55 channel.attr.read_timer_interval = 200;
56 channel.attr.output = LTTNG_EVENT_MMAP;
57
58 strcpy(ev1.name, "tp1");
59 ev1.type = LTTNG_EVENT_TRACEPOINT;
8005f29a 60 ev1.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
69c0b621
DG
61
62 strcpy(ev2.name, "ev2");
63 ev2.type = LTTNG_EVENT_TRACEPOINT;
8005f29a 64 ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
69c0b621
DG
65
66 strcpy(ev3.name, "ev3");
67 ev3.type = LTTNG_EVENT_TRACEPOINT;
8005f29a 68 ev3.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
69c0b621
DG
69
70 printf("\nTesting tracing UST events:\n");
71 printf("-----------\n");
72
73 if (argc < 2) {
74 printf("Missing session trace path\n");
75 return 1;
76 }
77
78 printf("Creating tracing session (%s): ", argv[1]);
f973f94b
MD
79 if ((ret = lttng_create_session(session_name, argv[1])) < 0) {
80 printf("error creating the session : %s\n", lttng_strerror(ret));
69c0b621 81 goto create_fail;
f973f94b 82 }
69c0b621
DG
83 PRINT_OK();
84
85 printf("Creating session handle: ");
86 if ((handle = lttng_create_handle(session_name, &dom)) == NULL) {
87 printf("error creating handle: %s\n", lttng_strerror(ret));
88 goto handle_fail;
89 }
90 PRINT_OK();
91
92 printf("Enabling %s UST channel: ", channel.name);
93 if ((ret = lttng_enable_channel(handle, &channel)) < 0) {
94 printf("error enable channel: %s\n", lttng_strerror(ret));
95 goto enable_fail;
96 }
97 PRINT_OK();
98
99 printf("Enabling %s UST event: ", ev1.name);
f973f94b
MD
100 if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) {
101 printf("error enabling event: %s\n", lttng_strerror(ret));
69c0b621 102 goto enable_fail;
f973f94b 103 }
69c0b621
DG
104 PRINT_OK();
105
106 printf("Enabling %s UST event: ", ev2.name);
107 if ((ret = lttng_enable_event(handle, &ev2, channel.name)) < 0) {
108 printf("error enabling event: %s\n", lttng_strerror(ret));
109 goto enable_fail;
110 }
111 PRINT_OK();
112
113 printf("Enabling %s UST event: ", ev3.name);
114 if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) {
115 printf("error enabling event: %s\n", lttng_strerror(ret));
116 goto enable_fail;
117 }
118 PRINT_OK();
119
120 printf("Disabling %s UST event: ", ev1.name);
121 if ((ret = lttng_disable_event(handle, ev1.name, channel.name)) < 0) {
122 printf("error enabling event: %s\n", lttng_strerror(ret));
123 goto enable_fail;
124 }
125 PRINT_OK();
126
127 printf("Disabling %s UST event: ", ev3.name);
128 if ((ret = lttng_disable_event(handle, ev3.name, channel.name)) < 0) {
129 printf("error enabling event: %s\n", lttng_strerror(ret));
130 goto enable_fail;
131 }
132 PRINT_OK();
133
134 printf("Renabling %s UST event: ", ev1.name);
135 if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) {
136 printf("error enabling event: %s\n", lttng_strerror(ret));
137 goto enable_fail;
138 }
139 PRINT_OK();
140
141 printf("Renabling %s UST event: ", ev3.name);
142 if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) {
143 printf("error enabling event: %s\n", lttng_strerror(ret));
144 goto enable_fail;
145 }
146 PRINT_OK();
147
148 printf("Start tracing: ");
149 if ((ret = lttng_start_tracing(session_name)) < 0) {
150 printf("error starting tracing: %s\n", lttng_strerror(ret));
151 goto start_fail;
152 }
153 PRINT_OK();
154
155 sleep(2);
156
157 printf("Stop tracing: ");
158 if ((ret = lttng_stop_tracing(session_name)) < 0) {
159 printf("error stopping tracing: %s\n", lttng_strerror(ret));
160 goto stop_fail;
161 }
162 PRINT_OK();
163
f848c3eb
DG
164 printf("Restart tracing: ");
165 if ((ret = lttng_start_tracing(session_name)) < 0) {
166 printf("error starting tracing: %s\n", lttng_strerror(ret));
167 goto start_fail;
168 }
169 PRINT_OK();
170
171 sleep(2);
172
173 printf("Stop tracing: ");
174 if ((ret = lttng_stop_tracing(session_name)) < 0) {
175 printf("error stopping tracing: %s\n", lttng_strerror(ret));
176 goto stop_fail;
177 }
178 PRINT_OK();
179
69c0b621
DG
180 printf("Destroy tracing session: ");
181 if ((ret = lttng_destroy_session(session_name)) < 0) {
182 printf("error destroying session: %s\n", lttng_strerror(ret));
183 }
184 PRINT_OK();
185
186 return 0;
187
188create_fail:
189 assert(ret != 0);
190handle_fail:
191 assert(handle != NULL);
192
193stop_fail:
194start_fail:
195enable_fail:
196 lttng_destroy_session(session_name);
197 lttng_destroy_handle(handle);
198
f973f94b 199 return 1;
69c0b621 200}
This page took 0.044237 seconds and 4 git commands to generate.