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
;
39 struct lttng_event sched_switch
;
40 struct lttng_event sched_process_exit
;
41 struct lttng_event sched_process_free
;
42 char *session_name
= "kernel_event_basic";
45 memset(&dom
, 0, sizeof(dom
));
46 memset(&channel
, 0, sizeof(channel
));
47 memset(&sched_switch
, 0, sizeof(sched_switch
));
48 memset(&sched_process_exit
, 0, sizeof(sched_process_exit
));
49 memset(&sched_process_free
, 0, sizeof(sched_process_free
));
51 dom
.type
= LTTNG_DOMAIN_KERNEL
;
53 strcpy(channel
.name
, "mychan");
54 channel
.attr
.overwrite
= 0;
55 channel
.attr
.subbuf_size
= 4096;
56 channel
.attr
.num_subbuf
= 8;
57 channel
.attr
.switch_timer_interval
= 0;
58 channel
.attr
.read_timer_interval
= 200;
59 channel
.attr
.output
= LTTNG_EVENT_SPLICE
;
61 strcpy(sched_switch
.name
, "sched_switch");
62 sched_switch
.type
= LTTNG_EVENT_TRACEPOINT
;
63 sched_switch
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
65 strcpy(sched_process_exit
.name
, "sched_process_exit");
66 sched_process_exit
.type
= LTTNG_EVENT_TRACEPOINT
;
67 sched_process_exit
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
69 strcpy(sched_process_free
.name
, "sched_process_free");
70 sched_process_free
.type
= LTTNG_EVENT_TRACEPOINT
;
71 sched_process_free
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
73 printf("\nTesting tracing kernel events:\n");
74 printf("-----------\n");
77 printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n");
82 printf("Missing session trace path\n");
86 printf("Creating tracing session (%s): ", argv
[1]);
87 if ((ret
= lttng_create_session(session_name
, argv
[1])) < 0) {
88 printf("error creating the session : %s\n", lttng_strerror(ret
));
93 printf("Creating session handle: ");
94 if ((handle
= lttng_create_handle(session_name
, &dom
)) == NULL
) {
95 printf("error creating handle: %s\n", lttng_strerror(ret
));
100 printf("Enabling %s kernel channel: ", channel
.name
);
101 if ((ret
= lttng_enable_channel(handle
, &channel
)) < 0) {
102 printf("error enable channel: %s\n", lttng_strerror(ret
));
106 printf("Enabling %s kernel event: ", sched_switch
.name
);
107 if ((ret
= lttng_enable_event(handle
, &sched_switch
, channel
.name
)) < 0) {
108 printf("error enabling event: %s\n", lttng_strerror(ret
));
113 printf("Enabling %s kernel event: ", sched_process_exit
.name
);
114 if ((ret
= lttng_enable_event(handle
, &sched_process_exit
, channel
.name
)) < 0) {
115 printf("error enabling event: %s\n", lttng_strerror(ret
));
120 printf("Enabling %s kernel event: ", sched_process_free
.name
);
121 if ((ret
= lttng_enable_event(handle
, &sched_process_free
, channel
.name
)) < 0) {
122 printf("error enabling event: %s\n", lttng_strerror(ret
));
127 printf("Disabling %s kernel event: ", sched_switch
.name
);
128 if ((ret
= lttng_disable_event(handle
, sched_switch
.name
, channel
.name
)) < 0) {
129 printf("error enabling event: %s\n", lttng_strerror(ret
));
134 printf("Disabling %s kernel event: ", sched_process_free
.name
);
135 if ((ret
= lttng_disable_event(handle
, sched_process_free
.name
, channel
.name
)) < 0) {
136 printf("error enabling event: %s\n", lttng_strerror(ret
));
141 printf("Renabling %s kernel event: ", sched_switch
.name
);
142 if ((ret
= lttng_enable_event(handle
, &sched_switch
, channel
.name
)) < 0) {
143 printf("error enabling event: %s\n", lttng_strerror(ret
));
148 printf("Renabling %s kernel event: ", sched_process_free
.name
);
149 if ((ret
= lttng_enable_event(handle
, &sched_process_free
, channel
.name
)) < 0) {
150 printf("error enabling event: %s\n", lttng_strerror(ret
));
155 printf("Start tracing: ");
156 if ((ret
= lttng_start_tracing(session_name
)) < 0) {
157 printf("error starting tracing: %s\n", lttng_strerror(ret
));
164 printf("Stop tracing: ");
165 if ((ret
= lttng_stop_tracing(session_name
)) < 0) {
166 printf("error stopping tracing: %s\n", lttng_strerror(ret
));
171 printf("Destroy tracing session: ");
172 if ((ret
= lttng_destroy_session(session_name
)) < 0) {
173 printf("error destroying session: %s\n", lttng_strerror(ret
));
180 assert(handle
!= NULL
);
187 lttng_destroy_session(session_name
);
188 lttng_destroy_handle(handle
);