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