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>
32 int main(int argc
, char **argv
)
34 struct lttng_handle
*handle
= NULL
;
35 struct lttng_domain dom
;
36 struct lttng_channel channel
;
37 struct lttng_event sched_switch
;
38 struct lttng_event sched_process_exit
;
39 struct lttng_event sched_process_free
;
43 char *session_name
= "kernel_event";
45 dom
.type
= LTTNG_DOMAIN_KERNEL
;
47 strcpy(channel
.name
, "mychan");
48 channel
.attr
.overwrite
= 0;
49 channel
.attr
.subbuf_size
= 4096;
50 channel
.attr
.num_subbuf
= 8;
51 channel
.attr
.switch_timer_interval
= 0;
52 channel
.attr
.read_timer_interval
= 200;
53 channel
.attr
.output
= LTTNG_EVENT_SPLICE
;
55 strcpy(sched_switch
.name
, "sched_switch");
56 sched_switch
.type
= LTTNG_EVENT_TRACEPOINT
;
58 strcpy(sched_process_exit
.name
, "sched_process_exit");
59 sched_process_exit
.type
= LTTNG_EVENT_TRACEPOINT
;
61 strcpy(sched_process_free
.name
, "sched_process_free");
62 sched_process_free
.type
= LTTNG_EVENT_TRACEPOINT
;
64 printf("\nTesting tracing kernel events:\n");
65 printf("-----------\n");
68 printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n");
73 printf("Missing session trace path\n");
77 printf("Creating tracing session (%s): ", argv
[1]);
78 if ((ret
= lttng_create_session(session_name
, argv
[1])) < 0) {
79 printf("error creating the session : %s\n", lttng_strerror(ret
));
84 printf("Creating session handle: ");
85 if ((handle
= lttng_create_handle(session_name
, &dom
)) == NULL
) {
86 printf("error creating handle: %s\n", lttng_strerror(ret
));
91 printf("Enabling %s kernel channel: ", channel
.name
);
92 if ((ret
= lttng_enable_channel(handle
, &channel
)) < 0) {
93 printf("error enable channel: %s\n", lttng_strerror(ret
));
97 printf("Enabling %s kernel event: ", sched_switch
.name
);
98 if ((ret
= lttng_enable_event(handle
, &sched_switch
, channel
.name
)) < 0) {
99 printf("error enabling event: %s\n", lttng_strerror(ret
));
104 printf("Enabling %s kernel event: ", sched_process_exit
.name
);
105 if ((ret
= lttng_enable_event(handle
, &sched_process_exit
, channel
.name
)) < 0) {
106 printf("error enabling event: %s\n", lttng_strerror(ret
));
111 printf("Enabling %s kernel event: ", sched_process_free
.name
);
112 if ((ret
= lttng_enable_event(handle
, &sched_process_free
, channel
.name
)) < 0) {
113 printf("error enabling event: %s\n", lttng_strerror(ret
));
118 printf("Disabling %s kernel event: ", sched_switch
.name
);
119 if ((ret
= lttng_disable_event(handle
, sched_switch
.name
, channel
.name
)) < 0) {
120 printf("error enabling event: %s\n", lttng_strerror(ret
));
125 printf("Disabling %s kernel event: ", sched_process_free
.name
);
126 if ((ret
= lttng_disable_event(handle
, sched_process_free
.name
, channel
.name
)) < 0) {
127 printf("error enabling event: %s\n", lttng_strerror(ret
));
132 printf("Renabling %s kernel event: ", sched_switch
.name
);
133 if ((ret
= lttng_enable_event(handle
, &sched_switch
, channel
.name
)) < 0) {
134 printf("error enabling event: %s\n", lttng_strerror(ret
));
139 printf("Renabling %s kernel event: ", sched_process_free
.name
);
140 if ((ret
= lttng_enable_event(handle
, &sched_process_free
, channel
.name
)) < 0) {
141 printf("error enabling event: %s\n", lttng_strerror(ret
));
146 printf("Start tracing: ");
147 if ((ret
= lttng_start_tracing(handle
)) < 0) {
148 printf("error starting tracing: %s\n", lttng_strerror(ret
));
155 printf("Stop tracing: ");
156 if ((ret
= lttng_stop_tracing(handle
)) < 0) {
157 printf("error stopping tracing: %s\n", lttng_strerror(ret
));
162 printf("Destroy tracing session: ");
163 if ((ret
= lttng_destroy_session(handle
)) < 0) {
164 printf("error destroying session: %s\n", lttng_strerror(ret
));
173 assert(handle
!= NULL
);
178 lttng_destroy_session(handle
);
179 lttng_destroy_handle(handle
);