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