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