Commit | Line | Data |
---|---|---|
e3fa263d 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 | { | |
34 | struct lttng_handle *handle = NULL; | |
35 | struct lttng_domain dom; | |
8c9ae521 | 36 | struct lttng_event event; |
d04f4d75 | 37 | char *channel_name = "channel0"; |
d3e8f6bb | 38 | char *session_name = "kernel_all_events_basic"; |
e3fa263d DG |
39 | int ret = 0; |
40 | ||
41 | dom.type = LTTNG_DOMAIN_KERNEL; | |
42 | ||
8c9ae521 DG |
43 | memset(&event, 0, sizeof(struct lttng_event)); |
44 | event.type = LTTNG_EVENT_TRACEPOINT; | |
45 | ||
c60ddab6 | 46 | printf("\nTesting tracing all kernel events:\n"); |
e3fa263d DG |
47 | printf("-----------\n"); |
48 | /* Check if root */ | |
49 | if (getuid() != 0) { | |
50 | printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n"); | |
51 | return 0; | |
52 | } | |
53 | ||
54 | if (argc < 2) { | |
55 | printf("Missing session trace path\n"); | |
56 | return 1; | |
57 | } | |
58 | ||
59 | printf("Creating tracing session (%s): ", argv[1]); | |
d3e8f6bb | 60 | if ((ret = lttng_create_session(session_name, argv[1])) < 0) { |
9a745bc7 | 61 | printf("error creating the session : %s\n", lttng_strerror(ret)); |
e3fa263d DG |
62 | goto create_fail; |
63 | } | |
64 | PRINT_OK(); | |
65 | ||
66 | printf("Creating session handle: "); | |
d3e8f6bb | 67 | if ((handle = lttng_create_handle(session_name, &dom)) == NULL) { |
9a745bc7 | 68 | printf("error creating handle: %s\n", lttng_strerror(ret)); |
e3fa263d DG |
69 | goto handle_fail; |
70 | } | |
71 | PRINT_OK(); | |
72 | ||
73 | printf("Enabling all kernel events: "); | |
8c9ae521 | 74 | if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { |
9a745bc7 | 75 | printf("error enabling event: %s\n", lttng_strerror(ret)); |
e3fa263d DG |
76 | goto enable_fail; |
77 | } | |
78 | PRINT_OK(); | |
79 | ||
80 | printf("Start tracing: "); | |
d3e8f6bb | 81 | if ((ret = lttng_start_tracing(session_name)) < 0) { |
9a745bc7 | 82 | printf("error starting tracing: %s\n", lttng_strerror(ret)); |
e3fa263d DG |
83 | goto start_fail; |
84 | } | |
85 | PRINT_OK(); | |
86 | ||
87 | sleep(2); | |
88 | ||
89 | printf("Stop tracing: "); | |
d3e8f6bb | 90 | if ((ret = lttng_stop_tracing(session_name)) < 0) { |
9a745bc7 | 91 | printf("error stopping tracing: %s\n", lttng_strerror(ret)); |
e3fa263d DG |
92 | goto stop_fail; |
93 | } | |
94 | PRINT_OK(); | |
95 | ||
96 | printf("Destroy tracing session: "); | |
d3e8f6bb | 97 | if ((ret = lttng_destroy_session(session_name)) < 0) { |
9a745bc7 | 98 | printf("error destroying session: %s\n", lttng_strerror(ret)); |
e3fa263d DG |
99 | } |
100 | PRINT_OK(); | |
101 | ||
102 | return 0; | |
103 | ||
104 | create_fail: | |
105 | assert(ret != 0); | |
106 | handle_fail: | |
107 | assert(handle != NULL); | |
108 | ||
109 | stop_fail: | |
110 | start_fail: | |
111 | enable_fail: | |
d3e8f6bb | 112 | lttng_destroy_session(session_name); |
e3fa263d DG |
113 | lttng_destroy_handle(handle); |
114 | ||
115 | return 1; | |
116 | } |